123 lines
4.4 KiB
Java
123 lines
4.4 KiB
Java
package org.gcube.dataanalysys.dataminerpoolmanager.service;
|
|
|
|
***REMOVED***
|
|
import java.util.Collection;
|
|
import java.util.Vector;
|
|
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.ansiblebridge.AnsibleBridge;
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.clients.ISClient;
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.datamodel.Algorithm;
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.datamodel.AlgorithmSet;
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.datamodel.Cluster;
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.datamodel.Dependency;
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.datamodel.Host;
|
|
|
|
public class DataminerPoolManager {
|
|
|
|
***REMOVED*** static Collection<Algorithm> algorithms;
|
|
***REMOVED***
|
|
***REMOVED*** static Collection<AlgorithmSet> sets;
|
|
***REMOVED***
|
|
***REMOVED*** static {
|
|
***REMOVED*** algorithms = new Vector<>();
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** public DataminerPoolManager() {
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** /**
|
|
***REMOVED*** * Add a new algorithm to the set of known ones. No further action is expected
|
|
***REMOVED*** * on the pool.
|
|
***REMOVED*** */
|
|
***REMOVED*** public void publishAlgorithm(Algorithm algorithm) {
|
|
***REMOVED*** algorithms.add(algorithm);
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** /**
|
|
***REMOVED*** * Re-deploy the given algorithm wherever it's installed
|
|
***REMOVED*** *
|
|
***REMOVED*** * @param algorithm
|
|
***REMOVED*** */
|
|
***REMOVED*** /*
|
|
***REMOVED*** * public void updateAlgorithm(Algorithm algorithm) { ***REMOVED*** TODO implement this ***REMOVED***
|
|
***REMOVED*** */
|
|
***REMOVED***
|
|
***REMOVED*** /**
|
|
***REMOVED*** * Add the give algorithm to the given set
|
|
***REMOVED*** *
|
|
***REMOVED*** * @param algorithmId
|
|
***REMOVED*** * @param setId
|
|
***REMOVED*** */
|
|
***REMOVED*** public void addAlgorithmToSet(String algorithmName, String setName) {
|
|
***REMOVED*** AlgorithmSet set = this.getAlgorithmSet(setName);
|
|
***REMOVED*** Algorithm algorithm = this.getAlgorithm(algorithmName);
|
|
***REMOVED*** if (set != null && algorithm != null) {
|
|
***REMOVED*** set.addAlgorithm(algorithm);
|
|
***REMOVED*** this.updateClusters();
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** /**
|
|
***REMOVED*** * Apply the given set of algorithms to the given cluster
|
|
***REMOVED*** *
|
|
***REMOVED*** * @param setId
|
|
***REMOVED*** * @param clusterId
|
|
***REMOVED*** */
|
|
***REMOVED*** public void applyAlgorithmSetToCluster(String setName, String clusterName) {
|
|
***REMOVED*** AlgorithmSet set = this.getAlgorithmSet(setName);
|
|
***REMOVED*** Cluster cluster = new ISClient().getCluster(clusterName);
|
|
***REMOVED*** if (set != null && cluster != null) {
|
|
***REMOVED*** cluster.addAlgorithmSet(set);
|
|
***REMOVED*** this.updateClusters();
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** private AlgorithmSet getAlgorithmSet(String name) {
|
|
***REMOVED*** for (AlgorithmSet set : sets) {
|
|
***REMOVED*** if (name.equals(set.getName())) {
|
|
***REMOVED*** return set;
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** return null;
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED*** private Algorithm getAlgorithm(String name) {
|
|
***REMOVED*** for (Algorithm a : algorithms) {
|
|
***REMOVED*** if (name.equals(a.getName())) {
|
|
***REMOVED*** return a;
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED*** return null;
|
|
***REMOVED*** ***REMOVED***
|
|
|
|
/**
|
|
* Publish the given algorithm in the given VRE
|
|
*
|
|
* @param algorithmName
|
|
* @param vre
|
|
*/
|
|
public void addAlgorithmToVRE(Algorithm algorithm, String vre) throws IOException {
|
|
|
|
***REMOVED*** create a fake algorithm set
|
|
AlgorithmSet algoSet = new AlgorithmSet();
|
|
algoSet.setName("fake");
|
|
algoSet.addAlgorithm(algorithm);
|
|
|
|
this.addAlgorithmsToVRE(algoSet, vre);
|
|
***REMOVED***
|
|
|
|
public void addAlgorithmsToVRE(AlgorithmSet algorithms, String vre) throws IOException {
|
|
|
|
***REMOVED*** create the cluster (dataminers in the vre)
|
|
Cluster cluster = new Cluster();
|
|
for(Host h:new ISClient().listDataminersInVRE()) {
|
|
cluster.addHost(h);
|
|
***REMOVED***
|
|
|
|
***REMOVED*** apply the changes
|
|
new AnsibleBridge().applyAlgorithmSetToCluster(algorithms, cluster);
|
|
|
|
***REMOVED***
|
|
|
|
***REMOVED***
|