@Test public void testUpgrade() throws Exception { initializeOneAgent(); UpgradeVersions upgradeVersions = new UpgradeVersions("2.0", "2.0"); Request request = Request.Builder.preparePost() .setUri( coordinatorUriBuilder() .appendPath("/v1/slot/assignment") .addParameter("host", "apple*") .build()) .setHeader(CONTENT_TYPE, APPLICATION_JSON) .setBodyGenerator(jsonBodyGenerator(upgradeVersionsCodec, upgradeVersions)) .build(); List<SlotStatusRepresentation> actual = httpClient.execute( request, createJsonResponseHandler(slotStatusesCodec, Status.OK.getStatusCode())); AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId); SlotStatus apple1Status = agentStatus.getSlotStatus(apple1SotId); SlotStatus apple2Status = agentStatus.getSlotStatus(apple2SlotId); SlotStatus bananaStatus = agentStatus.getSlotStatus(bananaSlotId); List<SlotStatusRepresentation> expected = ImmutableList.of( slotStatusRepresentationFactory.create(apple1Status), slotStatusRepresentationFactory.create(apple2Status)); assertEqualsNoOrder(actual, expected); assertEquals(apple1Status.getState(), STOPPED); assertEquals(apple2Status.getState(), STOPPED); assertEquals(bananaStatus.getState(), STOPPED); assertEquals( apple1Status.getAssignment(), upgradeVersions.upgradeAssignment(MOCK_REPO, APPLE_ASSIGNMENT)); assertEquals( apple2Status.getAssignment(), upgradeVersions.upgradeAssignment(MOCK_REPO, APPLE_ASSIGNMENT)); assertEquals(bananaStatus.getAssignment(), BANANA_ASSIGNMENT); }
private List<ServiceDescriptor> getServiceInventory(SlotStatus slotStatus) { Assignment assignment = slotStatus.getAssignment(); if (assignment == null) { return null; } String config = assignment.getConfig(); File cacheFile = getCacheFile(config); if (cacheFile.canRead()) { try { String json = CharStreams.toString(Files.newReaderSupplier(cacheFile, Charsets.UTF_8)); List<ServiceDescriptor> descriptors = descriptorsJsonCodec.fromJson(json); invalidServiceInventory.remove(config); return descriptors; } catch (Exception ignored) { // delete the bad cache file cacheFile.delete(); } } InputSupplier<? extends InputStream> configFile = ConfigUtils.newConfigEntrySupplier(repository, config, "airship-service-inventory.json"); if (configFile == null) { return null; } try { String json; try { json = CharStreams.toString(CharStreams.newReaderSupplier(configFile, Charsets.UTF_8)); } catch (FileNotFoundException e) { // no service inventory in the config, so replace with json null so caching works json = "null"; } invalidServiceInventory.remove(config); // cache json cacheFile.getParentFile().mkdirs(); Files.write(json, cacheFile, Charsets.UTF_8); List<ServiceDescriptor> descriptors = descriptorsJsonCodec.fromJson(json); return descriptors; } catch (Exception e) { if (invalidServiceInventory.add(config)) { log.error(e, "Unable to read service inventory for %s" + config); } } return null; }
private void assertOkResponse(Response response, SlotLifecycleState state, UUID... slotIds) { assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId); Builder<SlotStatusRepresentation> builder = ImmutableList.builder(); for (UUID slotId : slotIds) { SlotStatus slotStatus = agentStatus.getSlotStatus(slotId); builder.add( SlotStatusRepresentation.from(slotStatus.changeState(state), prefixSize, MOCK_REPO)); assertEquals(slotStatus.getAssignment(), APPLE_ASSIGNMENT); } assertEqualsNoOrder((Collection<?>) response.getEntity(), builder.build()); assertNull( response .getMetadata() .get("Content-Type")); // content type is set by jersey based on @Produces }