use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project container by OpenTOSCA.
the class AbstractTransformingPlanbuilder method mappingEqualsDA.
private boolean mappingEqualsDA(TNodeTemplate node1, TNodeTemplate node2) {
int node1DaSize = 0;
int node2DaSize = 0;
if (node1.getDeploymentArtifacts() != null) {
node1DaSize = node1.getDeploymentArtifacts().size();
}
if (node2.getDeploymentArtifacts() != null) {
node2DaSize = node2.getDeploymentArtifacts().size();
}
if (node1DaSize != node2DaSize) {
return false;
} else {
if (node1.getDeploymentArtifacts() != null) {
for (TDeploymentArtifact da : node1.getDeploymentArtifacts()) {
boolean matched = false;
if (node2.getDeploymentArtifacts() != null) {
for (TDeploymentArtifact da2 : node2.getDeploymentArtifacts()) {
if (da.getArtifactType().equals(da2.getArtifactType())) {
// up to this point only the type and id of the artifact template match, a deeper mathcing
// would really look at the references and stuff, but we assume that artifact template id's
// are unique across multiple service templates
matched = true;
}
}
}
if (!matched) {
return false;
}
}
}
}
return true;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project winery by eclipse.
the class BackendUtils method getAllReferencedArtifactTemplates.
@NonNull
private static Collection<QName> getAllReferencedArtifactTemplates(TDeploymentArtifacts tDeploymentArtifacts) {
if (tDeploymentArtifacts == null) {
return Collections.emptyList();
}
List<TDeploymentArtifact> deploymentArtifacts = tDeploymentArtifacts.getDeploymentArtifact();
if (deploymentArtifacts == null) {
return Collections.emptyList();
}
Collection<QName> res = new ArrayList<>();
for (TDeploymentArtifact da : deploymentArtifacts) {
QName artifactRef = da.getArtifactRef();
if (artifactRef != null) {
res.add(artifactRef);
}
}
return res;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project winery by eclipse.
the class IGenericRepository method getReferenceCount.
default int getReferenceCount(ArtifactTemplateId id) {
// We do not use a database, therefore, we have to go through all possibilities pointing to the artifact template
// DAs and IAs point to an artifact template
// DAs are contained in Node Type Implementations and Node Templates
// IAs are contained in Node Type Implementations and Relationship Type Implementations
int count = 0;
Collection<TDeploymentArtifact> allDAs = new HashSet<>();
Collection<TImplementationArtifact> allIAs = new HashSet<>();
// handle Node Type Implementation, which contains DAs and IAs
SortedSet<NodeTypeImplementationId> nodeTypeImplementations = this.getAllDefinitionsChildIds(NodeTypeImplementationId.class);
for (NodeTypeImplementationId ntiId : nodeTypeImplementations) {
final TNodeTypeImplementation nodeTypeImplementation = this.getElement(ntiId);
TDeploymentArtifacts deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts.getDeploymentArtifact());
}
TImplementationArtifacts implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts.getImplementationArtifact());
}
}
// check all Relationshiptype Implementations for IAs
SortedSet<RelationshipTypeImplementationId> relationshipTypeImplementations = this.getAllDefinitionsChildIds(RelationshipTypeImplementationId.class);
for (RelationshipTypeImplementationId rtiId : relationshipTypeImplementations) {
TImplementationArtifacts implementationArtifacts = this.getElement(rtiId).getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts.getImplementationArtifact());
}
}
// check all node templates for DAs
SortedSet<ServiceTemplateId> serviceTemplates = this.getAllDefinitionsChildIds(ServiceTemplateId.class);
for (ServiceTemplateId sid : serviceTemplates) {
TTopologyTemplate topologyTemplate = this.getElement(sid).getTopologyTemplate();
if (topologyTemplate != null) {
List<TEntityTemplate> nodeTemplateOrRelationshipTemplate = topologyTemplate.getNodeTemplateOrRelationshipTemplate();
for (TEntityTemplate template : nodeTemplateOrRelationshipTemplate) {
if (template instanceof TNodeTemplate) {
TNodeTemplate nodeTemplate = (TNodeTemplate) template;
TDeploymentArtifacts deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts.getDeploymentArtifact());
}
}
}
}
}
// now we have all DAs and IAs
QName ourQName = id.getQName();
// check DAs for artifact templates
for (TDeploymentArtifact da : allDAs) {
QName artifactRef = da.getArtifactRef();
if (ourQName.equals(artifactRef)) {
count++;
}
}
// check IAs for artifact templates
for (TImplementationArtifact ia : allIAs) {
QName artifactRef = ia.getArtifactRef();
if (ourQName.equals(artifactRef)) {
count++;
}
}
return count;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ServiceTemplateId id) {
// We have to use a HashSet to ensure that no duplicate ids are added
// E.g., there may be multiple relationship templates having the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
TServiceTemplate serviceTemplate = this.getElement(id);
// add included things to export queue
TBoundaryDefinitions boundaryDefs;
if ((boundaryDefs = serviceTemplate.getBoundaryDefinitions()) != null) {
TBoundaryDefinitions.Policies policies = boundaryDefs.getPolicies();
if (policies != null) {
for (TPolicy policy : policies.getPolicy()) {
PolicyTypeId policyTypeId = new PolicyTypeId(policy.getPolicyType());
ids.add(policyTypeId);
PolicyTemplateId policyTemplateId = new PolicyTemplateId(policy.getPolicyRef());
ids.add(policyTemplateId);
}
}
// reqs and caps don't have to be exported here as they are references to existing reqs/caps (of nested node templates)
}
if (serviceTemplate.getTopologyTemplate() != null) {
for (TEntityTemplate entityTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through deployment artifacts
TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
for (TDeploymentArtifact da : das) {
ids.add(new ArtifactTypeId(da.getArtifactType()));
if ((qname = da.getArtifactRef()) != null) {
ids.add(new ArtifactTemplateId(qname));
}
}
}
// crawl through reqs/caps
TNodeTemplate.Requirements requirements = n.getRequirements();
if (requirements != null) {
for (TRequirement req : requirements.getRequirement()) {
QName type = req.getType();
RequirementTypeId rtId = new RequirementTypeId(type);
ids.add(rtId);
}
}
TNodeTemplate.Capabilities capabilities = n.getCapabilities();
if (capabilities != null) {
for (TCapability cap : capabilities.getCapability()) {
QName type = cap.getType();
CapabilityTypeId ctId = new CapabilityTypeId(type);
ids.add(ctId);
}
}
// crawl through policies
org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
if (policies != null) {
for (TPolicy pol : policies.getPolicy()) {
QName type = pol.getPolicyType();
PolicyTypeId ctId = new PolicyTypeId(type);
ids.add(ctId);
QName template = pol.getPolicyRef();
if (template != null) {
PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
ids.add(policyTemplateId);
}
}
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project winery by eclipse.
the class NodeTemplateResource method createStateElement.
@POST
@Path("state")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createStateElement(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") FormDataBodyPart body, @Context UriInfo uriInfo) {
LOGGER.debug("Received state artifact for Node Template {} with ID {}", this.nodeTemplate.getName(), this.nodeTemplate.getId());
LOGGER.debug("Artifact file name is {} and is {} bytes big.", fileDetail.getFileName(), fileDetail.getSize());
// ensure that the artifact type exists.
IRepository repo = RepositoryFactory.getRepository();
repo.getElement(new ArtifactTypeId(OpenToscaBaseTypes.stateArtifactType));
// create DA
Optional<TDeploymentArtifact> stateDeploymentArtifact = this.getDeploymentArtifacts().getDeploymentArtifacts().stream().filter(artifact -> artifact.getArtifactType() != null).filter(artifact -> artifact.getArtifactType().equals(OpenToscaBaseTypes.stateArtifactType)).findFirst();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
TDeploymentArtifact deploymentArtifact = new TDeploymentArtifact.Builder("state", OpenToscaBaseTypes.stateArtifactType).build();
String componentVersion = dateFormat.format(new Date());
ArtifactTemplateId newArtifactTemplateId = new ArtifactTemplateId("http://opentosca.org/artifacttemplates", this.getServiceTemplateResource().getServiceTemplate().getName() + "-" + this.nodeTemplate.getId() + "-State" + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + componentVersion + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1", false);
LOGGER.debug("Created Artifact Template of Type \"State\" called {}", newArtifactTemplateId.getQName());
// if there is already a state artifact, update the file
if (stateDeploymentArtifact.isPresent()) {
LOGGER.debug("Updating the state DA of the Node Template...");
deploymentArtifact = stateDeploymentArtifact.get();
// create new ArtifactTemplate version
ArtifactTemplateId oldArtifactTemplateId = new ArtifactTemplateId(deploymentArtifact.getArtifactRef());
List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(oldArtifactTemplateId, repo);
WineryVersion newWineryVersion = VersionUtils.getNewWineryVersion(versions);
newWineryVersion.setWorkInProgressVersion(0);
newWineryVersion.setComponentVersion(componentVersion);
newArtifactTemplateId = (ArtifactTemplateId) VersionSupport.getDefinitionInTheGivenVersion(oldArtifactTemplateId, newWineryVersion);
} else {
LOGGER.debug("Creating the state DA of the Node Template...");
List<TDeploymentArtifact> list = this.nodeTemplate.getDeploymentArtifacts();
if (Objects.isNull(list)) {
list = new ArrayList<>();
this.nodeTemplate.setDeploymentArtifacts(list);
}
list.add(deploymentArtifact);
}
new ArtifactTemplatesResource().onJsonPost(new QNameWithTypeApiData(newArtifactTemplateId.getQName().getLocalPart(), newArtifactTemplateId.getQName().getNamespaceURI(), OpenToscaBaseTypes.stateArtifactType.toString()));
LOGGER.debug("Attaching the new Artifact...");
deploymentArtifact.setArtifactRef(newArtifactTemplateId.getQName());
Response response = new ArtifactTemplateResource(newArtifactTemplateId).getFilesResource().onPost(uploadedInputStream, fileDetail, body, uriInfo, this.nodeTemplate.getId() + ".state");
if (response.getStatus() != Response.Status.CREATED.getStatusCode()) {
LOGGER.debug("Could not create artifact file! Response was {}", response);
return response;
}
LOGGER.debug("Persisting now...");
return RestUtils.persist(this.res);
}
Aggregations