/** * Check if this host should be treated as scheduler host. Note that a host may be a scheduler * (e.g. VIC, Kubernetes) but it may be declared as plain docker host and in this case the host * should be treated as a plain docker host * * @param computeState * @return boolean value */ public static boolean isTreatedLikeSchedulerHost(ComputeState computeState) { return getDeclaredContainerHostType(computeState) != ContainerHostType.DOCKER; }
/** * Returns whether the trust alias should be set and it is not (e.g. because the upgrade of an * instance with hosts already configured) */ public static boolean isTrustAliasMissing(ComputeState computeState) { URI hostUri = ContainerDescription.getDockerHostUri(computeState); return UriUtils.HTTPS_SCHEME.equalsIgnoreCase(hostUri.getScheme()) && (getTrustAlias(computeState) == null); }
/** * Check if this host is a scheduler host (e.g. VIC, Kubernetes) * * @param computeState * @return boolean value */ public static boolean isSchedulerHost(ComputeState computeState) { return ContainerHostUtil.isVicHost(computeState) || ContainerHostUtil.isKubernetesHost(computeState); }
if (ContainerHostUtil.getDriver(host) == null) { logInfo("Skipping the installation of the system container." + "The driver is not initialized."); if (ContainerHostUtil.isVicHost(host)) { logInfo("VIC host detected, system containers will not be installed."); return; if (ContainerHostUtil.isKubernetesHost(host)) { logInfo("Kubernetes host detected, system containers will not be" + " installed.");
private void updateHostStateCustomProperties(ComputeState computeState, Map<String, Object> properties) { if (computeState != null && properties != null && !properties.isEmpty()) { computeState.customProperties = new HashMap<>(); properties.entrySet().stream() .forEach(entry -> { if (!entry.getKey().startsWith(HIDDEN_CUSTOM_PROPERTY_PREFIX)) { computeState.customProperties.put( HIDDEN_CUSTOM_PROPERTY_PREFIX + entry.getKey(), Utils.toJson(entry.getValue())); } else { computeState.customProperties.put(entry.getKey(), Utils.toJson(entry.getValue())); } }); computeState.customProperties.remove( ContainerHostService.NUMBER_OF_CONTAINERS_PER_HOST_PROP_NAME); if (ContainerHostUtil.isVicHost(computeState)) { parseVicStats(computeState, properties); } } }
ContainerHostUtil.cleanupAutogeneratedResources(this, generatedResourcesIds); if (ContainerHostUtil.isVicHost(computeState)) { String version = ContainerHostUtil.getHostServerVersion(computeState); ContainerHostUtil.verifyVchVersionIsSupported(getHost(), version) .whenComplete((ignore, ex) -> { if (ex != null) {
if (ContainerHostUtil.isKubernetesHost(hostComputeState)) { dockerHostPath = KubernetesHostConstants.KUBERNETES_HOST_HEALTH_PATH;
private void verifyNoSchedulersInPlacementZone(ContainerHostSpec hostSpec, Operation op, Runnable successCallback) { String placementZoneLink = hostSpec.hostState.resourcePoolLink; if (placementZoneLink == null || placementZoneLink.isEmpty()) { // no placement zone => no schedulers successCallback.run(); return; } AtomicBoolean schedulerFound = new AtomicBoolean(false); QueryTask queryTask = QueryUtil.buildPropertyQuery(ComputeState.class, ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, placementZoneLink); QueryUtil.addExpandOption(queryTask); new ServiceDocumentQuery<>(getHost(), ComputeState.class) .query(queryTask, (r) -> { if (r.hasException()) { op.fail(r.getException()); } else if (r.hasResult()) { if (ContainerHostUtil.isTreatedLikeSchedulerHost(r.getResult())) { schedulerFound.set(true); op.fail(new LocalizableValidationException( PLACEMENT_ZONE_CONTAINS_SCHEDULERS_MESSAGE, PLACEMENT_ZONE_CONTAINS_SCHEDULERS_MESSAGE_CODE)); } } else { if (!schedulerFound.get()) { successCallback.run(); } } }); }
@Test public void testIsSupportedVchVersion() { assertTrue(ContainerHostUtil.isSupportedVchVersion("1.0.0", null, null)); assertTrue(ContainerHostUtil.isSupportedVchVersion("1.0.0", "1.0.0", null)); assertTrue(ContainerHostUtil.isSupportedVchVersion("1.0.0", null, "1.1.0")); assertTrue(ContainerHostUtil.isSupportedVchVersion("1.0.0", "1.0.0", "1.1.0")); assertFalse(ContainerHostUtil.isSupportedVchVersion("1.0.0", null, "1.0.0")); assertFalse(ContainerHostUtil.isSupportedVchVersion("1.1.0", null, "1.0.0")); assertFalse(ContainerHostUtil.isSupportedVchVersion("1.1", "1.1.1", null)); assertFalse(ContainerHostUtil.isSupportedVchVersion("1.0", "2.0", null)); } }
/** * Check if docker is running on VMware Integrated Container host. * * @param computeState * host to check * @return boolean value */ public static boolean isVicHost(ComputeState computeState) { boolean vic = false; String driver = getDriver(computeState); driver = driver != null ? driver.toLowerCase().trim() : ""; vic = driver.startsWith(VMWARE_VIC_DRIVER1) || driver.startsWith(VMWARE_VIC_DRIVER2); return vic; }
private List<ContainerHostType> getSupportedHostTypes( PlacementHostSelectionTaskState state, ComponentDescription desc) { ServiceDocument serviceDocument = desc.getServiceDocument(); if (serviceDocument instanceof CompositeDescription) { CompositeDescription cd = (CompositeDescription) serviceDocument; List<ContainerHostType> commonSupportedHostTypes = null; for (String descriptionLink : cd.descriptionLinks) { ComponentMeta meta = CompositeComponentRegistry .metaByDescriptionLink(descriptionLink); ResourceType resourceType = ResourceType.fromName(meta.resourceType); List<ContainerHostType> supportedHostTypes = ContainerHostUtil .getContainerHostTypesForResourceType(resourceType); if (commonSupportedHostTypes == null) { commonSupportedHostTypes = supportedHostTypes; } else { AssertUtil.assertTrue(commonSupportedHostTypes.equals(supportedHostTypes), "supported host types are not the same for different components"); } } return commonSupportedHostTypes; } else { ResourceType resourceType = ResourceType.fromName(state.resourceType); return ContainerHostUtil.getContainerHostTypesForResourceType(resourceType); } }
"Could not add cluster.", "compute.pks.cluster.add.failed")); ContainerHostUtil.cleanupAutogeneratedResources(this, generatedResourcesIds); return null; });
private static boolean isAgentSupported(ComputeState host) { return !DeploymentProfileConfig.getInstance().isTest() && !ContainerHostUtil.isVicHost(host); }
public static void filterKubernetesHostLinks(Service sender, Set<String> hostLinks, BiConsumer<Set<String>, Map<Long, Throwable>> callback) { List<Operation> getHosts = new ArrayList<>(); for (String hostLink : hostLinks) { getHosts.add(Operation.createGet(sender, hostLink)); } OperationJoin.create(getHosts) .setCompletion((ops, errs) -> { Set<String> kubernetesHostLinks = new HashSet<>(); if (errs != null && !errs.isEmpty()) { callback.accept(null, errs); } else { for (Operation op : ops.values()) { if (op == null || op.getStatusCode() != Operation.STATUS_CODE_OK) { continue; } ComputeState state = op.getBody(ComputeState.class); if (isKubernetesHost(state)) { kubernetesHostLinks.add(state.documentSelfLink); } } callback.accept(kubernetesHostLinks, null); } }).sendWith(sender); }
private static DeferredResult<Void> verifyZoneContainsSingleSchedulerOrNoHost( String resourcePoolLink, Operation op, Service service) { if (resourcePoolLink == null) { // there is no placement zone to verify return null; } Query query = Query.Builder.create() .addKindFieldClause(ComputeState.class) .addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, resourcePoolLink) .addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, ComputeConstants.COMPUTE_CONTAINER_HOST_PROP_NAME, "true") .build(); QueryUtils.QueryByPages<ComputeState> queryHelper = new QueryUtils.QueryByPages<>( service.getHost(), query, ComputeState.class, null); return queryHelper.collectDocuments(Collectors.toList()).thenAccept(computes -> { if (computes.size() > 1) { throw new LocalizableValidationException( MULTIPLE_HOSTS_IN_PLACEMENT_ZONE_MESSAGE, MULTIPLE_HOSTS_IN_PLACEMENT_ZONE_MESSAGE_CODE); } if (!computes.isEmpty() && !ContainerHostUtil.isTreatedLikeSchedulerHost(computes.get(0))) { throw new LocalizableValidationException( NON_SCHEDULER_HOST_IN_PLACEMENT_ZONE_MESSAGE, NON_SCHEDULER_HOST_IN_PLACEMENT_ZONE_MESSAGE_CODE); } }); }
ConfigurationUtil.VCH_MAX_VERSION_EXCLUSIVE_PROPERTY, (maxVersionExclusive) -> { if (isSupportedVchVersion(vchVersion, minVersionInclusive, maxVersionExclusive)) { deferredResult.complete(null);
@Test public void testGetDriver() { final String driver = "overlay"; ComputeService.ComputeState state = new ComputeService.ComputeState(); state.customProperties = new HashMap<>(); state.customProperties.put(ContainerHostUtil.PROPERTY_NAME_DRIVER, driver); String result = ContainerHostUtil.getDriver(state); assertEquals(driver, result); // negative test state.customProperties = null; result = ContainerHostUtil.getDriver(state); assertNull(result); }
@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 Map<String, HostSelection> buildHostSelectionMap(QueryResult rpQueryResult) { Collection<ComputeState> computes = rpQueryResult.computesByLink.values(); final Map<String, HostSelection> initHostSelectionMap = new LinkedHashMap<>( computes.size()); for (ComputeState computeState : computes) { final HostSelection hostSelection = new HostSelection(); hostSelection.hostLink = computeState.documentSelfLink; hostSelection.resourcePoolLinks = rpQueryResult.rpLinksByComputeLink .get(computeState.documentSelfLink); hostSelection.deploymentPolicyLink = computeState.customProperties .get(ContainerHostService.CUSTOM_PROPERTY_DEPLOYMENT_POLICY); hostSelection.availableMemory = getPropertyLong( computeState.customProperties, ContainerHostService.DOCKER_HOST_AVAILABLE_MEMORY_PROP_NAME) .orElse(Long.MAX_VALUE); hostSelection.clusterStore = computeState.customProperties .get(ContainerHostService.DOCKER_HOST_CLUSTER_STORE_PROP_NAME); hostSelection.plugins = computeState.customProperties .get(ContainerHostService.DOCKER_HOST_PLUGINS_PROP_NAME); hostSelection.name = computeState.name != null ? computeState.name : "N/A"; hostSelection.hostType = ContainerHostUtil.getDeclaredContainerHostType(computeState); initHostSelectionMap.put(hostSelection.hostLink, hostSelection); } return initHostSelectionMap; }
public static ComputeState transformComputeForExpandedCluster(ComputeState state) { // we would like to have access to the whole object in order to update it if (isVicHost(state) || isKubernetesHost(state)) { return state; } ComputeState outState = new ComputeState(); // Cast before passing the compute state in order to use the // copyTo method with ServiceDocument instead of ResourceState. state.copyTo((ServiceDocument) outState); outState.address = state.address; outState.powerState = state.powerState; outState.name = state.name; return outState; }