From a789b1bbab99159d62110983a60787beece51be0 Mon Sep 17 00:00:00 2001 From: Sandy247 Date: Thu, 28 Feb 2019 15:09:03 +0530 Subject: [PATCH] Fixed workflow command and added support for workflow command in Scheduler API --- .../sdk/java/api/CompositeCommandBuilder.java | 2 + .../api/CreateScheduleCommandBuilder.java | 4 + .../CreateScheduleCommandBuilderImpl.java | 11 +- .../sdk/java/details/SchedulerApiImpl.java | 1 + .../entities/CompositeScheduleCommand.java | 25 +++ .../sdk/java/entities/ScheduleCommand.java | 164 ++++++++++-------- .../entities/SubCommandsDeserializer.java | 3 +- 7 files changed, 139 insertions(+), 71 deletions(-) create mode 100644 src/main/java/com/qubole/qds/sdk/java/entities/CompositeScheduleCommand.java diff --git a/src/main/java/com/qubole/qds/sdk/java/api/CompositeCommandBuilder.java b/src/main/java/com/qubole/qds/sdk/java/api/CompositeCommandBuilder.java index e40bf38d..5a360f22 100644 --- a/src/main/java/com/qubole/qds/sdk/java/api/CompositeCommandBuilder.java +++ b/src/main/java/com/qubole/qds/sdk/java/api/CompositeCommandBuilder.java @@ -27,4 +27,6 @@ public interface CompositeCommandBuilder extends InvokableBuilder> macros); public CreateScheduleCommandBuilder start_time(String start_time); diff --git a/src/main/java/com/qubole/qds/sdk/java/details/CreateScheduleCommandBuilderImpl.java b/src/main/java/com/qubole/qds/sdk/java/details/CreateScheduleCommandBuilderImpl.java index eb826f6b..89ff046c 100644 --- a/src/main/java/com/qubole/qds/sdk/java/details/CreateScheduleCommandBuilderImpl.java +++ b/src/main/java/com/qubole/qds/sdk/java/details/CreateScheduleCommandBuilderImpl.java @@ -16,9 +16,11 @@ package com.qubole.qds.sdk.java.details; import com.qubole.qds.sdk.java.api.CreateScheduleCommandBuilder; +import com.qubole.qds.sdk.java.entities.CompositeScheduleCommand; import com.qubole.qds.sdk.java.entities.DependencyInfo; -import com.qubole.qds.sdk.java.entities.ScheduleCommand; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.qubole.qds.sdk.java.entities.ScheduleCommand; + import java.io.IOException; import java.util.List; import java.util.Map; @@ -41,6 +43,13 @@ public CreateScheduleCommandBuilder command(ScheduleCommand command) return this; } + @Override + public CreateScheduleCommandBuilder compositecommand(CompositeScheduleCommand command) + { + node.putPOJO("command", command); + return this; + } + @Override public CreateScheduleCommandBuilder macros(List> macros) { diff --git a/src/main/java/com/qubole/qds/sdk/java/details/SchedulerApiImpl.java b/src/main/java/com/qubole/qds/sdk/java/details/SchedulerApiImpl.java index 107d2398..0a3a5782 100644 --- a/src/main/java/com/qubole/qds/sdk/java/details/SchedulerApiImpl.java +++ b/src/main/java/com/qubole/qds/sdk/java/details/SchedulerApiImpl.java @@ -95,6 +95,7 @@ public InvokableBuilder edit(String scheduleId, CreateScheduleCommandB @Override public InvokableBuilder create(CreateScheduleCommandBuilder configBuilder) { + System.out.println("Request : " + configBuilder.toString()); RequestDetails entity = new RequestDetails(configBuilder.toString(), RequestDetails.Method.POST); return new GenericInvokableBuilderImpl(client, entity, Schedule.class, "scheduler"); } diff --git a/src/main/java/com/qubole/qds/sdk/java/entities/CompositeScheduleCommand.java b/src/main/java/com/qubole/qds/sdk/java/entities/CompositeScheduleCommand.java new file mode 100644 index 00000000..ce0e5811 --- /dev/null +++ b/src/main/java/com/qubole/qds/sdk/java/entities/CompositeScheduleCommand.java @@ -0,0 +1,25 @@ +package com.qubole.qds.sdk.java.entities; + +import java.util.List; + +public class CompositeScheduleCommand { + + private List sub_commands; + + private CompositeScheduleCommand(List sub_commands){ + this.sub_commands = sub_commands; + } + + public static CompositeScheduleCommand getCompositeScheduleCommand(List sub_commands) + { + return new CompositeScheduleCommand(sub_commands); + } + + public List getSub_commands() { + return sub_commands; + } + + public void setSub_commands(List subcommands) { + this.sub_commands = subcommands; + } +} diff --git a/src/main/java/com/qubole/qds/sdk/java/entities/ScheduleCommand.java b/src/main/java/com/qubole/qds/sdk/java/entities/ScheduleCommand.java index d499b70f..4763ab10 100644 --- a/src/main/java/com/qubole/qds/sdk/java/entities/ScheduleCommand.java +++ b/src/main/java/com/qubole/qds/sdk/java/entities/ScheduleCommand.java @@ -18,10 +18,11 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) -public class ScheduleCommand -{ +public class ScheduleCommand { private boolean approx_mode; private String query; + private String inline; + private String command_type; private boolean approx_aggregations; private boolean sample; private String loader_stable; @@ -29,99 +30,124 @@ public class ScheduleCommand private String loader_table_name; private String md_cmd; - public ScheduleCommand() - { - } - - public ScheduleCommand(boolean approx_mode, String query, boolean approx_aggregations, boolean sample, String loader_stable, String script_location, String loader_table_name, String md_cmd) - { - this.approx_mode = approx_mode; - this.query = query; - this.approx_aggregations = approx_aggregations; - this.sample = sample; - this.loader_stable = loader_stable; - this.script_location = script_location; - this.loader_table_name = loader_table_name; - this.md_cmd = md_cmd; - } - - public boolean isApprox_mode() - { + public static class ScheduleCommandBuilder { + private final String query; + private String command_type = null; + private boolean approx_mode = false; + private boolean approx_aggregations = false; + private boolean sample = false; + private String loader_stable = null; + private String script_location = null; + private String loader_table_name = null; + private String md_cmd = null; + + public ScheduleCommandBuilder(String query) { + this.query = query; + } + + public ScheduleCommandBuilder command_type(String command_type) { + this.command_type = command_type; + return this; + } + + public ScheduleCommandBuilder approx_mode(boolean approx_mode) { + this.approx_mode = approx_mode; + return this; + } + + public ScheduleCommandBuilder approx_aggregations(boolean approx_aggregations) { + this.approx_aggregations = approx_aggregations; + return this; + } + + public ScheduleCommandBuilder sample(boolean sample) { + this.sample = sample; + return this; + } + + public ScheduleCommandBuilder loader_stable(String loader_stable) { + this.loader_stable = loader_stable; + return this; + } + + public ScheduleCommandBuilder script_location(String script_location) { + this.script_location = script_location; + return this; + } + + public ScheduleCommandBuilder loader_table_name(String loader_table_name) { + this.loader_table_name = loader_table_name; + return this; + } + + public ScheduleCommandBuilder md_cmd(String md_cmd) { + this.md_cmd = md_cmd; + return this; + } + + public ScheduleCommand build() { + return new ScheduleCommand(this); + } + } + + public ScheduleCommand(){} + private ScheduleCommand(ScheduleCommandBuilder builder) { + query = builder.query; + command_type = builder.command_type; + approx_mode = builder.approx_mode; + approx_aggregations = builder.approx_aggregations; + sample = builder.sample; + loader_stable = builder.loader_stable; + script_location = builder.script_location; + loader_table_name = builder.loader_table_name; + md_cmd = builder.md_cmd; + + if (command_type.equalsIgnoreCase("shellcommand")) + { + inline = query; + query = null; + } + } + + + public boolean isApprox_mode() { return approx_mode; } - public void setApprox_mode(boolean approx_mode) - { - this.approx_mode = approx_mode; + public String getCommand_type() { + return command_type; } - public String getQuery() - { + public String getQuery() { return query; } - public void setQuery(String query) + public String getInline() { - this.query = query; + return inline; } - public boolean isApprox_aggregations() - { + public boolean isApprox_aggregations() { return approx_aggregations; } - public void setApprox_aggregations(boolean approx_aggregations) - { - this.approx_aggregations = approx_aggregations; - } - - public boolean isSample() - { + public boolean isSample() { return sample; } - public void setSample(boolean sample) - { - this.sample = sample; - } - - public String getLoader_stable() - { + public String getLoader_stable() { return loader_stable; } - public void setLoader_stable(String loader_stable) - { - this.loader_stable = loader_stable; - } - - public String getScript_location() - { + public String getScript_location() { return script_location; } - public void setScript_location(String script_location) - { - this.script_location = script_location; - } - - public String getLoader_table_name() - { + public String getLoader_table_name() { return loader_table_name; } - public void setLoader_table_name(String loader_table_name) - { - this.loader_table_name = loader_table_name; - } - - public String getMd_cmd() - { + public String getMd_cmd() { return md_cmd; } - - public void setMd_cmd(String md_cmd) - { - this.md_cmd = md_cmd; - } } diff --git a/src/main/java/com/qubole/qds/sdk/java/entities/SubCommandsDeserializer.java b/src/main/java/com/qubole/qds/sdk/java/entities/SubCommandsDeserializer.java index 7cee03fe..f017865b 100644 --- a/src/main/java/com/qubole/qds/sdk/java/entities/SubCommandsDeserializer.java +++ b/src/main/java/com/qubole/qds/sdk/java/entities/SubCommandsDeserializer.java @@ -57,8 +57,9 @@ public SubCommands deserialize(JsonParser jp, DeserializationContext ctxt) Map.Entry element = elementsIterator.next(); String name = element.getKey(); JsonNode val = element.getValue(); + // System.out.println("Name = " + name + ";Value = " + val); if (name.equalsIgnoreCase("sub_commands")) { - Command[] subCommands = mapper.readValue(jp, Command[].class); + Command[] subCommands = mapper.treeToValue(val, Command[].class); if (subCommands != null) { compositeCommand.setsub_commands(subCommands); }