From 343e6545572e17e8a0aa880d5e9fea809a31d091 Mon Sep 17 00:00:00 2001 From: Nikolay Yordanov Date: Thu, 23 Nov 2023 11:45:52 +0200 Subject: [PATCH] [HOTFIX] Enable App Template subscription flow in ORD Service (#3490) * Apply hotfix changes * Bump versions --- chart/compass/values.yaml | 12 +- ...-views-app-tmpl-subscription-flow.down.sql | 715 ++++++++++++++++++ ...ix-views-app-tmpl-subscription-flow.up.sql | 699 +++++++++++++++++ tests/ord-aggregator/tests/handler_test.go | 10 +- .../tests/subscription_flow_test.go | 13 +- 5 files changed, 1432 insertions(+), 17 deletions(-) create mode 100644 components/schema-migrator/migrations/director/20231121105202_ord-fix-views-app-tmpl-subscription-flow.down.sql create mode 100644 components/schema-migrator/migrations/director/20231121105202_ord-fix-views-app-tmpl-subscription-flow.up.sql diff --git a/chart/compass/values.yaml b/chart/compass/values.yaml index 864b6f0b6f..3cbdeb6d0c 100644 --- a/chart/compass/values.yaml +++ b/chart/compass/values.yaml @@ -199,12 +199,12 @@ global: version: "v20231121-e91239f0" name: compass-operations-controller ord_service: - dir: prod/incubator/ - version: "v20231110-4f59bcba" + dir: dev/incubator/ + version: "PR-111" name: compass-ord-service schema_migrator: - dir: prod/incubator/ - version: "v20231121-e91239f0" + dir: dev/incubator/ + version: "PR-3490" name: compass-schema-migrator system_broker: dir: prod/incubator/ @@ -224,8 +224,8 @@ global: version: "v20230421-e8840c18" name: compass-console e2e_tests: - dir: prod/incubator/ - version: "v20231123-94083bbe" + dir: dev/incubator/ + version: "PR-3490" name: compass-e2e-tests isLocalEnv: false isForTesting: false diff --git a/components/schema-migrator/migrations/director/20231121105202_ord-fix-views-app-tmpl-subscription-flow.down.sql b/components/schema-migrator/migrations/director/20231121105202_ord-fix-views-app-tmpl-subscription-flow.down.sql new file mode 100644 index 0000000000..54702b0b93 --- /dev/null +++ b/components/schema-migrator/migrations/director/20231121105202_ord-fix-views-app-tmpl-subscription-flow.down.sql @@ -0,0 +1,715 @@ +BEGIN; + +-- drop views +DROP VIEW IF EXISTS tenants_specifications; -- this one won't be changed but it uses tenants_apis/events and it has to be dropped so the other two can be as well +DROP VIEW IF EXISTS tenants_entity_type_mappings; -- this one won't be changed but it uses tenants_apis/events and it has to be dropped so the other two can be as well +DROP VIEW IF EXISTS entity_type_mappings_tenants; -- this one won't be changed but it uses tenants_apis/events and it has to be dropped so the other two can be as well +DROP VIEW IF EXISTS tenants_apps; +DROP VIEW IF EXISTS tenants_apis; +DROP VIEW IF EXISTS tenants_aspects; +DROP VIEW IF EXISTS tenants_bundles; +DROP VIEW IF EXISTS tenants_capabilities; +DROP VIEW IF EXISTS tenants_entity_types; +DROP VIEW IF EXISTS tenants_events; +DROP VIEW IF EXISTS tenants_integration_dependencies; +DROP VIEW IF EXISTS tenants_packages; +DROP VIEW IF EXISTS tenants_products; +DROP VIEW IF EXISTS tenants_tombstones; +DROP VIEW IF EXISTS tenants_vendors; +DROP VIEW IF EXISTS apps_formations_id; + +-- drop formations index on tenant_id column +DROP INDEX IF EXISTS formations_tenant_id; + +-- recreate views + +CREATE OR REPLACE VIEW tenants_apps + (tenant_id, formation_id, id, name, description, status_condition, status_timestamp, healthcheck_url, + integration_system_id, provider_name, base_url, labels, tags, ready, created_at, updated_at, deleted_at, + error, app_template_id, correlation_ids, system_number, application_namespace, local_tenant_id, + tenant_business_type_id, product_type) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + apps.id, + apps.name, + apps.description, + apps.status_condition, + apps.status_timestamp, + apps.healthcheck_url, + apps.integration_system_id, + apps.provider_name, + apps.base_url, + apps.labels, + apps.tags, + apps.ready, + apps.created_at, + apps.updated_at, + apps.deleted_at, + apps.error, + apps.app_template_id, + apps.correlation_ids, + apps.system_number, + COALESCE(apps.application_namespace, tmpl.application_namespace) AS application_namespace, + apps.local_tenant_id, + apps.tenant_business_type_id, + tmpl.name AS product_type +FROM applications apps + LEFT JOIN app_templates tmpl ON apps.app_template_id = tmpl.id + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON apps.id = t_apps.id; + + +CREATE OR REPLACE VIEW tenants_apis + (tenant_id, formation_id, id, app_id, name, description, group_name, default_auth, version_value, + version_deprecated, version_deprecated_since, version_for_removal, ord_id, local_tenant_id, + short_description, system_instance_aware, policy_level, custom_policy_level, api_protocol, tags, + supported_use_cases, countries, links, api_resource_links, release_status, sunset_date, changelog_entries, + labels, package_id, visibility, disabled, part_of_products, line_of_business, industry, ready, created_at, + updated_at, deleted_at, error, implementation_standard, custom_implementation_standard, + custom_implementation_standard_description, target_urls, extensible_supported, extensible_description, + successors, resource_hash, documentation_labels, correlation_ids, direction, last_update, deprecation_date) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + apis.id, + apis.app_id, + apis.name, + apis.description, + apis.group_name, + apis.default_auth, + apis.version_value, + apis.version_deprecated, + apis.version_deprecated_since, + apis.version_for_removal, + apis.ord_id, + apis.local_tenant_id, + apis.short_description, + apis.system_instance_aware, + apis.policy_level, + apis.custom_policy_level, + apis.api_protocol, + apis.tags, + apis.supported_use_cases, + apis.countries, + apis.links, + apis.api_resource_links, + apis.release_status, + apis.sunset_date, + apis.changelog_entries, + apis.labels, + apis.package_id, + apis.visibility, + apis.disabled, + apis.part_of_products, + apis.line_of_business, + apis.industry, + apis.ready, + apis.created_at, + apis.updated_at, + apis.deleted_at, + apis.error, + apis.implementation_standard, + apis.custom_implementation_standard, + apis.custom_implementation_standard_description, + apis.target_urls, + actions.supported AS extensible_supported, + actions.description AS extensible_description, + apis.successors, + apis.resource_hash, + apis.documentation_labels, + apis.correlation_ids, + apis.direction, + apis.last_update, + apis.deprecation_date +FROM api_definitions apis + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON apis.app_id = t_apps.id, + jsonb_to_record(apis.extensible) actions(supported text, description text); + + +CREATE OR REPLACE VIEW tenants_aspects + (tenant_id, formation_id, id, integration_dependency_id, app_id, title, description, mandatory, + support_multiple_providers, api_resources, event_resources, ready, created_at, updated_at, deleted_at, + error) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + a.id, + a.integration_dependency_id, + a.app_id, + a.title, + a.description, + a.mandatory, + a.support_multiple_providers, + a.api_resources, + a.event_resources, + a.ready, + a.created_at, + a.updated_at, + a.deleted_at, + a.error +FROM aspects a + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON a.app_id = t_apps.id; + + +CREATE OR REPLACE VIEW tenants_bundles + (tenant_id, formation_id, id, app_id, name, description, version, instance_auth_request_json_schema, + default_instance_auth, ord_id, local_tenant_id, short_description, links, labels, tags, + credential_exchange_strategies, ready, created_at, updated_at, deleted_at, error, correlation_ids, + resource_hash) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + b.id, + b.app_id, + b.name, + b.description, + b.version, + b.instance_auth_request_json_schema, + b.default_instance_auth, + b.ord_id, + b.local_tenant_id, + b.short_description, + b.links, + b.labels, + b.tags, + b.credential_exchange_strategies, + b.ready, + b.created_at, + b.updated_at, + b.deleted_at, + b.error, + b.correlation_ids, + b.resource_hash +FROM bundles b + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON b.app_id = t_apps.id; + + +CREATE OR REPLACE VIEW tenants_capabilities + (tenant_id, formation_id, id, app_id, name, description, type, custom_type, version_value, + version_deprecated, version_deprecated_since, version_for_removal, ord_id, local_tenant_id, + short_description, system_instance_aware, tags, related_entity_types, links, release_status, labels, + package_id, visibility, ready, created_at, updated_at, deleted_at, error, resource_hash, + documentation_labels, correlation_ids, last_update) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + c.id, + c.app_id, + c.name, + c.description, + c.type, + c.custom_type, + c.version_value, + c.version_deprecated, + c.version_deprecated_since, + c.version_for_removal, + c.ord_id, + c.local_tenant_id, + c.short_description, + c.system_instance_aware, + c.tags, + c.related_entity_types, + c.links, + c.release_status, + c.labels, + c.package_id, + c.visibility, + c.ready, + c.created_at, + c.updated_at, + c.deleted_at, + c.error, + c.resource_hash, + c.documentation_labels, + c.correlation_ids, + c.last_update +FROM capabilities c + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON c.app_id = t_apps.id; + +CREATE OR REPLACE VIEW tenants_entity_types + (tenant_id, formation_id, id, ord_id, app_id, local_tenant_id, level, title, short_description, description, + system_instance_aware, changelog_entries, package_id, visibility, links, part_of_products, last_update, + policy_level, custom_policy_level, release_status, sunset_date, successors, extensible_supported, + extensible_description, tags, labels, documentation_labels, resource_hash, version_value, + version_deprecated, version_deprecated_since, version_for_removal, deprecation_date) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + et.id, + et.ord_id, + et.app_id, + et.local_tenant_id, + et.level, + et.title, + et.short_description, + et.description, + et.system_instance_aware, + et.changelog_entries, + et.package_id, + et.visibility, + et.links, + et.part_of_products, + et.last_update, + et.policy_level, + et.custom_policy_level, + et.release_status, + et.sunset_date, + et.successors, + actions.supported AS extensible_supported, + actions.description AS extensible_description, + et.tags, + et.labels, + et.documentation_labels, + et.resource_hash, + et.version_value, + et.version_deprecated, + et.version_deprecated_since, + et.version_for_removal, + et.deprecation_date +FROM entity_types et + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON et.app_id = t_apps.id, + jsonb_to_record(et.extensible) actions(supported text, description text); + +CREATE OR REPLACE VIEW tenants_events + (tenant_id, formation_id, id, app_id, name, description, group_name, version_value, version_deprecated, + version_deprecated_since, version_for_removal, ord_id, local_tenant_id, short_description, + system_instance_aware, policy_level, custom_policy_level, changelog_entries, links, tags, countries, + release_status, sunset_date, labels, package_id, visibility, disabled, part_of_products, line_of_business, + industry, ready, created_at, updated_at, deleted_at, error, implementation_standard, + custom_implementation_standard, custom_implementation_standard_description, extensible_supported, + extensible_description, successors, resource_hash, correlation_ids, last_update, deprecation_date, + event_resource_links) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + events.id, + events.app_id, + events.name, + events.description, + events.group_name, + events.version_value, + events.version_deprecated, + events.version_deprecated_since, + events.version_for_removal, + events.ord_id, + events.local_tenant_id, + events.short_description, + events.system_instance_aware, + events.policy_level, + events.custom_policy_level, + events.changelog_entries, + events.links, + events.tags, + events.countries, + events.release_status, + events.sunset_date, + events.labels, + events.package_id, + events.visibility, + events.disabled, + events.part_of_products, + events.line_of_business, + events.industry, + events.ready, + events.created_at, + events.updated_at, + events.deleted_at, + events.error, + events.implementation_standard, + events.custom_implementation_standard, + events.custom_implementation_standard_description, + actions.supported AS extensible_supported, + actions.description AS extensible_description, + events.successors, + events.resource_hash, + events.correlation_ids, + events.last_update, + events.deprecation_date, + events.event_resource_links +FROM event_api_definitions events + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON events.app_id = t_apps.id, + jsonb_to_record(events.extensible) actions(supported text, description text); + +CREATE OR REPLACE VIEW tenants_integration_dependencies + (tenant_id, formation_id, id, app_id, ord_id, local_tenant_id, correlation_ids, title, short_description, + description, package_id, last_update, visibility, release_status, sunset_date, successors, mandatory, + related_integration_dependencies, links, tags, labels, documentation_labels, resource_hash, version_value, + version_deprecated, version_deprecated_since, version_for_removal, ready, created_at, updated_at, + deleted_at, error) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + i.id, + i.app_id, + i.ord_id, + i.local_tenant_id, + i.correlation_ids, + i.title, + i.short_description, + i.description, + i.package_id, + i.last_update, + i.visibility, + i.release_status, + i.sunset_date, + i.successors, + i.mandatory, + i.related_integration_dependencies, + i.links, + i.tags, + i.labels, + i.documentation_labels, + i.resource_hash, + i.version_value, + i.version_deprecated, + i.version_deprecated_since, + i.version_for_removal, + i.ready, + i.created_at, + i.updated_at, + i.deleted_at, + i.error +FROM integration_dependencies i + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON i.app_id = t_apps.id; + +CREATE OR REPLACE VIEW tenants_packages + (tenant_id, formation_id, id, ord_id, title, short_description, description, version, package_links, links, + licence_type, tags, countries, labels, policy_level, app_id, custom_policy_level, vendor, part_of_products, + line_of_business, industry, resource_hash, support_info) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + p.id, + p.ord_id, + p.title, + p.short_description, + p.description, + p.version, + p.package_links, + p.links, + p.licence_type, + p.tags, + p.countries, + p.labels, + p.policy_level, + p.app_id, + p.custom_policy_level, + p.vendor, + p.part_of_products, + p.line_of_business, + p.industry, + p.resource_hash, + p.support_info +FROM packages p + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON p.app_id = t_apps.id; + +CREATE OR REPLACE VIEW tenants_products + (tenant_id, formation_id, ord_id, app_id, title, short_description, vendor, parent, labels, tags, + correlation_ids, id, documentation_labels, description) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + p.ord_id, + p.app_id, + p.title, + p.short_description, + p.vendor, + p.parent, + p.labels, + p.tags, + p.correlation_ids, + p.id, + p.documentation_labels, + p.description +FROM products p + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON p.app_id = t_apps.id OR p.app_id IS NULL; + +CREATE OR REPLACE VIEW tenants_tombstones (tenant_id, formation_id, ord_id, app_id, removal_date, id, description) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + t.ord_id, + t.app_id, + t.removal_date, + t.id, + t.description +FROM tombstones t + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON t.app_id = t_apps.id; + +CREATE OR REPLACE VIEW tenants_vendors + (tenant_id, formation_id, ord_id, app_id, title, labels, tags, partners, id, documentation_labels) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + v.ord_id, + v.app_id, + v.title, + v.labels, + v.tags, + v.partners, + v.id, + v.documentation_labels +FROM vendors v + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON v.app_id = t_apps.id OR v.app_id IS NULL; + +CREATE OR REPLACE VIEW tenants_specifications + (tenant_id, id, api_def_id, event_def_id, spec_data, api_spec_format, api_spec_type, event_spec_format, + event_spec_type, capability_def_id, capability_spec_type, capability_spec_format, custom_type, created_at) +AS +SELECT DISTINCT t_api_event_capability_def.tenant_id, + spec.id, + spec.api_def_id, + spec.event_def_id, + spec.spec_data, + spec.api_spec_format, + spec.api_spec_type, + spec.event_spec_format, + spec.event_spec_type, + spec.capability_def_id, + spec.capability_spec_type, + spec.capability_spec_format, + spec.custom_type, + spec.created_at +FROM specifications spec + JOIN (SELECT a.id, + a.tenant_id + FROM tenants_apis a + UNION ALL + SELECT e.id, + e.tenant_id + FROM tenants_events e + UNION ALL + SELECT c.id, + c.tenant_id + FROM tenants_capabilities c) t_api_event_capability_def + ON spec.api_def_id = t_api_event_capability_def.id OR spec.event_def_id = t_api_event_capability_def.id OR + spec.capability_def_id = t_api_event_capability_def.id; + +CREATE OR REPLACE VIEW tenants_entity_type_mappings + (tenant_id, id, api_definition_id, event_definition_id, api_model_selectors, entity_type_targets) +AS +SELECT DISTINCT t_api_event_def.tenant_id, + etm.id, + etm.api_definition_id, + etm.event_definition_id, + etm.api_model_selectors, + etm.entity_type_targets +FROM entity_type_mappings etm + JOIN (SELECT a.id, + a.tenant_id + FROM tenants_apis a + UNION ALL + SELECT e.id, + e.tenant_id + FROM tenants_events e) t_api_event_def + ON etm.api_definition_id = t_api_event_def.id OR etm.event_definition_id = t_api_event_def.id; + +CREATE OR REPLACE VIEW tenants_specifications + (tenant_id, id, api_def_id, event_def_id, spec_data, api_spec_format, api_spec_type, event_spec_format, + event_spec_type, capability_def_id, capability_spec_type, capability_spec_format, custom_type, created_at) +AS +SELECT DISTINCT t_api_event_capability_def.tenant_id, + spec.id, + spec.api_def_id, + spec.event_def_id, + spec.spec_data, + spec.api_spec_format, + spec.api_spec_type, + spec.event_spec_format, + spec.event_spec_type, + spec.capability_def_id, + spec.capability_spec_type, + spec.capability_spec_format, + spec.custom_type, + spec.created_at +FROM specifications spec + JOIN (SELECT a.id, + a.tenant_id + FROM tenants_apis a + UNION ALL + SELECT e.id, + e.tenant_id + FROM tenants_events e + UNION ALL + SELECT c.id, + c.tenant_id + FROM tenants_capabilities c) t_api_event_capability_def + ON spec.api_def_id = t_api_event_capability_def.id OR spec.event_def_id = t_api_event_capability_def.id OR + spec.capability_def_id = t_api_event_capability_def.id; + +CREATE OR REPLACE VIEW entity_type_mappings_tenants(id, tenant_id, owner) +AS +SELECT DISTINCT etm.id, + t_api_event_def.tenant_id, + t_api_event_def.owner +FROM entity_type_mappings etm + JOIN (SELECT a.id, + a.tenant_id, + ta.owner + FROM tenants_apis a + JOIN tenant_applications ta ON ta.id = a.app_id + UNION ALL + SELECT e.id, + e.tenant_id, + ta.owner + FROM tenants_events e + JOIN tenant_applications ta ON ta.id = e.app_id) t_api_event_def + ON etm.api_definition_id = t_api_event_def.id OR etm.event_definition_id = t_api_event_def.id; + +COMMIT; diff --git a/components/schema-migrator/migrations/director/20231121105202_ord-fix-views-app-tmpl-subscription-flow.up.sql b/components/schema-migrator/migrations/director/20231121105202_ord-fix-views-app-tmpl-subscription-flow.up.sql new file mode 100644 index 0000000000..458817596e --- /dev/null +++ b/components/schema-migrator/migrations/director/20231121105202_ord-fix-views-app-tmpl-subscription-flow.up.sql @@ -0,0 +1,699 @@ +BEGIN; + +-- drop views +DROP VIEW IF EXISTS tenants_specifications; -- this one won't be changed but it uses tenants_apis/events and it has to be dropped so the other two can be as well +DROP VIEW IF EXISTS tenants_entity_type_mappings; -- this one won't be changed but it uses tenants_apis/events and it has to be dropped so the other two can be as well +DROP VIEW IF EXISTS entity_type_mappings_tenants; -- this one won't be changed but it uses tenants_apis/events and it has to be dropped so the other two can be as well +DROP VIEW IF EXISTS tenants_apps; +DROP VIEW IF EXISTS tenants_apis; +DROP VIEW IF EXISTS tenants_aspects; +DROP VIEW IF EXISTS tenants_bundles; +DROP VIEW IF EXISTS tenants_capabilities; +DROP VIEW IF EXISTS tenants_entity_types; +DROP VIEW IF EXISTS tenants_events; +DROP VIEW IF EXISTS tenants_integration_dependencies; +DROP VIEW IF EXISTS tenants_packages; +DROP VIEW IF EXISTS tenants_products; +DROP VIEW IF EXISTS tenants_tombstones; +DROP VIEW IF EXISTS tenants_vendors; + +-- create formations index on tenant_id column +CREATE INDEX formations_tenant_id ON formations(tenant_id); + +-- create new view which will serve the following purpose: + +-- we need to calculate the formation_id of the formation/s based on the scenario label of all Applications that are in formation/s +-- this is needed for the App Template subscription flow in ORD Service +-- up to this change, the formation_id was missing in that flow because it is extracted from a JOIN between labels and ASAs but for the AppTemplates there are no ASAs involved and we have to calculate the formation_ids directly from the scenario label of the Apps that are in formation/s + +CREATE VIEW apps_formations_id(app_id, formation_id) AS +SELECT l.app_id AS app_id, f.id AS formation_id +FROM labels l + JOIN formations f ON f.tenant_id = l.tenant_id +WHERE app_id is not null and l.key = 'scenarios' and l.value ?| array[f.name]; + +-- recreate views, enhancing them by using information from the new view above + +-- in addition, a new default tenant value is introduced 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb' that will be used in the views +-- it was needed because we changed the filtering approaches of the ORD Service: up to this point, it could have filtered based on tenant_id or tenant_id + formation_id +-- however, this is no longer suitable for the future scenarios, so now we allow the ORD Service to filter based on tenant_id or formation_id + +-- since we no longer need tenant_id when we want to filter by formation_id, the apps_subaccounts usage in the views was removed in favour of the new apps_formations_id + +CREATE OR REPLACE VIEW tenants_apps + (tenant_id, formation_id, id, name, description, status_condition, status_timestamp, healthcheck_url, + integration_system_id, provider_name, base_url, labels, tags, ready, created_at, updated_at, deleted_at, + error, app_template_id, correlation_ids, system_number, application_namespace, local_tenant_id, + tenant_business_type_id, product_type) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + apps.id, + apps.name, + apps.description, + apps.status_condition, + apps.status_timestamp, + apps.healthcheck_url, + apps.integration_system_id, + apps.provider_name, + apps.base_url, + apps.labels, + apps.tags, + apps.ready, + apps.created_at, + apps.updated_at, + apps.deleted_at, + apps.error, + apps.app_template_id, + apps.correlation_ids, + apps.system_number, + COALESCE(apps.application_namespace, tmpl.application_namespace) AS application_namespace, + apps.local_tenant_id, + apps.tenant_business_type_id, + tmpl.name AS product_type +FROM applications apps + LEFT JOIN app_templates tmpl ON apps.app_template_id = tmpl.id + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT af.app_id, + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'::uuid AS tenant_id, + af.formation_id + FROM apps_formations_id af + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON apps.id = t_apps.id; + + +CREATE OR REPLACE VIEW tenants_apis + (tenant_id, formation_id, id, app_id, name, description, group_name, default_auth, version_value, + version_deprecated, version_deprecated_since, version_for_removal, ord_id, local_tenant_id, + short_description, system_instance_aware, policy_level, custom_policy_level, api_protocol, tags, + supported_use_cases, countries, links, api_resource_links, release_status, sunset_date, changelog_entries, + labels, package_id, visibility, disabled, part_of_products, line_of_business, industry, ready, created_at, + updated_at, deleted_at, error, implementation_standard, custom_implementation_standard, + custom_implementation_standard_description, target_urls, extensible_supported, extensible_description, + successors, resource_hash, documentation_labels, correlation_ids, direction, last_update, deprecation_date) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + apis.id, + apis.app_id, + apis.name, + apis.description, + apis.group_name, + apis.default_auth, + apis.version_value, + apis.version_deprecated, + apis.version_deprecated_since, + apis.version_for_removal, + apis.ord_id, + apis.local_tenant_id, + apis.short_description, + apis.system_instance_aware, + apis.policy_level, + apis.custom_policy_level, + apis.api_protocol, + apis.tags, + apis.supported_use_cases, + apis.countries, + apis.links, + apis.api_resource_links, + apis.release_status, + apis.sunset_date, + apis.changelog_entries, + apis.labels, + apis.package_id, + apis.visibility, + apis.disabled, + apis.part_of_products, + apis.line_of_business, + apis.industry, + apis.ready, + apis.created_at, + apis.updated_at, + apis.deleted_at, + apis.error, + apis.implementation_standard, + apis.custom_implementation_standard, + apis.custom_implementation_standard_description, + apis.target_urls, + actions.supported AS extensible_supported, + actions.description AS extensible_description, + apis.successors, + apis.resource_hash, + apis.documentation_labels, + apis.correlation_ids, + apis.direction, + apis.last_update, + apis.deprecation_date +FROM api_definitions apis + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT af.app_id, + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'::uuid AS tenant_id, + af.formation_id + FROM apps_formations_id af + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON apis.app_id = t_apps.id, + jsonb_to_record(apis.extensible) actions(supported text, description text); + + +CREATE OR REPLACE VIEW tenants_aspects + (tenant_id, formation_id, id, integration_dependency_id, app_id, title, description, mandatory, + support_multiple_providers, api_resources, event_resources, ready, created_at, updated_at, deleted_at, + error) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + a.id, + a.integration_dependency_id, + a.app_id, + a.title, + a.description, + a.mandatory, + a.support_multiple_providers, + a.api_resources, + a.event_resources, + a.ready, + a.created_at, + a.updated_at, + a.deleted_at, + a.error +FROM aspects a + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT af.app_id, + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'::uuid AS tenant_id, + af.formation_id + FROM apps_formations_id af + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON a.app_id = t_apps.id; + + +CREATE OR REPLACE VIEW tenants_bundles + (tenant_id, formation_id, id, app_id, name, description, version, instance_auth_request_json_schema, + default_instance_auth, ord_id, local_tenant_id, short_description, links, labels, tags, + credential_exchange_strategies, ready, created_at, updated_at, deleted_at, error, correlation_ids, + resource_hash) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + b.id, + b.app_id, + b.name, + b.description, + b.version, + b.instance_auth_request_json_schema, + b.default_instance_auth, + b.ord_id, + b.local_tenant_id, + b.short_description, + b.links, + b.labels, + b.tags, + b.credential_exchange_strategies, + b.ready, + b.created_at, + b.updated_at, + b.deleted_at, + b.error, + b.correlation_ids, + b.resource_hash +FROM bundles b + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT af.app_id, + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'::uuid AS tenant_id, + af.formation_id + FROM apps_formations_id af + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON b.app_id = t_apps.id; + + +CREATE OR REPLACE VIEW tenants_capabilities + (tenant_id, formation_id, id, app_id, name, description, type, custom_type, version_value, + version_deprecated, version_deprecated_since, version_for_removal, ord_id, local_tenant_id, + short_description, system_instance_aware, tags, related_entity_types, links, release_status, labels, + package_id, visibility, ready, created_at, updated_at, deleted_at, error, resource_hash, + documentation_labels, correlation_ids, last_update) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + c.id, + c.app_id, + c.name, + c.description, + c.type, + c.custom_type, + c.version_value, + c.version_deprecated, + c.version_deprecated_since, + c.version_for_removal, + c.ord_id, + c.local_tenant_id, + c.short_description, + c.system_instance_aware, + c.tags, + c.related_entity_types, + c.links, + c.release_status, + c.labels, + c.package_id, + c.visibility, + c.ready, + c.created_at, + c.updated_at, + c.deleted_at, + c.error, + c.resource_hash, + c.documentation_labels, + c.correlation_ids, + c.last_update +FROM capabilities c + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT af.app_id, + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'::uuid AS tenant_id, + af.formation_id + FROM apps_formations_id af + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON c.app_id = t_apps.id; + +CREATE OR REPLACE VIEW tenants_entity_types + (tenant_id, formation_id, id, ord_id, app_id, local_tenant_id, level, title, short_description, description, + system_instance_aware, changelog_entries, package_id, visibility, links, part_of_products, last_update, + policy_level, custom_policy_level, release_status, sunset_date, successors, extensible_supported, + extensible_description, tags, labels, documentation_labels, resource_hash, version_value, + version_deprecated, version_deprecated_since, version_for_removal, deprecation_date) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + et.id, + et.ord_id, + et.app_id, + et.local_tenant_id, + et.level, + et.title, + et.short_description, + et.description, + et.system_instance_aware, + et.changelog_entries, + et.package_id, + et.visibility, + et.links, + et.part_of_products, + et.last_update, + et.policy_level, + et.custom_policy_level, + et.release_status, + et.sunset_date, + et.successors, + actions.supported AS extensible_supported, + actions.description AS extensible_description, + et.tags, + et.labels, + et.documentation_labels, + et.resource_hash, + et.version_value, + et.version_deprecated, + et.version_deprecated_since, + et.version_for_removal, + et.deprecation_date +FROM entity_types et + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT af.app_id, + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'::uuid AS tenant_id, + af.formation_id + FROM apps_formations_id af + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON et.app_id = t_apps.id, + jsonb_to_record(et.extensible) actions(supported text, description text); + +CREATE OR REPLACE VIEW tenants_events + (tenant_id, formation_id, id, app_id, name, description, group_name, version_value, version_deprecated, + version_deprecated_since, version_for_removal, ord_id, local_tenant_id, short_description, + system_instance_aware, policy_level, custom_policy_level, changelog_entries, links, tags, countries, + release_status, sunset_date, labels, package_id, visibility, disabled, part_of_products, line_of_business, + industry, ready, created_at, updated_at, deleted_at, error, implementation_standard, + custom_implementation_standard, custom_implementation_standard_description, extensible_supported, + extensible_description, successors, resource_hash, correlation_ids, last_update, deprecation_date, + event_resource_links) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + events.id, + events.app_id, + events.name, + events.description, + events.group_name, + events.version_value, + events.version_deprecated, + events.version_deprecated_since, + events.version_for_removal, + events.ord_id, + events.local_tenant_id, + events.short_description, + events.system_instance_aware, + events.policy_level, + events.custom_policy_level, + events.changelog_entries, + events.links, + events.tags, + events.countries, + events.release_status, + events.sunset_date, + events.labels, + events.package_id, + events.visibility, + events.disabled, + events.part_of_products, + events.line_of_business, + events.industry, + events.ready, + events.created_at, + events.updated_at, + events.deleted_at, + events.error, + events.implementation_standard, + events.custom_implementation_standard, + events.custom_implementation_standard_description, + actions.supported AS extensible_supported, + actions.description AS extensible_description, + events.successors, + events.resource_hash, + events.correlation_ids, + events.last_update, + events.deprecation_date, + events.event_resource_links +FROM event_api_definitions events + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON events.app_id = t_apps.id, + jsonb_to_record(events.extensible) actions(supported text, description text); + +CREATE OR REPLACE VIEW tenants_integration_dependencies + (tenant_id, formation_id, id, app_id, ord_id, local_tenant_id, correlation_ids, title, short_description, + description, package_id, last_update, visibility, release_status, sunset_date, successors, mandatory, + related_integration_dependencies, links, tags, labels, documentation_labels, resource_hash, version_value, + version_deprecated, version_deprecated_since, version_for_removal, ready, created_at, updated_at, + deleted_at, error) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + i.id, + i.app_id, + i.ord_id, + i.local_tenant_id, + i.correlation_ids, + i.title, + i.short_description, + i.description, + i.package_id, + i.last_update, + i.visibility, + i.release_status, + i.sunset_date, + i.successors, + i.mandatory, + i.related_integration_dependencies, + i.links, + i.tags, + i.labels, + i.documentation_labels, + i.resource_hash, + i.version_value, + i.version_deprecated, + i.version_deprecated_since, + i.version_for_removal, + i.ready, + i.created_at, + i.updated_at, + i.deleted_at, + i.error +FROM integration_dependencies i + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT af.app_id, + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'::uuid AS tenant_id, + af.formation_id + FROM apps_formations_id af + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON i.app_id = t_apps.id; + +CREATE OR REPLACE VIEW tenants_packages + (tenant_id, formation_id, id, ord_id, title, short_description, description, version, package_links, links, + licence_type, tags, countries, labels, policy_level, app_id, custom_policy_level, vendor, part_of_products, + line_of_business, industry, resource_hash, support_info) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + p.id, + p.ord_id, + p.title, + p.short_description, + p.description, + p.version, + p.package_links, + p.links, + p.licence_type, + p.tags, + p.countries, + p.labels, + p.policy_level, + p.app_id, + p.custom_policy_level, + p.vendor, + p.part_of_products, + p.line_of_business, + p.industry, + p.resource_hash, + p.support_info +FROM packages p + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + apps_subaccounts.formation_id + FROM apps_subaccounts + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON p.app_id = t_apps.id; + +CREATE OR REPLACE VIEW tenants_products + (tenant_id, formation_id, ord_id, app_id, title, short_description, vendor, parent, labels, tags, + correlation_ids, id, documentation_labels, description) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + p.ord_id, + p.app_id, + p.title, + p.short_description, + p.vendor, + p.parent, + p.labels, + p.tags, + p.correlation_ids, + p.id, + p.documentation_labels, + p.description +FROM products p + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT af.app_id, + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'::uuid AS tenant_id, + af.formation_id + FROM apps_formations_id af + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON p.app_id = t_apps.id OR p.app_id IS NULL; + +CREATE OR REPLACE VIEW tenants_tombstones (tenant_id, formation_id, ord_id, app_id, removal_date, id, description) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + t.ord_id, + t.app_id, + t.removal_date, + t.id, + t.description +FROM tombstones t + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT af.app_id, + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'::uuid AS tenant_id, + af.formation_id + FROM apps_formations_id af + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON t.app_id = t_apps.id; + +CREATE OR REPLACE VIEW tenants_vendors + (tenant_id, formation_id, ord_id, app_id, title, labels, tags, partners, id, documentation_labels) +AS +SELECT DISTINCT t_apps.tenant_id, + t_apps.formation_id, + v.ord_id, + v.app_id, + v.title, + v.labels, + v.tags, + v.partners, + v.id, + v.documentation_labels +FROM vendors v + JOIN (SELECT a1.id, + a1.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM tenant_applications a1 + UNION ALL + SELECT af.app_id, + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'::uuid AS tenant_id, + af.formation_id + FROM apps_formations_id af + UNION ALL + SELECT apps_subaccounts.id, + apps_subaccounts.tenant_id, + 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'::uuid AS formation_id + FROM apps_subaccounts) t_apps ON v.app_id = t_apps.id OR v.app_id IS NULL; + +CREATE OR REPLACE VIEW entity_type_mappings_tenants(id, tenant_id, owner) +AS +SELECT DISTINCT etm.id, + t_api_event_def.tenant_id, + t_api_event_def.owner +FROM entity_type_mappings etm + JOIN (SELECT a.id, + a.tenant_id, + ta.owner + FROM tenants_apis a + JOIN tenant_applications ta ON ta.id = a.app_id + UNION ALL + SELECT e.id, + e.tenant_id, + ta.owner + FROM tenants_events e + JOIN tenant_applications ta ON ta.id = e.app_id) t_api_event_def + ON etm.api_definition_id = t_api_event_def.id OR etm.event_definition_id = t_api_event_def.id; + +CREATE OR REPLACE VIEW tenants_entity_type_mappings + (tenant_id, id, api_definition_id, event_definition_id, api_model_selectors, entity_type_targets) +AS +SELECT DISTINCT t_api_event_def.tenant_id, + etm.id, + etm.api_definition_id, + etm.event_definition_id, + etm.api_model_selectors, + etm.entity_type_targets +FROM entity_type_mappings etm + JOIN (SELECT a.id, + a.tenant_id + FROM tenants_apis a + UNION ALL + SELECT e.id, + e.tenant_id + FROM tenants_events e) t_api_event_def + ON etm.api_definition_id = t_api_event_def.id OR etm.event_definition_id = t_api_event_def.id; + +CREATE OR REPLACE VIEW tenants_specifications + (tenant_id, id, api_def_id, event_def_id, spec_data, api_spec_format, api_spec_type, event_spec_format, + event_spec_type, capability_def_id, capability_spec_type, capability_spec_format, custom_type, created_at) +AS +SELECT DISTINCT t_api_event_capability_def.tenant_id, + spec.id, + spec.api_def_id, + spec.event_def_id, + spec.spec_data, + spec.api_spec_format, + spec.api_spec_type, + spec.event_spec_format, + spec.event_spec_type, + spec.capability_def_id, + spec.capability_spec_type, + spec.capability_spec_format, + spec.custom_type, + spec.created_at +FROM specifications spec + JOIN (SELECT a.id, + a.tenant_id + FROM tenants_apis a + UNION ALL + SELECT e.id, + e.tenant_id + FROM tenants_events e + UNION ALL + SELECT c.id, + c.tenant_id + FROM tenants_capabilities c) t_api_event_capability_def + ON spec.api_def_id = t_api_event_capability_def.id OR spec.event_def_id = t_api_event_capability_def.id OR + spec.capability_def_id = t_api_event_capability_def.id; + +COMMIT; diff --git a/tests/ord-aggregator/tests/handler_test.go b/tests/ord-aggregator/tests/handler_test.go index 3c40c3f141..c371ad5818 100644 --- a/tests/ord-aggregator/tests/handler_test.go +++ b/tests/ord-aggregator/tests/handler_test.go @@ -326,6 +326,9 @@ func TestORDAggregator(stdT *testing.T) { httpClientWithoutVisibilityScope := cfgWithoutScopes.Client(ctx) httpClientWithoutVisibilityScope.Timeout = 20 * time.Second + httpClientWithoutVisibilityScopeCapabilities := cfgWithoutScopes.Client(ctx) + httpClientWithoutVisibilityScopeCapabilities.Timeout = 60 * time.Second + // create client to call Director graphql api with internal_visibility:read scope accessTokenWithInternalVisibility := token.GetAccessToken(t, oauthCredentialData, token.IntegrationSystemScopes) oauthGraphQLClientWithInternalVisibility := gql.NewAuthorizedGraphQLClientWithCustomURL(accessTokenWithInternalVisibility, testConfig.DirectorGraphqlOauthURL) @@ -558,7 +561,7 @@ func TestORDAggregator(stdT *testing.T) { t.Log("Successfully verified capability spec") // verify public capabilities via ORD Service - verifyEntitiesWithPublicVisibilityInORD(t, httpClientWithoutVisibilityScope, publicCapabilitiesMap, capabilitiesField, expectedNumberOfPublicCapabilities) + verifyEntitiesWithPublicVisibilityInORD(t, httpClientWithoutVisibilityScopeCapabilities, publicCapabilitiesMap, capabilitiesField, expectedNumberOfPublicCapabilities) // Verify integration dependencies respBody = makeRequestWithHeaders(t, httpClient, testConfig.ORDServiceURL+"/integrationDependencies?$format=json", map[string][]string{tenantHeader: {testConfig.DefaultTestTenant}}) @@ -1187,6 +1190,9 @@ func TestORDAggregator(stdT *testing.T) { httpClientWithoutVisibilityScope := cfgWithoutScopes.Client(ctx) httpClientWithoutVisibilityScope.Timeout = 20 * time.Second + httpClientWithoutVisibilityScopeCapabilities := cfgWithoutScopes.Client(ctx) + httpClientWithoutVisibilityScopeCapabilities.Timeout = 60 * time.Second + // create client to call Director graphql api with internal_visibility:read scope accessTokenWithInternalVisibility := token.GetAccessToken(t, oauthCredentialData, token.IntegrationSystemScopes) oauthGraphQLClientWithInternalVisibility := gql.NewAuthorizedGraphQLClientWithCustomURL(accessTokenWithInternalVisibility, testConfig.DirectorGraphqlOauthURL) @@ -1388,7 +1394,7 @@ func TestORDAggregator(stdT *testing.T) { t.Log("Successfully verified capability spec") // verify public capabilities via ORD Service - verifyEntitiesWithPublicVisibilityInORD(t, httpClientWithoutVisibilityScope, publicCapabilitiesMap, capabilitiesField, numberOfPublicCapabilities) + verifyEntitiesWithPublicVisibilityInORD(t, httpClientWithoutVisibilityScopeCapabilities, publicCapabilitiesMap, capabilitiesField, numberOfPublicCapabilities) // Verify integration dependencies respBody = makeRequestWithHeaders(t, httpClient, testConfig.ORDServiceURL+"/integrationDependencies?$format=json", map[string][]string{tenantHeader: {testConfig.DefaultTestTenant}}) diff --git a/tests/ord-service/tests/subscription_flow_test.go b/tests/ord-service/tests/subscription_flow_test.go index 55ea640855..236229c146 100644 --- a/tests/ord-service/tests/subscription_flow_test.go +++ b/tests/ord-service/tests/subscription_flow_test.go @@ -22,7 +22,7 @@ import ( "crypto/tls" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strings" "testing" @@ -268,7 +268,7 @@ func TestConsumerProviderFlow(stdT *testing.T) { } }() require.NoError(stdT, err) - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) require.NoError(stdT, err) require.Equal(stdT, http.StatusAccepted, resp.StatusCode, fmt.Sprintf("actual status code %d is different from the expected one: %d. Reason: %v", resp.StatusCode, http.StatusAccepted, string(body))) @@ -475,11 +475,6 @@ func TestConsumerProviderFlow(stdT *testing.T) { defer unassignFromFormation(stdT, ctx, consumerApp.ID, "APPLICATION", consumerFormationName, secondaryTenant) stdT.Logf("Successfully assigned application to formation %s", consumerFormationName) - stdT.Logf("Assign tenant %s to formation %s...", subscriptionConsumerSubaccountID, consumerFormationName) - assignToFormation(stdT, ctx, subscriptionConsumerSubaccountID, "TENANT", consumerFormationName, secondaryTenant) - defer unassignFromFormation(stdT, ctx, subscriptionConsumerSubaccountID, "TENANT", consumerFormationName, secondaryTenant) - stdT.Logf("Successfully assigned tenant %s to formation %s", subscriptionConsumerSubaccountID, consumerFormationName) - httpClient := &http.Client{ Timeout: 10 * time.Second, Transport: &http.Transport{ @@ -521,7 +516,7 @@ func TestConsumerProviderFlow(stdT *testing.T) { } }() require.NoError(stdT, err) - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) require.NoError(stdT, err) require.Equal(stdT, http.StatusAccepted, resp.StatusCode, fmt.Sprintf("actual status code %d is different from the expected one: %d. Reason: %v", resp.StatusCode, http.StatusAccepted, string(body))) @@ -787,7 +782,7 @@ func TestConsumerProviderFlow(stdT *testing.T) { } }() require.NoError(stdT, err) - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) require.NoError(stdT, err) require.Equal(stdT, http.StatusAccepted, resp.StatusCode, fmt.Sprintf("actual status code %d is different from the expected one: %d. Reason: %v", resp.StatusCode, http.StatusAccepted, string(body)))