Tom Beerbower created AMBARI-4517:
-------------------------------------

             Summary: Allow for external resources in Ambari Views
                 Key: AMBARI-4517
                 URL: https://issues.apache.org/jira/browse/AMBARI-4517
             Project: Ambari
          Issue Type: Task
            Reporter: Tom Beerbower
            Assignee: Tom Beerbower


Currently a view developer can specify resources for a view.  The resource 
plugs into the Ambari API framework and is exposed through a user defined 
service and resource adapter.
For example ...
{code}
    <resource>
        <name>file</name>
        <plural-name>files</plural-name>
        <id-property>id</id-property>
        
<resource-class>org.apache.ambari.view.explorer.FileResource</resource-class>
        
<provider-class>org.apache.ambari.view.explorer.FileResourceProvider</provider-class>
        
<service-class>org.apache.ambari.view.explorer.FileService</service-class>
    </resource>
{code}

The resources will be available through an instance of the view in the API.  In 
this case the files resources are listed under 'files' in the API response.  
Navigating to an individual resource under files will go through the 
framework's resource provider to satisfy the request for a file resource ...

{code}
{
  "href" : 
"http://c6401.ambari.apache.org:8080/api/v1/views/JAR_EXPLORER/instances/EXPLORER_JAR";,
  "ViewInstanceInfo" : {
    "instance_name" : "EXPLORER_JAR",
    "view_name" : "JAR_EXPLORER",
    "properties" : {
      "path" : "/vagrant/jar-explorer-view-0.9.0.jar"
    },
    "servlet_mappings" : {
      "ExplorerServlet" : "/views/JAR_EXPLORER/EXPLORER_JAR/ui"
    }
  },
  "files" : [
    {
      "href" : 
"http://c6401.ambari.apache.org:8080/api/v1/views/JAR_EXPLORER/instances/EXPLORER_JAR/files/META-INF_MANIFEST.MF";,
      "id" : "META-INF_MANIFEST.MF",
      "instance_name" : "EXPLORER_JAR",
      "view_name" : "JAR_EXPLORER"
    },
    {
      "href" : 
"http://c6401.ambari.apache.org:8080/api/v1/views/JAR_EXPLORER/instances/EXPLORER_JAR/files/META-INF_maven_org.apache.ambari_jar-explorer-view_pom.properties";,
      "id" : 
"META-INF_maven_org.apache.ambari_jar-explorer-view_pom.properties",
      "instance_name" : "EXPLORER_JAR",
      "view_name" : "JAR_EXPLORER"
    },
...
{code}


There are cases where the view developer may want to expose a resource more 
directly through the service and bypass the framework and resource adapter.  

For example ...

{code}
    <resource>
        <name>proxy</name>
        
<service-class>org.apache.ambari.view.proxy.ProxyAPIService</service-class>
    </resource>
{code}

In this case there is no resource provider.  The service definition is free to 
handle the request any way it pleases.  These external (outside of the 
framework) resources will still be linked to from the view API but will be 
serviced entirely by the defined service ...

{code}
{
  "href" : 
"http://c6401.ambari.apache.org:8080/api/v1/views/PROXY_API/instances/HW_DEFAULT_URL";,
  "ViewInstanceInfo" : {
    "instance_name" : "HW_DEFAULT_URL",
    "view_name" : "PROXY_API",
    "properties" : {
      "defaultURL" : "http://hortonworks.com/";
    },
    "servlet_mappings" : { }
  },
  "resources" : [
    {
      "href" : 
"http://c6401.ambari.apache.org:8080/api/v1/views/PROXY_API/instances/HW_DEFAULT_URL/resources/proxy";,
      "instance_name" : "HW_DEFAULT_URL",
      "name" : "proxy",
      "view_name" : "PROXY_API"
    }
  ]
}
{code}

The endpoint '/resources/proxy' will be serviced by the defined service 
(ProxyAPIService in this example) ...

{code}
public class ProxyAPIService {
  @Inject
  ViewContext context;

...

  @GET
  @Produces({"text/plain", "application/json"})
  public Response getResources(@Context HttpHeaders headers, @Context UriInfo 
ui) throws IOException{
    // Handle the request 
    ...
    return Response.ok(...).build();
  }
{code}





--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to