You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by tb...@apache.org on 2014/01/28 11:12:05 UTC
[1/2] git commit: AMBARI-4428 - Add Ambari View configuration code.
Updated Branches:
refs/heads/trunk 682ef9984 -> 3d7270b38
AMBARI-4428 - Add Ambari View configuration code.
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/3d7270b3
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3d7270b3
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3d7270b3
Branch: refs/heads/trunk
Commit: 3d7270b38d20346228b7e6e793a538a2deda6b4f
Parents: 89af4f1
Author: tbeerbower <tb...@hortonworks.com>
Authored: Mon Jan 27 12:21:42 2014 -0500
Committer: tbeerbower <tb...@hortonworks.com>
Committed: Tue Jan 28 05:06:59 2014 -0500
----------------------------------------------------------------------
.../view/configuration/InstanceConfig.java | 59 +++++
.../view/configuration/ParameterConfig.java | 70 ++++++
.../view/configuration/PropertyConfig.java | 56 +++++
.../view/configuration/ResourceConfig.java | 174 +++++++++++++
.../view/configuration/ServletConfig.java | 72 ++++++
.../configuration/ServletMappingConfig.java | 60 +++++
.../server/view/configuration/ViewConfig.java | 197 +++++++++++++++
.../view/configuration/InstanceConfigTest.java | 56 +++++
.../view/configuration/ParameterConfigTest.java | 62 +++++
.../view/configuration/PropertyConfigTest.java | 60 +++++
.../view/configuration/ResourceConfigTest.java | 99 ++++++++
.../view/configuration/ServletConfigTest.java | 51 ++++
.../configuration/ServletMappingConfigTest.java | 51 ++++
.../view/configuration/ViewConfigTest.java | 244 +++++++++++++++++++
14 files changed, 1311 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
new file mode 100644
index 0000000..fd80922
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
@@ -0,0 +1,59 @@
+/**
+ * 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.view.configuration;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import java.util.List;
+
+/**
+ * View instance configuration.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class InstanceConfig {
+ /**
+ * The instance name.
+ */
+ private String name;
+
+ /**
+ * The instance properties.
+ */
+ @XmlElement(name="property")
+ private List<PropertyConfig> properties;
+
+ /**
+ * Get the instance name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the instance properties.
+ *
+ * @return the instance properties
+ */
+ public List<PropertyConfig> getProperties() {
+ return properties;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ParameterConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ParameterConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ParameterConfig.java
new file mode 100644
index 0000000..97c9e22
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ParameterConfig.java
@@ -0,0 +1,70 @@
+/**
+ * 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.view.configuration;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+
+/**
+ * View parameter configuration.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ParameterConfig {
+ /**
+ * The parameter name.
+ */
+ private String name;
+
+ /**
+ * The parameter description.
+ */
+ private String description;
+
+ /**
+ * Indicates whether or not the parameter is required.
+ */
+ private boolean required;
+
+ /**
+ * Get the parameter name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the parameter description.
+ *
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Indicates whether or not the parameter is required.
+ *
+ * @return true if the parameter is required; false otherwise
+ */
+ public boolean isRequired() {
+ return required;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/PropertyConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/PropertyConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/PropertyConfig.java
new file mode 100644
index 0000000..e420c40
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/PropertyConfig.java
@@ -0,0 +1,56 @@
+/**
+ * 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.view.configuration;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+
+/**
+ * View instance property configuration.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class PropertyConfig {
+ /**
+ * The property key.
+ */
+ private String key;
+
+ /**
+ * The property value.
+ */
+ private String value;
+
+ /**
+ * Get the property key.
+ *
+ * @return the property key
+ */
+ public String getKey() {
+ return key;
+ }
+
+ /**
+ * Get the property value.
+ *
+ * @return the property value
+ */
+ public String getValue() {
+ return value;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ResourceConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ResourceConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ResourceConfig.java
new file mode 100644
index 0000000..8bc3de1
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ResourceConfig.java
@@ -0,0 +1,174 @@
+/**
+ * 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.view.configuration;
+
+
+import org.apache.ambari.view.ResourceProvider;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * View resource configuration.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ResourceConfig {
+ /**
+ * The resource name.
+ */
+ private String name;
+
+ /**
+ * The plural name of the resource.
+ */
+ @XmlElement(name="plural-name")
+ private String pluralName;
+
+ /**
+ * The id property of the resource.
+ */
+ @XmlElement(name="id-property")
+ private String idProperty;
+
+ /**
+ * The list of sub resource names.
+ */
+ @XmlElement(name="sub-resource-name")
+ private List<String> subResourceNames;
+
+ /**
+ * The resource provider class name.
+ */
+ @XmlElement(name="provider-class")
+ private String provider;
+
+ /**
+ * The resource provider class.
+ */
+ private Class<? extends ResourceProvider> providerClass = null;
+
+ /**
+ * The resource service class name.
+ */
+ @XmlElement(name="service-class")
+ private String service;
+
+ /**
+ * The resource service class.
+ */
+ private Class<?> serviceClass = null;
+
+ /**
+ * The resource service class name.
+ */
+ @XmlElement(name="resource-class")
+ private String resource;
+
+ /**
+ * The resource service class.
+ */
+ private Class<?> resourceClass = null;
+
+ /**
+ * Get the resource name.
+ *
+ * @return the resource name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the resource plural name.
+ *
+ * @return the plural name
+ */
+ public String getPluralName() {
+ return pluralName;
+ }
+
+ /**
+ * Get the id property of the resource.
+ *
+ * @return the id property
+ */
+ public String getIdProperty() {
+ return idProperty;
+ }
+
+ /**
+ * Get the list of sub-resource names.
+ *
+ * @return the sub-resource names
+ */
+ public List<String> getSubResourceNames() {
+ return subResourceNames == null ? Collections.<String>emptyList() : subResourceNames;
+ }
+
+ /**
+ * Get the resource provider class.
+ *
+ * @param cl the class loader
+ *
+ * @return the resource provider class
+ *
+ * @throws ClassNotFoundException if the class can not be loaded
+ */
+ public Class<? extends ResourceProvider> getProviderClass(ClassLoader cl) throws ClassNotFoundException {
+ if (providerClass == null) {
+ providerClass = cl.loadClass(provider).asSubclass(ResourceProvider.class);
+ }
+ return providerClass;
+ }
+
+ /**
+ * Get the resource service class.
+ *
+ * @param cl the class loader
+ *
+ * @return the resource service class
+ *
+ * @throws ClassNotFoundException if the class can not be loaded
+ */
+ public Class<?> getServiceClass(ClassLoader cl) throws ClassNotFoundException {
+ if (serviceClass == null) {
+ serviceClass = cl.loadClass(service);
+ }
+ return serviceClass;
+ }
+
+ /**
+ * Get the resource class.
+ *
+ * @param cl the class loader
+ *
+ * @return the resource class
+ *
+ * @throws ClassNotFoundException if the class can not be loaded
+ */
+ public Class<?> getResourceClass(ClassLoader cl) throws ClassNotFoundException {
+ if (resourceClass == null) {
+ resourceClass = cl.loadClass(resource);
+ }
+ return resourceClass;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletConfig.java
new file mode 100644
index 0000000..a62d0f3
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletConfig.java
@@ -0,0 +1,72 @@
+/**
+ * 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.view.configuration;
+
+import javax.servlet.http.HttpServlet;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * View servlet mapping.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ServletConfig {
+ /**
+ * The servlet name.
+ */
+ @XmlElement(name="servlet-name")
+ private String name;
+
+ /**
+ * The servlet class name.
+ */
+ @XmlElement(name="servlet-path")
+ private String path;
+
+ /**
+ * The servlet class.
+ */
+ private Class<? extends HttpServlet> servletClass = null;
+
+ /**
+ * The servlet name.
+ *
+ * @return the servlet name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the servlet class.
+ *
+ * @param cl the class loader
+ *
+ * @return the servlet class
+ *
+ * @throws ClassNotFoundException if the class can not be loaded
+ */
+ public Class<? extends HttpServlet> getServletClass(ClassLoader cl) throws ClassNotFoundException {
+ if (servletClass == null) {
+ servletClass = cl.loadClass(path).asSubclass(HttpServlet.class);
+ }
+ return servletClass;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletMappingConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletMappingConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletMappingConfig.java
new file mode 100644
index 0000000..cc11e07
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletMappingConfig.java
@@ -0,0 +1,60 @@
+/**
+ * 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.view.configuration;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * View servlet mapping configuration.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ServletMappingConfig {
+
+ /**
+ * The servlet name.
+ */
+ @XmlElement(name="servlet-name")
+ private String name;
+
+ /**
+ * The URL pattern.
+ */
+ @XmlElement(name="url-pattern")
+ private String urlPattern;
+
+ /**
+ * Get the servlet name.
+ *
+ * @return the servlet name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the URL pattern.
+ *
+ * @return the URL pattern
+ */
+ public String getUrlPattern() {
+ return urlPattern;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
new file mode 100644
index 0000000..daac81f
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
@@ -0,0 +1,197 @@
+/**
+ * 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.view.configuration;
+
+import javax.servlet.http.HttpServlet;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * View configuration.
+ */
+@XmlRootElement(name="view")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ViewConfig {
+ /**
+ * The unique view name.
+ */
+ private String name;
+
+ /**
+ * The public view name.
+ */
+ private String label;
+
+ /**
+ * The view version.
+ */
+ private String version;
+
+ /**
+ * The list of view parameters.
+ */
+ @XmlElement(name="parameter")
+ private List<ParameterConfig> parameters;
+
+ /**
+ * The list of view resources.
+ */
+ @XmlElement(name="resource")
+ private List<ResourceConfig> resources;
+
+ /**
+ * The list of view instances.
+ */
+ @XmlElement(name="instance")
+ private List<InstanceConfig> instances;
+
+ /**
+ * The list of servlets.
+ */
+ @XmlElement(name="servlet")
+ private List<ServletConfig> servlets;
+
+ /**
+ * The mapping of servlet names to servlet classes.
+ */
+ public Map<String, Class<? extends HttpServlet>> servletPathMap = null;
+
+ /**
+ * The list of servlet mappings.
+ */
+ @XmlElement(name="servlet-mapping")
+ private List<ServletMappingConfig> mappings;
+
+ /**
+ * The mapping of servlet names to URL patterns.
+ */
+ public Map<String, String> servletURLPatternMap = null;
+
+ /**
+ * Get the unique name.
+ *
+ * @return the view name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the public view name.
+ *
+ * @return the view label
+ */
+ public String getLabel() {
+ return label;
+ }
+
+ /**
+ * Get the view version.
+ *
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Get the list of view parameters.
+ *
+ * @return the list of parameters
+ */
+ public List<ParameterConfig> getParameters() {
+ return parameters;
+ }
+
+ /**
+ * Get the list of view resources.
+ *
+ * @return return the list of resources
+ */
+ public List<ResourceConfig> getResources() {
+ return resources;
+ }
+
+ /**
+ * Get the list of view instances.
+ *
+ * @return the list of view instances
+ */
+ public List<InstanceConfig> getInstances() {
+ return instances;
+ }
+
+ /**
+ * Get the list of servlets.
+ *
+ * @return the list of view servlets
+ */
+ public List<ServletConfig> getServlets() {
+ return servlets;
+ }
+
+ /**
+ * Get the list of servlet mappings.
+ *
+ * @return the list of view servlet mappings.
+ */
+ public List<ServletMappingConfig> getMappings() {
+ return mappings;
+ }
+
+ /**
+ * Get the mapping of servlet names to servlet classes.
+ *
+ * @param cl the class loader
+ *
+ * @return the mapping of servlet names to servlet classes
+ *
+ * @throws ClassNotFoundException if a servlet class can not be loaded
+ */
+ public synchronized Map<String, Class<? extends HttpServlet>> getServletPathMap(ClassLoader cl)
+ throws ClassNotFoundException{
+ if (servletPathMap == null) {
+ servletPathMap = new HashMap<String, Class<? extends HttpServlet>>();
+ for (ServletConfig servletConfig : servlets) {
+ servletPathMap.put(servletConfig.getName(), servletConfig.getServletClass(cl));
+ }
+ }
+ return servletPathMap;
+ }
+
+ /**
+ * Get the mapping of servlet names to URL patterns.
+ *
+ * @return the mapping of servlet names to URL patterns
+ */
+ public synchronized Map<String, String> getServletURLPatternMap() {
+ if (servletURLPatternMap == null) {
+ servletURLPatternMap = new HashMap<String, String>();
+ for (ServletMappingConfig servletMappingConfig : mappings) {
+ servletURLPatternMap.put(servletMappingConfig.getName(), servletMappingConfig.getUrlPattern());
+ }
+ }
+ return servletURLPatternMap;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
new file mode 100644
index 0000000..28fe7f3
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
@@ -0,0 +1,56 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBException;
+import java.util.List;
+
+/**
+ * InstanceConfig tests.
+ */
+public class InstanceConfigTest {
+ @Test
+ public void testGetName() throws Exception {
+ List<InstanceConfig> instances = getInstanceConfigs();
+
+ Assert.assertEquals(2, instances.size());
+ Assert.assertEquals("INSTANCE1", instances.get(0).getName());
+ Assert.assertEquals("INSTANCE2", instances.get(1).getName());
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ List<InstanceConfig> instances = getInstanceConfigs();
+
+ Assert.assertEquals(2, instances.size());
+ List<PropertyConfig> properties = instances.get(0).getProperties();
+ Assert.assertEquals(2, properties.size());
+
+ properties = instances.get(1).getProperties();
+ Assert.assertEquals(1, properties.size());
+ }
+
+ public static List<InstanceConfig> getInstanceConfigs() throws JAXBException {
+ ViewConfig config = ViewConfigTest.getConfig();
+ return config.getInstances();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ParameterConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ParameterConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ParameterConfigTest.java
new file mode 100644
index 0000000..7069d37
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ParameterConfigTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBException;
+import java.util.List;
+
+/**
+ * ParameterConfig tests.
+ */
+public class ParameterConfigTest {
+ @Test
+ public void testGetName() throws Exception {
+ List<ParameterConfig> parameters = getParameterConfigs();
+
+ Assert.assertEquals(2, parameters.size());
+ Assert.assertEquals("p1", parameters.get(0).getName());
+ Assert.assertEquals("p2", parameters.get(1).getName());
+ }
+
+ @Test
+ public void testGetDescription() throws Exception {
+ List<ParameterConfig> parameters = getParameterConfigs();
+
+ Assert.assertEquals(2, parameters.size());
+ Assert.assertEquals("Parameter 1.", parameters.get(0).getDescription());
+ Assert.assertEquals("Parameter 2.", parameters.get(1).getDescription());
+ }
+
+ @Test
+ public void testIsRequired() throws Exception {
+ List<ParameterConfig> parameters = getParameterConfigs();
+
+ Assert.assertEquals(2, parameters.size());
+ Assert.assertEquals(true, parameters.get(0).isRequired());
+ Assert.assertEquals(false, parameters.get(1).isRequired());
+ }
+
+ public static List<ParameterConfig> getParameterConfigs() throws JAXBException {
+ ViewConfig viewConfig = ViewConfigTest.getConfig();
+ return viewConfig.getParameters ();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/PropertyConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/PropertyConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/PropertyConfigTest.java
new file mode 100644
index 0000000..ce8b390
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/PropertyConfigTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * PropertyConfig tests.
+ */
+public class PropertyConfigTest {
+ @Test
+ public void testGetKey() throws Exception {
+
+ List<InstanceConfig> instanceConfigs = InstanceConfigTest.getInstanceConfigs();
+ for (InstanceConfig instanceConfig : instanceConfigs) {
+ List<PropertyConfig> propertyConfigs = instanceConfig.getProperties();
+
+ Assert.assertTrue(propertyConfigs.size() <= 2);
+ Assert.assertEquals("p1", propertyConfigs.get(0).getKey());
+
+ if (propertyConfigs.size() == 2) {
+ Assert.assertEquals("p2", propertyConfigs.get(1).getKey());
+ }
+ }
+ }
+
+ @Test
+ public void testGetValue() throws Exception {
+ List<InstanceConfig> instanceConfigs = InstanceConfigTest.getInstanceConfigs();
+ for (InstanceConfig instanceConfig : instanceConfigs) {
+ List<PropertyConfig> propertyConfigs = instanceConfig.getProperties();
+
+ Assert.assertTrue(propertyConfigs.size() <= 2);
+ Assert.assertTrue(propertyConfigs.get(0).getValue().startsWith("v1-"));
+
+ if (propertyConfigs.size() == 2) {
+ Assert.assertTrue(propertyConfigs.get(1).getValue().startsWith("v2-"));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ResourceConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ResourceConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ResourceConfigTest.java
new file mode 100644
index 0000000..c9cc5dd
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ResourceConfigTest.java
@@ -0,0 +1,99 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBException;
+import java.util.List;
+
+/**
+ * ResourceConfig tests.
+ */
+public class ResourceConfigTest {
+ @Test
+ public void testGetName() throws Exception {
+ List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+ Assert.assertEquals(2, resourceConfigs.size());
+ Assert.assertEquals("resource", resourceConfigs.get(0).getName());
+ Assert.assertEquals("subresource", resourceConfigs.get(1).getName());
+ }
+
+ @Test
+ public void testGetPluralName() throws Exception {
+ List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+ Assert.assertEquals(2, resourceConfigs.size());
+ Assert.assertEquals("resources", resourceConfigs.get(0).getPluralName());
+ Assert.assertEquals("subresources", resourceConfigs.get(1).getPluralName());
+ }
+
+ @Test
+ public void testGetIdProperty() throws Exception {
+ List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+ Assert.assertEquals(2, resourceConfigs.size());
+ Assert.assertEquals("id", resourceConfigs.get(0).getIdProperty());
+ Assert.assertEquals("id", resourceConfigs.get(1).getIdProperty());
+ }
+
+ @Test
+ public void testGetSubResourceNames() throws Exception {
+ List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+ Assert.assertEquals(2, resourceConfigs.size());
+ Assert.assertEquals(1, resourceConfigs.get(0).getSubResourceNames().size());
+ Assert.assertEquals("subresource", resourceConfigs.get(0).getSubResourceNames().get(0));
+ Assert.assertEquals(0, resourceConfigs.get(1).getSubResourceNames().size());
+ }
+
+ @Test
+ public void testGetProviderClass() throws Exception {
+ List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+ Assert.assertEquals(2, resourceConfigs.size());
+ Assert.assertTrue(resourceConfigs.get(0).getProviderClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResourceProvider.class));
+ Assert.assertTrue(resourceConfigs.get(1).getProviderClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResourceProvider.class));
+ }
+
+ @Test
+ public void testGetServiceClass() throws Exception {
+ List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+ Assert.assertEquals(2, resourceConfigs.size());
+ Assert.assertTrue(resourceConfigs.get(0).getResourceClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResource.class));
+ Assert.assertTrue(resourceConfigs.get(1).getResourceClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResource.class));
+ }
+
+ @Test
+ public void testGetResourceClass() throws Exception {
+ List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+ Assert.assertEquals(2, resourceConfigs.size());
+ Assert.assertTrue(resourceConfigs.get(0).getServiceClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResourceService.class));
+ Assert.assertTrue(resourceConfigs.get(1).getServiceClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResourceService.class));
+ }
+
+ public static List<ResourceConfig> getResourceConfigs() throws JAXBException {
+ ViewConfig viewConfig = ViewConfigTest.getConfig();
+ return viewConfig.getResources ();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletConfigTest.java
new file mode 100644
index 0000000..8cf0ff7
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletConfigTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBException;
+import java.util.List;
+
+/**
+ * ServletConfig tests.
+ */
+public class ServletConfigTest {
+ @Test
+ public void testGetName() throws Exception {
+ List<ServletConfig> servletConfigs = getServletConfigs();
+
+ Assert.assertEquals(1, servletConfigs.size());
+ Assert.assertEquals("MyViewServlet", servletConfigs.get(0).getName());
+ }
+
+ @Test
+ public void testGetServletClass() throws Exception {
+ List<ServletConfig> servletConfigs = getServletConfigs();
+
+ Assert.assertEquals(1, servletConfigs.size());
+ Assert.assertTrue(servletConfigs.get(0).getServletClass(getClass().getClassLoader()).equals(ViewConfigTest.MyViewServlet.class));
+ }
+
+ public static List<ServletConfig> getServletConfigs() throws JAXBException {
+ ViewConfig viewConfig = ViewConfigTest.getConfig();
+ return viewConfig.getServlets();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletMappingConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletMappingConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletMappingConfigTest.java
new file mode 100644
index 0000000..c0447bb
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletMappingConfigTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBException;
+import java.util.List;
+
+/**
+ * ServletMappingConfig tests.
+ */
+public class ServletMappingConfigTest {
+ @Test
+ public void testGetName() throws Exception {
+ List<ServletMappingConfig> mappingConfigs = getServletMappingConfigs();
+
+ Assert.assertEquals(1, mappingConfigs.size());
+ Assert.assertEquals("MyViewServlet", mappingConfigs.get(0).getName());
+ }
+
+ @Test
+ public void testGetUrlPattern() throws Exception {
+ List<ServletMappingConfig> mappingConfigs = getServletMappingConfigs();
+
+ Assert.assertEquals(1, mappingConfigs.size());
+ Assert.assertEquals("/ui", mappingConfigs.get(0).getUrlPattern());
+ }
+
+ public static List<ServletMappingConfig> getServletMappingConfigs() throws JAXBException {
+ ViewConfig viewConfig = ViewConfigTest.getConfig();
+ return viewConfig.getMappings();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
new file mode 100644
index 0000000..0ca6764
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
@@ -0,0 +1,244 @@
+/**
+ * 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.view.configuration;
+
+import org.apache.ambari.view.NoSuchResourceException;
+import org.apache.ambari.view.ReadRequest;
+import org.apache.ambari.view.ResourceAlreadyExistsException;
+import org.apache.ambari.view.ResourceProvider;
+import org.apache.ambari.view.SystemException;
+import org.apache.ambari.view.UnsupportedPropertyException;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.servlet.http.HttpServlet;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * ViewConfig tests.
+ */
+public class ViewConfigTest {
+
+ private static String xml = "<view>\n" +
+ " <name>MY_VIEW</name>\n" +
+ " <label>My View!</label>\n" +
+ " <version>1.0.0</version>\n" +
+ " <parameter>\n" +
+ " <name>p1</name>\n" +
+ " <description>Parameter 1.</description>\n" +
+ " <required>true</required>\n" +
+ " </parameter>\n" +
+ " <parameter>\n" +
+ " <name>p2</name>\n" +
+ " <description>Parameter 2.</description>\n" +
+ " <required>false</required>\n" +
+ " </parameter>\n" +
+ " <resource>\n" +
+ " <name>resource</name>\n" +
+ " <plural-name>resources</plural-name>\n" +
+ " <id-property>id</id-property>\n" +
+ " <resource-class>org.apache.ambari.server.view.configuration.ViewConfigTest$MyResource</resource-class>\n" +
+ " <provider-class>org.apache.ambari.server.view.configuration.ViewConfigTest$MyResourceProvider</provider-class>\n" +
+ " <service-class>org.apache.ambari.server.view.configuration.ViewConfigTest$MyResourceService</service-class>\n" +
+ " <sub-resource-name>subresource</sub-resource-name>\n" +
+ " </resource>\n" +
+ " <resource>\n" +
+ " <name>subresource</name>\n" +
+ " <plural-name>subresources</plural-name>\n" +
+ " <id-property>id</id-property>\n" +
+ " <resource-class>org.apache.ambari.server.view.configuration.ViewConfigTest$MyResource</resource-class>\n" +
+ " <provider-class>org.apache.ambari.server.view.configuration.ViewConfigTest$MyResourceProvider</provider-class>\n" +
+ " <service-class>org.apache.ambari.server.view.configuration.ViewConfigTest$MyResourceService</service-class>\n" +
+ " </resource>\n" +
+ " <servlet>\n" +
+ " <servlet-name>MyViewServlet</servlet-name>\n" +
+ " <servlet-path>org.apache.ambari.server.view.configuration.ViewConfigTest$MyViewServlet</servlet-path>\n" +
+ " </servlet>\n" +
+ " <servlet-mapping>\n" +
+ " <servlet-name>MyViewServlet</servlet-name>\n" +
+ " <url-pattern>/ui</url-pattern>\n" +
+ " </servlet-mapping>\n" +
+ " <instance>\n" +
+ " <name>INSTANCE1</name>\n" +
+ " <property>\n" +
+ " <key>p1</key>\n" +
+ " <value>v1-1</value>\n" +
+ " </property>\n" +
+ " <property>\n" +
+ " <key>p2</key>\n" +
+ " <value>v2-1</value>\n" +
+ " </property>\n" +
+ " </instance>\n" +
+ " <instance>\n" +
+ " <name>INSTANCE2</name>\n" +
+ " <property>\n" +
+ " <key>p1</key>\n" +
+ " <value>v1-2</value>\n" +
+ " </property>\n" +
+ " </instance>\n" +
+ "</view>";
+
+
+ @Test
+ public void testGetName() throws Exception {
+ ViewConfig config = getConfig();
+ Assert.assertEquals("MY_VIEW", config.getName());
+ }
+
+ @Test
+ public void testGetLabel() throws Exception {
+ ViewConfig config = getConfig();
+ Assert.assertEquals("My View!", config.getLabel());
+ }
+
+ @Test
+ public void testGetVersion() throws Exception {
+ ViewConfig config = getConfig();
+ Assert.assertEquals("1.0.0", config.getVersion());
+ }
+
+ @Test
+ public void testGetParameters() throws Exception {
+ ViewConfig config = getConfig();
+ List<ParameterConfig> parameters = config.getParameters();
+ Assert.assertEquals(2, parameters.size());
+ Assert.assertEquals("p1", parameters.get(0).getName());
+ Assert.assertEquals("p2", parameters.get(1).getName());
+ }
+
+ @Test
+ public void testGetResources() throws Exception {
+ ViewConfig config = getConfig();
+ List<ResourceConfig> resources = config.getResources();
+ Assert.assertEquals(2, resources.size());
+ Assert.assertEquals("resource", resources.get(0).getName());
+ Assert.assertEquals("subresource", resources.get(1).getName());
+ }
+
+ @Test
+ public void testGetInstances() throws Exception {
+ ViewConfig config = getConfig();
+ List<InstanceConfig> instances = config.getInstances();
+ Assert.assertEquals(2, instances.size());
+ Assert.assertEquals("INSTANCE1", instances.get(0).getName());
+ Assert.assertEquals("INSTANCE2", instances.get(1).getName());
+ }
+
+ @Test
+ public void testGetServlets() throws Exception {
+ ViewConfig config = getConfig();
+ List<ServletConfig> servlets = config.getServlets();
+ Assert.assertEquals(1, servlets.size());
+ Assert.assertEquals("MyViewServlet", servlets.get(0).getName());
+ }
+
+ @Test
+ public void testGetMappings() throws Exception {
+ ViewConfig config = getConfig();
+ List<ServletMappingConfig> mappings = config.getMappings();
+ Assert.assertEquals(1, mappings.size());
+ Assert.assertEquals("MyViewServlet", mappings.get(0).getName());
+ }
+
+ @Test
+ public void testGetServletPathMap() throws Exception {
+ ViewConfig config = getConfig();
+ Map<String, Class<? extends HttpServlet>> servletPathMap = config.getServletPathMap(getClass().getClassLoader());
+
+ Assert.assertEquals(1, servletPathMap.size());
+ Assert.assertEquals("MyViewServlet", servletPathMap.keySet().iterator().next());
+ Assert.assertTrue(servletPathMap.values().iterator().next().equals(MyViewServlet.class));
+ }
+
+ @Test
+ public void testGetServletURLPatternMap() throws Exception {
+ ViewConfig config = getConfig();
+ Map<String, String> servletURLPatternMap = config.getServletURLPatternMap();
+
+ Assert.assertEquals(1, servletURLPatternMap.size());
+ Assert.assertEquals("MyViewServlet", servletURLPatternMap.keySet().iterator().next());
+ Assert.assertEquals("/ui", servletURLPatternMap.values().iterator().next());
+ }
+
+ public static ViewConfig getConfig() throws JAXBException {
+ InputStream configStream = new ByteArrayInputStream(xml.getBytes());
+ JAXBContext jaxbContext = JAXBContext.newInstance(ViewConfig.class);
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+ return (ViewConfig) unmarshaller.unmarshal(configStream);
+ }
+
+ public static class MyViewServlet extends HttpServlet {
+ // nothing
+ }
+
+ public static class MyResource {
+ private String id;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+ }
+
+ public static class MyResourceProvider implements ResourceProvider<MyResource> {
+
+ @Override
+ public MyResource getResource(String resourceId, Set<String> properties)
+ throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+ return null;
+ }
+
+ @Override
+ public Set<MyResource> getResources(ReadRequest request)
+ throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+ return null;
+ }
+
+ @Override
+ public void createResource(String resourceId, Map<String, Object> properties)
+ throws SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException {
+ }
+
+ @Override
+ public boolean updateResource(String resourceId, Map<String, Object> properties)
+ throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+ return false;
+ }
+
+ @Override
+ public boolean deleteResource(String resourceId)
+ throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+ return false;
+ }
+ }
+
+ public static class MyResourceService {
+ // nothing
+ }
+}
[2/2] git commit: AMBARI-4406 - Create module for Ambari View
interfaces
Posted by tb...@apache.org.
AMBARI-4406 - Create module for Ambari View interfaces
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/89af4f19
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/89af4f19
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/89af4f19
Branch: refs/heads/trunk
Commit: 89af4f19005c2a87561e2279fed8745a6f8a9645
Parents: 682ef99
Author: tbeerbower <tb...@hortonworks.com>
Authored: Thu Jan 23 21:04:52 2014 -0500
Committer: tbeerbower <tb...@hortonworks.com>
Committed: Tue Jan 28 05:06:59 2014 -0500
----------------------------------------------------------------------
ambari-server/pom.xml | 5 +
ambari-views/pom.xml | 130 +++++++++++++++++++
ambari-views/src/main/assemblies/views.xml | 22 ++++
.../ambari/view/NoSuchResourceException.java | 50 +++++++
.../org/apache/ambari/view/ReadRequest.java | 39 ++++++
.../view/ResourceAlreadyExistsException.java | 48 +++++++
.../apache/ambari/view/ResourceProvider.java | 103 +++++++++++++++
.../org/apache/ambari/view/SystemException.java | 33 +++++
.../view/UnsupportedPropertyException.java | 70 ++++++++++
.../org/apache/ambari/view/ViewContext.java | 65 ++++++++++
.../apache/ambari/view/ViewResourceHandler.java | 41 ++++++
.../view/NoSuchResourceExceptionTest.java | 32 +++++
.../ResourceAlreadyExistsExceptionTest.java | 33 +++++
.../view/UnsupportedPropertyExceptionTest.java | 47 +++++++
pom.xml | 1 +
15 files changed, 719 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index f7ca909..1d6b427 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -583,6 +583,11 @@
</profiles>
<dependencies>
<dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>ambari-views</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-views/pom.xml b/ambari-views/pom.xml
new file mode 100644
index 0000000..5adc775
--- /dev/null
+++ b/ambari-views/pom.xml
@@ -0,0 +1,130 @@
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.apache.ambari</groupId>
+ <artifactId>ambari-project</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ <relativePath>../ambari-project</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.ambari</groupId>
+ <artifactId>ambari-views</artifactId>
+ <packaging>jar</packaging>
+ <name>Ambari Views</name>
+ <version>1.3.0-SNAPSHOT</version>
+ <description>Ambari View interfaces.</description>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>3.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-core</artifactId>
+ <version>1.8</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.8</version>
+ <executions>
+ <execution>
+ <id>parse-version</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>parse-version</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>regex-property</id>
+ <goals>
+ <goal>regex-property</goal>
+ </goals>
+ <configuration>
+ <name>ambariVersion</name>
+ <value>${project.version}</value>
+ <regex>-SNAPSHOT</regex>
+ <failIfNoMatch>false</failIfNoMatch>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.0</version>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <tarLongFileMode>gnu</tarLongFileMode>
+ <descriptors>
+ <descriptor>src/main/assemblies/views.xml</descriptor>
+ </descriptors>
+ </configuration>
+ <executions>
+ <execution>
+ <id>build-tarball</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/*.json</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>rpm-maven-plugin</artifactId>
+ <version>2.0.1</version>
+ <executions>
+ <execution>
+ <phase>none</phase>
+ <goals>
+ <goal>rpm</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
+
+
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/main/assemblies/views.xml
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/assemblies/views.xml b/ambari-views/src/main/assemblies/views.xml
new file mode 100644
index 0000000..7b895df
--- /dev/null
+++ b/ambari-views/src/main/assemblies/views.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+<assembly>
+</assembly>
+
+
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/main/java/org/apache/ambari/view/NoSuchResourceException.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/NoSuchResourceException.java b/ambari-views/src/main/java/org/apache/ambari/view/NoSuchResourceException.java
new file mode 100644
index 0000000..e1ab8ab
--- /dev/null
+++ b/ambari-views/src/main/java/org/apache/ambari/view/NoSuchResourceException.java
@@ -0,0 +1,50 @@
+/**
+ * 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.view;
+
+/**
+ * Indicates that a resource doesn't exist.
+ */
+public class NoSuchResourceException extends Exception {
+
+ /**
+ * The resource id.
+ */
+ private final String resourceId;
+
+ /**
+ * Constructor.
+ *
+ * @param resourceId the resource id
+ */
+ public NoSuchResourceException(String resourceId) {
+ super("The resource " + resourceId +
+ " specified in the request does not exist.");
+ this.resourceId = resourceId;
+ }
+
+ /**
+ * Get the id of the non-existent resource.
+ *
+ * @return the resource id
+ */
+ public String getResourceId() {
+ return resourceId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/main/java/org/apache/ambari/view/ReadRequest.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/ReadRequest.java b/ambari-views/src/main/java/org/apache/ambari/view/ReadRequest.java
new file mode 100644
index 0000000..ddadd42
--- /dev/null
+++ b/ambari-views/src/main/java/org/apache/ambari/view/ReadRequest.java
@@ -0,0 +1,39 @@
+/**
+ * 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.view;
+
+import java.util.Set;
+
+/**
+ * Information passed to a read request.
+ */
+public interface ReadRequest {
+ /**
+ * Get the requested property ids.
+ *
+ * @return the property ids
+ */
+ public Set<String> getPropertyIds();
+
+ /**
+ * Get the predicate.
+ *
+ * @return the predicate; may be null
+ */
+ public String getPredicate();
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/main/java/org/apache/ambari/view/ResourceAlreadyExistsException.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/ResourceAlreadyExistsException.java b/ambari-views/src/main/java/org/apache/ambari/view/ResourceAlreadyExistsException.java
new file mode 100644
index 0000000..1f53248
--- /dev/null
+++ b/ambari-views/src/main/java/org/apache/ambari/view/ResourceAlreadyExistsException.java
@@ -0,0 +1,48 @@
+/**
+ * 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.view;
+
+/**
+ * Indicates that a resource already exists.
+ */
+public class ResourceAlreadyExistsException extends Exception{
+ /**
+ * The resource id.
+ */
+ private final String resourceId;
+
+ /**
+ * Constructor.
+ *
+ * @param resourceId the resource id
+ */
+ public ResourceAlreadyExistsException(String resourceId) {
+ super("The resource " + resourceId +
+ " specified in the request already exists.");
+ this.resourceId = resourceId;
+ }
+
+ /**
+ * Get the id of the non-existent resource.
+ *
+ * @return the resource id
+ */
+ public String getResourceId() {
+ return resourceId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/main/java/org/apache/ambari/view/ResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/ResourceProvider.java b/ambari-views/src/main/java/org/apache/ambari/view/ResourceProvider.java
new file mode 100644
index 0000000..5ce989f
--- /dev/null
+++ b/ambari-views/src/main/java/org/apache/ambari/view/ResourceProvider.java
@@ -0,0 +1,103 @@
+/**
+ * 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.view;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Class used to access view sub-resources.
+ *
+ * @param <T> the type of the resource class provided by this ResourceProvider object.
+ */
+public interface ResourceProvider<T> {
+ /**
+ * Get a single resource from the given id. The resource should be
+ * populated with the given properties.
+ *
+ * @param resourceId the id of the requested resource
+ * @param properties the set of requested property ids
+ *
+ * @throws SystemException an internal system exception occurred
+ * @throws NoSuchResourceException a requested resource doesn't exist
+ * @throws UnsupportedPropertyException the request contains unsupported property ids
+ *
+ * @return the resource
+ */
+ public T getResource(String resourceId, Set<String> properties) throws
+ SystemException, NoSuchResourceException, UnsupportedPropertyException;
+
+ /**
+ * Get all of the resources. The resources should be populated with
+ * the given resources.
+ *
+ * @param request the read request
+ *
+ * @throws SystemException an internal system exception occurred
+ * @throws NoSuchResourceException a requested resource doesn't exist
+ * @throws UnsupportedPropertyException the request contains unsupported property ids
+ *
+ * @return a set containing all the resources
+ */
+ public Set<T> getResources(ReadRequest request) throws
+ SystemException, NoSuchResourceException, UnsupportedPropertyException;
+
+ /**
+ * Create a resource with the given id and given property values.
+ *
+ * @param resourceId the id of the requested resource
+ * @param properties the map of property values to set on the new resource
+ *
+ * @throws SystemException an internal system exception occurred
+ * @throws ResourceAlreadyExistsException attempted to create a resource which already exists
+ * @throws NoSuchResourceException a parent resource doesn't exist
+ * @throws UnsupportedPropertyException the request contains unsupported property ids
+ */
+ public void createResource(String resourceId, Map<String, Object> properties) throws
+ SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException;
+
+ /**
+ * Update the resource identified by given resource id with the given property values.
+ *
+ * @param resourceId the id of the requested resource
+ * @param properties the map of property values to update on the resource
+ *
+ * @throws SystemException an internal system exception occurred
+ * @throws NoSuchResourceException a requested resource doesn't exist
+ * @throws UnsupportedPropertyException the request contains unsupported property ids
+ *
+ * @return true if the resource was successfully updated
+ */
+ public boolean updateResource(String resourceId, Map<String, Object> properties) throws
+ SystemException, NoSuchResourceException, UnsupportedPropertyException;
+
+ /**
+ * Delete the resource identified by the given resource id.
+ *
+ * @param resourceId the id of the requested resource
+ *
+ * @throws SystemException an internal system exception occurred
+ * @throws NoSuchResourceException the resource instance to be deleted doesn't exist
+ * @throws UnsupportedPropertyException the request contains unsupported property ids
+ *
+ * @return true if the resource was successfully deleted
+ */
+ public boolean deleteResource(String resourceId) throws
+ SystemException, NoSuchResourceException, UnsupportedPropertyException;
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/main/java/org/apache/ambari/view/SystemException.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/SystemException.java b/ambari-views/src/main/java/org/apache/ambari/view/SystemException.java
new file mode 100644
index 0000000..4a38ef0
--- /dev/null
+++ b/ambari-views/src/main/java/org/apache/ambari/view/SystemException.java
@@ -0,0 +1,33 @@
+/**
+ * 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.view;
+
+/**
+ * Indicates that a system exception occurred.
+ */
+public class SystemException extends Exception {
+ /**
+ * Constructor.
+ *
+ * @param msg message
+ * @param throwable root exception
+ */
+ public SystemException(String msg, Throwable throwable) {
+ super(msg, throwable);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/main/java/org/apache/ambari/view/UnsupportedPropertyException.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/UnsupportedPropertyException.java b/ambari-views/src/main/java/org/apache/ambari/view/UnsupportedPropertyException.java
new file mode 100644
index 0000000..7db90eb
--- /dev/null
+++ b/ambari-views/src/main/java/org/apache/ambari/view/UnsupportedPropertyException.java
@@ -0,0 +1,70 @@
+/**
+ * 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.view;
+
+
+import java.util.Set;
+
+/**
+ * Thrown to indicate that the requested properties are not supported for the
+ * associated resource type.
+ */
+public class UnsupportedPropertyException extends Exception {
+ /**
+ * The resource type.
+ */
+ private final String type;
+
+ /**
+ * The unsupported property ids.
+ */
+ private final Set<String> propertyIds;
+
+ /**
+ * Construct an UnsupportedPropertyException.
+ *
+ * @param type the resource type
+ * @param propertyIds the unsupported property ids
+ */
+ public UnsupportedPropertyException(String type, Set<String> propertyIds) {
+ super("The properties " + propertyIds +
+ " specified in the request or predicate are not supported for the resource type " +
+ type + ".");
+ this.type = type;
+ this.propertyIds = propertyIds;
+ }
+
+ /**
+ * Get the resource type.
+ *
+ * @return the resource type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Get the unsupported property ids.
+ *
+ * @return the unsupported property ids
+ */
+ public Set<String> getPropertyIds() {
+ return propertyIds;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/main/java/org/apache/ambari/view/ViewContext.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/ViewContext.java b/ambari-views/src/main/java/org/apache/ambari/view/ViewContext.java
new file mode 100644
index 0000000..87f9a96
--- /dev/null
+++ b/ambari-views/src/main/java/org/apache/ambari/view/ViewContext.java
@@ -0,0 +1,65 @@
+/**
+ * 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.view;
+
+import java.util.Map;
+
+/**
+ * Context object available to the view components to provide access to
+ * the view and instance attributes as well as run time information about
+ * the current execution context.
+ */
+public interface ViewContext {
+ /**
+ * Get the current user name.
+ *
+ * @return the current user name
+ */
+ public String getUsername();
+
+ /**
+ * Get the view name.
+ *
+ * @return the view name
+ */
+ public String getViewName();
+
+ /**
+ * Get the view instance name.
+ *
+ * @return the view instance name
+ */
+ public String getInstanceName();
+
+ /**
+ * Get the property values specified to create the view instance.
+ *
+ * @return the view instance property values
+ */
+ public Map<String, String> getProperties();
+
+ /**
+ * Get the view resource provider for the given resource type.
+ *
+ * @param type the resource type
+ *
+ * @return the resource provider
+ */
+ public ResourceProvider<?> getResourceProvider(String type);
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/main/java/org/apache/ambari/view/ViewResourceHandler.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/ViewResourceHandler.java b/ambari-views/src/main/java/org/apache/ambari/view/ViewResourceHandler.java
new file mode 100644
index 0000000..22ed0f1
--- /dev/null
+++ b/ambari-views/src/main/java/org/apache/ambari/view/ViewResourceHandler.java
@@ -0,0 +1,41 @@
+/**
+ * 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.view;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * Handler object available to the view components used to allow
+ * the API framework to handle the request.
+ */
+public interface ViewResourceHandler {
+
+ /**
+ * Handle the API request.
+ *
+ * @param headers the headers
+ * @param ui the URI info
+ * @param resourceId the resource id; may be null for collection resources
+ *
+ * @return the response
+ */
+ public Response handleRequest(HttpHeaders headers, UriInfo ui, String resourceId);
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/test/java/org/apache/ambari/view/NoSuchResourceExceptionTest.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/test/java/org/apache/ambari/view/NoSuchResourceExceptionTest.java b/ambari-views/src/test/java/org/apache/ambari/view/NoSuchResourceExceptionTest.java
new file mode 100644
index 0000000..fc76282
--- /dev/null
+++ b/ambari-views/src/test/java/org/apache/ambari/view/NoSuchResourceExceptionTest.java
@@ -0,0 +1,32 @@
+/**
+ * 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.view;
+
+import org.junit.Assert;
+
+/**
+ * NoSuchResourceException tests.
+ */
+public class NoSuchResourceExceptionTest {
+ @org.junit.Test
+ public void testGetResourceId() throws Exception {
+ NoSuchResourceException exception = new NoSuchResourceException("id");
+ Assert.assertEquals("id", exception.getResourceId());
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/test/java/org/apache/ambari/view/ResourceAlreadyExistsExceptionTest.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/test/java/org/apache/ambari/view/ResourceAlreadyExistsExceptionTest.java b/ambari-views/src/test/java/org/apache/ambari/view/ResourceAlreadyExistsExceptionTest.java
new file mode 100644
index 0000000..f7f8dfd
--- /dev/null
+++ b/ambari-views/src/test/java/org/apache/ambari/view/ResourceAlreadyExistsExceptionTest.java
@@ -0,0 +1,33 @@
+/**
+ * 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.view;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * ResourceAlreadyExistsException tests.
+ */
+public class ResourceAlreadyExistsExceptionTest {
+ @Test
+ public void testGetResourceId() throws Exception {
+ ResourceAlreadyExistsException exception = new ResourceAlreadyExistsException("id");
+ Assert.assertEquals("id", exception.getResourceId());
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/ambari-views/src/test/java/org/apache/ambari/view/UnsupportedPropertyExceptionTest.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/test/java/org/apache/ambari/view/UnsupportedPropertyExceptionTest.java b/ambari-views/src/test/java/org/apache/ambari/view/UnsupportedPropertyExceptionTest.java
new file mode 100644
index 0000000..961ebe7
--- /dev/null
+++ b/ambari-views/src/test/java/org/apache/ambari/view/UnsupportedPropertyExceptionTest.java
@@ -0,0 +1,47 @@
+/**
+ * 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.view;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * UnsupportedPropertyException tests.
+ */
+public class UnsupportedPropertyExceptionTest {
+ @Test
+ public void testGetType() throws Exception {
+ UnsupportedPropertyException exception = new UnsupportedPropertyException("type", Collections.singleton("p1"));
+ Assert.assertEquals("type", exception.getType());
+ }
+
+ @Test
+ public void testGetPropertyIds() throws Exception {
+ Set<String> ids = new HashSet<String>();
+ ids.add("p1");
+ ids.add("p2");
+
+ UnsupportedPropertyException exception = new UnsupportedPropertyException("type", ids);
+ Assert.assertEquals(ids, exception.getPropertyIds());
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/89af4f19/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 811f129..33948b2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,6 +50,7 @@
<modules>
<module>ambari-web</module>
<module>ambari-project</module>
+ <module>ambari-views</module>
<module>ambari-server</module>
<module>ambari-agent</module>
<module>ambari-client</module>