diff --git a/gateway-topology-hadoop-xml/src/main/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceMessages.java b/gateway-topology-hadoop-xml/src/main/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceMessages.java index 63d92dfcbb..063fbad4b2 100644 --- a/gateway-topology-hadoop-xml/src/main/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceMessages.java +++ b/gateway-topology-hadoop-xml/src/main/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceMessages.java @@ -91,4 +91,7 @@ public interface HadoopXmlResourceMessages { @Message(level = MessageLevel.INFO, text = "Deleting file {0}") void deleteFile(String name); + + @Message(level = MessageLevel.WARN, text = "Not deleting provider {0} as it is referenced by on ore more descriptors.") + void notDeletingReferenceProvider(String provider); } diff --git a/gateway-topology-hadoop-xml/src/main/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceParserResult.java b/gateway-topology-hadoop-xml/src/main/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceParserResult.java index 1ab0e18977..96a4dbb578 100644 --- a/gateway-topology-hadoop-xml/src/main/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceParserResult.java +++ b/gateway-topology-hadoop-xml/src/main/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceParserResult.java @@ -17,13 +17,17 @@ package org.apache.knox.gateway.topology.hadoop.xml; import java.util.Collections; +import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import org.apache.knox.gateway.i18n.messages.MessagesFactory; import org.apache.knox.gateway.topology.simple.ProviderConfiguration; import org.apache.knox.gateway.topology.simple.SimpleDescriptor; class HadoopXmlResourceParserResult { + private static final HadoopXmlResourceMessages LOG = MessagesFactory.get(HadoopXmlResourceMessages.class); final Map providers; final Set descriptors; private final Set deletedDescriptors; @@ -38,7 +42,21 @@ class HadoopXmlResourceParserResult { this.providers = providers; this.descriptors = descriptors; this.deletedDescriptors = deletedDescriptors; - this.deletedProviders = deletedProviders; + this.deletedProviders = nonReferencedProviders(deletedProviders, descriptors); + } + + private Set nonReferencedProviders(Set deletedProviders, Set descriptors) { + Set referencedProviders = descriptors.stream() + .map(SimpleDescriptor::getProviderConfig).collect(Collectors.toSet()); + Set result = new HashSet<>(); + for (String provider : deletedProviders) { + if (referencedProviders.contains(provider)) { + LOG.notDeletingReferenceProvider(provider); + } else { + result.add(provider); + } + } + return result; } public Map getProviders() { diff --git a/gateway-topology-hadoop-xml/src/test/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceParserTest.java b/gateway-topology-hadoop-xml/src/test/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceParserTest.java index bca77c815d..f8329f3e76 100644 --- a/gateway-topology-hadoop-xml/src/test/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceParserTest.java +++ b/gateway-topology-hadoop-xml/src/test/java/org/apache/knox/gateway/topology/hadoop/xml/HadoopXmlResourceParserTest.java @@ -248,6 +248,13 @@ public void testDelete() throws Exception { assertEquals(new HashSet<>(Arrays.asList("admin", "knoxsso")), result.getDeletedProviders()); } + @Test + public void testReferencedProviderIsNotDeleted() throws Exception { + String testConfigPath = this.getClass().getClassLoader().getResource("testDelete2.xml").getPath(); + HadoopXmlResourceParserResult result = hadoopXmlResourceParser.parse(testConfigPath); + assertEquals(new HashSet<>(Arrays.asList("unused")), result.getDeletedProviders()); + } + private void validateTopology1Descriptors(SimpleDescriptor descriptor) { assertTrue(descriptor.isReadOnly()); assertEquals("topology1", descriptor.getName()); diff --git a/gateway-topology-hadoop-xml/src/test/resources/testDelete2.xml b/gateway-topology-hadoop-xml/src/test/resources/testDelete2.xml new file mode 100644 index 0000000000..674c304bb2 --- /dev/null +++ b/gateway-topology-hadoop-xml/src/test/resources/testDelete2.xml @@ -0,0 +1,39 @@ + + + + + descriptor_name1 + + discoveryType=ClouderaManager# + discoveryAddress=http://host:123# + discoveryUser=user# + discoveryPasswordAlias=alias# + cluster=Cluster 1# + providerConfigRef=used# + app:knoxauth:param1.name=param1.value# + app:admin-ui# + HIVE:url=http://localhost:456# + HIVE:version=1.0# + HIVE:httpclient.connectionTimeout=5m# + HIVE:httpclient.socketTimeout=100m + + + + providerConfigs:used, unused + remove + + \ No newline at end of file