Search in sources :

Example 6 with ArtifactTemplateId

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

the class YamlRepository method convertToYamlModel.

private YTServiceTemplate convertToYamlModel(RepositoryFileReference existing, TDefinitions definitions) throws IOException, MultiException {
    FromCanonical converter = new FromCanonical(this);
    YTServiceTemplate serviceTemplate;
    if (existing.getParent() instanceof NodeTypeImplementationId) {
        serviceTemplate = readServiceTemplate(existing);
        serviceTemplate = converter.convertNodeTypeImplementation(serviceTemplate, definitions.getNodeTypeImplementations().get(0));
    } else if (existing.getParent() instanceof RelationshipTypeImplementationId) {
        serviceTemplate = readServiceTemplate(existing);
        serviceTemplate = converter.convertRelationshipTypeImplementation(serviceTemplate, definitions.getRelationshipTypeImplementations().get(0));
    } else if (existing.getParent() instanceof NodeTypeId) {
        serviceTemplate = converter.convert(definitions);
        if (exists(existing)) {
            YTServiceTemplate oldServiceTemplate = readServiceTemplate(existing);
            serviceTemplate = replaceOldWithNewData(serviceTemplate, oldServiceTemplate);
        }
    } else if (existing.getParent() instanceof RelationshipTypeId) {
        serviceTemplate = converter.convert(definitions);
        if (exists(existing)) {
            YTServiceTemplate oldServiceTemplate = readServiceTemplate(existing);
            serviceTemplate = replaceOldRelationshipTypeWithNewData(serviceTemplate, oldServiceTemplate);
        }
    } else if (existing.getParent() instanceof ArtifactTemplateId) {
        ArtifactTemplateId id = (ArtifactTemplateId) existing.getParent();
        TArtifactTemplate artifactTemplate = definitions.getArtifactTemplates().get(0);
        YTArtifactDefinition artifact = converter.convertArtifactTemplate(artifactTemplate);
        List<YTMapImportDefinition> imports = converter.convertImports();
        Path targetPath = ref2AbsolutePath(existing);
        if (Files.exists(targetPath)) {
            serviceTemplate = readServiceTemplate(targetPath);
            if (serviceTemplate == null) {
                serviceTemplate = createNewCacheNodeTypeWithArtifact(existing, artifactTemplate, artifact, imports);
            } else if (getTypeFromArtifactName(id.getQName().getLocalPart()).equalsIgnoreCase("nodetypes")) {
                YTNodeType nodeType = serviceTemplate.getNodeTypes().entrySet().iterator().next().getValue();
                Map<String, YTArtifactDefinition> artifacts = nodeType.getArtifacts();
                if (artifacts.containsKey(artifactTemplate.getIdFromIdOrNameField())) {
                    artifacts.replace(artifactTemplate.getIdFromIdOrNameField(), artifact);
                } else {
                    artifacts.put(artifactTemplate.getIdFromIdOrNameField(), artifact);
                }
            } else if (existing.getParent() instanceof PolicyTypeId || existing.getParent() instanceof CapabilityTypeId) {
                // we simply take the new definition as is
                serviceTemplate = converter.convert(definitions);
            } else {
                serviceTemplate = converter.convert(definitions);
                if (exists(existing)) {
                    YTServiceTemplate existingServiceTemplate = readServiceTemplate(existing);
                    serviceTemplate = replaceTopologyTemplate(serviceTemplate, existingServiceTemplate);
                }
            }
        } else {
            serviceTemplate = createNewCacheNodeTypeWithArtifact(existing, artifactTemplate, artifact, imports);
        }
    } else {
        serviceTemplate = converter.convert(definitions);
    }
    return serviceTemplate;
}
Also used : Path(java.nio.file.Path) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) YTArtifactDefinition(org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition) FromCanonical(org.eclipse.winery.repository.yaml.converter.FromCanonical) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) YTNodeType(org.eclipse.winery.model.tosca.yaml.YTNodeType)

Example 7 with ArtifactTemplateId

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

the class BackendUtilsTest method synchronizeReferencesDoesNotRemoveUrls.

@Test
public void synchronizeReferencesDoesNotRemoveUrls() throws Exception {
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://example.org", "test-artifact-template", false);
    // alternative test implementation: Use git-based repository
    // this test at hand is closer to the implementation, but easier to write
    IRepository repository = mock(IRepository.class);
    ArtifactTemplateFilesDirectoryId artifactTemplateFilesDirectoryId = new ArtifactTemplateFilesDirectoryId(artifactTemplateId);
    when(repository.getContainedFiles(artifactTemplateFilesDirectoryId)).thenReturn(Collections.emptySortedSet());
    TArtifactTemplate artifactTemplate = createArtifactTemplateWithSingleReferenceToAnUrl();
    when(repository.getElement(artifactTemplateId)).thenReturn(artifactTemplate);
    TArtifactTemplate synchronizhedArtifactTemplate = BackendUtils.synchronizeReferences(repository, artifactTemplateId);
    assertEquals(createArtifactTemplateWithSingleReferenceToAnUrl(), synchronizhedArtifactTemplate);
}
Also used : ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Test(org.junit.jupiter.api.Test)

Example 8 with ArtifactTemplateId

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

