diff --git a/charts/tractusx-connector-azure-vault/templates/deployment-controlplane.yaml b/charts/tractusx-connector-azure-vault/templates/deployment-controlplane.yaml index 48c58f65a..deaf09d95 100644 --- a/charts/tractusx-connector-azure-vault/templates/deployment-controlplane.yaml +++ b/charts/tractusx-connector-azure-vault/templates/deployment-controlplane.yaml @@ -262,6 +262,16 @@ spec: - name: "EDC_DATASOURCE_EDR_URL" value: {{ tpl .Values.postgresql.jdbcUrl . | quote }} + # see extension https://github.com/eclipse-edc/Connector/tree/main/extensions/policy-monitor/store/sql/policy-monitor-store-sql + - name: "EDC_DATASOURCE_POLICY-MONITOR_NAME" + value: "policy-monitor" + - name: "EDC_DATASOURCE_POLICY-MONITOR_USER" + value: {{ .Values.postgresql.auth.username | required ".Values.postgresql.auth.username is required" | quote }} + - name: "EDC_DATASOURCE_POLICY-MONITOR_PASSWORD" + value: {{ .Values.postgresql.auth.password | required ".Values.postgresql.auth.password is required" | quote }} + - name: "EDC_DATASOURCE_POLICY-MONITOR_URL" + value: {{ tpl .Values.postgresql.jdbcUrl . | quote }} + # see extension https://github.com/eclipse-tractusx/tractusx-edc/tree/main/edc-extensions/bpn-validation/business-partner-store-sql - name: "EDC_DATASOURCE_BPN_NAME" value: "bpn" diff --git a/charts/tractusx-connector/templates/deployment-controlplane.yaml b/charts/tractusx-connector/templates/deployment-controlplane.yaml index d94abb9a4..b47c19b58 100644 --- a/charts/tractusx-connector/templates/deployment-controlplane.yaml +++ b/charts/tractusx-connector/templates/deployment-controlplane.yaml @@ -262,6 +262,16 @@ spec: - name: "EDC_DATASOURCE_EDR_URL" value: {{ tpl .Values.postgresql.jdbcUrl . | quote }} + # see extension https://github.com/eclipse-edc/Connector/tree/main/extensions/policy-monitor/store/sql/policy-monitor-store-sql + - name: "EDC_DATASOURCE_POLICY-MONITOR_NAME" + value: "policy-monitor" + - name: "EDC_DATASOURCE_POLICY-MONITOR_USER" + value: {{ .Values.postgresql.auth.username | required ".Values.postgresql.auth.username is required" | quote }} + - name: "EDC_DATASOURCE_POLICY-MONITOR_PASSWORD" + value: {{ .Values.postgresql.auth.password | required ".Values.postgresql.auth.password is required" | quote }} + - name: "EDC_DATASOURCE_POLICY-MONITOR_URL" + value: {{ tpl .Values.postgresql.jdbcUrl . | quote }} + # see extension https://github.com/eclipse-tractusx/tractusx-edc/tree/main/edc-extensions/bpn-validation/business-partner-store-sql - name: "EDC_DATASOURCE_BPN_NAME" value: "bpn" diff --git a/edc-extensions/postgresql-migration/README.md b/edc-extensions/postgresql-migration/README.md index 7a8b848c6..cf3c41db5 100644 --- a/edc-extensions/postgresql-migration/README.md +++ b/edc-extensions/postgresql-migration/README.md @@ -1,12 +1,14 @@ # Postgresql SQL Migration Extension -This extension applies SQL migrations to +This extension applies SQL migrations to these stores: -* the asset-index -* the contract-definition store -* contract-negotiation store -* policy store -* transfer-process store +* asset-index +* contract-definition +* contract-negotiation +* edr +* policy +* policy-monitor +* transfer-process ## Configuration @@ -17,5 +19,6 @@ This extension applies SQL migrations to | org.eclipse.tractusx.edc.postgresql.migration.contractnegotiation.enabled | Enable migration for contract negotiation tables | | true | | org.eclipse.tractusx.edc.postgresql.migration.edr.enabled | Enable migration for edr tables | | true | | org.eclipse.tractusx.edc.postgresql.migration.policy.enabled | Enable migration for policy tables | | true | +| org.eclipse.tractusx.edc.postgresql.migration.policy-monitor.enabled | Enable migration for policy monitor tables | | true | | org.eclipse.tractusx.edc.postgresql.migration.transferprocess.enabled | Enable migration for transfer process tables | | true | | org.eclipse.tractusx.edc.postgresql.migration.schema | The DB schema to be used during migration | | "public" | diff --git a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/AbstractPostgresqlMigrationExtension.java b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/AbstractPostgresqlMigrationExtension.java index e069ca128..ff88d9a9f 100644 --- a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/AbstractPostgresqlMigrationExtension.java +++ b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/AbstractPostgresqlMigrationExtension.java @@ -20,73 +20,79 @@ package org.eclipse.tractusx.edc.postgresql.migration; +import org.eclipse.edc.runtime.metamodel.annotation.Setting; import org.eclipse.edc.spi.persistence.EdcPersistenceException; import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.eclipse.edc.spi.system.configuration.Config; import org.eclipse.edc.sql.datasource.ConnectionFactoryDataSource; import org.flywaydb.core.Flyway; import org.flywaydb.core.api.MigrationVersion; -import org.flywaydb.core.api.output.MigrateResult; import java.util.Objects; import java.util.Properties; abstract class AbstractPostgresqlMigrationExtension implements ServiceExtension { + private static final String EDC_DATASOURCE_PREFIX = "edc.datasource"; private static final String MIGRATION_LOCATION_BASE = String.format("classpath:%s", AbstractPostgresqlMigrationExtension.class.getPackageName().replace(".", "/")); - protected abstract String getDataSourceNameConfigurationKey(); + private static final String DEFAULT_MIGRATION_ENABLED_TEMPLATE = "true"; + @Setting(value = "Enable/disables subsystem schema migration", defaultValue = DEFAULT_MIGRATION_ENABLED_TEMPLATE, type = "boolean") + private static final String MIGRATION_ENABLED_TEMPLATE = "org.eclipse.tractusx.edc.postgresql.migration.%s.enabled"; + + private static final String DEFAULT_MIGRATION_SCHEMA = "public"; + @Setting(value = "Schema used for the migration", defaultValue = DEFAULT_MIGRATION_SCHEMA) + private static final String MIGRATION_SCHEMA = "org.eclipse.tractusx.edc.postgresql.migration.schema"; + + @Override + public String name() { + return "Postgresql schema migration for subsystem " + getSubsystemName(); + } protected abstract String getSubsystemName(); @Override public void initialize(final ServiceExtensionContext context) { - final String subSystemName = Objects.requireNonNull(getSubsystemName()); + var config = context.getConfig(); + + var subSystemName = Objects.requireNonNull(getSubsystemName()); + var enabled = config.getBoolean(MIGRATION_ENABLED_TEMPLATE.formatted(subSystemName), Boolean.valueOf(DEFAULT_MIGRATION_ENABLED_TEMPLATE)); - final String dataSourceName = - context.getConfig().getString(getDataSourceNameConfigurationKey(), null); - if (dataSourceName == null) { + if (!enabled) { return; } - boolean enabled = context.getConfig() - .getBoolean(String.format("org.eclipse.tractusx.edc.postgresql.migration.%s.enabled", subSystemName), true); - String schema = context.getConfig() - .getString("org.eclipse.tractusx.edc.postgresql.migration.schema", "public"); + var configGroup = "%s.%s".formatted(EDC_DATASOURCE_PREFIX, subSystemName); + var datasourceConfig = config.getConfig(configGroup); - if (!enabled) { + var dataSourceName = datasourceConfig.getString("name", null); + if (dataSourceName == null) { + context.getMonitor().warning("No 'name' setting in group %s found, no schema migrations will run for subsystem %s" + .formatted(configGroup, subSystemName)); return; } - Config datasourceConfiguration = context.getConfig(String.join(".", EDC_DATASOURCE_PREFIX, dataSourceName)); - - final String jdbcUrl = Objects.requireNonNull(datasourceConfiguration.getString("url")); - final Properties jdbcProperties = new Properties(); - jdbcProperties.putAll(datasourceConfiguration.getRelativeEntries()); - - final DriverManagerConnectionFactory driverManagerConnectionFactory = - new DriverManagerConnectionFactory(jdbcUrl, jdbcProperties); - final ConnectionFactoryDataSource dataSource = - new ConnectionFactoryDataSource(driverManagerConnectionFactory); + var jdbcUrl = datasourceConfig.getString("url"); + var jdbcProperties = new Properties(); + jdbcProperties.putAll(datasourceConfig.getRelativeEntries()); - final String schemaHistoryTableName = getSchemaHistoryTableName(subSystemName); - final String migrationsLocation = getMigrationsLocation(); + var driverManagerConnectionFactory = new DriverManagerConnectionFactory(jdbcUrl, jdbcProperties); + var dataSource = new ConnectionFactoryDataSource(driverManagerConnectionFactory); - final Flyway flyway = + var flyway = Flyway.configure() .baselineVersion(MigrationVersion.fromVersion("0.0.0")) .failOnMissingLocations(true) .dataSource(dataSource) - .table(schemaHistoryTableName) - .locations(migrationsLocation) - .defaultSchema(schema) + .table("flyway_schema_history_%s".formatted(subSystemName)) + .locations("%s/%s".formatted(MIGRATION_LOCATION_BASE, subSystemName)) + .defaultSchema(config.getString(MIGRATION_SCHEMA, DEFAULT_MIGRATION_SCHEMA)) .load(); flyway.baseline(); - final MigrateResult migrateResult = flyway.migrate(); + var migrateResult = flyway.migrate(); if (!migrateResult.success) { throw new EdcPersistenceException( @@ -96,11 +102,4 @@ public void initialize(final ServiceExtensionContext context) { } } - private String getMigrationsLocation() { - return String.join("/", MIGRATION_LOCATION_BASE, getSubsystemName()); - } - - private String getSchemaHistoryTableName(final String subSystemName) { - return String.format("flyway_schema_history_%s", subSystemName); - } } diff --git a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/AssetPostgresqlMigrationExtension.java b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/AssetPostgresqlMigrationExtension.java index ab3d6489a..cf1814a58 100644 --- a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/AssetPostgresqlMigrationExtension.java +++ b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/AssetPostgresqlMigrationExtension.java @@ -20,15 +20,9 @@ package org.eclipse.tractusx.edc.postgresql.migration; -import org.eclipse.edc.connector.store.sql.assetindex.ConfigurationKeys; - public class AssetPostgresqlMigrationExtension extends AbstractPostgresqlMigrationExtension { private static final String NAME_SUBSYSTEM = "asset"; - protected String getDataSourceNameConfigurationKey() { - return ConfigurationKeys.DATASOURCE_SETTING_NAME; - } - protected String getSubsystemName() { return NAME_SUBSYSTEM; } diff --git a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/BusinessGroupPostgresMigrationExtension.java b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/BusinessGroupPostgresMigrationExtension.java index 91125a930..01f5f6810 100644 --- a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/BusinessGroupPostgresMigrationExtension.java +++ b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/BusinessGroupPostgresMigrationExtension.java @@ -14,16 +14,8 @@ package org.eclipse.tractusx.edc.postgresql.migration; -import org.eclipse.edc.connector.store.sql.assetindex.ConfigurationKeys; - public class BusinessGroupPostgresMigrationExtension extends AbstractPostgresqlMigrationExtension { - private static final String NAME = "businessgroup"; - - - @Override - protected String getDataSourceNameConfigurationKey() { - return ConfigurationKeys.DATASOURCE_SETTING_NAME; - } + private static final String NAME = "bpn"; @Override protected String getSubsystemName() { diff --git a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/ContractDefinitionPostgresqlMigrationExtension.java b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/ContractDefinitionPostgresqlMigrationExtension.java index 168814580..fe68a9c7f 100644 --- a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/ContractDefinitionPostgresqlMigrationExtension.java +++ b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/ContractDefinitionPostgresqlMigrationExtension.java @@ -23,12 +23,6 @@ public class ContractDefinitionPostgresqlMigrationExtension extends AbstractPostgresqlMigrationExtension { private static final String NAME_SUBSYSTEM = "contractdefinition"; - private static final String DATASOURCE_SETTING_NAME = "edc.datasource.contractdefinition.name"; - - protected String getDataSourceNameConfigurationKey() { - return DATASOURCE_SETTING_NAME; - } - protected String getSubsystemName() { return NAME_SUBSYSTEM; } diff --git a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/ContractNegotiationPostgresqlMigrationExtension.java b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/ContractNegotiationPostgresqlMigrationExtension.java index 760883b54..0ab3f38dd 100644 --- a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/ContractNegotiationPostgresqlMigrationExtension.java +++ b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/ContractNegotiationPostgresqlMigrationExtension.java @@ -23,12 +23,6 @@ public class ContractNegotiationPostgresqlMigrationExtension extends AbstractPostgresqlMigrationExtension { private static final String NAME_SUBSYSTEM = "contractnegotiation"; - private static final String DATASOURCE_SETTING_NAME = "edc.datasource.contractnegotiation.name"; - - protected String getDataSourceNameConfigurationKey() { - return DATASOURCE_SETTING_NAME; - } - protected String getSubsystemName() { return NAME_SUBSYSTEM; } diff --git a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/DriverManagerConnectionFactory.java b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/DriverManagerConnectionFactory.java index 9a273cccc..f4667de28 100644 --- a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/DriverManagerConnectionFactory.java +++ b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/DriverManagerConnectionFactory.java @@ -28,6 +28,13 @@ import java.util.Objects; import java.util.Properties; +/** + * From the EDC version after 0.4.1 this connection factory will be provided as injectable service, so this duplicate + * can be removed on the next version update. + * + * @deprecated will be removed on the next version + */ +@Deprecated(since = "0.6.0") class DriverManagerConnectionFactory implements ConnectionFactory { private final String jdbcUrl; private final Properties properties; diff --git a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/EdrPostgresqlMigrationExtension.java b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/EdrPostgresqlMigrationExtension.java index 2ebb12bb1..00e77c0d4 100644 --- a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/EdrPostgresqlMigrationExtension.java +++ b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/EdrPostgresqlMigrationExtension.java @@ -17,12 +17,6 @@ public class EdrPostgresqlMigrationExtension extends AbstractPostgresqlMigrationExtension { private static final String NAME_SUBSYSTEM = "edr"; - private static final String DATASOURCE_SETTING_NAME = "edc.datasource.edr.name"; - - protected String getDataSourceNameConfigurationKey() { - return DATASOURCE_SETTING_NAME; - } - protected String getSubsystemName() { return NAME_SUBSYSTEM; } diff --git a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/PolicyMonitorPostgresqlMigrationExtension.java b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/PolicyMonitorPostgresqlMigrationExtension.java new file mode 100644 index 000000000..ba6b71e4e --- /dev/null +++ b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/PolicyMonitorPostgresqlMigrationExtension.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.tractusx.edc.postgresql.migration; + +public class PolicyMonitorPostgresqlMigrationExtension extends AbstractPostgresqlMigrationExtension { + private static final String NAME_SUBSYSTEM = "policy-monitor"; + + protected String getSubsystemName() { + return NAME_SUBSYSTEM; + } +} diff --git a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/PolicyPostgresqlMigrationExtension.java b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/PolicyPostgresqlMigrationExtension.java index 02c7a5314..4921e75ee 100644 --- a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/PolicyPostgresqlMigrationExtension.java +++ b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/PolicyPostgresqlMigrationExtension.java @@ -23,12 +23,6 @@ public class PolicyPostgresqlMigrationExtension extends AbstractPostgresqlMigrationExtension { private static final String NAME_SUBSYSTEM = "policy"; - private static final String DATASOURCE_SETTING_NAME = "edc.datasource.policy.name"; - - protected String getDataSourceNameConfigurationKey() { - return DATASOURCE_SETTING_NAME; - } - protected String getSubsystemName() { return NAME_SUBSYSTEM; } diff --git a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/TransferProcessPostgresqlMigrationExtension.java b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/TransferProcessPostgresqlMigrationExtension.java index f9d41b896..6ff1b12c4 100644 --- a/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/TransferProcessPostgresqlMigrationExtension.java +++ b/edc-extensions/postgresql-migration/src/main/java/org/eclipse/tractusx/edc/postgresql/migration/TransferProcessPostgresqlMigrationExtension.java @@ -23,12 +23,6 @@ public class TransferProcessPostgresqlMigrationExtension extends AbstractPostgresqlMigrationExtension { private static final String NAME_SUBSYSTEM = "transferprocess"; - private static final String DATASOURCE_SETTING_NAME = "edc.datasource.transferprocess.name"; - - protected String getDataSourceNameConfigurationKey() { - return DATASOURCE_SETTING_NAME; - } - protected String getSubsystemName() { return NAME_SUBSYSTEM; } diff --git a/edc-extensions/postgresql-migration/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension b/edc-extensions/postgresql-migration/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension index 9acab3b4d..aaa4c53b0 100644 --- a/edc-extensions/postgresql-migration/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension +++ b/edc-extensions/postgresql-migration/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension @@ -21,6 +21,7 @@ org.eclipse.tractusx.edc.postgresql.migration.AssetPostgresqlMigrationExtension org.eclipse.tractusx.edc.postgresql.migration.ContractDefinitionPostgresqlMigrationExtension org.eclipse.tractusx.edc.postgresql.migration.ContractNegotiationPostgresqlMigrationExtension org.eclipse.tractusx.edc.postgresql.migration.PolicyPostgresqlMigrationExtension +org.eclipse.tractusx.edc.postgresql.migration.PolicyMonitorPostgresqlMigrationExtension org.eclipse.tractusx.edc.postgresql.migration.TransferProcessPostgresqlMigrationExtension org.eclipse.tractusx.edc.postgresql.migration.EdrPostgresqlMigrationExtension org.eclipse.tractusx.edc.postgresql.migration.BusinessGroupPostgresMigrationExtension diff --git a/edc-extensions/postgresql-migration/src/main/resources/org/eclipse/tractusx/edc/postgresql/migration/businessgroup/V0_0_1__Init_BusinessGroup_Schema.sql b/edc-extensions/postgresql-migration/src/main/resources/org/eclipse/tractusx/edc/postgresql/migration/bpn/V0_0_1__Init_BusinessGroup_Schema.sql similarity index 100% rename from edc-extensions/postgresql-migration/src/main/resources/org/eclipse/tractusx/edc/postgresql/migration/businessgroup/V0_0_1__Init_BusinessGroup_Schema.sql rename to edc-extensions/postgresql-migration/src/main/resources/org/eclipse/tractusx/edc/postgresql/migration/bpn/V0_0_1__Init_BusinessGroup_Schema.sql diff --git a/edc-extensions/postgresql-migration/src/main/resources/org/eclipse/tractusx/edc/postgresql/migration/policy-monitor/V0_0_1__Init_PolicyMonitor_Database_Schema.sql b/edc-extensions/postgresql-migration/src/main/resources/org/eclipse/tractusx/edc/postgresql/migration/policy-monitor/V0_0_1__Init_PolicyMonitor_Database_Schema.sql new file mode 100644 index 000000000..2e0fe0458 --- /dev/null +++ b/edc-extensions/postgresql-migration/src/main/resources/org/eclipse/tractusx/edc/postgresql/migration/policy-monitor/V0_0_1__Init_PolicyMonitor_Database_Schema.sql @@ -0,0 +1,46 @@ +-- +-- Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +-- +-- This program and the accompanying materials are made available under the +-- terms of the Apache License, Version 2.0 which is available at +-- https://www.apache.org/licenses/LICENSE-2.0 +-- +-- SPDX-License-Identifier: Apache-2.0 +-- +-- Contributors: +-- Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation +-- + +-- Statements are designed for and tested with Postgres only! + + +CREATE TABLE IF NOT EXISTS edc_lease +( + leased_by VARCHAR NOT NULL, + leased_at BIGINT, + lease_duration INTEGER NOT NULL, + lease_id VARCHAR NOT NULL + CONSTRAINT lease_pk + PRIMARY KEY +); + +COMMENT ON COLUMN edc_lease.leased_at IS 'posix timestamp of lease'; +COMMENT ON COLUMN edc_lease.lease_duration IS 'duration of lease in milliseconds'; + +CREATE TABLE IF NOT EXISTS edc_policy_monitor +( + entry_id VARCHAR NOT NULL PRIMARY KEY, + state INTEGER NOT NULL , + created_at BIGINT NOT NULL , + updated_at BIGINT NOT NULL , + state_count INTEGER DEFAULT 0 NOT NULL, + state_time_stamp BIGINT, + trace_context JSON, + error_detail VARCHAR, + lease_id VARCHAR + CONSTRAINT policy_monitor_lease_lease_id_fk + REFERENCES edc_lease + ON DELETE SET NULL, + properties JSON, + contract_id VARCHAR +); diff --git a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/PgParticipantRuntime.java b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/PgParticipantRuntime.java index 8cd68ed4c..d427e5c78 100644 --- a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/PgParticipantRuntime.java +++ b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/PgParticipantRuntime.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import static java.lang.String.format; import static org.eclipse.tractusx.edc.lifecycle.TestRuntimeConfiguration.DB_SCHEMA_NAME; @@ -80,34 +81,14 @@ public Map postgresqlConfiguration(String name) { var jdbcUrl = jdbcUrl(name); return new HashMap<>() { { - put("edc.datasource.asset.name", "asset"); - put("edc.datasource.asset.url", jdbcUrl); - put("edc.datasource.asset.user", USER); - put("edc.datasource.asset.password", PASSWORD); - put("edc.datasource.contractdefinition.name", "contractdefinition"); - put("edc.datasource.contractdefinition.url", jdbcUrl); - put("edc.datasource.contractdefinition.user", USER); - put("edc.datasource.contractdefinition.password", PASSWORD); - put("edc.datasource.contractnegotiation.name", "contractnegotiation"); - put("edc.datasource.contractnegotiation.url", jdbcUrl); - put("edc.datasource.contractnegotiation.user", USER); - put("edc.datasource.contractnegotiation.password", PASSWORD); - put("edc.datasource.policy.name", "policy"); - put("edc.datasource.policy.url", jdbcUrl); - put("edc.datasource.policy.user", USER); - put("edc.datasource.policy.password", PASSWORD); - put("edc.datasource.transferprocess.name", "transferprocess"); - put("edc.datasource.transferprocess.url", jdbcUrl); - put("edc.datasource.transferprocess.user", USER); - put("edc.datasource.transferprocess.password", PASSWORD); - put("edc.datasource.edr.name", "edr"); - put("edc.datasource.edr.url", jdbcUrl); - put("edc.datasource.edr.user", USER); - put("edc.datasource.edr.password", PASSWORD); - put("edc.datasource.bpn.name", "bpn"); - put("edc.datasource.bpn.url", jdbcUrl); - put("edc.datasource.bpn.user", USER); - put("edc.datasource.bpn.password", PASSWORD); + Stream.of("asset", "contractdefinition", "contractnegotiation", "policy", "transferprocess", "edr", "bpn", "policy-monitor") + .forEach(context -> { + var group = "edc.datasource." + context; + put(group + ".name", context); + put(group + ".url", jdbcUrl); + put(group + ".user", USER); + put(group + ".password", PASSWORD); + }); // use non-default schema name to test usage of non-default schema put("org.eclipse.tractusx.edc.postgresql.migration.schema", DB_SCHEMA_NAME); }