From a5dd553652713ea202d7ac4291836fac649031b4 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 6 May 2022 16:10:21 -0400 Subject: [PATCH] 17004: Add API server tests for output_properties Fix migration to update the trigram index Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- .../20220505112900_add_output_properties.rb | 23 +++++++++- services/api/db/structure.sql | 11 +++-- .../api/test/unit/container_request_test.rb | 42 +++++++++++++++++++ 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/services/api/db/migrate/20220505112900_add_output_properties.rb b/services/api/db/migrate/20220505112900_add_output_properties.rb index 42cde03bc7..7d8c4b1ffb 100644 --- a/services/api/db/migrate/20220505112900_add_output_properties.rb +++ b/services/api/db/migrate/20220505112900_add_output_properties.rb @@ -3,8 +3,29 @@ # SPDX-License-Identifier: AGPL-3.0 class AddOutputProperties < ActiveRecord::Migration[5.2] - def change + def trgm_indexes + { + "container_requests" => "container_requests_trgm_text_search_idx", + } + end + + def up add_column :container_requests, :output_properties, :jsonb, default: {} add_column :containers, :output_properties, :jsonb, default: {} + + trgm_indexes.each do |model, indx| + execute "DROP INDEX IF EXISTS #{indx}" + execute "CREATE INDEX #{indx} ON #{model} USING gin((#{model.classify.constantize.full_text_trgm}) gin_trgm_ops)" + end + end + + def down + remove_column :container_requests, :output_properties + remove_column :containers, :output_properties + + trgm_indexes.each do |model, indx| + execute "DROP INDEX IF EXISTS #{indx}" + execute "CREATE INDEX #{indx} ON #{model} USING gin((#{model.classify.constantize.full_text_trgm}) gin_trgm_ops)" + end end end diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql index e6bba67625..c5f6d567bf 100644 --- a/services/api/db/structure.sql +++ b/services/api/db/structure.sql @@ -480,7 +480,8 @@ CREATE TABLE public.container_requests ( output_ttl integer DEFAULT 0 NOT NULL, secret_mounts jsonb DEFAULT '{}'::jsonb, runtime_token text, - output_storage_classes jsonb DEFAULT '["default"]'::jsonb + output_storage_classes jsonb DEFAULT '["default"]'::jsonb, + output_properties jsonb DEFAULT '{}'::jsonb ); @@ -543,7 +544,8 @@ CREATE TABLE public.containers ( lock_count integer DEFAULT 0 NOT NULL, gateway_address character varying, interactive_session_started boolean DEFAULT false NOT NULL, - output_storage_classes jsonb DEFAULT '["default"]'::jsonb + output_storage_classes jsonb DEFAULT '["default"]'::jsonb, + output_properties jsonb DEFAULT '{}'::jsonb ); @@ -1782,7 +1784,7 @@ CREATE INDEX container_requests_search_index ON public.container_requests USING -- Name: container_requests_trgm_text_search_idx; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX container_requests_trgm_text_search_idx ON public.container_requests USING gin (((((((((((((((((((((((((((((((((((((((((((COALESCE(uuid, ''::character varying))::text || ' '::text) || (COALESCE(owner_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(modified_by_client_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(modified_by_user_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(name, ''::character varying))::text) || ' '::text) || COALESCE(description, ''::text)) || ' '::text) || COALESCE((properties)::text, ''::text)) || ' '::text) || (COALESCE(state, ''::character varying))::text) || ' '::text) || (COALESCE(requesting_container_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(container_uuid, ''::character varying))::text) || ' '::text) || COALESCE(runtime_constraints, ''::text)) || ' '::text) || (COALESCE(container_image, ''::character varying))::text) || ' '::text) || COALESCE(environment, ''::text)) || ' '::text) || (COALESCE(cwd, ''::character varying))::text) || ' '::text) || COALESCE(command, ''::text)) || ' '::text) || (COALESCE(output_path, ''::character varying))::text) || ' '::text) || COALESCE(filters, ''::text)) || ' '::text) || COALESCE(scheduling_parameters, ''::text)) || ' '::text) || (COALESCE(output_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(log_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(output_name, ''::character varying))::text)) public.gin_trgm_ops); +CREATE INDEX container_requests_trgm_text_search_idx ON public.container_requests USING gin (((((((((((((((((((((((((((((((((((((((((((((COALESCE(uuid, ''::character varying))::text || ' '::text) || (COALESCE(owner_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(modified_by_client_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(modified_by_user_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(name, ''::character varying))::text) || ' '::text) || COALESCE(description, ''::text)) || ' '::text) || COALESCE((properties)::text, ''::text)) || ' '::text) || (COALESCE(state, ''::character varying))::text) || ' '::text) || (COALESCE(requesting_container_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(container_uuid, ''::character varying))::text) || ' '::text) || COALESCE(runtime_constraints, ''::text)) || ' '::text) || (COALESCE(container_image, ''::character varying))::text) || ' '::text) || COALESCE(environment, ''::text)) || ' '::text) || (COALESCE(cwd, ''::character varying))::text) || ' '::text) || COALESCE(command, ''::text)) || ' '::text) || (COALESCE(output_path, ''::character varying))::text) || ' '::text) || COALESCE(filters, ''::text)) || ' '::text) || COALESCE(scheduling_parameters, ''::text)) || ' '::text) || (COALESCE(output_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(log_uuid, ''::character varying))::text) || ' '::text) || (COALESCE(output_name, ''::character varying))::text) || ' '::text) || COALESCE((output_properties)::text, ''::text))) public.gin_trgm_ops); -- @@ -3179,6 +3181,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220224203102'), ('20220301155729'), ('20220303204419'), -('20220401153101'); +('20220401153101'), +('20220505112900'); diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb index aa649e9106..5a75fb5fa2 100644 --- a/services/api/test/unit/container_request_test.rb +++ b/services/api/test/unit/container_request_test.rb @@ -1448,4 +1448,46 @@ class ContainerRequestTest < ActiveSupport::TestCase assert_equal ["foo_storage_class"], output1.storage_classes_desired assert_equal ["bar_storage_class"], output2.storage_classes_desired end + + [ + [{}, {}, {"type": "output"}], + [{"a1": "b1"}, {}, {"type": "output", "a1": "b1"}], + [{}, {"a1": "b1"}, {"type": "output", "a1": "b1"}], + [{"a1": "b1"}, {"a1": "c1"}, {"type": "output", "a1": "b1"}], + [{"a1": "b1"}, {"a2": "c2"}, {"type": "output", "a1": "b1", "a2": "c2"}], + [{"type": "blah"}, {}, {"type": "output"}], + ].each do |cr_prop, container_prop, expect_prop| + test "setting output_properties #{cr_prop} #{container_prop} on current container" do + act_as_user users(:active) do + cr = create_minimal_req!(priority: 1, + state: ContainerRequest::Committed, + output_name: 'foo', + output_properties: cr_prop) + + act_as_system_user do + logc = Collection.new(owner_uuid: system_user_uuid, + manifest_text: ". ef772b2f28e2c8ca84de45466ed19ee9+7815 0:0:arv-mount.txt\n") + logc.save! + + c = Container.find_by_uuid(cr.container_uuid) + c.update_attributes!(state: Container::Locked) + c.update_attributes!(state: Container::Running) + + c.update_attributes!(output_properties: container_prop) + + c.update_attributes!(state: Container::Complete, + exit_code: 0, + output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45', + log: logc.portable_data_hash) + logc.destroy + end + + cr.reload + expect_prop["container_request"] = cr.uuid + output = Collection.find_by_uuid(cr.output_uuid) + assert_equal expect_prop.symbolize_keys, output.properties.symbolize_keys + end + end + end + end -- 2.30.2