Search in sources :

Example 1 with ArtifactTemplateId

use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ComplianceRuleId 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<>();
    TComplianceRule complianceRule = this.getElement(id);
    // TODO extend to required Structure
    if (complianceRule.getIdentifier() != null) {
        for (TEntityTemplate entityTemplate : complianceRule.getIdentifier().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);
                    }
                }
            } else {
                assert (entityTemplate instanceof TRelationshipTemplate);
                ids.add(new RelationshipTypeId(qname));
            }
        }
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TComplianceRule(org.eclipse.winery.model.tosca.TComplianceRule) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) TCapability(org.eclipse.winery.model.tosca.TCapability) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) TPolicy(org.eclipse.winery.model.tosca.TPolicy) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Example 2 with ArtifactTemplateId

use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeImplementationId id) {
    // We have to use a HashSet to ensure that no duplicate ids are added
    // There may be multiple DAs/IAs referencing the same type
    Collection<DefinitionsChildId> ids = new HashSet<>();
    final TNodeTypeImplementation element = this.getElement(id);
    // DAs
    TDeploymentArtifacts deploymentArtifacts = element.getDeploymentArtifacts();
    if (deploymentArtifacts != null) {
        for (TDeploymentArtifact da : deploymentArtifacts.getDeploymentArtifact()) {
            QName qname;
            if ((qname = da.getArtifactRef()) != null) {
                ids.add(new ArtifactTemplateId(qname));
            }
            ids.add(new ArtifactTypeId(da.getArtifactType()));
        }
    }
    // IAs
    return this.getReferencedTOSCAComponentImplementationArtifactIds(ids, element.getImplementationArtifacts(), id);
}
Also used : TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) HashSet(java.util.HashSet)

Example 3 with ArtifactTemplateId

use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.

the class CsarExporter method addArtifactTemplateToZipFile.

/**
 * Special handling for artifact template directories source and files
 *
 * @param zos         Output stream for the archive that should contain the file
 * @param ref         Reference to the file that should be added to the archive
 * @param archivePath Path to the file inside the archive
 * @throws IOException thrown when the temporary directory can not be created
 */
private void addArtifactTemplateToZipFile(ArchiveOutputStream zos, IGenericRepository repository, RepositoryFileReference ref, String archivePath) throws IOException {
    GitInfo gitInfo = BackendUtils.getGitInformation((DirectoryId) ref.getParent());
    if (gitInfo == null) {
        try (InputStream is = repository.newInputStream(ref)) {
            if (is != null) {
                ArchiveEntry archiveEntry = new ZipArchiveEntry(archivePath);
                zos.putArchiveEntry(archiveEntry);
                IOUtils.copy(is, zos);
                zos.closeArchiveEntry();
            }
        } catch (Exception e) {
            CsarExporter.LOGGER.error("Could not copy file to ZIP outputstream", e);
        }
        return;
    }
    // TODO: This is not quite correct. The files should reside checked out at "source/"
    Path tempDir = Files.createTempDirectory(WINERY_TEMP_DIR_PREFIX);
    try {
        Git git = Git.cloneRepository().setURI(gitInfo.URL).setDirectory(tempDir.toFile()).call();
        git.checkout().setName(gitInfo.BRANCH).call();
        String path = "artifacttemplates/" + Util.URLencode(((ArtifactTemplateId) ref.getParent().getParent()).getQName().getNamespaceURI()) + "/" + ((ArtifactTemplateId) ref.getParent().getParent()).getQName().getLocalPart() + "/files/";
        TArtifactTemplate template = BackendUtils.getTArtifactTemplate((DirectoryId) ref.getParent());
        addWorkingTreeToArchive(zos, template, tempDir, path);
    } catch (GitAPIException e) {
        CsarExporter.LOGGER.error(String.format("Error while cloning repo: %s / %s", gitInfo.URL, gitInfo.BRANCH), e);
    } finally {
        deleteDirectory(tempDir);
    }
}
Also used : Path(java.nio.file.Path) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) ArchiveEntry(org.apache.commons.compress.archivers.ArchiveEntry) GitInfo(org.eclipse.winery.repository.GitInfo) ArchiveException(org.apache.commons.compress.archivers.ArchiveException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) JAXBException(javax.xml.bind.JAXBException) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)

Example 4 with ArtifactTemplateId

use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.

the class FilebasedRepositoryTest method referenceCountIsOneForBaobab.

@Test
public void referenceCountIsOneForBaobab() throws Exception {
    this.setRevisionTo("5b7f106ab79a9ba137ece9167a79753dfc64ac84");
    final ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://winery.opentosca.org/test/artifacttemplates/fruits", "baobab_bananaInterface_IA", false);
    Assert.assertEquals(1, this.repository.getReferenceCount(artifactTemplateId));
}
Also used : ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) Test(org.junit.Test)

Example 5 with ArtifactTemplateId

use of org.eclipse.winery.common.ids.definitions.ArtifactTemplateId in project winery by eclipse.

the class FilebasedRepositoryTest method allFilesCorrectlyImported.

@Test
public void allFilesCorrectlyImported() throws Exception {
    this.setRevisionTo("5b7f106ab79a9ba137ece9167a79753dfc64ac84");
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
    ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
    final Path subDirectories = Paths.get("dir1", "dir2", "dir3");
    Path workingDir = Files.createTempDirectory("winery");
    final Path subDir = workingDir.resolve(subDirectories);
    Files.createDirectories(subDir);
    Path tempFile = subDir.resolve("test.txt");
    Files.createFile(tempFile);
    BackendUtils.importDirectory(workingDir, this.repository, artifactTemplateSourceDirectoryId);
    RepositoryFileReference ref = new RepositoryFileReference(artifactTemplateSourceDirectoryId, subDirectories, "test.txt");
    Assert.assertTrue(repository.exists(ref));
}
Also used : Path(java.nio.file.Path) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) Test(org.junit.Test)

Aggregations

ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)13 QName (javax.xml.namespace.QName)6 RepositoryFileReference (org.eclipse.winery.common.RepositoryFileReference)6 Test (org.junit.Test)6 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)4 ArtifactTemplateSourceDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId)4 Path (java.nio.file.Path)3 HashSet (java.util.HashSet)3 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)3 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)3 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)3 TDeploymentArtifacts (org.eclipse.winery.model.tosca.TDeploymentArtifacts)3 ArtifactTemplateFilesDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 JAXBException (javax.xml.bind.JAXBException)2 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)2 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)2 PolicyTypeId (org.eclipse.winery.common.ids.definitions.PolicyTypeId)2 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)2