Bläddra i källkod

AMBARI-20523. make home directory check as optional in hive view 1.5 (pallavkul)

pallavkul 8 år sedan
förälder
incheckning
0d29a3d5a5

+ 18 - 0
contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/HelpService.java

@@ -23,6 +23,9 @@ import org.apache.ambari.view.ViewResourceHandler;
 import org.apache.ambari.view.hive2.resources.files.FileService;
 import org.apache.ambari.view.hive2.resources.jobs.atsJobs.ATSParserFactory;
 import org.apache.ambari.view.hive2.resources.jobs.atsJobs.ATSRequestsDelegateImpl;
+import org.apache.ambari.view.hive2.utils.ServiceCheck;
+import org.apache.ambari.view.hive2.utils.ServiceFormattedException;
+import org.apache.ambari.view.utils.hdfs.HdfsApiException;
 import org.json.simple.JSONObject;
 
 import javax.inject.Inject;
@@ -108,6 +111,21 @@ public class HelpService extends BaseService {
     }
   }
 
+  @GET
+  @Path("/service-check-policy")
+  public Response getServiceCheckList(){
+    ServiceCheck serviceCheck = new ServiceCheck(context);
+    try {
+      ServiceCheck.Policy policy = serviceCheck.getServiceCheckPolicy();
+      JSONObject policyJson = new JSONObject();
+      policyJson.put("serviceCheckPolicy", policy);
+      return Response.ok(policyJson).build();
+    } catch (HdfsApiException e) {
+      LOG.error("Error occurred while generating service check policy : ", e);
+      throw new ServiceFormattedException(e);
+    }
+  }
+
   private Response getOKResponse() {
     JSONObject response = new JSONObject();
     response.put("message", "OK");

+ 25 - 0
contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/utils/Constants.java

@@ -0,0 +1,25 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hive2.utils;
+
+public interface Constants {
+  String VIEW_CONF_KEYVALUES = "view.conf.keyvalues";
+  String DEFAULT_FS = "fs.defaultFS";
+  String AMBARI_SKIP_HOME_DIRECTORY_CHECK_PROTOCOL_LIST = "views.skip.home-directory-check.file-system.list";
+}

+ 132 - 0
contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/utils/ServiceCheck.java

@@ -0,0 +1,132 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hive2.utils;
+
+import com.google.common.base.Optional;
+import org.apache.ambari.view.ViewContext;
+import org.apache.ambari.view.commons.hdfs.ViewPropertyHelper;
+import org.apache.ambari.view.utils.hdfs.ConfigurationBuilder;
+import org.apache.ambari.view.utils.hdfs.HdfsApiException;
+import org.apache.hadoop.conf.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.*;
+
+public class ServiceCheck {
+  protected static final Logger LOG = LoggerFactory.getLogger(ServiceCheck.class);
+
+  private final ViewContext viewContext;
+
+  public ServiceCheck(ViewContext viewContext){
+    this.viewContext = viewContext;
+  }
+
+  public static class Policy {
+    private boolean checkHdfs = true;
+    private boolean checkHomeDirectory = true;
+    private boolean checkHive = true;
+    private boolean checkATS = true;
+
+    public Policy() {
+    }
+
+    public Policy(boolean checkHdfs, boolean checkHomeDirectory, boolean checkHive, boolean checkATS) {
+      this.checkHdfs = checkHdfs;
+      this.checkHomeDirectory = checkHomeDirectory;
+      this.checkHive = checkHive;
+      this.checkATS = checkATS;
+    }
+
+    public boolean isCheckHdfs() {
+      return checkHdfs;
+    }
+
+    public void setCheckHdfs(boolean checkHdfs) {
+      this.checkHdfs = checkHdfs;
+    }
+
+    public boolean isCheckHomeDirectory() {
+      return checkHomeDirectory;
+    }
+
+    public void setCheckHomeDirectory(boolean checkHomeDirectory) {
+      this.checkHomeDirectory = checkHomeDirectory;
+    }
+
+    public boolean isCheckHive() {
+      return checkHive;
+    }
+
+    public void setCheckHive(boolean checkHive) {
+      this.checkHive = checkHive;
+    }
+
+    public boolean isCheckATS() {
+      return checkATS;
+    }
+
+    public void setCheckATS(boolean checkATS) {
+      this.checkATS = checkATS;
+    }
+
+    @Override
+    public String toString() {
+      return "Policy{" +
+        "checkHdfs=" + checkHdfs +
+        ", checkHomeDirectory=" + checkHomeDirectory +
+        ", checkHive=" + checkHive +
+        ", checkATS=" + checkATS +
+        '}';
+    }
+  }
+
+  public Policy getServiceCheckPolicy() throws HdfsApiException {
+    Policy policy = new Policy();
+    Optional<Map<String, String>> viewConfigs = ViewPropertyHelper.getViewConfigs(viewContext, Constants.VIEW_CONF_KEYVALUES);
+    ConfigurationBuilder configBuilder;
+    if(viewConfigs.isPresent()) {
+      configBuilder = new ConfigurationBuilder(this.viewContext, viewConfigs.get());
+    }else{
+      configBuilder = new ConfigurationBuilder(this.viewContext);
+    }
+
+    Configuration configurations = configBuilder.buildConfig();
+    String defaultFS = configurations.get(Constants.DEFAULT_FS);
+
+    URI fsUri = null;
+    try {
+      fsUri = new URI(defaultFS);
+      String protocol = fsUri.getScheme();
+      String ambariSkipCheckValues = viewContext.getAmbariProperty(Constants.AMBARI_SKIP_HOME_DIRECTORY_CHECK_PROTOCOL_LIST);
+      List<String> protocolSkipList = (ambariSkipCheckValues == null? new LinkedList<String>() : Arrays.asList(ambariSkipCheckValues.split(",")));
+      if(null != protocol && protocolSkipList.contains(protocol)){
+        policy.setCheckHomeDirectory(false);
+        return policy;
+      }
+    } catch (URISyntaxException e) {
+      LOG.error("Error occurred while parsing the defaultFS URI.", e);
+      return policy;
+    }
+
+    return policy;
+  }
+}

+ 47 - 0
contrib/views/hive-next/src/main/resources/ui/hive-web/app/adapters/service-check.js

@@ -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.
+ */
+
+import Ember from 'ember';
+import application from './application';
+
+export default application.extend({
+
+  buildServiceURL: function (path) {
+    return this.buildURL() + "/resources/hive/" + path;
+  },
+
+  fetchServiceCheckPolicy: function(){
+    return this.doGet("service-check-policy");
+  },
+
+  doGet : function(path,inputData){
+    var self = this;
+    return new Ember.RSVP.Promise(function(resolve,reject){
+      Ember.$.ajax({
+        url :  self.buildServiceURL(path),
+        type : 'get',
+        headers: self.get('headers'),
+        dataType : 'json'
+      }).done(function(data) {
+        resolve(data);
+      }).fail(function(error) {
+        reject(error);
+      });
+    });
+  },
+});

+ 22 - 3
contrib/views/hive-next/src/main/resources/ui/hive-web/app/controllers/splash.js

@@ -69,7 +69,7 @@ checkConnection: function() {
   startTests: function() {
 
     var model = this.get('model');
-    var url = this.container.lookup('adapter:application').buildURL() + '/resources/hive/'
+    var url = this.container.lookup('adapter:application').buildURL() + '/resources/hive/';
     var self = this;
 
     var processResponse = function(name, data) {
@@ -102,12 +102,31 @@ checkConnection: function() {
 
       model.set(name + 'TestDone', true);
       var percent = model.get('percent');
-      model.set('percent', percent + 25);
+      model.set('percent', percent + (100/model.get("numberOfChecks")));
     };
 
 
+    let checks = [];
+    if(model.get("serviceCheckPolicy").checkHdfs){
+      checks.push("hdfs");
+    }else{
+      model.set("hdfs" + 'TestDone', true);
+      model.set("hdfs" + 'Test', true);
+    }
+    if(model.get("serviceCheckPolicy").checkATS){
+      checks.push("ats");
+    }else{
+      model.set("ats" + 'TestDone', true);
+      model.set("ats" + 'Test', true);
+    }
+    if(model.get("serviceCheckPolicy").checkHomeDirectory){
+      checks.push("userhome");
+    }else{
+      model.set("userhome" + 'TestDone', true);
+      model.set("userhome" + 'Test', true);
+    }
 
-    var promises = ['hdfs', 'ats', 'userhome'].map(function(name) {
+    var promises = checks.map(function(name) {
 
       var finalurl =  url + name + 'Status' ;
 

+ 32 - 9
contrib/views/hive-next/src/main/resources/ui/hive-web/app/routes/splash.js

@@ -30,7 +30,9 @@ export default Ember.Route.extend({
       atsTestDone: null,
       userhomeTest: null,
       userhomeTestDone: null,
-      percent: 0
+      percent: 0,
+      numberOfChecks: null,
+      serviceCheckPolicy: null,
     });
   },
 
@@ -61,7 +63,7 @@ export default Ember.Route.extend({
         var percent = model.get('percent');
         model.set("hiveserverTest", true);
         model.set("hiveserver" + 'TestDone', true);
-        model.set('percent', percent + 25);
+        model.set('percent', percent + (100/model.get("numberOfChecks")));
         loadView();
       }, function () {
         if (model.get('ldapFailure')) {
@@ -71,7 +73,7 @@ export default Ember.Route.extend({
             controller.checkConnection().then(function () {
               model.set("hiveserverTest", true);
               model.set("hiveserver" + 'TestDone', true);
-              model.set('percent', percent + 25);
+              model.set('percent', percent + (100/model.get("numberOfChecks")));
               loadView();
             }, function () {
               var percent = model.get('percent');
@@ -82,25 +84,46 @@ export default Ember.Route.extend({
               controller.set("errors", errors);
               model.get("hiveserverTest", false);
               model.set("hiveserver" + 'TestDone', true);
-              model.set('percent', percent + 25);
+              model.set('percent', percent + (100/model.get("numberOfChecks")));
               loadView();
             });
           });
         } else {
           model.get("hiveserverTest", false);
           model.set("hiveserver" + 'TestDone', true);
-          model.set('percent', model.get('percent') + 25);
+          model.set('percent', model.get('percent') + (100/model.get("numberOfChecks")));
           loadView();
         }
       });
     }
 
-    controller.startTests().then(function() {
-      checkHive();
-    });
-
+    this.fetchServiceCheckPolicy()
+      .then((data) => {
+        let numberOfChecks = 0;
+        let serviceCheckPolicy = data.serviceCheckPolicy;
+        for (let serviceCheck in serviceCheckPolicy) {
+          if (serviceCheckPolicy[serviceCheck] === true) {
+            numberOfChecks++;
+          }
+        }
+        model.set("numberOfChecks", numberOfChecks);
+        model.set("serviceCheckPolicy", serviceCheckPolicy);
+        controller.startTests().then(function () {
+          if(serviceCheckPolicy.checkHive === true){
+            checkHive();
+          }else{
+            model.set("hiveserver" + 'TestDone', true);
+            model.set("hiveserver" + 'Test', true);
+            loadView();
+          }
+        });
+      });
   },
 
+  fetchServiceCheckPolicy: function(){
+    let adapter = this.container.lookup('adapter:service-check');
+    return adapter.fetchServiceCheckPolicy();
+  },
   actions: {
     transition: function() {
       this.transitionTo('index');

+ 10 - 0
contrib/views/hive-next/src/main/resources/ui/hive-web/app/templates/splash.hbs

@@ -36,6 +36,7 @@
 
   <table class="table">
     <tbody>
+    {{#if model.serviceCheckPolicy.checkHdfs}}
     <tr>
       <td>
         {{#if modelhdfsTestDone}}
@@ -50,6 +51,9 @@
       </td>
       <td>HDFS test</td>
     </tr>
+    {{/if}}
+
+    {{#if model.serviceCheckPolicy.checkHive}}
     <tr>
       <td>
         {{#if modelhiveserverTestDone}}
@@ -64,6 +68,9 @@
       </td>
       <td>HiveServer test</td>
     </tr>
+    {{/if}}
+
+    {{#if model.serviceCheckPolicy.checkATS}}
     <tr>
       <td>
         {{#if modelatsTestDone}}
@@ -78,7 +85,9 @@
       </td>
       <td>ATS test</td>
     </tr>
+    {{/if}}
 
+    {{#if model.serviceCheckPolicy.checkHomeDirectory}}
     <tr>
       <td>
         {{#if modeluserhomeTestDone}}
@@ -93,6 +102,7 @@
       </td>
       <td>User Home Directory test</td>
     </tr>
+    {{/if}}
 
     </tbody>
   </table>