use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class YamlToscaExportUtil method processDefinitionsElement.
@Override
protected Collection<DefinitionsChildId> processDefinitionsElement(IRepository repository, DefinitionsChildId tcId, CsarContentProperties definitionsFileProperties) throws RepositoryCorruptException, IOException {
if (!repository.exists(tcId)) {
String error = "Component instance " + tcId.toReadableString() + " does not exist.";
LOGGER.error(error);
throw new RepositoryCorruptException(error);
}
TDefinitions entryDefinitions = repository.getDefinitions(tcId);
this.getPrepareForExport(repository, tcId, entryDefinitions);
Collection<DefinitionsChildId> referencedDefinitionsChildIds = repository.getReferencedDefinitionsChildIds(tcId);
if (!EXPORT_NORMATIVE_TYPES) {
referencedDefinitionsChildIds.removeIf(id -> id.getQName().getNamespaceURI().startsWith("tosca"));
}
// adjust imports: add imports of definitions
Collection<TImport> imports = new ArrayList<>();
Map<String, QName> importDefinitions = new HashMap<>();
for (DefinitionsChildId id : referencedDefinitionsChildIds) {
this.addToImports(repository, id, imports);
String defName = YamlExporter.getDefinitionsName(repository, id).concat(Constants.SUFFIX_TOSCA_DEFINITIONS);
importDefinitions.put(defName, id.getQName());
}
entryDefinitions.getImport().addAll(imports);
entryDefinitions.setImportDefinitions(importDefinitions);
// END: Definitions modification
YAMLDefinitionsBasedCsarEntry entry = new YAMLDefinitionsBasedCsarEntry(repository, entryDefinitions);
// Custom Adjustments for Service Templates
YamlExportAdjustmentsBuilder adjustmentsBuilder = new YamlExportAdjustmentsBuilder(entry);
if (!EXPORT_NORMATIVE_TYPES) {
adjustmentsBuilder.removeNormativeTypeImports();
}
entry = adjustmentsBuilder.setMetadataName(tcId).build();
this.referencesToPathInCSARMap.put(definitionsFileProperties, entry);
return referencedDefinitionsChildIds;
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class YamlExporter method writeCsar.
/**
* Writes a complete CSAR containing all necessary things reachable from the given service template
*
* @param entryId the id of the service template to export
* @param out the output stream to write to
* @return the TOSCA meta file for the generated Csar
*/
@Override
public String writeCsar(DefinitionsChildId entryId, OutputStream out, Map<String, Object> exportConfiguration) throws IOException, RepositoryCorruptException {
LOGGER.trace("Starting CSAR export with {}", entryId.toString());
Map<CsarContentProperties, CsarEntry> refMap = new HashMap<>();
YamlToscaExportUtil exporter = new YamlToscaExportUtil();
ExportedState exportedState = new ExportedState();
DefinitionsChildId currentId = entryId;
Collection<DefinitionsChildId> referencedIds;
// Process definitions and referenced files
do {
String definitionsPathInsideCSAR = getDefinitionsPathInsideCSAR(repository, currentId);
CsarContentProperties definitionsFileProperties = new CsarContentProperties(definitionsPathInsideCSAR);
if (!YamlRepository.ROOT_TYPE_QNAME.equals(currentId.getQName())) {
referencedIds = exporter.processTOSCA(repository, currentId, definitionsFileProperties, refMap, exportConfiguration);
// for each entryId add license and readme files (if they exist) to the refMap
addLicenseAndReadmeFiles(currentId, refMap);
exportedState.flagAsExported(currentId);
exportedState.flagAsExportRequired(referencedIds);
}
currentId = exportedState.pop();
} while (currentId != null);
// Archive creation
try (final ZipOutputStream zos = new ZipOutputStream(out)) {
// write all referenced files
for (Map.Entry<CsarContentProperties, CsarEntry> entry : refMap.entrySet()) {
CsarContentProperties fileProperties = entry.getKey();
CsarEntry ref = entry.getValue();
LOGGER.trace("Creating {}", fileProperties.getPathInsideCsar());
if (ref instanceof RepositoryRefBasedCsarEntry && ((RepositoryRefBasedCsarEntry) ref).getReference().getParent() instanceof DirectoryId) {
addArtifactTemplateToZipFile(zos, (RepositoryRefBasedCsarEntry) ref, fileProperties);
} else {
addCsarEntryToArchive(zos, ref, fileProperties);
}
}
// create manifest file and add it to archive
return this.addManifest(repository, entryId, refMap, zos, exportConfiguration);
}
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class BackendUtilsTestWithGitBackedRepository method getVersionsOfOneDefinitionWithComponentThatDoesNotHaveAVersion.
@Test
public void getVersionsOfOneDefinitionWithComponentThatDoesNotHaveAVersion() throws Exception {
this.setRevisionTo("origin/plain");
DefinitionsChildId id = new RelationshipTypeId("http://plain.winery.opentosca.org/relationshiptypes", "RelationshipTypeWithoutProperties", false);
List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository);
assertEquals(1, versions.size());
assertEquals("", versions.get(0).toString());
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class YamlCsarImporter method processDefinitionsImport.
@Override
protected Optional<ServiceTemplateId> processDefinitionsImport(TDefinitions defs, TOSCAMetaFile tmf, Path definitionsPath, List<String> errors, CsarImportOptions options) throws IOException {
Optional<ServiceTemplateId> entryServiceTemplate = Optional.empty();
String defaultNamespace = defs.getTargetNamespace();
List<TExtensibleElements> componentInstanceList = defs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation();
for (final TExtensibleElements ci : componentInstanceList) {
if (ci instanceof org.eclipse.winery.model.tosca.TServiceTemplate && Objects.isNull(((org.eclipse.winery.model.tosca.TServiceTemplate) ci).getTopologyTemplate())) {
continue;
}
// Determine & ensure that element has the namespace
String namespace = this.getNamespace(ci, defaultNamespace);
this.setNamespace(ci, namespace);
String id = ModelUtilities.getId(ci);
final DefinitionsChildId wid = determineWineryId(ci, namespace, id);
if (targetRepository.exists(wid)) {
if (options.isOverwrite()) {
targetRepository.forceDelete(wid);
String msg = String.format("Deleted %1$s %2$s to enable replacement", ci.getClass().getName(), wid.getQName().toString());
LOGGER.debug(msg);
} else {
String msg = String.format("Skipped %1$s %2$s, because it already exists", ci.getClass().getName(), wid.getQName().toString());
LOGGER.debug(msg);
// this is not displayed in the UI as we currently do not distinguish between pre-existing types and types created during the import.
continue;
}
}
// Create a fresh definitions object without the other data.
final TDefinitions newDefs = BackendUtils.createWrapperDefinitions(wid, targetRepository);
// add the current TExtensibleElements as the only content to it
newDefs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().add(ci);
// import license and readme files
importLicenseAndReadme(definitionsPath.getParent().getParent(), wid, tmf, errors);
importArtifacts(definitionsPath.getParent().getParent(), ci, wid, tmf, errors);
if (ci instanceof TNodeType) {
this.adjustNodeType(definitionsPath.getParent().getParent(), (TNodeType) ci, (NodeTypeId) wid, tmf, errors);
} else if (ci instanceof TRelationshipType) {
this.adjustRelationshipType(definitionsPath.getParent().getParent(), (TRelationshipType) ci, (RelationshipTypeId) wid, tmf, errors);
}
storeDefs(wid, newDefs);
}
List<TImport> imports = defs.getImport();
this.importImports(definitionsPath.getParent(), tmf, imports, errors, options);
return entryServiceTemplate;
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class YamlCsarImporter method importArtifacts.
private void importArtifacts(Path rootPath, TExtensibleElements ci, DefinitionsChildId wid, TOSCAMetaFile tmf, final List<String> errors) {
if (ci instanceof TServiceTemplate) {
TServiceTemplate st = (TServiceTemplate) ci;
if (st.getTopologyTemplate() != null) {
st.getTopologyTemplate().getNodeTemplates().forEach(node -> {
if (Objects.nonNull(node.getArtifacts()) && !node.getArtifacts().isEmpty()) {
node.getArtifacts().stream().map(this::fixForwardSlash).filter(a -> this.isImportable(rootPath, a)).forEach(a -> {
DirectoryId stFilesDir = new GenericDirectoryId(wid, IdNames.FILES_DIRECTORY);
DirectoryId ntFilesDir = new GenericDirectoryId(stFilesDir, node.getId());
DirectoryId artifactDir = new GenericDirectoryId(ntFilesDir, a.getName());
importArtifact(rootPath, a, artifactDir, tmf, errors);
fixArtifactRefName(rootPath, a);
});
}
});
}
} else if (ci instanceof TNodeType) {
TNodeType nt = (TNodeType) ci;
fixOperationImplFileRef(nt);
if (Objects.nonNull(nt.getArtifacts()) && !nt.getArtifacts().isEmpty()) {
nt.getArtifacts().stream().map(this::fixForwardSlash).filter(a -> this.isImportable(rootPath, a)).forEach(a -> {
DirectoryId typeFilesDir = new GenericDirectoryId(wid, IdNames.FILES_DIRECTORY);
DirectoryId artifactDir = new GenericDirectoryId(typeFilesDir, a.getName());
importArtifact(rootPath, a, artifactDir, tmf, errors);
fixArtifactRefName(rootPath, a);
});
}
}
}
Aggregations