private ContainerStats getContainerStats(String containerLink) throws Throwable { ServiceStats serviceStats = getDocument(ServiceStats.class, containerLink + ServiceHost.SERVICE_URI_SUFFIX_STATS); assertNotNull(serviceStats); return ContainerStats.transform(serviceStats); }
private void verifyHealthSuccessAfterThreshold(int successThreshold, ContainerDescription containerDesc, ContainerState container) throws Throwable { final String containerLink = container.documentSelfLink; for (int i = 1; i <= successThreshold; i++) { // Do maintenance HealthChecker.getInstance().doHealthCheck(host, containerDesc.documentSelfLink); final int successCount = i; waitFor(() -> { ContainerStats containerStats = getContainerStats(containerLink); return containerStats.healthCheckSuccess != null && containerStats.healthCheckSuccess && containerStats.healthSuccessCount == successCount; }); } waitFor(() -> { ContainerState healthyContainer = getDocument(ContainerState.class, containerLink); return ContainerState.CONTAINER_RUNNING_STATUS.equals(healthyContainer.status) && PowerState.RUNNING == healthyContainer.powerState; }); }
@Test public void testHealthConfigIdempotentPost() throws Throwable { String id = UUID.randomUUID().toString(); ContainerDescription containerDesc = createContainerDescription(); containerDesc.documentSelfLink = ContainerDescriptionService.FACTORY_LINK + "/" + id; containerDesc = doPost(containerDesc, ContainerDescriptionService.FACTORY_LINK); ContainerDescription putConfig = createContainerDescription(); putConfig.documentSelfLink = ContainerDescriptionService.FACTORY_LINK + "/" + id; putConfig.healthConfig.urlPath = "/ping1"; doOperation(putConfig, UriUtils.buildUri(host, putConfig.documentSelfLink), false, Action.PUT); containerDesc = getDocument(ContainerDescription.class, containerDesc.documentSelfLink); assertEquals(putConfig.healthConfig.urlPath, containerDesc.healthConfig.urlPath); putConfig = createContainerDescription(); putConfig.documentSelfLink = ContainerDescriptionService.FACTORY_LINK + "/" + id; putConfig.healthConfig.urlPath = "/ping2"; containerDesc = doPost(putConfig, ContainerDescriptionService.FACTORY_LINK); containerDesc = getDocument(ContainerDescription.class, containerDesc.documentSelfLink); assertEquals(putConfig.healthConfig.urlPath, containerDesc.healthConfig.urlPath); delete(containerDesc.documentSelfLink); putConfig = createContainerDescription(); putConfig.documentSelfLink = ContainerDescriptionService.FACTORY_LINK + "/" + id; putConfig.healthConfig.urlPath = "/ping3"; containerDesc = doPost(putConfig, ContainerDescriptionService.FACTORY_LINK); containerDesc = getDocument(ContainerDescription.class, containerDesc.documentSelfLink); assertEquals(putConfig.healthConfig.urlPath, containerDesc.healthConfig.urlPath); }
ContainerState containerWithError = getDocument(ContainerState.class, container.documentSelfLink);
@Test public void testHealthConfigPatch() throws Throwable { ContainerDescription containerDesc = createContainerDescription(); containerDesc = doPost(containerDesc, ContainerDescriptionService.FACTORY_LINK); ContainerDescription patchConfig = new ContainerDescription(); patchConfig.healthConfig = new HealthConfig(); patchConfig.healthConfig.urlPath = "/ping"; patchConfig.healthConfig.protocol = RequestProtocol.TCP; doOperation(patchConfig, UriUtils.buildUri(host, containerDesc.documentSelfLink), false, Action.PATCH); ContainerDescription config = getDocument(ContainerDescription.class, containerDesc.documentSelfLink); assertEquals(patchConfig.healthConfig.urlPath, config.healthConfig.urlPath); }