Skip to content
This repository was archived by the owner on Mar 4, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/com/etsy/arbiter/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
public class Action {
private String name;
private String cred;
private String type;
private String forceOk;
private String forceError;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -165,6 +178,7 @@ public int hashCode() {
public String toString() {
return "Action{" +
"name='" + name + '\'' +
", cred='" + cred + '\'' +
", type='" + type + '\'' +
", forceOk='" + forceOk + '\'' +
", forceError='" + forceError + '\'' +
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/etsy/arbiter/Credential.java
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<String, String> getConfigurationProperties() {
return configurationProperties;
}

public void setConfigurationProperties(Map<String, String> configurationProperties) {
this.configurationProperties = configurationProperties;
}

}
56 changes: 49 additions & 7 deletions src/main/java/com/etsy/arbiter/OozieWorkflowGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public void generateOozieWorkflows(String outputBase, List<Workflow> 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");
Expand Down Expand Up @@ -180,8 +181,45 @@ public void generateOozieWorkflows(String outputBase, List<Workflow> 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<Credential> credentials, Directives directives) {
if (credentials == null || credentials.isEmpty())
return;
directives.add("credentials");
for (Credential credential : credentials) {
ActionType type = getActionType(credential.getType());

Map<String, String> 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<String, String> 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
Expand All @@ -194,9 +232,12 @@ private void createActionElement(Action action, DirectedAcyclicGraph<Action, Def
ActionType type = getActionType(action.getType());

directives.add("action")
.attr("name", action.getName())
.add(type.getTag());

.attr("name", action.getName());
if (action.getCred() != null) {
directives.attr("cred", action.getCred());
}
directives.add(type.getTag());

if (type.getXmlns() != null) {
directives.attr("xmlns", type.getXmlns());
}
Expand Down Expand Up @@ -414,11 +455,12 @@ private void writeDocument(File outputDir, Document xmlDoc, Transformer transfor
* Create the root XML element
*
* @param name The name of the root element
* @param xmlns
* @param directives The Xembly Directives object to which to add the root element
*/
private void createRootElement(String name, Directives directives) {
private void createRootElement(String name, String xmlns, Directives directives) {
directives.add("workflow-app")
.attr("xmlns", "uri:oozie:workflow:0.2")
.attr("xmlns", xmlns)
.attr("name", name);
}

Expand Down
32 changes: 30 additions & 2 deletions src/main/java/com/etsy/arbiter/Workflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ public static Constructor getYamlConstructor() {
Constructor workflowConstructor = new Constructor(Workflow.class);
TypeDescription workflowDescription = new TypeDescription(Workflow.class);
workflowDescription.putListPropertyType("actions", Action.class);
workflowDescription.putListPropertyType("credentials", Credential.class);
workflowConstructor.addTypeDescription(workflowDescription);

return workflowConstructor;
}

private String name;

private String xmlns;
private List<Credential> credentials;
private List<Action> actions;

private Action errorHandler;
Expand All @@ -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<Credential> getCredentials() {
return credentials;
}

public void setCredentials(List<Credential> credentials) {
this.credentials = credentials;
}

public List<Action> getActions() {
public List<Action> getActions() {
return actions;
}

Expand Down Expand Up @@ -85,19 +103,27 @@ 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;
}

@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;
Expand All @@ -107,6 +133,8 @@ public int hashCode() {
public String toString() {
return "Workflow{" +
"name='" + name + '\'' +
", xmlns=" + xmlns +
", credentials=" + credentials +
", actions=" + actions +
", errorHandler=" + errorHandler +
'}';
Expand Down