/** * remove a csar from a set of dependencies * * @param csar * @param from * @return */ private Set<CSARDependency> remove(Csar csar, Set<CSARDependency> from) { CSARDependency toRemove = new CSARDependency(csar.getName(), csar.getVersion()); return from == null ? null : from.stream().filter(csarDependency -> !Objects.equals(toRemove, csarDependency)).collect(Collectors.toSet()); }
private void checkNotReleased(Csar archive) { if (archive != null && !VersionUtil.isSnapshot(archive.getVersion())) { throw new AlreadyExistException("CSAR: " + archive.getName() + ", Version: " + archive.getVersion() + " already exists in the repository."); } }
private void checkNotUsedInActiveDeployment(Csar csar) throws CSARUsedInActiveDeployment { if (csar != null && deploymentService.isArchiveDeployed(csar.getName(), csar.getVersion())) { throw new CSARUsedInActiveDeployment("CSAR: " + csar.getName() + ", Version: " + csar.getVersion() + " is used in an active deployment."); } }
@ApiOperation(value = "Download a CSAR given its id.", notes = "Returns zipped content of a CSAR.") @RequestMapping(value = "/{csarId:.+?}/download", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) @PreAuthorize("isAuthenticated()") @SneakyThrows public ResponseEntity<InputStreamResource> download(@PathVariable String csarId) { Csar csar = csarService.getOrFail(csarId); csarAuthorizationFilter.checkReadAccess(csar); Path csarToDownload = archiveRepositry.getCSAR(csar.getName(), csar.getVersion()); return ResponseEntity.ok().contentLength(csarToDownload.toFile().length()).contentType(MediaType.APPLICATION_OCTET_STREAM) .body(new InputStreamResource(Files.newInputStream(csarToDownload))); }
/** * Get the git history for a given archive. * * @param csar The archive under edition. * @param from Start to query from the given history. * @param count The number of history entries to retrieve. * @return A list of simplified history entries. */ public List<SimpleGitHistoryEntry> getHistory(Csar csar, int from, int count) { Path archiveGitPath = csarRepositry.getExpandedCSAR(csar.getName(), csar.getVersion()); return RepositoryManager.getHistory(archiveGitPath, from, count); }
/** * Set a remote repository. * * @param csar The archive for which to set the remote. * @param remoteName The remote name. * @param remoteUrl The repository url. */ public void setRemote(Csar csar, String remoteName, String remoteUrl) { Path archiveGitPath = csarRepositry.getExpandedCSAR(csar.getName(), csar.getVersion()); RepositoryManager.setRemote(archiveGitPath, remoteName, remoteUrl); }
/** * Push modifications to git repository. * * @param csar The concerned archive. * @param username The username of the git repository, null if none. * @param password The password of the git repository, null if none. * @param remoteBranch The name of the remote branch to push to. */ public void push(Csar csar, String username, String password, String remoteBranch) { Path archiveGitPath = csarRepositry.getExpandedCSAR(csar.getName(), csar.getVersion()); RepositoryManager.push(archiveGitPath, username, password, remoteBranch); }
/** * Get the url of the remote git repository. * * @param csar The concerned archive. * @param remoteName The name of the remote * @return The url corresponding to the remote name. */ public String getRemoteUrl(Csar csar, String remoteName) { Path archiveGitPath = csarRepositry.getExpandedCSAR(csar.getName(), csar.getVersion()); return RepositoryManager.getRemoteUrl(archiveGitPath, remoteName); }
public void copy(Path path, Csar csar) throws IOException { Path archiveGitPath = csarRepositry.getExpandedCSAR(csar.getName(), csar.getVersion()); FileUtil.copy(archiveGitPath, path); }
private static void setArtifactToCorrectArchiveReference(AbstractArtifact artifact, Topology topology, Csar csar) { if (topology.getArchiveName().equals(artifact.getArchiveName()) && topology.getArchiveVersion().equals(artifact.getArchiveVersion())) { // Must migrate to new reference artifact.setArchiveName(csar.getName()); artifact.setArchiveVersion(csar.getVersion()); } }
/** * 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()); }
private void saveYamlAndZipFile() throws IOException { // Update the yaml in the archive Csar csar = EditionContextManager.getCsar(); Path targetPath = EditionContextManager.get().getLocalGitPath().resolve(csar.getYamlFilePath()); String yaml = exportService.getYaml(csar, EditionContextManager.getTopology()); try (BufferedWriter writer = Files.newBufferedWriter(targetPath)) { writer.write(yaml); } // Update the archive zip for download repositoryService.updateArchiveZip(EditionContextManager.getCsar().getName(), EditionContextManager.getCsar().getVersion()); }
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())); }
/** * Delete an archive if no topology depends from it. * * @param csarId The id of the archive to delete. * @throws DeleteReferencedObjectException If the csar is a dependency of another csar or topology */ public void deleteCsar(String csarId) { Csar csar = getOrFail(csarId); // a csar that is a dependency of another csar can not be deleted if (isDependency(csar.getName(), csar.getVersion())) { throw new DeleteReferencedObjectException("This csar can not be deleted since it's a dependencie for others"); } deleteCsar(csar); }
@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); } }
@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()); }
private void processTopology(String workspace, ParsingResult<ArchiveRoot> parsedArchive) { Topology topology = parsedArchive.getResult().getTopology(); if (topology != null) { topology.setArchiveName(parsedArchive.getResult().getArchive().getName()); topology.setArchiveVersion(parsedArchive.getResult().getArchive().getVersion()); topology.setWorkspace(workspace); } }
@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()); }
@Override public void process(Csar csar, Topology topology, RemoveSubstitutionTypeOperation operation) { if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) { throw new NotFoundException("No substitution type has been found"); } // FIXME check also on live edited topologies. // the substitute type os within the topology's archive if (hasArchiveUsing(csar.getName(), csar.getVersion())) { throw new DeleteReferencedObjectException("The substitution can not be removed since it's type is already used in at least another topology"); } topologyService.unloadType(topology, topology.getSubstitutionMapping().getSubstitutionType()); topology.setSubstitutionMapping(null); }
@Test public void testRootCategories() throws FileNotFoundException, ParsingException { ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-root-categories.yml")); assertNoBlocker(parsingResult); ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion()); Assert.assertEquals("Tosca default namespace value", archiveRoot.getArchive().getToscaDefaultNamespace()); Assert.assertEquals("Template name value", archiveRoot.getArchive().getName()); Assert.assertEquals("Temlate author value", archiveRoot.getArchive().getTemplateAuthor()); Assert.assertEquals("1.0.0-SNAPSHOT", archiveRoot.getArchive().getVersion()); Assert.assertEquals("This is an example of a single line description (no folding).", archiveRoot.getArchive().getDescription()); }