Skip to content

Commit

Permalink
Merge pull request apache#2710 from atkach/AMBARI-25032-trunk
Browse files Browse the repository at this point in the history
AMBARI-25032 Cover Service controllers with unit tests
  • Loading branch information
atkach authored Dec 11, 2018
2 parents 47882ab + 86936b9 commit a9153f1
Show file tree
Hide file tree
Showing 4 changed files with 1,062 additions and 187 deletions.
46 changes: 24 additions & 22 deletions ambari-web/app/controllers/main/service/add_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,11 @@ App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, {
* @param stepController App.WizardStep5Controller
*/
saveMasterComponentHosts: function (stepController) {
var obj = stepController.get('selectedServicesMasters');
var masterComponentHosts = [];
var installedComponents = App.HostComponent.find();
var installedComponentsMap = App.HostComponent.find().toMapByProperty('componentName');

obj.forEach(function (_component) {
var installedComponent = installedComponents.findProperty('componentName', _component.component_name);
stepController.get('selectedServicesMasters').forEach(function (_component) {
var installedComponent = installedComponentsMap[_component.component_name];
masterComponentHosts.push({
display_name: _component.display_name,
component: _component.component_name,
Expand All @@ -252,7 +251,7 @@ App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, {
this.setDBProperty('masterComponentHosts', masterComponentHosts);
this.set('content.masterComponentHosts', masterComponentHosts);

this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
this.set('content.skipMasterStep', masterComponentHosts.everyProperty('isInstalled', true));
this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
},

Expand Down Expand Up @@ -287,8 +286,11 @@ App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, {
*/
skipConfigStep: function () {
var skipConfigStep = true;
var selectedServices = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
selectedServices.map(function (serviceName) {
this.get('content.services')
.filterProperty('isSelected', true)
.filterProperty('isInstalled', false)
.mapProperty('serviceName')
.map(function (serviceName) {
skipConfigStep = skipConfigStep && this.isServiceNotConfigurable(serviceName);
}, this);
return skipConfigStep;
Expand Down Expand Up @@ -368,9 +370,12 @@ App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, {
*/
saveClients: function () {
var clients = [];
var serviceComponents = App.StackServiceComponent.find();
this.get('content.services').filterProperty('isSelected').filterProperty('isInstalled',false).forEach(function (_service) {
var serviceClients = serviceComponents.filterProperty('serviceName', _service.get('serviceName')).filterProperty('isClient');
var clientComponents = App.StackServiceComponent.find().filterProperty('isClient');
this.get('content.services')
.filterProperty('isSelected')
.filterProperty('isInstalled', false)
.forEach(function (_service) {
var serviceClients = clientComponents.filterProperty('serviceName', _service.get('serviceName'));
serviceClients.forEach(function (client) {
clients.push({
component_name: client.get('componentName'),
Expand Down Expand Up @@ -440,10 +445,9 @@ App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, {
* @method installServices
*/
installServices: function (callback) {
var self = this;
this.set('content.cluster.oldRequestsId', []);
this.installAdditionalClients().done(function () {
self.installSelectedServices(callback);
this.installAdditionalClients().done(() => {
this.installSelectedServices(callback);
});
},

Expand All @@ -453,11 +457,10 @@ App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, {
* @method installSelectedServices
*/
installSelectedServices: function (callback) {
var name = 'common.services.update';
var selectedServices = this.get('content.services').filterProperty('isInstalled', false).filterProperty('isSelected', true).mapProperty('serviceName');
var selectedServices = this.get('content.services').filterProperty('isInstalled', false).filterProperty('isSelected').mapProperty('serviceName');
var dependentServices = this.getServicesBySelectedSlaves();
var data = this.generateDataForInstallServices(selectedServices.concat(dependentServices));
this.installServicesRequest(name, data, callback.bind(this));
this.installServicesRequest('common.services.update', data, callback.bind(this));
},

installServicesRequest: function (name, data, callback) {
Expand All @@ -476,11 +479,11 @@ App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, {
* @returns {Array}
*/
getServicesBySelectedSlaves: function () {
var result = [];
const result = [];
this.get('content.slaveComponentHosts').forEach(function (slaveComponent) {
if (slaveComponent.hosts.someProperty('isInstalled', false)) {
var stackComponent = App.StackServiceComponent.find().findProperty('componentName', slaveComponent.componentName);
if (stackComponent) {
const stackComponent = App.StackServiceComponent.find(slaveComponent.componentName);
if (stackComponent.get('isLoaded')) {
result.push(stackComponent.get('serviceName'));
}
}
Expand All @@ -497,14 +500,13 @@ App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, {
var dfd = $.Deferred();
var count = 0;
if (this.get('content.additionalClients.length') > 0) {
this.get('content.additionalClients').forEach(function (c) {
this.get('content.additionalClients').forEach((c) => {
if (c.hostNames.length > 0) {
var queryStr = 'HostRoles/component_name='+ c.componentName + '&HostRoles/host_name.in(' + c.hostNames.join() + ')';
this.get('installClietsQueue').addRequest({
name: 'common.host_component.update',
sender: this,
data: {
query: queryStr,
query: 'HostRoles/component_name='+ c.componentName + '&HostRoles/host_name.in(' + c.hostNames.join() + ')',
context: 'Install ' + App.format.role(c.componentName, false),
HostRoles: {
state: 'INSTALLED'
Expand Down
135 changes: 65 additions & 70 deletions ambari-web/app/controllers/main/service/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,8 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow
startStopPopupSuccessCallback: function (data, ajaxOptions, params) {
if (data && data.Requests) {
params.query.set('status', 'SUCCESS');
if (App.get('testMode')) {
const requestData = JSON.parse(ajaxOptions.data),
state = requestData.Body.ServiceInfo.state || requestData.Body.HostRoles.state,
config = this.get('callBackConfig')[state];
this.set('content.workStatus', App.Service.Health[config.f]);
this.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.f]);
setTimeout(() => {
this.set('content.workStatus', App.Service.Health[config.c2]);
this.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.hs]);
}, App.get('testModeDelayForActions'));
}
// load data (if we need to show this background operations popup) from persist
App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
App.router.get('userSettingsController').dataLoading('show_bg').done((initValue) => {
if (initValue) {
App.router.get('backgroundOperationsController').showPopup();
}
Expand Down Expand Up @@ -356,33 +345,8 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow
if (nameNodesWithOldCheckpoints.length) {
// too old
this.getHdfsUser().done(() => {
const maxAge = App.nnCheckpointAgeAlertThreshold,
hdfsUser = this.get('hdfsUser'),
confirmButton = Em.I18n.t('common.next');
let msg;
if (App.get('hasNameNodeFederation') && !groupName) {
const oldCheckpointNameSpacesList = nameNodesWithOldCheckpoints.map(nn => `<li>${nn.haNameSpace}</li>`),
nameSpacesString = `<ul>${oldCheckpointNameSpacesList.join('')}</ul>`,
hostNamesList = nameNodesWithOldCheckpoints.map(nn => `<b>${nn.hostName}</b>`).join(', ');
msg = Em.Object.create({
confirmMsg: Em.I18n.t('services.service.stop.HDFS.warningMsg.nameSpaces.checkPointTooOld').format(maxAge) +
nameSpacesString +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.makeSure') +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.instructions.multipleHosts.login').format(hostNamesList) +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.instructions').format(hdfsUser),
confirmButton
})
} else {
const hostName = nameNodesWithOldCheckpoints[0].hostName;
msg = Em.Object.create({
confirmMsg: Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld').format(maxAge) +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.makeSure') +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.instructions.singleHost.login').format(hostName) +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.instructions').format(hdfsUser),
confirmButton
})
}
return App.showConfirmationFeedBackPopup(callback, msg);
const message = this.getMessageForOldCheckpoints(groupName, nameNodesWithOldCheckpoints);
return App.showConfirmationFeedBackPopup(callback, message);
});
} else if (isNameNodeCheckpointUnavailable) {
// not available
Expand All @@ -396,6 +360,40 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow
}
});
},

/**
*
* @param {string} groupName
* @param {Array} nameNodesWithOldCheckpoints
* @return {Em.Object}
*/
getMessageForOldCheckpoints: function(groupName, nameNodesWithOldCheckpoints) {
const maxAge = App.nnCheckpointAgeAlertThreshold,
hdfsUser = this.get('hdfsUser'),
confirmButton = Em.I18n.t('common.next');
if (App.get('hasNameNodeFederation') && !groupName) {
const oldCheckpointNameSpacesList = nameNodesWithOldCheckpoints.map(nn => `<li>${nn.haNameSpace}</li>`),
nameSpacesString = `<ul>${oldCheckpointNameSpacesList.join('')}</ul>`,
hostNamesList = nameNodesWithOldCheckpoints.map(nn => `<b>${nn.hostName}</b>`).join(', ');
return Em.Object.create({
confirmMsg: Em.I18n.t('services.service.stop.HDFS.warningMsg.nameSpaces.checkPointTooOld').format(maxAge) +
nameSpacesString +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.makeSure') +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.instructions.multipleHosts.login').format(hostNamesList) +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.instructions').format(hdfsUser),
confirmButton
});
} else {
const hostName = nameNodesWithOldCheckpoints[0].hostName;
return Em.Object.create({
confirmMsg: Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld').format(maxAge) +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.makeSure') +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.instructions.singleHost.login').format(hostName) +
Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.instructions').format(hdfsUser),
confirmButton
});
}
},

pullNnCheckPointTime: function (haNameSpace) {
let clusterIdValue;
Expand Down Expand Up @@ -641,35 +639,32 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow
},
/**
* On click handler for Yarn Refresh Queues command from items menu
* @param event
*/
refreshYarnQueues : function (event) {
var controller = this;
var hosts = App.Service.find('YARN').get('hostComponents').filterProperty('componentName', 'RESOURCEMANAGER').mapProperty('hostName');
return App.showConfirmationPopup(function() {
App.ajax.send({
name : 'service.item.refreshQueueYarnRequest',
sender: controller,
data : {
command : "REFRESHQUEUES",
context : Em.I18n.t('services.service.actions.run.yarnRefreshQueues.context') ,
hosts : hosts.join(','),
serviceName : "YARN",
componentName : "RESOURCEMANAGER",
forceRefreshConfigTags : "capacity-scheduler"
},
success : 'refreshYarnQueuesSuccessCallback',
error : 'refreshYarnQueuesErrorCallback',
showLoadingPopup: true
});
});
},
refreshYarnQueuesSuccessCallback : function(data, ajaxOptions, params) {
refreshYarnQueues : function () {
return App.showConfirmationPopup(() => {
App.ajax.send({
name: 'service.item.refreshQueueYarnRequest',
sender: this,
data: {
command: "REFRESHQUEUES",
context: Em.I18n.t('services.service.actions.run.yarnRefreshQueues.context'),
hosts: App.MasterComponent.find('RESOURCEMANAGER').get('hostNames').join(','),
serviceName: "YARN",
componentName: "RESOURCEMANAGER",
forceRefreshConfigTags: "capacity-scheduler"
},
success: 'refreshYarnQueuesSuccessCallback',
error: 'refreshYarnQueuesErrorCallback',
showLoadingPopup: true
});
});
},
refreshYarnQueuesSuccessCallback: function(data, ajaxOptions, params) {
if (data.Requests.id) {
App.router.get('backgroundOperationsController').showPopup();
}
},
refreshYarnQueuesErrorCallback : function(data) {
refreshYarnQueuesErrorCallback: function(data) {
var error = Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error');
if(data && data.responseText){
try {
Expand All @@ -689,11 +684,11 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow
var context = Em.I18n.t('services.service.actions.run.stopLdapKnox.context');
this.startStopLdapKnox('STOPDEMOLDAP',context);
},

startStopLdapKnox: function(command,context) {
startStopLdapKnox: function (command, context) {
var controller = this;
var host = App.HostComponent.find().findProperty('componentName', 'KNOX_GATEWAY').get('hostName');
return App.showConfirmationPopup(function() {
return App.showConfirmationPopup(() => {
App.ajax.send({
name: 'service.item.startStopLdapKnox',
sender: controller,
Expand Down Expand Up @@ -731,7 +726,7 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow
var isRefreshQueueRequired, self = this;
return App.showConfirmationPopup(function () {
// regresh queue request is sending only if YARN service has stale configs
isRefreshQueueRequired = App.Service.find().findProperty('serviceName', 'YARN').get('isRestartRequired');
isRefreshQueueRequired = App.Service.find('YARN').get('isRestartRequired');
if (isRefreshQueueRequired) {
self.restartLLAPAndRefreshQueueRequest();
} else {
Expand Down Expand Up @@ -759,8 +754,8 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow
},

restartLLAPAndRefreshQueueRequest: function () {
var hiveServerInteractiveHost = App.HostComponent.find().findProperty('componentName', 'HIVE_SERVER_INTERACTIVE').get('hostName');
var resourceManagerHost = App.HostComponent.find().findProperty('componentName', 'RESOURCEMANAGER').get('hostName');
var hiveServerInteractiveHost = App.MasterComponent.find('HIVE_SERVER_INTERACTIVE').get('hostNames')[0];
var resourceManagerHost = App.MasterComponent.find('RESOURCEMANAGER').get('hostNames')[0];
var batches = [{
"order_id": 1,
"type": "POST",
Expand Down Expand Up @@ -909,7 +904,7 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow
},

regenerateKeytabFileOperationsRequestError: function () {
App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('alerts.notifications.regenerateKeytab.service.error').format(this.content.get('serviceName')));
App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('alerts.notifications.regenerateKeytab.service.error').format(this.get('content.serviceName')));
},
/**
* On click callback for <code>run compaction</code> button
Expand Down
Loading

0 comments on commit a9153f1

Please sign in to comment.