Search in sources :

Example 46 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class SelfContainmentPackager method createSelfContainedVersion.

public DefinitionsChildId createSelfContainedVersion(DefinitionsChildId entryId) throws IOException {
    ServiceTemplateId newServiceTemplateId = new ServiceTemplateId(VersionSupport.getSelfContainedVersion(entryId));
    if (!repository.exists(newServiceTemplateId)) {
        repository.duplicate(entryId, newServiceTemplateId);
        TServiceTemplate serviceTemplate = repository.getElement(newServiceTemplateId);
        Collection<DefinitionsChildId> referencedElements = repository.getReferencedDefinitionsChildIds(newServiceTemplateId);
        for (DefinitionsChildId elementId : referencedElements) {
            if (elementId instanceof NodeTypeId) {
                Collection<NodeTypeImplementationId> nodeTypeImplementationIds = repository.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, elementId.getQName());
                if (nodeTypeImplementationIds.stream().noneMatch(DefinitionsChildId::isSelfContained)) {
                    // self-contained element does not exist yet!
                    List<TNodeTypeImplementation> nodeTypeImplementations = nodeTypeImplementationIds.stream().map(repository::getElement).filter(element -> element.getImplementationArtifacts() != null).collect(Collectors.toList());
                    for (TNodeTypeImplementation impl : nodeTypeImplementations) {
                        Optional<SelfContainmentPlugin> nodeTypeBasedPlugin = this.selfContainmentPlugins.stream().filter(plugin -> plugin.canHandleNodeType(elementId.getQName(), repository)).findFirst();
                        if (nodeTypeBasedPlugin.isPresent()) {
                            NodeTypeImplementationId selfContainedNodeTypeImpl = getSelfContainedNodeTypeImplId(impl);
                            try {
                                repository.duplicate(new NodeTypeImplementationId(impl.getTargetNamespace(), impl.getIdFromIdOrNameField(), false), selfContainedNodeTypeImpl);
                                TNodeTypeImplementation selfContained = this.repository.getElement(selfContainedNodeTypeImpl);
                                nodeTypeBasedPlugin.get().downloadDependenciesBasedOnNodeType(selfContained, this.repository);
                                repository.setElement(selfContainedNodeTypeImpl, selfContained);
                            } catch (IOException e) {
                                logger.error("While creating self-contained Node Type Implementation", e);
                            }
                        } else if (impl.getImplementationArtifacts() != null) {
                            createSelfContainedNodeTypeImplementation(impl);
                        }
                    }
                }
            } else if (elementId instanceof ArtifactTemplateId) {
                if (serviceTemplate.getTopologyTemplate() != null) {
                    TArtifactTemplate artifactTemplate = repository.getElement(elementId);
                    SelfContainmentPlugin.GeneratedArtifacts generatedArtifacts = this.downloadArtifacts(elementId.getQName(), artifactTemplate.getType());
                    if (generatedArtifacts != null && generatedArtifacts.selfContainedArtifactQName != null) {
                        // first, we need to identify the element that is referencing the artifact
                        serviceTemplate.getTopologyTemplate().getNodeTemplates().stream().map(TNodeTemplate::getDeploymentArtifacts).filter(Objects::nonNull).filter(daList -> daList.stream().anyMatch(da -> da.getArtifactRef() != null && da.getArtifactRef().equals(elementId.getQName()))).flatMap(Collection::stream).forEach(da -> da.setArtifactRef(generatedArtifacts.selfContainedArtifactQName));
                    }
                }
            }
        }
        repository.setElement(newServiceTemplateId, serviceTemplate);
    } else {
        logger.info("Self-contained version already exists! '{}'", newServiceTemplateId.getQName());
    }
    return newServiceTemplateId;
}
Also used : TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Collection(java.util.Collection) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Objects(java.util.Objects) List(java.util.List) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) VersionSupport(org.eclipse.winery.model.version.VersionSupport) IRepository(org.eclipse.winery.repository.backend.IRepository) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) Optional(java.util.Optional) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Objects(java.util.Objects) Collection(java.util.Collection) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 47 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class CsarExporterTest method testPutCsarInBlockchainAndImmutableStorage.

