Skip to content

Commit

Permalink
Fixed workflow command and added support for workflow command in Sche…
Browse files Browse the repository at this point in the history
…duler API
  • Loading branch information
Sandy247 committed Feb 28, 2019
1 parent d5faca7 commit a789b1b
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public interface CompositeCommandBuilder extends InvokableBuilder<CommandRespons
public CompositeCommandBuilder clusterLabel(String clusterLabel);

public CompositeCommandBuilder addSubCommand(BaseCommand command);

public BaseCommand build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package com.qubole.qds.sdk.java.api;

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 java.util.List;
import java.util.Map;

Expand All @@ -26,6 +28,8 @@ public interface CreateScheduleCommandBuilder

public CreateScheduleCommandBuilder command(ScheduleCommand command);

public CreateScheduleCommandBuilder compositecommand(CompositeScheduleCommand command);

public CreateScheduleCommandBuilder macros(List<Map<String, String>> macros);

public CreateScheduleCommandBuilder start_time(String start_time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Map<String, String>> macros)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public InvokableBuilder<Schedule> edit(String scheduleId, CreateScheduleCommandB
@Override
public InvokableBuilder<Schedule> create(CreateScheduleCommandBuilder configBuilder)
{
System.out.println("Request : " + configBuilder.toString());
RequestDetails entity = new RequestDetails(configBuilder.toString(), RequestDetails.Method.POST);
return new GenericInvokableBuilderImpl<Schedule>(client, entity, Schedule.class, "scheduler");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.qubole.qds.sdk.java.entities;

import java.util.List;

public class CompositeScheduleCommand {

private List<ScheduleCommand> sub_commands;

private CompositeScheduleCommand(List<ScheduleCommand> sub_commands){
this.sub_commands = sub_commands;
}

public static CompositeScheduleCommand getCompositeScheduleCommand(List<ScheduleCommand> sub_commands)
{
return new CompositeScheduleCommand(sub_commands);
}

public List<ScheduleCommand> getSub_commands() {
return sub_commands;
}

public void setSub_commands(List<ScheduleCommand> subcommands) {
this.sub_commands = subcommands;
}
}
164 changes: 95 additions & 69 deletions src/main/java/com/qubole/qds/sdk/java/entities/ScheduleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,110 +18,136 @@
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;
private String script_location;
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public SubCommands deserialize(JsonParser jp, DeserializationContext ctxt)
Map.Entry<String, JsonNode> 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);
}
Expand Down

0 comments on commit a789b1b

Please sign in to comment.