Search in sources :

Example 31 with ServiceTemplateId

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

the class AccountabilityResource method getFileHistory.

@GET
@Path("fileHistory")
@Produces(MediaType.APPLICATION_JSON)
public List<FileProvenanceElement> getFileHistory(@QueryParam("fileId") String fileId) {
    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(new QName(provenanceId));
    String qNameWithComponentVersionOnly = VersionSupport.getQNameWithComponentVersionOnly(serviceTemplateId);
    Objects.requireNonNull(fileId);
    String fileIdDecoded = EncodingUtil.URLdecode(fileId);
    try {
        return getAccountabilityManager().getHistory(qNameWithComponentVersionOnly, fileIdDecoded).exceptionally(error -> null).get();
    } catch (InterruptedException | ExecutionException | AccountabilityException e) {
        LOGGER.error("Cannot history of file {}. Reason: {}", fileId, e.getMessage());
        throw createException(e);
    }
}
Also used : ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AccountabilityManager(org.eclipse.winery.accountability.AccountabilityManager) Path(javax.ws.rs.Path) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement) ArrayList(java.util.ArrayList) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Charset(java.nio.charset.Charset) Consumes(javax.ws.rs.Consumes) VersionSupport(org.eclipse.winery.model.version.VersionSupport) AccountabilityManagerFactory(org.eclipse.winery.accountability.AccountabilityManagerFactory) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) AuthorizationNode(org.eclipse.winery.accountability.model.authorization.AuthorizationNode) IOException(java.io.IOException) StreamingOutput(javax.ws.rs.core.StreamingOutput) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(javax.ws.rs.core.Response) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) WebApplicationException(javax.ws.rs.WebApplicationException) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) QName(javax.xml.namespace.QName) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 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)

Example 33 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 34 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 35 with ServiceTemplateId

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

the class DriverInjectionTest method injectDriver.

@Test
public void injectDriver() throws Exception {
    setRevisionTo("d8ee55deecf37f5052d27807df691a7b70ec50f2");
    ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
    TTopologyTemplate topologyTemplate = this.repository.getElement(id).getTopologyTemplate();
    TTopologyTemplate tTopologyTemplate = DriverInjection.injectDriver(topologyTemplate);
    TNodeTemplate nodeTemplateWithAbstractDA = tTopologyTemplate.getNodeTemplate("shetland_pony");
    List<TDeploymentArtifact> deploymentArtifacts = nodeTemplateWithAbstractDA.getDeploymentArtifacts();
    List<String> deploymentArtifactNames = new ArrayList<>();
    deploymentArtifacts.stream().forEach(da -> deploymentArtifactNames.add(da.getName()));
    TRelationshipTemplate relationshipTemplate = tTopologyTemplate.getRelationshipTemplate("con_71");
    assertEquals(2, deploymentArtifacts.size());
    assertTrue(deploymentArtifactNames.contains("WesternEquipment_Pony"));
    assertTrue(deploymentArtifactNames.contains("DressageEquipment_Pony"));
    assertEquals("org.test.dressagedriver", ModelUtilities.getPropertiesKV(relationshipTemplate).get("Driver"));
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

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