service_config.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var validator = require('utils/validator');
  20. App.ServiceConfig = Ember.Object.extend({
  21. serviceName: '',
  22. configCategories: [],
  23. configs: null,
  24. restartRequired: false,
  25. restartRequiredMessage: '',
  26. restartRequiredHostsAndComponents: {},
  27. errorCount: function () {
  28. var overrideErrors = 0;
  29. this.get('configs').filterProperty("overrides").forEach(function (e) {
  30. e.overrides.forEach(function (e) {
  31. if (e.error) {
  32. overrideErrors += 1;
  33. }
  34. })
  35. })
  36. var masterErrors = this.get('configs').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  37. var slaveErrors = 0;
  38. this.get('configCategories').forEach(function (_category) {
  39. slaveErrors += _category.get('slaveErrorCount');
  40. }, this);
  41. return masterErrors + slaveErrors + overrideErrors;
  42. }.property('configs.@each.isValid', 'configs.@each.isVisible', 'configCategories.@each.slaveErrorCount', 'configs.@each.overrideErrorTrigger')
  43. });
  44. App.ServiceConfigCategory = Ember.Object.extend({
  45. name: null,
  46. /**
  47. * We cant have spaces in the name as this is being used as HTML element id while rendering. Hence we introduced 'displayName' where we can have spaces like 'Secondary Name Node' etc.
  48. */
  49. displayName: null,
  50. slaveConfigs: null,
  51. /**
  52. * check whether to show custom view in category instead of default
  53. */
  54. isCustomView: false,
  55. customView: null,
  56. /**
  57. * Each category might have a site-name associated (hdfs-site, core-site, etc.)
  58. * and this will be used when determining which category a particular property
  59. * ends up in, based on its site.
  60. */
  61. siteFileName: null,
  62. /**
  63. * Can this category add new properties. Used for custom configurations.
  64. */
  65. canAddProperty: false,
  66. primaryName: function () {
  67. switch (this.get('name')) {
  68. case 'DataNode':
  69. return 'DATANODE';
  70. break;
  71. case 'TaskTracker':
  72. return 'TASKTRACKER';
  73. break;
  74. case 'RegionServer':
  75. return 'HBASE_REGIONSERVER';
  76. }
  77. }.property('name'),
  78. isForMasterComponent: function () {
  79. var masterServices = [ 'NameNode', 'SNameNode', 'JobTracker', 'HBase Master', 'Oozie Master',
  80. 'Hive Metastore', 'WebHCat Server', 'ZooKeeper Server', 'Nagios', 'Ganglia' ];
  81. return (masterServices.contains(this.get('name')));
  82. }.property('name'),
  83. isForSlaveComponent: function () {
  84. return this.get('name') === 'DataNode' || this.get('name') === 'TaskTracker' ||
  85. this.get('name') === 'RegionServer';
  86. }.property('name'),
  87. slaveErrorCount: function () {
  88. var length = 0;
  89. if (this.get('slaveConfigs.groups')) {
  90. this.get('slaveConfigs.groups').forEach(function (_group) {
  91. length += _group.get('errorCount');
  92. }, this);
  93. }
  94. return length;
  95. }.property('slaveConfigs.groups.@each.errorCount'),
  96. isAdvanced : function(){
  97. var name = this.get('name');
  98. return name.indexOf("Advanced") !== -1 ;
  99. }.property('name')
  100. });
  101. App.SlaveConfigs = Ember.Object.extend({
  102. componentName: null,
  103. displayName: null,
  104. hosts: null,
  105. groups: null
  106. });
  107. App.Group = Ember.Object.extend({
  108. name: null,
  109. hostNames: null,
  110. properties: null,
  111. errorCount: function () {
  112. if (this.get('properties')) {
  113. return this.get('properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  114. }
  115. }.property('properties.@each.isValid', 'properties.@each.isVisible')
  116. });
  117. App.ServiceConfigProperty = Ember.Object.extend({
  118. id: '', //either 'puppet var' or 'site property'
  119. name: '',
  120. displayName: '',
  121. value: '',
  122. retypedPassword: '',
  123. defaultValue: '',
  124. defaultDirectory: '',
  125. description: '',
  126. displayType: 'string', // string, digits, number, directories, custom
  127. unit: '',
  128. category: 'General',
  129. isRequired: true, // by default a config property is required
  130. isReconfigurable: true, // by default a config property is reconfigurable
  131. isEditable: true, // by default a config property is editable
  132. isVisible: true,
  133. isSecureConfig: false,
  134. errorMessage: '',
  135. serviceConfig: null, // points to the parent App.ServiceConfig object
  136. filename: '',
  137. isOriginalSCP : true, // if true, then this is original SCP instance and its value is not overridden value.
  138. parentSCP: null, // This is the main SCP which is overridden by this. Set only when isOriginalSCP is false.
  139. selectedHostOptions : null, // contain array of hosts configured with overridden value
  140. overrides : null,
  141. isUserProperty: null, // This property was added by user. Hence they get removal actions etc.
  142. isOverridable: true,
  143. error: false,
  144. overrideErrorTrigger: 0, //Trigger for overrridable property error
  145. isRestartRequired: false,
  146. restartRequiredMessage: 'Restart required',
  147. index: null, //sequence number in category
  148. editDone: false, //Text field: on focusOut: true, on focusIn: false
  149. /**
  150. * On Overridable property error message, change overrideErrorTrigger value to recount number of errors service have
  151. */
  152. observeErrors: function () {
  153. this.set("overrideErrorTrigger", this.get("overrideErrorTrigger") + 1);
  154. }.observes("overrides.@each.errorMessage"),
  155. /**
  156. * No override capabilities for fields which are not edtiable
  157. * and fields which represent master hosts.
  158. */
  159. isPropertyOverridable : function() {
  160. var overrideable = this.get('isOverridable');
  161. var editable = this.get('isEditable');
  162. var dt = this.get('displayType');
  163. return overrideable && editable && ("masterHost"!=dt);
  164. }.property('isEditable', 'displayType', 'isOverridable'),
  165. isOverridden: function() {
  166. var overrides = this.get('overrides');
  167. return (overrides != null && overrides.get('length')>0) || !this.get('isOriginalSCP');
  168. }.property('overrides', 'overrides.length', 'isOriginalSCP'),
  169. isRemovable: function() {
  170. var isOriginalSCP = this.get('isOriginalSCP');
  171. var isUserProperty = this.get('isUserProperty');
  172. // Removable when this is a user property, or it is not an original property
  173. return isUserProperty || !isOriginalSCP;
  174. }.property('isUserProperty', 'isOriginalSCP'),
  175. init: function () {
  176. if(this.get("displayType")=="password"){
  177. this.set('retypedPassword', this.get('defaultValue'));
  178. this.set('value', this.get('defaultValue'));
  179. }
  180. if ((this.get('id') === 'puppet var') && this.get('value') == '') {
  181. this.set('value', this.get('defaultValue'));
  182. }
  183. // TODO: remove mock data
  184. },
  185. /**
  186. * Indicates when value is not the default value.
  187. * Returns false when there is no default value.
  188. */
  189. isNotDefaultValue: function () {
  190. var value = this.get('value');
  191. var dValue = this.get('defaultValue');
  192. var isEditable = this.get('isEditable');
  193. return isEditable && dValue != null && value !== dValue;
  194. }.property('value', 'defaultValue', 'isEditable'),
  195. /**
  196. * Don't show "Undo" for hosts on Installer Step7
  197. */
  198. cantBeUndone: function() {
  199. var types = ["masterHost", "slaveHosts", "masterHosts", "slaveHost","radio button"];
  200. var displayType = this.get('displayType');
  201. var result = false;
  202. types.forEach(function(type) {
  203. if (type === displayType) {
  204. result = true;
  205. return;
  206. }
  207. });
  208. return result;
  209. }.property('displayType'),
  210. initialValue: function (localDB) {
  211. var masterComponentHostsInDB = localDB.masterComponentHosts;
  212. //console.log("value in initialvalue: " + JSON.stringify(masterComponentHostsInDB));
  213. var hostsInfo = localDB.hosts; // which we are setting in installerController in step3.
  214. var slaveComponentHostsInDB = localDB.slaveComponentHosts;
  215. var isOnlyFirstOneNeeded = true;
  216. switch (this.get('name')) {
  217. case 'namenode_host':
  218. var temp = masterComponentHostsInDB.findProperty('component', 'NAMENODE');
  219. this.set('value', temp.hostName);
  220. break;
  221. case 'snamenode_host':
  222. this.set('value', masterComponentHostsInDB.findProperty('component', 'SECONDARY_NAMENODE').hostName);
  223. break;
  224. case 'datanode_hosts':
  225. this.set('value', slaveComponentHostsInDB.findProperty('componentName', 'DATANODE').hosts.mapProperty('hostName'));
  226. break;
  227. case 'hs_host':
  228. this.set('value', masterComponentHostsInDB.filterProperty('component', 'HISTORYSERVER').mapProperty('hostName'));
  229. break;
  230. case 'rm_host':
  231. this.set('value', masterComponentHostsInDB.findProperty('component', 'RESOURCEMANAGER').hostName);
  232. break;
  233. case 'nm_hosts':
  234. this.set('value', slaveComponentHostsInDB.findProperty('componentName', 'NODEMANAGER').hosts.mapProperty('hostName'));
  235. break;
  236. case 'jobtracker_host':
  237. this.set('value', masterComponentHostsInDB.findProperty('component', 'JOBTRACKER').hostName);
  238. break;
  239. case 'tasktracker_hosts':
  240. this.set('value', slaveComponentHostsInDB.findProperty('componentName', 'TASKTRACKER').hosts.mapProperty('hostName'));
  241. break;
  242. case 'hbasemaster_host':
  243. this.set('value', masterComponentHostsInDB.filterProperty('component', 'HBASE_MASTER').mapProperty('hostName'));
  244. break;
  245. case 'regionserver_hosts':
  246. this.set('value', slaveComponentHostsInDB.findProperty('componentName', 'HBASE_REGIONSERVER').hosts.mapProperty('hostName'));
  247. break;
  248. case 'hivemetastore_host':
  249. this.set('value', masterComponentHostsInDB.findProperty('component', 'HIVE_SERVER').hostName);
  250. break;
  251. case 'hive_ambari_host':
  252. this.set('value', masterComponentHostsInDB.findProperty('component', 'HIVE_SERVER').hostName);
  253. break;
  254. case 'oozieserver_host':
  255. this.set('value', masterComponentHostsInDB.findProperty('component', 'OOZIE_SERVER').hostName);
  256. break;
  257. case 'webhcatserver_host':
  258. this.set('value', masterComponentHostsInDB.findProperty('component', 'WEBHCAT_SERVER').hostName);
  259. break;
  260. case 'hueserver_host':
  261. this.set('value', masterComponentHostsInDB.findProperty('component', 'HUE_SERVER').hostName);
  262. break;
  263. case 'oozie_ambari_host':
  264. this.set('value', masterComponentHostsInDB.findProperty('component', 'OOZIE_SERVER').hostName);
  265. break;
  266. case 'zookeeperserver_hosts':
  267. this.set('value', masterComponentHostsInDB.filterProperty('component', 'ZOOKEEPER_SERVER').mapProperty('hostName'));
  268. break;
  269. case 'dfs_name_dir':
  270. case 'dfs_data_dir':
  271. case 'yarn_nodemanager_local-dirs':
  272. case 'mapred_local_dir':
  273. this.unionAllMountPoints(!isOnlyFirstOneNeeded, localDB);
  274. break;
  275. case 'fs_checkpoint_dir':
  276. case 'zk_data_dir':
  277. case 'oozie_data_dir':
  278. this.unionAllMountPoints(isOnlyFirstOneNeeded, localDB);
  279. break;
  280. }
  281. },
  282. unionAllMountPoints: function (isOnlyFirstOneNeeded, localDB) {
  283. var hostname = '';
  284. var mountPointsPerHost = [];
  285. var mountPointAsRoot;
  286. var masterComponentHostsInDB = localDB.masterComponentHosts;
  287. var slaveComponentHostsInDB = localDB.slaveComponentHosts;
  288. var hostsInfo = localDB.hosts; // which we are setting in installerController in step3.
  289. App.Host.find().forEach(function(item){
  290. if(!hostsInfo[item.get('id')]){
  291. hostsInfo[item.get('id')] = {
  292. name: item.get('id'),
  293. cpu: item.get('cpu'),
  294. memory: item.get('memory'),
  295. disk_info: item.get('diskInfo'),
  296. bootStatus: "REGISTERED",
  297. isInstalled: true
  298. };
  299. }
  300. });
  301. var temp = '';
  302. var setOfHostNames = [];
  303. switch (this.get('name')) {
  304. case 'dfs_name_dir':
  305. var components = masterComponentHostsInDB.filterProperty('component', 'NAMENODE');
  306. components.forEach(function (component) {
  307. setOfHostNames.push(component.hostName);
  308. }, this);
  309. break;
  310. case 'fs_checkpoint_dir':
  311. var components = masterComponentHostsInDB.filterProperty('component', 'SECONDARY_NAMENODE');
  312. components.forEach(function (component) {
  313. setOfHostNames.push(component.hostName);
  314. }, this);
  315. break;
  316. case 'dfs_data_dir':
  317. temp = slaveComponentHostsInDB.findProperty('componentName', 'DATANODE');
  318. temp.hosts.forEach(function (host) {
  319. setOfHostNames.push(host.hostName);
  320. }, this);
  321. break;
  322. case 'mapred_local_dir':
  323. temp = slaveComponentHostsInDB.findProperty('componentName', 'TASKTRACKER') || slaveComponentHostsInDB.findProperty('componentName', 'NODEMANAGER');
  324. temp.hosts.forEach(function (host) {
  325. setOfHostNames.push(host.hostName);
  326. }, this);
  327. break;
  328. case 'yarn_nodemanager_local-dirs':
  329. temp = slaveComponentHostsInDB.findProperty('componentName', 'NODEMANAGER');
  330. temp.hosts.forEach(function (host) {
  331. setOfHostNames.push(host.hostName);
  332. }, this);
  333. break;
  334. case 'zk_data_dir':
  335. var components = masterComponentHostsInDB.filterProperty('component', 'ZOOKEEPER_SERVER');
  336. components.forEach(function (component) {
  337. setOfHostNames.push(component.hostName);
  338. }, this);
  339. break;
  340. case 'oozie_data_dir':
  341. var components = masterComponentHostsInDB.filterProperty('component', 'OOZIE_SERVER');
  342. components.forEach(function (component) {
  343. setOfHostNames.push(component.hostName);
  344. }, this);
  345. break;
  346. }
  347. // In Add Host Wizard, if we did not select this slave component for any host, then we don't process any further.
  348. if (setOfHostNames.length === 0) {
  349. return;
  350. }
  351. var allMountPoints = [];
  352. for (var i = 0; i < setOfHostNames.length; i++) {
  353. hostname = setOfHostNames[i];
  354. mountPointsPerHost = hostsInfo[hostname].disk_info;
  355. mountPointAsRoot = mountPointsPerHost.findProperty('mountpoint', '/');
  356. mountPointsPerHost = mountPointsPerHost.filter(function (mPoint) {
  357. return !(['/', '/home', '/boot'].contains(mPoint.mountpoint) || ['devtmpfs', 'tmpfs', 'vboxsf'].contains(mPoint.type));
  358. });
  359. mountPointsPerHost.forEach(function (mPoint) {
  360. if( !allMountPoints.findProperty("mountpoint", mPoint.mountpoint)) {
  361. allMountPoints.push(mPoint);
  362. }
  363. }, this);
  364. }
  365. if (allMountPoints.length == 0) {
  366. allMountPoints.push(mountPointAsRoot);
  367. }
  368. this.set('value', '');
  369. if (!isOnlyFirstOneNeeded) {
  370. allMountPoints.forEach(function (eachDrive) {
  371. var mPoint = this.get('value');
  372. if (!mPoint) {
  373. mPoint = "";
  374. }
  375. if (eachDrive.mountpoint === "/") {
  376. mPoint += this.get('defaultDirectory') + "\n";
  377. } else {
  378. mPoint += eachDrive.mountpoint + this.get('defaultDirectory') + "\n";
  379. }
  380. this.set('value', mPoint);
  381. this.set('defaultValue', mPoint);
  382. }, this);
  383. } else {
  384. var mPoint = allMountPoints[0].mountpoint;
  385. if (mPoint === "/") {
  386. mPoint = this.get('defaultDirectory') + "\n";
  387. } else {
  388. mPoint = mPoint + this.get('defaultDirectory') + "\n";
  389. }
  390. this.set('value', mPoint);
  391. this.set('defaultValue', mPoint);
  392. }
  393. },
  394. isValid: function () {
  395. return this.get('errorMessage') === '';
  396. }.property('errorMessage'),
  397. viewClass: function () {
  398. switch (this.get('displayType')) {
  399. case 'checkbox':
  400. return App.ServiceConfigCheckbox;
  401. case 'password':
  402. return App.ServiceConfigPasswordField;
  403. case 'combobox':
  404. return App.ServiceConfigComboBox;
  405. case 'radio button':
  406. return App.ServiceConfigRadioButtons;
  407. break;
  408. case 'directories':
  409. return App.ServiceConfigTextArea;
  410. break;
  411. case 'multiLine':
  412. return App.ServiceConfigTextArea;
  413. break;
  414. case 'custom':
  415. return App.ServiceConfigBigTextArea;
  416. case 'masterHost':
  417. return App.ServiceConfigMasterHostView;
  418. case 'masterHosts':
  419. return App.ServiceConfigMasterHostsView;
  420. case 'slaveHosts':
  421. return App.ServiceConfigSlaveHostsView;
  422. default:
  423. if (this.get('unit')) {
  424. return App.ServiceConfigTextFieldWithUnit;
  425. } else {
  426. return App.ServiceConfigTextField;
  427. }
  428. }
  429. }.property('displayType'),
  430. validate: function () {
  431. var value = this.get('value');
  432. var valueRange = this.get('valueRange');
  433. var values = [];//value split by "," to check UNIX users, groups list
  434. var isError = false;
  435. if (typeof value === 'string' && value.length === 0) {
  436. if (this.get('isRequired')) {
  437. this.set('errorMessage', 'This is required');
  438. isError = true;
  439. } else {
  440. return;
  441. }
  442. }
  443. if (!isError) {
  444. switch (this.get('displayType')) {
  445. case 'int':
  446. if (!validator.isValidInt(value)) {
  447. this.set('errorMessage', 'Must contain digits only');
  448. isError = true;
  449. } else {
  450. if(valueRange){
  451. if(value < valueRange[0] || value > valueRange[1]){
  452. this.set('errorMessage', 'Must match the range');
  453. isError = true;
  454. }
  455. }
  456. }
  457. break;
  458. case 'float':
  459. if (!validator.isValidFloat(value)) {
  460. this.set('errorMessage', 'Must be a valid number');
  461. isError = true;
  462. }
  463. break;
  464. case 'UNIXList':
  465. if(value != '*'){
  466. values = value.split(',');
  467. for(var i = 0, l = values.length; i < l; i++){
  468. if(!validator.isValidUNIXUser(values[i])){
  469. if(this.get('type') == 'USERS'){
  470. this.set('errorMessage', 'Must be a valid list of user names');
  471. } else {
  472. this.set('errorMessage', 'Must be a valid list of group names');
  473. }
  474. isError = true;
  475. }
  476. }
  477. }
  478. break;
  479. case 'checkbox':
  480. break;
  481. case 'directories':
  482. if (!validator.isValidDir(value)) {
  483. this.set('errorMessage', 'Must be a slash at the start');
  484. isError = true;
  485. }
  486. break;
  487. case 'directory':
  488. if (!validator.isValidDir(value)) {
  489. this.set('errorMessage', 'Must be a slash at the start');
  490. isError = true;
  491. }
  492. break;
  493. case 'custom':
  494. break;
  495. case 'user':
  496. if (!validator.isValidUserName(value)) {
  497. this.set('errorMessage', Em.I18n.t('users.userName.validationFail'));
  498. isError = true;
  499. }
  500. break;
  501. case 'email':
  502. if (!validator.isValidEmail(value)) {
  503. this.set('errorMessage', 'Must be a valid email address');
  504. isError = true;
  505. }
  506. break;
  507. case 'password':
  508. // retypedPassword is set by the retypePasswordView child view of App.ServiceConfigPasswordField
  509. if (value !== this.get('retypedPassword')) {
  510. this.set('errorMessage', 'Passwords do not match');
  511. isError = true;
  512. }
  513. }
  514. }
  515. if (!isError) {
  516. // Check if this value is already in any of the overrides
  517. var self = this;
  518. var isOriginalSCP = this.get('isOriginalSCP');
  519. var parentSCP = this.get('parentSCP');
  520. if (!isOriginalSCP) {
  521. var hosts = this.get('selectedHostOptions');
  522. if(hosts==null || hosts.get('length')<1){
  523. this.set('errorMessage', 'Select hosts to apply exception to');
  524. isError = true;
  525. }
  526. if (!isError && parentSCP != null) {
  527. if (value === parentSCP.get('value')) {
  528. this.set('errorMessage', 'Host exceptions must have different value');
  529. isError = true;
  530. } else {
  531. var overrides = parentSCP.get('overrides');
  532. overrides.forEach(function (override) {
  533. if (self != override && value === override.get('value')) {
  534. self.set('errorMessage', 'Multiple host exceptions cannot have same value');
  535. isError = true;
  536. }
  537. });
  538. }
  539. }
  540. }
  541. }
  542. if (!isError) {
  543. this.set('errorMessage', '');
  544. this.set('error', false);
  545. } else {
  546. this.set('error', true);
  547. }
  548. }.observes('value', 'retypedPassword')
  549. });
  550. App.ConfigSiteTag = Ember.Object.extend({
  551. site: DS.attr('string'),
  552. tag: DS.attr('string'),
  553. /**
  554. * Object map of hostname->override-tag for overrides.
  555. * <b>Creators should set new object here.<b>
  556. */
  557. hostOverrides: null
  558. });