use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class SelfContainmentPackager method createSelfContainedVersion.
public DefinitionsChildId createSelfContainedVersion(DefinitionsChildId entryId) throws IOException {
ServiceTemplateId newServiceTemplateId = new ServiceTemplateId(VersionSupport.getSelfContainedVersion(entryId));
if (!repository.exists(newServiceTemplateId)) {
repository.duplicate(entryId, newServiceTemplateId);
TServiceTemplate serviceTemplate = repository.getElement(newServiceTemplateId);
Collection<DefinitionsChildId> referencedElements = repository.getReferencedDefinitionsChildIds(newServiceTemplateId);
for (DefinitionsChildId elementId : referencedElements) {
if (elementId instanceof NodeTypeId) {
Collection<NodeTypeImplementationId> nodeTypeImplementationIds = repository.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, elementId.getQName());
if (nodeTypeImplementationIds.stream().noneMatch(DefinitionsChildId::isSelfContained)) {
// self-contained element does not exist yet!
List<TNodeTypeImplementation> nodeTypeImplementations = nodeTypeImplementationIds.stream().map(repository::getElement).filter(element -> element.getImplementationArtifacts() != null).collect(Collectors.toList());
for (TNodeTypeImplementation impl : nodeTypeImplementations) {
Optional<SelfContainmentPlugin> nodeTypeBasedPlugin = this.selfContainmentPlugins.stream().filter(plugin -> plugin.canHandleNodeType(elementId.getQName(), repository)).findFirst();
if (nodeTypeBasedPlugin.isPresent()) {
NodeTypeImplementationId selfContainedNodeTypeImpl = getSelfContainedNodeTypeImplId(impl);
try {
repository.duplicate(new NodeTypeImplementationId(impl.getTargetNamespace(), impl.getIdFromIdOrNameField(), false), selfContainedNodeTypeImpl);
TNodeTypeImplementation selfContained = this.repository.getElement(selfContainedNodeTypeImpl);
nodeTypeBasedPlugin.get().downloadDependenciesBasedOnNodeType(selfContained, this.repository);
repository.setElement(selfContainedNodeTypeImpl, selfContained);
} catch (IOException e) {
logger.error("While creating self-contained Node Type Implementation", e);
}
} else if (impl.getImplementationArtifacts() != null) {
createSelfContainedNodeTypeImplementation(impl);
}
}
}
} else if (elementId instanceof ArtifactTemplateId) {
if (serviceTemplate.getTopologyTemplate() != null) {
TArtifactTemplate artifactTemplate = repository.getElement(elementId);
SelfContainmentPlugin.GeneratedArtifacts generatedArtifacts = this.downloadArtifacts(elementId.getQName(), artifactTemplate.getType());
if (generatedArtifacts != null && generatedArtifacts.selfContainedArtifactQName != null) {
// first, we need to identify the element that is referencing the artifact
serviceTemplate.getTopologyTemplate().getNodeTemplates().stream().map(TNodeTemplate::getDeploymentArtifacts).filter(Objects::nonNull).filter(daList -> daList.stream().anyMatch(da -> da.getArtifactRef() != null && da.getArtifactRef().equals(elementId.getQName()))).flatMap(Collection::stream).forEach(da -> da.setArtifactRef(generatedArtifacts.selfContainedArtifactQName));
}
}
}
}
repository.setElement(newServiceTemplateId, serviceTemplate);
} else {
logger.info("Self-contained version already exists! '{}'", newServiceTemplateId.getQName());
}
return newServiceTemplateId;
}
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));
}
}
}
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());
}
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class FulfillPoliciesTest method setUp.
@BeforeEach
public void setUp() throws GitAPIException {
setRevisionTo("bb9ff7e08f7b72d30a2fae326740ef8051701671");
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationFulfillPoliciesTest1", false);
topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
}
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));
}
}
}
Aggregations