Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 3737010b0 -> 453101c7a
  refs/heads/trunk ef80b5ef3 -> 93f0896ec


AMBARI-13297. change nimbus.monitor.freq.secs=120 in ambari (dlysnichenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/453101c7
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/453101c7
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/453101c7

Branch: refs/heads/branch-2.1
Commit: 453101c7ae03ba077436c084b2038e24313d6e9d
Parents: 3737010
Author: Lisnichenko Dmitro <dlysniche...@hortonworks.com>
Authored: Mon Oct 5 20:48:54 2015 +0300
Committer: Lisnichenko Dmitro <dlysniche...@hortonworks.com>
Committed: Mon Oct 5 20:48:54 2015 +0300

----------------------------------------------------------------------
 .../server/upgrade/SchemaUpgradeHelper.java     |   1 +
 .../server/upgrade/UpgradeCatalog213.java       | 133 +++++++++++++
 .../0.9.1.2.1/configuration/storm-site.xml      |   2 +-
 .../stacks/HDP/2.2/upgrades/upgrade-2.3.xml     |   5 +
 .../server/upgrade/UpgradeCatalog213Test.java   | 189 +++++++++++++++++++
 5 files changed, 329 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/453101c7/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
index 62a18f4..cd57df1 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
@@ -179,6 +179,7 @@ public class SchemaUpgradeHelper {
       catalogBinder.addBinding().to(UpgradeCatalog210.class);
       catalogBinder.addBinding().to(UpgradeCatalog211.class);
       catalogBinder.addBinding().to(UpgradeCatalog212.class);
+      catalogBinder.addBinding().to(UpgradeCatalog213.class);
       catalogBinder.addBinding().to(FinalUpgradeCatalog.class);
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/453101c7/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog213.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog213.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog213.java
new file mode 100644
index 0000000..7caf50e
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog213.java
@@ -0,0 +1,133 @@
+/*
+ * 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.Inject;
+import com.google.inject.Injector;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.orm.dao.DaoUtils;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Upgrade catalog for version 2.1.3.
+ */
+public class UpgradeCatalog213 extends AbstractUpgradeCatalog {
+
+  private static final String STORM_SITE = "storm-site";
+
+  /**
+   * Logger.
+   */
+  private static final Logger LOG = 
LoggerFactory.getLogger(UpgradeCatalog212.class);
+
+  @Inject
+  DaoUtils daoUtils;
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Don't forget to register new UpgradeCatalogs in {@link 
org.apache.ambari.server.upgrade.SchemaUpgradeHelper.UpgradeHelperModule#configure()}
+   *
+   * @param injector Guice injector to track dependencies and uses bindings to 
inject them.
+   */
+  @Inject
+  public UpgradeCatalog213(Injector injector) {
+    super(injector);
+
+    daoUtils = injector.getInstance(DaoUtils.class);
+  }
+
+  // ----- UpgradeCatalog ----------------------------------------------------
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public String getTargetVersion() {
+    return "2.1.3";
+  }
+
+  // ----- AbstractUpgradeCatalog --------------------------------------------
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public String getSourceVersion() {
+    return "2.1.2";
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  protected void executeDDLUpdates() throws AmbariException, SQLException {
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  protected void executePreDMLUpdates() throws AmbariException, SQLException {
+  }
+
+  @Override
+  protected void executeDMLUpdates() throws AmbariException, SQLException {
+    addMissingConfigs();
+  }
+
+  protected void addMissingConfigs() throws AmbariException {
+    updateStormConfigs();
+  }
+
+  protected void updateStormConfigs() throws AmbariException {
+    AmbariManagementController ambariManagementController = 
injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = clusters.getClusters();
+
+      if ((clusterMap != null) && !clusterMap.isEmpty()) {
+        // Iterate through the clusters and perform any configuration updates
+        for (final Cluster cluster : clusterMap.values()) {
+          Config stormSiteProps = cluster.getDesiredConfigByType(STORM_SITE);
+
+          if (stormSiteProps != null) {
+            String value = 
stormSiteProps.getProperties().get("nimbus.monitor.freq.secs");
+            if (value != null && value.equals("10")) {
+              Map<String, String> updates = new HashMap<String, String>();
+              updates.put("nimbus.monitor.freq.secs", "120");
+              updateConfigurationPropertiesForCluster(cluster, STORM_SITE, 
updates, true, false);
+            }
+          }
+        }
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/453101c7/ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/configuration/storm-site.xml
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/configuration/storm-site.xml
 
b/ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/configuration/storm-site.xml
index 5055a67..b7453f9 100644
--- 
a/ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/configuration/storm-site.xml
+++ 
b/ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/configuration/storm-site.xml
@@ -156,7 +156,7 @@
   </property>
   <property>
     <name>nimbus.monitor.freq.secs</name>
-    <value>10</value>
+    <value>120</value>
     <description>
       How often nimbus should wake up to check heartbeats and do 
reassignments. Note
        that if a machine ever goes down Nimbus will immediately wake up and 
take action.

http://git-wip-us.apache.org/repos/asf/ambari/blob/453101c7/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/upgrade-2.3.xml
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/upgrade-2.3.xml 
b/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/upgrade-2.3.xml
index e6d845d..18c7928 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/upgrade-2.3.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/upgrade-2.3.xml
@@ -1236,6 +1236,11 @@
             <function>delete_storm_local_data</function>
           </task>
 
+          <task xsi:type="configure" summary="Updating 
nimbus.monitor.freq.secs">
+            <type>storm-site</type>
+            <set key="nimbus.monitor.freq.secs" value="120" />
+          </task>
+
           <task xsi:type="configure" summary="Converting nimbus.host into 
nimbus.seeds">
             <type>storm-site</type>
             <transfer operation="copy" from-key="nimbus.host" 
to-key="nimbus.seeds" coerce-to="yaml-array"/>

http://git-wip-us.apache.org/repos/asf/ambari/blob/453101c7/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog213Test.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog213Test.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog213Test.java
new file mode 100644
index 0000000..b6e0ccb
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog213Test.java
@@ -0,0 +1,189 @@
+/*
+ * 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 static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+
+import com.google.inject.AbstractModule;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.orm.DBAccessor;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.StackDAO;
+import org.apache.ambari.server.orm.entities.StackEntity;
+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.stack.OsFamily;
+import org.easymock.EasyMockSupport;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.Provider;
+import com.google.inject.persist.PersistService;
+
+/**
+ * {@link org.apache.ambari.server.upgrade.UpgradeCatalog213} unit tests.
+ */
+public class UpgradeCatalog213Test {
+  private Injector injector;
+  private Provider<EntityManager> entityManagerProvider = 
createStrictMock(Provider.class);
+  private EntityManager entityManager = createNiceMock(EntityManager.class);
+  private UpgradeCatalogHelper upgradeCatalogHelper;
+  private StackEntity desiredStackEntity;
+
+  @Before
+  public void init() {
+    reset(entityManagerProvider);
+    expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
+    replay(entityManagerProvider);
+    injector = Guice.createInjector(new InMemoryDefaultTestModule());
+    injector.getInstance(GuiceJpaInitializer.class);
+
+    upgradeCatalogHelper = injector.getInstance(UpgradeCatalogHelper.class);
+    // inject AmbariMetaInfo to ensure that stacks get populated in the DB
+    injector.getInstance(AmbariMetaInfo.class);
+    // load the stack entity
+    StackDAO stackDAO = injector.getInstance(StackDAO.class);
+    desiredStackEntity = stackDAO.find("HDP", "2.2.0");
+  }
+
+  @After
+  public void tearDown() {
+    injector.getInstance(PersistService.class).stop();
+  }
+
+  @Test
+  public void testExecuteDMLUpdates() throws Exception {
+    Method addMissingConfigs = 
UpgradeCatalog213.class.getDeclaredMethod("addMissingConfigs");
+
+    UpgradeCatalog213 upgradeCatalog213 = 
createMockBuilder(UpgradeCatalog213.class)
+        .addMockedMethod(addMissingConfigs)
+        .createMock();
+
+    upgradeCatalog213.addMissingConfigs();
+    expectLastCall().once();
+
+    replay(upgradeCatalog213);
+
+    upgradeCatalog213.executeDMLUpdates();
+
+    verify(upgradeCatalog213);
+  }
+
+  @Test
+  public void testUpdateStormSiteConfigs() throws Exception {
+    EasyMockSupport easyMockSupport = new EasyMockSupport();
+    final AmbariManagementController mockAmbariManagementController = 
easyMockSupport.createNiceMock(AmbariManagementController.class);
+    final ConfigHelper mockConfigHelper = 
easyMockSupport.createMock(ConfigHelper.class);
+
+    final Clusters mockClusters = 
easyMockSupport.createStrictMock(Clusters.class);
+    final Cluster mockClusterExpected = 
easyMockSupport.createNiceMock(Cluster.class);
+    final Map<String, String> propertiesStormSite = new HashMap<String, 
String>() {
+      {
+        put("nimbus.monitor.freq.secs", "10");
+      }
+    };
+
+    final Config mockStormSite = easyMockSupport.createNiceMock(Config.class);
+    
expect(mockStormSite.getProperties()).andReturn(propertiesStormSite).once();
+
+    final Map<String, String> propertiesExpectedHiveSite = new HashMap<String, 
String>() {{
+      put("nimbus.monitor.freq.secs", "210");
+    }};
+
+    final Injector mockInjector = Guice.createInjector(new AbstractModule() {
+      @Override
+      protected void configure() {
+        
bind(AmbariManagementController.class).toInstance(mockAmbariManagementController);
+        bind(ConfigHelper.class).toInstance(mockConfigHelper);
+        bind(Clusters.class).toInstance(mockClusters);
+
+        bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
+        bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
+      }
+    });
+
+    
expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
+    expect(mockClusters.getClusters()).andReturn(new HashMap<String, 
Cluster>() {{
+      put("normal", mockClusterExpected);
+    }}).once();
+
+    
expect(mockClusterExpected.getDesiredConfigByType("storm-site")).andReturn(mockStormSite).atLeastOnce();
+    
expect(mockStormSite.getProperties()).andReturn(propertiesExpectedHiveSite).atLeastOnce();
+
+    easyMockSupport.replayAll();
+    mockInjector.getInstance(UpgradeCatalog213.class).updateStormConfigs();
+    easyMockSupport.verifyAll();
+  }
+
+  /**
+   * @param dbAccessor
+   * @return
+   */
+  private AbstractUpgradeCatalog getUpgradeCatalog(final DBAccessor 
dbAccessor) {
+    Module module = new Module() {
+      @Override
+      public void configure(Binder binder) {
+        binder.bind(DBAccessor.class).toInstance(dbAccessor);
+        binder.bind(EntityManager.class).toInstance(entityManager);
+        binder.bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
+      }
+    };
+
+    Injector injector = Guice.createInjector(module);
+    return injector.getInstance(UpgradeCatalog213.class);
+  }
+
+  @Test
+  public void testGetSourceVersion() {
+    final DBAccessor dbAccessor = createNiceMock(DBAccessor.class);
+    UpgradeCatalog upgradeCatalog = getUpgradeCatalog(dbAccessor);
+    Assert.assertEquals("2.1.2", upgradeCatalog.getSourceVersion());
+  }
+
+  @Test
+  public void testGetTargetVersion() throws Exception {
+    final DBAccessor dbAccessor = createNiceMock(DBAccessor.class);
+    UpgradeCatalog upgradeCatalog = getUpgradeCatalog(dbAccessor);
+
+    Assert.assertEquals("2.1.3", upgradeCatalog.getTargetVersion());
+  }
+}
\ No newline at end of file

Reply via email to