[ARVADOS] updated: 77c4def0b319e3720dba05a3c1fb0ab78323f227
git at public.curoverse.com
git at public.curoverse.com
Sat May 3 15:26:00 EDT 2014
Summary of changes:
.../main/java/org/arvados/sdk/java/Arvados.java | 222 +++++++++-----------
.../java/org/arvados/sdk/java/ArvadosTest.java | 211 +++++++++++++------
2 files changed, 240 insertions(+), 193 deletions(-)
via 77c4def0b319e3720dba05a3c1fb0ab78323f227 (commit)
via 65c155b7f691ce6a885125618bde3c9d68f6b47e (commit)
via d433ba0f548414219b3d976125e1ea530e1ba9ef (commit)
from d17ef1d036b4262f6c6c40324cc56d04d26581d3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 77c4def0b319e3720dba05a3c1fb0ab78323f227
Author: radhika <radhika at curoverse.com>
Date: Sat May 3 15:24:42 2014 -0400
2525: call method invocation should match arvados api documentation, instead of discover document format.
diff --git a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
index 12b82da..11b2199 100644
--- a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
+++ b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
@@ -1,7 +1,7 @@
package org.arvados.sdk.java;
import com.google.api.client.http.javanet.*;
-import com.google.api.client.http.FileContent;
+import com.google.api.client.http.ByteArrayContent;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpContent;
import com.google.api.client.http.HttpRequest;
@@ -18,7 +18,6 @@ import com.google.api.services.discovery.model.RestDescription;
import com.google.api.services.discovery.model.RestMethod;
import com.google.api.services.discovery.model.RestResource;
-import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
@@ -134,51 +133,76 @@ public class Arvados {
return (restDescription);
}
- public String call(String resourceName, String methodName, List<String> callParams) throws Exception {
+ public String call(String resourceName, String methodName, Map<String, Object> paramsMap) throws Exception {
RestMethod method = getMatchingMethod(resourceName, methodName);
+ HashMap<String, Object> parameters = loadParameters(paramsMap, method);
+
+ GenericUrl url = new GenericUrl(UriTemplate.expand(
+ ARVADOS_ROOT_URL + restDescription.getBasePath() + method.getPath(),
+ parameters, true));
+
+ try {
+ // construct the request
+ HttpRequestFactory requestFactory;
+ requestFactory = HTTP_TRANSPORT.createRequestFactory();
+
+ // possibly required content
+ HttpContent content = null;
+
+ if (!method.getHttpMethod().equals("GET") && !method.getHttpMethod().equals("DELETE")) {
+ String objectName = resourceName.substring(0, resourceName.length()-1);
+ Object requestBody = paramsMap.get(objectName);
+ if (requestBody == null) {
+ error("POST method requires content object " + objectName);
+ }
+
+ content = new ByteArrayContent("application/json", ((String)requestBody).getBytes());
+ }
+
+ HttpRequest request = requestFactory.buildRequest(method.getHttpMethod(), url, content);
+
+ // make the request
+ List<String> authHeader = new ArrayList<String>();
+ authHeader.add("OAuth2 " + ARVADOS_API_TOKEN);
+ request.getHeaders().put("Authorization", authHeader);
+ String response = request.execute().parseAsString();
+
+ logger.debug(response);
+
+ return response;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ private HashMap<String, Object> loadParameters(Map<String, Object> paramsMap,
+ RestMethod method) throws Exception {
HashMap<String, Object> parameters = Maps.newHashMap();
- File requestBodyFile = null;
- // Start looking for params at index 4. The first 4 were: call arvados v1 <method_name>
- int i = 4;
// required parameters
if (method.getParameterOrder() != null) {
for (String parameterName : method.getParameterOrder()) {
JsonSchema parameter = method.getParameters().get(parameterName);
if (Boolean.TRUE.equals(parameter.getRequired())) {
- if (i == callParams.size()) {
+ Object parameterValue = paramsMap.get(parameterName);
+ if (parameterValue == null) {
error("missing required parameter: " + parameter);
} else {
- putParameter(null, parameters, parameterName, parameter, callParams.get(i++));
+ putParameter(null, parameters, parameterName, parameter, parameterValue);
}
}
}
}
- // possibly required content
- if (!method.getHttpMethod().equals("GET") && !method.getHttpMethod().equals("DELETE")) {
- String fileName = callParams.get(i++);
- requestBodyFile = new File(fileName);
- if (!requestBodyFile.canRead()) {
- error("POST method requires input file. Unable to read file: " + fileName);
- }
- }
-
- while (i < callParams.size()) {
- String argName = callParams.get(i++);
- if (!argName.startsWith("--")) {
- error("optional parameters must start with \"--\": " + argName);
- }
- String parameterName = argName.substring(2);
- if (i == callParams.size()) {
- error("missing parameter value for: " + argName);
- }
- String parameterValue = callParams.get(i++);
+ for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
+ String parameterName = entry.getKey();
+ Object parameterValue = entry.getValue();
+
if (parameterName.equals("contentType")) {
- String contentType = parameterValue;
if (method.getHttpMethod().equals("GET") || method.getHttpMethod().equals("DELETE")) {
- error("HTTP content type cannot be specified for this method: " + argName);
+ error("HTTP content type cannot be specified for this method: " + parameterName);
}
} else {
JsonSchema parameter = null;
@@ -188,37 +212,11 @@ public class Arvados {
if (parameter == null && method.getParameters() == null) {
parameter = method.getParameters().get(parameterName);
}
- putParameter(argName, parameters, parameterName, parameter, parameterValue);
+ putParameter(parameterName, parameters, parameterName, parameter, parameterValue);
}
}
-
- GenericUrl url = new GenericUrl(UriTemplate.expand(
- ARVADOS_ROOT_URL + restDescription.getBasePath() + method.getPath(), parameters,
- true));
-
- HttpContent content = null;
- if (requestBodyFile != null) {
- content = new FileContent("application/json", requestBodyFile);
- }
-
- try {
- HttpRequestFactory requestFactory;
- requestFactory = HTTP_TRANSPORT.createRequestFactory();
-
- HttpRequest request = requestFactory.buildRequest(method.getHttpMethod(), url, content);
-
- List<String> authHeader = new ArrayList<String>();
- authHeader.add("OAuth2 " + ARVADOS_API_TOKEN);
- request.getHeaders().put("Authorization", authHeader);
- String response = request.execute().parseAsString();
-
- logger.debug(response);
-
- return response;
- } catch (Exception e) {
- e.printStackTrace();
- throw e;
- }
+
+ return parameters;
}
private RestMethod getMatchingMethod(String resourceName, String methodName)
@@ -327,21 +325,19 @@ public class Arvados {
}
private void putParameter(String argName, Map<String, Object> parameters,
- String parameterName, JsonSchema parameter, String parameterValue) throws Exception {
+ String parameterName, JsonSchema parameter, Object parameterValue) throws Exception {
Object value = parameterValue;
if (parameter != null) {
if ("boolean".equals(parameter.getType())) {
- value = Boolean.valueOf(parameterValue);
+ value = Boolean.valueOf(parameterValue.toString());
} else if ("number".equals(parameter.getType())) {
- value = new BigDecimal(parameterValue);
+ value = new BigDecimal(parameterValue.toString());
} else if ("integer".equals(parameter.getType())) {
- value = new BigInteger(parameterValue);
+ value = new BigInteger(parameterValue.toString());
}
}
- Object oldValue = parameters.put(parameterName, value);
- if (oldValue != null) {
- error("duplicate parameter: " + argName);
- }
+
+ parameters.put(parameterName, value);
}
private static void error(String detail) throws Exception {
@@ -351,4 +347,4 @@ public class Arvados {
throw new Exception(errorDetail);
}
-}
+}
\ No newline at end of file
diff --git a/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java b/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
index 8b681d2..7c623e2 100644
--- a/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
+++ b/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
@@ -1,7 +1,7 @@
package org.arvados.sdk.java;
import java.io.File;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -50,11 +50,7 @@ public class ArvadosTest {
public void testCallUsersList() throws Exception {
Arvados arv = new Arvados("arvados", "v1");
- List<String> params = new ArrayList<String>();
- params.add("call");
- params.add("arvados");
- params.add("v1");
- params.add("users.list");
+ Map<String, Object> params = new HashMap<String, Object>();
String response = arv.call("users", "list", params);
assertTrue("Expected users.list in response", response.contains("arvados#userList"));
@@ -86,11 +82,7 @@ public class ArvadosTest {
Arvados arv = new Arvados("arvados", "v1");
// call user.system and get uuid of this user
- List<String> params = new ArrayList<String>();
- params.add("call");
- params.add("arvados");
- params.add("v1");
- params.add("users.list");
+ Map<String, Object> params = new HashMap<String, Object>();
String response = arv.call("users", "list", params);
JSONParser parser = new JSONParser();
@@ -104,12 +96,8 @@ public class ArvadosTest {
String userUuid = (String)firstUser.get("uuid");
// invoke users.get with the system user uuid
- params = new ArrayList<String>();
- params.add("call");
- params.add("arvados");
- params.add("v1");
- params.add("users.get");
- params.add(userUuid);
+ params = new HashMap<String, Object>();
+ params.put("uuid", userUuid);
response = arv.call("users", "get", params);
@@ -130,12 +118,8 @@ public class ArvadosTest {
File file = new File(getClass().getResource( "/create_user.json" ).toURI());
String filePath = file.getPath();
- List<String> params = new ArrayList<String>();
- params.add("call");
- params.add("arvados");
- params.add("v1");
- params.add("users.create");
- params.add(filePath);
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("user", "{}");
String response = arv.call("users", "create", params);
JSONParser parser = new JSONParser();
@@ -144,6 +128,57 @@ public class ArvadosTest {
assertNotNull("Expected uuid for first user", jsonObject.get("uuid"));
}
+ @Test
+ public void testCreateUserWithMissingRequiredParam() throws Exception {
+ Arvados arv = new Arvados("arvados", "v1");
+
+ Map<String, Object> params = new HashMap<String, Object>();
+
+ Exception caught = null;
+ try {
+ arv.call("users", "create", params);
+ } catch (Exception e) {
+ caught = e;
+ }
+
+ assertNotNull ("expected exception", caught);
+ assertTrue ("Expected POST method requires content object user",
+ caught.getMessage().contains("ERROR: POST method requires content object user"));
+ }
+
+ /**
+ * Test users.create api
+ * @throws Exception
+ */
+ @Test
+ public void testCreateAndUpdateUser() throws Exception {
+ Arvados arv = new Arvados("arvados", "v1");
+
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("user", "{}");
+ String response = arv.call("users", "create", params);
+
+ JSONParser parser = new JSONParser();
+ JSONObject jsonObject = (JSONObject) parser.parse(response);
+ assertEquals("Expected kind to be user", "arvados#user", jsonObject.get("kind"));
+
+ Object uuid = jsonObject.get("uuid");
+ assertNotNull("Expected uuid for first user", uuid);
+
+ // update this user
+ params = new HashMap<String, Object>();
+ params.put("user", "{}");
+ params.put("uuid", uuid);
+ response = arv.call("users", "update", params);
+
+ parser = new JSONParser();
+ jsonObject = (JSONObject) parser.parse(response);
+ assertEquals("Expected kind to be user", "arvados#user", jsonObject.get("kind"));
+
+ uuid = jsonObject.get("uuid");
+ assertNotNull("Expected uuid for first user", uuid);
+ }
+
/**
* Test unsupported api version api
* @throws Exception
@@ -152,15 +187,9 @@ public class ArvadosTest {
public void testUnsupportedApiName() throws Exception {
Arvados arv = new Arvados("not_arvados", "v1");
- List<String> params = new ArrayList<String>();
- params.add("call");
- params.add("not_arvados");
- params.add("v1");
- params.add("users.list");
-
Exception caught = null;
try {
- arv.call("users", "list", params);
+ arv.call("users", "list", null);
} catch (Exception e) {
caught = e;
}
@@ -177,15 +206,9 @@ public class ArvadosTest {
public void testUnsupportedVersion() throws Exception {
Arvados arv = new Arvados("arvados", "v2");
- List<String> params = new ArrayList<String>();
- params.add("call");
- params.add("arvados");
- params.add("v2"); // no such version
- params.add("users.list");
-
Exception caught = null;
try {
- arv.call("users", "list", params);
+ arv.call("users", "list", null);
} catch (Exception e) {
caught = e;
}
@@ -202,15 +225,9 @@ public class ArvadosTest {
public void testCallForNoSuchResrouce() throws Exception {
Arvados arv = new Arvados("arvados", "v1");
- List<String> params = new ArrayList<String>();
- params.add("call");
- params.add("arvados");
- params.add("v1");
- params.add("users.list");
-
Exception caught = null;
try {
- arv.call("abcd", "list", params);
+ arv.call("abcd", "list", null);
} catch (Exception e) {
caught = e;
}
@@ -227,15 +244,9 @@ public class ArvadosTest {
public void testCallForNoSuchResrouceMethod() throws Exception {
Arvados arv = new Arvados("arvados", "v1");
- List<String> params = new ArrayList<String>();
- params.add("call");
- params.add("arvados");
- params.add("v1");
- params.add("users.list");
-
Exception caught = null;
try {
- arv.call("users", "abcd", params);
+ arv.call("users", "abcd", null);
} catch (Exception e) {
caught = e;
}
@@ -255,12 +266,8 @@ public class ArvadosTest {
File file = new File(getClass().getResource( "/first_pipeline.json" ).toURI());
String filePath = file.getPath();
- List<String> params = new ArrayList<String>();
- params.add("call");
- params.add("arvados");
- params.add("v1");
- params.add("pipeline_templates.create");
- params.add(filePath);
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("pipeline_template", "{}"); // TBD - read file and send
String response = arv.call("pipeline_templates", "create", params);
JSONParser parser = new JSONParser();
@@ -270,12 +277,8 @@ public class ArvadosTest {
assertNotNull("Expected uuid for pipeline template", uuid);
// get the pipeline
- params = new ArrayList<String>();
- params.add("call");
- params.add("arvados");
- params.add("v1");
- params.add("pipeline_templates.get");
- params.add(uuid);
+ params = new HashMap<String, Object>();
+ params.put("uuid", uuid);
response = arv.call("pipeline_templates", "get", params);
parser = new JSONParser();
@@ -297,11 +300,27 @@ public class ArvadosTest {
Arvados arv = new Arvados("arvados", "v1", token, host, hostInsecure);
- List<String> params = new ArrayList<String>();
- params.add("call");
- params.add("arvados");
- params.add("v1");
- params.add("users.list");
+ Map<String, Object> params = new HashMap<String, Object>();
+
+ String response = arv.call("users", "list", params);
+ assertTrue("Expected users.list in response", response.contains("arvados#userList"));
+ assertTrue("Expected users.list in response", response.contains("uuid"));
+
+ JSONParser parser = new JSONParser();
+ Object obj = parser.parse(response);
+ JSONObject jsonObject = (JSONObject) obj;
+ assertEquals("Expected kind to be users.list", "arvados#userList", jsonObject.get("kind"));
+ }
+
+ /**
+ * Test users.list api
+ * @throws Exception
+ */
+ @Test
+ public void testCallUsersListWithLimit() throws Exception {
+ Arvados arv = new Arvados("arvados", "v1");
+
+ Map<String, Object> params = new HashMap<String, Object>();
String response = arv.call("users", "list", params);
assertTrue("Expected users.list in response", response.contains("arvados#userList"));
@@ -310,7 +329,33 @@ public class ArvadosTest {
JSONParser parser = new JSONParser();
Object obj = parser.parse(response);
JSONObject jsonObject = (JSONObject) obj;
+
+ assertEquals("Expected kind to be users.list", "arvados#userList", jsonObject.get("kind"));
+
+ List items = (List)jsonObject.get("items");
+ assertNotNull("expected users list items", items);
+ assertTrue("expected at least one item in users list", items.size()>0);
+
+ int numUsersListItems = items.size();
+
+ // make the request again with limit
+ params = new HashMap<String, Object>();
+ params.put("limit", numUsersListItems-1);
+
+ response = arv.call("users", "list", params);
+
+ parser = new JSONParser();
+ obj = parser.parse(response);
+ jsonObject = (JSONObject) obj;
+
assertEquals("Expected kind to be users.list", "arvados#userList", jsonObject.get("kind"));
+
+ items = (List)jsonObject.get("items");
+ assertNotNull("expected users list items", items);
+ assertTrue("expected at least one item in users list", items.size()>0);
+
+ int numUsersListItems2 = items.size();
+ assertEquals ("Got more users than requested", numUsersListItems-1, numUsersListItems2);
}
}
\ No newline at end of file
commit 65c155b7f691ce6a885125618bde3c9d68f6b47e
Author: radhika <radhika at curoverse.com>
Date: Sat May 3 12:45:38 2014 -0400
2525: call method invocation should match arvados api documentation, instead of discover document format.
diff --git a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
index eec3e4e..12b82da 100644
--- a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
+++ b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
@@ -26,8 +26,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+
import org.apache.log4j.Logger;
public class Arvados {
@@ -35,8 +34,6 @@ public class Arvados {
private HttpTransport HTTP_TRANSPORT;
private final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
- private static final Pattern METHOD_PATTERN = Pattern.compile("((\\w+)\\.)*(\\w+)");
-
private String ARVADOS_API_TOKEN;
private String ARVADOS_API_HOST;
private boolean ARVADOS_API_HOST_INSECURE;
@@ -44,21 +41,21 @@ public class Arvados {
private String ARVADOS_ROOT_URL;
private static final Logger logger = Logger.getLogger(Arvados.class);
-
+
// Get it on a discover call and reuse on the call requests
RestDescription restDescription = null;
String apiName = null;
String apiVersion = null;
-
+
public Arvados (String apiName, String apiVersion){
this (apiName, apiVersion, null, null, null);
}
-
+
public Arvados (String apiName, String apiVersion, String token, String host, String hostInsecure){
try {
this.apiName = apiName;
this.apiVersion = apiVersion;
-
+
// Read needed environmental variables if they are not passed
if (token != null) {
ARVADOS_API_TOKEN = token;
@@ -85,7 +82,7 @@ public class Arvados {
} else {
ARVADOS_API_HOST_INSECURE = "true".equals(System.getenv().get("ARVADOS_API_HOST_INSECURE")) ? true : false;
}
-
+
// Create HTTP_TRANSPORT object
NetHttpTransport.Builder builder = new NetHttpTransport.Builder();
if (ARVADOS_API_HOST_INSECURE) {
@@ -96,7 +93,7 @@ public class Arvados {
t.printStackTrace();
}
}
-
+
/**
* Make a discover call and cache the response in-memory. Reload the document on each invocation.
* @param params
@@ -104,7 +101,7 @@ public class Arvados {
* @throws Exception
*/
public RestDescription discover() throws Exception {
- restDescription = loadArvadosApi(apiName, apiVersion);
+ restDescription = loadArvadosApi();
// compute method details
ArrayList<MethodDetails> result = Lists.newArrayList();
@@ -133,60 +130,15 @@ public class Arvados {
}
}
logger.debug(buffer.toString());
-
+
return (restDescription);
}
public String call(String resourceName, String methodName, List<String> callParams) throws Exception {
- if (resourceName == null) {
- error("missing resource name");
- }
- if (methodName == null) {
- error("missing method name");
- }
-
- String fullMethodName = callParams.get(3);
- Matcher m = METHOD_PATTERN.matcher(fullMethodName);
- if (!m.matches()) {
- error ("invalid method name: " + fullMethodName);
- }
-
- // initialize rest description if not already
- if (restDescription == null) {
- restDescription = loadArvadosApi(callParams.get(1), callParams.get(2));
- }
-
- Map<String, RestMethod> methodMap = null;
- int curIndex = 0;
- int nextIndex = fullMethodName.indexOf('.');
- if (nextIndex == -1) {
- methodMap = restDescription.getMethods();
- } else {
- Map<String, RestResource> resources = restDescription.getResources();
- while (true) {
- RestResource resource = resources.get(fullMethodName.substring(curIndex, nextIndex));
- if (resource == null) {
- break;
- }
- curIndex = nextIndex + 1;
- nextIndex = fullMethodName.indexOf(curIndex + 1, '.');
- if (nextIndex == -1) {
- methodMap = resource.getMethods();
- break;
- }
- resources = resource.getResources();
- }
- }
-
- RestMethod method =
- methodMap == null ? null : methodMap.get(fullMethodName.substring(curIndex));
- if (method == null) {
- error("method not found: " + fullMethodName);
- }
+ RestMethod method = getMatchingMethod(resourceName, methodName);
HashMap<String, Object> parameters = Maps.newHashMap();
File requestBodyFile = null;
- String contentType = "application/json";
// Start looking for params at index 4. The first 4 were: call arvados v1 <method_name>
int i = 4;
@@ -224,7 +176,7 @@ public class Arvados {
}
String parameterValue = callParams.get(i++);
if (parameterName.equals("contentType")) {
- contentType = parameterValue;
+ String contentType = parameterValue;
if (method.getHttpMethod().equals("GET") || method.getHttpMethod().equals("DELETE")) {
error("HTTP content type cannot be specified for this method: " + argName);
}
@@ -246,7 +198,7 @@ public class Arvados {
HttpContent content = null;
if (requestBodyFile != null) {
- content = new FileContent(contentType, requestBodyFile);
+ content = new FileContent("application/json", requestBodyFile);
}
try {
@@ -261,7 +213,7 @@ public class Arvados {
String response = request.execute().parseAsString();
logger.debug(response);
-
+
return response;
} catch (Exception e) {
e.printStackTrace();
@@ -269,6 +221,36 @@ public class Arvados {
}
}
+ private RestMethod getMatchingMethod(String resourceName, String methodName)
+ throws Exception {
+ if (resourceName == null) {
+ error("missing resource name");
+ }
+ if (methodName == null) {
+ error("missing method name");
+ }
+
+ // initialize rest description if not already
+ if (restDescription == null) {
+ restDescription = loadArvadosApi();
+ }
+
+ Map<String, RestMethod> methodMap = null;
+ Map<String, RestResource> resources = restDescription.getResources();
+ RestResource resource = resources.get(resourceName);
+ if (resource == null) {
+ error("resource not found");
+ }
+ methodMap = resource.getMethods();
+ RestMethod method =
+ methodMap == null ? null : methodMap.get(methodName);
+ if (method == null) {
+ error("method not found: ");
+ }
+
+ return method;
+ }
+
/**
* Not thread-safe. So, create for each request.
* @param apiName
@@ -276,16 +258,16 @@ public class Arvados {
* @return
* @throws Exception
*/
- private RestDescription loadArvadosApi(String apiName, String apiVersion)
+ private RestDescription loadArvadosApi()
throws Exception {
try {
Discovery discovery;
-
+
Discovery.Builder discoveryBuilder = new Discovery.Builder(HTTP_TRANSPORT, JSON_FACTORY, null);
discoveryBuilder.setRootUrl(ARVADOS_ROOT_URL);
discoveryBuilder.setApplicationName(apiName);
-
+
discovery = discoveryBuilder.build();
return discovery.apis().getRest(apiName, apiVersion).execute();
@@ -361,10 +343,10 @@ public class Arvados {
error("duplicate parameter: " + argName);
}
}
-
+
private static void error(String detail) throws Exception {
String errorDetail = "ERROR: " + detail;
-
+
logger.debug(errorDetail);
throw new Exception(errorDetail);
}
diff --git a/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java b/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
index 8a3bd0f..8b681d2 100644
--- a/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
+++ b/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
@@ -111,7 +111,7 @@ public class ArvadosTest {
params.add("users.get");
params.add(userUuid);
- response = arv.call("user", "get", params);
+ response = arv.call("users", "get", params);
//JSONParser parser = new JSONParser();
jsonObject = (JSONObject) parser.parse(response);;
@@ -175,7 +175,7 @@ public class ArvadosTest {
*/
@Test
public void testUnsupportedVersion() throws Exception {
- Arvados arv = new Arvados("arvados", "v1");
+ Arvados arv = new Arvados("arvados", "v2");
List<String> params = new ArrayList<String>();
params.add("call");
@@ -203,10 +203,10 @@ public class ArvadosTest {
Arvados arv = new Arvados("arvados", "v1");
List<String> params = new ArrayList<String>();
- params.add("users.list");
params.add("call");
params.add("arvados");
params.add("v1");
+ params.add("users.list");
Exception caught = null;
try {
@@ -216,7 +216,7 @@ public class ArvadosTest {
}
assertNotNull ("expected exception", caught);
- assertTrue ("Expected ERROR: 404 not found", caught.getMessage().contains("404 Not Found"));
+ assertTrue ("Expected ERROR: 404 not found", caught.getMessage().contains("ERROR: resource not found"));
}
/**
@@ -228,10 +228,10 @@ public class ArvadosTest {
Arvados arv = new Arvados("arvados", "v1");
List<String> params = new ArrayList<String>();
- params.add("users.list");
params.add("call");
params.add("arvados");
params.add("v1");
+ params.add("users.list");
Exception caught = null;
try {
@@ -241,7 +241,7 @@ public class ArvadosTest {
}
assertNotNull ("expected exception", caught);
- assertTrue ("Expected ERROR: 404 not found", caught.getMessage().contains("404 Not Found"));
+ assertTrue ("Expected ERROR: 404 not found", caught.getMessage().contains("ERROR: method not found"));
}
/**
commit d433ba0f548414219b3d976125e1ea530e1ba9ef
Author: radhika <radhika at curoverse.com>
Date: Sat May 3 11:52:55 2014 -0400
2525: call method invocation should match arvados api documentation, instead of discover document format.
diff --git a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
index 66feadd..eec3e4e 100644
--- a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
+++ b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
@@ -137,19 +137,18 @@ public class Arvados {
return (restDescription);
}
- public String call(List<String> callParams) throws Exception {
- if (callParams.size() == 1) {
- error("call", "missing api name");
- } else if (callParams.size() == 2) {
- error("call", "missing api version");
- } else if (callParams.size() == 3) {
- error("call", "missing method name");
+ public String call(String resourceName, String methodName, List<String> callParams) throws Exception {
+ if (resourceName == null) {
+ error("missing resource name");
}
-
+ if (methodName == null) {
+ error("missing method name");
+ }
+
String fullMethodName = callParams.get(3);
Matcher m = METHOD_PATTERN.matcher(fullMethodName);
if (!m.matches()) {
- error("call", "invalid method name: " + fullMethodName);
+ error ("invalid method name: " + fullMethodName);
}
// initialize rest description if not already
@@ -182,7 +181,7 @@ public class Arvados {
RestMethod method =
methodMap == null ? null : methodMap.get(fullMethodName.substring(curIndex));
if (method == null) {
- error("call", "method not found: " + fullMethodName);
+ error("method not found: " + fullMethodName);
}
HashMap<String, Object> parameters = Maps.newHashMap();
@@ -197,7 +196,7 @@ public class Arvados {
JsonSchema parameter = method.getParameters().get(parameterName);
if (Boolean.TRUE.equals(parameter.getRequired())) {
if (i == callParams.size()) {
- error("call", "missing required parameter: " + parameter);
+ error("missing required parameter: " + parameter);
} else {
putParameter(null, parameters, parameterName, parameter, callParams.get(i++));
}
@@ -210,24 +209,24 @@ public class Arvados {
String fileName = callParams.get(i++);
requestBodyFile = new File(fileName);
if (!requestBodyFile.canRead()) {
- error("call", "POST method requires input file. Unable to read file: " + fileName);
+ error("POST method requires input file. Unable to read file: " + fileName);
}
}
while (i < callParams.size()) {
String argName = callParams.get(i++);
if (!argName.startsWith("--")) {
- error("call", "optional parameters must start with \"--\": " + argName);
+ error("optional parameters must start with \"--\": " + argName);
}
String parameterName = argName.substring(2);
if (i == callParams.size()) {
- error("call", "missing parameter value for: " + argName);
+ error("missing parameter value for: " + argName);
}
String parameterValue = callParams.get(i++);
if (parameterName.equals("contentType")) {
contentType = parameterValue;
if (method.getHttpMethod().equals("GET") || method.getHttpMethod().equals("DELETE")) {
- error("call", "HTTP content type cannot be specified for this method: " + argName);
+ error("HTTP content type cannot be specified for this method: " + argName);
}
} else {
JsonSchema parameter = null;
@@ -359,13 +358,12 @@ public class Arvados {
}
Object oldValue = parameters.put(parameterName, value);
if (oldValue != null) {
- error("call", "duplicate parameter: " + argName);
+ error("duplicate parameter: " + argName);
}
}
- private static void error(String command, String detail) throws Exception {
- String errorDetail = "ERROR: " + detail +
- "For help, type: Arvados" + (command == null ? "" : " help " + command);
+ private static void error(String detail) throws Exception {
+ String errorDetail = "ERROR: " + detail;
logger.debug(errorDetail);
throw new Exception(errorDetail);
diff --git a/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java b/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
index 66345de..8a3bd0f 100644
--- a/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
+++ b/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
@@ -56,7 +56,7 @@ public class ArvadosTest {
params.add("v1");
params.add("users.list");
- String response = arv.call(params);
+ String response = arv.call("users", "list", params);
assertTrue("Expected users.list in response", response.contains("arvados#userList"));
assertTrue("Expected users.list in response", response.contains("uuid"));
@@ -92,7 +92,7 @@ public class ArvadosTest {
params.add("v1");
params.add("users.list");
- String response = arv.call(params);
+ String response = arv.call("users", "list", params);
JSONParser parser = new JSONParser();
Object obj = parser.parse(response);
JSONObject jsonObject = (JSONObject) obj;
@@ -111,7 +111,7 @@ public class ArvadosTest {
params.add("users.get");
params.add(userUuid);
- response = arv.call(params);
+ response = arv.call("user", "get", params);
//JSONParser parser = new JSONParser();
jsonObject = (JSONObject) parser.parse(response);;
@@ -136,7 +136,7 @@ public class ArvadosTest {
params.add("v1");
params.add("users.create");
params.add(filePath);
- String response = arv.call(params);
+ String response = arv.call("users", "create", params);
JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(response);
@@ -160,7 +160,7 @@ public class ArvadosTest {
Exception caught = null;
try {
- arv.call(params);
+ arv.call("users", "list", params);
} catch (Exception e) {
caught = e;
}
@@ -185,7 +185,7 @@ public class ArvadosTest {
Exception caught = null;
try {
- arv.call(params);
+ arv.call("users", "list", params);
} catch (Exception e) {
caught = e;
}
@@ -199,26 +199,52 @@ public class ArvadosTest {
* @throws Exception
*/
@Test
- public void testCallWithTooFewParams() throws Exception {
+ public void testCallForNoSuchResrouce() throws Exception {
Arvados arv = new Arvados("arvados", "v1");
List<String> params = new ArrayList<String>();
+ params.add("users.list");
params.add("call");
params.add("arvados");
params.add("v1");
Exception caught = null;
try {
- arv.call(params);
+ arv.call("abcd", "list", params);
} catch (Exception e) {
caught = e;
}
assertNotNull ("expected exception", caught);
- assertTrue ("Expected ERROR: missing method name", caught.getMessage().contains("ERROR: missing method name"));
+ assertTrue ("Expected ERROR: 404 not found", caught.getMessage().contains("404 Not Found"));
}
/**
+ * Test unsupported api version api
+ * @throws Exception
+ */
+ @Test
+ public void testCallForNoSuchResrouceMethod() throws Exception {
+ Arvados arv = new Arvados("arvados", "v1");
+
+ List<String> params = new ArrayList<String>();
+ params.add("users.list");
+ params.add("call");
+ params.add("arvados");
+ params.add("v1");
+
+ Exception caught = null;
+ try {
+ arv.call("users", "abcd", params);
+ } catch (Exception e) {
+ caught = e;
+ }
+
+ assertNotNull ("expected exception", caught);
+ assertTrue ("Expected ERROR: 404 not found", caught.getMessage().contains("404 Not Found"));
+ }
+
+ /**
* Test pipeline_tempates.create api
* @throws Exception
*/
@@ -235,7 +261,7 @@ public class ArvadosTest {
params.add("v1");
params.add("pipeline_templates.create");
params.add(filePath);
- String response = arv.call(params);
+ String response = arv.call("pipeline_templates", "create", params);
JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(response);
@@ -250,7 +276,7 @@ public class ArvadosTest {
params.add("v1");
params.add("pipeline_templates.get");
params.add(uuid);
- response = arv.call(params);
+ response = arv.call("pipeline_templates", "get", params);
parser = new JSONParser();
jsonObject = (JSONObject) parser.parse(response);
@@ -277,7 +303,7 @@ public class ArvadosTest {
params.add("v1");
params.add("users.list");
- String response = arv.call(params);
+ String response = arv.call("users", "list", params);
assertTrue("Expected users.list in response", response.contains("arvados#userList"));
assertTrue("Expected users.list in response", response.contains("uuid"));
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list