@EventListener public synchronized void handleArchiveUpdated(BeforeArchiveIndexed event) { contextCache.invalidate(event.getArchiveRoot().getArchive().getId()); }
/** * Get an archive from it's id. * * @param name The name of the archive to get. * @param version The version of the archive to get. * @return The archive from it's id. */ public Csar getArchive(String name, String version) { String id = new Csar(name, version).getId(); Csar archive = archivesMap.get(id); log.debug("get archive from map {} {} {}", id, archive); if (archive == null) { archive = csarRepositorySearchService.getArchive(name, version); log.debug("get archive from repo {} {} {}", id, archive, csarRepositorySearchService.getClass().getName()); archivesMap.put(id, archive); } return archive; }
public void deleteCsar(Csar csar) { // dispatch event before indexing publisher.publishEvent(new BeforeArchiveDeleted(this, csar.getId())); deleteCsarContent(csar); csarDAO.delete(Csar.class, csar.getId()); // physically delete files alienRepository.removeCSAR(csar.getName(), csar.getVersion()); // dispatch event before indexing publisher.publishEvent(new AfterArchiveDeleted(this, csar.getId())); }
archivesMap.remove(csar.getId()); log.debug("Removed dependency {} from the TOSCA context.", removedDependency); } else {
@Override @SneakyThrows(JsonProcessingException.class) public synchronized void onPluginClosed(ManagedPlugin managedPlugin) { Map<String, IArchiveProviderPlugin> archiveProviderBeans = managedPlugin.getPluginContext().getBeansOfType(IArchiveProviderPlugin.class); for (Map.Entry<String, IArchiveProviderPlugin> archiveProvider : safe(archiveProviderBeans).entrySet()) { try { Map<Csar, List<Usage>> usages = deleteArchives(safe(archiveProvider.getValue().getArchives())); for (Map.Entry<Csar, List<Usage>> usage : safe(usages).entrySet()) { log.warn( "Fail to delete archive " + usage.getKey().getId() + " from plugin" + managedPlugin.getPlugin().getId() + "/" + archiveProvider.getKey() + " as it is used. you should clean it up manually. " + JsonUtil.toString(usage.getValue()), usage.getValue()); } } catch (PluginArchiveException e) { } } }
/** * Rename the preconfigured input entry in the inputs file * * @param csar * @param topology * @param operation */ private void renamePreconfiguredInput(Csar csar, Topology topology, RenameInputOperation operation) { Map<String, Object> variables = editorFileService.loadInputsVariables(csar.getId()); if (!variables.containsKey(operation.getInputName())) { return; } Object value = variables.remove(operation.getInputName()); variables.put(operation.getNewInputName(), value); UpdateFileOperation updateFileOperation = new UpdateFileOperation(quickFileStorageService.getRelativeInputsFilePath(), new ByteArrayInputStream(YamlParserUtil.dumpAsMap(variables).getBytes(StandardCharsets.UTF_8))); updateFileProcessor.process(csar, topology, updateFileOperation); }
/** * Delete the content of the csar from the repository: elements, topologies * * @param csar */ public void deleteCsarContent(Csar csar) { // Delete the topology defined in this archive. csarDAO.delete(Topology.class, csar.getId()); // latest version indicator will be recomputed to match this new reality indexerService.deleteElements(csar.getName(), csar.getVersion()); }
/** * 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; }
/** * Query for csars that are defined by locations. * * @return A maps of <csar_id, list of locations that uses the csar>. */ public Map<String, List<Location>> getAllExposedArchivesIdsExluding(Location excludedLocation) { // exclude a location from the search QueryBuilder query = QueryBuilders.boolQuery() .mustNot(QueryBuilders.idsQuery(Location.class.getSimpleName().toLowerCase()).ids(excludedLocation.getId())); List<Location> locations = alienDAO.customFindAll(Location.class, query); Map<String, List<Location>> archiveIds = Maps.newHashMap(); if (locations != null) { for (Location location : locations) { ILocationConfiguratorPlugin configuratorPlugin = getConfiguratorPlugin(location); List<PluginArchive> pluginArchives = configuratorPlugin.pluginArchives(); for (PluginArchive pluginArchive : safe(pluginArchives)) { String archiveId = pluginArchive.getArchive().getArchive().getId(); List<Location> locationsPerArchive = archiveIds.get(archiveId); if (locationsPerArchive == null) { locationsPerArchive = Lists.newArrayList(); archiveIds.put(archiveId, locationsPerArchive); } locationsPerArchive.add(location); } } } return archiveIds; }
@Override @SneakyThrows public void process(Csar csar, Topology topology, T operation) { // load if exists the corresponding variables file operation.setPath(getRelativeVariablesFilePath(operation)); Map<String, Object> variables = loadVariables(EditionContextManager.get().getCsar().getId(), operation); // if the expression is empty, remove the var if (StringUtils.isBlank(operation.getExpression())) { // stop processing if the input is not yet preconfigured if (!variables.containsKey(operation.getName())) { return; } variables.remove(operation.getName()); } else { // update the value of the variable variables.put(operation.getName(), YamlParserUtil.load(operation.getExpression())); } if (operation.getTempFileId() == null) { operation.setArtifactStream(new ByteArrayInputStream(YamlParserUtil.dumpAsMap(variables).getBytes(StandardCharsets.UTF_8))); } super.process(csar, topology, operation); }
@Override public void checkWriteAccess(Csar csar) { // if this csar has node types, check the COMPONENTS_MANAGER Role if (toscaTypeSearchService.hasTypes(csar.getName(), csar.getVersion())) { AuthorizationUtil.checkHasOneRoleIn(Role.COMPONENTS_MANAGER); } // if the csar is bound to a topology, check the ARCHITECT Role if (topologyCatalogService.exists(csar.getId())) { AuthorizationUtil.checkHasOneRoleIn(Role.ARCHITECT); } }
/** * 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; } }
for (PluginArchive pluginArchive : pluginArchives) { Csar csar = pluginArchive.getArchive().getArchive(); List<Location> locationsExposingArchive = allExposedArchivesIds.get(csar.getId()); LocationArchiveDeleteRequested e = new LocationArchiveDeleteRequested(this); e.setCsar(csar);
/** * Load all elements from the given archive in the context. * * @param root The parsed archive to load. */ public void register(ArchiveRoot root) { log.debug("Register archive {}", root); archivesMap.put(root.getArchive().getId(), root.getArchive()); register(ArtifactType.class, root.getArtifactTypes()); register(CapabilityType.class, root.getCapabilityTypes()); register(DataType.class, root.getDataTypes()); register(NodeType.class, root.getNodeTypes()); register(RelationshipType.class, root.getRelationshipTypes()); register(PolicyType.class, root.getPolicyTypes()); }
log.debug("Imported archive {}", archiveRoot.getArchive().getId());
csar.setToscaDefinitionsVersion(csarService.getOrFail(new Csar(oldArchiveName, oldArchiveVersion).getId()).getToscaDefinitionsVersion()); } else { csar.setToscaDefinitionsVersion(ToscaParser.LATEST_DSL); applicationTopologyVersion.setArchiveId(csar.getId()); applicationTopologyVersion.setQualifier(qualifier); applicationTopologyVersion.setDescription(description);
@Then("^I should have a CSAR with id \"([^\"]*)\"$") public void I_have_CSAR_created_with_id(String csarId) throws Throwable { Context.getInstance().registerRestResponse(Context.getRestClientInstance().get("/rest/v1/csars/" + csarId)); commonStepDefinitions.I_should_receive_a_RestResponse_with_no_error(); CsarInfoDTO csarInfoDTO = JsonUtil.read(Context.getInstance().takeRestResponse(), CsarInfoDTO.class).getData(); Assert.assertNotNull(csarInfoDTO); Assert.assertEquals(csarInfoDTO.getCsar().getId(), csarId); }