public String apply(SlotStatus input) { return input.getLocation(); } };
@Override public ImmutableList<ServiceDescriptor> getServiceInventory(Iterable<SlotStatus> allSlotStatus) { ImmutableList.Builder<ServiceDescriptor> newDescriptors = ImmutableList.builder(); for (SlotStatus slotStatus : allSlotStatus) { // if the self reference is null, the slot is totally offline so skip for now if (slotStatus.getSelf() == null) { continue; } List<ServiceDescriptor> serviceDescriptors = getServiceInventory(slotStatus); if (serviceDescriptors == null) { continue; } for (ServiceDescriptor serviceDescriptor : serviceDescriptors) { newDescriptors.add(new ServiceDescriptor(null, slotStatus.getId().toString(), serviceDescriptor.getType(), serviceDescriptor.getPool(), slotStatus.getLocation(), slotStatus.getState() == SlotLifecycleState.RUNNING ? ServiceState.RUNNING : ServiceState.STOPPED, interpolateProperties(serviceDescriptor.getProperties(), slotStatus))); } } return newDescriptors.build(); }
@Test public void testGetAllSlotStatus() throws Exception { SlotStatus appleSlotStatus = agent.install(appleInstallation); SlotStatus bananaSlotStatus = agent.install(bananaInstallation); Request request = Request.Builder.prepareGet().setUri(urlFor("/v1/agent/slot")).build(); List<Map<String, Object>> response = client.execute(request, createJsonResponseHandler(listCodec, Status.OK.getStatusCode())); List<Map<String, Object>> expected = listCodec.fromJson(Resources.toString(Resources.getResource("slot-status-list.json"), UTF_8)); expected.get(0).put("id", appleSlotStatus.getId().toString()); expected.get(0).put("shortId", appleSlotStatus.getId().toString()); expected.get(0).put("version", appleSlotStatus.getVersion()); expected.get(0).put("self", urlFor(appleSlotStatus).toASCIIString()); expected.get(0).put("externalUri", urlFor(appleSlotStatus).toASCIIString()); expected.get(0).put("location", appleSlotStatus.getLocation()); expected.get(0).put("shortLocation", appleSlotStatus.getLocation()); expected.get(0).put("installPath", appleSlotStatus.getInstallPath()); expected.get(0).put("resources", ImmutableMap.<String, Integer>of("memory", 512)); expected.get(1).put("id", bananaSlotStatus.getId().toString()); expected.get(1).put("shortId", bananaSlotStatus.getId().toString()); expected.get(1).put("version", bananaSlotStatus.getVersion()); expected.get(1).put("self", urlFor(bananaSlotStatus).toASCIIString()); expected.get(1).put("externalUri", urlFor(bananaSlotStatus).toASCIIString()); expected.get(1).put("location", bananaSlotStatus.getLocation()); expected.get(1).put("shortLocation", bananaSlotStatus.getLocation()); expected.get(1).put("installPath", bananaSlotStatus.getInstallPath()); expected.get(1).put("resources", ImmutableMap.<String, Integer>of("cpu", 1)); assertEqualsNoOrder(response, expected); }
@Test public void testGetAllSlotStatus() throws Exception { SlotStatus appleSlotStatus = agent.install(appleInstallation); SlotStatus bananaSlotStatus = agent.install(bananaInstallation); Request request = Request.Builder.prepareGet().setUri(urlFor("/v1/agent/slot")).build(); List<Map<String, Object>> response = client.execute(request, createJsonResponseHandler(listCodec, Status.OK.getStatusCode())); List<Map<String, Object>> expected = listCodec.fromJson(Resources.toString(Resources.getResource("slot-status-list.json"), UTF_8)); expected.get(0).put("id", appleSlotStatus.getId().toString()); expected.get(0).put("shortId", appleSlotStatus.getId().toString()); expected.get(0).put("version", appleSlotStatus.getVersion()); expected.get(0).put("self", urlFor(appleSlotStatus).toASCIIString()); expected.get(0).put("externalUri", urlFor(appleSlotStatus).toASCIIString()); expected.get(0).put("location", appleSlotStatus.getLocation()); expected.get(0).put("shortLocation", appleSlotStatus.getLocation()); expected.get(0).put("installPath", appleSlotStatus.getInstallPath()); expected.get(0).put("resources", ImmutableMap.<String, Integer>of("memory", 512)); expected.get(1).put("id", bananaSlotStatus.getId().toString()); expected.get(1).put("shortId", bananaSlotStatus.getId().toString()); expected.get(1).put("version", bananaSlotStatus.getVersion()); expected.get(1).put("self", urlFor(bananaSlotStatus).toASCIIString()); expected.get(1).put("externalUri", urlFor(bananaSlotStatus).toASCIIString()); expected.get(1).put("location", bananaSlotStatus.getLocation()); expected.get(1).put("shortLocation", bananaSlotStatus.getLocation()); expected.get(1).put("installPath", bananaSlotStatus.getInstallPath()); expected.get(1).put("resources", ImmutableMap.<String, Integer>of("cpu", 1)); assertEqualsNoOrder(response, expected); }
@Test public void testGetSlotStatus() throws Exception { SlotStatus slotStatus = agent.install(appleInstallation); Request request = Request.Builder.prepareGet().setUri(urlFor("/v1/agent/slot", slotStatus.getId().toString())).build(); Map<String, Object> response = client.execute(request, createJsonResponseHandler(mapCodec, Status.OK.getStatusCode())); Map<String, Object> expected = mapCodec.fromJson(Resources.toString(Resources.getResource("slot-status.json"), UTF_8)); expected.put("id", slotStatus.getId().toString()); expected.put("shortId", slotStatus.getId().toString()); expected.put("self", urlFor(slotStatus).toASCIIString()); expected.put("externalUri", urlFor(slotStatus).toASCIIString()); expected.put("version", slotStatus.getVersion()); expected.put("location", slotStatus.getLocation()); expected.put("shortLocation", slotStatus.getLocation()); expected.put("installPath", slotStatus.getInstallPath()); // agent does not return instance id or expected status expected.remove("instanceId"); expected.remove("expectedBinary"); expected.remove("expectedConfig"); expected.remove("expectedStatus"); assertEquals(response, expected); }
@Test public void testGetSlotStatus() throws Exception { SlotStatus slotStatus = agent.install(appleInstallation); Request request = Request.Builder.prepareGet().setUri(urlFor("/v1/agent/slot", slotStatus.getId().toString())).build(); Map<String, Object> response = client.execute(request, createJsonResponseHandler(mapCodec, Status.OK.getStatusCode())); Map<String, Object> expected = mapCodec.fromJson(Resources.toString(Resources.getResource("slot-status.json"), UTF_8)); expected.put("id", slotStatus.getId().toString()); expected.put("shortId", slotStatus.getId().toString()); expected.put("self", urlFor(slotStatus).toASCIIString()); expected.put("externalUri", urlFor(slotStatus).toASCIIString()); expected.put("version", slotStatus.getVersion()); expected.put("location", slotStatus.getLocation()); expected.put("shortLocation", slotStatus.getLocation()); expected.put("installPath", slotStatus.getInstallPath()); // agent does not return instance id or expected status expected.remove("instanceId"); expected.remove("expectedBinary"); expected.remove("expectedConfig"); expected.remove("expectedStatus"); assertEquals(response, expected); }
@Test public void testTerminateSlot() throws Exception { SlotStatus slotStatus = agent.install(appleInstallation); Request request = Request.Builder.prepareDelete() .setUri(urlFor("/v1/agent/slot", slotStatus.getId().toString())) .build(); Map<String, Object> response = client.execute(request, createJsonResponseHandler(mapCodec, Status.OK.getStatusCode())); assertNull(agent.getSlot(slotStatus.getId())); Map<String, Object> expected = ImmutableMap.<String, Object>builder() .put("id", slotStatus.getId().toString()) .put("shortId", slotStatus.getId().toString()) .put("self", urlFor(slotStatus).toASCIIString()) .put("externalUri", urlFor(slotStatus).toASCIIString()) .put("location", slotStatus.getLocation()) .put("shortLocation", slotStatus.getLocation()) .put("status", TERMINATED.toString()) .put("version", VersionsUtil.createSlotVersion(slotStatus.getId(), TERMINATED, null)) .put("resources", ImmutableMap.<String, Integer>of()) .build(); assertEquals(response, expected); }
@Test public void testTerminateSlot() throws Exception { SlotStatus slotStatus = agent.install(appleInstallation); Request request = Request.Builder.prepareDelete() .setUri(urlFor("/v1/agent/slot", slotStatus.getId().toString())) .build(); Map<String, Object> response = client.execute(request, createJsonResponseHandler(mapCodec, Status.OK.getStatusCode())); assertNull(agent.getSlot(slotStatus.getId())); Map<String, Object> expected = ImmutableMap.<String, Object>builder() .put("id", slotStatus.getId().toString()) .put("shortId", slotStatus.getId().toString()) .put("self", urlFor(slotStatus).toASCIIString()) .put("externalUri", urlFor(slotStatus).toASCIIString()) .put("location", slotStatus.getLocation()) .put("shortLocation", slotStatus.getLocation()) .put("status", TERMINATED.toString()) .put("version", VersionsUtil.createSlotVersion(slotStatus.getId(), TERMINATED, null)) .put("resources", ImmutableMap.<String, Integer>of()) .build(); assertEquals(response, expected); }
@Test public void testStop() throws Exception { SlotStatus slotStatus = agent.install(appleInstallation); agent.getSlot(slotStatus.getId()).start(); Request request = Request.Builder.preparePut() .setUri(urlFor(slotStatus, "lifecycle")) .setBodyGenerator(createStaticBodyGenerator("stopped", UTF_8)) .build(); Map<String, Object> response = client.execute(request, createJsonResponseHandler(mapCodec, Status.OK.getStatusCode())); Map<String, Object> expected = ImmutableMap.<String, Object>builder() .put("id", slotStatus.getId().toString()) .put("shortId", slotStatus.getId().toString()) .put("binary", appleInstallation.getAssignment().getBinary()) .put("shortBinary", appleInstallation.getAssignment().getBinary()) .put("config", appleInstallation.getAssignment().getConfig()) .put("shortConfig", appleInstallation.getAssignment().getConfig()) .put("self", urlFor(slotStatus).toASCIIString()) .put("externalUri", urlFor(slotStatus).toASCIIString()) .put("location", slotStatus.getLocation()) .put("shortLocation", slotStatus.getLocation()) .put("status", STOPPED.toString()) .put("version", slotStatus.getVersion()) .put("installPath", slotStatus.getInstallPath()) .put("resources", ImmutableMap.<String, Integer>of("memory", 512)) .build(); assertEquals(response, expected); }
@Test public void testStart() throws Exception { SlotStatus slotStatus = agent.install(appleInstallation); Request request = Request.Builder.preparePut() .setUri(urlFor(slotStatus, "lifecycle")) .setBodyGenerator(createStaticBodyGenerator("running", UTF_8)) .build(); Map<String, Object> response = client.execute(request, createJsonResponseHandler(mapCodec, Status.OK.getStatusCode())); Map<String, Object> expected = ImmutableMap.<String, Object>builder() .put("id", slotStatus.getId().toString()) .put("shortId", slotStatus.getId().toString()) .put("binary", appleInstallation.getAssignment().getBinary()) .put("shortBinary", appleInstallation.getAssignment().getBinary()) .put("config", appleInstallation.getAssignment().getConfig()) .put("shortConfig", appleInstallation.getAssignment().getConfig()) .put("self", urlFor(slotStatus).toASCIIString()) .put("externalUri", urlFor(slotStatus).toASCIIString()) .put("location", slotStatus.getLocation()) .put("shortLocation", slotStatus.getLocation()) .put("status", RUNNING.toString()) .put("version", VersionsUtil.createSlotVersion(slotStatus.getId(), RUNNING, appleInstallation.getAssignment())) .put("installPath", slotStatus.getInstallPath()) .put("resources", ImmutableMap.<String, Integer>of("memory", 512)) .build(); assertEquals(response, expected); }
@Test public void testRestart() throws Exception { SlotStatus slotStatus = agent.install(appleInstallation); Request request = Request.Builder.preparePut() .setUri(urlFor(slotStatus, "lifecycle")) .setBodyGenerator(createStaticBodyGenerator("restarting", UTF_8)) .build(); Map<String, Object> response = client.execute(request, createJsonResponseHandler(mapCodec, Status.OK.getStatusCode())); Map<String, Object> expected = ImmutableMap.<String, Object>builder() .put("id", slotStatus.getId().toString()) .put("shortId", slotStatus.getId().toString()) .put("binary", appleInstallation.getAssignment().getBinary()) .put("shortBinary", appleInstallation.getAssignment().getBinary()) .put("config", appleInstallation.getAssignment().getConfig()) .put("shortConfig", appleInstallation.getAssignment().getConfig()) .put("self", urlFor(slotStatus).toASCIIString()) .put("externalUri", urlFor(slotStatus).toASCIIString()) .put("location", slotStatus.getLocation()) .put("shortLocation", slotStatus.getLocation()) .put("status", RUNNING.toString()) .put("version", VersionsUtil.createSlotVersion(slotStatus.getId(), RUNNING, appleInstallation.getAssignment())) .put("installPath", slotStatus.getInstallPath()) .put("resources", ImmutableMap.<String, Integer>of("memory", 512)) .build(); assertEquals(response, expected); }
@Test public void testAssign() throws Exception { SlotStatus slotStatus = agent.install(appleInstallation); String json = installationCodec.toJson(InstallationRepresentation.from(appleInstallation)); Request request = Request.Builder.preparePut() .setUri(urlFor(slotStatus, "assignment")) .setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON) .setBodyGenerator(createStaticBodyGenerator(json, UTF_8)) .build(); Map<String, Object> response = client.execute(request, createJsonResponseHandler(mapCodec, Status.OK.getStatusCode())); Map<String, Object> expected = ImmutableMap.<String, Object>builder() .put("id", slotStatus.getId().toString()) .put("shortId", slotStatus.getId().toString()) .put("binary", appleInstallation.getAssignment().getBinary()) .put("shortBinary", appleInstallation.getAssignment().getBinary()) .put("config", appleInstallation.getAssignment().getConfig()) .put("shortConfig", appleInstallation.getAssignment().getConfig()) .put("self", urlFor(slotStatus).toASCIIString()) .put("externalUri", urlFor(slotStatus).toASCIIString()) .put("location", slotStatus.getLocation()) .put("shortLocation", slotStatus.getLocation()) .put("status", STOPPED.toString()) .put("version", slotStatus.getVersion()) .put("installPath", slotStatus.getInstallPath()) .put("resources", ImmutableMap.<String, Integer>of("memory", 512)) .build(); assertEquals(response, expected); }
.put("self", urlFor(slot).toASCIIString()) .put("externalUri", urlFor(slot).toASCIIString()) .put("location", slot.status().getLocation()) .put("shortLocation", slot.status().getLocation()) .put("status", STOPPED.toString()) .put("version", slot.status().getVersion())
slotStatus.getExternalUri(), slotStatus.getInstanceId(), slotStatus.getLocation(), slotStatus.getLocation(), binary, shortBinary,
@Test public void testTerminate() throws Exception { // setup assertEquals(slot.assign(APPLE_INSTALLATION).getAssignment(), APPLE_ASSIGNMENT); // test remoteAgent.setStatus(agent.getAgentStatus()); RemoteSlot remoteSlot = new HttpRemoteSlot(slot.status(), client, remoteAgent); SlotStatus actual = remoteSlot.terminate(); // verify SlotStatus expected = createSlotStatus(slot.getId(), slot.getSelf(), slot.getExternalUri(), slot.status().getInstanceId(), slot.status().getLocation(), TERMINATED, null, null, ImmutableMap.<String, Integer>of()); assertEquals(actual, expected); }
status.getExternalUri(), status.getInstanceId(), status.getLocation(), trimLeadingSegments(status.getLocation(), '/', commonLocationParts), binary, shortBinary,
slot.getExternalUri(), slot.getInstanceId(), slot.getLocation(), UNKNOWN, null,
slot.getExternalUri(), slot.getInstanceId(), slot.getLocation(), UNKNOWN, null,