@SneakyThrows @EventListener public synchronized void reportArchiveUsage(ArchiveUsageRequestEvent event) { for (String topologyId : contextCache.asMap().keySet()) { if (isTopologyUsingArchive(event.getArchiveName(), event.getArchiveVersion(), topologyId)) { event.addUsage(new Usage(contextCache.get(topologyId).getCsar().getName(), "Topology editor", topologyId, contextCache.get(topologyId).getCsar().getWorkspace())); } } }
/** * Inject the workspace in indexed elements. * * @param archiveRoot The archive out of parsing */ private void processTypes(ArchiveRoot archiveRoot) { processTypes(archiveRoot.getArchive().getWorkspace(), archiveRoot.getArtifactTypes()); processTypes(archiveRoot.getArchive().getWorkspace(), archiveRoot.getCapabilityTypes()); processTypes(archiveRoot.getArchive().getWorkspace(), archiveRoot.getDataTypes()); processTypes(archiveRoot.getArchive().getWorkspace(), archiveRoot.getNodeTypes()); processTypes(archiveRoot.getArchive().getWorkspace(), archiveRoot.getRelationshipTypes()); processTypes(archiveRoot.getArchive().getWorkspace(), archiveRoot.getPolicyTypes()); }
/** * Generate resources related to a csar list * * @param csars * @return */ public List<Usage> generateCsarsInfo(Csar[] csars) { String resourceName; String resourceId; List<Usage> resourceList = Lists.newArrayList(); for (Csar csar : csars) { if (ArchiveDelegateType.APPLICATION.toString().equals(csar.getDelegateType())) { Application application = applicationService.checkAndGetApplication(csar.getDelegateId()); resourceName = application.getName(); } else { resourceName = csar.getName(); } Usage temp = new Usage(resourceName, Csar.class.getSimpleName().toLowerCase(), csar.getId(), csar.getWorkspace()); resourceList.add(temp); } return resourceList; }
/** * Generate resources (application or template) related to a topology list * * @param topologies * @return */ public List<Usage> generateTopologiesInfo(Topology[] topologies) { List<Usage> resourceList = Lists.newArrayList(); List<Csar> topologiesCsar = getTopologiesCsar(topologies); for (Csar csar : topologiesCsar) { if (Objects.equals(csar.getDelegateType(), ArchiveDelegateType.APPLICATION.toString())) { // get the related application Application application = applicationService.checkAndGetApplication(csar.getDelegateId()); resourceList.add(new Usage(application.getName(), csar.getDelegateType(), csar.getDelegateId(), csar.getWorkspace())); } else { resourceList.add(new Usage(csar.getName() + "[" + csar.getVersion() + "]", "topologyTemplate", csar.getId(), csar.getWorkspace())); } } return resourceList; } }
if (Objects.equals(currentIndexedArchive.getWorkspace(), archiveRoot.getArchive().getWorkspace())) { if (currentIndexedArchive.getHash() != null && currentIndexedArchive.getHash().equals(archiveRoot.getArchive().getHash())) { indexArchiveTypes(archiveName, archiveVersion, archiveRoot.getArchive().getWorkspace(), archiveRoot, currentIndexedArchive, metapropsNames); indexTopology(archiveRoot, parsingErrors, archiveName, archiveVersion);
.addUsage(new Usage(application.getName(), Application.class.getSimpleName().toLowerCase(), csar.getDelegateId(), csar.getWorkspace()));
@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; }
/** * Post process the archive: For every definition of the model it fills the id fields in the TOSCA elements from the key of the elements map. * * @param parsedArchive The archive to post process */ protected ParsingResult<ArchiveRoot> doProcess(Path archive, ParsingResult<ArchiveRoot> parsedArchive, String workspace) { String hash = FileUtil.deepSHA1(archive); parsedArchive.getResult().getArchive().setHash(hash); parsedArchive.getResult().getArchive().setWorkspace(workspace); // FIXME how should we manage hash for the topology tempalte ? processTopology(parsedArchive.getResult().getArchive().getWorkspace(), parsedArchive); // Injext archive hash in every indexed node type. processTypes(parsedArchive.getResult()); processArtifacts(archive, parsedArchive); processSubstitution(parsedArchive.getResult(), parsedArchive.getContext().getParsingErrors()); return parsedArchive; }
topology.setWorkspace(csar.getWorkspace());