Skip to content

Commit

Permalink
Remove SPI discovery from DB adapter providers
Browse files Browse the repository at this point in the history
  • Loading branch information
takraj committed May 30, 2024
1 parent b1385a6 commit 492ea69
Show file tree
Hide file tree
Showing 27 changed files with 151 additions and 437 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@
package org.apache.nifi.migration;

import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;

import org.apache.nifi.components.PropertyDescriptor;

public final class DatabaseAdapterProviderMigration {

static final String GENERIC_DATABASE_ADAPTER_NAME = "Generic";
static final String MSSQL_DATABASE_ADAPTER_NAME = "MS SQL 2012+";
static final String MSSQL_2012_DATABASE_ADAPTER_NAME = "MS SQL 2012+";
static final String MSSQL_2008_DATABASE_ADAPTER_NAME = "MS SQL 2008";
static final String MYSQL_DATABASE_ADAPTER_NAME = "MySQL";
static final String ORACLE_DATABASE_ADAPTER_NAME = "Oracle";
static final String LEGACY_ORACLE_DATABASE_ADAPTER_NAME = "Oracle";
static final String ORACLE_12_DATABASE_ADAPTER_NAME = "Oracle 12+";
static final String PHOENIX_DATABASE_ADAPTER_NAME = "Phoenix";
static final String POSTGRESQL_DATABASE_ADAPTER_NAME = "PostgreSQL";

static final String GENERIC_DATABASE_ADAPTER_PROVIDER_CLASSNAME = "org.apache.nifi.db.GenericDatabaseAdapterProvider";
static final String MSSQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME = "org.apache.nifi.db.MSSQLDatabaseAdapterProvider";
static final String MSSQL_2012_DATABASE_ADAPTER_PROVIDER_CLASSNAME = "org.apache.nifi.db.MSSQL2012DatabaseAdapterProvider";
static final String MSSQL_2008_DATABASE_ADAPTER_PROVIDER_CLASSNAME = "org.apache.nifi.db.MSSQL2008DatabaseAdapterProvider";
static final String MYSQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME = "org.apache.nifi.db.MySQLDatabaseAdapterProvider";
static final String ORACLE_DATABASE_ADAPTER_PROVIDER_CLASSNAME = "org.apache.nifi.db.OracleDatabaseAdapterProvider";
static final String LEGACY_ORACLE_DATABASE_ADAPTER_PROVIDER_CLASSNAME = "org.apache.nifi.db.LegacyOracleDatabaseAdapterProvider";
static final String ORACLE_12_DATABASE_ADAPTER_PROVIDER_CLASSNAME = "org.apache.nifi.db.Oracle12DatabaseAdapterProvider";
static final String PHOENIX_DATABASE_ADAPTER_PROVIDER_CLASSNAME = "org.apache.nifi.db.PhoenixDatabaseAdapterProvider";
static final String POSTGRESQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME = "org.apache.nifi.db.PostgreSQLDatabaseAdapterProvider";

Expand All @@ -57,21 +58,24 @@ public static void migrateProperties(final PropertyConfiguration config,
}

final String serviceId;
String dbType = config.getRawPropertyValue(dbTypeProperty).get();
switch (dbType) {
switch (config.getRawPropertyValue(dbTypeProperty).orElseThrow()) {
case GENERIC_DATABASE_ADAPTER_NAME:
serviceId = config.createControllerService(GENERIC_DATABASE_ADAPTER_PROVIDER_CLASSNAME, emptyMap());
break;
case MSSQL_DATABASE_ADAPTER_NAME:
case MSSQL_2012_DATABASE_ADAPTER_NAME:
serviceId = config.createControllerService(MSSQL_2012_DATABASE_ADAPTER_PROVIDER_CLASSNAME, emptyMap());
break;
case MSSQL_2008_DATABASE_ADAPTER_NAME:
serviceId = config.createControllerService(MSSQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME, singletonMap(DB_TYPE_PROPERTY, dbType));
serviceId = config.createControllerService(MSSQL_2008_DATABASE_ADAPTER_PROVIDER_CLASSNAME, emptyMap());
break;
case MYSQL_DATABASE_ADAPTER_NAME:
serviceId = config.createControllerService(MYSQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME, emptyMap());
break;
case ORACLE_DATABASE_ADAPTER_NAME:
case LEGACY_ORACLE_DATABASE_ADAPTER_NAME:
serviceId = config.createControllerService(LEGACY_ORACLE_DATABASE_ADAPTER_PROVIDER_CLASSNAME, emptyMap());
break;
case ORACLE_12_DATABASE_ADAPTER_NAME:
serviceId = config.createControllerService(ORACLE_DATABASE_ADAPTER_PROVIDER_CLASSNAME, singletonMap(DB_TYPE_PROPERTY, dbType));
serviceId = config.createControllerService(ORACLE_12_DATABASE_ADAPTER_PROVIDER_CLASSNAME, emptyMap());
break;
case PHOENIX_DATABASE_ADAPTER_NAME:
serviceId = config.createControllerService(PHOENIX_DATABASE_ADAPTER_PROVIDER_CLASSNAME, emptyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package org.apache.nifi.migration;

import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.apache.nifi.migration.DatabaseAdapterProviderMigration.GENERIC_DATABASE_ADAPTER_PROVIDER_CLASSNAME;
import static org.apache.nifi.migration.DatabaseAdapterProviderMigration.MSSQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME;
import static org.apache.nifi.migration.DatabaseAdapterProviderMigration.LEGACY_ORACLE_DATABASE_ADAPTER_PROVIDER_CLASSNAME;
import static org.apache.nifi.migration.DatabaseAdapterProviderMigration.MSSQL_2008_DATABASE_ADAPTER_PROVIDER_CLASSNAME;
import static org.apache.nifi.migration.DatabaseAdapterProviderMigration.MSSQL_2012_DATABASE_ADAPTER_PROVIDER_CLASSNAME;
import static org.apache.nifi.migration.DatabaseAdapterProviderMigration.MYSQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME;
import static org.apache.nifi.migration.DatabaseAdapterProviderMigration.ORACLE_DATABASE_ADAPTER_PROVIDER_CLASSNAME;
import static org.apache.nifi.migration.DatabaseAdapterProviderMigration.ORACLE_12_DATABASE_ADAPTER_PROVIDER_CLASSNAME;
import static org.apache.nifi.migration.DatabaseAdapterProviderMigration.PHOENIX_DATABASE_ADAPTER_PROVIDER_CLASSNAME;
import static org.apache.nifi.migration.DatabaseAdapterProviderMigration.POSTGRESQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -48,7 +49,7 @@ class DatabaseAdapterProviderMigrationTest {

@ParameterizedTest
@MethodSource("provideArgs")
void testMigrateDatabaseTypeProperty(String serviceClassname, String dbType, boolean specifyDbType) {
void testMigrateDatabaseTypeProperty(String serviceClassname, String dbType) {
final Map<String, String> properties = Map.of(
DB_TYPE, dbType
);
Expand All @@ -64,26 +65,22 @@ void testMigrateDatabaseTypeProperty(String serviceClassname, String dbType, boo

final CreatedControllerService createdService = result.getCreatedControllerServices().iterator().next();

assertEquals(config.getRawPropertyValue(DATABASE_ADAPTER_PROVIDER).get(), createdService.id());
assertEquals(config.getRawPropertyValue(DATABASE_ADAPTER_PROVIDER).orElseThrow(), createdService.id());
assertEquals(serviceClassname, createdService.implementationClassName());

if (specifyDbType) {
assertEquals(singletonMap(DB_TYPE, dbType), createdService.serviceProperties());
} else {
assertEquals(emptyMap(), createdService.serviceProperties());
}
assertEquals(emptyMap(), createdService.serviceProperties());
}

private static Stream<Arguments> provideArgs() {
return Stream.of(
Arguments.of(GENERIC_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "Generic", false),
Arguments.of(MSSQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "MS SQL 2012+", true),
Arguments.of(MSSQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "MS SQL 2008", true),
Arguments.of(MYSQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "MySQL", false),
Arguments.of(ORACLE_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "Oracle", true),
Arguments.of(ORACLE_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "Oracle 12+", true),
Arguments.of(PHOENIX_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "Phoenix", false),
Arguments.of(POSTGRESQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "PostgreSQL", false)
Arguments.of(GENERIC_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "Generic"),
Arguments.of(MSSQL_2012_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "MS SQL 2012+"),
Arguments.of(MSSQL_2008_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "MS SQL 2008"),
Arguments.of(MYSQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "MySQL"),
Arguments.of(LEGACY_ORACLE_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "Oracle"),
Arguments.of(ORACLE_12_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "Oracle 12+"),
Arguments.of(PHOENIX_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "Phoenix"),
Arguments.of(POSTGRESQL_DATABASE_ADAPTER_PROVIDER_CLASSNAME, "PostgreSQL")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-generic-db-adapter-provider</artifactId>
<artifactId>nifi-db-adapter</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-generic-db-adapter-provider</artifactId>
<artifactId>nifi-db-adapter</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,7 @@
<dependencies>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-generic-db-adapter-provider</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-mssql-db-adapter-provider</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-mysql-db-adapter-provider</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-oracle-db-adapter-provider</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-phoenix-db-adapter-provider</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-postgresql-db-adapter-provider</artifactId>
<artifactId>nifi-db-adapter</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>nifi-postgresql-db-adapter-provider</artifactId>
<artifactId>nifi-db-adapter</artifactId>
<packaging>jar</packaging>

<dependencies>
Expand All @@ -34,6 +34,31 @@
<artifactId>nifi-database-adapter-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-generic-database-adapter</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-mssql-database-adapter</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-mysql-database-adapter</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-oracle-database-adapter</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-phoenix-database-adapter</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-postgresql-database-adapter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.db;

import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.db.impl.OracleDatabaseAdapter;

/**
* Provider implementation for Legacy Oracle SQL dialect.
*/
@Tags({"sql", "database", "syntax", "dialect", "adapter", "provider", "oracle", "legacy"})
@CapabilityDescription("Provides an adapter for Legacy Oracle SQL dialect.")
public class LegacyOracleDatabaseAdapterProvider extends AbstractControllerService implements DatabaseAdapterProvider {

@Override
public DatabaseAdapter getAdapter() {
return new OracleDatabaseAdapter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.db;

import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.db.impl.MSSQL2008DatabaseAdapter;

/**
* Provider implementation for Microsoft SQL 2008 dialect.
*/
@Tags({"sql", "database", "syntax", "dialect", "adapter", "provider", "mssql", "2008", "legacy"})
@CapabilityDescription("Provides an adapter for Microsoft SQL 2008 dialect.")
public class MSSQL2008DatabaseAdapterProvider extends AbstractControllerService implements DatabaseAdapterProvider {

@Override
public DatabaseAdapter getAdapter() {
return new MSSQL2008DatabaseAdapter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@

import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.db.impl.MSSQLDatabaseAdapter;

/**
* Provider implementation for Microsoft SQL dialect.
* Provider implementation for Microsoft SQL 2012+ dialect.
*/
@Tags({"sql", "database", "syntax", "dialect", "adapter", "provider", "mssql"})
@CapabilityDescription("Provides an adapter for Microsoft SQL dialect.")
public class MSSQLDatabaseAdapterProvider extends AbstractSpiDatabaseAdapterProvider {
@Tags({"sql", "database", "syntax", "dialect", "adapter", "provider", "mssql", "2012"})
@CapabilityDescription("Provides an adapter for Microsoft SQL 2012+ dialect.")
public class MSSQL2012DatabaseAdapterProvider extends AbstractControllerService implements DatabaseAdapterProvider {

@Override
public DatabaseAdapter getAdapter() {
return getSelectedAdapter();
return new MSSQLDatabaseAdapter();
}
}
Loading

0 comments on commit 492ea69

Please sign in to comment.