108 lines
3.2 KiB
Java
108 lines
3.2 KiB
Java
package org.gcube.dataanalysys.dataminerpoolmanager.ansible;
|
|
|
|
import java.io.File;
|
|
***REMOVED***
|
|
import java.util.UUID;
|
|
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.ansible.model.Inventory;
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.ansible.model.Playbook;
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.ansible.model.Role;
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.ansible.model.RoleFile;
|
|
import org.gcube.dataanalysys.dataminerpoolmanager.ansiblebridge.AnsibleSerializeHelper;
|
|
|
|
/**
|
|
* This class is responsible for the interface with ansible, retrieving log,
|
|
* etc. etc. It's not supposed to access templates and static stuff files. It
|
|
* does not know the service datamodel.
|
|
*
|
|
* @author paolo
|
|
*
|
|
*/
|
|
public class AnsibleWorker ***REMOVED***
|
|
|
|
/**
|
|
* The name of the inventory
|
|
*/
|
|
private static String INVENTORY_NAME = "inventory.yaml";
|
|
|
|
/**
|
|
* The directory containing roles
|
|
*/
|
|
private static String ROLES_DIR = "roles";
|
|
|
|
/**
|
|
* The name of the playbook
|
|
*/
|
|
private static String PLAYBOOK_NAME = "playbook.yaml";
|
|
|
|
/**
|
|
* The root of the worker. This corresponds to a standard ansible working dir.
|
|
*/
|
|
private File workerRoot;
|
|
|
|
public AnsibleWorker(File root) ***REMOVED***
|
|
this.workerRoot = root;
|
|
this.ensureWorkStructure();
|
|
***REMOVED***
|
|
|
|
private File getWorkdir() ***REMOVED***
|
|
return this.workerRoot;
|
|
***REMOVED***
|
|
|
|
private File getRolesDir() ***REMOVED***
|
|
return new File(this.getWorkdir(), ROLES_DIR);
|
|
***REMOVED***
|
|
|
|
public String getWorkerId() ***REMOVED***
|
|
return this.workerRoot.getName();
|
|
***REMOVED***
|
|
|
|
private void ensureWorkStructure() ***REMOVED***
|
|
***REMOVED*** generate root
|
|
this.getWorkdir().mkdirs();
|
|
***REMOVED***
|
|
|
|
private void removeWorkStructure() ***REMOVED***
|
|
***REMOVED*** remove the working dir
|
|
***REMOVED*** this.getWorkdir().delete();
|
|
***REMOVED***
|
|
|
|
public File getPlaybookFile() ***REMOVED***
|
|
return new File(this.getWorkdir(), PLAYBOOK_NAME);
|
|
***REMOVED***
|
|
|
|
public File getInventoryFile() ***REMOVED***
|
|
return new File(this.getWorkdir(), INVENTORY_NAME);
|
|
***REMOVED***
|
|
|
|
|
|
public void setInventory(Inventory inventory) throws IOException ***REMOVED***
|
|
***REMOVED*** serialize the string to the 'inventory' file
|
|
AnsibleSerializeHelper.serialize(inventory, this.getInventoryFile());
|
|
***REMOVED***
|
|
|
|
public void setPlaybook(Playbook playbook) throws IOException ***REMOVED***
|
|
***REMOVED*** serialize the string to the 'playbook' file
|
|
AnsibleSerializeHelper.serialize(playbook, this.getPlaybookFile());
|
|
***REMOVED***
|
|
|
|
public void addRole(Role r) throws IOException ***REMOVED***
|
|
***REMOVED*** Serialize role in the workdir
|
|
AnsibleSerializeHelper.serializeRole(r, this.getRolesDir());
|
|
***REMOVED***
|
|
|
|
public void apply() ***REMOVED***
|
|
***REMOVED*** TODO execute the playbook and return output
|
|
System.out.println("TODO: execute: ansible-playbook -v -i " + this.getInventoryFile().getName() + " " + this.getPlaybookFile().getName());
|
|
***REMOVED***
|
|
|
|
/**
|
|
* Destroy the worker:
|
|
* - remove the working dir
|
|
*/
|
|
public void destroy() ***REMOVED***
|
|
this.removeWorkStructure();
|
|
***REMOVED***
|
|
|
|
***REMOVED***
|