kubernetesHost.customProperties = new HashMap<>(); kubernetesHost.customProperties.put(CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.KUBERNETES.name()); kubernetesHost.customProperties.put(HOST_DOCKER_ADAPTER_TYPE_PROP_NAME, ContainerHostService.DockerAdapterType.API.name());
private void getHostInfoResponse(AdapterRequest mockRequest, Consumer<Map<String, Object>> callback) { Map<String, Object> properties = new HashMap<>(); if (mockRequest.customProperties != null) { String hostType = mockRequest.customProperties.get(CONTAINER_HOST_TYPE_PROP_NAME); if (hostType != null && hostType.equals(ContainerHostType.VCH.toString())) { properties.put(DOCKER_INFO_STORAGE_DRIVER_PROP_NAME, VIC_STORAGE_DRIVER_PROP_VALUE); } } queryContainersByHost(mockRequest, (containerStates) -> { properties.put(ContainerHostService.NUMBER_OF_CONTAINERS_PER_HOST_PROP_NAME, containerStates.size()); callback.accept(properties); }); }
private void filterByNetworkMode(Map<String, HostSelection> hostSelectionMap) { Iterator<Entry<String, HostSelection>> it = hostSelectionMap.entrySet().iterator(); while (it.hasNext()) { Entry<String, HostSelection> entry = it.next(); if (entry.getValue() == null) { it.remove(); } else { HostSelection hs = entry.getValue(); if (hs.hostType != null && hs.hostType.equals(ContainerHostType.VCH) && networkMode != null && networkMode.matches("host|none")) { host.log(Level.WARNING, "Host [%s] dropped because the the network mode 'host' and 'none' " + "are not allowed on VCH host.'", hs.name); it.remove(); } } } }
map.put(ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME, hostType.name()); map.put(ComputeConstants.HOST_AUTH_CREDENTIALS_PROP_NAME, PropertyUtils.getPropertyString(hostSpec.hostState.customProperties,
cs.customProperties.put(ComputeConstants.COMPUTE_HOST_PROP_NAME, "true"); cs.customProperties.put(ComputeConstants.DOCKER_URI_PROP_NAME, hostSpec.uri.toString()); cs.customProperties.put(CONTAINER_HOST_TYPE_PROP_NAME, hostType.toString()); if (hostSpec.sslTrust != null) { cs.customProperties.put(ComputeConstants.HOST_TRUST_CERTS_PROP_NAME,
resourcePool.customProperties.put(CLUSTER_TYPE_CUSTOM_PROP, hostType.toString()); if (clusterDetails != null && !clusterDetails.isEmpty()) { resourcePool.customProperties.put(
String error = String.format( ContainerHostUtil.CONTAINER_HOST_TYPE_NOT_SUPPORTED_MESSAGE_FORMAT, hostType.toString()); op.fail(new LocalizableValidationException(error, ContainerHostUtil.CONTAINER_HOST_TYPE_NOT_SUPPORTED_MESSAGE_CODE, hostType));
@Test public void testRequestBrokerContainerHostRemovalWithKubernetesResources() throws Throwable { computeHost.customProperties.put(ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.KUBERNETES.name()); computeHost = doPatch(computeHost, computeHost.documentSelfLink); PodState podState = new PodState(); podState.parentLink = computeHost.documentSelfLink; podState = doPost(podState, PodFactoryService.SELF_LINK); ServiceState serviceState = new ServiceState(); serviceState.parentLink = computeHost.documentSelfLink; serviceState = doPost(serviceState, ServiceEntityFactoryHandler.SELF_LINK); RequestBrokerState request = new RequestBrokerState(); request.resourceType = ResourceType.CONTAINER_HOST_TYPE.getName(); request.resourceLinks = new HashSet<>(Collections.singletonList( computeHost.documentSelfLink)); request.operation = RequestBrokerState.REMOVE_RESOURCE_OPERATION; request = startRequest(request); waitForRequestToComplete(request); List<String> podStateLinks = findResourceLinks(PodState.class, Collections.singletonList(podState.documentSelfLink)); assertTrue("PodState links not removed: " + podStateLinks, podStateLinks.isEmpty()); List<String> serviceStateLinks = findResourceLinks(ServiceState.class, Collections.singletonList(serviceState.documentSelfLink)); assertTrue("ServiceState links not removed: " + serviceStateLinks, serviceStateLinks.isEmpty()); Collection<String> computeSelfLinks = findResourceLinks(ComputeState.class, Collections.singletonList(computeHost.documentSelfLink)); assertTrue("ComputeState was not deleted: " + computeSelfLinks, computeSelfLinks.isEmpty()); }
private ComputeState createComputeState(ContainerHostType hostType, ComputeService.PowerState hostState, List<String> tenantLinks, String clusterName, String clusterDetails ) throws Throwable { ComputeState cs = new ComputeState(); cs.id = UUID.randomUUID().toString(); cs.address = COMPUTE_ADDRESS; cs.powerState = hostState; cs.customProperties = new HashMap<>(); cs.customProperties.put(ContainerHostService.HOST_DOCKER_ADAPTER_TYPE_PROP_NAME, "API"); cs.customProperties.put(ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME, hostType.toString()); cs.customProperties.put(MockDockerHostAdapterService.CONTAINER_HOST_TYPE_PROP_NAME, hostType.toString()); cs.tenantLinks = new ArrayList<>(tenantLinks); if (clusterDetails != null && !clusterDetails.isEmpty()) { cs.customProperties.put( ClusterService.CLUSTER_DETAILS_CUSTOM_PROP, clusterDetails); } if (clusterName != null) { cs.customProperties.put( ClusterService.CLUSTER_NAME_CUSTOM_PROP, clusterName); } return cs; }
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; }
ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME)) .setTermMatchValue(ContainerHostType.DOCKER.toString()); q.querySpec.query.addBooleanClause(hostTypeClause); q.querySpec.resultLimit = ServiceDocumentQuery.DEFAULT_QUERY_RESULT_LIMIT;
private void validateHostTypeAndConnection(ContainerHostSpec hostSpec, Operation op) { ContainerHostType hostType; try { hostType = ContainerHostUtil.getDeclaredContainerHostType(hostSpec.hostState); } catch (LocalizableValidationException ex) { logWarning("Error getting host type: %s", ex.getMessage()); op.fail(ex); return; } // Apply the appropriate validation for each host type switch (hostType) { case DOCKER: validateConnection(hostSpec, op); break; case VCH: validateVicHost(hostSpec, op); break; case KUBERNETES: validateConnection(hostSpec, op); break; default: String error = String.format( ContainerHostUtil.CONTAINER_HOST_TYPE_NOT_SUPPORTED_MESSAGE_FORMAT, hostType.toString()); op.fail(new LocalizableValidationException(error, ContainerHostUtil.CONTAINER_HOST_TYPE_NOT_SUPPORTED_MESSAGE_CODE, hostType)); break; } }
private ComputeState createComputeState(ResourcePoolState placementZone, boolean isScheduler) throws Throwable { ComputeState computeState = new ComputeState(); computeState.address = "no-address"; computeState.descriptionLink = "no-description-link"; if (placementZone != null) { computeState.resourcePoolLink = placementZone.documentSelfLink; } else { computeState.resourcePoolLink = defaultPlacementZone.documentSelfLink; } computeState.customProperties = new HashMap<>(); computeState.customProperties.put(ComputeConstants.COMPUTE_CONTAINER_HOST_PROP_NAME, "true"); if (isScheduler) { computeState.customProperties.put(ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.VCH.toString()); } else { computeState.customProperties.put(ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.DOCKER.toString()); } return doPost(computeState, ComputeService.FACTORY_LINK); }
private ComputeState createCompute(String authCredentialsLink, boolean isKubernetesHost, boolean pksManaged) throws Throwable { ComputeState kubernetesHost = new ComputeState(); kubernetesHost.address = "hostname"; kubernetesHost.descriptionLink = "description"; kubernetesHost.customProperties = new HashMap<>(); kubernetesHost.customProperties.put(HOST_AUTH_CREDENTIALS_PROP_NAME, authCredentialsLink); if (isKubernetesHost) { kubernetesHost.customProperties.put(CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.KUBERNETES.name()); } else { kubernetesHost.customProperties.put(CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.DOCKER.name()); } if (pksManaged) { kubernetesHost.customProperties.put(PKS_ENDPOINT_PROP_NAME, "/endpoint/link"); } return doPost(kubernetesHost, ComputeService.FACTORY_LINK); } }
@Test public void testGetContainerHostTypesForResourceType() { List<ContainerHostType> allTypes = new ArrayList<>( Arrays.asList(ContainerHostType.values())); List<ContainerHostType> k8sTypes = ContainerHostUtil .getContainerHostTypesForResourceType(ResourceType.KUBERNETES_DEPLOYMENT_TYPE); assertEquals(Collections.singletonList(ContainerHostType.KUBERNETES), k8sTypes); k8sTypes = ContainerHostUtil .getContainerHostTypesForResourceType(ResourceType.KUBERNETES_POD_TYPE); assertEquals(Collections.singletonList(ContainerHostType.KUBERNETES), k8sTypes); k8sTypes = ContainerHostUtil.getContainerHostTypesForResourceType( ResourceType.KUBERNETES_REPLICATION_CONTROLLER_TYPE); assertEquals(Collections.singletonList(ContainerHostType.KUBERNETES), k8sTypes); k8sTypes = ContainerHostUtil .getContainerHostTypesForResourceType(ResourceType.KUBERNETES_SERVICE_TYPE); assertEquals(Collections.singletonList(ContainerHostType.KUBERNETES), k8sTypes); allTypes.remove(ContainerHostType.KUBERNETES); List<ContainerHostType> otherTypes = ContainerHostUtil .getContainerHostTypesForResourceType(ResourceType.CONTAINER_TYPE); assertEquals(allTypes, otherTypes); }
private ContainerHostSpec createContainerHostSpec(final String projectLinkDocker) { ContainerHostSpec hostSpecDocker1 = new ContainerHostSpec(); hostSpecDocker1.hostState = new ComputeState(); hostSpecDocker1.hostState.id = UUID.randomUUID().toString(); hostSpecDocker1.hostState.address = "test-address"; hostSpecDocker1.hostState.tenantLinks = Collections.singletonList(projectLinkDocker); hostSpecDocker1.acceptCertificate = true; hostSpecDocker1.hostState.customProperties = new HashMap<>(); hostSpecDocker1.hostState.customProperties.put( ContainerHostService.HOST_DOCKER_ADAPTER_TYPE_PROP_NAME, ContainerHostService.DockerAdapterType.API.name()); hostSpecDocker1.hostState.customProperties.put( ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.DOCKER.name()); hostSpecDocker1.hostState.customProperties.put( ComputeConstants.HOST_AUTH_CREDENTIALS_PROP_NAME, ""); return hostSpecDocker1; }
public static ContainerHostType getDeclaredContainerHostType(ComputeState computeState) { AssertUtil.assertNotNull(computeState, "computeState"); if (computeState.customProperties == null) { return ContainerHostType.getDefaultHostType(); } String hostTypeRaw = computeState.customProperties .get(ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME); if (hostTypeRaw == null) { return ContainerHostType.getDefaultHostType(); } try { return ContainerHostType.valueOf(hostTypeRaw); } catch (IllegalArgumentException ex) { String error = String.format(CONTAINER_HOST_TYPE_NOT_SUPPORTED_MESSAGE_FORMAT, hostTypeRaw); throw new LocalizableValidationException(ex, error, CONTAINER_HOST_TYPE_NOT_SUPPORTED_MESSAGE_CODE, hostTypeRaw); } }
protected ComputeState createKubernetesHost(ResourcePoolState resourcePool) throws Throwable { ComputeDescription createDockerHostDescription = createDockerHostDescription(); ComputeState compute = new ComputeState(); compute.resourcePoolLink = resourcePool.documentSelfLink; compute.primaryMAC = UUID.randomUUID().toString(); compute.powerState = PowerState.ON; compute.adapterManagementReference = URI.create("http://localhost:8081"); // not real reference compute.descriptionLink = createDockerHostDescription.documentSelfLink; compute.customProperties = new HashMap<>(); compute.customProperties.put(ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.KUBERNETES.name()); compute = getOrCreateDocument(compute, ComputeService.FACTORY_LINK); assertNotNull(compute); addForDeletion(compute); return compute; }
@Test public void testIsSchedulerHost() { final String alias = "alias"; ComputeService.ComputeState state = new ComputeService.ComputeState(); state.customProperties = new HashMap<>(); state.customProperties.put(ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.KUBERNETES.name()); state.customProperties.put(ContainerHostUtil.PROPERTY_NAME_DRIVER, ContainerHostUtil.VMWARE_VIC_DRIVER2); boolean result = ContainerHostUtil.isSchedulerHost(state); assertTrue(result); // negative test state.customProperties = new HashMap<>(); result = ContainerHostUtil.isSchedulerHost(state); assertFalse(result); }