private boolean isContainerNetworkType(RequestBrokerState state) { return ResourceType.NETWORK_TYPE.getName().equals(state.resourceType); }
public static Class<?> getDescriptionClass(String type) { ResourceType resourceType = ResourceType.fromContentType(type); Class<?> clazz = CompositeComponentRegistry .metaByType(resourceType.getName()).descriptionClass; return clazz; }
public static void assertComponentTypes( Map<String, ComponentTemplate<?>> components) { assertNotEmpty(components, "components"); Set<String> yamlLiterals = Stream.of(ResourceType.getValues()) .map(type -> type.getContentType()) .collect(Collectors.toSet()); components.forEach((componentName, component) -> { if (!yamlLiterals.contains(component.type)) { String errorMessage = String.format("Component '%s' has an unsupported type '%s'", componentName, component.type); throw new LocalizableValidationException(errorMessage, "compute.template.components.unsupported.type", componentName, component.type); } }); }
public static ComponentTemplate<ResourceState> fromDescriptionToComponentTemplate( NestedState nestedState, String resourceTypeName) { ResourceState description = (ResourceState) nestedState.object; assertNotNull(description, "description"); ComponentTemplate<ResourceState> template = new ComponentTemplate<>(); ResourceType resourceType = ResourceType.fromName(resourceTypeName); template.data = description; template.type = resourceType.getContentType(); template.children = nestedState.children; if (description instanceof ContainerDescription) { template.dependsOn = ((ContainerDescription) description).dependsOn; ((ContainerDescription) description).dependsOn = null; } if (description instanceof ContainerNetworkDescription) { transformDriversToComponentTemplate((ContainerNetworkDescription) description); } return template; }
public static ComponentTemplate<ContainerVolumeDescription> fromContainerVolumeDescriptionToComponentTemplate( ContainerVolumeDescription description) { assertNotNull(description, "description"); ComponentTemplate<ContainerVolumeDescription> template = new ComponentTemplate<>(); template.type = ResourceType.VOLUME_TYPE.getContentType(); template.data = description; template.data.id = null; return template; }
private static boolean isKubernetesType(String descriptionLink) { ComponentMeta meta = CompositeComponentRegistry.metaByDescriptionLink(descriptionLink); ResourceType resourceType = ResourceType.fromName(meta.resourceType); switch (resourceType) { case KUBERNETES_GENERIC_TYPE: case KUBERNETES_DEPLOYMENT_TYPE: case KUBERNETES_POD_TYPE: case KUBERNETES_REPLICATION_CONTROLLER_TYPE: case KUBERNETES_SERVICE_TYPE: return true; default: return false; } } }
@Test public void getAllTypesAsString() { String all = ResourceType.getAllTypesAsString(); assertEquals(-1, all.indexOf("CONTAINER_LOAD_BALANCER")); }
@Test public void fromContentType() { ResourceType r = ResourceType.fromContentType("App.Closure"); assertSame(ResourceType.CLOSURE_TYPE, r); try { ResourceType.fromContentType("App.LoadBalancer"); fail("CONTAINER_LOAD_BALANCER_TYPE should throw error"); } catch (Exception ignored) { } }
public static ComponentTemplate<ClosureDescription> fromClosureDescriptionToComponentTemplate( ClosureDescription description) { assertNotNull(description, "description"); ComponentTemplate<ClosureDescription> template = new ComponentTemplate<>(); template.type = ResourceType.CLOSURE_TYPE.getContentType(); template.data = description; template.data.id = null; return template; }
ResourceType type = ResourceType.fromName(rn.resourceType); List<String> trackedExecutionTasks = state.trackedExecutionTasksByResourceType .get(type);
@Override protected void validateStateOnStart(RequestBrokerState state) throws IllegalArgumentException { if (state.operation == null) { state.operation = RequestBrokerState.PROVISION_RESOURCE_OPERATION; } if (isProvisionOperation(state) || isClusteringOperation(state)) { if (!isPKSClusterType(state)) { assertNotEmpty(state.resourceDescriptionLink, "resourceDescriptionLink"); } } else { assertNotEmpty(state.resourceLinks, "resourceLinks"); } if (!(isContainerType(state) || isContainerHostType(state) || isContainerNetworkType(state) || isContainerVolumeType(state) || isComputeType(state) || isCompositeComponentType(state) || isClosureType(state) || isPKSClusterType(state))) { throw new LocalizableValidationException( String.format("Only [ %s ] resource types are supported.", ResourceType.getAllTypesAsString()), "request.supported.resource-types", ResourceType.getAllTypesAsString()); } if (state.resourceCount <= 0) { state.resourceCount = 1; } }
private boolean isPKSClusterType(RequestBrokerState state) { return ResourceType.PKS_CLUSTER_TYPE.getName().equals(state.resourceType); }
private NestedState createComponentNestedState(ComponentTemplate<?> component) { NestedState nestedState = new NestedState(); nestedState.object = (ServiceDocument) component.data; nestedState.children = component.children; ResourceType resourceType = ResourceType.fromContentType(component.type); String factoryLink = CompositeComponentRegistry .descriptionFactoryLinkByType(resourceType.getName()); nestedState.factoryLink = factoryLink; return nestedState; }
public static ComponentTemplate<ContainerNetworkDescription> fromContainerNetworkDescriptionToComponentTemplate( ContainerNetworkDescription description) { assertNotNull(description, "description"); ComponentTemplate<ContainerNetworkDescription> template = new ComponentTemplate<>(); template.type = ResourceType.NETWORK_TYPE.getContentType(); template.data = description; transformDriversToComponentTemplate(description); template.data.id = null; return template; }
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); } }
private boolean isContainerType(RequestBrokerState state) { return ResourceType.CONTAINER_TYPE.getName().equals(state.resourceType); }
@SuppressWarnings("unchecked") public static ComponentTemplate<?> deserializeComponent(Map<String, Object> obj, ObjectMapper objectMapper) { String contentType = (String) obj.get("type"); ResourceType resourceType = ResourceType.fromContentType(contentType); Class<? extends ResourceState> descriptionClass = CompositeComponentRegistry .metaByType(resourceType.getName()).descriptionClass; Map<String, Object> data = (Map<String, Object>) obj.get("data"); Map<String, NestedState> children = deserializeChildren(data, descriptionClass); ComponentTemplate<?> componentTemplate = objectMapper .convertValue(obj, ComponentTemplate.class); componentTemplate.children = children; return componentTemplate; }
@SuppressWarnings({ "rawtypes", "unchecked" }) public static CompositeTemplate createCompositeTemplate( List<? extends ResourceState> containerDescriptions, List<Binding.ComponentBinding> componentBindings) { CompositeTemplate compositeTemplate = new CompositeTemplate(); compositeTemplate.components = containerDescriptions.stream() .collect(Collectors.toMap(cd -> cd.name, cd -> { ComponentTemplate componentTemplate = new ComponentTemplate(); componentTemplate.type = ResourceType.CONTAINER_TYPE.getContentType(); componentTemplate.data = cd; return componentTemplate; })); compositeTemplate.bindings = componentBindings; return compositeTemplate; }