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); } } }
@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); } }
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; }