@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 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 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("status", STOPPED.toString()) .put("version", slot.status().getVersion()) .put("installPath", slot.status().getInstallPath()) .put("resources", ImmutableMap.<String, Integer>of("memory", 512)) .build();
UNKNOWN, null, slot.getInstallPath(), slot.getResources()); status = status.changeSlotStatus(slot);
UNKNOWN, null, slot.getInstallPath(), slot.getResources()); status = status.changeSlotStatus(slot);
slotStatus.getVersion(), slotStatus.getStatusMessage(), slotStatus.getInstallPath(), slotStatus.getResources(), expectedBinary,
status.getVersion(), status.getStatusMessage(), status.getInstallPath(), status.getResources(), expectedBinary,
@Test public void testRestart() throws Exception { initializeOneAgent(); appleSlot1.start(); coordinator.updateAllAgentsAndWait(); assertEquals(appleSlot1.status().getState(), RUNNING); File pidFile = newFile(appleSlot1.status().getInstallPath(), "..", "installation", "launcher.pid").getCanonicalFile(); String pidBeforeRestart = Files.readFirstLine(pidFile, Charsets.UTF_8); Request request = Request.Builder.preparePut() .setUri(coordinatorUriBuilder().appendPath("/v1/slot/lifecycle").addParameter("binary", "*:apple:*").build()) .setBodyGenerator(createStaticBodyGenerator("restarting", UTF_8)) .build(); List<SlotStatusRepresentation> actual = httpClient.execute(request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode())); List<SlotStatusRepresentation> expected = ImmutableList.of( slotStatusRepresentationFactory.create(appleSlot1.status().changeInstanceId(agentInstanceId)), slotStatusRepresentationFactory.create(appleSlot2.status().changeInstanceId(agentInstanceId))); assertEqualsNoOrder(actual, expected); assertEquals(appleSlot1.status().getState(), RUNNING); assertEquals(appleSlot2.status().getState(), RUNNING); assertEquals(bananaSlot.status().getState(), STOPPED); String pidAfterRestart = Files.readFirstLine(pidFile, Charsets.UTF_8); assertNotEquals(pidAfterRestart, pidBeforeRestart); }