use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class ManagementBusInvocationPluginScript method createDANamePathMapEnvVar.
/**
* @return mapping with DeploymentArtifact names and their paths.
*/
private String createDANamePathMapEnvVar(final Csar csar, final TNodeType nodeType, final TNodeTemplate nodeTemplate) {
LOG.debug("Checking if NodeTemplate {} has DAs...", nodeTemplate.getName());
List<String> daArtifactReferences;
final Map<String, List<String>> daNameReferenceMapping = new HashMap<>();
final ResolvedArtifacts resolvedArtifacts = containerEngine.resolvedDeploymentArtifacts(csar, nodeTemplate);
for (final ResolvedDeploymentArtifact resolvedDA : resolvedArtifacts.getDeploymentArtifacts()) {
daArtifactReferences = resolvedDA.getReferences();
for (final String daArtifactReference : daArtifactReferences) {
LOG.debug("Artifact reference for DA: {} found: {} .", resolvedDA.getName(), daArtifactReference);
List<String> currentValue = daNameReferenceMapping.computeIfAbsent(resolvedDA.getName(), k -> new ArrayList<>());
currentValue.add(daArtifactReference);
}
}
final List<TNodeTypeImplementation> nodeTypeImpls = ToscaEngine.getNodeTypeImplementations(csar, nodeType);
for (final TNodeTypeImplementation nodeTypeImpl : nodeTypeImpls) {
List<TDeploymentArtifact> das = nodeTypeImpl.getDeploymentArtifacts();
if (das != null) {
for (final TDeploymentArtifact da : das) {
final TArtifactTemplate daArtifactTemplate;
try {
daArtifactTemplate = ToscaEngine.resolveArtifactTemplate(csar, da.getArtifactRef());
} catch (NotFoundException e) {
LOG.warn("Failed to find ArtifactTemplate with reference [{}] for DeploymentArtifact {}", da.getArtifactRef(), da.getName());
continue;
}
if (daArtifactTemplate.getArtifactReferences() == null) {
continue;
}
for (final TArtifactReference daArtifactReference : daArtifactTemplate.getArtifactReferences()) {
LOG.debug("Artifact reference for DA: {} found: {} .", da.getName(), daArtifactReference);
List<String> currentValue = daNameReferenceMapping.computeIfAbsent(da.getName(), k -> new ArrayList<>());
currentValue.add(daArtifactReference.getReference());
}
}
}
}
StringBuilder daEnvMap = new StringBuilder();
if (!daNameReferenceMapping.isEmpty()) {
LOG.debug("NodeTemplate {} has {} DAs.", nodeTemplate.getName(), daNameReferenceMapping.size());
daEnvMap.append("DAs=\"");
for (final Entry<String, List<String>> da : daNameReferenceMapping.entrySet()) {
final String daName = da.getKey();
final List<String> daRefs = da.getValue();
for (String daRef : daRefs) {
// FIXME / is a brutal assumption
if (!daRef.startsWith("/")) {
daRef = "/" + daRef;
}
daEnvMap.append(daName).append(",").append(daRef).append(";");
}
}
daEnvMap.append("\" ");
LOG.debug("Created DA-DANamePathMapEnvVar for NodeTemplate {} : {}", nodeTemplate.getName(), daEnvMap);
}
return daEnvMap.toString();
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class ModelUtils method calculateEffectiveDAs.
private static List<TDeploymentArtifact> calculateEffectiveDAs(TNodeTemplate nodeTemplate, TNodeTypeImplementation nodeTypeImplementation, Csar csar, boolean traceHierarchy) {
List<TDeploymentArtifact> nodeImplementationDAs = nodeTypeImplementation == null || nodeTypeImplementation.getDeploymentArtifacts() == null ? new ArrayList<>() : nodeTypeImplementation.getDeploymentArtifacts();
List<TDeploymentArtifact> nodeTemplateDAs = nodeTemplate.getDeploymentArtifacts() == null ? new ArrayList<>() : nodeTemplate.getDeploymentArtifacts();
// DAs at the Node Template override the Node Type Implementation, if the name is equal.
List<TDeploymentArtifact> effectiveDAs = new ArrayList<>(nodeTemplateDAs);
nodeImplementationDAs.forEach(nodeTypeImplementationDA -> {
if (effectiveDAs.stream().noneMatch(nodeTemplateDa -> nodeTemplateDa.getName().equals(nodeTypeImplementationDA.getName()))) {
effectiveDAs.add(nodeTypeImplementationDA);
}
});
if (traceHierarchy) {
TNodeType nodeType = csar.nodeTypesMap().get(nodeTemplate.getType());
List<QName> nodeTypeHierarchy = ModelUtils.getNodeTypeHierarchy(nodeType, csar);
// >1 since the hierarchy always contains the type itself at place 0.
for (int index = 1; index < nodeTypeHierarchy.size(); index++) {
QName parentType = nodeTypeHierarchy.get(index);
csar.nodeTypeImplementations().stream().filter(implementation -> implementation.getNodeType().equals(parentType)).forEach(parentImplementation -> calculateEffectiveDAs(nodeTemplate, parentImplementation, csar, false).forEach(da -> {
if (!effectiveDAs.contains(da)) {
effectiveDAs.add(da);
}
}));
}
}
return effectiveDAs;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class CsarImpl method addArtifactTemplate.
public void addArtifactTemplate(InputStream inputStream, ServiceTemplateId serviceTemplateId, String nodeTemplateId) throws IOException {
final String artifactTypeNamespace = "http://opentosca.org/artifacttypes";
final String artifactTypeName = "State";
// final QName artifactTypeQName = new QName (artifactTypeNamespace, artifactTypeName);
final String artifactTemplateNamespace = "http://opentosca.org/stateartifacttemplates";
final String artifactTemplateName = serviceTemplateId.getQName().getLocalPart() + "_" + nodeTemplateId + "_StateArtifactTemplate";
final QName artifactTemplateQName = new QName(artifactTemplateNamespace, artifactTemplateName);
// ArtifactType handling
TArtifactType artifactType = new TArtifactType.Builder(artifactTypeName).setTargetNamespace(artifactTypeNamespace).build();
ArtifactTypeId artTypeId = new ArtifactTypeId(artifactType.getQName());
this.wineryRepo.setElement(artTypeId, artifactType);
// ArtifactTemplate handling
TArtifactTemplate artifactTemplate = new TArtifactTemplate.Builder(artifactTemplateName, artifactType.getQName()).setName(artifactTemplateName).build();
ArtifactTemplateId artTemplateId = new ArtifactTemplateId(artifactTemplateQName);
this.wineryRepo.setElement(artTemplateId, artifactTemplate);
ArtifactTemplateFilesDirectoryId artFileId = new ArtifactTemplateFilesDirectoryId(artTemplateId);
RepositoryFileReference fileRef = new RepositoryFileReference(artFileId, "stateArtifact.state");
this.wineryRepo.putContentToFile(fileRef, inputStream, MediaType.parse("application/x-state"));
BackendUtils.synchronizeReferences(this.wineryRepo, artTemplateId);
TServiceTemplate servTemp = this.wineryRepo.getElement(serviceTemplateId);
for (TNodeTemplate nestedNodeTemplate : BackendUtils.getAllNestedNodeTemplates(servTemp)) {
if (nestedNodeTemplate.getId().equals(nodeTemplateId)) {
TDeploymentArtifact deploymentArtifact = new TDeploymentArtifact.Builder(nodeTemplateId + "_StateArtifact", artifactType.getQName()).setArtifactRef(artTemplateId.getQName()).setArtifactRef(artTemplateId.getQName()).build();
if (nestedNodeTemplate.getDeploymentArtifacts() == null) {
nestedNodeTemplate.setDeploymentArtifacts(new ArrayList<>());
}
nestedNodeTemplate.getDeploymentArtifacts().add(deploymentArtifact);
this.wineryRepo.setElement(serviceTemplateId, servTemp);
break;
}
}
// update the ArtifactTemplates list
this.artifactTemplates.putAll(this.wineryRepo.getQNameToElementMapping(ArtifactTemplateId.class));
}
Aggregations