public static String buildPlacementZoneDefaultName(ContainerHostType hostType, String hostAddress) { StringBuilder sb = new StringBuilder(hostType.toString().toLowerCase()); sb.append(":"); sb.append(hostAddress.replaceAll("^https?:\\/\\/", "")); return sb.toString(); }
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 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; }
resourcePool.customProperties.put(CLUSTER_TYPE_CUSTOM_PROP, hostType.toString()); if (clusterDetails != null && !clusterDetails.isEmpty()) { resourcePool.customProperties.put(
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,
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));
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; } }
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 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 createComputeState(ResourcePoolState placementZone, AuthCredentialsServiceState credentials) throws Throwable { assertNotNull(placementZone); assertNotNull(credentials); ComputeState computeState = new ComputeState(); computeState.address = "no-address"; computeState.descriptionLink = "no-description-link"; computeState.resourcePoolLink = placementZone.documentSelfLink; computeState.customProperties = new HashMap<>(); computeState.customProperties.put(ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.DOCKER.toString()); computeState.customProperties.put(ComputeConstants.HOST_AUTH_CREDENTIALS_PROP_NAME, credentials.documentSelfLink); return doPost(computeState, ComputeService.FACTORY_LINK); }