importEntity.setState(Import.State.STARTED); importEntity.setStarted(System.currentTimeMillis()); importEntity.setErrorMessage(" "); rootEM.update(importEntity); if (logger.isTraceEnabled()) { importEntity.setErrorMessage(e.getMessage()); importEntity.setState(Import.State.FAILED); rootEM.update(importEntity); return; importEntity.setErrorMessage("No organization could be found"); importEntity.setState(Import.State.FAILED); rootEM.update(importEntity); return; importEntity.setErrorMessage(e.getMessage()); importEntity.setState(Import.State.FAILED); rootEM.update(importEntity); return; importEntity.setState(Import.State.FINISHED); importEntity.setErrorMessage("No files found in the bucket: " + bucketName); rootEM.update(importEntity); importEntity.addProperties(fileMetadata); importEntity.setFileCount(fileJobs.size()); rootEM.update(importEntity);
/** * Query Entity Manager for the error message generated for an import job. */ @Override public String getErrorMessage(final UUID uuid) throws Exception { //get application entity manager if (uuid == null) { logger.error("getErrorMessage(): UUID passed in cannot be null."); return "UUID passed in cannot be null"; } EntityManager rootEm = emf.getEntityManager(emf.getManagementAppId()); //retrieve the import entity. Import importUG = rootEm.get(uuid, Import.class); if (importUG == null) { logger.error("getErrorMessage(): no entity with that uuid was found"); return "No Such Element found"; } return importUG.getErrorMessage(); }
/** * This method is called when the job is retried maximum times by the * scheduler but still fails. Thus the scheduler marks it as DEAD. */ @Override public void dead( final JobExecution execution ) throws Exception { // marks the job as failed as it will not be retried by the scheduler. EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId()); Import importUG = importService.getImportEntity(execution); importUG.setErrorMessage("The Job has been tried maximum times but still failed"); importUG.setState(Import.State.FAILED); rootEm.update(importUG); } }
importEntity.getUuid()); return; failCount++; if (importEntity != null) { importEntity.setErrorMessage("Error determining status of file import jobs"); importEntity.setState(Import.State.FINISHED); } else { importEntity.setState(Import.State.FAILED); if (logger.isTraceEnabled()) { logger.trace("Updated import entity {}:{} with state {}", importEntity.getType(), importEntity.getUuid(), importEntity.getState());
/** * Test to the doImport Collection method with fake application ID */ @Test @Ignore("Pending merge of export-feature branch. Import application not supported") public void testDoImportCollectionWithFakeApplicationID() throws Exception { UUID fakeappId = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); // import S3Import s3Import = new S3ImportImpl(); ImportService importService = setup.getImportService(); HashMap<String, Object> payload = payloadBuilder(); payload.put("organizationId",organization.getUuid()); payload.put("applicationId",fakeappId); payload.put("collectionName","custom-test"); //schedule the import job final Import importEntity = importService.schedule( null, payload ); final UUID importUUID = importEntity.getUuid(); //create and initialize jobData returned in JobExecution. JobData jobData = jobImportDataCreator(payload, importUUID, s3Import); JobExecution jobExecution = mock( JobExecution.class ); when( jobExecution.getJobData() ).thenReturn( jobData ); //import the all collection files for the organization-application and wait for the import to finish importService.doImport(jobExecution); assertEquals(importService.getState(importUUID),Import.State.FAILED); }
Import importEntity = new Import(); importEntity = emMgmtApp.create( importEntity );
/** * Query Entity Manager for the state of the Import Entity. This corresponds to the GET /import */ @Override public Import.State getState(UUID uuid) throws Exception { Preconditions.checkNotNull(uuid, "uuid cannot be null"); EntityManager rootEm = emf.getEntityManager(emf.getManagementAppId()); //retrieve the import entity. Import importUG = rootEm.get(uuid, Import.class); if (importUG == null) { throw new EntityNotFoundException("Could not find entity with uuid " + uuid); } return importUG.getState(); }
/** * This method is called when the job is retried maximum times by the scheduler but still fails. * Thus the scheduler marks it as DEAD. */ @Override public void dead( final JobExecution execution ) throws Exception { // Get the root entity manager EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() ); // Mark the sub-job i.e. File Import Job as Failed FileImport fileImport = null;//importService.getFileImportEntity(execution); fileImport.setErrorMessage("The Job has been tried maximum times but still failed"); fileImport.setState(FileImport.State.FAILED); rootEm.update(fileImport); // If one file Job fails, mark the main import Job also as failed Results ImportJobResults = rootEm.getSourceEntities( fileImport, "includes", null, Level.ALL_PROPERTIES); List<Entity> importEntity = ImportJobResults.getEntities(); UUID importId = importEntity.get(0).getUuid(); Import importUG = rootEm.get(importId, Import.class); importUG.setState(Import.State.FAILED); rootEm.update(importUG); } }
/** * Test to the doImport method with fake application ID */ @Test @Ignore("Pending merge of export-feature branch. Import application not supported") public void testDoImportWithFakeApplicationID() throws Exception { UUID fakeappId = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); // import S3Import s3Import = new S3ImportImpl(); ImportService importService = setup.getImportService(); HashMap<String, Object> payload = payloadBuilder(); payload.put("organizationId",organization.getUuid()); payload.put("applicationId",fakeappId); //schedule the import job final Import importEntity = importService.schedule( null, payload ); final UUID importUUID = importEntity.getUuid(); //create and initialize jobData returned in JobExecution. JobData jobData = jobImportDataCreator(payload, importUUID, s3Import); JobExecution jobExecution = mock( JobExecution.class ); when( jobExecution.getJobData() ).thenReturn( jobData ); //import the application files for the organization and wait for the import to finish importService.doImport(jobExecution); assertEquals(Import.State.FAILED, importService.getState(importUUID)); }
@Override protected void doJob(JobExecution jobExecution) throws Exception { logger.info( "execute ImportJob {}", jobExecution.getJobId().toString() ); try { JobData jobData = jobExecution.getJobData(); if (jobData == null) { logger.error("jobData cannot be null"); return; } // heartbeat to indicate job has started jobExecution.heartbeat(); // call the doImport method from import service which // schedules the sub-jobs i.e. parsing of files to FileImport Job importService.doImport(jobExecution); } catch ( Throwable t ) { logger.error("Error calling in importJob", t); // update import job record UUID importId = (UUID) jobExecution.getJobData().getProperty(IMPORT_ID); EntityManager mgmtApp = emf.getEntityManager(emf.getManagementAppId()); Import importEntity = mgmtApp.get(importId, Import.class); importEntity.setState(Import.State.FAILED); importEntity.setErrorMessage(t.getMessage()); mgmtApp.update(importEntity); throw t; } if (logger.isTraceEnabled()) { logger.trace("Import Service completed job"); } }
/** * Test to the doImport method with fake organization ID */ @Test @Ignore("Pending merge of export-feature branch. Import organization not supported") public void testDoImportWithFakeOrganizationID() throws Exception { UUID fakeOrgId = UUID.fromString( "AAAAAAAA-FFFF-FFFF-FFFF-AAAAAAAAAAAA" ); // import S3Import s3Import = new S3ImportImpl(); ImportService importService = setup.getImportService(); HashMap<String, Object> payload = payloadBuilder(); payload.put("organizationId",fakeOrgId); //schedule the import job final Import importEntity = importService.schedule( null, payload ); final UUID importUUID = importEntity.getUuid(); //create and initialize jobData returned in JobExecution. JobData jobData = jobImportDataCreator(payload, importUUID, s3Import); JobExecution jobExecution = mock( JobExecution.class ); when( jobExecution.getJobData() ).thenReturn( jobData ); //import the all application files for the organization and wait for the import to finish importService.doImport(jobExecution); assertEquals(Import.State.FAILED, importService.getState(importUUID)); }
/** * Test to the doImport method with null organziation ID */ @Test @Ignore("Pending merge of export-feature branch. Import organization not supported") public void testDoImportWithNullOrganizationID() throws Exception { // import S3Import s3Import = new S3ImportImpl(); ImportService importService = setup.getImportService(); HashMap<String, Object> payload = payloadBuilder(); //schedule the import job final Import importEntity = importService.schedule( null, payload ); final UUID importUUID = importEntity.getUuid(); //create and initialize jobData returned in JobExecution. JobData jobData = jobImportDataCreator(payload, importUUID, s3Import); JobExecution jobExecution = mock( JobExecution.class ); when( jobExecution.getJobData() ).thenReturn( jobData ); importService.doImport(jobExecution); assertEquals(importService.getState(importUUID),Import.State.FAILED); }
final UUID importUUID = importEntity.getUuid();
final UUID importUUID = importEntity.getUuid();