forked from apache/nifi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-12782 Migrated GCS processors' Proxy properties to ProxyConfigur…
…ationService Extracted proxy service migration code into a common util module because the same logic was already used in AWS module, and it is also reusable in other components for proxy property migration. Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes apache#8400.
- Loading branch information
1 parent
d9bcc8b
commit d370b47
Showing
10 changed files
with
229 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
nifi-nar-bundles/nifi-extension-utils/nifi-migration-utils/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-extension-utils</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>nifi-migration-utils</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-mock</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
69 changes: 69 additions & 0 deletions
69
...s/nifi-migration-utils/src/main/java/org/apache/nifi/migration/ProxyServiceMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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.migration; | ||
|
||
import org.apache.nifi.components.PropertyDescriptor; | ||
|
||
import java.net.Proxy; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public final class ProxyServiceMigration { | ||
|
||
static final String PROXY_SERVICE_CLASSNAME = "org.apache.nifi.proxy.StandardProxyConfigurationService"; | ||
|
||
static final String PROXY_SERVICE_TYPE = "proxy-type"; | ||
static final String PROXY_SERVICE_HOST = "proxy-server-host"; | ||
static final String PROXY_SERVICE_PORT = "proxy-server-port"; | ||
static final String PROXY_SERVICE_USERNAME = "proxy-user-name"; | ||
static final String PROXY_SERVICE_PASSWORD = "proxy-user-password"; | ||
|
||
private ProxyServiceMigration() {} | ||
|
||
/** | ||
* Migrates component level proxy properties to ProxyConfigurationService. | ||
* | ||
* @param config the component's property config to be migrated | ||
* @param proxyServiceProperty the component's property descriptor referencing ProxyConfigurationService | ||
* @param proxyHostProperty the name of the component level Proxy Host property | ||
* @param proxyPortProperty the name of the component level Proxy Port property | ||
* @param proxyUsernameProperty the name of the component level Proxy Username property | ||
* @param proxyPasswordProperty the name of the component level Proxy Password property | ||
*/ | ||
public static void migrateProxyProperties(final PropertyConfiguration config, final PropertyDescriptor proxyServiceProperty, | ||
final String proxyHostProperty, final String proxyPortProperty, | ||
final String proxyUsernameProperty, final String proxyPasswordProperty) { | ||
if (config.isPropertySet(proxyHostProperty)) { | ||
final Map<String, String> proxyProperties = new HashMap<>(); | ||
proxyProperties.put(PROXY_SERVICE_TYPE, Proxy.Type.HTTP.name()); | ||
proxyProperties.put(PROXY_SERVICE_HOST, config.getRawPropertyValue(proxyHostProperty).get()); | ||
|
||
// Map any optional proxy configs | ||
config.getRawPropertyValue(proxyPortProperty).ifPresent(value -> proxyProperties.put(PROXY_SERVICE_PORT, value)); | ||
config.getRawPropertyValue(proxyUsernameProperty).ifPresent(value -> proxyProperties.put(PROXY_SERVICE_USERNAME, value)); | ||
config.getRawPropertyValue(proxyPasswordProperty).ifPresent(value -> proxyProperties.put(PROXY_SERVICE_PASSWORD, value)); | ||
|
||
final String serviceId = config.createControllerService(PROXY_SERVICE_CLASSNAME, proxyProperties); | ||
config.setProperty(proxyServiceProperty, serviceId); | ||
} | ||
|
||
config.removeProperty(proxyHostProperty); | ||
config.removeProperty(proxyPortProperty); | ||
config.removeProperty(proxyUsernameProperty); | ||
config.removeProperty(proxyPasswordProperty); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...fi-migration-utils/src/test/java/org/apache/nifi/migration/ProxyServiceMigrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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.migration; | ||
|
||
import org.apache.nifi.components.PropertyDescriptor; | ||
import org.apache.nifi.util.MockPropertyConfiguration; | ||
import org.apache.nifi.util.MockPropertyConfiguration.CreatedControllerService; | ||
import org.apache.nifi.util.PropertyMigrationResult; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.net.Proxy; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class ProxyServiceMigrationTest { | ||
|
||
private static final PropertyDescriptor PROXY_SERVICE = new PropertyDescriptor.Builder() | ||
.name("proxy-service") | ||
.build(); | ||
|
||
private static final String OBSOLETE_PROXY_HOST = "proxy-host"; | ||
private static final String OBSOLETE_PROXY_PORT = "proxy-port"; | ||
private static final String OBSOLETE_PROXY_USERNAME = "proxy-username"; | ||
private static final String OBSOLETE_PROXY_PASSWORD = "proxy-password"; | ||
|
||
private static final String PROXY_HOST_VALUE = "localhost"; | ||
private static final String PROXY_PORT_VALUE = "8888"; | ||
private static final String PROXY_USERNAME_VALUE = "user"; | ||
private static final String PROXY_PASSWORD_VALUE = "pass"; | ||
|
||
@Test | ||
void testMigrateProxyProperties() { | ||
final Map<String, String> properties = Map.of( | ||
OBSOLETE_PROXY_HOST, PROXY_HOST_VALUE, | ||
OBSOLETE_PROXY_PORT, PROXY_PORT_VALUE, | ||
OBSOLETE_PROXY_USERNAME, PROXY_USERNAME_VALUE, | ||
OBSOLETE_PROXY_PASSWORD, PROXY_PASSWORD_VALUE | ||
); | ||
final MockPropertyConfiguration config = new MockPropertyConfiguration(properties); | ||
|
||
ProxyServiceMigration.migrateProxyProperties(config, PROXY_SERVICE, OBSOLETE_PROXY_HOST, OBSOLETE_PROXY_PORT, OBSOLETE_PROXY_USERNAME, OBSOLETE_PROXY_PASSWORD); | ||
|
||
assertFalse(config.hasProperty(OBSOLETE_PROXY_HOST)); | ||
assertFalse(config.hasProperty(OBSOLETE_PROXY_PORT)); | ||
assertFalse(config.hasProperty(OBSOLETE_PROXY_USERNAME)); | ||
assertFalse(config.hasProperty(OBSOLETE_PROXY_PASSWORD)); | ||
|
||
assertTrue(config.isPropertySet(PROXY_SERVICE)); | ||
|
||
PropertyMigrationResult result = config.toPropertyMigrationResult(); | ||
assertEquals(1, result.getCreatedControllerServices().size()); | ||
|
||
final CreatedControllerService createdService = result.getCreatedControllerServices().iterator().next(); | ||
|
||
assertEquals(config.getRawPropertyValue(PROXY_SERVICE).get(), createdService.id()); | ||
assertEquals(ProxyServiceMigration.PROXY_SERVICE_CLASSNAME, createdService.implementationClassName()); | ||
|
||
assertEquals(Map.of( | ||
ProxyServiceMigration.PROXY_SERVICE_TYPE, Proxy.Type.HTTP.name(), | ||
ProxyServiceMigration.PROXY_SERVICE_HOST, PROXY_HOST_VALUE, | ||
ProxyServiceMigration.PROXY_SERVICE_PORT, PROXY_PORT_VALUE, | ||
ProxyServiceMigration.PROXY_SERVICE_USERNAME, PROXY_USERNAME_VALUE, | ||
ProxyServiceMigration.PROXY_SERVICE_PASSWORD, PROXY_PASSWORD_VALUE | ||
), | ||
createdService.serviceProperties()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.