@Test public void testHeartbeatUpdatesTiRunningFromPaused() { Long tOid = 123L; TargetInstance mockTargetInstance = mock(TargetInstance.class); when(mockTargetInstance.getState()).thenReturn(TargetInstance.STATE_PAUSED); HarvestAgentStatusDTO agentStatusDTO2 = setupHarvestAgentWithHarvestState(tOid, "Running", mockTargetInstance); underTest.heartbeat(agentStatusDTO2); verify(mockTargetInstanceDAO).load(tOid); verify(mockTargetInstanceManager).save(mockTargetInstance); verify(mockTargetInstance).setState(TargetInstance.STATE_RUNNING); }
@Override public void heartbeat(HarvestAgentStatusDTO aStatus) { if (harvestAgents.containsKey(aStatus.getName())) { log.debug("Updating status for {}", aStatus.getName()); } else { log.info("Registering harvest agent " + aStatus.getName()); } aStatus.setLastUpdated(new Date()); HarvestAgentStatusDTO currentStatus = harvestAgents.get(aStatus.getName()); if (currentStatus != null) { aStatus.setAcceptTasks(currentStatus.isAcceptTasks()); } harvestAgents.put(aStatus.getName(), aStatus); HashMap<String, HarvesterStatusDTO> harvesterStatusMap = aStatus.getHarvesterStatus(); for (String key : harvesterStatusMap.keySet()) { long tiOid = Long.parseLong(key.substring(key.lastIndexOf("-") + 1)); if (!lock(tiOid)) break; log.debug("Obtained lock for ti " + tiOid); TargetInstance ti = targetInstanceDao.load(tiOid); HarvesterStatusDTO harvesterStatusDto = (HarvesterStatusDTO) harvesterStatusMap.get(key); updateStatusWithEnvironment(harvesterStatusDto); HarvesterStatus harvesterStatus = createHarvesterStatus(ti, harvesterStatusDto); String harvesterStatusValue = harvesterStatus.getStatus(); if (harvesterStatusValue.startsWith("Paused")) { doHeartbeatPaused(ti); } if (harvesterStatusValue.startsWith("Running")) { doHeartbeatRunning(aStatus, ti, harvesterStatus); } if (harvesterStatusValue.startsWith("Finished")) { doHeartbeatFinished(ti); } if (harvesterStatusValue.startsWith("Could not launch job - Fatal InitializationException")) { doHeartbeatLaunchFailed(ti); } targetInstanceManager.save(ti); unLock(tiOid); log.debug("Released lock for ti " + tiOid); } }
HarvestAgentManagerImpl implements HarvestAgentManager { @Override public void heartbeat(HarvestAgentStatusDTO aStatus) { if (harvestAgents.containsKey(aStatus.getName())) { log.debug("Updating status for {}", aStatus.getName()); } else { log.info("Registering harvest agent " + aStatus.getName()); } aStatus.setLastUpdated(new Date()); HarvestAgentStatusDTO currentStatus = harvestAgents.get(aStatus.getName()); if (currentStatus != null) { aStatus.setAcceptTasks(currentStatus.isAcceptTasks()); } harvestAgents.put(aStatus.getName(), aStatus); HashMap<String, HarvesterStatusDTO> harvesterStatusMap = aStatus.getHarvesterStatus(); for (String key : harvesterStatusMap.keySet()) { long tiOid = Long.parseLong(key.substring(key.lastIndexOf("-") + 1)); if (!lock(tiOid)) break; log.debug("Obtained lock for ti " + tiOid); TargetInstance ti = targetInstanceDao.load(tiOid); HarvesterStatusDTO harvesterStatusDto = (HarvesterStatusDTO) harvesterStatusMap.get(key); updateStatusWithEnvironment(harvesterStatusDto); HarvesterStatus harvesterStatus = createHarvesterStatus(ti, harvesterStatusDto); String harvesterStatusValue = harvesterStatus.getStatus(); if (harvesterStatusValue.startsWith("Paused")) { doHeartbeatPaused(ti); } if (harvesterStatusValue.startsWith("Running")) { doHeartbeatRunning(aStatus, ti, harvesterStatus); } if (harvesterStatusValue.startsWith("Finished")) { doHeartbeatFinished(ti); } if (harvesterStatusValue.startsWith("Could not launch job - Fatal InitializationException")) { doHeartbeatLaunchFailed(ti); } targetInstanceManager.save(ti); unLock(tiOid); log.debug("Released lock for ti " + tiOid); } } }
HarvestAgentManagerImpl implements HarvestAgentManager { @Override public void heartbeat(HarvestAgentStatusDTO aStatus) { if (harvestAgents.containsKey(aStatus.getName())) { log.debug("Updating status for {}", aStatus.getName()); } else { log.info("Registering harvest agent " + aStatus.getName()); } aStatus.setLastUpdated(new Date()); HarvestAgentStatusDTO currentStatus = harvestAgents.get(aStatus.getName()); if (currentStatus != null) { aStatus.setAcceptTasks(currentStatus.isAcceptTasks()); } harvestAgents.put(aStatus.getName(), aStatus); HashMap<String, HarvesterStatusDTO> harvesterStatusMap = aStatus.getHarvesterStatus(); for (String key : harvesterStatusMap.keySet()) { long tiOid = Long.parseLong(key.substring(key.lastIndexOf("-") + 1)); if (!lock(tiOid)) break; log.debug("Obtained lock for ti " + tiOid); TargetInstance ti = targetInstanceDao.load(tiOid); HarvesterStatusDTO harvesterStatusDto = (HarvesterStatusDTO) harvesterStatusMap.get(key); updateStatusWithEnvironment(harvesterStatusDto); HarvesterStatus harvesterStatus = createHarvesterStatus(ti, harvesterStatusDto); String harvesterStatusValue = harvesterStatus.getStatus(); if (harvesterStatusValue.startsWith("Paused")) { doHeartbeatPaused(ti); } if (harvesterStatusValue.startsWith("Running")) { doHeartbeatRunning(aStatus, ti, harvesterStatus); } if (harvesterStatusValue.startsWith("Finished")) { doHeartbeatFinished(ti); } if (harvesterStatusValue.startsWith("Could not launch job - Fatal InitializationException")) { doHeartbeatLaunchFailed(ti); } targetInstanceManager.save(ti); unLock(tiOid); log.debug("Released lock for ti " + tiOid); } }  }
HarvestAgentManagerImpl implements HarvestAgentManager { @Override public void heartbeat(HarvestAgentStatusDTO aStatus) { if (harvestAgents.containsKey(aStatus.getName())) { log.debug("Updating status for {}", aStatus.getName()); } else { log.info("Registering harvest agent " + aStatus.getName()); } aStatus.setLastUpdated(new Date()); HarvestAgentStatusDTO currentStatus = harvestAgents.get(aStatus.getName()); if (currentStatus != null) { aStatus.setAcceptTasks(currentStatus.isAcceptTasks()); } harvestAgents.put(aStatus.getName(), aStatus); HashMap<String, HarvesterStatusDTO> harvesterStatusMap = aStatus.getHarvesterStatus(); for (String key : harvesterStatusMap.keySet()) { long tiOid = Long.parseLong(key.substring(key.lastIndexOf("-") + 1)); if (!lock(tiOid)) break; log.debug("Obtained lock for ti " + tiOid); TargetInstance ti = targetInstanceDao.load(tiOid); HarvesterStatusDTO harvesterStatusDto = (HarvesterStatusDTO) harvesterStatusMap.get(key); updateStatusWithEnvironment(harvesterStatusDto); HarvesterStatus harvesterStatus = createHarvesterStatus(ti, harvesterStatusDto); String harvesterStatusValue = harvesterStatus.getStatus(); if (harvesterStatusValue.startsWith("Paused")) { doHeartbeatPaused(ti); } if (harvesterStatusValue.startsWith("Running")) { doHeartbeatRunning(aStatus, ti, harvesterStatus); } if (harvesterStatusValue.startsWith("Finished")) { doHeartbeatFinished(ti); } if (harvesterStatusValue.startsWith("Could not launch job - Fatal InitializationException")) { doHeartbeatLaunchFailed(ti); } targetInstanceManager.save(ti); unLock(tiOid); log.debug("Released lock for ti " + tiOid); } }  @Override void heartbeat(HarvestAgentStatusDTO aStatus); @Override void updateProfileOverrides(TargetInstance aTargetInstance, String profileString); @Override void pause(TargetInstance aTargetInstance); @Override void resume(TargetInstance aTargetInstance); @Override void abort(TargetInstance aTargetInstance); @Override void stop(TargetInstance aTargetInstance); @Override void pauseAll(); @Override void resumeAll(); @Override LogReader getLogReader(TargetInstance aTargetInstance); @Override void pauseAgent(String agentName); @Override void resumeAgent(String agentName); @Override boolean runningOrPaused(TargetInstance aTargetInstance); @Override void restrictBandwidthFor(TargetInstance targetInstance); @Override List<HarvestAgentStatusDTO> getHarvestersForAgency(String agencyName); @Override void markDead(HarvestAgentStatusDTO agent); @Override void initiateHarvest(HarvestAgentStatusDTO aHarvestAgent, TargetInstance aTargetInstance, String profile,
			String seedsString); @Override void recoverHarvests(String haHost, int haPort, String haService, List<String> activeJobs); @Override boolean lock(Long tiOid); @Override void unLock(Long tiOid); @Override HashMap<String, HarvestAgentStatusDTO> getHarvestAgents(); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); void setHarvestAgentFactory(HarvestAgentFactory harvestAgentFactory); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); @Override void purgeAbortedTargetInstances(String[] tiNames); @Override List<HarvestAgentStatusDTO> getAvailableHarvesters(String agencyName); @Override HarvestAgentStatusDTO getHarvester(String agencyName, String harvesterType); }
