public static HealthConfig fromPodContainerProbeToContainerDescriptionHealthConfig(Container podContainer) { if (podContainer.livenessProbe == null) { return null; } Probe probe = podContainer.livenessProbe; HealthConfig healthConfig = new HealthConfig(); if (probe.exec != null) { healthConfig.protocol = RequestProtocol.COMMAND; healthConfig.command = String.join(" ", probe.exec.command); } else if (probe.httpGet != null) { healthConfig.protocol = RequestProtocol.HTTP; healthConfig.httpVersion = HttpVersion.HTTP_v1_1; healthConfig.httpMethod = Action.GET; healthConfig.urlPath = probe.httpGet.path; healthConfig.port = fromPodContainerProbePortToHealthCheckPort(podContainer); healthConfig.timeoutMillis = (int) TimeUnit.SECONDS.toMillis(probe.timeoutSeconds); healthConfig.healthyThreshold = probe.successThreshold; healthConfig.unhealthyThreshold = probe.failureThreshold; } else if (probe.tcpSocket != null) { healthConfig.protocol = RequestProtocol.TCP; healthConfig.port = fromPodContainerProbePortToHealthCheckPort(podContainer); healthConfig.timeoutMillis = (int) TimeUnit.SECONDS.toMillis(probe.timeoutSeconds); healthConfig.healthyThreshold = probe.successThreshold; healthConfig.unhealthyThreshold = probe.failureThreshold; } else { healthConfig = null; } return healthConfig; }
template.customProperties.put("propKey string", "customPropertyValue string"); template.healthConfig = new HealthConfig(); template.healthConfig.port = 80; template.healthConfig.httpMethod = Action.GET;
ContainerDescription desc = TestRequestStateFactory.createContainerDescription("name1", true, true); desc.healthConfig = new HealthConfig(); desc.healthConfig.autoredeploy = true; desc.healthConfig.protocol = RequestProtocol.HTTP;
expectedProbe3.tcpSocket.port = "32000"; HealthConfig healthConfig1 = new HealthConfig(); healthConfig1.protocol = RequestProtocol.COMMAND; healthConfig1.command = "test command"; healthConfig1.healthyThreshold = 1; HealthConfig healthConfig2 = new HealthConfig(); healthConfig2.protocol = RequestProtocol.HTTP; healthConfig2.urlPath = "/test"; healthConfig2.port = 32000; HealthConfig healthConfig3 = new HealthConfig(); healthConfig3.protocol = RequestProtocol.TCP; healthConfig3.port = 32000;
containerDesc.documentSelfLink = UriUtils.buildUriPath( ContainerDescriptionService.FACTORY_LINK, "mockDescId"); containerDesc.healthConfig = new HealthConfig(); containerDesc.healthConfig.protocol = RequestProtocol.HTTP; containerDesc.healthConfig.httpMethod = Action.GET;
@Test public void testDeserializeSerializeSimpleCompositeTemplate() throws IOException { String expectedContent = getContent("composite.simple.yaml"); CompositeTemplate template = deserializeCompositeTemplate(expectedContent); assertNull(template.id); assertNull(template.status); assertComponentTypes(template.components); assertContainersComponents(ResourceType.CONTAINER_TYPE.getContentType(), 1, template.components); assertContainersComponents(ResourceType.NETWORK_TYPE.getContentType(), 0, template.components); assertContainersComponents(ResourceType.VOLUME_TYPE.getContentType(), 0, template.components); template.id = "new-id"; template.status = Status.RETIRED; ContainerDescription helloData = (ContainerDescription) template.components .get("hello").data; helloData.healthConfig = new HealthConfig(); helloData.logConfig = new LogConfig(); String content = serializeCompositeTemplate(template); assertNotNull(content); assertFalse(content.contains("new-id")); assertFalse(content.contains(Status.RETIRED.toString())); assertFalse(content.contains("health_config")); assertFalse(content.contains("log_config")); }
@Test public void testConvertPodContainerProbeToHealthConfigHTTP() { Container podContainer = new Container(); podContainer.livenessProbe = new Probe(); podContainer.livenessProbe.httpGet = new HTTPGetAction(); podContainer.livenessProbe.httpGet.port = "8080"; podContainer.livenessProbe.httpGet.path = "/health"; podContainer.livenessProbe.timeoutSeconds = 3; HealthConfig expectedHealthConfig = new HealthConfig(); expectedHealthConfig.protocol = RequestProtocol.HTTP; expectedHealthConfig.httpVersion = HttpVersion.HTTP_v1_1; expectedHealthConfig.httpMethod = Action.GET; expectedHealthConfig.urlPath = "/health"; expectedHealthConfig.port = 8080; expectedHealthConfig.timeoutMillis = 3000; HealthConfig actualHealthConfig = fromPodContainerProbeToContainerDescriptionHealthConfig( podContainer); assertNotNull(actualHealthConfig); assertEquals(actualHealthConfig.protocol, expectedHealthConfig.protocol); assertEquals(actualHealthConfig.port, expectedHealthConfig.port); assertEquals(actualHealthConfig.httpMethod, expectedHealthConfig.httpMethod); assertEquals(actualHealthConfig.httpVersion, expectedHealthConfig.httpVersion); assertEquals(actualHealthConfig.urlPath, expectedHealthConfig.urlPath); assertEquals(actualHealthConfig.timeoutMillis, expectedHealthConfig.timeoutMillis); }
@Test public void testHealthCheckWithHttpAndDefaultPortThresholds() throws Throwable { // Create health config and a container to check the health for ContainerDescription containerDesc = createContainerDescription(); containerDesc.documentSelfLink = UriUtils.buildUriPath( ContainerDescriptionService.FACTORY_LINK, "mockDescId"); containerDesc.healthConfig = new HealthConfig(); containerDesc.healthConfig.protocol = RequestProtocol.HTTP; containerDesc.healthConfig.httpMethod = Action.GET; containerDesc.healthConfig.urlPath = TestHealthService.SELF_LINK; containerDesc = doPost(containerDesc, ContainerDescriptionService.FACTORY_LINK); ContainerState container = createContainerStateNoAddress(containerDesc.documentSelfLink); container.powerState = PowerState.RUNNING; container = doPost(container, ContainerFactoryService.SELF_LINK); verifyHealthFailureAfterThreshold(3, containerDesc, container); // Start a test service to ping for health check TestHealthService pingService = new TestHealthService(); URI pingServiceUri = UriUtils.buildUri(host, TestHealthService.SELF_LINK); host.startService(Operation.createPost(pingServiceUri), pingService); waitForServiceAvailability(TestHealthService.SELF_LINK); verifyHealthSuccessAfterThreshold(3, containerDesc, container); }
@Test public void testConvertPodContainerProbeToHealthConfigTCP() { Container podContainer = new Container(); podContainer.livenessProbe = new Probe(); podContainer.livenessProbe.tcpSocket = new TCPSocketAction(); podContainer.livenessProbe.tcpSocket.port = "8080"; podContainer.livenessProbe.timeoutSeconds = 3; HealthConfig expectedHealthConfig = new HealthConfig(); expectedHealthConfig.protocol = RequestProtocol.TCP; expectedHealthConfig.port = 8080; expectedHealthConfig.timeoutMillis = 3000; HealthConfig actualHealthConfig = fromPodContainerProbeToContainerDescriptionHealthConfig( podContainer); assertNotNull(actualHealthConfig); assertEquals(actualHealthConfig.protocol, expectedHealthConfig.protocol); assertEquals(actualHealthConfig.port, expectedHealthConfig.port); assertEquals(actualHealthConfig.timeoutMillis, expectedHealthConfig.timeoutMillis); }
@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); }
private HealthConfig createDefaultHealthConfig() { HealthConfig defaultConfig = new HealthConfig(); defaultConfig.healthyThreshold = DEFAULT_HEALTHY_THRESHOLD; defaultConfig.unhealthyThreshold = DEFAULT_UNHEALTHY_THRESHOLD; return defaultConfig; }
protected HealthConfig createHealthConfigTcp(int port) { HealthConfig healthConfig = new HealthConfig(); healthConfig.protocol = RequestProtocol.TCP; healthConfig.port = port; healthConfig.healthyThreshold = 2; healthConfig.unhealthyThreshold = 2; healthConfig.timeoutMillis = 2000; return healthConfig; }
private HealthConfig createHealthConfig() { HealthConfig healthConfig = new HealthConfig(); healthConfig.protocol = RequestProtocol.HTTP; healthConfig.healthyThreshold = 2; healthConfig.unhealthyThreshold = 2; healthConfig.httpMethod = Action.GET; healthConfig.httpVersion = HttpVersion.HTTP_v1_1; healthConfig.urlPath = TestHealthService.SELF_LINK; healthConfig.timeoutMillis = 2000; return healthConfig; }
private HealthConfig createHealthConfig() { HealthConfig healthConfig = new HealthConfig(); healthConfig.protocol = RequestProtocol.HTTP; healthConfig.healthyThreshold = 2; healthConfig.unhealthyThreshold = 2; healthConfig.httpMethod = Action.GET; healthConfig.httpVersion = HttpVersion.HTTP_v1_1; healthConfig.timeoutMillis = 2000; return healthConfig; }