use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class DASpecificationTest method getNodesWithSuitableConcreteDAAndTheDirectlyConnectedNode.
@Test
public void getNodesWithSuitableConcreteDAAndTheDirectlyConnectedNode() throws Exception {
setRevisionTo("5f63267261584a513dd8a9b7960687cc3dda910a");
ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
TTopologyTemplate topologyTemplate = this.repository.getElement(id).getTopologyTemplate();
TNodeTemplate nodeTemplateWithAbstractDA = topologyTemplate.getNodeTemplate("shetland_pony");
TDeploymentArtifact deploymentArtifact = nodeTemplateWithAbstractDA.getDeploymentArtifacts().getDeploymentArtifact().get(0);
TNodeTemplate nodeTemplateConcretDA1 = topologyTemplate.getNodeTemplate("dressageequipment");
TRelationshipTemplate relationshipTemplate1 = topologyTemplate.getRelationshipTemplate("con_42");
TNodeTemplate nodeTemplateConcretDA2 = topologyTemplate.getNodeTemplate("westernequipment");
TRelationshipTemplate relationshipTemplate2 = topologyTemplate.getRelationshipTemplate("con_54");
Map<TRelationshipTemplate, TNodeTemplate> concreteDAsAndConnectedNodes = new HashMap<>();
concreteDAsAndConnectedNodes.put(relationshipTemplate1, nodeTemplateConcretDA1);
concreteDAsAndConnectedNodes.put(relationshipTemplate2, nodeTemplateConcretDA2);
Map<TRelationshipTemplate, TNodeTemplate> actualNodeWithConcreteDA = DASpecification.getNodesWithSuitableConcreteDAAndTheDirectlyConnectedNode(nodeTemplateWithAbstractDA, deploymentArtifact, topologyTemplate);
assertEquals(concreteDAsAndConnectedNodes, actualNodeWithConcreteDA);
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class TOSCAGraphIsomorphismTest method testServiceTemplateAndComplianceRuleAssociation.
@Test
public void testServiceTemplateAndComplianceRuleAssociation() throws IOException {
HashMap<DefinitionsChildId, TExtensibleElements> allEntities = new HashMap<>();
String dirABC = "/ABC";
String dirBCD = "/BCD";
ServiceTemplateId stId = new ServiceTemplateId(new QName(TEST_TARGET_NAMESPACE + dirABC + dirBCD, "test1"));
TServiceTemplate tServiceTemplate = createTServiceTemplate("ServiceTemplateTestId", TEST_TARGET_NAMESPACE + dirABC + dirBCD);
allEntities.put(stId, tServiceTemplate);
ComplianceRuleId crId1 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test1"));
ComplianceRuleId crId2 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirABC, "test2"));
ComplianceRuleId crId3 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirABC, "test3"));
ComplianceRuleId crId4 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirBCD, "test4"));
TComplianceRule ruleOne = createTComplianceRule(crId1);
allEntities.put(crId1, ruleOne);
TComplianceRule ruleTwo = createTComplianceRule(crId2);
allEntities.put(crId2, ruleTwo);
TComplianceRule ruleThree = createTComplianceRule(crId3);
allEntities.put(crId3, ruleThree);
TComplianceRule ruleFour = createTComplianceRule(crId4);
allEntities.put(crId4, ruleFour);
persist(allEntities);
ServiceTemplateComplianceRuleRuleChecker checker = new ServiceTemplateComplianceRuleRuleChecker(tServiceTemplate);
List<ComplianceRuleId> ruleIds = checker.getRuleIds(tServiceTemplate);
assertTrue(ruleIds.stream().filter(id -> id.equals(crId1)).findFirst().isPresent());
assertTrue(ruleIds.stream().filter(id -> id.equals(crId2)).findFirst().isPresent());
assertTrue(ruleIds.stream().filter(id -> id.equals(crId3)).findFirst().isPresent());
assertFalse(ruleIds.stream().filter(id -> id.equals(crId4)).findFirst().isPresent());
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId 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.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class CsarExporter method writeCsar.
/**
* Writes a complete CSAR containing all necessary things reachable from the given service template
*
* @param entryId the id of the service template to export
* @param out the output stream to write to
*/
public void writeCsar(IRepository repository, DefinitionsChildId entryId, OutputStream out) throws ArchiveException, IOException, JAXBException, RepositoryCorruptException {
CsarExporter.LOGGER.trace("Starting CSAR export with {}", entryId.toString());
Map<RepositoryFileReference, String> refMap = new HashMap<>();
Collection<String> definitionNames = new ArrayList<>();
try (final ArchiveOutputStream zos = new ArchiveStreamFactory().createArchiveOutputStream("zip", out)) {
ToscaExportUtil exporter = new ToscaExportUtil();
Map<String, Object> conf = new HashMap<>();
ExportedState exportedState = new ExportedState();
DefinitionsChildId currentId = entryId;
do {
String defName = CsarExporter.getDefinitionsPathInsideCSAR(repository, currentId);
definitionNames.add(defName);
zos.putArchiveEntry(new ZipArchiveEntry(defName));
Collection<DefinitionsChildId> referencedIds;
referencedIds = exporter.exportTOSCA(repository, currentId, zos, refMap, conf);
zos.closeArchiveEntry();
exportedState.flagAsExported(currentId);
exportedState.flagAsExportRequired(referencedIds);
currentId = exportedState.pop();
} while (currentId != null);
// if we export a ServiceTemplate, data for the self-service portal might exist
if (entryId instanceof ServiceTemplateId) {
ServiceTemplateId serviceTemplateId = (ServiceTemplateId) entryId;
this.addSelfServiceMetaData(repository, serviceTemplateId, refMap);
this.addSelfServiceFiles(repository, serviceTemplateId, refMap, zos);
}
// now, refMap contains all files to be added to the CSAR
// write manifest directly after the definitions to have it more at the beginning of the ZIP rather than having it at the very end
this.addManifest(repository, entryId, definitionNames, refMap, zos);
// used for generated XSD schemas
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = tFactory.newTransformer();
} catch (TransformerConfigurationException e1) {
CsarExporter.LOGGER.debug(e1.getMessage(), e1);
throw new IllegalStateException("Could not instantiate transformer", e1);
}
// write all referenced files
for (RepositoryFileReference ref : refMap.keySet()) {
String archivePath = refMap.get(ref);
CsarExporter.LOGGER.trace("Creating {}", archivePath);
if (ref instanceof DummyRepositoryFileReferenceForGeneratedXSD) {
addDummyRepositoryFileReferenceForGeneratedXSD(zos, transformer, (DummyRepositoryFileReferenceForGeneratedXSD) ref, archivePath);
} else {
if (ref.getParent() instanceof DirectoryId) {
// special handling for artifact template directories "source" and "files"
addArtifactTemplateToZipFile(zos, repository, ref, archivePath);
} else {
addFileToZipArchive(zos, repository, ref, archivePath);
zos.closeArchiveEntry();
}
}
}
this.addNamespacePrefixes(zos, repository);
}
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class Splitting method composeServiceTemplates.
/**
* @param serviceTemplateIds
* @return
* @throws IOException
*/
public ServiceTemplateId composeServiceTemplates(String composedSolutionServiceTemplateID, List<ServiceTemplateId> serviceTemplateIds) throws IOException, SplittingException {
IRepository repository = RepositoryFactory.getRepository();
String solutionNamespace = "http://www.opentosca.org/solutions/";
// create composed service template
ServiceTemplateId composedServiceTemplateId = new ServiceTemplateId(solutionNamespace, composedSolutionServiceTemplateID, false);
repository.forceDelete(composedServiceTemplateId);
repository.flagAsExisting(composedServiceTemplateId);
TServiceTemplate composedServiceTemplate = new TServiceTemplate();
composedServiceTemplate.setName(composedServiceTemplateId.getXmlId().getDecoded());
composedServiceTemplate.setId(composedServiceTemplate.getName());
composedServiceTemplate.setTargetNamespace(solutionNamespace);
TTopologyTemplate composedTopologyTemplate = new TTopologyTemplate();
composedServiceTemplate.setTopologyTemplate(composedTopologyTemplate);
repository.setElement(composedServiceTemplateId, composedServiceTemplate);
// add all node and relationship templates from the solution fragements to the composed topology template
for (ServiceTemplateId id : serviceTemplateIds) {
BackendUtils.mergeServiceTemplateAinServiceTemplateB(id, composedServiceTemplateId);
}
composedServiceTemplate = repository.getElement(composedServiceTemplateId);
composedTopologyTemplate = composedServiceTemplate.getTopologyTemplate();
List<TRequirement> openRequirements = getOpenRequirements(composedTopologyTemplate);
for (TRequirement requirement : openRequirements) {
QName requiredCapabilityTypeQName = getRequiredCapabilityTypeQNameOfRequirement(requirement);
TNodeTemplate nodeWithOpenCapability = composedTopologyTemplate.getNodeTemplates().stream().filter(nt -> nt.getCapabilities() != null).filter(nt -> nt.getCapabilities().getCapability().stream().anyMatch(c -> c.getType().equals(requiredCapabilityTypeQName))).findFirst().orElse(null);
if (nodeWithOpenCapability != null) {
TCapability matchingCapability = nodeWithOpenCapability.getCapabilities().getCapability().stream().filter(c -> c.getType().equals(requiredCapabilityTypeQName)).findFirst().get();
TRelationshipType matchingRelationshipType = getMatchingRelationshipType(requirement, matchingCapability);
if (matchingRelationshipType != null) {
addMatchingRelationshipTemplateToTopologyTemplate(composedTopologyTemplate, matchingRelationshipType, requirement, matchingCapability);
} else {
throw new SplittingException("No suitable relationship type found for matching");
}
}
}
LOGGER.debug("Persisting...");
repository.setElement(composedServiceTemplateId, composedServiceTemplate);
LOGGER.debug("Persisted.");
return composedServiceTemplateId;
}
Aggregations