@Test
@Disabled
public // todo check how to enable
void testPutCsarInBlockchainAndImmutableStorage() throws Exception {
    setRevisionTo("origin/plain");
    CsarExporter exporter = new CsarExporter(repository);
    DefinitionsChildId id = new ServiceTemplateId("http://plain.winery.opentosca.org/servicetemplates", "ServiceTemplateWithAllReqCapVariants", false);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    CompletableFuture<String> future = exporter.writeCsarAndSaveManifestInProvenanceLayer(id, os);
    String transactionHash = future.get();
    assertNotNull(transactionHash);
    try (InputStream inputStream = new ByteArrayInputStream(os.toByteArray());
        ZipInputStream zis = new ZipInputStream(inputStream)) {
        ManifestContents manifestContents = parseManifest(zis);
        assertNotNull(manifestContents);
        for (String section : manifestContents.getSectionNames()) {
            assertNotNull(manifestContents.getAttributesForSection(section).get(TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS));
        }
    }
}
Also used : ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) ZipInputStream(java.util.zip.ZipInputStream) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 48 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class CsarExporterTest method testCsarFilesAreMentionedInTheManifest.

@Test
public void testCsarFilesAreMentionedInTheManifest() throws Exception {
    Map<String, Object> exportConfiguration = new HashMap<>();
    exportConfiguration.put(INCLUDE_HASHES.name(), null);
    try (InputStream inputStream = this.createOutputAndInputStream("origin/plain", new ServiceTemplateId("http://plain.winery.opentosca.org/servicetemplates", "ServiceTemplateWithAllReqCapVariants", false), exportConfiguration);
        ZipInputStream zis = new ZipInputStream(inputStream)) {
        ZipEntry entry;
        List<String> elementsList = new ArrayList<>();
        ManifestContents manifestContents = null;
        while ((entry = zis.getNextEntry()) != null) {
            String name = entry.getName();
            elementsList.add(name);
            assertNotNull(name);
            assertFalse(name.contains("\\"), "name contains backslashes");
            if ("TOSCA-Metadata/TOSCA.meta".equals(name)) {
                byte[] bytes = IOUtils.toByteArray(zis);
                String s = new String(bytes, StandardCharsets.UTF_8);
                manifestContents = new RecoveringManifestParser().parse(s);
            }
        }
        assertNotNull(manifestContents);
        for (String section : manifestContents.getSectionNames()) {
            // ensures that the file is contained in the archive
            assertTrue(elementsList.remove(section), "Contains element " + section);
        }
        // ensures that the manifest was part of the archive
        assertTrue(elementsList.remove("TOSCA-Metadata/TOSCA.meta"));
        // ensures that every file in the archive is listed in the manifest
        assertEquals(0, elementsList.size());
    }
}
Also used : RecoveringManifestParser(org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) ZipInputStream(java.util.zip.ZipInputStream) Test(org.junit.jupiter.api.Test)

Example 49 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class FulfillPoliciesTest method setUp.

@BeforeEach
public void setUp() throws GitAPIException {
    setRevisionTo("bb9ff7e08f7b72d30a2fae326740ef8051701671");
    ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationFulfillPoliciesTest1", false);
    topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
}
Also used : TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 50 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class CsarExporterTest method csarFilesHaveImmutableStorageAddresses.

@Test
// todo check how to enable
@Disabled
public void csarFilesHaveImmutableStorageAddresses() throws Exception {
    Map<String, Object> exportConfiguration = new HashMap<>();
    exportConfiguration.put(STORE_IMMUTABLY.name(), null);
    try (InputStream inputStream = this.createOutputAndInputStream("origin/plain", new ServiceTemplateId("http://plain.winery.opentosca.org/servicetemplates", "ServiceTemplateWithAllReqCapVariants", false), exportConfiguration);
        ZipInputStream zis = new ZipInputStream(inputStream)) {
        ManifestContents manifestContents = parseManifest(zis);
        assertNotNull(manifestContents);
        for (String section : manifestContents.getSectionNames()) {
            assertNotNull(manifestContents.getAttributesForSection(section).get(TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS));
        }
    }
}
Also used : ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) ZipInputStream(java.util.zip.ZipInputStream) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)126 Test (org.junit.jupiter.api.Test)73 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)44 ArrayList (java.util.ArrayList)41 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)40 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)35 QName (javax.xml.namespace.QName)25 IOException (java.io.IOException)24 IRepository (org.eclipse.winery.repository.backend.IRepository)19 List (java.util.List)17 POST (javax.ws.rs.POST)17 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 HashMap (java.util.HashMap)15 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)15 Map (java.util.Map)14 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)14 URI (java.net.URI)13 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)13 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13