package org.gcube.dataanalysys.dataminerpoolmanager.ansiblebridge.template; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; import java.util.Vector; import org.gcube.dataanalysys.dataminerpoolmanager.ansible.model.Role; import org.gcube.dataanalysys.dataminerpoolmanager.ansible.model.RoleFile; import org.gcube.dataanalysys.dataminerpoolmanager.datamodel.Algorithm; import org.gcube.dataanalysys.dataminerpoolmanager.datamodel.Dependency; public class AlgorithmPackage ***REMOVED*** private Algorithm algorithm; public AlgorithmPackage(Algorithm a) ***REMOVED*** this.algorithm = a; ***REMOVED*** protected Map getDictionary(Algorithm a) ***REMOVED*** Map out = new HashMap(); out.put("name", a.getName()); String deps = ""; for(Dependency d:a.getDependencies()) ***REMOVED*** deps+=String.format("- ***REMOVED*** role: %s ***REMOVED***\n", d.getType()+"-"+d.getName()); ***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*** System.out.println("WARNING: template is null"); ***REMOVED*** ***REMOVED*** catch (NoSuchElementException e) ***REMOVED*** ***REMOVED*** e.printStackTrace(); System.out.println("WARNING: no template found for " + roleName); ***REMOVED*** ***REMOVED*** return out; ***REMOVED*** ***REMOVED***