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));
}
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();
}
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());
}
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());
}
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));
}
Aggregations