X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/1062d90268c69372ff98be2d86cf7d9423c31da0..e20590d485505f58f7745d74a311ca539c9be940:/apps/workbench/app/controllers/work_units_controller.rb diff --git a/apps/workbench/app/controllers/work_units_controller.rb b/apps/workbench/app/controllers/work_units_controller.rb index 0c8ea6e704..86e3cdd91d 100644 --- a/apps/workbench/app/controllers/work_units_controller.rb +++ b/apps/workbench/app/controllers/work_units_controller.rb @@ -1,4 +1,13 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + class WorkUnitsController < ApplicationController + skip_around_action :require_thread_api_token, if: proc { |ctrl| + !Rails.configuration.Users.AnonymousUserToken.empty? and + 'show_child_component' == ctrl.action_name + } + def find_objects_for_index # If it's not the index rows partial display, just return # The /index request will again be invoked to display the @@ -8,23 +17,36 @@ class WorkUnitsController < ApplicationController @limit = 20 @filters = @filters || [] + pipelines = [] + jobs = [] + # get next page of pipeline_instances - filters = @filters + [["uuid", "is_a", ["arvados#pipelineInstance"]]] - pipelines = PipelineInstance.limit(@limit).order(["created_at desc"]).filter(filters) + if PipelineInstance.api_exists?(:index) + filters = @filters + [["uuid", "is_a", ["arvados#pipelineInstance"]]] + pipelines = PipelineInstance.limit(@limit).order(["created_at desc"]).filter(filters).with_count("none") + end - # get next page of jobs - filters = @filters + [["uuid", "is_a", ["arvados#job"]]] - jobs = Job.limit(@limit).order(["created_at desc"]).filter(filters) + if params[:show_children] + # get next page of jobs + if Job.api_exists?(:index) + filters = @filters + [["uuid", "is_a", ["arvados#job"]]] + jobs = Job.limit(@limit).order(["created_at desc"]).filter(filters).with_count("none") + end + end # get next page of container_requests filters = @filters + [["uuid", "is_a", ["arvados#containerRequest"]]] - crs = ContainerRequest.limit(@limit).order(["created_at desc"]).filter(filters) + if !params[:show_children] + filters << ["requesting_container_uuid", "=", nil] + end + crs = ContainerRequest.limit(@limit).order(["created_at desc"]).filter(filters).with_count("none") @objects = (jobs.to_a + pipelines.to_a + crs.to_a).sort_by(&:created_at).reverse.first(@limit) if @objects.any? @next_page_filters = next_page_filters('<=') @next_page_href = url_for(partial: :all_processes_rows, - filters: @next_page_filters.to_json) + filters: @next_page_filters.to_json, + show_children: params[:show_children]) preload_links_for_objects(@objects.to_a) else @next_page_href = nil @@ -46,12 +68,12 @@ class WorkUnitsController < ApplicationController elsif rc == Workflow # workflow json workflow = Workflow.find? template_uuid - if workflow.workflow + if workflow.definition begin - wf_json = YAML::load(workflow.workflow) + wf_json = ActiveSupport::HashWithIndifferentAccess.new YAML::load(workflow.definition) rescue => e - logger.error "Error converting workflow yaml to json: #{e.message}" - raise ArgumentError, "Error converting workflow yaml to json: #{e.message}" + logger.error "Error converting definition yaml to json: #{e.message}" + raise ArgumentError, "Error converting definition yaml to json: #{e.message}" end end @@ -61,18 +83,63 @@ class WorkUnitsController < ApplicationController attrs['properties'] = {'template_uuid' => template_uuid} attrs['priority'] = 1 attrs['state'] = "Uncommitted" + attrs['use_existing'] = false # required - attrs['command'] = ["arvados-cwl-runner", "--local", "--api=containers", "/var/lib/cwl/workflow.json", "/var/lib/cwl/cwl.input.json"] attrs['container_image'] = "arvados/jobs" attrs['cwd'] = "/var/spool/cwl" attrs['output_path'] = "/var/spool/cwl" + # runtime constriants + runtime_constraints = { + "vcpus" => 1, + "ram" => 1024 * 1024 * 1024, + "API" => true + } + + keep_cache = 256 + input_defaults = {} + if wf_json + main = get_cwl_main(wf_json) + main[:inputs].each do |input| + if input[:default] + input_defaults[cwl_shortname(input[:id])] = input[:default] + end + end + if main[:hints] + main[:hints].each do |hint| + if hint[:class] == "http://arvados.org/cwl#WorkflowRunnerResources" + if hint[:coresMin] + runtime_constraints["vcpus"] = hint[:coresMin] + end + if hint[:ramMin] + runtime_constraints["ram"] = hint[:ramMin] * 1024 * 1024 + end + if hint[:keep_cache] + keep_cache = hint[:keep_cache] + end + if hint[:acrContainerImage] + attrs['container_image'] = hint[:acrContainerImage] + end + end + end + end + end + + attrs['command'] = ["arvados-cwl-runner", + "--enable-reuse", + "--local", + "--api=containers", + "--project-uuid=#{params['work_unit']['owner_uuid']}", + "--collection-cache-size=#{keep_cache}", + "/var/lib/cwl/workflow.json#main", + "/var/lib/cwl/cwl.input.json"] + # mounts mounts = { "/var/lib/cwl/cwl.input.json" => { "kind" => "json", - "content" => {} + "content" => input_defaults }, "stdout" => { "kind" => "file", @@ -91,12 +158,6 @@ class WorkUnitsController < ApplicationController end attrs['mounts'] = mounts - # runtime constriants - runtime_constraints = { - "vcpus" => 1, - "ram" => 256000000, - "API" => true - } attrs['runtime_constraints'] = runtime_constraints else raise ArgumentError, "Unsupported template uuid: #{template_uuid}" @@ -111,4 +172,53 @@ class WorkUnitsController < ApplicationController render_error status: 422 end end + + def find_object_by_uuid + if params['object_type'] + @object = params['object_type'].constantize.find(params['uuid']) + else + super + end + end + + def show_child_component + data = JSON.load(params[:action_data]) + + current_obj = {} + current_obj_uuid = data['current_obj_uuid'] + current_obj_name = data['current_obj_name'] + current_obj_type = data['current_obj_type'] + current_obj_parent = data['current_obj_parent'] + if current_obj_uuid + resource_class = resource_class_for_uuid current_obj_uuid + obj = object_for_dataclass(resource_class, current_obj_uuid) + current_obj = obj if obj + end + + if current_obj.is_a?(Hash) and !current_obj.any? + if current_obj_parent + resource_class = resource_class_for_uuid current_obj_parent + parent = object_for_dataclass(resource_class, current_obj_parent) + parent_wu = parent.work_unit + children = parent_wu.children + if current_obj_uuid + wu = children.select {|c| c.uuid == current_obj_uuid}.first + else current_obj_name + wu = children.select {|c| c.label.to_s == current_obj_name}.first + end + end + else + if current_obj_type == JobWorkUnit.to_s + wu = JobWorkUnit.new(current_obj, current_obj_name, current_obj_parent) + elsif current_obj_type == PipelineInstanceWorkUnit.to_s + wu = PipelineInstanceWorkUnit.new(current_obj, current_obj_name, current_obj_parent) + elsif current_obj_type == ContainerWorkUnit.to_s + wu = ContainerWorkUnit.new(current_obj, current_obj_name, current_obj_parent) + end + end + + respond_to do |f| + f.html { render(partial: "show_component", locals: {wu: wu}) } + end + end end