TaskCommand extends BaseCommand { public String lookupAgentId(String hostIp) { checkNotNull(hostIp); final ImmutableMap.Builder<String, String> termsBuilder = new ImmutableMap.Builder<>(); termsBuilder.put(HostService.State.FIELD_NAME_HOST_ADDRESS, hostIp); List<String> result = xenonClient.queryDocumentsForLinks(HostService.State.class, termsBuilder.build()); checkState(result.size() == 1, "Expect one and only one host with Address {}, found {}", hostIp, result.size()); String agentId = ServiceUtils.getIDFromDocumentSelfLink(result.get(0)); checkNotNull(agentId); return agentId; } @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 public void testLookupAgentIdSuccess() { TestTaskCommand command = new TestTaskCommand(apiFeXenonRestClient, photonControllerXenonRestClient, hostClient, housekeeperClient, taskBackend, stepCommandFactory, task, deployerClient, deployerXenonClient, housekeeperXenonClient); String agentId = command.lookupAgentId("host-ip"); assertEquals(this.agentId, agentId); }
@Test public void testLookupAgentIdNotFound() { TestTaskCommand command = new TestTaskCommand(apiFeXenonRestClient, photonControllerXenonRestClient, hostClient, housekeeperClient, taskBackend, stepCommandFactory, task, deployerClient, deployerXenonClient, housekeeperXenonClient); try { command.lookupAgentId("unknown-ip"); fail(); } catch (IllegalStateException ex) { } }