@Override public Set<CSARDependency> getDependencies(String name, String version) { Csar csar = csarService.get(name, version); if (csar == null) { throw new NotFoundException("Csar with name [" + name + "] and version [" + version + "] cannot be found"); } if (csar.getDependencies() == null || csar.getDependencies().isEmpty()) { return Sets.newHashSet(); } return Sets.newHashSet(csar.getDependencies()); }
private void setDependencies(Topology instance, ArchiveRoot archiveRoot) { if (archiveRoot.getArchive().getDependencies() == null) { return; } instance.setDependencies(Sets.newHashSet(archiveRoot.getArchive().getDependencies())); }
/** * Compute a list of transitive dependency conflicts from the Context. * * @param context the EditionContext of the Topology being built. * @return a list of dependency conflicts. */ private List<DependencyConflictDTO> getDependencyConflictDTOs(EditionContext context) { // Generate a map with all transitive dependency conflict for each dependency in the context. final Set<CSARDependency> dependencies = context.getToscaContext().getDependencies(); Map<CSARDependency, Set<CSARDependency>> dependencyConflictMap = new HashMap<>(); dependencies.forEach(source -> { final Set<CSARDependency> transitives = Optional.ofNullable(ToscaContext.get().getArchive(source.getName(), source.getVersion()).getDependencies()) .orElse(Collections.emptySet()).stream().filter(o -> !dependencies.contains(o)).collect(Collectors.toSet()); if (!transitives.isEmpty()) { dependencyConflictMap.put(source, transitives); } }); final ArrayList<DependencyConflictDTO> dependencyConflicts = new ArrayList<>(); dependencyConflictMap.forEach((source, conflicts) -> conflicts.forEach(conflict -> { String actualVersion = dependencies.stream().filter(d -> d.getName().equals(conflict.getName())).findFirst().map(CSARDependency::getVersion) .orElse(""); dependencyConflicts.add(new DependencyConflictDTO(source.getName(), conflict.getName() + ":" + conflict.getVersion(), actualVersion)); })); return dependencyConflicts; }
private Set<CSARDependency> findDependencies(Object[] args) { for (Object arg : args) { if (arg instanceof Topology) { return ((Topology) arg).getDependencies(); } if (arg instanceof Set) { Set set = (Set) arg; if (set.size() > 0 && set.iterator().next() instanceof CSARDependency) { return (Set<CSARDependency>) arg; } } if (arg instanceof AbstractToscaType) { AbstractToscaType type = ((AbstractToscaType) arg); Csar csar = csarRepositorySearchService.getArchive(type.getArchiveName(), type.getArchiveVersion()); if (csar == null) { throw new NotFoundException("Unable to find dependencies from type as it's archive cannot be found in the repository."); } Set<CSARDependency> dependencies = csar.getDependencies() == null ? Sets.newHashSet() : csar.getDependencies(); dependencies.add(new CSARDependency(type.getArchiveName(), type.getArchiveVersion())); return dependencies; } } return Sets.<CSARDependency> newHashSet(); }
@ApiOperation(value = "Add dependency to the csar with given id.") @RequestMapping(value = "/{csarId:.+?}/dependencies", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize("isAuthenticated()") @Audit @Deprecated public RestResponse<Boolean> addDependency(@PathVariable String csarId, @Valid @RequestBody CSARDependency dependency) { Csar csar = csarService.getOrFail(csarId); csarAuthorizationFilter.checkWriteAccess(csar); Set<CSARDependency> existingDependencies = csar.getDependencies(); if (existingDependencies == null) { existingDependencies = Sets.newHashSet(); csar.setDependencies(existingDependencies); } boolean couldBeSaved = existingDependencies.add(dependency); csarDAO.save(csar); return RestResponseBuilder.<Boolean> builder().data(couldBeSaved).build(); }
private void performIndexing(ArchiveRoot root, Map<String, MetaPropConfiguration> metapropsNames) { indexerService.indexInheritableElements(root.getArtifactTypes(), root.getArchive().getDependencies()); indexerService.indexInheritableElements(root.getCapabilityTypes(), root.getArchive().getDependencies()); root.getNodeTypes().forEach((id, nodeType) -> { feedA4CMetaproperties(nodeType, nodeType.getTags(), metapropsNames); } ); indexerService.indexInheritableElements(root.getNodeTypes(), root.getArchive().getDependencies()); indexerService.indexInheritableElements(root.getRelationshipTypes(), root.getArchive().getDependencies()); indexerService.indexInheritableElements(root.getDataTypes(), root.getArchive().getDependencies()); indexerService.indexInheritableElements(root.getPolicyTypes(), root.getArchive().getDependencies()); if (root.getLocalImports() != null) { for (ArchiveRoot child : root.getLocalImports()) { performIndexing(child, metapropsNames); } } } }
if (archiveRoot.getArchive().getDependencies() == null || archiveRoot.getArchive().getDependencies().isEmpty()) { return; Set<CSARDependency> dependencies = archiveRoot.getArchive().getDependencies();
private String getArtifactTypeByExtension(String artifactReference, Node node, ArchiveRoot archiveRoot) { int dotIndex = artifactReference.lastIndexOf('.'); String extension = (dotIndex == -1) ? "" : artifactReference.substring(dotIndex + 1); String type = null; ArtifactType indexedType = getFromArchiveRootWithExtension(archiveRoot, extension); if (indexedType == null) { ArtifactType artifactType = repositorySearchService.getElementInDependencies(ArtifactType.class, archiveRoot.getArchive().getDependencies(), "fileExt", extension); if (artifactType != null) { type = artifactType.getElementId(); } if (type == null) { ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.TYPE_NOT_FOUND, "Implementation artifact", node.getStartMark(), "No artifact type in the repository references the artifact's extension", node.getEndMark(), extension)); type = "unknown"; } } else { type = indexedType.getElementId(); } return type; }
ToscaContext.get().addDependency(dependency); Set<CSARDependency> dependencies = archiveRoot.getArchive().getDependencies(); if (dependencies == null) { dependencies = new HashSet<>();
Set<CSARDependency> allDependencies = new HashSet<>(safe(csar.getDependencies())); allDependencies.add(new CSARDependency(csar.getName(), csar.getVersion(), csar.getHash())); CapabilityType capabilityType = toscaTypeSearchService.getElementInDependencies(CapabilityType.class, capabilityDefinition.getType(),
/** * From all exposed plugin archives of the location, get the one that are not yet indexed * * @param orchestrator * @param location * @return an object of type {@link ArchiveToIndex} with the indexable archives and the full list of dependencies */ private ArchiveToIndex getArchivesToIndex(Orchestrator orchestrator, Location location) { Set<CSARDependency> dependencies = Sets.newHashSet(); IOrchestratorPlugin orchestratorInstance = (IOrchestratorPlugin) orchestratorPluginService.getOrFail(orchestrator.getId()); ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType()); List<PluginArchive> allPluginArchives = configuratorPlugin.pluginArchives(); Set<PluginArchive> archivesToIndex = Sets.newHashSet(); for (PluginArchive pluginArchive : safe(allPluginArchives)) { ArchiveRoot archive = pluginArchive.getArchive(); Csar csar = csarService.get(archive.getArchive().getName(), archive.getArchive().getVersion()); String lastParsedHash = null; if (csar == null) { // the archive does not exist into the repository: should be indexed lastParsedHash = archive.getArchive().getHash(); archivesToIndex.add(pluginArchive); } else { // Else, just take the hash lastParsedHash = csar.getHash(); } if (archive.getArchive().getDependencies() != null) { dependencies.addAll(archive.getArchive().getDependencies()); } dependencies.add(new CSARDependency(archive.getArchive().getName(), archive.getArchive().getVersion(), lastParsedHash)); } return new ArchiveToIndex(dependencies, archivesToIndex); }
@Test public void testImportDependencyMissing() throws FileNotFoundException, ParsingException { Csar csar = new Csar("tosca-normative-types", "1.0.0-SNAPSHOT-wd03"); Mockito.when(csarRepositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(null); ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-import-dependency.yml")); Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion()); assertNoBlocker(parsingResult); ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); assertNotNull(archiveRoot.getArchive().getDependencies()); Assert.assertEquals(0, archiveRoot.getArchive().getDependencies().size()); }
@Test public void testImportDependency() throws FileNotFoundException, ParsingException { Csar csar = new Csar("tosca-normative-types", "1.0.0-SNAPSHOT-wd03"); Mockito.when(csarRepositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(csar); ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-import-dependency.yml")); Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion()); assertNoBlocker(parsingResult); ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); assertNotNull(archiveRoot.getArchive().getDependencies()); Assert.assertEquals(1, archiveRoot.getArchive().getDependencies().size()); Assert.assertEquals(new CSARDependency(csar.getName(), csar.getVersion()), archiveRoot.getArchive().getDependencies().iterator().next()); }
if (csar.getDependencies() != null) { dependencies.addAll(csar.getDependencies());
@Override protected void processServiceResourceReplacement(Topology topology, Map<String, NodeTemplate> topologyTemplateMap, String nodeId, String serviceResourceId) { ServiceResource serviceResource = getServiceResourceService().getOrFail(serviceResourceId); NodeTemplate serviceNodeTemplate = serviceResource.getNodeInstance().getNodeTemplate(); ServiceNodeTemplate substitutionNodeTemplate = new ServiceNodeTemplate(serviceNodeTemplate.getType(), serviceNodeTemplate.getProperties(), serviceNodeTemplate.getAttributes(), serviceNodeTemplate.getRelationships(), serviceNodeTemplate.getRequirements(), serviceNodeTemplate.getCapabilities(), serviceNodeTemplate.getInterfaces(), serviceNodeTemplate.getArtifacts()); substitutionNodeTemplate.setServiceResourceId(serviceResource.getId()); substitutionNodeTemplate.setAttributeValues(serviceResource.getNodeInstance().getAttributeValues()); NodeTemplate abstractTopologyNode = topologyTemplateMap.put(nodeId, substitutionNodeTemplate); substitutionNodeTemplate.setName(abstractTopologyNode.getName()); substitutionNodeTemplate.setRelationships(abstractTopologyNode.getRelationships()); // add all the necessary dependencies to the topology Csar csar = getToscaTypeSearchService().getArchive(serviceResource.getDependency().getName(), serviceResource.getDependency().getVersion()); Set<CSARDependency> dependencies = Sets.newHashSet(); if (csar.getDependencies() != null) { dependencies.addAll(csar.getDependencies()); } dependencies.add(new CSARDependency(csar.getName(), csar.getVersion())); topology.getDependencies().addAll(dependencies); } }
if (csar.getDependencies() == null) { csar.setDependencies(Sets.newHashSet()); if (csar.getDependencies().add(csarDependencyLoader.buildDependencyBean(nodeType.getArchiveName(), nodeType.getArchiveVersion()))) { updateCsar = true; indexerService.indexInheritableElement(csar.getName(), csar.getVersion(), substituteNodeType, csar.getDependencies());
@Then("^The CSAR \"([^\"]*)\" version \"([^\"]*)\" does not have a dependency to \"([^\"]*)\" version \"([^\"]*)\"$") public void The_csar_version_does_not_depend_on_csar_version(String csarName, String csarVersion, String dependencyName, String dependencyVersion) throws Throwable { String response = Context.getRestClientInstance().get("/rest/v1/csars/" + csarName + ":" + csarVersion); CsarInfoDTO csar = JsonUtil.read(response, CsarInfoDTO.class).getData(); Assert.assertFalse(csar.getCsar().getDependencies().contains(new CSARDependency(dependencyName, dependencyVersion))); }
@Then("^I have the CSAR \"([^\"]*)\" version \"([^\"]*)\" to contain a dependency to \"([^\"]*)\" version \"([^\"]*)\"$") public void I_have_the_CSAR_version_to_contain_a_dependency_to_version(String csarName, String csarVersion, String dependencyName, String dependencyVersion) throws Throwable { String response = Context.getRestClientInstance().get("/rest/v1/csars/" + csarName + ":" + csarVersion + "-SNAPSHOT"); CsarInfoDTO csar = JsonUtil.read(response, CsarInfoDTO.class).getData(); Assert.assertTrue(csar.getCsar().getDependencies().contains(new CSARDependency(dependencyName, dependencyVersion))); }