package org.gcube.dataanalysis.dataminer.poolmanager.ansiblebridge.template; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; import java.util.Vector; ***REMOVED*** import org.gcube.dataanalysis.dataminer.poolmanager.ansible.model.Role; ***REMOVED*** import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency; ***REMOVED*** ***REMOVED*** public class AlgorithmPackage ***REMOVED*** private Algorithm algorithm; private boolean includeAlgorithmDependencies; private Logger logger; public AlgorithmPackage(Algorithm a,boolean includeAlgorithmDependencies) ***REMOVED*** this.logger = LoggerFactory.getLogger(AlgorithmPackage.class); this.algorithm = a; this.includeAlgorithmDependencies = includeAlgorithmDependencies; ***REMOVED*** protected Map getDictionary(Algorithm a) ***REMOVED*** Map out = new HashMap(); out.put("name", a.getName()); out.put("category", a.getCategory()); out.put("class", a.getClazz()); out.put("atype", a.getAlgorithmType()); out.put("skipjava", a.getSkipJava()); out.put("vre", ScopeProvider.instance.get()); ***REMOVED***out.put("vre", "FAKE_VRE"); out.put("packageurl", a.getPackageURL()); out.put("description", a.getDescription()); String deps = ""; if(includeAlgorithmDependencies)***REMOVED*** for(Dependency d:a.getDependencies()) ***REMOVED*** deps+=String.format("- ***REMOVED*** role: %s ***REMOVED***\n", d.getType()+"-"+d.getName().replaceAll("/", "-")); ***REMOVED******REMOVED*** deps = deps.trim(); out.put("dependencies", deps); return out; ***REMOVED*** protected Algorithm getAlgorithm() ***REMOVED*** return this.algorithm; ***REMOVED*** public Collection getRoles(TemplateManager tm) ***REMOVED*** Collection out = new Vector<>(); for(String mode:new String[]***REMOVED***"add"***REMOVED***) ***REMOVED*** ***REMOVED*** "remove", "update" String roleName = "gcube-algorithm-"+this.getAlgorithm().getName()+("add".equals(mode) ? "" : "-"+mode); try ***REMOVED*** ***REMOVED*** find template Role template = tm.getRoleTemplate("gcube-algorithm-" + mode); ***REMOVED*** if(template!=null) ***REMOVED*** Map dictionary = this.getDictionary(this.getAlgorithm()); Role r = tm.fillRoleTemplate(template, dictionary); r.setName(roleName); out.add(r); ***REMOVED*** else ***REMOVED*** this.logger.warn("WARNING: template is null"); ***REMOVED*** ***REMOVED*** catch (NoSuchElementException e) ***REMOVED*** ***REMOVED*** e.printStackTrace(); this.logger.warn("WARNING: no template found for " + roleName); ***REMOVED*** ***REMOVED*** return out; ***REMOVED*** ***REMOVED***