14870: Saving previous retry logs into collection WIP
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Fri, 1 Mar 2019 20:48:56 +0000 (15:48 -0500)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Fri, 1 Mar 2019 21:21:44 +0000 (16:21 -0500)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

services/api/app/models/container_request.rb
services/api/test/unit/container_request_test.rb

index 0c2ad096557d3f335fa398946a9c8dc1012044e2..e1ae2b54891adbc85e8fc6b48e17e9faaeac9b59 100644 (file)
@@ -3,6 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0
 
 require 'whitelist_update'
+require 'arvados/collection'
 
 class ContainerRequest < ArvadosModel
   include ArvadosModelUpdates
@@ -149,18 +150,28 @@ class ContainerRequest < ArvadosModel
       manifest = Collection.where(portable_data_hash: pdh).first.manifest_text
 
       coll_uuid = self.send(out_type + '_uuid')
-      coll = coll_uuid.nil? ? nil : Collection.where(uuid: coll_uuid).first
+      coll = coll_uuid.nil? ? nil : Collection.find_by_uuid(coll_uuid)
       if !coll
         coll = Collection.new(
           owner_uuid: self.owner_uuid,
           name: coll_name,
+          manifest_text: "",
           properties: {
             'type' => out_type,
             'container_request' => uuid,
           })
       end
+
+      if out_type == "log"
+        src = Arv::Collection.new(manifest)
+        dst = Arv::Collection.new(coll.manifest_text)
+        dst.cp_r("./", ".", src)
+        dst.cp_r("./", "container #{container.uuid}", src)
+        manifest = dst.manifest_text
+      end
+
       coll.assign_attributes(
-        portable_data_hash: pdh,
+        portable_data_hash: Digest::MD5.hexdigest(manifest) + '+' + manifest.bytesize.to_s,
         manifest_text: manifest,
         trash_at: trash_at,
         delete_at: trash_at)
@@ -203,6 +214,16 @@ class ContainerRequest < ArvadosModel
         return false
       else
         self.container_count += 1
+        if self.container_uuid_was
+          # old_container = Container.find_by_uuid()
+          # # copy logs from old container into CR's log collection
+          # #
+          #   src = Arv::Collection.new(manifest)
+          #   tgt = Arv::Collection.new(coll.manifest_text)
+          #   tgt.cp_r("./", "./", src)
+          #   tgt.cp_r("./", "container #{container.uuid}", src)
+          #   manifest = tgt.manifest_text
+        end
       end
     end
   end
index a7700573d4d83eade9badb4d9c4b0650ddc0947e..86f05d301a59fab402c3cb3dc7c967a6744d9480 100644 (file)
@@ -245,6 +245,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
     cr.reload
     assert_equal "Final", cr.state
     assert_equal users(:active).uuid, cr.modified_by_user_uuid
+    puts "CR #{Collection.find_by_uuid(cr.log_uuid).manifest_text}"
     ['output', 'log'].each do |out_type|
       pdh = Container.find_by_uuid(cr.container_uuid).send(out_type)
       assert_equal(1, Collection.where(portable_data_hash: pdh,