summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiddharth Wagle <swagle@hortonworks.com>2015-03-27 15:09:09 -0700
committerSiddharth Wagle <swagle@hortonworks.com>2015-03-27 16:49:49 -0700
commita982836df6fad9a8d648c6bcc5b1852b2be4d7de (patch)
tree6525118a2c23bd42d555354fa5aedf1d2e022261
parent592609bb077e157f094da7c968ca629dc5095ae5 (diff)
AMBARI-10259. Expose the widget artifact on stack version and stack service resource. (swagle)
-rw-r--r--ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java10
-rw-r--r--ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProvider.java77
-rw-r--r--ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceDirectory.java20
-rw-r--r--ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceModule.java4
-rw-r--r--ambari-server/src/main/java/org/apache/ambari/server/stack/StackDirectory.java18
-rw-r--r--ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java5
-rw-r--r--ambari-server/src/main/java/org/apache/ambari/server/state/ServiceInfo.java14
-rw-r--r--ambari-server/src/main/java/org/apache/ambari/server/state/StackInfo.java11
-rw-r--r--ambari-server/src/main/java/org/apache/ambari/server/state/stack/WidgetLayout.java69
-rw-r--r--ambari-server/src/main/java/org/apache/ambari/server/state/stack/WidgetLayoutInfo.java115
-rw-r--r--ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/metrics.json70
-rw-r--r--ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/widgets.json192
-rw-r--r--ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProviderTest.java44
-rw-r--r--ambari-server/src/test/resources/stacks/OTHER/2.0/services/HBASE/widgets.json192
14 files changed, 834 insertions, 7 deletions
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
index 895215300b..143022e23f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
@@ -102,6 +102,16 @@ public class AmbariMetaInfo {
public static final String KERBEROS_DESCRIPTOR_FILE_NAME = "kerberos.json";
/**
+ * The filename name for a Widgets descriptor file at either the stack or service level
+ */
+ public static final String WIDGETS_DESCRIPTOR_FILE_NAME = "widgets.json";
+
+ /**
+ * Filename for theme file at service layer
+ */
+ public static final String SERVICE_THEME_FILE_NAME = "theme.json";
+
+ /**
* This string is used in placeholder in places that are common for
* all operating systems or in situations where os type is not important.
*/
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProvider.java
index b7530a09e7..53734aabb0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProvider.java
@@ -18,6 +18,8 @@
package org.apache.ambari.server.controller.internal;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
import com.google.inject.Inject;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.StackAccessException;
@@ -42,9 +44,13 @@ import org.apache.ambari.server.state.kerberos.KerberosDescriptorFactory;
import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptor;
import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptorFactory;
import org.apache.ambari.server.state.stack.MetricDefinition;
+import org.apache.ambari.server.state.stack.WidgetLayout;
+import org.apache.commons.lang.StringUtils;
import java.io.File;
+import java.io.FileReader;
import java.io.IOException;
+import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -144,6 +150,9 @@ public class StackArtifactResourceProvider extends AbstractControllerResourcePro
@Inject
private static KerberosServiceDescriptorFactory kerberosServiceDescriptorFactory;
+ Type widgetLayoutType = new TypeToken<Map<String, List<WidgetLayout>>>(){}.getType();
+ Gson gson = new Gson();
+
/**
* set resource properties, pk and fk's
*/
@@ -185,6 +194,7 @@ public class StackArtifactResourceProvider extends AbstractControllerResourcePro
resources.addAll(getKerberosDescriptors(request, predicate));
resources.addAll(getMetricsDescriptors(request, predicate));
+ resources.addAll(getWidgetsDescriptors(request, predicate));
// add other artifacts types here
if (resources.isEmpty()) {
@@ -342,8 +352,8 @@ public class StackArtifactResourceProvider extends AbstractControllerResourcePro
} catch (IOException e) {
- LOG.error("Unable to process Kerberos Descriptor. Properties: " + properties, e);
- throw new SystemException("An internal exception occurred while attempting to build a Kerberos Descriptor " +
+ LOG.error("Unable to process Metrics Descriptor. Properties: " + properties, e);
+ throw new SystemException("An internal exception occurred while attempting to build a Metrics Descriptor " +
"artifact. See ambari server logs for more information", e);
}
@@ -370,24 +380,24 @@ public class StackArtifactResourceProvider extends AbstractControllerResourcePro
for (Map<String, Object> properties : getPropertyMaps(predicate)) {
String artifactName = (String) properties.get(ARTIFACT_NAME_PROPERTY_ID);
- if (artifactName == null || artifactName.equals(KERBEROS_DESCRIPTOR_NAME)) {
+ if (artifactName == null || artifactName.equals(WIDGETS_DESCRIPTOR_NAME)) {
String stackName = (String) properties.get(STACK_NAME_PROPERTY_ID);
String stackVersion = (String) properties.get(STACK_VERSION_PROPERTY_ID);
String stackService = (String) properties.get(STACK_SERVICE_NAME_PROPERTY_ID);
Map<String, Object> descriptor;
try {
- descriptor = getKerberosDescriptor(stackName, stackVersion, stackService);
+ descriptor = getWidgetsDescriptor(stackName, stackVersion, stackService);
} catch (IOException e) {
- LOG.error("Unable to process Kerberos Descriptor. Properties: " + properties, e);
- throw new SystemException("An internal exception occurred while attempting to build a Kerberos Descriptor " +
+ LOG.error("Unable to process Widgets Descriptor. Properties: " + properties, e);
+ throw new SystemException("An internal exception occurred while attempting to build a Widgets Descriptor " +
"artifact. See ambari server logs for more information", e);
}
if (descriptor != null) {
Resource resource = new ResourceImpl(Resource.Type.StackArtifact);
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
- setResourceProperty(resource, ARTIFACT_NAME_PROPERTY_ID, KERBEROS_DESCRIPTOR_NAME, requestedIds);
+ setResourceProperty(resource, ARTIFACT_NAME_PROPERTY_ID, WIDGETS_DESCRIPTOR_NAME, requestedIds);
setResourceProperty(resource, ARTIFACT_DATA_PROPERTY_ID, descriptor, requestedIds);
setResourceProperty(resource, STACK_NAME_PROPERTY_ID, stackName, requestedIds);
setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, stackVersion, requestedIds);
@@ -401,6 +411,59 @@ public class StackArtifactResourceProvider extends AbstractControllerResourcePro
return resources;
}
+ private Map<String, Object> getWidgetsDescriptor(String stackName,
+ String stackVersion, String serviceName)
+ throws NoSuchParentResourceException, IOException {
+
+ AmbariManagementController controller = getManagementController();
+ StackInfo stackInfo;
+ try {
+ stackInfo = controller.getAmbariMetaInfo().getStack(stackName, stackVersion);
+ } catch (StackAccessException e) {
+ throw new NoSuchParentResourceException(String.format(
+ "Parent stack resource doesn't exist: stackName='%s', stackVersion='%s'", stackName, stackVersion));
+ }
+
+ if (StringUtils.isEmpty(serviceName)) {
+ return getWidgetsDescriptorForCluster(stackInfo);
+ } else {
+ return getWidgetsDescriptorForService(stackInfo, serviceName);
+ }
+ }
+
+ private Map<String, Object> getWidgetsDescriptorForService(StackInfo stackInfo, String serviceName)
+ throws NoSuchParentResourceException, IOException {
+
+ Map<String, Object> widgetDescriptor = null;
+
+ ServiceInfo serviceInfo = stackInfo.getService(serviceName);
+ if (serviceInfo == null) {
+ throw new NoSuchParentResourceException("Service not found. serviceName" + " = " + serviceName);
+ }
+
+ File widgetDescriptorFile = serviceInfo.getWidgetsDescriptorFile();
+ if (widgetDescriptorFile != null && widgetDescriptorFile.exists()) {
+ widgetDescriptor = gson.fromJson(new FileReader(widgetDescriptorFile), widgetLayoutType);
+ }
+
+ return widgetDescriptor;
+ }
+
+ private Map<String, Object> getWidgetsDescriptorForCluster(StackInfo stackInfo)
+ throws NoSuchParentResourceException, IOException {
+
+ Map<String, Object> widgetDescriptor = null;
+
+ String widgetDescriptorFileLocation = stackInfo.getWidgetsDescriptorFileLocation();
+ if (widgetDescriptorFileLocation != null) {
+ File widgetDescriptorFile = new File(widgetDescriptorFileLocation);
+ if (widgetDescriptorFile.exists()) {
+ widgetDescriptor = gson.fromJson(new FileReader(widgetDescriptorFile), widgetLayoutType);
+ }
+ }
+
+ return widgetDescriptor;
+ }
/**
* Get a kerberos descriptor.
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceDirectory.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceDirectory.java
index e7f27ee332..e1fa524265 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceDirectory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceDirectory.java
@@ -52,6 +52,11 @@ public abstract class ServiceDirectory extends StackDefinitionDirectory {
private File kerberosDescriptorFile;
/**
+ * widgets descriptor file
+ */
+ private File widgetsDescriptorFile;
+
+ /**
* package directory path
*/
protected String packageDir;
@@ -109,6 +114,12 @@ public abstract class ServiceDirectory extends StackDefinitionDirectory {
+ File.separator + AmbariMetaInfo.KERBEROS_DESCRIPTOR_FILE_NAME);
kerberosDescriptorFile = kdf.exists() ? kdf : null;
+ File wdf = new File(directory.getAbsolutePath()
+ + File.separator + AmbariMetaInfo.WIDGETS_DESCRIPTOR_FILE_NAME);
+ widgetsDescriptorFile = wdf.exists() ? wdf : null;
+
+ File themeFile = new File(directory.getAbsolutePath() + File.separator + AmbariMetaInfo.SERVICE_THEME_FILE_NAME);
+ this.themeFile = themeFile.exists() ? themeFile : null;
}
/**
@@ -156,6 +167,15 @@ public abstract class ServiceDirectory extends StackDefinitionDirectory {
}
/**
+ * Obtain the Widgets Descriptor file.
+ *
+ * @return Widgets Descriptor file
+ */
+ public File getWidgetsDescriptorFile() {
+ return widgetsDescriptorFile;
+ }
+
+ /**
* Obtain the service metainfo file object representation.
*
* @return
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceModule.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceModule.java
index ef16e881e2..1e4a773c42 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceModule.java
@@ -111,6 +111,7 @@ public class ServiceModule extends BaseModule<ServiceModule, ServiceInfo> implem
serviceInfo.setMetricsFile(serviceDirectory.getMetricsFile());
serviceInfo.setAlertsFile(serviceDirectory.getAlertsFile());
serviceInfo.setKerberosDescriptorFile(serviceDirectory.getKerberosDescriptorFile());
+ serviceInfo.setWidgetsDescriptorFile(serviceDirectory.getWidgetsDescriptorFile());
serviceInfo.setSchemaVersion(AmbariMetaInfo.SCHEMA_VERSION_2);
serviceInfo.setServicePackageFolder(serviceDirectory.getPackageDir());
@@ -177,6 +178,9 @@ public class ServiceModule extends BaseModule<ServiceModule, ServiceInfo> implem
if (serviceInfo.getThemesMap().isEmpty()) {
serviceInfo.setThemesMap(parent.getThemesMap());
}
+ if (serviceInfo.getWidgetsDescriptorFile() == null) {
+ serviceInfo.setWidgetsDescriptorFile(parent.getWidgetsDescriptorFile());
+ }
mergeCustomCommands(parent.getCustomCommands(), serviceInfo.getCustomCommands());
mergeConfigDependencies(parent);
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackDirectory.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackDirectory.java
index d38cee9204..89c10c6bf9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackDirectory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackDirectory.java
@@ -68,6 +68,11 @@ public class StackDirectory extends StackDefinitionDirectory {
private String kerberosDescriptorFilePath;
/**
+ * kerberos descriptor file path
+ */
+ private String widgetsDescriptorFilePath;
+
+ /**
* repository file
*/
private RepositoryXml repoFile;
@@ -196,6 +201,15 @@ public class StackDirectory extends StackDefinitionDirectory {
}
/**
+ * Obtain the path to the (stack-level) widgets descriptor file
+ *
+ * @return the path to the (stack-level) widgets descriptor file
+ */
+ public String getWidgetsDescriptorFilePath() {
+ return widgetsDescriptorFilePath;
+ }
+
+ /**
* Obtain the repository directory path.
*
* @return repository directory path
@@ -277,6 +291,10 @@ public class StackDirectory extends StackDefinitionDirectory {
kerberosDescriptorFilePath = getAbsolutePath() + File.separator + AmbariMetaInfo.KERBEROS_DESCRIPTOR_FILE_NAME;
}
+ if (subDirs.contains(AmbariMetaInfo.WIDGETS_DESCRIPTOR_FILE_NAME)) {
+ widgetsDescriptorFilePath = getAbsolutePath() + File.separator + AmbariMetaInfo.WIDGETS_DESCRIPTOR_FILE_NAME;
+ }
+
parseUpgradePacks(subDirs);
parseServiceDirectories(subDirs);
parseRepoFile(subDirs);
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java
index e0480c86d3..0b27ae5e77 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java
@@ -224,6 +224,10 @@ public class StackModule extends BaseModule<StackModule, StackInfo> implements V
stackInfo.setKerberosDescriptorFileLocation(parentStack.getModuleInfo().getKerberosDescriptorFileLocation());
}
+ if (stackInfo.getWidgetsDescriptorFileLocation() == null) {
+ stackInfo.setWidgetsDescriptorFileLocation(parentStack.getModuleInfo().getWidgetsDescriptorFileLocation());
+ }
+
mergeServicesWithParent(parentStack, allStacks, commonServices);
}
@@ -412,6 +416,7 @@ public class StackModule extends BaseModule<StackModule, StackInfo> implements V
stackInfo.setStackHooksFolder(stackDirectory.getHooksDir());
stackInfo.setRcoFileLocation(stackDirectory.getRcoFilePath());
stackInfo.setKerberosDescriptorFileLocation(stackDirectory.getKerberosDescriptorFilePath());
+ stackInfo.setWidgetsDescriptorFileLocation(stackDirectory.getWidgetsDescriptorFilePath());
stackInfo.setUpgradesFolder(stackDirectory.getUpgradesDir());
stackInfo.setUpgradePacks(stackDirectory.getUpgradePacks());
stackInfo.setRoleCommandOrder(stackDirectory.getRoleCommandOrder());
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceInfo.java
index 67342e3246..6959b83723 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceInfo.java
@@ -116,6 +116,9 @@ public class ServiceInfo implements Validable{
@XmlTransient
private File kerberosDescriptorFile = null;
+
+ @XmlTransient
+ private File widgetsDescriptorFile = null;
@XmlTransient
private boolean valid = true;
@@ -615,6 +618,17 @@ public class ServiceInfo implements Validable{
}
/**
+ * @return the widgets descriptor file, or <code>null</code> if none exists
+ */
+ public File getWidgetsDescriptorFile() {
+ return widgetsDescriptorFile;
+ }
+
+ public void setWidgetsDescriptorFile(File widgetsDescriptorFile) {
+ this.widgetsDescriptorFile = widgetsDescriptorFile;
+ }
+
+ /**
* @return config types this service contains configuration for, but which are primarily related to another service
*/
public Set<String> getExcludedConfigTypes() {
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/StackInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/state/StackInfo.java
index 4b6898ae44..2aa89ccd46 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/StackInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/StackInfo.java
@@ -40,6 +40,7 @@ public class StackInfo implements Comparable<StackInfo>, Validable{
private boolean active;
private String rcoFileLocation;
private String kerberosDescriptorFileLocation;
+ private String widgetsDescriptorFileLocation;
private List<RepositoryInfo> repositories;
private Collection<ServiceInfo> services;
private String parentStackVersion;
@@ -234,6 +235,8 @@ public class StackInfo implements Comparable<StackInfo>, Validable{
// Get the stack-level Kerberos descriptor file path
String stackDescriptorFileFilePath = getKerberosDescriptorFileLocation();
+ String widgetDescriptorFilePath = getWidgetsDescriptorFileLocation();
+
// Collect the services' Kerberos descriptor files
Collection<ServiceInfo> serviceInfos = getServices();
// The collection of service descriptor files. A Set is being used because some Kerberos descriptor
@@ -316,6 +319,14 @@ public class StackInfo implements Comparable<StackInfo>, Validable{
this.kerberosDescriptorFileLocation = kerberosDescriptorFileLocation;
}
+ public String getWidgetsDescriptorFileLocation() {
+ return widgetsDescriptorFileLocation;
+ }
+
+ public void setWidgetsDescriptorFileLocation(String widgetsDescriptorFileLocation) {
+ this.widgetsDescriptorFileLocation = widgetsDescriptorFileLocation;
+ }
+
public String getStackHooksFolder() {
return stackHooksFolder;
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/WidgetLayout.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/WidgetLayout.java
new file mode 100644
index 0000000000..d730adfebf
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/WidgetLayout.java
@@ -0,0 +1,69 @@
+/**
+ * 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.state.stack;
+
+import com.google.gson.annotations.SerializedName;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+import java.util.List;
+import java.util.Map;
+
+public class WidgetLayout {
+ @SerializedName("layout_name")
+ private String layoutName;
+ @SerializedName("section_name")
+ private String sectionName;
+ @SerializedName("widgetLayoutInfo")
+ private List<WidgetLayoutInfo> widgetLayoutInfoList;
+
+ @JsonProperty("layout_name")
+ public String getLayoutName() {
+ return layoutName;
+ }
+
+ public void setLayoutName(String layoutName) {
+ this.layoutName = layoutName;
+ }
+
+ public String getSectionName() {
+ return sectionName;
+ }
+
+ @JsonProperty("section_name")
+ public void setSectionName(String sectionName) {
+ this.sectionName = sectionName;
+ }
+
+ @JsonProperty("widgetLayoutInfo")
+ public List<WidgetLayoutInfo> getWidgetLayoutInfoList() {
+ return widgetLayoutInfoList;
+ }
+
+ public void setWidgetLayoutInfoList(List<WidgetLayoutInfo> widgetLayoutInfoList) {
+ this.widgetLayoutInfoList = widgetLayoutInfoList;
+ }
+
+ @Override
+ public String toString() {
+ return "WidgetLayout{" +
+ "layoutName='" + layoutName + '\'' +
+ ", sectionName='" + sectionName + '\'' +
+ ", widgetLayoutInfoList=" + widgetLayoutInfoList +
+ '}';
+ }
+}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/WidgetLayoutInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/WidgetLayoutInfo.java
new file mode 100644
index 0000000000..d3d317d746
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/WidgetLayoutInfo.java
@@ -0,0 +1,115 @@
+/**
+ * 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.state.stack;
+
+import com.google.gson.annotations.SerializedName;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+import java.util.List;
+import java.util.Map;
+
+public class WidgetLayoutInfo {
+ @SerializedName("widget_name")
+ private String widgetName;
+ @SerializedName("display_name")
+ private String displayName;
+ @SerializedName("description")
+ private String description;
+ @SerializedName("widget_type")
+ private String type;
+ @SerializedName("is_visible")
+ private boolean visibility;
+ @SerializedName("metrics")
+ private List<Map<String, String>> metricsInfo;
+ @SerializedName("values")
+ private List<Map<String, String>> values;
+ @SerializedName("properties")
+ private Map<String, String> properties;
+
+ @JsonProperty("widget_name")
+ public String getWidgetName() {
+ return widgetName;
+ }
+
+ public void setWidgetName(String widgetName) {
+ this.widgetName = widgetName;
+ }
+
+ @JsonProperty("display_name")
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ @JsonProperty("description")
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @JsonProperty("widget_type")
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ @JsonProperty("is_visible")
+ public boolean getVisibility() {
+ return visibility;
+ }
+
+ public void setVisibility(boolean visibility) {
+ this.visibility = visibility;
+ }
+
+ @JsonProperty("metrics")
+ public List<Map<String, String>> getMetricsInfo() {
+ return metricsInfo;
+ }
+
+ public void setMetricsInfo(List<Map<String, String>> metricsInfo) {
+ this.metricsInfo = metricsInfo;
+ }
+
+ @JsonProperty("values")
+ public List<Map<String, String>> getValues() {
+ return values;
+ }
+
+ public void setValues(List<Map<String, String>> values) {
+ this.values = values;
+ }
+
+ @JsonProperty("properties")
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, String> properties) {
+ this.properties = properties;
+ }
+}
diff --git a/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/metrics.json b/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/metrics.json
index 4f99b254d2..1c25729f7c 100644
--- a/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/metrics.json
+++ b/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/metrics.json
@@ -655,6 +655,76 @@
"pointInTime": false,
"temporal": true
},
+ "metrics/hbase/regionserver/Server/Get_num_ops": {
+ "metric": "regionserver.Server.Get_num_ops",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/regionserver/Server/Append_num_ops": {
+ "metric": "regionserver.Server.Append_num_ops",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/regionserver/Server/Delete_num_ops": {
+ "metric": "regionserver.Server.Delete_num_ops",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/regionserver/Server/Mutate_num_ops": {
+ "metric": "regionserver.Server.Mutate_num_ops",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/regionserver/Server/Get_95th_percentile": {
+ "metric": "regionserver.Server.Get_95th_percentile",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/regionserver/Server/Mutate_95th_percentile": {
+ "metric": "regionserver.Server.Mutate_95th_percentile",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/regionserver/Server/Increment_95th_percentile": {
+ "metric": "regionserver.Server.Increment_95th_percentile",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/regionserver/Server/Append_95th_percentile": {
+ "metric": "regionserver.Server.Append_95th_percentile",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/regionserver/Server/Delete_95th_percentile": {
+ "metric": "regionserver.Server.Delete_95th_percentile",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/regionserver/Server/percentFilesLocal": {
+ "metric": "regionserver.Server.percentFilesLocal",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/regionserver/Server/updatesBlockedTime": {
+ "metric": "regionserver.Server.updatesBlockedTime",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/ipc/IPC/numOpenConnections": {
+ "metric": "ipc.IPC.numOpenConnections",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/ipc/IPC/numActiveHandler": {
+ "metric": "ipc.IPC.numActiveHandler",
+ "pointInTime": false,
+ "temporal": true
+ },
+ "metrics/hbase/ipc/IPC/numCallsInGeneralQueue": {
+ "metric": "ipc.IPC.numCallsInGeneralQueue",
+ "pointInTime": false,
+ "temporal": true
+ },
"metrics/rpc/enableTable_avg_time": {
"metric": "rpc.rpc.enableTable_avg_time",
"pointInTime": true,
diff --git a/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/widgets.json b/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/widgets.json
new file mode 100644
index 0000000000..a64a2c8ac9
--- /dev/null
+++ b/ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/widgets.json
@@ -0,0 +1,192 @@
+{
+ "layouts": [
+ {
+ "layout_name": "default_hbase_layout",
+ "section_name": "HBASE_SUMMARY",
+ "widgetLayoutInfo": [
+ {
+ "widget_name": "RS_READS_WRITES",
+ "display_name": "RegionServer Reads and Writes",
+ "description": "This widget shows all the read requests and write requests on all regions for a RegionServer",
+ "widget_type": "GRAPH",
+ "is_visible": true,
+ "metrics": [
+ {
+ "name": "regionserver.Server.Get_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Get_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER",
+ "host_component_criteria": "isActive=true"
+ },
+ {
+ "name": "regionserver.Server.Scan_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Scan_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ },
+ {
+ "name": "regionserver.Server.Append_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Append_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ },
+ {
+ "name": "regionserver.Server.Delete_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Delete_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ },
+ {
+ "name": "regionserver.Server.Increment_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Increment_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ },
+ {
+ "name": "regionserver.Server.Mutate_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Mutate_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ }
+ ],
+ "values": [
+ {
+ "name": "Read Requests",
+ "value": "`${regionserver.Server.Get_num_ops + regionserver.Server.Scan_num_ops}`"
+ },
+ {
+ "name": "Write Requests",
+ "value": "`${metrics.hbase.regionserver.Server.Append_num_ops + metrics.hbase.regionserver.Server.Delete_num_ops + metrics.hbase.regionserver.Server.Increment_num_ops + metrics.hbase.regionserver.Server.Mutate_num_ops}`"
+ }
+ ],
+ "properties": {
+ "display_unit": "Requests",
+ "graph_type": "LINE",
+ "time_ranger": "1 week"
+ }
+ },
+ {
+ "widget_name": "OPEN_CONNECTIONS",
+ "display_name": "Open Connections",
+ "description": "This widget shows number of current open connections",
+ "widget_type": "GRAPH",
+ "is_visible": true,
+ "metrics": [
+ {
+ "name": "ipc.IPC.numOpenConnections",
+ "ambari_id": "metrics/hbase/ipc/IPC/numOpenConnections",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ }
+ ],
+ "values": [
+ {
+ "name": "Open Connections",
+ "value": "`${ipc.IPC.numOpenConnections}`"
+ }
+ ],
+ "properties": {
+ "display_unit": "Connections",
+ "graph_type": "STACK",
+ "time_ranger": "1 hour"
+ }
+ },
+ {
+ "widget_name": "ACTIVE_HANDLER",
+ "display_name": "Active Handlers vs Calls in General Queue",
+ "widget_type": "GRAPH",
+ "is_visible": true,
+ "metrics": [
+ {
+ "name": "ipc.IPC.numOpenConnections",
+ "ambari_id": "metrics/hbase/ipc/IPC/numOpenConnections",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ },
+ {
+ "name": "ipc.IPC.numCallsInGeneralQueue",
+ "ambari_id": "metrics/hbase/ipc/IPC/numOpenConnections",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ }
+ ],
+ "values": [
+ {
+ "name": "Active Handlers",
+ "value": "`${ipc.IPC.numActiveHandler}`"
+ },
+ {
+ "name": "Calls in General Queue",
+ "value": "`${ipc.IPC.numCallsInGeneralQueue}`"
+ }
+ ],
+ "properties": {
+ "graph_type": "LINE",
+ "time_ranger": "1 hour"
+ }
+ },
+ {
+ "widget_name": "FILES_LOCAL",
+ "display_name": "Files Local",
+ "description": "This widget shows percentage of files local.",
+ "widget_type": "NUMBER",
+ "is_visible": true,
+ "metrics": [
+ {
+ "name": "regionserver.Server.percentFilesLocal",
+ "ambari_id": "metrics/hbase/regionserver/percentFilesLocal",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ }
+ ],
+ "values": [
+ {
+ "name": "Files Local",
+ "value": "`${regionserver.Server.percentFilesLocal}`"
+ }
+ ],
+ "properties": {
+ "display_unit": "%"
+ }
+ },
+ {
+ "widget_name": "UPDATED_BLOCKED_TIME",
+ "display_name": "Updated Blocked Time",
+ "description": "",
+ "widget_type": "GRAPH",
+ "is_visible": true,
+ "metrics": [
+ {
+ "name": "regionserver.Server.updatesBlockedTime",
+ "ambari_id": "metrics/hbase/regionserver/Server/updatesBlockedTime",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ }
+ ],
+ "values": [
+ {
+ "name": "Updated Blocked Time",
+ "value": "`${regionserver.Server.updatesBlockedTime}`"
+ }
+ ],
+ "properties": {
+ "display_unit": "seconds",
+ "graph_type": "LINE",
+ "time_ranger": "1 day"
+ }
+ }
+ ]
+ }
+]
+}
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProviderTest.java
index b3e7e51a40..1251d99b95 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackArtifactResourceProviderTest.java
@@ -30,12 +30,14 @@ import org.apache.ambari.server.controller.utilities.PropertyHelper;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.state.stack.MetricDefinition;
+import org.apache.ambari.server.state.stack.WidgetLayout;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.apache.ambari.server.controller.internal.StackArtifactResourceProvider.ARTIFACT_DATA_PROPERTY_ID;
@@ -116,8 +118,50 @@ public class StackArtifactResourceProviderTest {
MetricDefinition md = (MetricDefinition) ((ArrayList) descriptor.get
("Component")).iterator().next();
Assert.assertEquals(326, md.getMetrics().size());
+
verify(managementController);
}
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testGetWidgetDescriptorForService() throws Exception {
+ AmbariManagementController managementController = createNiceMock(AmbariManagementController.class);
+
+ expect(managementController.getAmbariMetaInfo()).andReturn(metaInfo).anyTimes();
+
+ replay(managementController);
+
+ StackArtifactResourceProvider resourceProvider = getStackArtifactResourceProvider(managementController);
+
+ Set<String> propertyIds = new HashSet<String>();
+ propertyIds.add(ARTIFACT_NAME_PROPERTY_ID);
+ propertyIds.add(STACK_NAME_PROPERTY_ID);
+ propertyIds.add(STACK_VERSION_PROPERTY_ID);
+ propertyIds.add(STACK_SERVICE_NAME_PROPERTY_ID);
+ propertyIds.add(ARTIFACT_DATA_PROPERTY_ID);
+
+ Request request = PropertyHelper.getReadRequest(propertyIds);
+
+ Predicate predicate = new PredicateBuilder().property
+ (ARTIFACT_NAME_PROPERTY_ID).equals("widgets_descriptor").and().property
+ (STACK_NAME_PROPERTY_ID).equals("OTHER").and().property
+ (STACK_VERSION_PROPERTY_ID).equals("2.0").and().property
+ (STACK_SERVICE_NAME_PROPERTY_ID).equals("HBASE").toPredicate();
+
+ Set<Resource> resources = resourceProvider.getResources(request, predicate);
+
+ Assert.assertEquals(1, resources.size());
+ Resource resource = resources.iterator().next();
+ Map<String, Map<String, Object>> propertyMap = resource.getPropertiesMap();
+ Map<String, Object> descriptor = propertyMap.get(ARTIFACT_DATA_PROPERTY_ID);
+ Assert.assertNotNull(descriptor);
+ Assert.assertEquals(1, ((List<Object>) descriptor.get("layouts")).size());
+ WidgetLayout layout = ((List<WidgetLayout>) descriptor.get("layouts")).iterator().next();
+ Assert.assertEquals("default_hbase_layout", layout.getLayoutName());
+ Assert.assertEquals("HBASE_SUMMARY", layout.getSectionName());
+ Assert.assertEquals(5, layout.getWidgetLayoutInfoList().size());
+
+ verify(managementController);
+ }
}
diff --git a/ambari-server/src/test/resources/stacks/OTHER/2.0/services/HBASE/widgets.json b/ambari-server/src/test/resources/stacks/OTHER/2.0/services/HBASE/widgets.json
new file mode 100644
index 0000000000..705c3eb221
--- /dev/null
+++ b/ambari-server/src/test/resources/stacks/OTHER/2.0/services/HBASE/widgets.json
@@ -0,0 +1,192 @@
+{
+ "layouts": [
+ {
+ "layout_name": "default_hbase_layout",
+ "section_name": "HBASE_SUMMARY",
+ "widgetLayoutInfo": [
+ {
+ "widget_name": "RS_READS_WRITES",
+ "display_name": "RegionServer Reads and Writes",
+ "description": "This widget shows all the read requests and write requests on all regions for a RegionServer",
+ "widget_type": "GRAPH",
+ "is_visible": true,
+ "metrics": [
+ {
+ "name": "regionserver.Server.Get_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Get_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER",
+ "host_component_criteria": "isActive=true"
+ },
+ {
+ "name": "regionserver.Server.Scan_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Scan_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ },
+ {
+ "name": "regionserver.Server.Append_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Append_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ },
+ {
+ "name": "regionserver.Server.Delete_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Delete_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ },
+ {
+ "name": "regionserver.Server.Increment_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Increment_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ },
+ {
+ "name": "regionserver.Server.Mutate_num_ops",
+ "ambari_id": "metrics/hbase/regionserver/Server/Mutate_num_ops",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ }
+ ],
+ "values": [
+ {
+ "name": "Read Requests",
+ "value": "`${regionserver.Server.Get_num_ops + regionserver.Server.Scan_num_ops}`"
+ },
+ {
+ "name": "Write Requests",
+ "value": "`${metrics.hbase.regionserver.Server.Append_num_ops + metrics.hbase.regionserver.Server.Delete_num_ops + metrics.hbase.regionserver.Server.Increment_num_ops + metrics.hbase.regionserver.Server.Mutate_num_ops}`"
+ }
+ ],
+ "properties": {
+ "display_unit": "Requests",
+ "graph_type": "LINE",
+ "time_ranger": "1 week"
+ }
+ },
+ {
+ "widget_name": "OPEN_CONNECTIONS",
+ "display_name": "Open Connections",
+ "description": "This widget shows number of current open connections",
+ "widget_type": "GRAPH",
+ "is_visible": true,
+ "metrics": [
+ {
+ "name": "ipc.IPC.numOpenConnections",
+ "ambari_id": "metrics/hbase/ipc/IPC/numOpenConnections",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ }
+ ],
+ "values": [
+ {
+ "name": "Open Connections",
+ "value": "`${ipc.IPC.numOpenConnections}`"
+ }
+ ],
+ "properties": {
+ "display_unit": "Connections",
+ "graph_type": "STACK",
+ "time_ranger": "1 hour"
+ }
+ },
+ {
+ "widget_name": "ACTIVE_HANDLER",
+ "display_name": "Active Handlers vs Calls in General Queue",
+ "widget_type": "GRAPH",
+ "is_visible": true,
+ "metrics": [
+ {
+ "name": "ipc.IPC.numOpenConnections",
+ "ambari_id": "metrics/hbase/ipc/IPC/numOpenConnections",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ },
+ {
+ "name": "ipc.IPC.numCallsInGeneralQueue",
+ "ambari_id": "metrics/hbase/ipc/IPC/numOpenConnections",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ }
+ ],
+ "values": [
+ {
+ "name": "Active Handlers",
+ "value": "`${ipc.IPC.numActiveHandler}`"
+ },
+ {
+ "name": "Calls in General Queue",
+ "value": "`${ipc.IPC.numCallsInGeneralQueue}`"
+ }
+ ],
+ "properties": {
+ "graph_type": "LINE",
+ "time_ranger": "1 hour"
+ }
+ },
+ {
+ "widget_name": "FILES_LOCAL",
+ "display_name": "Files Local",
+ "description": "This widget shows percentage of files local.",
+ "widget_type": "NUMBER",
+ "is_visible": true,
+ "metrics": [
+ {
+ "name": "regionserver.Server.percentFilesLocal",
+ "ambari_id": "metrics/hbase/regionserver/percentFilesLocal",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ }
+ ],
+ "values": [
+ {
+ "name": "Files Local",
+ "value": "`${regionserver.Server.percentFilesLocal}`"
+ }
+ ],
+ "properties": {
+ "display_unit": "%"
+ }
+ },
+ {
+ "widget_name": "UPDATED_BLOCKED_TIME",
+ "display_name": "Updated Blocked Time",
+ "description": "",
+ "widget_type": "GRAPH",
+ "is_visible": true,
+ "metrics": [
+ {
+ "name": "regionserver.Server.updatesBlockedTime",
+ "ambari_id": "metrics/hbase/regionserver/Server/updatesBlockedTime",
+ "category": "",
+ "service_name": "HBASE",
+ "component_name": "HBASE_REGIONSERVER"
+ }
+ ],
+ "values": [
+ {
+ "name": "Updated Blocked Time",
+ "value": "`${regionserver.Server.updatesBlockedTime}`"
+ }
+ ],
+ "properties": {
+ "display_unit": "seconds",
+ "graph_type": "LINE",
+ "time_ranger": "1 day"
+ }
+ }
+ ]
+ }
+ ]
+}