You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by mp...@apache.org on 2018/04/16 09:17:21 UTC
[ambari] branch trunk updated: AMBARI-23565. Restore configs does
not work. (mpapirkovskyy)
This is an automated email from the ASF dual-hosted git repository.
mpapirkovskyy pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new 73871e9 AMBARI-23565. Restore configs does not work. (mpapirkovskyy)
73871e9 is described below
commit 73871e999c08831a50da9e1e937a5b85472f8daa
Author: Myroslav Papirkovskyi <mp...@apache.org>
AuthorDate: Thu Apr 12 22:24:30 2018 +0300
AMBARI-23565. Restore configs does not work. (mpapirkovskyy)
---
.../apache/ambari/server/state/ConfigHelper.java | 7 +++
.../ambari/server/state/ConfigHelperTest.java | 73 ++++++++++++++++++++++
2 files changed, 80 insertions(+)
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
index 71d1cc4..f040605 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
@@ -1812,6 +1812,13 @@ public class ConfigHelper {
}
}
+ // check for case configs were removed
+ for (String key : actualValues.keySet()) {
+ if (!desiredValues.containsKey(key)) {
+ keys.add(type + "/" + key);
+ }
+ }
+
return keys;
}
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
index 6c7d648..8729807 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
@@ -22,9 +22,12 @@ import static org.easymock.EasyMock.createStrictMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -55,6 +58,7 @@ import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.security.SecurityHelper;
import org.apache.ambari.server.security.TestAuthenticationFactory;
+import org.apache.ambari.server.security.authorization.AuthorizationException;
import org.apache.ambari.server.stack.StackManagerFactory;
import org.apache.ambari.server.state.configgroup.ConfigGroup;
import org.apache.ambari.server.state.configgroup.ConfigGroupFactory;
@@ -1066,6 +1070,75 @@ public class ConfigHelperTest {
verify(sch);
}
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testFindChangedKeys() throws AmbariException, AuthorizationException, NoSuchMethodException,
+ InvocationTargetException, IllegalAccessException {
+ final String configType = "hdfs-site";
+ final String newPropertyName = "new.property";
+
+ ConfigurationRequest newProperty = new ConfigurationRequest();
+ newProperty.setClusterName(clusterName);
+ newProperty.setType(configType);
+ newProperty.setVersionTag("version3");
+ newProperty.setProperties(new HashMap<String, String>() {{
+ put("hadoop.caller.context.enabled", "false");
+ put(newPropertyName, "true");
+ }});
+ newProperty.setPropertiesAttributes(null);
+
+ final ClusterRequest clusterRequestNewProperty =
+ new ClusterRequest(cluster.getClusterId(), clusterName,
+ cluster.getDesiredStackVersion().getStackVersion(), null);
+
+ clusterRequestNewProperty.setDesiredConfig(Collections.singletonList(newProperty));
+ managementController.updateClusters(new HashSet<ClusterRequest>() {{
+ add(clusterRequestNewProperty);
+ }}, null);
+
+
+ ConfigurationRequest removedNewProperty = new ConfigurationRequest();
+ removedNewProperty.setClusterName(clusterName);
+ removedNewProperty.setType(configType);
+ removedNewProperty.setVersionTag("version4");
+ removedNewProperty.setProperties(new HashMap<String, String>() {{
+ put("hadoop.caller.context.enabled", "false");
+ }});
+ removedNewProperty.setPropertiesAttributes(null);
+
+ final ClusterRequest clusterRequestRemovedNewProperty =
+ new ClusterRequest(cluster.getClusterId(), clusterName,
+ cluster.getDesiredStackVersion().getStackVersion(), null);
+
+ clusterRequestRemovedNewProperty.setDesiredConfig(Collections.singletonList(removedNewProperty));
+ managementController.updateClusters(new HashSet<ClusterRequest>() {{
+ add(clusterRequestRemovedNewProperty);
+ }}, null);
+
+ ConfigHelper configHelper = injector.getInstance(ConfigHelper.class);
+ Method method = ConfigHelper.class.getDeclaredMethod("findChangedKeys",
+ Cluster.class, String.class, Collection.class, Collection.class);
+ method.setAccessible(true);
+
+ // property value was changed
+ Collection<String> value = (Collection<String>) method.invoke(configHelper, cluster, configType,
+ Collections.singletonList("version1"), Collections.singletonList("version2"));
+ assertTrue(value.size() == 1);
+ assertEquals(configType + "/hadoop.caller.context.enabled", value.iterator().next());
+
+ // property was added
+ value = (Collection<String>) method.invoke(configHelper, cluster, configType,
+ Collections.singletonList("version2"), Collections.singletonList("version3"));
+ assertTrue(value.size() == 1);
+ assertEquals(configType + "/" + newPropertyName, value.iterator().next());
+
+ // property was removed
+ value = (Collection<String>) method.invoke(configHelper, cluster, configType,
+ Collections.singletonList("version3"), Collections.singletonList("version4"));
+ assertTrue(value.size() == 1);
+ assertEquals(configType + "/" + newPropertyName, value.iterator().next());
+ }
+
}
public static class RunWithCustomModule {
--
To stop receiving notification emails like this one, please contact
mpapirkovskyy@apache.org.