@Test public void testRecoverHarvests() { HarvestAgentH3 hah3Spy = spy(hah3); mock(HarvesterH3.class); List<String> coreJobs = new ArrayList<>(); coreJobs.add("job01"); coreJobs.add("job02"); coreJobs.add("job03"); coreJobs.add("job04"); Map<String, String> h3Jobs = new HashMap<>(); h3Jobs.put("job01", "RUNNING"); h3Jobs.put("job02", "FINISHED"); h3Jobs.put("job03", "PAUSED"); doReturn(h3Jobs).when(hah3Spy).getActiveH3Jobs(); hah3Spy.recoverHarvests(coreJobs); for(String job : coreJobs){ Harvester recoveredJob = hah3Spy.getHarvester(job); if(h3Jobs.containsKey(job)){ assertNotNull(recoveredJob); assertEquals(recoveredJob.getName(), job); } else{ assertNull(recoveredJob); } } }
public void recoverHarvests(List<String> activeCoreJobs) { try { if (!activeCoreJobs.isEmpty()) { log.info("Checking for harvests to recover. Active jobs received from Core: " + activeCoreJobs.size()); Map<String, String> activeH3JobNames = getActiveH3Jobs(); if (!activeH3JobNames.isEmpty()) { for (String jobName : activeCoreJobs) { log.info("Checking job " + jobName + " for recovery"); if (activeH3JobNames.containsKey(jobName)) { Harvester harvester = null; String h3JobState = activeH3JobNames.get(jobName); if (h3JobState.equals("RUNNING") || h3JobState.equals("PAUSED") || h3JobState.equals("FINISHED")) { log.info("Harves Agent recovering job " + jobName + " from H3 in state: " + h3JobState); super.initiateHarvest(jobName, "", ""); harvester = getHarvester(jobName); harvester.recover(); harvester.setAlertThreshold(alertThreshold); } } } } else { log.info("No harvests to recover from H3 instance."); } } else { log.info("No harvests to recover from Core."); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Failed to recover harvests: " + e.getMessage(), e); } } }
HarvestAgentH3 extends AbstractHarvestAgent implements LogProvider { public void recoverHarvests(List<String> activeCoreJobs) { try { if (!activeCoreJobs.isEmpty()) { log.info("Checking for harvests to recover. Active jobs received from Core: " + activeCoreJobs.size()); Map<String, String> activeH3JobNames = getActiveH3Jobs(); if (!activeH3JobNames.isEmpty()) { for (String jobName : activeCoreJobs) { log.info("Checking job " + jobName + " for recovery"); if (activeH3JobNames.containsKey(jobName)) { Harvester harvester = null; String h3JobState = activeH3JobNames.get(jobName); if (h3JobState.equals("RUNNING") || h3JobState.equals("PAUSED") || h3JobState.equals("FINISHED")) { log.info("Harves Agent recovering job " + jobName + " from H3 in state: " + h3JobState); super.initiateHarvest(jobName, "", ""); harvester = getHarvester(jobName); harvester.recover(); harvester.setAlertThreshold(alertThreshold); } } } } else { log.info("No harvests to recover from H3 instance."); } } else { log.info("No harvests to recover from Core."); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Failed to recover harvests: " + e.getMessage(), e); } } } }
HarvestAgentH3 extends AbstractHarvestAgent implements LogProvider { public void recoverHarvests(List<String> activeCoreJobs) { try { if (!activeCoreJobs.isEmpty()) { log.info("Checking for harvests to recover. Active jobs received from Core: " + activeCoreJobs.size()); Map<String, String> activeH3JobNames = getActiveH3Jobs(); if (!activeH3JobNames.isEmpty()) { for (String jobName : activeCoreJobs) { log.info("Checking job " + jobName + " for recovery"); if (activeH3JobNames.containsKey(jobName)) { Harvester harvester = null; String h3JobState = activeH3JobNames.get(jobName); if (h3JobState.equals("RUNNING") || h3JobState.equals("PAUSED") || h3JobState.equals("FINISHED")) { log.info("Harves Agent recovering job " + jobName + " from H3 in state: " + h3JobState); super.initiateHarvest(jobName, "", ""); harvester = getHarvester(jobName); harvester.recover(); harvester.setAlertThreshold(alertThreshold); } } } } else { log.info("No harvests to recover from H3 instance."); } } else { log.info("No harvests to recover from Core."); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Failed to recover harvests: " + e.getMessage(), e); } } } HarvestAgentH3(); }
HarvestAgentH3 extends AbstractHarvestAgent implements LogProvider { public void recoverHarvests(List<String> activeCoreJobs) { try { if (!activeCoreJobs.isEmpty()) { log.info("Checking for harvests to recover. Active jobs received from Core: " + activeCoreJobs.size()); Map<String, String> activeH3JobNames = getActiveH3Jobs(); if (!activeH3JobNames.isEmpty()) { for (String jobName : activeCoreJobs) { log.info("Checking job " + jobName + " for recovery"); if (activeH3JobNames.containsKey(jobName)) { Harvester harvester = null; String h3JobState = activeH3JobNames.get(jobName); if (h3JobState.equals("RUNNING") || h3JobState.equals("PAUSED") || h3JobState.equals("FINISHED")) { log.info("Harves Agent recovering job " + jobName + " from H3 in state: " + h3JobState); super.initiateHarvest(jobName, "", ""); harvester = getHarvester(jobName); harvester.recover(); harvester.setAlertThreshold(alertThreshold); } } } } else { log.info("No harvests to recover from H3 instance."); } } else { log.info("No harvests to recover from Core."); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Failed to recover harvests: " + e.getMessage(), e); } } } HarvestAgentH3(); void initiateHarvest(String aJob, String aProfile, String aSeeds); void recoverHarvests(List<String> activeCoreJobs); void abort(String aJob); void stop(String aJob); int completeHarvest(String aJob, int aFailureStep); HarvestAgentStatusDTO getStatus(); void loadSettings(String aJob); File getLogFile(String aJob, String aFileName); List getLogFileNames(String aJob); LogFilePropertiesDTO[] getLogFileAttributes(String aJob); void pause(String aJob); void resume(String aJob); void setHost(String aHost); String getHost(); void setMaxHarvests(int aMaxHarvests); void setName(String aName); HarvesterType getHarvesterType(); void setPort(int aPort); void setService(String aService); void setLogReaderService(String aLogReaderService); ArrayList getAllowedAgencies(); void setAllowedAgencies(ArrayList aAllowedAgencies); void setDigitalAssetStore(DigitalAssetStore aDigitalAssetStore); void setHarvestCoordinatorNotifier(
            HarvestAgentListener harvestCoordinatorNotifier); void setBaseHarvestDirectory(String aBaseHarvestDirectory); void setProvenanceNote(String provenanceNote); void setAlertThreshold(int alertThreshold); String getName(); void updateProfileOverrides(String aJob, String aProfile); void purgeAbortedTargetInstances(String[] targetInstanceNames); Map<String, String> getActiveH3Jobs(); boolean isValidProfile(String profile); HarvestAgentScriptResult executeShellScript(String jobName, String engine, String shellScript); }
HarvestAgentH3 extends AbstractHarvestAgent implements LogProvider { public void recoverHarvests(List<String> activeCoreJobs) { try { if (!activeCoreJobs.isEmpty()) { log.info("Checking for harvests to recover. Active jobs received from Core: " + activeCoreJobs.size()); Map<String, String> activeH3JobNames = getActiveH3Jobs(); if (!activeH3JobNames.isEmpty()) { for (String jobName : activeCoreJobs) { log.info("Checking job " + jobName + " for recovery"); if (activeH3JobNames.containsKey(jobName)) { Harvester harvester = null; String h3JobState = activeH3JobNames.get(jobName); if (h3JobState.equals("RUNNING") || h3JobState.equals("PAUSED") || h3JobState.equals("FINISHED")) { log.info("Harves Agent recovering job " + jobName + " from H3 in state: " + h3JobState); super.initiateHarvest(jobName, "", ""); harvester = getHarvester(jobName); harvester.recover(); harvester.setAlertThreshold(alertThreshold); } } } } else { log.info("No harvests to recover from H3 instance."); } } else { log.info("No harvests to recover from Core."); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Failed to recover harvests: " + e.getMessage(), e); } } } HarvestAgentH3(); void initiateHarvest(String aJob, String aProfile, String aSeeds); void recoverHarvests(List<String> activeCoreJobs); void abort(String aJob); void stop(String aJob); int completeHarvest(String aJob, int aFailureStep); HarvestAgentStatusDTO getStatus(); void loadSettings(String aJob); File getLogFile(String aJob, String aFileName); List getLogFileNames(String aJob); LogFilePropertiesDTO[] getLogFileAttributes(String aJob); void pause(String aJob); void resume(String aJob); void setHost(String aHost); String getHost(); void setMaxHarvests(int aMaxHarvests); void setName(String aName); HarvesterType getHarvesterType(); void setPort(int aPort); void setService(String aService); void setLogReaderService(String aLogReaderService); ArrayList getAllowedAgencies(); void setAllowedAgencies(ArrayList aAllowedAgencies); void setDigitalAssetStore(DigitalAssetStore aDigitalAssetStore); void setHarvestCoordinatorNotifier(
            HarvestAgentListener harvestCoordinatorNotifier); void setBaseHarvestDirectory(String aBaseHarvestDirectory); void setProvenanceNote(String provenanceNote); void setAlertThreshold(int alertThreshold); String getName(); void updateProfileOverrides(String aJob, String aProfile); void purgeAbortedTargetInstances(String[] targetInstanceNames); Map<String, String> getActiveH3Jobs(); boolean isValidProfile(String profile); HarvestAgentScriptResult executeShellScript(String jobName, String engine, String shellScript);  }