ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject [1/2] AMBARI-4461 - Application Views Infrastructure and allowing new views and API extensibility - framework
Date Wed, 29 Jan 2014 19:40:14 GMT
Updated Branches:
  refs/heads/trunk ea420ff9c -> a0a10fc5a


http://git-wip-us.apache.org/repos/asf/ambari/blob/a0a10fc5/ambari-server/src/main/java/org/apache/ambari/server/view/ViewSubResourceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewSubResourceDefinition.java b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewSubResourceDefinition.java
new file mode 100644
index 0000000..9ea6eb0
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewSubResourceDefinition.java
@@ -0,0 +1,101 @@
+/**
+ * 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;
+
+import org.apache.ambari.server.api.resources.BaseResourceDefinition;
+import org.apache.ambari.server.api.resources.SubResourceDefinition;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.view.configuration.ResourceConfig;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * View sub-resource definition based on a view resource configuration.
+ */
+public class ViewSubResourceDefinition extends BaseResourceDefinition {
+  /**
+   * The associated view definition.
+   */
+  private final ViewDefinition viewDefinition;
+
+  /**
+   * The configuration.
+   */
+  private final ResourceConfig resourceConfiguration;
+
+  /**
+   * The sub resource definitions.
+   */
+  Set<SubResourceDefinition> definitions;
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Construct a sub-resource definition.
+   *
+   * @param viewDefinition         the view definition
+   * @param resourceConfiguration  the resource configuration
+   */
+  public ViewSubResourceDefinition(ViewDefinition viewDefinition, ResourceConfig resourceConfiguration) {
+    super(new Resource.Type(getQualifiedResourceTypeName(viewDefinition.getName(), resourceConfiguration.getName())));
+
+    this.viewDefinition        = viewDefinition;
+    this.resourceConfiguration = resourceConfiguration;
+  }
+
+
+  // ----- ResourceDefinition ------------------------------------------------
+
+  @Override
+  public String getPluralName() {
+    return resourceConfiguration.getPluralName();
+  }
+
+  @Override
+  public String getSingularName() {
+    return resourceConfiguration.getName();
+  }
+
+  @Override
+  public synchronized Set<SubResourceDefinition> getSubResourceDefinitions() {
+    if (definitions == null) {
+      definitions = new HashSet<SubResourceDefinition>();
+      List<String> subResourceNames = resourceConfiguration.getSubResourceNames();
+      if (subResourceNames != null) {
+        for (String subType : subResourceNames) {
+          Resource.Type type = Resource.Type.valueOf(
+              getQualifiedResourceTypeName(viewDefinition.getName(), subType));
+          definitions.add(new SubResourceDefinition(type));
+        }
+      }
+    }
+    return definitions;
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  // qualify the resource type name with the view name
+  private static String getQualifiedResourceTypeName(String viewName, String resourceTypeName) {
+    return viewName + "/" + resourceTypeName;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a0a10fc5/ambari-server/src/main/java/org/apache/ambari/server/view/ViewSubResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewSubResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewSubResourceProvider.java
new file mode 100644
index 0000000..9a275d3
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewSubResourceProvider.java
@@ -0,0 +1,338 @@
+/**
+ * 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;
+
+import org.apache.ambari.server.controller.internal.AbstractResourceProvider;
+import org.apache.ambari.server.controller.internal.RequestStatusImpl;
+import org.apache.ambari.server.controller.internal.ResourceImpl;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.view.ReadRequest;
+
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * An SPI resource provider implementation used to adapt a
+ * view resource provider to the SPI interfaces for view
+ * sub-resources.
+ */
+public class ViewSubResourceProvider extends AbstractResourceProvider {
+
+  private static final String VIEW_NAME_PROPERTY_ID = "view_name";
+  private static final String INSTANCE_NAME_PROPERTY_ID = "instance_name";
+
+  private final ViewDefinition viewDefinition;
+  private final String pkField;
+  private final Resource.Type type;
+  private final Map<String, PropertyDescriptor> descriptorMap;
+
+  private final Set<String> pkPropertyIds;
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Construct a view resource provider for the given resource type and bean class.
+   *
+   * @param type            the resource type
+   * @param clazz           the resource bean class
+   * @param pkField         the primary key field name
+   * @param viewDefinition  the associated view definition
+   *
+   * @throws IntrospectionException if an exception occurs during introspection of the resource bean class
+   */
+  public ViewSubResourceProvider(Resource.Type type, Class<?> clazz, String pkField, ViewDefinition viewDefinition)
+      throws IntrospectionException {
+
+    super(discoverPropertyIds(clazz), getKeyPropertyIds(pkField, type));
+    this.pkField        = pkField;
+    this.viewDefinition = viewDefinition;
+    this.pkPropertyIds  = new HashSet<String>(getKeyPropertyIds().values());
+    this.type           = type;
+    this.descriptorMap  = getDescriptorMap(clazz);
+  }
+
+
+  // ----- ResourceProvider --------------------------------------------------
+
+  @Override
+  public RequestStatus createResources(Request request)
+      throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
+
+    Set<Map<String, Object>> properties = request.getProperties();
+
+    for (Map<String, Object> propertyMap : properties) {
+      String resourceId   = (String) propertyMap.get(pkField);
+      String instanceName = (String) propertyMap.get(INSTANCE_NAME_PROPERTY_ID);
+
+      try {
+        getResourceProvider(instanceName).createResource(resourceId, propertyMap);
+      } catch (org.apache.ambari.view.NoSuchResourceException e) {
+        throw new NoSuchParentResourceException(e.getMessage(), e);
+      } catch (org.apache.ambari.view.UnsupportedPropertyException e) {
+        throw new UnsupportedPropertyException(getResourceType(e), e.getPropertyIds());
+      } catch (org.apache.ambari.view.ResourceAlreadyExistsException e) {
+        throw new ResourceAlreadyExistsException(e.getMessage());
+      } catch (Exception e) {
+        throw new SystemException(e.getMessage(), e);
+      }
+    }
+    return new RequestStatusImpl(null);
+  }
+
+  @Override
+  public Set<Resource> getResources(Request request, Predicate predicate)
+      throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+
+    Set<String> requestedIds = getRequestPropertyIds(request, predicate);
+
+    Set<ViewInstanceDefinition> instanceDefinitions = new HashSet<ViewInstanceDefinition>();
+
+    try {
+
+      Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
+      int size = propertyMaps.size();
+
+      Collection<ViewInstanceDefinition> viewInstanceDefinitions = viewDefinition.getInstanceDefinitions();
+      if (size == 0) {
+        instanceDefinitions.addAll(viewInstanceDefinitions);
+      } else {
+        for (Map<String, Object> propertyMap : propertyMaps) {
+          String instanceName = (String) propertyMap.get(INSTANCE_NAME_PROPERTY_ID);
+          if (size == 1 && instanceName != null) {
+            String resourceId = (String) propertyMap.get(pkField);
+            if (resourceId != null) {
+              Object bean = getResourceProvider(instanceName).getResource(resourceId, requestedIds);
+              return Collections.singleton(getResource(bean, viewDefinition.getName(), instanceName, requestedIds));
+            }
+          }
+          if (instanceName == null) {
+            instanceDefinitions.addAll(viewInstanceDefinitions);
+            break;
+          } else {
+            instanceDefinitions.add(viewDefinition.getInstanceDefinition(instanceName));
+          }
+        }
+      }
+
+      Set<Resource> results = new HashSet<Resource>();
+      ReadRequest readRequest = new ViewReadRequest(requestedIds, predicate == null ? "" : predicate.toString());
+      for (ViewInstanceDefinition instanceDefinition : instanceDefinitions) {
+
+        Set<?> beans = instanceDefinition.getResourceProvider(type).getResources(readRequest);
+
+        for (Object bean : beans) {
+          Resource resource = getResource(bean, viewDefinition.getName(), instanceDefinition.getName(), requestedIds);
+          if (predicate.evaluate(resource)) {
+            results.add(resource);
+          }
+        }
+      }
+      return results;
+    } catch (org.apache.ambari.view.NoSuchResourceException e) {
+      throw new NoSuchParentResourceException(e.getMessage(), e);
+    } catch (org.apache.ambari.view.UnsupportedPropertyException e) {
+      throw new UnsupportedPropertyException(getResourceType(e), e.getPropertyIds());
+    } catch (Exception e) {
+      throw new SystemException(e.getMessage(), e);
+    }
+  }
+
+  @Override
+  public RequestStatus updateResources(Request request, Predicate predicate)
+      throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+    Iterator<Map<String,Object>> iterator = request.getProperties().iterator();
+
+    if (iterator.hasNext()) {
+      Map<String,Object> propertyMap = iterator.next();
+      Set<Resource>      resources   = getResources(request, predicate);
+
+      for (Resource resource : resources) {
+        String resourceId   = (String) resource.getPropertyValue(pkField);
+        String instanceName = (String) resource.getPropertyValue(INSTANCE_NAME_PROPERTY_ID);
+
+        try {
+          getResourceProvider(instanceName).updateResource(resourceId, propertyMap);
+        } catch (org.apache.ambari.view.NoSuchResourceException e) {
+          throw new NoSuchParentResourceException(e.getMessage(), e);
+        } catch (org.apache.ambari.view.UnsupportedPropertyException e) {
+          throw new UnsupportedPropertyException(getResourceType(e), e.getPropertyIds());
+        } catch (Exception e) {
+          throw new SystemException(e.getMessage(), e);
+        }
+      }
+    }
+    return new RequestStatusImpl(null);
+  }
+
+  @Override
+  public RequestStatus deleteResources(Predicate predicate)
+      throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+
+    Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate);
+    for (Resource resource : resources) {
+      String resourceId   = (String) resource.getPropertyValue(pkField);
+      String instanceName = (String) resource.getPropertyValue(INSTANCE_NAME_PROPERTY_ID);
+
+      try {
+        getResourceProvider(instanceName).deleteResource(resourceId);
+      } catch (org.apache.ambari.view.NoSuchResourceException e) {
+        throw new NoSuchParentResourceException(e.getMessage(), e);
+      } catch (org.apache.ambari.view.UnsupportedPropertyException e) {
+        throw new UnsupportedPropertyException(getResourceType(e), e.getPropertyIds());
+      } catch (Exception e) {
+        throw new SystemException(e.getMessage(), e);
+      }
+    }
+    return new RequestStatusImpl(null);
+  }
+
+  @Override
+  protected Set<String> getPKPropertyIds() {
+    return pkPropertyIds;
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  // get a Resource from the bean
+  private Resource getResource(Object bean, String viewName, String instanceName, Set<String> requestedIds)
+      throws InvocationTargetException, IllegalAccessException {
+
+    Resource resource = new ResourceImpl(type);
+
+    resource.setProperty(VIEW_NAME_PROPERTY_ID, viewName);
+    resource.setProperty(INSTANCE_NAME_PROPERTY_ID, instanceName);
+
+    for (Map.Entry<String, PropertyDescriptor> entry : descriptorMap.entrySet()) {
+      Object value = entry.getValue().getReadMethod().invoke(bean);
+
+      setResourceProperty(resource, entry.getKey(), value, requestedIds);
+    }
+    return resource;
+  }
+
+  // get the resource provider associated with the given instance name for this resource type
+  private org.apache.ambari.view.ResourceProvider<?> getResourceProvider(String instanceName) {
+    return viewDefinition.getInstanceDefinition(instanceName).getResourceProvider(type);
+  }
+
+  // get the resource type associated with the given UnsupportedPropertyException
+  private Resource.Type getResourceType(org.apache.ambari.view.UnsupportedPropertyException e) {
+    Resource.Type type = Resource.Type.valueOf(e.getType());
+    return type == null ? this.type : type;
+  }
+
+  // discover the property ids for the given bean class
+  private static Set<String> discoverPropertyIds(Class<?> clazz) throws IntrospectionException {
+    Set<String> propertyIds = new HashSet<String>(getDescriptorMap(clazz).keySet());
+    propertyIds.add(INSTANCE_NAME_PROPERTY_ID);
+    propertyIds.add("view_name");
+
+    return propertyIds;
+  }
+
+  // get a descriptor map for the given bean class
+  private static Map<String, PropertyDescriptor> getDescriptorMap(Class<?> clazz) throws IntrospectionException {
+    Map<String, PropertyDescriptor> descriptorMap = new HashMap<String, PropertyDescriptor>();
+
+    for (PropertyDescriptor pd : Introspector.getBeanInfo(clazz).getPropertyDescriptors()) {
+      String name = pd.getName();
+      if (pd.getReadMethod() != null && !name.equals("class")) {
+        descriptorMap.put(name, pd);
+      }
+    }
+    return descriptorMap;
+  }
+
+  // get the key property ids for the resource
+  private static Map<Resource.Type, String> getKeyPropertyIds(String pkField, Resource.Type type) {
+
+    Map<Resource.Type, String> keyPropertyIds = new HashMap<Resource.Type, String>();
+
+    keyPropertyIds.put(Resource.Type.View, VIEW_NAME_PROPERTY_ID);
+    keyPropertyIds.put(Resource.Type.ViewInstance, INSTANCE_NAME_PROPERTY_ID);
+    keyPropertyIds.put(type, pkField);
+
+    return keyPropertyIds;
+  }
+
+
+  // ----- inner class : ViewReadRequest -------------------------------------
+
+  /**
+   * A read request to pass the the view resource provider.
+   */
+  private static class ViewReadRequest implements ReadRequest {
+    /**
+     * The property ids of the request.
+     */
+    private final Set<String> propertyIds;
+
+    /**
+     * The request predicate.
+     */
+    private final String predicate;
+
+
+    // ----- Constructors ----------------------------------------------------
+
+    /**
+     * Construct a view read request.
+     *
+     * @param propertyIds  the property ids
+     * @param predicate    the predicate
+     */
+    private ViewReadRequest(Set<String> propertyIds, String predicate) {
+      this.propertyIds = propertyIds;
+      this.predicate = predicate;
+    }
+
+
+    // ----- ReadRequest -----------------------------------------------------
+
+    @Override
+    public Set<String> getPropertyIds() {
+      return propertyIds;
+    }
+
+    @Override
+    public String getPredicate() {
+      return predicate;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a0a10fc5/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ViewInstanceResourceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ViewInstanceResourceDefinitionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ViewInstanceResourceDefinitionTest.java
new file mode 100644
index 0000000..e1feaad
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ViewInstanceResourceDefinitionTest.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.server.api.resources;
+
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * ViewInstanceResourceDefinition tests.
+ */
+public class ViewInstanceResourceDefinitionTest {
+  @Test
+  public void testGetPluralName() throws Exception {
+    ViewInstanceResourceDefinition viewInstanceResourceDefinition = getViewInstanceResourceDefinition();
+    Assert.assertEquals("instances", viewInstanceResourceDefinition.getPluralName());
+  }
+
+  @Test
+  public void testGetSingularName() throws Exception {
+    ViewInstanceResourceDefinition viewInstanceResourceDefinition = getViewInstanceResourceDefinition();
+    Assert.assertEquals("instance", viewInstanceResourceDefinition.getSingularName());
+  }
+
+  @Test
+  public void testGetSubResourceDefinitions() throws Exception {
+    ViewInstanceResourceDefinition viewInstanceResourceDefinition = getViewInstanceResourceDefinition();
+    Set<SubResourceDefinition> subResourceDefinitions = viewInstanceResourceDefinition.getSubResourceDefinitions();
+
+    Assert.assertEquals(2, subResourceDefinitions.size());
+
+    for (SubResourceDefinition subResourceDefinition : subResourceDefinitions) {
+      Resource.Type type = subResourceDefinition.getType();
+      Assert.assertTrue(type.name().equals("sub1") || type.name().equals("sub2"));
+    }
+  }
+
+  public static ViewInstanceResourceDefinition getViewInstanceResourceDefinition() {
+    Set<SubResourceDefinition> subResourceDefinitions = new HashSet<SubResourceDefinition>();
+
+    subResourceDefinitions.add(new SubResourceDefinition(new Resource.Type("sub1")));
+    subResourceDefinitions.add(new SubResourceDefinition(new Resource.Type("sub2")));
+
+    return new ViewInstanceResourceDefinition(subResourceDefinitions);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a0a10fc5/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ViewResourceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ViewResourceDefinitionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ViewResourceDefinitionTest.java
new file mode 100644
index 0000000..4da48d6
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ViewResourceDefinitionTest.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.api.resources;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Set;
+
+/**
+ * ViewResourceDefinition tests.
+ */
+public class ViewResourceDefinitionTest {
+  @Test
+  public void testGetPluralName() throws Exception {
+    ViewResourceDefinition viewResourceDefinition = new ViewResourceDefinition();
+    Assert.assertEquals("views", viewResourceDefinition.getPluralName());
+  }
+
+  @Test
+  public void testGetSingularName() throws Exception {
+    ViewResourceDefinition viewResourceDefinition = new ViewResourceDefinition();
+    Assert.assertEquals("view", viewResourceDefinition.getSingularName());
+  }
+
+  @Test
+  public void testGetSubResourceDefinitions() throws Exception {
+    ViewResourceDefinition viewResourceDefinition = new ViewResourceDefinition();
+    Set<SubResourceDefinition> subResourceDefinitions = viewResourceDefinition.getSubResourceDefinitions ();
+
+    Assert.assertEquals(1, subResourceDefinitions.size());
+
+    Assert.assertEquals("ViewInstance", subResourceDefinitions.iterator().next().getType().name());
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a0a10fc5/ambari-server/src/test/java/org/apache/ambari/server/view/ViewContextImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewContextImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewContextImplTest.java
new file mode 100644
index 0000000..7422393
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewContextImplTest.java
@@ -0,0 +1,92 @@
+/**
+ * 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;
+
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.view.configuration.InstanceConfig;
+import org.apache.ambari.server.view.configuration.InstanceConfigTest;
+import org.apache.ambari.view.ResourceProvider;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.easymock.EasyMock.createNiceMock;
+
+/**
+ * ViewContextImpl tests.
+ */
+public class ViewContextImplTest {
+  @Test
+  public void testGetViewName() throws Exception {
+    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
+    ViewDefinition viewDefinition = ViewDefinitionTest.getViewDefinition();
+    ViewInstanceDefinition viewInstanceDefinition = new ViewInstanceDefinition(viewDefinition, instanceConfig);
+
+    ViewContextImpl viewContext = new ViewContextImpl(viewInstanceDefinition);
+
+    Assert.assertEquals("MY_VIEW", viewContext.getViewName());
+  }
+
+  @Test
+  public void testGetInstanceName() throws Exception {
+    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
+    ViewDefinition viewDefinition = ViewDefinitionTest.getViewDefinition();
+    ViewInstanceDefinition viewInstanceDefinition = new ViewInstanceDefinition(viewDefinition, instanceConfig);
+
+    ViewContextImpl viewContext = new ViewContextImpl(viewInstanceDefinition);
+
+    Assert.assertEquals("INSTANCE1", viewContext.getInstanceName());
+  }
+
+  @Test
+  public void testGetProperties() throws Exception {
+    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
+    ViewDefinition viewDefinition = ViewDefinitionTest.getViewDefinition();
+    ViewInstanceDefinition viewInstanceDefinition = new ViewInstanceDefinition(viewDefinition, instanceConfig);
+    viewInstanceDefinition.addProperty("p1", "v1");
+    viewInstanceDefinition.addProperty("p2", "v2");
+    viewInstanceDefinition.addProperty("p3", "v3");
+
+    ViewContextImpl viewContext = new ViewContextImpl(viewInstanceDefinition);
+
+    Map<String, String> properties = viewContext.getProperties();
+    Assert.assertEquals(3, properties.size());
+
+    Assert.assertEquals("v1", properties.get("p1"));
+    Assert.assertEquals("v2", properties.get("p2"));
+    Assert.assertEquals("v3", properties.get("p3"));
+  }
+
+  @Test
+  public void testGetResourceProvider() throws Exception {
+    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
+    ViewDefinition viewDefinition = ViewDefinitionTest.getViewDefinition();
+    ViewInstanceDefinition viewInstanceDefinition = new ViewInstanceDefinition(viewDefinition, instanceConfig);
+
+    ResourceProvider provider = createNiceMock(ResourceProvider.class);
+    Resource.Type type = new Resource.Type("MY_VIEW/myType");
+
+    viewInstanceDefinition.addResourceProvider(type, provider);
+
+    ViewContextImpl viewContext = new ViewContextImpl(viewInstanceDefinition);
+
+    Assert.assertEquals(provider, viewContext.getResourceProvider("myType"));
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a0a10fc5/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDefinitionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDefinitionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDefinitionTest.java
new file mode 100644
index 0000000..22a03ad
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDefinitionTest.java
@@ -0,0 +1,155 @@
+/**
+ * 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;
+
+import org.apache.ambari.server.api.resources.BaseResourceDefinition;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.view.configuration.ResourceConfig;
+import org.apache.ambari.server.view.configuration.ResourceConfigTest;
+import org.apache.ambari.server.view.configuration.ViewConfig;
+import org.apache.ambari.server.view.configuration.ViewConfigTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Set;
+
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * ViewDefinition tests.
+ */
+public class ViewDefinitionTest {
+
+  public static ViewDefinition getViewDefinition() throws Exception {
+    return new ViewDefinition(ViewConfigTest.getConfig());
+  }
+
+  public static ViewDefinition getViewDefinition(ViewConfig config) throws Exception {
+    return new ViewDefinition(config);
+  }
+
+  @Test
+  public void testGetName() throws Exception {
+    ViewDefinition viewDefinition = getViewDefinition();
+    Assert.assertEquals("MY_VIEW", viewDefinition.getName());
+  }
+
+  @Test
+  public void testGetLabel() throws Exception {
+    ViewDefinition viewDefinition = getViewDefinition();
+    Assert.assertEquals("My View!", viewDefinition.getLabel());
+  }
+
+  @Test
+  public void testGetVersion() throws Exception {
+    ViewDefinition viewDefinition = getViewDefinition();
+    Assert.assertEquals("1.0.0", viewDefinition.getVersion());
+  }
+
+  @Test
+  public void testGetConfiguration() throws Exception {
+    ViewConfig viewConfig = ViewConfigTest.getConfig();
+    ViewDefinition viewDefinition = getViewDefinition(viewConfig);
+    Assert.assertEquals(viewConfig, viewDefinition.getConfiguration());
+  }
+
+  @Test
+  public void testAddGetResourceProvider() throws Exception {
+    ViewDefinition viewDefinition = getViewDefinition();
+
+    ResourceProvider provider = createNiceMock(ResourceProvider.class);
+
+    Resource.Type type = new Resource.Type("myType");
+    viewDefinition.addResourceProvider(type, provider);
+
+    Assert.assertEquals(provider, viewDefinition.getResourceProvider(type));
+  }
+
+  @Test
+  public void testAddGetResourceDefinition() throws Exception {
+    ViewDefinition viewDefinition = getViewDefinition();
+
+    BaseResourceDefinition definition = createNiceMock(BaseResourceDefinition.class);
+    Resource.Type type = new Resource.Type("myType");
+
+    expect(definition.getType()).andReturn(type);
+
+    replay(definition);
+
+    viewDefinition.addResourceDefinition(definition);
+
+    Assert.assertEquals(definition, viewDefinition.getResourceDefinition(type));
+
+    verify(definition);
+  }
+
+  @Test
+  public void testAddGetResourceConfiguration() throws Exception {
+    ViewDefinition viewDefinition = getViewDefinition();
+
+    ResourceConfig config = ResourceConfigTest.getResourceConfigs().get(0);
+
+    Resource.Type type1 = new Resource.Type("myType");
+
+    viewDefinition.addResourceConfiguration(type1, config);
+
+    Assert.assertEquals(config, viewDefinition.getResourceConfigurations().get(type1));
+
+    Resource.Type type2 = new Resource.Type("myType2");
+
+    viewDefinition.addResourceConfiguration(type2, config);
+
+    Assert.assertEquals(config, viewDefinition.getResourceConfigurations().get(type2));
+
+    Set<Resource.Type> types = viewDefinition.getViewResourceTypes();
+
+    Assert.assertEquals(2, types.size());
+
+    Assert.assertTrue(types.contains(type1));
+    Assert.assertTrue(types.contains(type2));
+  }
+
+  @Test
+  public void testAddGetInstanceDefinition() throws Exception {
+    ViewDefinition viewDefinition = getViewDefinition();
+
+    ViewInstanceDefinition definition = createNiceMock(ViewInstanceDefinition.class);
+
+    expect(definition.getName()).andReturn("instance1");
+
+    replay(definition);
+
+    viewDefinition.addInstanceDefinition(definition);
+
+    Assert.assertEquals(definition, viewDefinition.getInstanceDefinition("instance1"));
+
+    Collection<ViewInstanceDefinition> definitions = viewDefinition.getInstanceDefinitions();
+
+    Assert.assertEquals(1, definitions.size());
+
+    Assert.assertTrue(definitions.contains(definition));
+
+    verify(definition);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a0a10fc5/ambari-server/src/test/java/org/apache/ambari/server/view/ViewInstanceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewInstanceDefinitionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewInstanceDefinitionTest.java
new file mode 100644
index 0000000..6df3e1e
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewInstanceDefinitionTest.java
@@ -0,0 +1,127 @@
+/**
+ * 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;
+
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.view.configuration.InstanceConfig;
+import org.apache.ambari.server.view.configuration.InstanceConfigTest;
+import org.apache.ambari.view.ResourceProvider;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.easymock.EasyMock.createNiceMock;
+
+/**
+ * ViewInstanceDefinition tests.
+ */
+public class ViewInstanceDefinitionTest {
+  @Test
+  public void testGetViewDefinition() throws Exception {
+    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
+    ViewDefinition viewDefinition = ViewDefinitionTest.getViewDefinition();
+    ViewInstanceDefinition viewInstanceDefinition = new ViewInstanceDefinition(viewDefinition, instanceConfig);
+
+    Assert.assertEquals(viewDefinition, viewInstanceDefinition.getViewDefinition());
+  }
+
+  @Test
+  public void testGetConfiguration() throws Exception {
+    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
+    ViewDefinition viewDefinition = ViewDefinitionTest.getViewDefinition();
+    ViewInstanceDefinition viewInstanceDefinition = new ViewInstanceDefinition(viewDefinition, instanceConfig);
+
+    Assert.assertEquals(instanceConfig, viewInstanceDefinition.getConfiguration());
+  }
+
+  @Test
+  public void testGetName() throws Exception {
+    ViewInstanceDefinition viewInstanceDefinition = getViewInstanceDefinition();
+
+    Assert.assertEquals("INSTANCE1", viewInstanceDefinition.getName());
+  }
+
+  @Test
+  public void testAddGetServletMapping() throws Exception {
+    ViewInstanceDefinition viewInstanceDefinition = getViewInstanceDefinition();
+
+    viewInstanceDefinition.addServletMapping("Servlet1", "path1");
+    viewInstanceDefinition.addServletMapping("Servlet2", "path2");
+
+    Map<String, String> mappings = viewInstanceDefinition.getServletMappings();
+
+    Assert.assertEquals(2, mappings.size());
+
+    Assert.assertEquals("path1", mappings.get("Servlet1"));
+    Assert.assertEquals("path2", mappings.get("Servlet2"));
+  }
+
+  @Test
+  public void testAddGetProperty() throws Exception {
+    ViewInstanceDefinition viewInstanceDefinition = getViewInstanceDefinition();
+
+    viewInstanceDefinition.addProperty("p1", "v1");
+    viewInstanceDefinition.addProperty("p2", "v2");
+    viewInstanceDefinition.addProperty("p3", "v3");
+
+    Map<String, String> properties = viewInstanceDefinition.getProperties();
+
+    Assert.assertEquals(3, properties.size());
+
+    Assert.assertEquals("v1", properties.get("p1"));
+    Assert.assertEquals("v2", properties.get("p2"));
+    Assert.assertEquals("v3", properties.get("p3"));
+  }
+
+  @Test
+  public void testAddGetService() throws Exception {
+    ViewInstanceDefinition viewInstanceDefinition = getViewInstanceDefinition();
+
+    Object service = new Object();
+
+    viewInstanceDefinition.addService("resources", service);
+
+    Object service2 = new Object();
+
+    viewInstanceDefinition.addService("subresources", service2);
+
+    Assert.assertEquals(service, viewInstanceDefinition.getService("resources"));
+    Assert.assertEquals(service2, viewInstanceDefinition.getService("subresources"));
+  }
+
+  @Test
+  public void testAddGetResourceProvider() throws Exception {
+    ViewInstanceDefinition viewInstanceDefinition = getViewInstanceDefinition();
+
+    ResourceProvider provider = createNiceMock(ResourceProvider.class);
+    Resource.Type type = new Resource.Type("MY_VIEW/myType");
+
+    viewInstanceDefinition.addResourceProvider(type, provider);
+
+    Assert.assertEquals(provider, viewInstanceDefinition.getResourceProvider(type));
+    Assert.assertEquals(provider, viewInstanceDefinition.getResourceProvider("myType"));
+  }
+
+  public static ViewInstanceDefinition getViewInstanceDefinition() throws Exception {
+    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
+    ViewDefinition viewDefinition = ViewDefinitionTest.getViewDefinition();
+    return new ViewInstanceDefinition(viewDefinition, instanceConfig);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a0a10fc5/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
new file mode 100644
index 0000000..754727d
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.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;
+
+import org.apache.ambari.server.api.resources.SubResourceDefinition;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.view.configuration.ResourceConfig;
+import org.apache.ambari.server.view.configuration.ResourceConfigTest;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * ViewRegistry tests.
+ */
+public class ViewRegistryTest {
+  @Test
+  public void testAddGetDefinitions() throws Exception {
+    ViewDefinition viewDefinition = ViewDefinitionTest.getViewDefinition();
+
+    ViewRegistry registry = ViewRegistry.getInstance();
+
+    registry.addDefinition(viewDefinition);
+
+    Assert.assertEquals(viewDefinition, registry.getDefinition("MY_VIEW"));
+
+    Collection<ViewDefinition> viewDefinitions = registry.getDefinitions();
+
+    Assert.assertEquals(1, viewDefinitions.size());
+
+    Assert.assertEquals(viewDefinition, viewDefinitions.iterator().next());
+  }
+
+  @Test
+  public void testAddGetInstanceDefinitions() throws Exception {
+    ViewDefinition viewDefinition = ViewDefinitionTest.getViewDefinition();
+    ViewInstanceDefinition viewInstanceDefinition = ViewInstanceDefinitionTest.getViewInstanceDefinition();
+
+    ViewRegistry registry = ViewRegistry.getInstance();
+
+    registry.addDefinition(viewDefinition);
+
+    registry.addInstanceDefinition(viewDefinition, viewInstanceDefinition);
+
+    Assert.assertEquals(viewInstanceDefinition, registry.getInstanceDefinition("MY_VIEW", "INSTANCE1"));
+
+    Collection<ViewInstanceDefinition> viewInstanceDefinitions = registry.getInstanceDefinitions(viewDefinition);
+
+    Assert.assertEquals(1, viewInstanceDefinitions.size());
+
+    Assert.assertEquals(viewInstanceDefinition, viewInstanceDefinitions.iterator().next());
+  }
+
+  @Test
+  public void testGetSubResourceDefinitions() throws Exception {
+    ViewDefinition viewDefinition = ViewDefinitionTest.getViewDefinition();
+    ViewRegistry registry = ViewRegistry.getInstance();
+
+    ResourceConfig config = ResourceConfigTest.getResourceConfigs().get(0);
+    Resource.Type type1 = new Resource.Type("myType");
+
+    viewDefinition.addResourceConfiguration(type1, config);
+    registry.addDefinition(viewDefinition);
+    Set<SubResourceDefinition> subResourceDefinitions = registry.getSubResourceDefinitions("MY_VIEW");
+
+    Assert.assertEquals(1, subResourceDefinitions.size());
+    Assert.assertEquals("myType", subResourceDefinitions.iterator().next().getType().name());
+  }
+
+  @Before
+  public void before() throws Exception {
+    ViewRegistry.getInstance().clear();
+  }
+
+  @AfterClass
+  public static void afterClass() {
+    ViewRegistry.getInstance().clear();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a0a10fc5/ambari-server/src/test/java/org/apache/ambari/server/view/ViewSubResourceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewSubResourceDefinitionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewSubResourceDefinitionTest.java
new file mode 100644
index 0000000..5b1b4d3
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewSubResourceDefinitionTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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;
+
+import org.apache.ambari.server.api.resources.SubResourceDefinition;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.view.configuration.ResourceConfig;
+import org.apache.ambari.server.view.configuration.ResourceConfigTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Set;
+
+/**
+ * ViewSubResourceDefinition tests.
+ */
+public class ViewSubResourceDefinitionTest {
+  @Test
+  public void testGetPluralName() throws Exception {
+    ViewSubResourceDefinition viewSubResourceDefinition = getViewSubResourceDefinition();
+
+    Assert.assertEquals("resources", viewSubResourceDefinition.getPluralName());
+  }
+
+  @Test
+  public void testGetSingularName() throws Exception {
+    ViewSubResourceDefinition viewSubResourceDefinition = getViewSubResourceDefinition();
+
+    Assert.assertEquals("resource", viewSubResourceDefinition.getSingularName());
+  }
+
+  @Test
+  public void testGetSubResourceDefinitions() throws Exception {
+    ViewSubResourceDefinition viewSubResourceDefinition = getViewSubResourceDefinition();
+
+    new Resource.Type("MY_VIEW/resource");
+    new Resource.Type("MY_VIEW/subresource");
+
+    Set<SubResourceDefinition> subResourceDefinitions = viewSubResourceDefinition.getSubResourceDefinitions ();
+
+    Assert.assertEquals(1, subResourceDefinitions.size());
+
+    Assert.assertEquals("MY_VIEW/subresource", subResourceDefinitions.iterator().next().getType().name());
+  }
+
+  public static ViewSubResourceDefinition getViewSubResourceDefinition() throws Exception {
+    ViewDefinition viewDefinition = ViewDefinitionTest.getViewDefinition();
+    ResourceConfig resourceConfig = ResourceConfigTest.getResourceConfigs().get(0);
+
+    return new ViewSubResourceDefinition(viewDefinition, resourceConfig);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a0a10fc5/ambari-views/src/main/java/org/apache/ambari/view/URLStreamProvider.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/URLStreamProvider.java b/ambari-views/src/main/java/org/apache/ambari/view/URLStreamProvider.java
new file mode 100644
index 0000000..78c9d12
--- /dev/null
+++ b/ambari-views/src/main/java/org/apache/ambari/view/URLStreamProvider.java
@@ -0,0 +1,40 @@
+/**
+ * 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.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Provider of a URL stream.
+ */
+public interface URLStreamProvider {
+  /**
+   * Read from the input stream specified by the given URL spec.
+   *
+   * @param spec           the String to parse as a URL
+   * @param requestMethod  the HTTP method (GET,POST,PUT,etc.).
+   * @param params         the body of the request; may be null
+   *
+   * @return the input stream
+   *
+   * @throws IOException if an error occurred connecting to the server
+   */
+  public InputStream readFrom(String spec, String requestMethod, String params) throws IOException;
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a0a10fc5/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
index 87f9a96..37bf6d5 100644
--- a/ambari-views/src/main/java/org/apache/ambari/view/ViewContext.java
+++ b/ambari-views/src/main/java/org/apache/ambari/view/ViewContext.java
@@ -62,4 +62,11 @@ public interface ViewContext {
    * @return the resource provider
    */
   public ResourceProvider<?> getResourceProvider(String type);
+
+  /**
+   * Get a URL stream provider.
+   *
+   * @return a stream provider
+   */
+  public URLStreamProvider getURLStreamProvider();
 }


Mime
View raw message