private boolean isFromOneOfTypes(String[] supportedArtifacts, ArtifactType artifactType) { for (String supportedArtifact : supportedArtifacts) { if (ToscaTypeUtils.isOfType(artifactType, supportedArtifact)) { return true; } } return false; }
public static Properties from(Resource resource) { YamlWithIntermediateValuePropertiesFactoryBean factoryBean = new YamlWithIntermediateValuePropertiesFactoryBean(); factoryBean.setResources(resource); return factoryBean.getObject(); } }
/** * @return true if this node is hosted on another. */ public static boolean isHosted(Topology topology, NodeTemplate nodeTemplate) { return getImmediateHostTemplate(topology, nodeTemplate) != null; }
public static int getDefaultInstanceCount(Topology topology, NodeTemplate template, int multiplicator) { Capability scalableCapability = TopologyUtils.getScalableCapability(topology, template.getName(), false); int defaultInstanceCount = 1; if (scalableCapability != null) { ScalingPolicy scalingPolicy = TopologyUtils.getScalingPolicy(scalableCapability); if (!ScalingPolicy.NOT_SCALABLE_POLICY.equals(scalingPolicy)) { defaultInstanceCount = scalingPolicy.getInitialInstances(); } } // now look for the host NodeTemplate host = getImmediateHostTemplate(topology, template); if (host != null) { return getDefaultInstanceCount(topology, host, multiplicator * defaultInstanceCount); } else { return multiplicator * defaultInstanceCount; } }
public static Capability getScalableCapability(Topology topology, String nodeTemplateId, boolean throwNotFoundException) { NodeTemplate nodeTemplate = throwNotFoundException ? getNodeTemplate(topology, nodeTemplateId) : safe(topology.getNodeTemplates()).get(nodeTemplateId); if (nodeTemplate == null) { return null; } return throwNotFoundException ? NodeTemplateUtils.getCapabilityByTypeOrFail(nodeTemplate, NormativeCapabilityTypes.SCALABLE) : NodeTemplateUtils.getCapabilityByType(nodeTemplate, NormativeCapabilityTypes.SCALABLE); }
private int getPlannedInstancesCount(String nodeTemplateId, Topology topology) { Capability scalableCapability = TopologyUtils.getScalableCapability(topology, nodeTemplateId, false); if (scalableCapability != null) { ScalingPolicy scalingPolicy = TopologyUtils.getScalingPolicy(scalableCapability); return scalingPolicy.getInitialInstances(); } return 1; }
/** * Get a {@link NodeTemplate} given its name from a topology * * @param topology the topology * @param nodeTemplateId the name of the node template * @return the found node template, throws NotFoundException if not found */ public static NodeTemplate getNodeTemplate(Topology topology, String nodeTemplateId) { Map<String, NodeTemplate> nodeTemplates = getNodeTemplates(topology); return getNodeTemplate(topology.getId(), nodeTemplateId, nodeTemplates); }
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; }
/** * Get the first capability that match the given type. * * @param nodeTemplate The node template in witch to lookup for the capability. * @param capabilityType The capability type to look for. * @return The capability matching the type. * @throws NotFoundException if the capability is not found. */ public static Capability getCapabilityByTypeOrFail(NodeTemplate nodeTemplate, String capabilityType) { Capability capability = getCapabilityByType(nodeTemplate, capabilityType); if (capability == null) { throw new NotFoundException(""); } return capability; }
/** * Construct a relationship name from target and relationship type. * * @param type type of the relationship * @param targetName name of the target * @return the default constructed name */ private static String getRelationShipName(String type, String targetName) { String[] tokens = type.split("\\."); if (tokens.length > 1) { return toLowerCase(tokens[tokens.length - 1]) + toUpperCase(targetName); } else { return toLowerCase(type) + toUpperCase(targetName); } }
public static ScalingPolicy getScalingPolicy(Capability capability) { int initialInstances = getScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, capability); int minInstances = getScalingProperty(NormativeComputeConstants.SCALABLE_MIN_INSTANCES, capability); int maxInstances = getScalingProperty(NormativeComputeConstants.SCALABLE_MAX_INSTANCES, capability); return new ScalingPolicy(minInstances, maxInstances, initialInstances); }
/** * Get the first capability 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 Capability getCapabilityByType(NodeTemplate nodeTemplate, String capabilityTypeName) { Entry<String, Capability> capabilityEntry = getCapabilitEntryyByType(nodeTemplate, capabilityTypeName); return capabilityEntry == null ? null : capabilityEntry.getValue(); }
public static NodeTemplate getImmediateHostTemplate(Topology topology, NodeTemplate template, IToscaTypeFinder toscaTypeFinder) { RelationshipTemplate host = getRelationshipFromType(template, NormativeRelationshipConstants.HOSTED_ON, id -> toscaTypeFinder.findElement(RelationshipType.class, id)); if (host == null) { return null; } return topology.getNodeTemplates().get(host.getTarget()); }
private String copyName(String name, Collection<String> existingSet) { return TopologyUtils.getNexAvailableName(name + "_" + "copy", "", safe(existingSet)); }
private DataType findDataType(String type) { DataType dataType = dataTypeFinder.findDataType(DataType.class, type); if (dataType == null) { dataType = dataTypeFinder.findDataType(PrimitiveDataType.class, type); } return dataType; } }
private Map<String, Integer> countNodeInstance(Topology topology) { return TopologyUtils.estimateWorkflowStepInstanceCount(topology); }
/** * Get all incoming relationships of a node that match the requested type. * * @param template The node template for which to get relationships. * @param type The expected type. * @return */ public static RelationshipTemplate getRelationshipFromType(NodeTemplate template, String type) { return getRelationshipFromType(template, type, id -> ToscaContext.getOrFail(RelationshipType.class, id)); }
private static boolean isHostedOnRelationship(String type) { RelationshipType relationshipType = ToscaContext.getOrFail(RelationshipType.class, type); return ToscaTypeUtils.isOfType(relationshipType, NormativeRelationshipConstants.HOSTED_ON); }
private static void getDataTypeDependency(Map<String, DataType> indexedDataTypes, String type, DataTypeFinder dataTypeFinder) { if (ToscaTypes.isPrimitive(type) || indexedDataTypes.containsKey(type)) { return; } DataType dataType = dataTypeFinder.findDataType(DataType.class, type); if (dataType == null) { dataType = dataTypeFinder.findDataType(PrimitiveDataType.class, type); } indexedDataTypes.put(type, dataType); } }
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; }