Repository: ambari Updated Branches: refs/heads/branch-2.5 685cc5456 -> 0d29a3d5a
AMBARI-20523. make home directory check as optional in hive view 1.5 (pallavkul) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0d29a3d5 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0d29a3d5 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0d29a3d5 Branch: refs/heads/branch-2.5 Commit: 0d29a3d5a51579502fe4c2863fb9a42146aaca61 Parents: 685cc54 Author: pallavkul <[email protected]> Authored: Wed Mar 22 22:42:51 2017 +0530 Committer: pallavkul <[email protected]> Committed: Wed Mar 22 22:44:36 2017 +0530 ---------------------------------------------------------------------- .../apache/ambari/view/hive2/HelpService.java | 18 +++ .../ambari/view/hive2/utils/Constants.java | 25 ++++ .../ambari/view/hive2/utils/ServiceCheck.java | 132 +++++++++++++++++++ .../ui/hive-web/app/adapters/service-check.js | 47 +++++++ .../ui/hive-web/app/controllers/splash.js | 25 +++- .../resources/ui/hive-web/app/routes/splash.js | 41 ++++-- .../ui/hive-web/app/templates/splash.hbs | 10 ++ 7 files changed, 286 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/0d29a3d5/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/HelpService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/HelpService.java b/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/HelpService.java index afc2939..ec01739 100644 --- a/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/HelpService.java +++ b/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"); http://git-wip-us.apache.org/repos/asf/ambari/blob/0d29a3d5/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/utils/Constants.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/utils/Constants.java b/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/utils/Constants.java new file mode 100644 index 0000000..b373002 --- /dev/null +++ b/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"; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/0d29a3d5/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/utils/ServiceCheck.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/utils/ServiceCheck.java b/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/utils/ServiceCheck.java new file mode 100644 index 0000000..6e6ade3 --- /dev/null +++ b/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; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/0d29a3d5/contrib/views/hive-next/src/main/resources/ui/hive-web/app/adapters/service-check.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive-next/src/main/resources/ui/hive-web/app/adapters/service-check.js b/contrib/views/hive-next/src/main/resources/ui/hive-web/app/adapters/service-check.js new file mode 100644 index 0000000..a2c2c44 --- /dev/null +++ b/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); + }); + }); + }, +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/0d29a3d5/contrib/views/hive-next/src/main/resources/ui/hive-web/app/controllers/splash.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive-next/src/main/resources/ui/hive-web/app/controllers/splash.js b/contrib/views/hive-next/src/main/resources/ui/hive-web/app/controllers/splash.js index 1bf6d42..423a0e3 100644 --- a/contrib/views/hive-next/src/main/resources/ui/hive-web/app/controllers/splash.js +++ b/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' ; http://git-wip-us.apache.org/repos/asf/ambari/blob/0d29a3d5/contrib/views/hive-next/src/main/resources/ui/hive-web/app/routes/splash.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive-next/src/main/resources/ui/hive-web/app/routes/splash.js b/contrib/views/hive-next/src/main/resources/ui/hive-web/app/routes/splash.js index 179a912..7e35340 100644 --- a/contrib/views/hive-next/src/main/resources/ui/hive-web/app/routes/splash.js +++ b/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'); http://git-wip-us.apache.org/repos/asf/ambari/blob/0d29a3d5/contrib/views/hive-next/src/main/resources/ui/hive-web/app/templates/splash.hbs ---------------------------------------------------------------------- diff --git a/contrib/views/hive-next/src/main/resources/ui/hive-web/app/templates/splash.hbs b/contrib/views/hive-next/src/main/resources/ui/hive-web/app/templates/splash.hbs index 5612542..f8d706d 100644 --- a/contrib/views/hive-next/src/main/resources/ui/hive-web/app/templates/splash.hbs +++ b/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>
