csar.setToscaDefinitionsVersion(csarService.getOrFail(new Csar(oldArchiveName, oldArchiveVersion).getId()).getToscaDefinitionsVersion()); } else { csar.setToscaDefinitionsVersion(ToscaParser.LATEST_DSL);
@Override public Topology createTopologyAsTemplate(String name, String description, String version, String workspace, String fromTopologyId) { NameValidationUtils.validate("topologyTemplateName", name); // Every version of a topology template has a Cloud Service Archive Csar csar = new Csar(name, StringUtils.isNotBlank(version) ? version : VersionUtil.DEFAULT_VERSION_NAME); csar.setWorkspace(workspace); csar.setDelegateType(ArchiveDelegateType.CATALOG.toString()); csar.setToscaDefinitionsVersion(ToscaParser.LATEST_DSL); if (description == null) { csar.setDescription("This archive has been created with alien4cloud."); } else { csar.setDescription("Enclosing archive for topology " + description); } Topology topology; if (fromTopologyId != null) { // "cloning" the topology // TODO Currently, the fromTopologyId is always null. If this implementation needed, please think about initializing the workflow topology = alienDAO.findById(Topology.class, fromTopologyId); } else { topology = new Topology(); // Init the workflow if the topology is totally new workflowBuilderService.initWorkflows(workflowBuilderService.buildTopologyContext(topology, csar)); } topology.setDescription(description); topology.setArchiveName(csar.getName()); topology.setArchiveVersion(csar.getVersion()); topology.setWorkspace(csar.getWorkspace()); archiveIndexer.importNewArchive(csar, topology, null); return topology; }
/** * Perform validation of a Tosca archive. * * @param archiveRoot The archive to validate and post process. */ public void process(ArchiveRoot archiveRoot) { // Register the archive in the context to ensure that all types are mapped to the TOSCA context. // In alien4cloud archives are referenced by id and version however this is not required by TOSCA, the following code set/unset temporary ids and reset // them to avoid registration issue. String archiveName = archiveRoot.getArchive().getName(); String archiveVersion = archiveRoot.getArchive().getVersion(); archiveRoot.getArchive().setYamlFilePath(ParsingContextExecution.getFileName()); archiveRoot.getArchive().setToscaDefinitionsVersion(ParsingContextExecution.getDefinitionVersion()); if (archiveName == null) { archiveRoot.getArchive().setName(ParsingContextExecution.getFileName()); } if (archiveVersion == null) { archiveRoot.getArchive().setVersion("undefined"); } // All type validation may require local archive types, so we need to register the current archive. ToscaContext.get().register(archiveRoot); doProcess(archiveRoot); // reset to TOSCA template value (in case they where changed) archiveRoot.getArchive().setName(archiveName); archiveRoot.getArchive().setVersion(archiveVersion); }