2 * This Sample test program is useful in getting started with working with Arvados Java SDK.
3 * Please also see arvadso
9 import java.io.BufferedWriter;
10 import java.io.FileWriter;
11 import java.util.HashMap;
12 import java.util.List;
15 import org.arvados.sdk.java.Arvados;
16 import org.json.simple.JSONObject;
17 import org.json.simple.parser.JSONParser;
19 import com.google.api.services.discovery.model.RestDescription;
21 public class ArvadosSDKJavaExample {
22 /** Make sure the following environment variables are set before using Arvados:
23 * ARVADOS_API_TOKEN, ARVADOS_API_HOST, ARVADOS_API_HOST_INSECURE
25 public static void main(String[] args) throws Exception {
26 String apiName = "arvados";
27 String apiVersion = "v1";
29 Arvados arv = new Arvados(apiName, apiVersion);
31 // Make a discover request.
32 System.out.println("Making an arvados discovery api request");
33 RestDescription restDescription = arv.discover();
34 System.out.println("Arvados discovery docuemnt:\n" + restDescription);
36 // Make a users.list call
37 System.out.println("Making an arvados users.list api call");
39 Map<String, Object> params = new HashMap<String, Object>();
41 String response = arv.call("users", "list", params);
42 System.out.println("Arvados users.list:\n" + response);
44 // get uuid of the first user from the response
45 JSONParser parser = new JSONParser();
46 Object obj = parser.parse(response);
47 JSONObject jsonObject = (JSONObject) obj;
48 List items = (List)jsonObject.get("items");
50 JSONObject firstUser = (JSONObject)items.get(0);
51 String userUuid = (String)firstUser.get("uuid");
53 // Make a users.get call on the uuid obtained above
54 System.out.println("Making a users.get call for " + userUuid);
55 params = new HashMap<String, Object>();
56 params.put("uuid", userUuid);
57 response = arv.call("users", "get", params);
58 System.out.println("Arvados users.get:\n" + response);
60 // Make a users.create call
61 System.out.println("Making a users.create call.");
63 params = new HashMap<String, Object>();
64 params.put("user", "{}");
65 response = arv.call("users", "create", params);
66 System.out.println("Arvados users.create:\n" + response);
68 // delete the newly created user
69 parser = new JSONParser();
70 obj = parser.parse(response);
71 jsonObject = (JSONObject) obj;
72 userUuid = (String)jsonObject.get("uuid");
73 params = new HashMap<String, Object>();
74 params.put("uuid", userUuid);
75 response = arv.call("users", "delete", params);
77 // Make a pipeline_templates.list call
78 System.out.println("Making a pipeline_templates.list call.");
80 params = new HashMap<String, Object>();
81 response = arv.call("pipeline_templates", "list", params);
83 System.out.println("Arvados pipelinetempates.list:\n" + response);