private boolean isFromOneOfTypes(String[] supportedArtifacts, ArtifactType artifactType) { for (String supportedArtifact : supportedArtifacts) { if (ToscaTypeUtils.isOfType(artifactType, supportedArtifact)) { return true; } } return false; }
private static boolean isHostedOnRelationship(String type) { RelationshipType relationshipType = ToscaContext.getOrFail(RelationshipType.class, type); return ToscaTypeUtils.isOfType(relationshipType, NormativeRelationshipConstants.HOSTED_ON); }
@Override public Map<String, Capability> getCompatibleCapabilityByType(NodeTemplate nodeTemplate, String type) { Map<String, Capability> capabilities = nodeTemplate.getCapabilities(); if (capabilities == null) { return Collections.emptyMap(); } Map<String, Capability> targetCapabilitiesMatch = Maps.newHashMap(); for (Map.Entry<String, Capability> capabilityEntry : capabilities.entrySet()) { String capabilityTypeName = capabilityEntry.getValue().getType(); CapabilityType capabilityType = toscaContextFinder.find(CapabilityType.class, capabilityTypeName); if (ToscaTypeUtils.isOfType(capabilityType, type)) { targetCapabilitiesMatch.put(capabilityEntry.getKey(), capabilityEntry.getValue()); } } return targetCapabilitiesMatch; }
public static boolean isComputeOrVolume(String nodeId, TopologyContext topologyContext) { NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeId); if (nodeTemplate == null) { return false; } NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTemplate.getType()); return isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE) || isOfType(nodeType, "tosca.nodes.BlockStorage"); }
public static boolean isComputeOrNetwork(String nodeId, TopologyContext topologyContext) { NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeId); if (nodeTemplate == null) { return false; } NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTemplate.getType()); return isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE) || isOfType(nodeType, NETWORK_TYPE); }
public static boolean isNativeOrSubstitutionNode(String nodeId, TopologyContext topologyContext) { NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeId); if (nodeTemplate == null) { return false; } NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTemplate.getType()); if (nodeType.isAbstract() || nodeType.getSubstitutionTopologyId() != null) { return true; } // TODO: the following should be removed after merge with orchestrator refactoring branch // (since these types will be abstract) return isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE) || isOfType(nodeType, NETWORK_TYPE) || isOfType(nodeType, "tosca.nodes.BlockStorage"); }
public static PaaSNodeTemplate getHostTemplate(PaaSNodeTemplate paaSNodeTemplate) { while (paaSNodeTemplate != null) { if (ToscaTypeUtils.isOfType(paaSNodeTemplate.getIndexedToscaElement(), NormativeComputeConstants.COMPUTE_TYPE)) { // Found the compute return paaSNodeTemplate; } else { // Not found then go to the parent paaSNodeTemplate = paaSNodeTemplate.getParent(); } } return null; }
/** * Get the non-natives node of a topology. * * @param topology * @return a Map of non-natives nodes. */ @ToscaContextual public Map<String, NodeTemplate> getNonNativesNodes(Topology topology) { Map<String, NodeTemplate> nonNativesNode = new HashMap<>(); if (topology.getNodeTemplates() != null) { for (Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) { NodeTemplate template = templateEntry.getValue(); NodeType indexedToscaElement = ToscaContext.getOrFail(NodeType.class, template.getType()); boolean isCompute = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeComputeConstants.COMPUTE_TYPE); boolean isNetwork = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeNetworkConstants.NETWORK_TYPE); boolean isVolume = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeBlockStorageConstants.BLOCKSTORAGE_TYPE); if (!isCompute && !isNetwork && !isVolume) { nonNativesNode.put(templateEntry.getKey(), template); } } } return nonNativesNode; }
private boolean isCapabilityNotOfType(Capability capability, String expectedCapabilityType) { CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType()); return !ToscaTypeUtils.isOfType(capabilityType, expectedCapabilityType); }
private void doScaledUpNode(ScalingVisitor scalingVisitor, String nodeTemplateId, Map<String, NodeTemplate> nodeTemplates) { scalingVisitor.visit(nodeTemplateId); for (Entry<String, NodeTemplate> nEntry : nodeTemplates.entrySet()) { if (nEntry.getValue().getRelationships() != null) { for (Entry<String, RelationshipTemplate> rt : nEntry.getValue().getRelationships().entrySet()) { RelationshipType relType = getRelationshipType(rt.getValue().getType()); if (nodeTemplateId.equals(rt.getValue().getTarget()) && ToscaTypeUtils.isOfType(relType, NormativeRelationshipConstants.HOSTED_ON)) { doScaledUpNode(scalingVisitor, nEntry.getKey(), nodeTemplates); } } } } }
@Override public List<CapabilityDefinition> getCompatibleCapabilityByType(NodeType nodeType, String type) { List<CapabilityDefinition> targetCapabilitiesMatch = Lists.newArrayList(); for (CapabilityDefinition capabilityDefinition : safe(nodeType.getCapabilities())) { CapabilityType capabilityType = toscaContextFinder.find(CapabilityType.class, capabilityDefinition.getType()); if (ToscaTypeUtils.isOfType(capabilityType, type)) { targetCapabilitiesMatch.add(capabilityDefinition); } } return targetCapabilitiesMatch; } }
/** * Get the first capability entry that match the given type. * * @param nodeTemplate The node template in witch to lookup for the capability. * @param capabilityTypeName The capability type to look for. * @return The capability matching the type or null if no capability of the requested type is defined. */ public static Entry<String, Capability> getCapabilitEntryyByType(NodeTemplate nodeTemplate, String capabilityTypeName) { for (Entry<String, Capability> capabilityEntry : safe(nodeTemplate.getCapabilities()).entrySet()) { if (capabilityEntry.getValue().getType().equals(capabilityTypeName)) { return capabilityEntry; } // if the type does not strictly equals we should check the derived from element CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityEntry.getValue().getType()); if (ToscaTypeUtils.isOfType(capabilityType, capabilityTypeName)) { return capabilityEntry; } } return null; }
public static RelationshipTemplate getRelationshipFromType(NodeTemplate template, String type, IRelationshipTypeFinder toscaTypeFinder) { for (RelationshipTemplate relationshipTemplate : safe(template.getRelationships()).values()) { RelationshipType relationshipType = toscaTypeFinder.findElement(relationshipTemplate.getType()); if (relationshipType != null && ToscaTypeUtils.isOfType(relationshipType, type)) { return relationshipTemplate; } } return null; }
/** * Returns all the nodes that target this node template with a relationship of the given type. */ public static Set<NodeTemplate> getSourceNodesByRelationshipType(Topology topology, NodeTemplate nodeTemplate, String relationshipTypeName) { Set<NodeTemplate> result = Sets.newHashSet(); for (NodeTemplate node : topology.getNodeTemplates().values()) { for (RelationshipTemplate relationshipTemplate : safe(node.getRelationships()).values()) { if (relationshipTemplate.getTarget().equals(nodeTemplate.getName())) { RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType()); if (ToscaTypeUtils.isOfType(relationshipType, relationshipTypeName)) { result.add(node); } } } } return result; }
@Override public void switchMaintenanceMode(PaaSDeploymentContext deploymentContext, boolean maintenanceModeOn) { String deploymentPaaSId = deploymentContext.getDeploymentPaaSId(); MockRuntimeDeploymentInfo runtimeDeploymentInfo = runtimeDeploymentInfos.get(deploymentContext.getDeploymentPaaSId()); Topology topology = runtimeDeploymentInfo.getDeploymentContext().getDeploymentTopology(); Map<String, Map<String, InstanceInformation>> nodes = runtimeDeploymentInfo.getInstanceInformations(); if (nodes == null || nodes.isEmpty()) { return; } for (Entry<String, Map<String, InstanceInformation>> nodeEntry : nodes.entrySet()) { String nodeTemplateId = nodeEntry.getKey(); Map<String, InstanceInformation> nodeInstances = nodeEntry.getValue(); if (nodeInstances != null && !nodeInstances.isEmpty()) { NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateId); NodeType nodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies()); if (ToscaTypeUtils.isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE)) { for (Entry<String, InstanceInformation> nodeInstanceEntry : nodeInstances.entrySet()) { String instanceId = nodeInstanceEntry.getKey(); InstanceInformation instanceInformation = nodeInstanceEntry.getValue(); if (instanceInformation != null) { switchInstanceMaintenanceMode(deploymentPaaSId, nodeTemplateId, instanceId, instanceInformation, maintenanceModeOn); } } } } } }
/** * Deeply explore the hosted_on hierarchy of the given node to find a node of the given type. */ public static NodeTemplate getHostOfTypeInHostingHierarchy(Topology topology, NodeTemplate nodeTemplate, String hostType) { if (nodeTemplate.getRelationships() != null) { for (RelationshipTemplate relationshipTemplate : nodeTemplate.getRelationships().values()) { RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType()); if (isOfType(relationshipType, NormativeRelationshipConstants.HOSTED_ON)) { NodeTemplate hostNode = topology.getNodeTemplates().get(relationshipTemplate.getTarget()); NodeType hostNodeType = ToscaContext.get(NodeType.class, hostNode.getType()); if (isOfType(hostNodeType, hostType)) { return hostNode; } else { return getHostOfTypeInHostingHierarchy(topology, hostNode, hostType); } } } } return null; }
@Override protected boolean typeSpecificMatching(NodeTemplate abstractTemplate, LocationResourceTemplate candidate, NodeType candidateType, LocationResources locationResources, MatchingConfiguration matchingConfiguration) { for (Entry<String, Capability> candidateCapability : safe(candidate.getTemplate().getCapabilities()).entrySet()) { MatchingFilterDefinition configuredFilterDefinition = matchingConfiguration == null ? null : safe(matchingConfiguration.getCapabilities()).get(candidateCapability.getKey()); Map<String, List<IMatchPropertyConstraint>> configuredFilters = configuredFilterDefinition == null ? null : configuredFilterDefinition.getProperties(); CapabilityType capabilityType = locationResources.getCapabilityTypes().get(candidateCapability.getValue().getType()); // Ignore scalable capabiltiy for matching. if (!ToscaTypeUtils.isOfType(capabilityType, NormativeCapabilityTypes.SCALABLE)) { Capability templateCapability = safe(abstractTemplate.getCapabilities()).get(candidateCapability.getKey()); if (templateCapability != null && !isValidTemplatePropertiesMatch(templateCapability.getProperties(), candidateCapability.getValue().getProperties(), capabilityType.getProperties(), configuredFilters)) { return false; } } } return true; } }
/** * Get the first capability that match the given type. * * @param nodeType The node type in witch to lookup for the capability. * @param capabilityTypeName The capability type to look for. * @return The capability definition matching the type or null if no capability of the requested type is defined. */ public static CapabilityDefinition getCapabilityByType(NodeType nodeType, String capabilityTypeName) { for (CapabilityDefinition capability : safe(nodeType.getCapabilities())) { if (capability.getType().equals(capabilityTypeName)) { return capability; } // if the type does not strictly equals we should check the derived from element CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType()); if (ToscaTypeUtils.isOfType(capabilityType, capabilityTypeName)) { return capability; } } return null; } }
private ScalingPolicy getScalingPolicy(String nodeTemplateId, Map<String, NodeTemplate> nodeTemplates, Topology topology) { // Get the scaling of parent if not exist Capability scalableCapability = TopologyUtils.getScalableCapability(topology, nodeTemplateId, false); if (scalableCapability == null) { if (nodeTemplates.get(nodeTemplateId).getRelationships() != null) { for (RelationshipTemplate rel : nodeTemplates.get(nodeTemplateId).getRelationships().values()) { RelationshipType relType = getRelationshipType(rel.getType()); if (ToscaTypeUtils.isOfType(relType, NormativeRelationshipConstants.HOSTED_ON)) { return getScalingPolicy(rel.getTarget(), nodeTemplates, topology); } } } else { return null; } } else { return TopologyUtils.getScalingPolicy(scalableCapability); } return null; }
if (capabilityType != null && !ToscaTypeUtils.isOfType(capabilityType, NormativeCapabilityTypes.SCALABLE)) { locationCapability.setProperties( CollectionUtils.merge(abstractCapability.getProperties(), locationCapability.getProperties(), true, topologyNotMergedProps));