ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-18524 Kafka widget update needs UpgradeCatalog handling (dsen)
Date Tue, 25 Oct 2016 09:30:10 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 b48cb475d -> 691df258c


AMBARI-18524 Kafka widget update needs UpgradeCatalog handling (dsen)


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

Branch: refs/heads/branch-2.4
Commit: 691df258c07a6bb026c0b1c8795a1b02133b35ee
Parents: b48cb47
Author: Dmytro Sen <dsen@apache.org>
Authored: Mon Oct 24 13:24:00 2016 +0300
Committer: Dmytro Sen <dsen@apache.org>
Committed: Tue Oct 25 12:30:03 2016 +0300

----------------------------------------------------------------------
 .../server/upgrade/AbstractUpgradeCatalog.java  |  98 +++++++++++++++
 .../server/upgrade/SchemaUpgradeHelper.java     |   1 +
 .../server/upgrade/UpgradeCatalog222.java       |   2 +-
 .../server/upgrade/UpgradeCatalog240.java       |  83 -------------
 .../server/upgrade/UpgradeCatalog2402.java      | 120 +++++++++++++++++++
 .../server/upgrade/UpgradeCatalog242.java       |   2 +-
 6 files changed, 221 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/691df258/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
index 8fa720f..482ccc8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
@@ -18,9 +18,11 @@
 package org.apache.ambari.server.upgrade;
 
 import java.io.File;
+import java.io.FileReader;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.StringReader;
+import java.lang.reflect.Type;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -39,6 +41,8 @@ import java.util.TreeMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 import javax.persistence.EntityManager;
 import javax.xml.bind.JAXBException;
 import javax.xml.parsers.DocumentBuilder;
@@ -53,6 +57,7 @@ import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
 import org.apache.ambari.server.orm.dao.ArtifactDAO;
 import org.apache.ambari.server.orm.dao.MetainfoDAO;
+import org.apache.ambari.server.orm.dao.WidgetDAO;
 import org.apache.ambari.server.orm.dao.PermissionDAO;
 import org.apache.ambari.server.orm.dao.ResourceTypeDAO;
 import org.apache.ambari.server.orm.dao.RoleAuthorizationDAO;
@@ -61,6 +66,7 @@ import org.apache.ambari.server.orm.entities.ArtifactEntity;
 import org.apache.ambari.server.orm.entities.MetainfoEntity;
 import org.apache.ambari.server.orm.entities.PermissionEntity;
 import org.apache.ambari.server.orm.entities.RoleAuthorizationEntity;
+import org.apache.ambari.server.orm.entities.WidgetEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
@@ -69,12 +75,15 @@ import org.apache.ambari.server.state.PropertyInfo;
 import org.apache.ambari.server.state.PropertyUpgradeBehavior;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.alert.SourceType;
 import org.apache.ambari.server.state.kerberos.AbstractKerberosDescriptorContainer;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptorFactory;
 import org.apache.ambari.server.state.kerberos.KerberosIdentityDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptor;
+import org.apache.ambari.server.state.stack.WidgetLayout;
+import org.apache.ambari.server.state.stack.WidgetLayoutInfo;
 import org.apache.ambari.server.utils.VersionUtils;
 import org.apache.ambari.server.view.ViewArchiveUtility;
 import org.apache.ambari.server.view.configuration.ViewConfig;
@@ -1091,4 +1100,93 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog
{
     return leafQueues;
   }
 
