diff --git a/src/main/java/com/etsy/arbiter/Action.java b/src/main/java/com/etsy/arbiter/Action.java index 80c65af..41a4755 100644 --- a/src/main/java/com/etsy/arbiter/Action.java +++ b/src/main/java/com/etsy/arbiter/Action.java @@ -25,6 +25,7 @@ */ public class Action { private String name; + private String cred; private String type; private String forceOk; private String forceError; @@ -40,7 +41,15 @@ public String getName() { public void setName(String name) { this.name = name; } + + public String getCred() { + return cred; + } + public void setCred(String cred) { + this.cred = cred; + } + public String getType() { return type; } @@ -126,6 +135,9 @@ public boolean equals(Object o) { if (name != null ? !name.equals(action.name) : action.name != null) { return false; } + if (cred != null ? !cred.equals(action.cred) : action.cred != null) { + return false; + } if (type != null ? !type.equals(action.type) : action.type != null) { return false; } @@ -151,6 +163,7 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; + result = 31 * result + (cred != null ? cred.hashCode() : 0); result = 31 * result + (type != null ? type.hashCode() : 0); result = 31 * result + (forceOk != null ? forceOk.hashCode() : 0); result = 31 * result + (forceError != null ? forceError.hashCode() : 0); @@ -165,6 +178,7 @@ public int hashCode() { public String toString() { return "Action{" + "name='" + name + '\'' + + ", cred='" + cred + '\'' + ", type='" + type + '\'' + ", forceOk='" + forceOk + '\'' + ", forceError='" + forceError + '\'' + diff --git a/src/main/java/com/etsy/arbiter/Credential.java b/src/main/java/com/etsy/arbiter/Credential.java new file mode 100644 index 0000000..5632d32 --- /dev/null +++ b/src/main/java/com/etsy/arbiter/Credential.java @@ -0,0 +1,38 @@ +package com.etsy.arbiter; + +import java.util.Map; +/** + * Represents Credential type in Oozie workflow + * + * @author venky + */ +public class Credential { + private String name; + private String type; + private Map configurationProperties; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Map getConfigurationProperties() { + return configurationProperties; + } + + public void setConfigurationProperties(Map configurationProperties) { + this.configurationProperties = configurationProperties; + } + +} diff --git a/src/main/java/com/etsy/arbiter/OozieWorkflowGenerator.java b/src/main/java/com/etsy/arbiter/OozieWorkflowGenerator.java index fc82452..e0cd39b 100644 --- a/src/main/java/com/etsy/arbiter/OozieWorkflowGenerator.java +++ b/src/main/java/com/etsy/arbiter/OozieWorkflowGenerator.java @@ -106,7 +106,8 @@ public void generateOozieWorkflows(String outputBase, List workflows, Document xmlDoc = builder.newDocument(); Directives directives = new Directives(); - createRootElement(workflow.getName(), directives); + createRootElement(workflow.getName(), workflow.getXmlns(), directives); + addCredentials(workflow.getCredentials(), directives); Action kill = getActionByType(workflowGraph, "kill"); Action end = getActionByType(workflowGraph, "end"); @@ -180,8 +181,45 @@ public void generateOozieWorkflows(String outputBase, List workflows, writeDocument(outputDirFile, xmlDoc, transformer, workflow.getName(), currentDateString); } } - + /** + * Add the Credential element to Oozie workflow + * + * @param credentials List of credential elements to be added to workflow + * @param directives The Xembly Directives object to which to add the new XML elements + * + * @author venky + */ + private void addCredentials(List credentials, Directives directives) { + if (credentials == null || credentials.isEmpty()) + return; + directives.add("credentials"); + for (Credential credential : credentials) { + ActionType type = getActionType(credential.getType()); + + Map mergedConfigurationProperties = new HashMap<>(type.getProperties()); + if (credential.getConfigurationProperties() != null) { + mergedConfigurationProperties.putAll(credential.getConfigurationProperties()); + } + directives.add("credential") + .attr("name", credential.getName()) + .attr("type", type.getTag()); + for (Map.Entry entry : mergedConfigurationProperties.entrySet()) { + directives.add("property") + .add("name") + .set(entry.getKey()) + .up() + .add("value") + .set(entry.getValue()) + .up() + .up(); + } + directives.up(); + } + directives.up(); + } + + /** * Add the XML element for an action * * @param action The action for which to add the element @@ -194,9 +232,12 @@ private void createActionElement(Action action, DirectedAcyclicGraph credentials; private List actions; private Action errorHandler; @@ -54,8 +56,24 @@ public String getName() { public void setName(String name) { this.name = name; } + + public String getXmlns() { + return xmlns; + } + + public void setXmlns(String xmlns) { + this.xmlns = xmlns; + } + + public List getCredentials() { + return credentials; + } + + public void setCredentials(List credentials) { + this.credentials = credentials; + } - public List getActions() { + public List getActions() { return actions; } @@ -85,12 +103,18 @@ public boolean equals(Object o) { if (actions != null ? !actions.equals(workflow.actions) : workflow.actions != null) { return false; } + if (credentials != null ? !credentials.equals(workflow.credentials) : workflow.credentials != null) { + return false; + } if (errorHandler != null ? !errorHandler.equals(workflow.errorHandler) : workflow.errorHandler != null) { return false; } if (name != null ? !name.equals(workflow.name) : workflow.name != null) { return false; } + if (xmlns != null ? !xmlns.equals(workflow.xmlns) : workflow.xmlns != null) { + return false; + } return true; } @@ -98,6 +122,8 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; + result = 31 * result + (xmlns != null ? xmlns.hashCode() : 0); + result = 31 * result + (credentials != null ? credentials.hashCode() : 0); result = 31 * result + (actions != null ? actions.hashCode() : 0); result = 31 * result + (errorHandler != null ? errorHandler.hashCode() : 0); return result; @@ -107,6 +133,8 @@ public int hashCode() { public String toString() { return "Workflow{" + "name='" + name + '\'' + + ", xmlns=" + xmlns + + ", credentials=" + credentials + ", actions=" + actions + ", errorHandler=" + errorHandler + '}';