private static void fillAbstractInstantiableTemplate(AbstractInstantiableTemplate template, AbstractInstantiableToscaType type, AbstractInstantiableTemplate templateToMerge, boolean mergeUndefinedProps) { fillAbstractTemplate(template, type, templateToMerge, mergeUndefinedProps); template.setArtifacts(Maps.newLinkedHashMap()); fillDeploymentArtifactsMap(template.getArtifacts(), type.getArtifacts(), templateToMerge != null ? templateToMerge.getArtifacts() : null); // For now we just copy attributes as is. template.setAttributes(type.getAttributes()); if (templateToMerge != null && templateToMerge.getInterfaces() != null) { // FIXME we should merge here rather than replace template.setInterfaces(templateToMerge.getInterfaces()); } }
private static <T extends AbstractInstantiableTemplate, U extends AbstractInstantiableToscaType> boolean hasImplementation(T template, Class<U> templateClass, TopologyContext topologyContext, String stepInterfaceName, String stepOperationName) { if (hasImplementation(template.getInterfaces(), stepInterfaceName, stepOperationName)) { // The operation is overridden on the node level and is not empty return true; } else { U templateType = topologyContext.findElement(templateClass, template.getType()); if (templateType == null) { throw new NotFoundException("Template Type " + template.getType() + " cannot be found"); } else { return hasImplementation(templateType.getInterfaces(), stepInterfaceName, stepOperationName); } } }
private <T extends AbstractInstantiableTemplate> void processTemplate(ArchivePathChecker archivePathResolver, T template, ParsingResult<ArchiveRoot> parsedArchive) { if (template.getArtifacts() != null) { template.getArtifacts().values().stream().filter(artifact -> artifact != null) .forEach(artifact -> processArtifact(archivePathResolver, artifact, parsedArchive)); } processInterfaces(archivePathResolver, template.getInterfaces(), parsedArchive); }
private <T extends AbstractInstantiableTemplate, U extends AbstractInheritableToscaType> Stream<ArtifactTask> validateTemplate(String name, T template) { return safe(template.getArtifacts()).entrySet().stream().filter(artifactEntry -> StringUtils.isBlank(artifactEntry.getValue().getArtifactRef())) .map(artifactEntry -> new ArtifactTask(name, artifactEntry.getKey(), ArtifactTaskCode.MISSING)); }
@SuppressWarnings("unchecked") private <V extends AbstractInheritableToscaType> void fillType(Topology topology, AbstractInstantiableTemplate template, IPaaSTemplate<V> paaSTemplate, Class<V> clazz) { V indexedToscaElement = ToscaContext.getOrFail(clazz, template.getType()); paaSTemplate.setIndexedToscaElement(indexedToscaElement); List<String> derivedFroms = indexedToscaElement.getDerivedFrom(); List<V> derivedFromTypes = Lists.newArrayList(); if (derivedFroms != null) { for (String derivedFrom : derivedFroms) { derivedFromTypes.add(ToscaContext.get(clazz, derivedFrom)); } } paaSTemplate.setDerivedFroms(derivedFromTypes); try { Path csarPath = repository.getCSAR(indexedToscaElement.getArchiveName(), indexedToscaElement.getArchiveVersion()); paaSTemplate.setCsarPath(csarPath); } catch (AlreadyExistException e) { log.debug("No csarPath for " + indexedToscaElement + "; not setting in " + paaSTemplate); } }
@SneakyThrows private void mergeInterfaces(AbstractPaaSTemplate pasSTemplate, AbstractInstantiableTemplate abstractTemplate) { AbstractToscaType type = pasSTemplate.getIndexedToscaElement(); Map<String, Interface> typeInterfaces = null; if (type instanceof AbstractInstantiableToscaType) { typeInterfaces = ((AbstractInstantiableToscaType) type).getInterfaces(); } Map<String, Interface> templateInterfaces = abstractTemplate.getInterfaces(); // Here merge interfaces: the interface defined in the template should override those from type. pasSTemplate.setInterfaces( IndexedModelUtils.mergeInterfaces(JsonUtil.toMap(JsonUtil.toString(typeInterfaces), String.class, Interface.class), templateInterfaces)); }
return getPropertyValue(paaSTemplate.getTemplate().getProperties(), paaSTemplate.getIndexedToscaElement().getProperties(), elementName); } else if (paaSTemplate instanceof PaaSNodeTemplate) {
/** * Map the template's artifacts associated with an input to into the given artifactMap. * * @param artifactMap The map of inputArtifactId -> List of associated artifacts into which to map the given template's artifacts. * @param template The template for which to map artifact. */ private static void processInputArtifactForTemplate(Map<String, List<DeploymentArtifact>> artifactMap, AbstractInstantiableTemplate template) { for (DeploymentArtifact da : template.getArtifacts().values()) { String inputArtifactId = InputArtifactUtil.getInputArtifactId(da); if (inputArtifactId != null) { List<DeploymentArtifact> das = artifactMap.get(inputArtifactId); if (das == null) { das = Lists.newArrayList(); artifactMap.put(inputArtifactId, das); } das.add(da); } } } }
private boolean isEligible(AbstractInstantiableTemplate template, LocationMatchNodeFilter.NodeMatchContext matchContext) { if (template == null) { return true; } ArtifactSupport artifactSupport = matchContext.getArtifactSupport(); // if no supported artifact defined, then return true if (artifactSupport == null || ArrayUtils.isEmpty(artifactSupport.getTypes())) { return true; } String[] supportedArtifacts = artifactSupport.getTypes(); AbstractInstantiableToscaType indexedArtifactToscaElement = matchContext.getElement(AbstractInstantiableToscaType.class, template.getType()); if (MapUtils.isNotEmpty(indexedArtifactToscaElement.getInterfaces())) { for (Interface interfaz : indexedArtifactToscaElement.getInterfaces().values()) { for (Operation operation : interfaz.getOperations().values()) { if (operation.getImplementationArtifact() != null) { String artifactTypeString = operation.getImplementationArtifact().getArtifactType(); ArtifactType artifactType = matchContext.getElement(ArtifactType.class, artifactTypeString); // stop the checking once one artifactType is not supported if (!isFromOneOfTypes(supportedArtifacts, artifactType)) { return false; } } } } } return true; }
return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue); AbstractPropertyValue propertyValue = getFromPath(evaluatorContext, targetTemplate, targetTemplate.getProperties(), function.getElementNameToFetch()); if (propertyValue == null && targetTemplate instanceof NodeTemplate) { propertyValue = doGetProperty(evaluatorContext, return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);