Browse Source

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

Alejandro Fernandez 10 years ago
parent
commit
6cf98ff4ab

+ 7 - 1
contrib/views/jobs/pom.xml

@@ -169,7 +169,7 @@
             </resource>
             </resource>
         </resources>
         </resources>
     </build>
     </build>
-<dependencies>
+    <dependencies>
       <dependency>
       <dependency>
         <groupId>org.apache.ambari</groupId>
         <groupId>org.apache.ambari</groupId>
         <artifactId>ambari-views</artifactId>
         <artifactId>ambari-views</artifactId>
@@ -182,5 +182,11 @@
         <version>2.5</version>
         <version>2.5</version>
         <scope>provided</scope>
         <scope>provided</scope>
       </dependency>
       </dependency>
+
+      <dependency>
+        <groupId>com.google.inject</groupId>
+        <artifactId>guice</artifactId>
+      </dependency>
+
     </dependencies>
     </dependencies>
 </project>
 </project>

+ 36 - 0
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();
+}

+ 66 - 0
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;
+  }
+}

+ 44 - 0
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;
+  }
+}

+ 46 - 0
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();
+	}
+}

+ 5 - 0
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>
       <description>The URL to the YARN ResourceManager, used to provide YARN Application data. For example: http://yarn.resourcemanager.address:8088</description>
       <required>true</required>
       <required>true</required>
   </parameter>
   </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>
 </view>