TaskCommand extends BaseCommand { public HostClient findHost(BaseDiskEntity disk) throws RpcException, InterruptedException, DiskNotFoundException { checkNotNull(hostClient); if (disk.getAgent() != null) { try { String hostIp = lookupHostIp(disk.getAgent()); if (StringUtils.isNotBlank(hostIp)) { hostClient.setHostIp(hostIp); return hostClient; } } catch (DocumentNotFoundException ex) { logger.error(String.format("Host %s does not exist.", disk.getAgent()), ex); } } throw new DiskNotFoundException(disk.getKind(), disk.getId()); } @Inject  TaskCommand(
      ApiFeXenonRestClient xenonClient,
      PhotonControllerXenonRestClient photonControllerXenonRestClient,
      HostClient hostClient,
      HousekeeperClient housekeeperClient,
      DeployerClient deployerClient,
      com.vmware.photon.controller.api.frontend.backends.clients.DeployerClient deployerXenonClient,
      com.vmware.photon.controller.api.frontend.backends.clients.HousekeeperClient housekeeperXenonClient,
      EntityLockBackend entityLockBackend,
      @Assisted TaskEntity task); void markAllStepsAsFailed(Throwable t); TaskEntity getTask(); Resource getResource(); void setResource(Resource resource); String getReservation(); void setReservation(String reservation); HostClient getHostClient(); ApiFeXenonRestClient getApiFeXenonRestClient(); PhotonControllerXenonRestClient getPhotonControllerXenonRestClient(); HousekeeperClient getHousekeeperClient(); com.vmware.photon.controller.api.frontend.backends.clients.HousekeeperClient getHousekeeperXenonClient(); DeployerClient getDeployerClient(); com.vmware.photon.controller.api.frontend.backends.clients.DeployerClient getDeployerXenonClient(); HostClient getHostClient(VmEntity vm); HostClient getHostClient(VmEntity vm, boolean useCachedHostInfo); HostClient findHost(BaseDiskEntity disk); String lookupAgentId(String hostIp);  }
@Test(dataProvider = "getDiskEntitiesParam") public void testFindDiskHostWithDiskNotFoundException(BaseDiskEntity disk) throws Exception { TestTaskCommand command = new TestTaskCommand(apiFeXenonRestClient, photonControllerXenonRestClient, hostClient, housekeeperClient, taskBackend, stepCommandFactory, task, deployerClient, deployerXenonClient, housekeeperXenonClient); disk.setId("disk-1"); try { command.findHost(disk); fail(); } catch (DiskNotFoundException ex) { } assertThat(disk.getAgent(), is(nullValue())); }
@Test(dataProvider = "getDiskEntitiesParam") public void testFindDiskHostWithAgentId(BaseDiskEntity disk) throws Exception { TestTaskCommand command = new TestTaskCommand(apiFeXenonRestClient, photonControllerXenonRestClient, hostClient, housekeeperClient, taskBackend, stepCommandFactory, task, deployerClient, deployerXenonClient, housekeeperXenonClient); disk.setId("disk-1"); disk.setAgent(agentId); command.findHost(disk); InOrder inOrder = inOrder(photonControllerXenonRestClient, hostClient); inOrder.verify(hostClient).setHostIp("host-ip"); verifyNoMoreInteractions(photonControllerXenonRestClient, hostClient); }