/** * 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. */ /** * Contains helpful utilities for handling batch and scheduled requests. */ module.exports = { /** * Some services have components which have a need for rolling restarts. This * method returns the name of the host-component which supports rolling * restarts for a service. */ getRollingRestartComponentName : function(serviceName) { var rollingRestartComponent = null; switch (serviceName) { case 'HDFS': rollingRestartComponent = 'DATANODE'; break; case 'YARN': rollingRestartComponent = 'NODEMANAGER'; break; case 'MAPREDUCE': rollingRestartComponent = 'TASKTRACKER'; break; case 'HBASE': rollingRestartComponent = 'HBASE_REGIONSERVER'; break; case 'STORM': rollingRestartComponent = 'SUPERVISOR'; break; default: break; } return rollingRestartComponent; }, restartAllServiceHostComponents : function(serviceName, staleConfigsOnly) { var service = App.Service.find(serviceName); if (service) { var hostComponents = service.get('hostComponents') if (staleConfigsOnly) { hostComponents = hostComponents.filterProperty('staleConfigs', true); } this.restartHostComponents(hostComponents); } }, restartHostComponents : function(hostComponentsList) { var componentToHostsMap = {}; var componentToServiceMap = {}; hostComponentsList.forEach(function(hc) { var componentName = hc.get('componentName'); if (!componentToHostsMap[componentName]) { componentToHostsMap[componentName] = []; } componentToHostsMap[componentName].push(hc.get('host.hostName')); componentToServiceMap[componentName] = hc.get('service.serviceName'); }); for ( var componentName in componentToHostsMap) { var hosts = componentToHostsMap[componentName].join(","); var data = { serviceName : componentToServiceMap[componentName], componentName : componentName, hosts : hosts } var sender = { successFunction : function() { App.router.get('applicationController').dataLoading().done(function(initValue) { if (initValue) { App.router.get('backgroundOperationsController').showPopup(); } }); }, errorFunction : function(xhr, textStatus, error, opt) { App.ajax.defaultErrorHandler(xhr, opt.url, 'POST', xhr.status); } } App.ajax.send({ name : 'restart.service.hostComponents', sender : sender, data : data, success : 'successFunction', error : 'errorFunction' }); } }, /** * Makes a REST call to the server requesting the rolling restart of the * provided host components. */ _doPostBatchRollingRestartRequest : function(restartHostComponents, batchSize, intervalTimeSeconds, tolerateSize, successCallback, errorCallback) { var clusterName = App.get('clusterName'); var data = { restartHostComponents : restartHostComponents, batchSize : batchSize, intervalTimeSeconds : intervalTimeSeconds, tolerateSize : tolerateSize, clusterName : clusterName } var sender = { successFunction : function() { successCallback(); }, errorFunction : function(xhr, textStatus, error, opt) { errorCallback(xhr, textStatus, error, opt); } } App.ajax.send({ name : 'rolling_restart.post', sender : sender, data : data, success : 'successFunction', error : 'errorFunction' }); }, /** * Launches dialog to handle rolling restarts of host components. * * Rolling restart is supported for the following host components only *