h2. Initialize SDK
-<pre>
+{% codeblock as go %}
import (
"git.curoverse.com/arvados.git/sdk/go/arvados"
"git.curoverse.com/arvados.git/sdk/go/arvadosclient"
log.Fatalf("Error setting up arvados client %s", err.Error())
}
}
-</pre>
+{% endcodeblock %}
h2. create
-<pre>
+{% codeblock as go %}
var collection arvados.Collection
err := api.Create("collections", Dict{"collection": Dict{"name": "create example"}}, &collection)
-</pre>
+{% endcodeblock %}
h2. delete
-<pre>
+{% codeblock as go %}
var collection arvados.Collection
err := api.Delete("collections", "aaaaa-4zz18-ccccccccccccccc", Dict{}, &collection)
-</pre>
+{% endcodeblock %}
h2. get
-<pre>
+{% codeblock as go %}
var collection arvados.Collection
err := api.Get("collections", "aaaaa-4zz18-ccccccccccccccc", Dict{}, &collection)
-</pre>
+{% endcodeblock %}
h2. list
-<pre>
+{% codeblock as go %}
var collection arvados.Collection
err := api.List("collections", Dict{}, &collection)
-</pre>
+{% endcodeblock %}
h2. update
-<pre>
+{% codeblock as go %}
var collection arvados.Collection
err := api.Update("collections", "aaaaa-4zz18-ccccccccccccccc", Dict{"collection": Dict{"name": "update example"}}, &collection)
-</pre>
+{% endcodeblock %}
h2. Get current user
-<pre>
+{% codeblock as go %}
var user arvados.User
err := api.Get("users", "current", Dict{}, &user)
-</pre>
+{% endcodeblock %}
h2. Example program
h2. Initialize SDK
-<pre>
+{% codeblock as java %}
import org.arvados.sdk.Arvados;
-</pre>
+{% endcodeblock %}
-<pre>
+{% codeblock as java %}
String apiName = "arvados";
String apiVersion = "v1";
Arvados arv = new Arvados(apiName, apiVersion);
-</pre>
+{% endcodeblock %}
h2. create
-<pre>
+{% codeblock as java %}
Map<String, String> collection = new HashMap<String, String>();
collection.put("name", "create example");
Map<String, Object> params = new HashMap<String, Object>();
params.put("collection", collection);
Map response = arv.call("collections", "create", params);
-</pre>
+{% endcodeblock %}
h2. delete
-<pre>
+{% codeblock as java %}
Map<String, Object> params = new HashMap<String, Object>();
params.put("uuid", uuid);
Map response = arv.call("collections", "delete", params);
-</pre>
+{% endcodeblock %}
h2. get
-<pre>
+{% codeblock as java %}
params = new HashMap<String, Object>();
params.put("uuid", userUuid);
Map response = arv.call("users", "get", params);
-</pre>
+{% endcodeblock %}
h2. list
-<pre>
+{% codeblock as java %}
Map<String, Object> params = new HashMap<String, Object>();
Map response = arv.call("users", "list", params);
Map firstUser = (Map)items.get(0);
String userUuid = (String)firstUser.get("uuid");
-</pre>
+{% endcodeblock %}
h2. update
-<pre>
+{% codeblock as java %}
Map<String, String> collection = new HashMap<String, String>();
collection.put("name", "update example");
params.put("uuid", uuid);
params.put("collection", collection);
Map response = arv.call("collections", "update", params);
-</pre>
+{% endcodeblock %}
h2. Get current user
-<pre>
+{% codeblock as java %}
Map<String, Object> params = new HashMap<String, Object>();
Map response = arv.call("users", "current", params);
-</pre>
+{% endcodeblock %}
Set up an API client user agent:
-<notextile>
-<pre><code class="userinput">
+{% codeblock as perl %}
use Arvados;
my $arv = Arvados->new('apiVersion' => 'v1');
-</code></pre>
-</notextile>
+{% endcodeblock %}
The SDK retrieves the list of API methods from the server at run time. Therefore, the set of available methods is determined by the server version rather than the SDK version.
Create an object:
-<notextile>
-<pre><code class="userinput">my $test_link = $arv->{'links'}->{'create'}->execute('link' => { 'link_class' => 'test', 'name' => 'test' });
-</code></pre>
-</notextile>
+{% codeblock as perl %}
+my $test_link = $arv->{'links'}->{'create'}->execute('link' => { 'link_class' => 'test', 'name' => 'test' });
+{% endcodeblock %}
h2. delete
-<notextile>
-<pre><code class="userinput">my $some_user = $arv->{'collections'}->{'get'}->execute('uuid' => $collection_uuid);
-</code></pre>
-</notextile>
+{% codeblock as perl %}
+my $some_user = $arv->{'collections'}->{'get'}->execute('uuid' => $collection_uuid);
+{% endcodeblock %}
h2. get
Retrieve an object by ID:
-<notextile>
-<pre><code class="userinput">my $some_user = $arv->{'users'}->{'get'}->execute('uuid' => $current_user_uuid);
-</code></pre>
-</notextile>
+{% codeblock as perl %}
+my $some_user = $arv->{'users'}->{'get'}->execute('uuid' => $current_user_uuid);
+{% endcodeblock %}
Get the UUID of an object that was retrieved using the SDK:
-<notextile>
-<pre><code class="userinput">my $current_user_uuid = $current_user->{'uuid'}
-</code></pre>
-</notextile>
+{% codeblock as perl %}
+my $current_user_uuid = $current_user->{'uuid'}
+{% endcodeblock %}
h2. list
Get a list of objects:
-<notextile>
-<pre><code class="userinput">my $repos = $arv->{'repositories'}->{'list'}->execute;
+{% codeblock as perl %}
+my $repos = $arv->{'repositories'}->{'list'}->execute;
print ("UUID of first repo returned is ", $repos->{'items'}->[0], "\n");
-</code></pre>
-</notextile>
+{% endcodeblock %}
h2. update
Update an object:
-<notextile>
-<pre><code class="userinput">my $test_link = $arv->{'links'}->{'update'}->execute(
+{% codeblock as perl %}
+my $test_link = $arv->{'links'}->{'update'}->execute(
'uuid' => $test_link->{'uuid'},
'link' => { 'properties' => { 'foo' => 'bar' } });
-</code></pre>
-</notextile>
+{% endcodeblock %}
h2. Get current user
Get the User object for the current user:
-<notextile>
-<pre><code class="userinput">my $current_user = $arv->{'users'}->{'current'}->execute;
-</code></pre>
-</notextile>
+{% codeblock as perl %}
+my $current_user = $arv->{'users'}->{'current'}->execute;
+{% endcodeblock %}
h2. Cancel a container request
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
arvados.api().container_requests().update(uuid=container_request_uuid, body={"priority": 0}).execute()
-</code></pre>
+{% endcodeblock %}
h2. Cancel all container requests
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
api = arvados.api()
result = api.container_requests().list(filters=[["state", "=", "Committed"], ["priority", ">", "0"]]).execute()["items"]
for container_request in result:
api.container_requests().update(uuid=container_request["uuid"], body={"priority": 0}).execute()
-</code></pre>
+{% endcodeblock %}
h2. List completed container requests
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
api = arvados.api()
result = api.container_requests().list(filters=[["name", "like", name], ["state", "=", "Final"]]).execute()["items"]
container_uuids = [cr["container_uuid"] for cr in result]
for container_request in result:
container = container_dict[container_request["container_uuid"]]
print("%s, %s, %s" % (container_request["uuid"], container_request["name"], "Success" if container["exit_code"] == 0 else "Failed"))
-</code></pre>
+{% endcodeblock %}
h2. Get input of a CWL workflow
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
api = arvados.api()
+container_request_uuid="qr1hi-xvhdp-zzzzzzzzzzzzzzz"
container_request = arvados.api().container_requests().get(uuid=container_request_uuid).execute()
print(container_request["mounts"]["/var/lib/cwl/cwl.input.json"])
-</code></pre>
+{% endcodeblock %}
h2. Get output of a CWL workflow
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
import arvados.collection
api = arvados.api()
+container_request_uuid="qr1hi-xvhdp-zzzzzzzzzzzzzzz"
container_request = arvados.api().container_requests().get(uuid=container_request_uuid).execute()
collection = arvados.collection.CollectionReader(container_request["output_uuid"])
print(collection.open("cwl.output.json").read())
-</code></pre>
+{% endcodeblock %}
h2. List input of child requests
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
api = arvados.api()
parent_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
-namefilter = "bwa%"
+namefilter = "bwa%" # the "like" filter uses SQL pattern match syntax
container_request = arvados.api().container_requests().get(uuid=parent_request_uuid).execute()
parent_container_uuid = container_request["container_uuid"]
child_requests = arvados.api().container_requests().list(filters=[
for m in c["mounts"].values():
if "portable_data_hash" in m:
print(" %s" % m["portable_data_hash"])
-</code></pre>
+{% endcodeblock %}
h2. List output of child requests
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
api = arvados.api()
-parent_request_uuid = "qr1hi-xvhdp-61y7cjymnhyp7yu"
-namefilter = "bwa%"
+parent_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
+namefilter = "bwa%" # the "like" filter uses SQL pattern match syntax
container_request = arvados.api().container_requests().get(uuid=parent_request_uuid).execute()
parent_container_uuid = container_request["container_uuid"]
child_requests = arvados.api().container_requests().list(filters=[
uuid_to_pdh = {c["uuid"]: c["portable_data_hash"] for c in collections["items"]}
for c in child_requests["items"]:
print("%s -> %s" % (c["name"], uuid_to_pdh[c["output_uuid"]]))
-</code></pre>
+{% endcodeblock %}
h2. List failed child requests
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
api = arvados.api()
-parent_request_uuid = "qr1hi-xvhdp-3d8f1zatx1xio36"
+parent_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
container_request = arvados.api().container_requests().get(uuid=parent_request_uuid).execute()
parent_container_uuid = container_request["container_uuid"]
child_requests = arvados.api().container_requests().list(filters=[
["uuid", "in", child_containers.keys()]], limit=1000).execute()
for c in cancelled_child_containers["items"]:
print("%s (%s)" % (child_containers[c["uuid"]]["name"], child_containers[c["uuid"]]["uuid"]))
-</code></pre>
+{% endcodeblock %}
h2. Get log of a child request
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
import arvados.collection
api = arvados.api()
-container_request_uuid = "qr1hi-xvhdp-3d8f1zatx1xio36"
+container_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
container_request = arvados.api().container_requests().get(uuid=container_request_uuid).execute()
collection = arvados.collection.CollectionReader(container_request["log_uuid"])
for c in collection:
print(collection.open(c).read())
-</code></pre>
+{% endcodeblock %}
h2. Create a collection sharing link
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
api = arvados.api()
download="https://your.download.server"
-collection_uuid="your-4zz18-collectionuuid"
+collection_uuid="qr1hi-4zz18-zzzzzzzzzzzzzzz"
token = api.api_client_authorizations().create(body={"api_client_authorization":{"scopes": [
"GET /arvados/v1/collections/%s" % collection_uuid,
"GET /arvados/v1/collections/%s/" % collection_uuid,
"GET /arvados/v1/keep_services/accessible"]}}).execute()
print("%s/c=%s/t=%s/_/" % (download, collection_uuid, token["api_token"]))
-</code></pre>
+{% endcodeblock %}
h2. Combine two or more collections
Note, if two collections have files of the same name, the contents will be concatenated in the resulting manifest.
-<pre><code>import arvados
+{% codeblock as python %}
+import arvados
import arvados.collection
api = arvados.api()
project_uuid = "qr1hi-tpzed-zzzzzzzzzzzzzzz"
combined_manifest += c["manifest_text"]
newcol = arvados.collection.Collection(combined_manifest)
newcol.save_new(name="My combined collection", owner_uuid=project_uuid)
-</code></pre>
+{% endcodeblock %}
h2. Initialize SDK
-<pre>
+{% codeblock as python %}
import arvados
api = arvados.api("v1")
-</pre>
+{% endcodeblock %}
h2. create
-<pre>
+{% codeblock as python %}
result = api.collections().create(body={"collection": {"name": "create example"}}).execute()
-</pre>
+{% endcodeblock %}
h2. delete
-<pre>
+{% codeblock as python %}
result = api.collections().delete(uuid="aaaaa-4zz18-ccccccccccccccc").execute()
-</pre>
+{% endcodeblock %}
h2. get
-<pre>
+{% codeblock as python %}
result = api.collections().get(uuid="aaaaa-4zz18-ccccccccccccccc").execute()
-</pre>
+{% endcodeblock %}
h2. list
-<pre>
+{% codeblock as python %}
result = api.collections().list(filters=[["uuid", "=", "aaaaa-bbbbb-ccccccccccccccc"]]).execute()
-</pre>
+{% endcodeblock %}
h2. update
-<pre>
+{% codeblock as python %}
result = api.collections().update(uuid="aaaaa-4zz18-ccccccccccccccc", body={"collection": {"name": "update example"}}).execute()
-</pre>
+{% endcodeblock %}
h2. Get current user
-<pre>
+{% codeblock as python %}
result = api.users().current().execute()
-</pre>
+{% endcodeblock %}
Import the module and set up an API client user agent:
-<pre>
+{% codeblock as ruby %}
require 'arvados'
arv = Arvados.new(apiVersion: 'v1')
-</pre>
+{% endcodeblock %}
The SDK retrieves the list of API methods from the server at run time. Therefore, the set of available methods is determined by the server version rather than the SDK version.
Create an object:
-<pre>
+{% codeblock as ruby %}
new_link = arv.link.create(link: {link_class: 'test', name: 'test'})
-</pre>
+{% endcodeblock %}
h2. delete
Delete an object:
-<pre>
+{% codeblock as ruby %}
arv.link.delete(uuid: new_link[:uuid])
-</pre>
+{% endcodeblock %}
h2. get
Retrieve an object by ID:
-<pre>
+{% codeblock as ruby %}
some_user = arv.user.get(uuid: current_user_uuid)
-</pre>
+{% endcodeblock %}
h2. list
Get a list of objects:
-<pre>
+{% codeblock as ruby %}
repos = arv.repository.list
first_repo = repos[:items][0]
puts "UUID of first repo returned is #{first_repo[:uuid]}"</code>
+{% endcodeblock %}
+
UUID of first repo returned is qr1hi-s0uqq-b1bnybpx3u5temz
-</pre>
h2. update
Update an object:
-<pre>
+{% codeblock as ruby %}
updated_link = arv.link.update(uuid: new_link[:uuid],
link: {properties: {foo: 'bar'}})
-</pre>
+{% endcodeblock %}
h2. Get current user
Get the User object for the current user:
-<pre>
+{% codeblock as ruby %}
current_user = arv.user.current
-</pre>
+{% endcodeblock %}
Get the UUID of an object that was retrieved using the SDK:
-<pre>
+{% codeblock as ruby %}
current_user_uuid = current_user[:uuid]
-</pre>
+{% endcodeblock %}
def render_liquid page, content
liquid self.body, content, page, binding
end
-
+
##
# Render a page's liquid and return the intermediate result
def liquid template, content, page, binding = TOPLEVEL_BINDING
unless defined? @liquid_template
@liquid_template = Liquid::Template.parse(template)
end
-
+
vars = {}
vars["content"] = content
vars["page"] = page.config.h.clone
vars["page"]["url"] = page.url
-
+
@liquid_template.render(vars)
end
end
raise SyntaxError.new("Error in tag 'code' - Valid syntax: include '[code_file]' as '[language]'")
end
end
-
+
def render(context)
require 'coderay'
html
end
- Liquid::Template.register_tag('code', LiquidCode)
+ Liquid::Template.register_tag('code', LiquidCode)
+ end
+
+ class LiquidCodeBlock < Liquid::Block
+ Syntax = /((?:as)\s+(#{Liquid::QuotedFragment}+))?/o
+
+ def initialize(tag_name, markup, tokens)
+ Liquid::Tag.instance_method(:initialize).bind(self).call(tag_name, markup, tokens)
+
+ if markup =~ Syntax
+ @language = $2
+ @attributes = {}
+ else
+ raise SyntaxError.new("Error in tag 'code' - Valid syntax: codeblock as '[language]'")
+ end
+ end
+
+ def render(context)
+ require 'coderay'
+
+ partial = super
+ html = ''
+
+ if partial[0] == '\n'
+ partial = partial[1..-1]
+ end
+
+ context.stack do
+ html = CodeRay.scan(partial, @language).div
+ end
+
+ "<notextile>#{html}</notextile>"
+ end
+
+ Liquid::Template.register_tag('codeblock', LiquidCodeBlock)
end
end