123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- /**
- * 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.
- */
- var App = require('app');
- App.WidgetWizardController = App.WizardController.extend({
- name: 'widgetWizardController',
- totalSteps: 3,
- /**
- * Used for hiding back button in wizard
- */
- hideBackButton: true,
- content: Em.Object.create({
- controllerName: 'widgetWizardController',
- widgetService: null,
- widgetType: "",
- /**
- * @type {number}
- * @default null
- */
- layoutId: null,
- /**
- * Example:
- * {
- * "display_unit": "%",
- * "warning_threshold": 70,
- * "error_threshold": 90
- * }
- */
- widgetProperties: {},
- /**
- * Example:
- * [{
- * widget_id: "metrics/rpc/closeRegion_num_ops",
- * name: "rpc.rpc.closeRegion_num_ops",
- * pointInTime: true,
- * temporal: true,
- * category: "default"
- * serviceName: "HBASE"
- * componentName: "HBASE_CLIENT"
- * type: "GANGLIA"//or JMX
- * level: "COMPONENT"//or HOSTCOMPONENT
- * }]
- * @type {Array}
- */
- allMetrics: [],
- /**
- * Example:
- * [{
- * "name": "regionserver.Server.percentFilesLocal",
- * "serviceName": "HBASE",
- * "componentName": "HBASE_REGIONSERVER"
- * }]
- */
- widgetMetrics: [],
- /**
- * Example:
- * [{
- * "name": "Files Local",
- * "value": "${regionserver.Server.percentFilesLocal}"
- * }]
- */
- widgetValues: [],
- widgetName: "",
- widgetDescription: "",
- widgetAuthor: function () {
- return App.router.get('loginName');
- }.property('App.router.loginName'),
- widgetScope: null
- }),
- loadMap: {
- '1': [
- {
- type: 'sync',
- callback: function () {
- this.load('widgetService');
- this.load('widgetType');
- }
- }
- ],
- '2': [
- {
- type: 'sync',
- callback: function () {
- this.load('widgetProperties', true);
- this.load('widgetValues', true);
- this.load('widgetMetrics', true);
- this.load('expressions', true);
- this.load('dataSets', true);
- this.load('templateValue', true);
- }
- },
- {
- type: 'async',
- callback: function () {
- return this.loadAllMetrics();
- }
- }
- ]
- },
- /**
- * set current step
- * @param {string} currentStep
- * @param {boolean} completed
- * @param {boolean} skipStateSave
- */
- setCurrentStep: function (currentStep, completed, skipStateSave) {
- this._super(currentStep, completed);
- if (App.get('testMode') || skipStateSave) {
- return;
- }
- this.saveClusterStatus('WIDGET_DEPLOY');
- },
- setStepsEnable: function () {
- for (var i = 1; i <= this.get('totalSteps'); i++) {
- var step = this.get('isStepDisabled').findProperty('step', i);
- if (i <= this.get('currentStep') && App.get('router.clusterController.isLoaded')) {
- step.set('value', false);
- } else {
- step.set('value', i != this.get('currentStep'));
- }
- }
- }.observes('currentStep', 'App.router.clusterController.isLoaded'),
- /**
- * save status of the cluster.
- * @param {object} clusterStatus
- */
- saveClusterStatus: function (clusterStatus) {
- App.clusterStatus.setClusterStatus({
- clusterState: clusterStatus,
- wizardControllerName: 'widgetWizardController',
- localdb: App.db.data
- });
- },
- /**
- * save wizard properties to controller and localStorage
- * @param {string} name
- * @param value
- */
- save: function (name, value) {
- this.set('content.' + name, value);
- this._super(name);
- },
- /**
- * load widget metrics
- * on resolve deferred return array of widget metrics
- * @returns {$.Deferred}
- */
- loadAllMetrics: function () {
- var widgetMetrics = this.getDBProperty('allMetrics');
- var self = this;
- var dfd = $.Deferred();
- if (widgetMetrics.length === 0) {
- this.loadAllMetricsFromServer(function () {
- dfd.resolve(self.get('content.allMetrics'));
- });
- } else {
- this.set('content.allMetrics', widgetMetrics);
- dfd.resolve(widgetMetrics);
- }
- return dfd.promise();
- },
- /**
- * load metrics from server
- * @param {function} callback
- * @returns {$.ajax}
- */
- loadAllMetricsFromServer: function (callback) {
- return App.ajax.send({
- name: 'widgets.wizard.metrics.get',
- sender: this,
- data: {
- stackVersionURL: App.get('stackVersionURL'),
- serviceNames: App.Service.find().filter(function (item) {
- return App.StackService.find(item.get('id')).get('isServiceWithWidgets');
- }).mapProperty('serviceName').join(',')
- },
- callback: callback,
- success: 'loadAllMetricsFromServerCallback'
- });
- },
- /**
- *
- * @param {object} json
- */
- loadAllMetricsFromServerCallback: function (json) {
- var self = this;
- var result = [];
- var metrics = {};
- if (json) {
- json.items.forEach(function (service) {
- var data = service.artifacts[0].artifact_data[service.StackServices.service_name];
- for (var componentName in data) {
- for (var level in data[componentName]) {
- metrics = data[componentName][level][0]['metrics']['default'];
- for (var widgetId in metrics) {
- var metricObj = {
- widget_id: widgetId,
- point_in_time: metrics[widgetId].pointInTime,
- temporal: metrics[widgetId].temporal,
- name: metrics[widgetId].name,
- level: level.toUpperCase(),
- type: data[componentName][level][0]["type"].toUpperCase(),
- component_name: componentName,
- service_name: service.StackServices.service_name
- };
- result.push(metricObj);
- if (metricObj.level === 'HOSTCOMPONENT') {
- self.insertHostComponentCriteria(metricObj);
- }
- }
- }
- }
- }, this);
- }
- this.save('allMetrics', result);
- },
- /**
- *
- * @param metricObj {Object}
- */
- insertHostComponentCriteria: function (metricObj) {
- switch (metricObj.component_name) {
- case 'NAMENODE':
- metricObj.host_component_criteria = 'host_components/metrics/dfs/FSNamesystem/HAState=active';
- break;
- case 'RESOURCEMANAGER':
- metricObj.host_component_criteria = 'host_components/HostRoles/ha_state=ACTIVE';
- break;
- default:
- }
- },
- /**
- * post widget definition to server
- * @returns {$.ajax}
- */
- postWidgetDefinition: function (data) {
- //TODO remove setting diplay_name once API supports it
- data.WidgetInfo.display_name = data.WidgetInfo.widget_name;
- return App.ajax.send({
- name: 'widgets.wizard.add',
- sender: this,
- data: {
- data: data
- },
- success: 'postWidgetDefinitionSuccessCallback'
- });
- },
- /**
- * assign created widget to active layout if it present
- * @param data
- */
- postWidgetDefinitionSuccessCallback: function (data) {
- if (Em.isNone(this.get('content.layoutId'))) return;
- var widgets = App.WidgetLayout.find(this.get('content.layoutId')).get('widgets').toArray();
- widgets.pushObject(Em.Object.create({
- id: data.resources[0].WidgetInfo.id
- }));
- App.router.get('mainServiceInfoSummaryController').saveWidgetLayout(widgets);
- },
- /**
- * Remove all loaded data.
- * Created as copy for App.router.clearAllSteps
- */
- clearAllSteps: function () {
- this.clearInstallOptions();
- // clear temporary information stored during the install
- this.set('content.cluster', this.getCluster());
- },
- clearTasksData: function () {
- this.saveTasksStatuses(undefined);
- this.saveRequestIds(undefined);
- this.saveTasksRequestIds(undefined);
- },
- /**
- * Clear all temporary data
- */
- finish: function () {
- this.setCurrentStep('1', false, true);
- this.save('widgetType', '');
- this.resetDbNamespace();
- App.get('router.updateController').updateAll();
- }
- });
|