You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2016/06/14 09:10:41 UTC
[4/6] ambari git commit: AMBARI-17112. Fixed implementation of
on-ambari-upgrade support. Patch 2: add logic for ambari-upgrade
(dlysnichenko)
http://git-wip-us.apache.org/repos/asf/ambari/blob/3e152bb9/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java
new file mode 100644
index 0000000..345f62a
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java
@@ -0,0 +1,188 @@
+/*
+ * 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.ambari.server.upgrade;
+
+import com.google.inject.Injector;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.ConfigHelper;
+import org.apache.ambari.server.state.PropertyInfo;
+import org.apache.ambari.server.state.PropertyUpgradeBehavior;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceInfo;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.verify;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.anyString;
+
+public class AbstractUpgradeCatalogTest {
+ private static final String CONFIG_TYPE = "hdfs-site.xml";
+ private final String CLUSTER_NAME = "c1";
+ private final String SERVICE_NAME = "HDFS";
+ private AmbariManagementController amc;
+ private ConfigHelper configHelper;
+ private Injector injector;
+ private Cluster cluster;
+ private Clusters clusters;
+ private ServiceInfo serviceInfo;
+ private Config oldConfig;
+ private AbstractUpgradeCatalog upgradeCatalog;
+ private HashMap<String, String> oldProperties;
+
+ @Before
+ public void init() throws AmbariException {
+ injector = createNiceMock(Injector.class);
+ configHelper = createNiceMock(ConfigHelper.class);
+ amc = createNiceMock(AmbariManagementController.class);
+ cluster = createNiceMock(Cluster.class);
+ clusters = createStrictMock(Clusters.class);
+ serviceInfo = createNiceMock(ServiceInfo.class);
+ oldConfig = createNiceMock(Config.class);
+
+ expect(injector.getInstance(ConfigHelper.class)).andReturn(configHelper).anyTimes();
+ expect(injector.getInstance(AmbariManagementController.class)).andReturn(amc).anyTimes();
+ expect(amc.getClusters()).andReturn(clusters).anyTimes();
+
+ HashMap<String, Cluster> clusterMap = new HashMap<>();
+ clusterMap.put(CLUSTER_NAME, cluster);
+ expect(clusters.getClusters()).andReturn(clusterMap).anyTimes();
+
+ HashSet<PropertyInfo> stackProperties = new HashSet<>();
+ expect(configHelper.getStackProperties(cluster)).andReturn(stackProperties).anyTimes();
+
+ HashMap<String, Service> serviceMap = new HashMap<>();
+ serviceMap.put(SERVICE_NAME, null);
+ expect(cluster.getServices()).andReturn(serviceMap).anyTimes();
+
+ HashSet<PropertyInfo> serviceProperties = new HashSet<>();
+ serviceProperties.add(createProperty(CONFIG_TYPE, "prop1", true, false, false));
+ serviceProperties.add(createProperty(CONFIG_TYPE, "prop2", false, true, false));
+ serviceProperties.add(createProperty(CONFIG_TYPE, "prop3", false, false, true));
+ serviceProperties.add(createProperty(CONFIG_TYPE, "prop4", true, false, false));
+
+ expect(configHelper.getServiceProperties(cluster, SERVICE_NAME)).andReturn(serviceProperties).anyTimes();
+
+ expect(configHelper.getPropertyValueFromStackDefinitions(cluster, "hdfs-site", "prop1")).andReturn("v1").anyTimes();
+ expect(configHelper.getPropertyValueFromStackDefinitions(cluster, "hdfs-site", "prop2")).andReturn("v2").anyTimes();
+ expect(configHelper.getPropertyValueFromStackDefinitions(cluster, "hdfs-site", "prop3")).andReturn("v3").anyTimes();
+ expect(configHelper.getPropertyValueFromStackDefinitions(cluster, "hdfs-site", "prop4")).andReturn("v4").anyTimes();
+ expect(configHelper.getPropertyOwnerService(eq(cluster), eq("hdfs-site"), anyString())).andReturn(serviceInfo).anyTimes();
+ expect(serviceInfo.getName()).andReturn(SERVICE_NAME).anyTimes();
+
+ expect(cluster.getDesiredConfigByType("hdfs-site")).andReturn(oldConfig).anyTimes();
+ oldProperties = new HashMap<>();
+ expect(oldConfig.getProperties()).andReturn(oldProperties).anyTimes();
+
+ upgradeCatalog = new AbstractUpgradeCatalog(injector) {
+ @Override
+ protected void executeDDLUpdates() throws AmbariException, SQLException { }
+
+ @Override
+ protected void executePreDMLUpdates() throws AmbariException, SQLException { }
+
+ @Override
+ protected void executeDMLUpdates() throws AmbariException, SQLException { }
+
+ @Override
+ public String getTargetVersion() { return null; }
+ };
+ }
+
+ @Test
+ public void shouldAddConfigurationFromXml() throws AmbariException {
+
+ oldProperties.put("prop1", "v1-old");
+
+ Map<String, Map<String, String>> tags = Collections.<String, Map<String, String>>emptyMap();
+ Map<String, String> mergedProperties = new HashMap<>();
+ mergedProperties.put("prop1", "v1-old");
+ mergedProperties.put("prop4", "v4");
+
+ expect(amc.createConfig(eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null);
+
+ replay(injector, configHelper, amc, cluster, clusters, serviceInfo, oldConfig);
+
+ upgradeCatalog.addNewConfigurationsFromXml();
+
+ verify(configHelper, amc, cluster, clusters, serviceInfo, oldConfig);
+ }
+
+ @Test
+ public void shouldUpdateConfigurationFromXml() throws AmbariException {
+
+ oldProperties.put("prop1", "v1-old");
+ oldProperties.put("prop2", "v2-old");
+ oldProperties.put("prop3", "v3-old");
+
+ Map<String, Map<String, String>> tags = Collections.<String, Map<String, String>>emptyMap();
+ Map<String, String> mergedProperties = new HashMap<>();
+ mergedProperties.put("prop1", "v1-old");
+ mergedProperties.put("prop2", "v2");
+ mergedProperties.put("prop3", "v3-old");
+
+ expect(amc.createConfig(eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null);
+
+ replay(injector, configHelper, amc, cluster, clusters, serviceInfo, oldConfig);
+
+ upgradeCatalog.addNewConfigurationsFromXml();
+
+ verify(configHelper, amc, cluster, clusters, serviceInfo, oldConfig);
+ }
+
+ @Test
+ public void shouldDeleteConfigurationFromXml() throws AmbariException {
+
+ oldProperties.put("prop1", "v1-old");
+ oldProperties.put("prop3", "v3-old");
+
+ Map<String, Map<String, String>> tags = Collections.<String, Map<String, String>>emptyMap();
+ Map<String, String> mergedProperties = new HashMap<>();
+ mergedProperties.put("prop1", "v1-old");
+
+ expect(amc.createConfig(eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null);
+
+ replay(injector, configHelper, amc, cluster, clusters, serviceInfo, oldConfig);
+
+ upgradeCatalog.addNewConfigurationsFromXml();
+
+ verify(configHelper, amc, cluster, clusters, serviceInfo, oldConfig);
+ }
+
+ private static PropertyInfo createProperty(String filename, String name, boolean add, boolean update, boolean delete) {
+ PropertyInfo propertyInfo = new PropertyInfo();
+ propertyInfo.setFilename(filename);
+ propertyInfo.setName(name);
+ propertyInfo.setPropertyAmbariUpgradeBehavior(new PropertyUpgradeBehavior(add, delete, update));
+ return propertyInfo;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/3e152bb9/ambari-server/src/test/resources/bad-stacks/HDP/0.1/services/YARN/configuration/capacity-scheduler.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/bad-stacks/HDP/0.1/services/YARN/configuration/capacity-scheduler.xml b/ambari-server/src/test/resources/bad-stacks/HDP/0.1/services/YARN/configuration/capacity-scheduler.xml
index f938677..4d41766 100644
--- a/ambari-server/src/test/resources/bad-stacks/HDP/0.1/services/YARN/configuration/capacity-scheduler.xml
+++ b/ambari-server/src/test/resources/bad-stacks/HDP/0.1/services/YARN/configuration/capacity-scheduler.xml
@@ -26,15 +26,13 @@
<property>
<name>yarn.scheduler.capacity.maximum-am-resource-percent</name>
<value>0.2</value>
- <deleted>true</deleted>
<description>Maximum percent of resources in the cluster.</description>
<final>false</final>
- <on-ambari-upgrade add="true"/>
+ <on-ambari-upgrade delete="true"/>
</property>
<property require-input="true">
<name>yarn.scheduler.capacity.root.queues</name>
<value>default</value>
- <deleted>false</deleted>
<description>The queues at the this level (root is the root queue).</description>
<on-ambari-upgrade add="true"/>
</property>
http://git-wip-us.apache.org/repos/asf/ambari/blob/3e152bb9/ambari-server/src/test/resources/bad-stacks/HDP/0.1/services/YARN/configuration/yarn-site.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/bad-stacks/HDP/0.1/services/YARN/configuration/yarn-site.xml b/ambari-server/src/test/resources/bad-stacks/HDP/0.1/services/YARN/configuration/yarn-site.xml
index 1efe20c..f515e9c 100644
--- a/ambari-server/src/test/resources/bad-stacks/HDP/0.1/services/YARN/configuration/yarn-site.xml
+++ b/ambari-server/src/test/resources/bad-stacks/HDP/0.1/services/YARN/configuration/yarn-site.xml
@@ -22,15 +22,13 @@
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>localhost:8025</value>
- <deleted>true</deleted>
- <on-ambari-upgrade add="true"/>
+ <on-ambari-upgrade delete="true"/>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>localhost:8030</value>
<description>The address of the scheduler interface.</description>
- <deleted>true</deleted>
- <on-ambari-upgrade add="true"/>
+ <on-ambari-upgrade delete="true"/>
</property>
<property>
<name>yarn.resourcemanager.address</name>
http://git-wip-us.apache.org/repos/asf/ambari/blob/3e152bb9/ambari-server/src/test/resources/stacks/HDP/2.0.6/services/YARN/configuration/yarn-site.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/stacks/HDP/2.0.6/services/YARN/configuration/yarn-site.xml b/ambari-server/src/test/resources/stacks/HDP/2.0.6/services/YARN/configuration/yarn-site.xml
index 0d500e9..d7d5445 100644
--- a/ambari-server/src/test/resources/stacks/HDP/2.0.6/services/YARN/configuration/yarn-site.xml
+++ b/ambari-server/src/test/resources/stacks/HDP/2.0.6/services/YARN/configuration/yarn-site.xml
@@ -28,15 +28,13 @@
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>localhost:8025</value>
- <deleted>true</deleted>
- <on-ambari-upgrade add="true"/>
+ <on-ambari-upgrade delete="true"/>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>localhost:8030</value>
<description>The address of the scheduler interface.</description>
- <deleted>true</deleted>
- <on-ambari-upgrade add="true"/>
+ <on-ambari-upgrade delete="true"/>
</property>
<property>
<name>yarn.resourcemanager.address</name>
http://git-wip-us.apache.org/repos/asf/ambari/blob/3e152bb9/ambari-server/src/test/resources/stacks/HDP/2.0.7/services/YARN/configuration/yarn-site.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/stacks/HDP/2.0.7/services/YARN/configuration/yarn-site.xml b/ambari-server/src/test/resources/stacks/HDP/2.0.7/services/YARN/configuration/yarn-site.xml
index d68478f..723ed0f 100644
--- a/ambari-server/src/test/resources/stacks/HDP/2.0.7/services/YARN/configuration/yarn-site.xml
+++ b/ambari-server/src/test/resources/stacks/HDP/2.0.7/services/YARN/configuration/yarn-site.xml
@@ -22,15 +22,13 @@
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>localhost:8025</value>
- <deleted>true</deleted>
- <on-ambari-upgrade add="true"/>
+ <on-ambari-upgrade delete="true"/>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>localhost:8030</value>
<description>The address of the scheduler interface.</description>
- <deleted>true</deleted>
- <on-ambari-upgrade add="true"/>
+ <on-ambari-upgrade delete="true"/>
</property>
<property>
<name>yarn.resourcemanager.address</name>
http://git-wip-us.apache.org/repos/asf/ambari/blob/3e152bb9/ambari-server/src/test/resources/stacks/HDP/2.0.8/services/HDFS/configuration/hdfs-site.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/stacks/HDP/2.0.8/services/HDFS/configuration/hdfs-site.xml b/ambari-server/src/test/resources/stacks/HDP/2.0.8/services/HDFS/configuration/hdfs-site.xml
index 6e736ff..dde5fe8 100644
--- a/ambari-server/src/test/resources/stacks/HDP/2.0.8/services/HDFS/configuration/hdfs-site.xml
+++ b/ambari-server/src/test/resources/stacks/HDP/2.0.8/services/HDFS/configuration/hdfs-site.xml
@@ -30,7 +30,6 @@
<value>true</value>
<description>to enable dfs append</description>
<final>true</final>
- <deleted>false</deleted>
<on-ambari-upgrade add="true"/>
</property>
<property>
http://git-wip-us.apache.org/repos/asf/ambari/blob/3e152bb9/ambari-server/src/test/resources/stacks/OTHER/1.0/services/HDFS/configuration/hdfs-site.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/stacks/OTHER/1.0/services/HDFS/configuration/hdfs-site.xml b/ambari-server/src/test/resources/stacks/OTHER/1.0/services/HDFS/configuration/hdfs-site.xml
index 6e736ff..dde5fe8 100644
--- a/ambari-server/src/test/resources/stacks/OTHER/1.0/services/HDFS/configuration/hdfs-site.xml
+++ b/ambari-server/src/test/resources/stacks/OTHER/1.0/services/HDFS/configuration/hdfs-site.xml
@@ -30,7 +30,6 @@
<value>true</value>
<description>to enable dfs append</description>
<final>true</final>
- <deleted>false</deleted>
<on-ambari-upgrade add="true"/>
</property>
<property>
http://git-wip-us.apache.org/repos/asf/ambari/blob/3e152bb9/ambari-server/src/test/resources/stacks_with_cycle/OTHER/1.0/services/HDFS/configuration/hdfs-site.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/stacks_with_cycle/OTHER/1.0/services/HDFS/configuration/hdfs-site.xml b/ambari-server/src/test/resources/stacks_with_cycle/OTHER/1.0/services/HDFS/configuration/hdfs-site.xml
index 6e736ff..dde5fe8 100644
--- a/ambari-server/src/test/resources/stacks_with_cycle/OTHER/1.0/services/HDFS/configuration/hdfs-site.xml
+++ b/ambari-server/src/test/resources/stacks_with_cycle/OTHER/1.0/services/HDFS/configuration/hdfs-site.xml
@@ -30,7 +30,6 @@
<value>true</value>
<description>to enable dfs append</description>
<final>true</final>
- <deleted>false</deleted>
<on-ambari-upgrade add="true"/>
</property>
<property>