DefaultTopologyContext(Topology topology, Csar csar) { super(); this.topology = topology; this.dslVersion = csar.getToscaDefinitionsVersion(); }
private CSARDependency getDependencyByName(String dependencyName) { for (CSARDependency d : dependencies) { if (d.getName().equals(dependencyName)) { return d; } } return null; }
/** * Update a dependency according to what is currently in the repository * * @param initialDependency * @return */ private CSARDependency getUpdatedDependencyIfNeeded(CSARDependency initialDependency) { CSARDependency updatedDependency = null; Csar csar = csarService.getOrFail(initialDependency.getName(), initialDependency.getVersion()); if ((StringUtils.isNotBlank(initialDependency.getHash()) || StringUtils.isNotBlank(csar.getHash())) && !Objects.equals(initialDependency.getHash(), csar.getHash())) { updatedDependency = new CSARDependency(csar.getName(), csar.getVersion(), csar.getHash()); } return updatedDependency; }
/** * 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()); }
/** * 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()); }
/** * Add a dependency to the current context. * * @param dependency The dependency to add. */ public void addDependency(CSARDependency dependency) { log.debug("Add dependency to context", dependency); if (dependency.getHash() == null) { // we should try to get the hash from the repository Csar csar = getArchive(dependency.getName(), dependency.getVersion()); dependency.setHash(csar.getHash()); } dependencies.add(dependency); }
/** * 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); }
@Override @ToscaContextual public CSARDependency buildDependencyBean(String name, String version) { CSARDependency newDependency = new CSARDependency(name, version); Csar csar = ToscaContext.get().getArchive(name, version); if (csar != null) { newDependency.setHash(csar.getHash()); } return newDependency; } }
private CsarDependenciesBean initDependencyBeanFromToscaMeta(ToscaMeta toscaMeta) { CsarDependenciesBean csarDependenciesBean = new CsarDependenciesBean(); csarDependenciesBean.setSelf(new CSARDependency(toscaMeta.getName(), toscaMeta.getVersion())); return csarDependenciesBean; }
/** * Get a cloud service archive, or fail with {@link NotFoundException} if not found * * @param name The name of the archive. * @param version The version of the archive. * @return The {@link Csar Cloud Service Archive} if found in the repository. */ public Csar getOrFail(String name, String version) { return getOrFail(Csar.createId(name, version)); }
/** * Set the dependencies of a given csar to the provided set. * <p> * This method will remove ,if present, the provided <b>csar</b> from the provided set of <b>dependencies</b>, to avoid cyclic dependencies on itself. * </p> * Note that no saving operation is perform here * * @param csar: The csar we want to set the dependencies * @param dependencies The provided dependencies to use. */ public void setDependencies(Csar csar, Set<CSARDependency> dependencies) { csar.setDependencies(remove(csar, dependencies)); save(csar); }
@Override public int hashCode() { return archive.getArchive().hashCode(); } }
/** * Save a Cloud Service Archive in ElasticSearch. * * @param csar The csar to save. */ public void save(Csar csar) { // save the csar import date csar.setImportDate(new Date()); this.csarDAO.save(csar); }
@Override public boolean equals(Object obj) { if (obj instanceof PluginArchive) { return archive.getArchive().equals(((PluginArchive) obj).archive.getArchive()); } return false; }
/** * 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); }
@Id public String getId() { return Csar.createId(archiveName, archiveVersion); }
/** * Get the yaml string out of a cloud service archive and topology. * * @param csar The csar that contains archive meta-data. * @param topology The topology template within the archive. * @param generateWorkflow if true, all wf will be generate, if false, only the custom wf will be generate * @return The TOSCA yaml file that describe the topology. */ public String getYaml(Csar csar, Topology topology, boolean generateWorkflow) { return getYaml(csar, topology, generateWorkflow, csar.getToscaDefinitionsVersion()); }
@Id public String getId() { return Csar.createId(applicationId, version); }
@Override public String getDSLVersion() { return archiveRoot.getArchive().getToscaDefinitionsVersion(); }
@Override public Csar getArchive(String archiveName, String archiveVersion) { return searchDAO.findById(Csar.class, Csar.createId(archiveName, archiveVersion)); }