[ARVADOS] created: 05f94a7837527f79df122e9942eaab166e987b15

Git user git at public.curoverse.com
Wed Jan 4 09:26:25 EST 2017


        at  05f94a7837527f79df122e9942eaab166e987b15 (commit)


commit 05f94a7837527f79df122e9942eaab166e987b15
Author: Lucas Di Pentima <lucas at curoverse.com>
Date:   Wed Jan 4 11:25:20 2017 -0300

    10223: Added support to CR output_name on cwl-runner. Updated test.

diff --git a/sdk/cwl/arvados_cwl/arvcontainer.py b/sdk/cwl/arvados_cwl/arvcontainer.py
index dbbd83d..edf8c26 100644
--- a/sdk/cwl/arvados_cwl/arvcontainer.py
+++ b/sdk/cwl/arvados_cwl/arvcontainer.py
@@ -237,6 +237,7 @@ class RunnerContainer(Runner):
         command = ["arvados-cwl-runner", "--local", "--api=containers"]
         if self.output_name:
             command.append("--output-name=" + self.output_name)
+            container_req["output_name"] = self.output_name
 
         if self.output_tags:
             command.append("--output-tags=" + self.output_tags)
diff --git a/sdk/cwl/tests/test_submit.py b/sdk/cwl/tests/test_submit.py
index a39972b..17b864b 100644
--- a/sdk/cwl/tests/test_submit.py
+++ b/sdk/cwl/tests/test_submit.py
@@ -469,6 +469,7 @@ class TestSubmit(unittest.TestCase):
             logging.exception("")
 
         stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', "--output-name="+output_name, '--enable-reuse', '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/cwl.input.json']
