@Test public void createApplicationFromApplicationSummary () { ApplicationSummary applicationSummary; CloudFoundryApplication container; String applicationId = randomUUID().toString(); Integer containerInstances = new Random().nextInt(5) + 1; String name = randomUUID().toString(); Integer diskQuota = new Random().nextInt(); Integer memoryLimit = new Random().nextInt(); String requestedState = randomUUID().toString(); applicationSummary = ApplicationSummary.builder() .instances(containerInstances) .name(name) .id(applicationId) .diskQuota(diskQuota) .memoryLimit(memoryLimit) .requestedState(requestedState) .runningInstances(containerInstances) .build(); doReturn(Collections.emptyList()).when(cloudFoundryApplicationPlatform).gatherApplicationRoutes(any(), any()); container = CloudFoundryApplication.builder() .applicationID(applicationId) .containerInstances(containerInstances) .name(name) .applicationRoutes(Collections.emptyList()) .build(); CloudFoundryApplication actualContainer = cloudFoundryApplicationPlatform.createApplicationFromApplicationSummary(applicationSummary); assertEquals(container, actualContainer); verify(containerManager, times(1)).offer(actualContainer); reset(containerManager); assertSame(actualContainer, cloudFoundryApplicationPlatform.createApplicationFromApplicationSummary(applicationSummary)); verify(containerManager, times(0)).offer(actualContainer); }
CloudFoundryApplication createApplicationFromApplicationSummary (ApplicationSummary applicationSummary) { CloudFoundryApplication container = containerManager.getMatchingContainer(CloudFoundryApplication.class, applicationSummary .getName()); if (container == null) { container = CloudFoundryApplication.builder() .platform(this) .name(applicationSummary.getName()) .applicationID(applicationSummary.getId()) .containerInstances(applicationSummary.getInstances()) .applicationRoutes(gatherApplicationRoutes(applicationSummary.getName(), applicationSummary .getId())) .build(); log.debug("Created Cloud Foundry Application Container {} from {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container), kv("ApplicationSummary", applicationSummary)); containerManager.offer(container); } else { log.debug("Found existing Cloud Foundry Application Container {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); } return container; }
CloudFoundryApplicationPlatform extends CloudFoundryPlatform { CloudFoundryApplication createApplicationFromApplicationSummary (ApplicationSummary applicationSummary) { CloudFoundryApplication container = containerManager.getMatchingContainer(CloudFoundryApplication.class, applicationSummary .getName()); if (container == null) { container = CloudFoundryApplication.builder() .platform(this) .name(applicationSummary.getName()) .applicationID(applicationSummary.getId()) .containerInstances(applicationSummary.getInstances()) .applicationRoutes(gatherApplicationRoutes(applicationSummary.getName(), applicationSummary .getId())) .build(); log.debug("Created Cloud Foundry Application Container {} from {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container), kv("ApplicationSummary", applicationSummary)); containerManager.offer(container); } else { log.debug("Found existing Cloud Foundry Application Container {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); } return container; } }
CloudFoundryApplicationPlatform extends CloudFoundryPlatform { CloudFoundryApplication createApplicationFromApplicationSummary (ApplicationSummary applicationSummary) { CloudFoundryApplication container = containerManager.getMatchingContainer(CloudFoundryApplication.class, applicationSummary .getName()); if (container == null) { container = CloudFoundryApplication.builder() .platform(this) .name(applicationSummary.getName()) .applicationID(applicationSummary.getId()) .containerInstances(applicationSummary.getInstances()) .applicationRoutes(gatherApplicationRoutes(applicationSummary.getName(), applicationSummary .getId())) .build(); log.debug("Created Cloud Foundry Application Container {} from {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container), kv("ApplicationSummary", applicationSummary)); containerManager.offer(container); } else { log.debug("Found existing Cloud Foundry Application Container {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); } return container; } @Autowired  CloudFoundryApplicationPlatform(); }
CloudFoundryApplicationPlatform extends CloudFoundryPlatform { CloudFoundryApplication createApplicationFromApplicationSummary (ApplicationSummary applicationSummary) { CloudFoundryApplication container = containerManager.getMatchingContainer(CloudFoundryApplication.class, applicationSummary .getName()); if (container == null) { container = CloudFoundryApplication.builder() .platform(this) .name(applicationSummary.getName()) .applicationID(applicationSummary.getId()) .containerInstances(applicationSummary.getInstances()) .applicationRoutes(gatherApplicationRoutes(applicationSummary.getName(), applicationSummary .getId())) .build(); log.debug("Created Cloud Foundry Application Container {} from {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container), kv("ApplicationSummary", applicationSummary)); containerManager.offer(container); } else { log.debug("Found existing Cloud Foundry Application Container {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); } return container; } @Autowired  CloudFoundryApplicationPlatform(); ContainerHealth checkPlatformHealth(); @Override List<Container> generateRoster(); @Override boolean isContainerRecycled(Container container); void rescaleApplication(String applicationName, int instances); void restartApplication(String applicationName); void unmapRoute(UnmapRouteRequest unmapRouteRequest); void mapRoute(MapRouteRequest mapRouteRequest); }
CloudFoundryApplicationPlatform extends CloudFoundryPlatform { CloudFoundryApplication createApplicationFromApplicationSummary (ApplicationSummary applicationSummary) { CloudFoundryApplication container = containerManager.getMatchingContainer(CloudFoundryApplication.class, applicationSummary .getName()); if (container == null) { container = CloudFoundryApplication.builder() .platform(this) .name(applicationSummary.getName()) .applicationID(applicationSummary.getId()) .containerInstances(applicationSummary.getInstances()) .applicationRoutes(gatherApplicationRoutes(applicationSummary.getName(), applicationSummary .getId())) .build(); log.debug("Created Cloud Foundry Application Container {} from {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container), kv("ApplicationSummary", applicationSummary)); containerManager.offer(container); } else { log.debug("Found existing Cloud Foundry Application Container {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); } return container; } @Autowired  CloudFoundryApplicationPlatform(); ContainerHealth checkPlatformHealth(); @Override List<Container> generateRoster(); @Override boolean isContainerRecycled(Container container); void rescaleApplication(String applicationName, int instances); void restartApplication(String applicationName); void unmapRoute(UnmapRouteRequest unmapRouteRequest); void mapRoute(MapRouteRequest mapRouteRequest);  }