10293: add output_uuid to container_request and set it during finalize.
authorradhika <radhika@curoverse.com>
Thu, 10 Nov 2016 22:16:52 +0000 (17:16 -0500)
committerradhika <radhika@curoverse.com>
Thu, 10 Nov 2016 22:16:52 +0000 (17:16 -0500)
services/api/app/models/container_request.rb
services/api/db/migrate/20161110171221_add_output_uuid_to_container_request.rb [new file with mode: 0644]
services/api/db/structure.sql
services/api/test/unit/container_request_test.rb

index 05738de81e50627654e62e3f3a34d6cc46754460..bac4032f67d2b7871009727e4c8c2230b8a0dc2e 100644 (file)
@@ -42,6 +42,7 @@ class ContainerRequest < ArvadosModel
     t.add :runtime_constraints
     t.add :state
     t.add :use_existing
+    t.add :output_uuid
   end
 
   # Supported states for a container request
@@ -79,13 +80,13 @@ class ContainerRequest < ArvadosModel
   # Finalize the container request after the container has
   # finished/cancelled.
   def finalize!
-    update_attributes!(state: Final)
+    out_uuid = nil
     c = Container.find_by_uuid(container_uuid)
     ['output', 'log'].each do |out_type|
       pdh = c.send(out_type)
       next if pdh.nil?
       manifest = Collection.where(portable_data_hash: pdh).first.manifest_text
-      Collection.create!(owner_uuid: owner_uuid,
+      coll = Collection.create!(owner_uuid: owner_uuid,
                          manifest_text: manifest,
                          portable_data_hash: pdh,
                          name: "Container #{out_type} for request #{uuid}",
@@ -93,7 +94,9 @@ class ContainerRequest < ArvadosModel
                            'type' => out_type,
                            'container_request' => uuid,
                          })
+      out_uuid = coll.uuid if out_type == 'output'
     end
+    update_attributes!(state: Final, output_uuid: out_uuid)
   end
 
   protected
@@ -271,8 +274,8 @@ class ContainerRequest < ArvadosModel
         errors.add :state, "of container request can only be set to Final by system."
       end
 
-      if self.state_changed? || self.name_changed? || self.description_changed?
-          permitted.push :state, :name, :description
+      if self.state_changed? || self.name_changed? || self.description_changed? || self.output_uuid_changed?
+          permitted.push :state, :name, :description, :output_uuid
       else
         errors.add :state, "does not allow updates"
       end
diff --git a/services/api/db/migrate/20161110171221_add_output_uuid_to_container_request.rb b/services/api/db/migrate/20161110171221_add_output_uuid_to_container_request.rb
new file mode 100644 (file)
index 0000000..3c590b1
--- /dev/null
@@ -0,0 +1,18 @@
+require 'has_uuid'
+
+class AddOutputUuidToContainerRequest < ActiveRecord::Migration
+  extend HasUuid::ClassMethods
+
+  def up
+    add_column :container_requests, :output_uuid, :string
+
+    no_such_coll = Server::Application.config.uuid_prefix + '-' + '4zz18' + '-xxxxxxxxxxxxxxx'
+    update_sql <<-EOS
+update container_requests set output_uuid = ('#{no_such_coll}');
+EOS
+  end
+
+  def down
+    remove_column :container_requests, :output_uuid
+  end
+end
index 0db782af69484e6a8e0c476620891702055f36c7..a3f4f5578bfebe934d42123444e8b22bdd21518a 100644 (file)
@@ -291,7 +291,8 @@ CREATE TABLE container_requests (
     filters text,
     updated_at timestamp without time zone NOT NULL,
     container_count integer DEFAULT 0,
-    use_existing boolean DEFAULT true
+    use_existing boolean DEFAULT true,
+    output_uuid character varying(255)
 );
 
 
@@ -2694,4 +2695,6 @@ INSERT INTO schema_migrations (version) VALUES ('20160909181442');
 
 INSERT INTO schema_migrations (version) VALUES ('20160926194129');
 
-INSERT INTO schema_migrations (version) VALUES ('20161019171346');
\ No newline at end of file
+INSERT INTO schema_migrations (version) VALUES ('20161019171346');
+
+INSERT INTO schema_migrations (version) VALUES ('20161110171221');
\ No newline at end of file
index 34aa442c0938381e5fb56ebb2c6379616ad93976..aa6a34d6a0533d610fa52488d74455e0e6949eb0 100644 (file)
@@ -230,9 +230,10 @@ class ContainerRequestTest < ActiveSupport::TestCase
     cr.reload
     assert_equal "Committed", cr.state
 
+    output_pdh = '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'
     act_as_system_user do
       c.update_attributes!(state: Container::Complete,
-                           output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45',
+                           output: output_pdh,
                            log: 'fa7aeb5140e2848d39b416daeef4ffc5+45')
     end
 
@@ -244,6 +245,9 @@ class ContainerRequestTest < ActiveSupport::TestCase
                                        owner_uuid: project.uuid).count,
                    "Container #{out_type} should be copied to #{project.uuid}")
     end
+    assert_not_nil cr.output_uuid
+    output = Collection.find_by_uuid cr.output_uuid
+    assert_equal output_pdh, output.portable_data_hash
   end
 
   test "Container makes container request, then is cancelled" do