Search in sources :

Example 6 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 7 with ArtifactTemplateId

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

the class ServiceTemplatesResource method createFromArtifact.

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createFromArtifact(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") FormDataBodyPart body, @FormDataParam("artifactType") QName artifactType, @FormDataParam("nodeTypes") List<FormDataBodyPart> nodeTypesList, @FormDataParam("infrastructureNodeType") QName infrastructureNodeType, @FormDataParam("tags") List<FormDataBodyPart> sentTagsList, @Context UriInfo uriInfo) throws IllegalArgumentException, JAXBException, IOException {
    Set<String> sentTags = new HashSet<>();
    if (sentTagsList != null) {
        for (FormDataBodyPart tag : sentTagsList) {
            sentTags.add(tag.getValue());
        }
    }
    Set<String> tags = RestUtils.clean(sentTags);
    Set<QName> nodeTypes = new HashSet<>();
    for (FormDataBodyPart nodetype : nodeTypesList) {
        nodeTypes.add(QName.valueOf(nodetype.getValue()));
    }
    nodeTypes = RestUtils.cleanQNameSet(nodeTypes);
    Collection<ServiceTemplateId> xaasPackages = this.getXaaSPackageTemplates(artifactType);
    Collection<ServiceTemplateId> toRemove = new ArrayList<ServiceTemplateId>();
    // check whether the serviceTemplate contains all the given nodeTypes
    for (ServiceTemplateId serviceTemplate : xaasPackages) {
        if (!RestUtils.containsNodeTypes(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), nodeTypes) | !RestUtils.containsTags(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), tags)) {
            toRemove.add(serviceTemplate);
            continue;
        }
        if (infrastructureNodeType != null && !infrastructureNodeType.getLocalPart().equals("undefined")) {
            if (RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageInfrastructure") == null) {
                toRemove.add(serviceTemplate);
                continue;
            } else {
                String value = RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageInfrastructure");
                String localName = value.split("}")[1];
                String namespace = value.split("}")[0].substring(1);
                if (!infrastructureNodeType.equals(new QName(namespace, localName))) {
                    toRemove.add(serviceTemplate);
                }
            }
        }
    }
    xaasPackages.removeAll(toRemove);
    if (xaasPackages.size() <= 0) {
        return Response.serverError().entity("No suitable ServiceTemplate found for given artifact and configuration").build();
    }
    // take the first found serviceTemplate
    ServiceTemplateId serviceTemplate = xaasPackages.iterator().next();
    // create new name for the cloned sTemplate
    String newTemplateName = fileDetail.getFileName() + "ServiceTemplate";
    // create artifactTemplate for the uploaded artifact
    ArtifactTemplateId artifactTemplateId = RestUtils.createArtifactTemplate(uploadedInputStream, fileDetail, body, artifactType, uriInfo);
    // clone serviceTemplate
    ServiceTemplateId serviceTemplateId = RestUtils.cloneServiceTemplate(serviceTemplate, newTemplateName, fileDetail.getFileName());
    if (RestUtils.hasDA(serviceTemplateId, RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageNode"), RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageDeploymentArtifact"))) {
        // inject artifact as DA into cloned ServiceTemplate
        BackendUtils.injectArtifactTemplateIntoDeploymentArtifact(serviceTemplateId, RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageNode"), RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageDeploymentArtifact"), artifactTemplateId);
    } else {
        return Response.serverError().entity("Tagged DeploymentArtifact couldn't be found on given specified NodeTemplate").build();
    }
    URI absUri = RestUtils.getAbsoluteURI(serviceTemplateId);
    // http://localhost:8080/winery/servicetemplates/winery/servicetemplates/http%253A%252F%252Fopentosca.org%252Fservicetemplates/hs_err_pid13228.logServiceTemplate/
    // http://localhost:8080/winery/servicetemplates/winery/servicetemplates/http%253A%252F%252Fopentosca.org%252Fservicetemplates/java0.logServiceTemplate/
    String absUriString = absUri.toString().replace("/winery/servicetemplates", "");
    absUri = URI.create(absUriString);
    return Response.created(absUri).build();
}
Also used : FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) QName(javax.xml.namespace.QName) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) URI(java.net.URI) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)

Example 8 with ArtifactTemplateId

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

the class BackendUtilsTest method repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated.

@Test
public void repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated() {
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
    ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
    final RepositoryFileReference repositoryFileReference = BackendUtils.getRepositoryFileReference(Paths.get("main"), Paths.get("main", "file.txt"), artifactTemplateSourceDirectoryId);
    Assert.assertEquals(artifactTemplateSourceDirectoryId, repositoryFileReference.getParent());
    Assert.assertEquals(Optional.empty(), repositoryFileReference.getSubDirectory());
    Assert.assertEquals("file.txt", repositoryFileReference.getFileName());
}
Also used : 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)

Example 9 with ArtifactTemplateId

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

the class BackendUtilsTest method repositoryFileReferenceWithSubdirectoryCorrectlyCreated.

@Test
public void repositoryFileReferenceWithSubdirectoryCorrectlyCreated() {
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
    ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
    final Path subDirectories = Paths.get("d1", "d2");
    final RepositoryFileReference repositoryFileReference = BackendUtils.getRepositoryFileReference(Paths.get("main"), Paths.get("main", "d1", "d2", "file.txt"), artifactTemplateSourceDirectoryId);
    Assert.assertEquals(artifactTemplateSourceDirectoryId, repositoryFileReference.getParent());
    Assert.assertEquals(Optional.of(subDirectories), repositoryFileReference.getSubDirectory());
    Assert.assertEquals("file.txt", repositoryFileReference.getFileName());
}
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)

Example 10 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)23 QName (javax.xml.namespace.QName)10 Test (org.junit.Test)9 RepositoryFileReference (org.eclipse.winery.common.RepositoryFileReference)8 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)6 ArtifactTemplateSourceDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId)6 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)4 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)4 InputStream (java.io.InputStream)3 HashSet (java.util.HashSet)3 PolicyTemplateId (org.eclipse.winery.common.ids.definitions.PolicyTemplateId)3 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)3 ArtifactTemplateFilesDirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Response (javax.ws.rs.core.Response)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