Merge branch '15424-wb2-welcome-page' refs #15424
[arvados.git] / services / api / app / models / container_request.rb
index 7a710f070dc618b4863c5a2260f167c3c5914656..5a7818147308a6f3fa41966430ffce837ab2cee7 100644 (file)
@@ -76,24 +76,6 @@ class ContainerRequest < ArvadosModel
     t.add :use_existing
   end
 
-  def self._index_requires_parameters
-    (super rescue {}).
-      merge({
-        include_trash: {
-          type: 'boolean', required: false, description: "Include container requests whose owner project is trashed."
-        },
-      })
-  end
-
-  def self._show_requires_parameters
-    (super rescue {}).
-      merge({
-        include_trash: {
-          type: 'boolean', required: false, description: "Show container request even if its owner project is trashed."
-        },
-      })
-  end
-
   # Supported states for a container request
   States =
     [
@@ -171,7 +153,27 @@ class ContainerRequest < ArvadosModel
   # Finalize the container request after the container has
   # finished/cancelled.
   def finalize!
-    update_collections(container: Container.find_by_uuid(container_uuid))
+    container = Container.find_by_uuid(container_uuid)
+    update_collections(container: container)
+
+    if container.state == Container::Complete
+      log_col = Collection.where(portable_data_hash: container.log).first
+      if log_col
+        # Need to save collection
+        completed_coll = Collection.new(
+          owner_uuid: self.owner_uuid,
+          name: "Container log for container #{container_uuid}",
+          properties: {
+            'type' => 'log',
+            'container_request' => self.uuid,
+            'container_uuid' => container_uuid,
+          },
+          portable_data_hash: log_col.portable_data_hash,
+          manifest_text: log_col.manifest_text)
+        completed_coll.save_with_unique_name!
+      end
+    end
+
     update_attributes!(state: Final)
   end
 
@@ -205,6 +207,7 @@ class ContainerRequest < ArvadosModel
       end
 
       if out_type == "log"
+        # Copy the log into a merged collection
         src = Arv::Collection.new(manifest)
         dst = Arv::Collection.new(coll.manifest_text)
         dst.cp_r("./", ".", src)