Skip to content

Commit

Permalink
Merge pull request #7 from qubole/ISSUE-6
Browse files Browse the repository at this point in the history
Issue #6 - Support optional inline for command results
  • Loading branch information
Randgalt committed May 20, 2014
2 parents 73b7013 + cac9059 commit 0a53446
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/qubole/qds/sdk/java/api/CommandApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.qubole.qds.sdk.java.entities.Command;
import com.qubole.qds.sdk.java.entities.Commands;
import com.qubole.qds.sdk.java.entities.ResultValue;
import javax.ws.rs.core.Response;

/**
Expand Down Expand Up @@ -87,7 +86,7 @@ public interface CommandApi
* @param queryId the query id of the command
* @return new builder
*/
public InvokableBuilder<ResultValue> results(String queryId);
public ResultsCommandBuilder results(String queryId);

/**
* Corresponds to http://www.qubole.com/docs/view-command-logs/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.qubole.qds.sdk.java.api;

import com.qubole.qds.sdk.java.entities.ResultValue;

public interface ResultsCommandBuilder extends InvokableBuilder<ResultValue>
{
public InvokableBuilder<ResultValue> inline(Boolean value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.qubole.qds.sdk.java.client.QdsClient;
import com.qubole.qds.sdk.java.entities.Command;
import com.qubole.qds.sdk.java.entities.Commands;
import com.qubole.qds.sdk.java.entities.ResultValue;
import com.qubole.qds.sdk.java.entities.Status;
import javax.ws.rs.core.Response;

Expand Down Expand Up @@ -36,9 +35,9 @@ public InvokableBuilder<Command> status(String queryId)
}

@Override
public InvokableBuilder<ResultValue> results(String queryId)
public ResultsCommandBuilder results(String queryId)
{
return new GenericInvokableBuilderImpl<ResultValue>(client, null, ResultValue.class, "commands", queryId, "results");
return new ResultsCommandBuilderImpl(client, queryId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.qubole.qds.sdk.java.details;

import com.google.common.collect.Maps;
import com.qubole.qds.sdk.java.api.InvokableBuilder;
import com.qubole.qds.sdk.java.api.ResultsCommandBuilder;
import com.qubole.qds.sdk.java.client.QdsClient;
import com.qubole.qds.sdk.java.entities.ResultValue;
import java.util.Map;
import java.util.concurrent.Future;

class ResultsCommandBuilderImpl extends InvocationCallbackBase<ResultValue> implements ResultsCommandBuilder
{
private final QdsClient client;
private final String queryId;
private Boolean inline;

@Override
public InvokableBuilder<ResultValue> inline(Boolean value)
{
inline = value;
return this;
}

@Override
public Future<ResultValue> invoke()
{
ClientEntity entity = null;
if ( inline != null )
{
Map<String, String> queryParams = Maps.newHashMap();
queryParams.put("inline", inline.toString());
entity = new ClientEntity(null, ClientEntity.Method.GET, queryParams);
}
return invokeRequest(client, null, entity, ResultValue.class, "commands", queryId, "results");
}

ResultsCommandBuilderImpl(QdsClient client, String queryId)
{
this.client = client;
this.queryId = queryId;
}
}
12 changes: 4 additions & 8 deletions src/test/java/com/qubole/qds/sdk/java/Tester.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.qubole.qds.sdk.java;

import com.google.common.io.ByteStreams;
import com.qubole.qds.sdk.java.client.DefaultQdsConfiguration;
import com.qubole.qds.sdk.java.client.QdsClient;
import com.qubole.qds.sdk.java.client.QdsClientFactory;
import com.qubole.qds.sdk.java.client.QdsConfiguration;
import javax.ws.rs.core.Response;
import java.io.InputStream;
import com.qubole.qds.sdk.java.entities.ResultValue;
import java.util.concurrent.Future;

public class Tester
Expand All @@ -18,11 +16,9 @@ public static void main(String[] args) throws Exception
QdsClient client = QdsClientFactory.newClient(configuration);
try
{
Future<Response> invoke = client.cluster().list().raw().invoke();
Response value = invoke.get();
InputStream inputStream = value.readEntity(InputStream.class);
String rawJson = new String(ByteStreams.toByteArray(inputStream));
System.out.println(rawJson);
Future<ResultValue> invoke = client.command().results("222070").inline(false).invoke();
ResultValue value = invoke.get();
System.out.println(value);
}
finally
{
Expand Down

0 comments on commit 0a53446

Please sign in to comment.