HarvestCoordinatorImpl implements HarvestCoordinator { public void harvestComplete(HarvestResultDTO aResult) { TargetInstance ti = targetInstanceDao.load(aResult.getTargetInstanceOid()); if (ti == null) { throw new WCTRuntimeException("Unknown TargetInstance oid recieved " + aResult.getTargetInstanceOid() + " failed to save HarvestResult."); } if (aResult.getHarvestNumber() == 1 && !ti.getHarvestResults().isEmpty()) { log.warn("Duplicate 'Harvest Complete' message received for job: " + ti.getOid() + ". Message ignored."); return; } log.info("'Harvest Complete' message received for job: " + ti.getOid() + "."); HarvestResult harvestResult = null; if (aResult instanceof ArcHarvestResultDTO) { harvestResult = new ArcHarvestResult((ArcHarvestResultDTO) aResult, ti); } else { harvestResult = new HarvestResult(aResult, ti); } harvestResult.setState(HarvestResult.STATE_INDEXING); List<HarvestResult> hrs = ti.getHarvestResults(); hrs.add(harvestResult); ti.setHarvestResults(hrs); ti.setState(TargetInstance.STATE_HARVESTED); targetInstanceDao.save(harvestResult); targetInstanceDao.save(ti); harvestBandwidthManager.sendBandWidthRestrictions(); boolean bActiveSchedules = false; AbstractTarget tiTarget = ti.getTarget(); Date now = new Date(); for (Schedule schedule : tiTarget.getSchedules()) { if (schedule.getEndDate() == null) { bActiveSchedules = true; } else { if (schedule.getEndDate().after(now)) { bActiveSchedules = true; } } } if (targetInstanceDao.countActiveTIsForTarget(tiTarget.getOid()) == 0 && !bActiveSchedules) { Target t = targetManager.load(tiTarget.getOid(), true); t.changeState(Target.STATE_COMPLETED); targetManager.save(t); } try { digitalAssetStoreFactory.getDAS().initiateIndexing( new ArcHarvestResultDTO(harvestResult.getOid(), harvestResult.getTargetInstance().getOid(), harvestResult .getCreationDate(), harvestResult.getHarvestNumber(), harvestResult.getProvenanceNote())); } catch (DigitalAssetStoreException ex) { log.error("Could not send initiateIndexing message to the DAS", ex); } inTrayManager.generateNotification(ti.getOwner().getOid(), MessageType.CATEGORY_MISC, MessageType.TARGET_INSTANCE_COMPLETE, ti); inTrayManager.generateTask(Privilege.ENDORSE_HARVEST, MessageType.TARGET_INSTANCE_ENDORSE, ti); log.info("'Harvest Complete' message processed for job: " + ti.getOid() + "."); runAutoPrune(ti); } HarvestCoordinatorImpl(); void heartbeat(HarvestAgentStatusDTO aStatus); void requestRecovery(String haHost, int port, String haService); void recoverHarvests(String haHost, int haPort, String haService); void harvestComplete(HarvestResultDTO aResult); Boolean reIndexHarvestResult(HarvestResult origHarvestResult); void notification(Long aTargetInstanceOid, int notificationCategory, String aMessageType); void notification(String aSubject, int notificationCategory, String aMessage); void harvest(TargetInstance aTargetInstance, HarvestAgentStatusDTO aHarvestAgent); synchronized void checkForBandwidthTransition(); long getCurrentGlobalMaxBandwidth(); HashMap<String, List<BandwidthRestriction>> getBandwidthRestrictions(); BandwidthRestriction getBandwidthRestriction(Long aOid); BandwidthRestriction getBandwidthRestriction(String aDay, Date aTime); void saveOrUpdate(BandwidthRestriction bandwidthRestriction); void delete(BandwidthRestriction bandwidthRestriction); void setMinimumBandwidth(int aMinimumBandwidth); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); int getMaxBandwidthPercent(); void setMaxBandwidthPercent(int maxBandwidthPercent); void updateProfileOverrides(TargetInstance aTargetInstance); void pause(TargetInstance aTargetInstance); void resume(TargetInstance aTargetInstance); void abort(TargetInstance aTargetInstance); void stop(TargetInstance aTargetInstance); void pauseAll(); void resumeAll(); void pauseQueue(); void resumeQueue(); boolean isQueuePaused(); void processSchedule(); synchronized void harvestOrQueue(QueuedTargetInstanceDTO aTargetInstance); boolean isMiniumBandwidthAvailable(TargetInstance aTargetInstance); List<String> listLogFiles(TargetInstance aTargetInstance); LogFilePropertiesDTO[] listLogFileAttributes(TargetInstance aTargetInstance); String[] tailLog(TargetInstance aTargetInstance, String aFileName, int aNoOfLines); Integer countLogLines(TargetInstance aTargetInstance, String aFileName); String[] headLog(TargetInstance aTargetInstance, String aFileName, int aNoOfLines); String[] getLog(TargetInstance aTargetInstance, String aFileName, int aStartLine, int aNoOfLines); Integer getFirstLogLineBeginning(TargetInstance aTargetInstance, String aFileName, String match); Integer getFirstLogLineContaining(TargetInstance aTargetInstance, String aFileName, String match); Integer getFirstLogLineAfterTimeStamp(TargetInstance aTargetInstance, String aFileName, Long timestamp); String[] getLogLinesByRegex(TargetInstance aTargetInstance, String aFileName, int aNoOfLines, String aRegex,
			boolean prependLineNumbers); String[] getHopPath(TargetInstance aTargetInstance, String aFileName, String aUrl); File getLogfile(TargetInstance aTargetInstance, String aFilename); void purgeDigitalAssets(); void purgeAbortedTargetInstances(); void setDigitalAssetStoreFactory(DigitalAssetStoreFactory digitalAssetStoreFactory); void setTargetManager(TargetManager targetManager); void setInTrayManager(InTrayManager inTrayManager); void setDaysBeforeDASPurge(int daysBeforeDASPurge); void setDaysBeforeAbortedTargetInstancePurge(int daysBeforeAbortedTargetInstancePurge); void setSipBuilder(SipBuilder sipBuilder); void addToHarvestResult(Long harvestResultOid, ArcHarvestFileDTO ahf); void addHarvestResources(Long harvestResultOid, Collection<HarvestResourceDTO> dtos); Long createHarvestResult(HarvestResultDTO harvestResultDTO); void finaliseIndex(Long harvestResultOid); void runQaRecommentationService(TargetInstance ti); void notifyAQAComplete(String aqaId); void removeIndexes(TargetInstance ti); void removeIndexes(HarvestResult hr); void completeArchiving(Long targetInstanceOid, String archiveIID); void failedArchiving(Long targetInstanceOid, String message); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); @Override void pauseAgent(String agentName); @Override void resumeAgent(String agentName); @Override int getHarvestOptimizationLookAheadHours(); void setHarvestOptimizationLookAheadHours(int harvestOptimizeLookAheadHours); @Override void setHarvestOptimizationEnabled(boolean state); @Override boolean isHarvestOptimizationEnabled(); int getNumHarvestersExcludedFromOptimisation(); void setNumHarvestersExcludedFromOptimisation(int numHarvestersExcludedFromOptimisation); @Override HashMap<String, HarvestAgentStatusDTO> getHarvestAgents(); void setHarvestAgentManager(HarvestAgentManager harvestAgentManager); void setHarvestLogManager(HarvestLogManager harvestLogManager); void setHarvestBandwidthManager(HarvestBandwidthManager harvestBandwidthManager); void setHarvestQaManager(HarvestQaManager harvestQaManager);  }
@Test public final void testHarvestComplete() { MockDigitalAssetStore store = new MockDigitalAssetStore(); testInstance.setDigitalAssetStoreFactory(new MockDigitalAssetStoreFactory(store)); TargetInstance ti = tiDao.load(5001L); ti.setState(TargetInstance.STATE_STOPPING); HarvestResultDTO ahr = new ArcHarvestResultDTO(); ahr.setCreationDate(new Date()); ahr.setTargetInstanceOid(ti.getOid()); ahr.setProvenanceNote("Original Harvest"); List<HarvestResult> results = ti.getHarvestResults(); assertTrue(results.isEmpty()); testInstance.harvestComplete(ahr); assertEquals(ti.getState(), TargetInstance.STATE_HARVESTED); results = ti.getHarvestResults(); assertFalse(results.isEmpty()); assertEquals(1, results.size()); testInstance.harvestComplete(ahr); assertEquals(ti.getState(), TargetInstance.STATE_HARVESTED); results = ti.getHarvestResults(); assertFalse(results.isEmpty()); assertEquals(1, results.size()); }