the class BackendUtilsTest method synchronizeReferencesDoesNotRemoveExistentFileAndDoesNotRemoveUrls.

@Test
public void synchronizeReferencesDoesNotRemoveExistentFileAndDoesNotRemoveUrls() throws Exception {
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://example.org", "test-artifact-template", false);
    // alternative test implementation: Use git-based repository
    // this test at hand is closer to the implementation, but easier to write
    IRepository repository = mock(IRepository.class);
    ArtifactTemplateFilesDirectoryId artifactTemplateFilesDirectoryId = new ArtifactTemplateFilesDirectoryId(artifactTemplateId);
    SortedSet<RepositoryFileReference> containedReferences = new TreeSet<>();
    RepositoryFileReference repositoryFileReference = new RepositoryFileReference(artifactTemplateId, "exists.txt");
    containedReferences.add(repositoryFileReference);
    when(repository.getContainedFiles(artifactTemplateFilesDirectoryId)).thenReturn(containedReferences);
    TArtifactTemplate artifactTemplate = createArtifactTemplateWithReferenceToAnUrlAndExistentFile();
    when(repository.getElement(artifactTemplateId)).thenReturn(artifactTemplate);
    TArtifactTemplate synchronizedArtifactTemplate = BackendUtils.synchronizeReferences(repository, artifactTemplateId);
    assertEquals(createArtifactTemplateWithReferenceToAnUrlAndExistentFile(), synchronizedArtifactTemplate);
}
Also used : ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) TreeSet(java.util.TreeSet) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Test(org.junit.jupiter.api.Test)

Example 9 with ArtifactTemplateId

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

the class RestUtils method createArtifactTemplate.

public static ArtifactTemplateId createArtifactTemplate(InputStream uploadedInputStream, FormDataContentDisposition fileDetail, FormDataBodyPart body, QName artifactType, UriInfo uriInfo) {
    ArtifactTemplatesResource templateResource = new ArtifactTemplatesResource();
    QNameWithTypeApiData qNameApiData = new QNameWithTypeApiData();
    qNameApiData.localname = "xaasPackager_" + fileDetail.getFileName();
    qNameApiData.namespace = "http://opentosca.org/xaaspackager";
    qNameApiData.type = artifactType.toString();
    templateResource.onJsonPost(qNameApiData);
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://opentosca.org/xaaspackager", "xaasPackager_" + fileDetail.getFileName(), false);
    ArtifactTemplateResource atRes = new ArtifactTemplateResource(artifactTemplateId);
    atRes.getFilesResource().onPost(uploadedInputStream, fileDetail, body, uriInfo);
    return artifactTemplateId;
}
Also used : QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource)

Example 10 with ArtifactTemplateId

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

the class DockerPlugin method downloadDependenciesBasedOnArtifact.

@Override
public GeneratedArtifacts downloadDependenciesBasedOnArtifact(QName artifactTemplate, IRepository repository) {
    ArtifactTemplateId originalId = new ArtifactTemplateId(artifactTemplate);
    ArtifactTemplateFilesDirectoryId originalFilesId = new ArtifactTemplateFilesDirectoryId(originalId);
    GeneratedArtifacts generatedArtifacts = new GeneratedArtifacts(artifactTemplate);
    for (RepositoryFileReference containedFile : repository.getContainedFiles(originalFilesId)) {
        if (containedFile.getFileName().endsWith(".zip")) {
            try (InputStream in = repository.newInputStream(containedFile)) {
                Path tempDirectory = Files.createTempDirectory(containedFile.getFileName());
                List<String> fileListFromZip = Utils.getFileListFromZip(new ZipInputStream(in), tempDirectory.toAbsolutePath().toString());
                if (fileListFromZip.contains("Dockerfile")) {
                    generatedArtifacts.selfContainedArtifactQName = this.createDockerImage(tempDirectory, originalId, repository);
                }
                FileUtils.forceDelete(tempDirectory);
            } catch (IOException e) {
                logger.error("Error while opening input-stream to zip file!", e);
            }
        } else if (containedFile.getFileName().equals("Dockerfile")) {
            try {
                Path tempDirectory = Files.createTempDirectory(containedFile.getFileName());
                FileUtils.copyFiles(repository.ref2AbsolutePath(containedFile).getParent(), tempDirectory, new ArrayList<>());
                generatedArtifacts.selfContainedArtifactQName = this.createDockerImage(tempDirectory, originalId, repository);
                FileUtils.forceDelete(tempDirectory);
            } catch (IOException e) {
                logger.error("Error while creating temp directory!", e);
            }
        }
    }
    return generatedArtifacts;
}
Also used : Path(java.nio.file.Path) ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) ZipInputStream(java.util.zip.ZipInputStream) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)

Aggregations

ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)36 QName (javax.xml.namespace.QName)20 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)13 IOException (java.io.IOException)10 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)10 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)9 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)9 RepositoryFileReference (org.eclipse.winery.repository.common.RepositoryFileReference)9 Test (org.junit.jupiter.api.Test)9 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)8 ArtifactTemplateFilesDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId)8 ArrayList (java.util.ArrayList)7 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)7 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)7 Path (java.nio.file.Path)6 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)6 PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)6 InputStream (java.io.InputStream)5 RelationshipTypeImplementationId (org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)5