+        stubs.expect_container_spec["output_name"] = output_name
 
         expect_container = copy.deepcopy(stubs.expect_container_spec)
         stubs.api.container_requests().create.assert_called_with(

commit f81427c5f93c159d26c3125aaa7ede4c5986dd07
Author: Lucas Di Pentima <lucas at curoverse.com>
Date:   Mon Jan 2 18:14:33 2017 -0300

    10223: Added output_name column to container_request. When being finalized, if output_name is set then the output
    collection will be named accordingly. If there is a unique index violation, a date is added to its name.
    Also, added output_name to CR search index.

diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb
index f92fa21..4555820 100644
--- a/services/api/app/models/container_request.rb
+++ b/services/api/app/models/container_request.rb
@@ -35,18 +35,19 @@ class ContainerRequest < ArvadosModel
     t.add :environment
     t.add :expires_at
     t.add :filters
+    t.add :log_uuid
     t.add :mounts
     t.add :name
+    t.add :output_name
     t.add :output_path
+    t.add :output_uuid
     t.add :priority
     t.add :properties
     t.add :requesting_container_uuid
     t.add :runtime_constraints
+    t.add :scheduling_parameters
     t.add :state
     t.add :use_existing
-    t.add :output_uuid
-    t.add :log_uuid
-    t.add :scheduling_parameters
   end
 
   # Supported states for a container request
@@ -90,15 +91,34 @@ class ContainerRequest < ArvadosModel
     ['output', 'log'].each do |out_type|
       pdh = c.send(out_type)
       next if pdh.nil?
+      if self.output_name and out_type == 'output'
+        coll_name = self.output_name
+      else
+        coll_name = "Container #{out_type} for request #{uuid}"
+      end
       manifest = Collection.where(portable_data_hash: pdh).first.manifest_text
-      coll = Collection.create!(owner_uuid: owner_uuid,
-                         manifest_text: manifest,
-                         portable_data_hash: pdh,
-                         name: "Container #{out_type} for request #{uuid}",
-                         properties: {
-                           'type' => out_type,
-                           'container_request' => uuid,
-                         })
+      begin
+        coll = Collection.create!(owner_uuid: owner_uuid,
+                                  manifest_text: manifest,
+                                  portable_data_hash: pdh,
+                                  name: coll_name,
+                                  properties: {
+                                    'type' => out_type,
+                                    'container_request' => uuid,
+                                  })
+      rescue ActiveRecord::RecordNotUnique => rn
+        ActiveRecord::Base.connection.execute 'ROLLBACK'
+        raise unless out_type == 'output' and self.output_name
+        # Postgres specific unique name check. See ApplicationController#create for
+        # a detailed explanation.
+        raise unless rn.original_exception.is_a? PG::UniqueViolation
+        err = rn.original_exception
+        detail = err.result.error_field(PG::Result::PG_DIAG_MESSAGE_DETAIL)
+        raise unless /^Key \(owner_uuid, name\)=\([a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}, .*?\) already exists\./.match detail
+        # Output collection name collision detected: append a timestamp.
+        coll_name = "#{self.output_name} #{Time.now.getgm.strftime('%FT%TZ')}"
+        retry
+      end
       if out_type == 'output'
         out_coll = coll.uuid
       else
@@ -269,7 +289,8 @@ class ContainerRequest < ArvadosModel
                      :container_image, :cwd, :description, :environment,
                      :filters, :mounts, :name, :output_path, :priority,
                      :properties, :requesting_container_uuid, :runtime_constraints,
-                     :state, :container_uuid, :use_existing, :scheduling_parameters
+                     :state, :container_uuid, :use_existing, :scheduling_parameters,
+                     :output_name
 
     when Committed
       if container_uuid.nil?
@@ -281,14 +302,16 @@ class ContainerRequest < ArvadosModel
       end
 
       # Can update priority, container count, name and description
-      permitted.push :priority, :container_count, :container_count_max, :container_uuid, :name, :description
+      permitted.push :priority, :container_count, :container_count_max, :container_uuid,
+                     :name, :description
 
       if self.state_changed?
         # Allow create-and-commit in a single operation.
         permitted.push :command, :container_image, :cwd, :description, :environment,
                        :filters, :mounts, :name, :output_path, :properties,
                        :requesting_container_uuid, :runtime_constraints,
-                       :state, :container_uuid, :use_existing, :scheduling_parameters
+                       :state, :container_uuid, :use_existing, :scheduling_parameters,
+                       :output_name
       end
 
     when Final
diff --git a/services/api/db/migrate/20161223090712_add_output_name_to_container_requests.rb b/services/api/db/migrate/20161223090712_add_output_name_to_container_requests.rb
new file mode 100644
index 0000000..0e6adfb
--- /dev/null
+++ b/services/api/db/migrate/20161223090712_add_output_name_to_container_requests.rb
@@ -0,0 +1,9 @@
+class AddOutputNameToContainerRequests < ActiveRecord::Migration
+  def up
+    add_column :container_requests, :output_name, :string, :default => nil
+  end
+
+  def down
+    remove_column :container_requests, :output_name
+  end
+end
diff --git a/services/api/db/migrate/20170102153111_add_output_name_to_container_request_search_index.rb b/services/api/db/migrate/20170102153111_add_output_name_to_container_request_search_index.rb
new file mode 100644
index 0000000..0bd7c47
--- /dev/null
+++ b/services/api/db/migrate/20170102153111_add_output_name_to_container_request_search_index.rb
@@ -0,0 +1,21 @@
+class AddOutputNameToContainerRequestSearchIndex < ActiveRecord::Migration
+  def up
+    begin
+      remove_index :container_requests, :name => 'container_requests_search_index'
+    rescue
+    end
+    add_index :container_requests,
+              ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "name", "state", "requesting_container_uuid", "container_uuid", "container_image", "cwd", "output_path", "output_uuid", "log_uuid", "output_name"],
+              name: "container_requests_search_index"
+  end
+
+  def down
+    begin
+      remove_index :container_requests, :name => 'container_requests_search_index'
+    rescue
+    end
+	  add_index :container_requests,
+              ["uuid", "owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "name", "state", "requesting_container_uuid", "container_uuid", "container_image", "cwd", "output_path", "output_uuid", "log_uuid"],
+              name: "container_requests_search_index"
+  end
+end
diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql
index 7ee7ea6..fb32872 100644
--- a/services/api/db/structure.sql
+++ b/services/api/db/structure.sql
@@ -294,7 +294,8 @@ CREATE TABLE container_requests (
     use_existing boolean DEFAULT true,
     scheduling_parameters text,
     output_uuid character varying(255),
-    log_uuid character varying(255)
+    log_uuid character varying(255),
+    output_name character varying(255) DEFAULT NULL::character varying
 );
 
 
@@ -1527,7 +1528,7 @@ CREATE INDEX container_requests_full_text_search_idx ON container_requests USING
 -- Name: container_requests_search_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
 --
 
-CREATE INDEX container_requests_search_index ON container_requests USING btree (uuid, owner_uuid, modified_by_client_uuid, modified_by_user_uuid, name, state, requesting_container_uuid, container_uuid, container_image, cwd, output_path, output_uuid, log_uuid);
+CREATE INDEX container_requests_search_index ON container_requests USING btree (uuid, owner_uuid, modified_by_client_uuid, modified_by_user_uuid, name, state, requesting_container_uuid, container_uuid, container_image, cwd, output_path, output_uuid, log_uuid, output_name);
 
 
 --
@@ -2706,4 +2707,8 @@ INSERT INTO schema_migrations (version) VALUES ('20161115171221');
 
 INSERT INTO schema_migrations (version) VALUES ('20161115174218');
 
-INSERT INTO schema_migrations (version) VALUES ('20161213172944');
\ No newline at end of file
+INSERT INTO schema_migrations (version) VALUES ('20161213172944');
+
+INSERT INTO schema_migrations (version) VALUES ('20161223090712');
+
+INSERT INTO schema_migrations (version) VALUES ('20170102153111');
\ No newline at end of file
diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb
index c4d1efe..1f65c01 100644
--- a/services/api/test/unit/container_request_test.rb
+++ b/services/api/test/unit/container_request_test.rb
@@ -505,6 +505,41 @@ class ContainerRequestTest < ActiveSupport::TestCase
     assert_equal prev_container_uuid, cr.container_uuid
   end
 
+  test "Set up output collection on finalized container request" do
+    set_user_from_auth :active
+    output_name = 'Test output collection'
+    cr = create_minimal_req!(priority: 1,
+                             state: ContainerRequest::Committed,
+                             output_name: output_name)
+    cr.reload
+    act_as_system_user do
+      c = Container.find_by_uuid(cr.container_uuid)
+      c.update_attributes!(state: Container::Locked)
+      c.update_attributes!(state: Container::Running)
+      c.update_attributes!(state: Container::Complete,
+                           exit_code: 0,
+                           output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45',
+                           log: 'fa7aeb5140e2848d39b416daeef4ffc5+45')
+    end
+    cr.reload
+    output_coll = Collection.find_by_uuid(cr.output_uuid)
+    assert_not_nil output_coll
+    assert_equal output_coll.name, output_name
+    # Now ask for a second CR, equal to the first one so it will reuse the container
+    cr2 = create_minimal_req!(priority: 1,
+                              state: ContainerRequest::Uncommitted,
+                              output_name: output_name)
+    cr2.state = ContainerRequest::Committed
+    cr2.save
+    assert_equal ContainerRequest::Final, cr2.state
+    output_coll_2 = Collection.find_by_uuid(cr2.output_uuid)
+    # Make sure the resulting output collection name include the original name
+    # plus the date
+    assert_not_equal output_coll_2.name, output_coll.name
+    assert output_coll_2.name.include? output_name
+    assert_match /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/, output_coll_2.name
+  end
+
   test "Finalize committed request when reusing a finished container" do
     set_user_from_auth :active
     cr = create_minimal_req!(priority: 1, state: ContainerRequest::Committed)

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list