private ContainerHostSpec createHostSpec(AddClusterRequest clusterRequest, String credentialsLink) { ComputeState kubernetesHost = new ComputeState(); kubernetesHost.address = clusterRequest.getExternalAddress(); kubernetesHost.tenantLinks = clusterRequest.tenantLinks;
waitForServiceAvailability(ContainerFactoryService.SELF_LINK); ComputeState hostState = new ComputeState(); hostState.address = host.getPreferredAddress(); hostState.descriptionLink = UriUtils.buildUriPath(ComputeService.FACTORY_LINK,
ComputeState dockerHost = createDockerHost(createDockerHostDescription(), resourcePool); ComputeState computeState = new ComputeState(); computeState.powerState = PowerState.SUSPEND;
String hostId = UUID.randomUUID().toString(); ComputeState cs = new ComputeState(); cs.id = hostId;
new AuthCredentialsServiceState(), AuthCredentialsService.FACTORY_LINK); ComputeState compute = new ComputeState(); compute.customProperties = new HashMap<>(); compute.customProperties.put(ComputeConstants.HOST_AUTH_CREDENTIALS_PROP_NAME,
private void createComputeState(ResourceAllocationTaskState currentState, String parentLink, String computeResourceId, String name, List<String> diskLinks, List<String> networkLinks, ComputeDescription cd) { ComputeService.ComputeState computeState = new ComputeService.ComputeState(); computeState.id = computeResourceId; computeState.name = name;
@Test public void testHostPermanentlyNotAvailable() throws Throwable { ComputeState state = new ComputeState(); state.powerState = PowerState.SUSPEND; Map<String, String> properties = new HashMap<>();
@Test public void testContainerShouldNotBeDeployedWhenHostIsSuspended() throws Throwable { // Create a docker hosts ResourcePoolState resourcePool = createResourcePool(); ComputeState dockerHost = createDockerHost(createDockerHostDescription(), resourcePool); ComputeState computeState = new ComputeState(); computeState.powerState = PowerState.SUSPEND; // Disable the hosts doOperation(computeState, UriUtils.buildUri(host, dockerHost.documentSelfLink), false, Action.PATCH); // Try to deploy a container ContainerDescription containerDescription = createContainerDescription(); GroupResourcePlacementState groupPlacementState = createGroupResourcePlacement( resourcePool); RequestBrokerState request = new RequestBrokerState(); request.resourceType = ResourceType.CONTAINER_TYPE.getName(); request.resourceDescriptionLink = containerDescription.documentSelfLink; request.tenantLinks = groupPlacementState.tenantLinks; request = startRequest(request); request = waitForRequestToFail(request); assertTrue(request.taskInfo.failure.message.startsWith( "No powered-on container hosts found")); // check the custom property from container description assertNotNull(request.customProperties); String containerDescProp = request.customProperties.get("propKey string"); assertNotNull(containerDescProp); assertEquals("customPropertyValue string", containerDescProp); }
@Test public void testGetShellInvalidAgentPortShouldFail() throws Throwable { waitForServiceAvailability(ContainerShellService.SELF_LINK); waitForServiceAvailability(ComputeService.FACTORY_LINK); waitForServiceAvailability(ContainerDescriptionService.FACTORY_LINK); waitForServiceAvailability(CompositeDescriptionFactoryService.SELF_LINK); waitForServiceAvailability(ContainerFactoryService.SELF_LINK); ComputeState hostState = new ComputeState(); hostState.address = host.getPreferredAddress(); hostState.descriptionLink = UriUtils.buildUriPath(ComputeService.FACTORY_LINK, "test-host"); hostState = doPost(hostState, ComputeService.FACTORY_LINK); ContainerState containerState = new ContainerState(); containerState.image = "test-image"; containerState.parentLink = hostState.documentSelfLink; containerState = doPost(containerState, ContainerFactoryService.SELF_LINK); ContainerState agentState = new ContainerState(); agentState.image = "test-agent"; agentState.documentSelfLink = ContainerFactoryService.SELF_LINK + "/admiral_agent__" + UriUtils.getLastPathSegment(hostState.documentSelfLink); agentState.parentLink = hostState.documentSelfLink; agentState = doPost(agentState, ContainerFactoryService.SELF_LINK); try { getDocument(String.class, ContainerShellService.SELF_LINK + "?id=" + UriUtils.getLastPathSegment(containerState.documentSelfLink)); fail("It should have failed!"); } catch (LocalizableValidationException e) { assertEquals("Could not locate shell port", e.getMessage()); } }
@Test public void testHostNotAvailable() throws Throwable { ComputeState state = new ComputeState(); state.powerState = PowerState.ON; doOperation(state, UriUtils.buildUri(host, dockerHostState.documentSelfLink), false, Action.PATCH); waitFor(() -> { dockerHostState = retrieveDockerHostState(); return PowerState.ON == dockerHostState.powerState; }); MockDockerHostService service = new MockDockerHostService(); service.setSelfLink( MockDockerPathConstants.BASE_VERSIONED_PATH + MockDockerPathConstants.INFO); mockDockerHost.stopService(service); ContainerHostDataCollectionState dataCollectionState = new ContainerHostDataCollectionState(); dataCollectionState.computeContainerHostLinks = new ArrayList<>(); dataCollectionState.computeContainerHostLinks .add(retrieveDockerHostState().documentSelfLink); doOperation(dataCollectionState, UriUtils.buildUri(host, ContainerHostDataCollectionService.HOST_INFO_DATA_COLLECTION_LINK), false, Service.Action.PATCH); waitFor(() -> { dockerHostState = retrieveDockerHostState(); return PowerState.SUSPEND == dockerHostState.powerState; }); }
ComputeState cs = new ComputeState(); cs.id = UUID.randomUUID().toString(); cs.address = address;
protected ComputeState createKubernetesHostComputeState(String testKubernetesCredentialsLink) throws Throwable { ComputeDescription computeDescription = new ComputeDescription(); computeDescription.customProperties = new HashMap<>(); computeDescription.id = UUID.randomUUID().toString(); waitForServiceAvailability(ComputeDescriptionService.FACTORY_LINK); String computeDescriptionLink = doPost(computeDescription, ComputeDescriptionService.FACTORY_LINK).documentSelfLink; ComputeState computeState = new ComputeState(); computeState.id = "testParentComputeState"; computeState.descriptionLink = computeDescriptionLink; computeState.customProperties = new HashMap<>(); computeState.customProperties.put( ComputeConstants.HOST_AUTH_CREDENTIALS_PROP_NAME, testKubernetesCredentialsLink); computeState.customProperties.put( ContainerHostService.HOST_DOCKER_ADAPTER_TYPE_PROP_NAME, ContainerHostService.DockerAdapterType.API.name()); computeState.customProperties.put( ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.KUBERNETES.name()); computeState.customProperties.put( KubernetesHostConstants.KUBERNETES_HOST_NAMESPACE_PROP_NAME, KubernetesHostConstants.KUBERNETES_HOST_DEFAULT_NAMESPACE); computeState.address = kubernetesUri.toString(); waitForServiceAvailability(ComputeService.FACTORY_LINK); ComputeState kubernetesHostState = doPost(computeState, ComputeService.FACTORY_LINK); return kubernetesHostState; }
@Test public void testHealthCheckSuccessWithHttpAndPortBindings() throws Throwable { ComputeState containerHost = new ComputeState(); containerHost.address = host.getPreferredAddress(); containerHost.descriptionLink = UriUtils.buildUriPath(ComputeService.FACTORY_LINK, "mockId"); containerHost = doPost(containerHost, ComputeService.FACTORY_LINK); // Create health config and a container to check the health for String mockContainerDescriptionLink = UriUtils.buildUriPath( ContainerDescriptionService.FACTORY_LINK, "mockDescId"); ContainerDescription containerDesc = createContainerDescription(); containerDesc.documentSelfLink = mockContainerDescriptionLink; containerDesc.healthConfig.port = 85; containerDesc = doPost(containerDesc, ContainerDescriptionService.FACTORY_LINK); ContainerState container = createContainerStateNoAddress(mockContainerDescriptionLink); container.parentLink = containerHost.documentSelfLink; PortBinding portBinding = new PortBinding(); portBinding.containerPort = "85"; portBinding.hostPort = String.valueOf(host.getPort()); container.ports = Arrays.asList(portBinding); container = doPost(container, ContainerFactoryService.SELF_LINK); // 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(containerDesc.healthConfig.healthyThreshold, containerDesc, container); }
public static ComputeStateWithDescription create( ComputeDescription desc, ComputeState currentState) { ComputeStateWithDescription chsWithDesc = new ComputeStateWithDescription(); currentState.copyTo(chsWithDesc); chsWithDesc.address = currentState.address; chsWithDesc.diskLinks = currentState.diskLinks; chsWithDesc.parentLink = currentState.parentLink; chsWithDesc.powerState = currentState.powerState; chsWithDesc.primaryMAC = currentState.primaryMAC; chsWithDesc.type = currentState.type; chsWithDesc.environmentName = currentState.environmentName; chsWithDesc.resourcePoolLink = currentState.resourcePoolLink; chsWithDesc.adapterManagementReference = currentState.adapterManagementReference; chsWithDesc.networkInterfaceLinks = currentState.networkInterfaceLinks; chsWithDesc.description = desc; chsWithDesc.descriptionLink = desc.documentSelfLink; chsWithDesc.regionId = currentState.regionId; chsWithDesc.zoneId = currentState.zoneId; chsWithDesc.hostName = currentState.hostName; chsWithDesc.instanceType = currentState.instanceType; chsWithDesc.cpuCount = currentState.cpuCount; chsWithDesc.cpuMhzPerCore = currentState.cpuMhzPerCore; chsWithDesc.gpuCount = currentState.gpuCount; chsWithDesc.totalMemoryBytes = currentState.totalMemoryBytes; chsWithDesc.endpointLink = currentState.endpointLink; return chsWithDesc; } }
protected void createParentComputeState() throws Throwable { waitForServiceAvailability(ComputeService.FACTORY_LINK); ComputeDescription computeDescription = new ComputeDescription(); computeDescription.customProperties = new HashMap<>(); computeDescription.id = UUID.randomUUID().toString(); String computeDescriptionLink = doPost(computeDescription, ComputeDescriptionService.FACTORY_LINK).documentSelfLink; ComputeState computeState = new ComputeState(); computeState.id = "testParentComputeState"; computeState.descriptionLink = computeDescriptionLink; computeState.customProperties = new HashMap<>(); computeState.customProperties.put( ComputeConstants.HOST_AUTH_CREDENTIALS_PROP_NAME, testDockerCredentialsLink); computeState.address = dockerUri.getHost(); computeState.customProperties.put( ContainerHostService.DOCKER_HOST_SCHEME_PROP_NAME, String.valueOf(dockerUri.getScheme())); computeState.customProperties.put( ContainerHostService.DOCKER_HOST_PORT_PROP_NAME, String.valueOf(dockerUri.getPort())); computeState.customProperties.put( ContainerHostService.DOCKER_HOST_PATH_PROP_NAME, String.valueOf(dockerUri.getPath())); computeState.customProperties.put( ContainerHostService.HOST_DOCKER_ADAPTER_TYPE_PROP_NAME, ContainerHostService.DockerAdapterType.API.name()); computeState = doPost(computeState, ComputeService.FACTORY_LINK); this.parentComputeStateLink = computeState.documentSelfLink; }
@Test public void testHostAvailableAfterFailure() throws Throwable { ComputeState state = new ComputeState(); state.powerState = PowerState.SUSPEND; Map<String, String> properties = new HashMap<>(); properties.put(ContainerHostService.RETRIES_COUNT_PROP_NAME, "1"); state.customProperties = properties; doOperation(state, UriUtils.buildUri(host, dockerHostState.documentSelfLink), false, Action.PATCH); waitFor(() -> { dockerHostState = retrieveDockerHostState(); return PowerState.SUSPEND == dockerHostState.powerState; }); ContainerHostDataCollectionState dataCollectionState = new ContainerHostDataCollectionState(); dataCollectionState.computeContainerHostLinks = new ArrayList<>(); dataCollectionState.computeContainerHostLinks .add(retrieveDockerHostState().documentSelfLink); doOperation(dataCollectionState, UriUtils.buildUri(host, ContainerHostDataCollectionService.HOST_INFO_DATA_COLLECTION_LINK), false, Service.Action.PATCH); waitFor(() -> { dockerHostState = retrieveDockerHostState(); return PowerState.ON == dockerHostState.powerState; }); }
private ComputeState createContainerHost(DeploymentPolicy policy, String resourcePoolLink) throws Throwable { ComputeDescription computeDesc = new ComputeDescription(); computeDesc.supportedChildren = new ArrayList<>( Arrays.asList(ComputeType.DOCKER_CONTAINER.toString())); computeDesc.instanceAdapterReference = UriUtils.buildUri(ServiceHost.LOCAL_HOST, 8484, "compute-test-adapter", null); computeDesc.authCredentialsLink = UriUtils.buildUriPath( AuthCredentialsService.FACTORY_LINK, CommonTestStateFactory.AUTH_CREDENTIALS_ID); computeDesc = doPost(computeDesc, ComputeDescriptionService.FACTORY_LINK); addForDeletion(computeDesc); ComputeState cs = new ComputeState(); Random r = new Random(); cs.address = r.nextInt(256) + "." + r.nextInt(256) + "." + r.nextInt(256) + "." + r.nextInt(256); cs.descriptionLink = computeDesc.documentSelfLink; cs.powerState = PowerState.ON; cs.resourcePoolLink = resourcePoolLink; cs.adapterManagementReference = URI.create("http://localhost:8081"); cs.customProperties = new HashMap<>(); if (policy != null) { cs.customProperties.put(ContainerHostService.CUSTOM_PROPERTY_DEPLOYMENT_POLICY, policy.documentSelfLink); } cs = doPost(cs, ComputeService.FACTORY_LINK); addForDeletion(cs); return cs; }
protected void createParentComputeState() throws Throwable { waitForServiceAvailability(ComputeService.FACTORY_LINK); ComputeDescription computeDescription = new ComputeDescription(); computeDescription.customProperties = new HashMap<String, String>(); computeDescription.id = UUID.randomUUID().toString(); String computeDescriptionLink = doPost(computeDescription, ComputeDescriptionService.FACTORY_LINK).documentSelfLink; ComputeState computeState = new ComputeState(); computeState.id = "testParentComputeState"; computeState.descriptionLink = computeDescriptionLink; computeState.customProperties = new HashMap<String, String>(); computeState.customProperties.put(ComputeConstants.HOST_AUTH_CREDENTIALS_PROP_NAME, testDockerCredentialsLink); computeState.address = dockerUri.getHost(); computeState.customProperties.put(ContainerHostService.DOCKER_HOST_SCHEME_PROP_NAME, String.valueOf(dockerUri.getScheme())); computeState.customProperties.put(ContainerHostService.DOCKER_HOST_PORT_PROP_NAME, String.valueOf(dockerUri.getPort())); computeState.customProperties.put(ContainerHostService.DOCKER_HOST_PATH_PROP_NAME, String.valueOf(dockerUri.getPath())); computeState.customProperties.put(ContainerHostService.HOST_DOCKER_ADAPTER_TYPE_PROP_NAME, ContainerHostService.DockerAdapterType.API.name()); computeState = doPost(computeState, ComputeService.FACTORY_LINK); this.parentComputeStateLink = computeState.documentSelfLink; }
private ComputeState createContainerHost(String descriptionLink, String rpLink, Long totalMemoryBytes, Long availableMemoryBytes, Long cpuCores, Double cpuUsage) throws Throwable { ComputeState cs = new ComputeState(); cs.descriptionLink = descriptionLink; cs.resourcePoolLink = rpLink; cs.customProperties = new HashMap<>(); if (totalMemoryBytes != null) { cs.customProperties.put(ContainerHostService.DOCKER_HOST_TOTAL_MEMORY_PROP_NAME, totalMemoryBytes.toString()); } if (availableMemoryBytes != null) { cs.customProperties.put(ContainerHostService.DOCKER_HOST_AVAILABLE_MEMORY_PROP_NAME, availableMemoryBytes.toString()); } if (cpuCores != null) { cs.customProperties.put(ContainerHostService.DOCKER_HOST_NUM_CORES_PROP_NAME, cpuCores.toString()); } if (cpuUsage != null) { cs.customProperties.put(ContainerHostService.DOCKER_HOST_CPU_USAGE_PCT_PROP_NAME, cpuUsage.toString()); } return doPost(cs, ComputeService.FACTORY_LINK); }
@Test public void testHealthCheckSuccessWithTcpAndPortBindings() throws Throwable { ComputeState containerHost = new ComputeState(); containerHost.address = host.getPreferredAddress(); containerHost.descriptionLink = UriUtils.buildUriPath(ComputeService.FACTORY_LINK, "mockId"); containerHost = doPost(containerHost, ComputeService.FACTORY_LINK); // Create health config and a container to check the health for String mockContainerDescriptionLink = UriUtils.buildUriPath( ContainerDescriptionService.FACTORY_LINK, "mockDescId"); ContainerDescription containerDesc = createContainerDescription(); containerDesc.documentSelfLink = mockContainerDescriptionLink; containerDesc.healthConfig.protocol = RequestProtocol.TCP; containerDesc.healthConfig.port = 8085; containerDesc = doPost(containerDesc, ContainerDescriptionService.FACTORY_LINK); ContainerState container = createContainerStateNoAddress(mockContainerDescriptionLink); container.parentLink = containerHost.documentSelfLink; PortBinding portBinding = new PortBinding(); portBinding.containerPort = "8085"; portBinding.hostPort = "8085"; container.ports = Arrays.asList(portBinding); container = doPost(container, ContainerFactoryService.SELF_LINK); try (ServerSocket socket = new ServerSocket(containerDesc.healthConfig.port)) { verifyHealthSuccessAfterThreshold(containerDesc.healthConfig.healthyThreshold, containerDesc, container); } }