+  /**
+   *
+   * @param serviceName
+   * @param widgetMap
+   * @param sectionLayoutMap
+   * @throws AmbariException
+   */
+  protected void updateWidgetDefinitionsForService(String serviceName, Map<String, List<String>>
widgetMap,
+                                                   Map<String, String> sectionLayoutMap)
throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    AmbariMetaInfo ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
+    Type widgetLayoutType = new TypeToken<Map<String, List<WidgetLayout>>>(){}.getType();
+    Gson gson = injector.getInstance(Gson.class);
+    WidgetDAO widgetDAO = injector.getInstance(WidgetDAO.class);
+
+    Clusters clusters = ambariManagementController.getClusters();
+
+    Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+    for (final Cluster cluster : clusterMap.values()) {
+      long clusterID = cluster.getClusterId();
+
+      StackId stackId = cluster.getDesiredStackVersion();
+      Map<String, Object> widgetDescriptor = null;
+      StackInfo stackInfo = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion());
+      ServiceInfo serviceInfo = stackInfo.getService(serviceName);
+      if (serviceInfo == null) {
+        LOG.info("Skipping updating widget definition, because " + serviceName +  " service
is not present in cluster " +
+            "cluster_name= " + cluster.getClusterName());
+        continue;
+      }
+
+      for (String section : widgetMap.keySet()) {
+        List<String> widgets = widgetMap.get(section);
+        for (String widgetName : widgets) {
+          List<WidgetEntity> widgetEntities = widgetDAO.findByName(clusterID,
+              widgetName, "ambari", section);
+
+          if (widgetEntities != null && widgetEntities.size() > 0) {
+            WidgetEntity entityToUpdate = null;
+            if (widgetEntities.size() > 1) {
+              LOG.info("Found more that 1 entity with name = "+ widgetName +
+                  " for cluster = " + cluster.getClusterName() + ", skipping update.");
+            } else {
+              entityToUpdate = widgetEntities.iterator().next();
+            }
+            if (entityToUpdate != null) {
+              LOG.info("Updating widget: " + entityToUpdate.getWidgetName());
+              // Get the definition from widgets.json file
+              WidgetLayoutInfo targetWidgetLayoutInfo = null;
+              File widgetDescriptorFile = serviceInfo.getWidgetsDescriptorFile();
+              if (widgetDescriptorFile != null && widgetDescriptorFile.exists())
{
+                try {
+                  widgetDescriptor = gson.fromJson(new FileReader(widgetDescriptorFile),
widgetLayoutType);
+                } catch (Exception ex) {
+                  String msg = "Error loading widgets from file: " + widgetDescriptorFile;
+                  LOG.error(msg, ex);
+                  widgetDescriptor = null;
+                }
+              }
+              if (widgetDescriptor != null) {
+                LOG.debug("Loaded widget descriptor: " + widgetDescriptor);
+                for (Object artifact : widgetDescriptor.values()) {
+                  List<WidgetLayout> widgetLayouts = (List<WidgetLayout>) artifact;
+                  for (WidgetLayout widgetLayout : widgetLayouts) {
+                    if (widgetLayout.getLayoutName().equals(sectionLayoutMap.get(section)))
{
+                      for (WidgetLayoutInfo layoutInfo : widgetLayout.getWidgetLayoutInfoList())
{
+                        if (layoutInfo.getWidgetName().equals(widgetName)) {
+                          targetWidgetLayoutInfo = layoutInfo;
+                        }
+                      }
+                    }
+                  }
+                }
+              }
+              if (targetWidgetLayoutInfo != null) {
+                entityToUpdate.setMetrics(gson.toJson(targetWidgetLayoutInfo.getMetricsInfo()));
+                entityToUpdate.setWidgetValues(gson.toJson(targetWidgetLayoutInfo.getValues()));
+                entityToUpdate.setDescription(targetWidgetLayoutInfo.getDescription());
+                widgetDAO.merge(entityToUpdate);
+              } else {
+                LOG.warn("Unable to find widget layout info for " + widgetName +
+                    " in the stack: " + stackId);
+              }
+            }
+          }
+        }
+      }
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/691df258/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 79c5256..fd43e91 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
@@ -190,6 +190,7 @@ public class SchemaUpgradeHelper {
       catalogBinder.addBinding().to(UpgradeCatalog222.class);
       catalogBinder.addBinding().to(UpgradeCatalog230.class);
       catalogBinder.addBinding().to(UpgradeCatalog240.class);
+      catalogBinder.addBinding().to(UpgradeCatalog2402.class);
       catalogBinder.addBinding().to(UpgradeCatalog242.class);
       catalogBinder.addBinding().to(FinalUpgradeCatalog.class);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/691df258/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog222.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog222.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog222.java
index 7b675f1..ab3b493 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog222.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog222.java
@@ -572,7 +572,7 @@ public class UpgradeCatalog222 extends AbstractUpgradeCatalog {
     return Collections.emptyMap();
   }
 
-  private void updateWidgetDefinitionsForService(String serviceName, Map<String, List<String>>
widgetMap,
+  protected void updateWidgetDefinitionsForService(String serviceName, Map<String, List<String>>
widgetMap,
                                                  Map<String, String> sectionLayoutMap)
throws AmbariException {
     AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
     AmbariMetaInfo ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/691df258/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
index 48de9ec..dab20a0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
@@ -2660,89 +2660,6 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
     updateWidgetDefinitionsForService("HDFS", widgetMap, sectionLayoutMap);
   }
 
-  private void updateWidgetDefinitionsForService(String serviceName, Map<String, List<String>>
widgetMap,
-                                                 Map<String, String> sectionLayoutMap)
throws AmbariException {
-    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
-    AmbariMetaInfo ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
-    Type widgetLayoutType = new TypeToken<Map<String, List<WidgetLayout>>>(){}.getType();
-    Gson gson = injector.getInstance(Gson.class);
-    WidgetDAO widgetDAO = injector.getInstance(WidgetDAO.class);
-
-    Clusters clusters = ambariManagementController.getClusters();
-
-    Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
-    for (final Cluster cluster : clusterMap.values()) {
-      long clusterID = cluster.getClusterId();
-
-      StackId stackId = cluster.getDesiredStackVersion();
-      Map<String, Object> widgetDescriptor = null;
-      StackInfo stackInfo = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion());
-      ServiceInfo serviceInfo = stackInfo.getService(serviceName);
-      if (serviceInfo == null) {
-        LOG.info("Skipping updating widget definition, because " + serviceName +  " service
is not present in cluster " +
-          "cluster_name= " + cluster.getClusterName());
-        continue;
-      }
-
-      for (String section : widgetMap.keySet()) {
-        List<String> widgets = widgetMap.get(section);
-        for (String widgetName : widgets) {
-          List<WidgetEntity> widgetEntities = widgetDAO.findByName(clusterID,
-            widgetName, "ambari", section);
-
-          if (widgetEntities != null && widgetEntities.size() > 0) {
-            WidgetEntity entityToUpdate = null;
-            if (widgetEntities.size() > 1) {
-              LOG.info("Found more that 1 entity with name = "+ widgetName +
-                " for cluster = " + cluster.getClusterName() + ", skipping update.");
-            } else {
-              entityToUpdate = widgetEntities.iterator().next();
-            }
-            if (entityToUpdate != null) {
-              LOG.info("Updating widget: " + entityToUpdate.getWidgetName());
-              // Get the definition from widgets.json file
-              WidgetLayoutInfo targetWidgetLayoutInfo = null;
-              File widgetDescriptorFile = serviceInfo.getWidgetsDescriptorFile();
-              if (widgetDescriptorFile != null && widgetDescriptorFile.exists())
{
-                try {
-                  widgetDescriptor = gson.fromJson(new FileReader(widgetDescriptorFile),
widgetLayoutType);
-                } catch (Exception ex) {
-                  String msg = "Error loading widgets from file: " + widgetDescriptorFile;
-                  LOG.error(msg, ex);
-                  widgetDescriptor = null;
-                }
-              }
-              if (widgetDescriptor != null) {
-                LOG.debug("Loaded widget descriptor: " + widgetDescriptor);
-                for (Object artifact : widgetDescriptor.values()) {
-                  List<WidgetLayout> widgetLayouts = (List<WidgetLayout>) artifact;
-                  for (WidgetLayout widgetLayout : widgetLayouts) {
-                    if (widgetLayout.getLayoutName().equals(sectionLayoutMap.get(section)))
{
-                      for (WidgetLayoutInfo layoutInfo : widgetLayout.getWidgetLayoutInfoList())
{
-                        if (layoutInfo.getWidgetName().equals(widgetName)) {
-                          targetWidgetLayoutInfo = layoutInfo;
-                        }
-                      }
-                    }
-                  }
-                }
-              }
-              if (targetWidgetLayoutInfo != null) {
-                entityToUpdate.setMetrics(gson.toJson(targetWidgetLayoutInfo.getMetricsInfo()));
-                entityToUpdate.setWidgetValues(gson.toJson(targetWidgetLayoutInfo.getValues()));
-                entityToUpdate.setDescription(targetWidgetLayoutInfo.getDescription());
-                widgetDAO.merge(entityToUpdate);
-              } else {
-                LOG.warn("Unable to find widget layout info for " + widgetName +
-                  " in the stack: " + stackId);
-              }
-            }
-          }
-        }
-      }
-    }
-  }
-
   /**
    * @return True if the stack is >=HDP-2.5, false otherwise.
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/691df258/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog2402.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog2402.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog2402.java
new file mode 100644
index 0000000..35c844b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog2402.java
@@ -0,0 +1,120 @@
+/*
+ * 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.configuration.Configuration;
+import org.apache.ambari.server.orm.dao.ClusterDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * Upgrade catalog for version 2.4.0.
+ */
+public class UpgradeCatalog2402 extends AbstractUpgradeCatalog {
+
+  @Inject
+  ClusterDAO clusterDAO;
+
+  @Inject
+  Configuration config;
+
+  /**
+   * Logger.
+   */
+  private static final Logger LOG = LoggerFactory.getLogger(UpgradeCatalog2402.class);
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Don't forget to register new UpgradeCatalogs in {@link SchemaUpgradeHelper.UpgradeHelperModule#configure()}
+   *
+   * @param injector Guice injector to track dependencies and uses bindings to inject them.
+   */
+  @Inject
+  public UpgradeCatalog2402(Injector injector) {
+    super(injector);
+    injector.injectMembers(this);
+  }
+
+  // ----- UpgradeCatalog ----------------------------------------------------
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public String getTargetVersion() {
+    return "2.4.0.2";
+  }
+
+  // ----- AbstractUpgradeCatalog --------------------------------------------
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public String getSourceVersion() {
+    return "2.4.0";
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  protected void executeDDLUpdates() throws AmbariException, SQLException {
+
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  protected void executePreDMLUpdates() throws AmbariException, SQLException {
+
+  }
+
+  @Override
+  protected void executeDMLUpdates() throws AmbariException, SQLException {
+    updateKafkaWidgetDefinition();
+  }
+
+
+  protected void updateKafkaWidgetDefinition() throws AmbariException {
+    LOG.info("Updating Kafka widget definition.");
+
+    Map<String, List<String>> widgetMap = new HashMap<>();
+    Map<String, String> sectionLayoutMap = new HashMap<>();
+
+    List<String> kafkaSummaryWidgets = new ArrayList<>(Arrays.asList("Active
Controller Count"));
+    widgetMap.put("KAFKA_SUMMARY", kafkaSummaryWidgets);
+    sectionLayoutMap.put("KAFKA_SUMMARY", "default_kafka_dashboard");
+
+    updateWidgetDefinitionsForService("KAFKA", widgetMap, sectionLayoutMap);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/691df258/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog242.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog242.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog242.java
index 980b651..31093f1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog242.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog242.java
@@ -102,7 +102,7 @@ public class UpgradeCatalog242 extends AbstractUpgradeCatalog {
    */
   @Override
   public String getSourceVersion() {
-    return "2.4.0";
+    return "2.4.0.2";
   }
 
 


Mime
View raw message