ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alejan...@apache.org
Subject git commit: AMBARI-7719. Jobs View: /resources/status should provide view parameters (alejandro)
Date Tue, 14 Oct 2014 00:11:23 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-1.7.0 27d0867eb -> ee27729d8


AMBARI-7719. Jobs View: /resources/status should provide view parameters (alejandro)


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

Branch: refs/heads/branch-1.7.0
Commit: ee27729d8dae653c8808d96f7a36c8722792ded5
Parents: 27d0867
Author: Alejandro Fernandez <afernandez@hortonworks.com>
Authored: Mon Oct 13 17:09:59 2014 -0700
Committer: Alejandro Fernandez <afernandez@hortonworks.com>
Committed: Mon Oct 13 17:09:59 2014 -0700

----------------------------------------------------------------------
 contrib/views/jobs/pom.xml                      |  8 ++-
 .../apache/ambari/view/jobs/ViewController.java | 36 +++++++++++
 .../ambari/view/jobs/ViewControllerImpl.java    | 66 ++++++++++++++++++++
 .../org/apache/ambari/view/jobs/ViewStatus.java | 44 +++++++++++++
 .../view/jobs/rest/ViewStatusResource.java      | 46 ++++++++++++++
 contrib/views/jobs/src/main/resources/view.xml  |  5 ++
 6 files changed, 204 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ee27729d/contrib/views/jobs/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/views/jobs/pom.xml b/contrib/views/jobs/pom.xml
index f2173e3..5677c09 100644
--- a/contrib/views/jobs/pom.xml
+++ b/contrib/views/jobs/pom.xml
@@ -169,7 +169,7 @@
             </resource>
         </resources>
     </build>
-<dependencies>
+    <dependencies>
       <dependency>
         <groupId>org.apache.ambari</groupId>
         <artifactId>ambari-views</artifactId>
@@ -182,5 +182,11 @@
         <version>2.5</version>
         <scope>provided</scope>
       </dependency>
+
+      <dependency>
+        <groupId>com.google.inject</groupId>
+        <artifactId>guice</artifactId>
+      </dependency>
+
     </dependencies>
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/ee27729d/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewController.java
----------------------------------------------------------------------
diff --git a/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewController.java
b/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewController.java
new file mode 100644
index 0000000..508bc14
--- /dev/null
+++ b/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewController.java
@@ -0,0 +1,36 @@
+/**
+ * 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.jobs;
+
+import com.google.inject.ImplementedBy;
+
+/**
+ * Interface of controller to handle requests for the Jobs View.
+ */
+@ImplementedBy(ViewControllerImpl.class)
+public interface ViewController {
+
+  public static final String PARAM_YARN_ATS_URL = "yarn.ats.url";
+  public static final String PARAM_YARN_RESOURCEMANAGER_URL = "yarn.resourcemanager.url";
+
+  /**
+   * @return Get the properties that any user is allowed to see, even non-admin users.
+   */
+  public ViewStatus getViewStatus();
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/ee27729d/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewControllerImpl.java
----------------------------------------------------------------------
diff --git a/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewControllerImpl.java
b/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewControllerImpl.java
new file mode 100644
index 0000000..de2e94e
--- /dev/null
+++ b/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewControllerImpl.java
@@ -0,0 +1,66 @@
+/**
+ * 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.jobs;
+
+import java.lang.String;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.view.ViewContext;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/**
+ * Implementation of controller to handle requests for the Jobs View.
+ */
+@Singleton
+public class ViewControllerImpl implements ViewController {
+
+  @Inject
+  private ViewContext viewContext;
+
+  /**
+   * Because only an admin user is allowed to see the properties in
+   * api/v1/views/JOBS/versions/{version_number}/instances/{instance_name}/ ,
+   * we need a way for all users to see the basic properties of the Jobs View, primarily
+   * the YARN ATS URL and YARN Resource Manager URL
+   * @return Get the properties that any user is allowed to see, even non-admin users.
+   */
+  @Override
+  public ViewStatus getViewStatus() {
+    ViewStatus status = new ViewStatus();
+    Map<String, String> parameters = new HashMap<String, String>();
+    parameters.put(ViewController.PARAM_YARN_ATS_URL, getViewParameterValue(ViewController.PARAM_YARN_ATS_URL));
+    parameters.put(ViewController.PARAM_YARN_RESOURCEMANAGER_URL, getViewParameterValue(ViewController.PARAM_YARN_RESOURCEMANAGER_URL));
+    status.setParameters(parameters);
+    return status;
+  }
+
+  /**
+   * @param parameterName Parameter to get the value for
+   * @return Returns the value of the given parameter
+   */
+  private String getViewParameterValue(String parameterName) {
+    String value = viewContext.getProperties().get(parameterName);
+    if ("null".equals(value)) {
+      return null;
+    }
+    return value;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/ee27729d/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewStatus.java
----------------------------------------------------------------------
diff --git a/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewStatus.java
b/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewStatus.java
new file mode 100644
index 0000000..7d9fa95
--- /dev/null
+++ b/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/ViewStatus.java
@@ -0,0 +1,44 @@
+/**
+ * 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.jobs;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Class to represent the public-facing properties of the Jobs View that any user is allowed
to see.
+ */
+public class ViewStatus {
+
+  private Map<String, String> parameters = new HashMap<String, String>();
+
+  /**
+   * @return Get all of the public properties
+   */
+  public Map<String, String> getParameters() {
+    return parameters;
+  }
+
+  /**
+   * @param parameters Parameters to save
+   */
+  public void setParameters(Map<String, String> parameters) {
+    this.parameters = parameters;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/ee27729d/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/rest/ViewStatusResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/rest/ViewStatusResource.java
b/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/rest/ViewStatusResource.java
new file mode 100644
index 0000000..402955e
--- /dev/null
+++ b/contrib/views/jobs/src/main/java/org/apache/ambari/view/jobs/rest/ViewStatusResource.java
@@ -0,0 +1,46 @@
+/**
+ * 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.jobs.rest;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.ambari.view.jobs.ViewController;
+import org.apache.ambari.view.jobs.ViewStatus;
+
+import com.google.inject.Inject;
+
+/**
+ * Resource that exposes the status (mainly public properties) of the Jobs View.
+ */
+public class ViewStatusResource {
+
+	@Inject
+	ViewController controller;
+
+  /**
+   * @return Get the properties that any user is allowed to see, even non-admin users.
+   */
+	@GET
+	@Produces({ MediaType.APPLICATION_JSON })
+	public ViewStatus getViewStatus() {
+		return controller.getViewStatus();
+	}
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/ee27729d/contrib/views/jobs/src/main/resources/view.xml
----------------------------------------------------------------------
diff --git a/contrib/views/jobs/src/main/resources/view.xml b/contrib/views/jobs/src/main/resources/view.xml
index 6dd5ee6..a17d06d 100644
--- a/contrib/views/jobs/src/main/resources/view.xml
+++ b/contrib/views/jobs/src/main/resources/view.xml
@@ -28,4 +28,9 @@ limitations under the License. Kerberos, LDAP, Custom. Binary/Htt
       <description>The URL to the YARN ResourceManager, used to provide YARN Application
data. For example: http://yarn.resourcemanager.address:8088</description>
       <required>true</required>
   </parameter>
+  <!-- The status resource exists to show the subset of properties that any user is allowed
to see, not just an admin user. -->
+  <resource>
+    <name>status</name>
+    <service-class>org.apache.ambari.view.jobs.rest.ViewStatusResource</service-class>
+  </resource>
 </view>


Mime
View raw message