HarvestAgentManagerImpl implements HarvestAgentManager { @Override public void heartbeat(HarvestAgentStatusDTO aStatus) { if (harvestAgents.containsKey(aStatus.getName())) { log.debug("Updating status for {}", aStatus.getName()); } else { log.info("Registering harvest agent " + aStatus.getName()); } aStatus.setLastUpdated(new Date()); HarvestAgentStatusDTO currentStatus = harvestAgents.get(aStatus.getName()); if (currentStatus != null) { aStatus.setAcceptTasks(currentStatus.isAcceptTasks()); } harvestAgents.put(aStatus.getName(), aStatus); HashMap<String, HarvesterStatusDTO> harvesterStatusMap = aStatus.getHarvesterStatus(); for (String key : harvesterStatusMap.keySet()) { long tiOid = Long.parseLong(key.substring(key.lastIndexOf("-") + 1)); if (!lock(tiOid)) break; log.debug("Obtained lock for ti " + tiOid); TargetInstance ti = targetInstanceDao.load(tiOid); HarvesterStatusDTO harvesterStatusDto = (HarvesterStatusDTO) harvesterStatusMap.get(key); updateStatusWithEnvironment(harvesterStatusDto); HarvesterStatus harvesterStatus = createHarvesterStatus(ti, harvesterStatusDto); String harvesterStatusValue = harvesterStatus.getStatus(); if (harvesterStatusValue.startsWith("Paused")) { doHeartbeatPaused(ti); } if (harvesterStatusValue.startsWith("Running")) { doHeartbeatRunning(aStatus, ti, harvesterStatus); } if (harvesterStatusValue.startsWith("Finished")) { doHeartbeatFinished(ti); } if (harvesterStatusValue.startsWith("Could not launch job - Fatal InitializationException")) { doHeartbeatLaunchFailed(ti); } targetInstanceManager.save(ti); unLock(tiOid); log.debug("Released lock for ti " + tiOid); } }  @Override void heartbeat(HarvestAgentStatusDTO aStatus); @Override void updateProfileOverrides(TargetInstance aTargetInstance, String profileString); @Override void pause(TargetInstance aTargetInstance); @Override void resume(TargetInstance aTargetInstance); @Override void abort(TargetInstance aTargetInstance); @Override void stop(TargetInstance aTargetInstance); @Override void pauseAll(); @Override void resumeAll(); @Override LogReader getLogReader(TargetInstance aTargetInstance); @Override void pauseAgent(String agentName); @Override void resumeAgent(String agentName); @Override boolean runningOrPaused(TargetInstance aTargetInstance); @Override void restrictBandwidthFor(TargetInstance targetInstance); @Override List<HarvestAgentStatusDTO> getHarvestersForAgency(String agencyName); @Override void markDead(HarvestAgentStatusDTO agent); @Override void initiateHarvest(HarvestAgentStatusDTO aHarvestAgent, TargetInstance aTargetInstance, String profile,
			String seedsString); @Override void recoverHarvests(String haHost, int haPort, String haService, List<String> activeJobs); @Override boolean lock(Long tiOid); @Override void unLock(Long tiOid); @Override HashMap<String, HarvestAgentStatusDTO> getHarvestAgents(); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); void setHarvestAgentFactory(HarvestAgentFactory harvestAgentFactory); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); @Override void purgeAbortedTargetInstances(String[] tiNames); @Override List<HarvestAgentStatusDTO> getAvailableHarvesters(String agencyName); @Override HarvestAgentStatusDTO getHarvester(String agencyName, String harvesterType);  }