service_config.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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. configGroups: [],
  28. errorCount: function () {
  29. var overrideErrors = 0;
  30. this.get('configs').filterProperty("overrides").forEach(function (e) {
  31. e.overrides.forEach(function (e) {
  32. if (e.error) {
  33. overrideErrors += 1;
  34. }
  35. })
  36. });
  37. var masterErrors = this.get('configs').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  38. var slaveErrors = 0;
  39. this.get('configCategories').forEach(function (_category) {
  40. slaveErrors += _category.get('slaveErrorCount');
  41. }, this);
  42. return masterErrors + slaveErrors + overrideErrors;
  43. }.property('configs.@each.isValid', 'configs.@each.isVisible', 'configCategories.@each.slaveErrorCount', 'configs.@each.overrideErrorTrigger')
  44. });
  45. App.ServiceConfigCategory = Ember.Object.extend({
  46. name: null,
  47. /**
  48. * 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.
  49. */
  50. displayName: null,
  51. slaveConfigs: null,
  52. /**
  53. * check whether to show custom view in category instead of default
  54. */
  55. isCustomView: false,
  56. customView: null,
  57. /**
  58. * Each category might have a site-name associated (hdfs-site, core-site, etc.)
  59. * and this will be used when determining which category a particular property
  60. * ends up in, based on its site.
  61. */
  62. siteFileName: null,
  63. /**
  64. * Can this category add new properties. Used for custom configurations.
  65. */
  66. canAddProperty: false,
  67. primaryName: function () {
  68. switch (this.get('name')) {
  69. case 'DataNode':
  70. return 'DATANODE';
  71. break;
  72. case 'TaskTracker':
  73. return 'TASKTRACKER';
  74. break;
  75. case 'RegionServer':
  76. return 'HBASE_REGIONSERVER';
  77. }
  78. return null;
  79. }.property('name'),
  80. isForMasterComponent: function () {
  81. var masterServices = [ 'NameNode', 'SNameNode', 'JobTracker', 'HBase Master', 'Oozie Master',
  82. 'Hive Metastore', 'WebHCat Server', 'ZooKeeper Server', 'Nagios', 'Ganglia' ];
  83. return (masterServices.contains(this.get('name')));
  84. }.property('name'),
  85. isForSlaveComponent: function () {
  86. var slaveComponents = ['DataNode', 'TaskTracker', 'RegionServer'];
  87. return (slaveComponents.contains(this.get('name')));
  88. }.property('name'),
  89. slaveErrorCount: function () {
  90. var length = 0;
  91. if (this.get('slaveConfigs.groups')) {
  92. this.get('slaveConfigs.groups').forEach(function (_group) {
  93. length += _group.get('errorCount');
  94. }, this);
  95. }
  96. return length;
  97. }.property('slaveConfigs.groups.@each.errorCount'),
  98. isAdvanced : function(){
  99. var name = this.get('name');
  100. return name.indexOf("Advanced") !== -1 ;
  101. }.property('name')
  102. });
  103. App.SlaveConfigs = Ember.Object.extend({
  104. componentName: null,
  105. displayName: null,
  106. hosts: null,
  107. groups: null
  108. });
  109. App.Group = Ember.Object.extend({
  110. name: null,
  111. hostNames: null,
  112. properties: null,
  113. errorCount: function () {
  114. if (this.get('properties')) {
  115. return this.get('properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  116. }
  117. }.property('properties.@each.isValid', 'properties.@each.isVisible')
  118. });
  119. App.ServiceConfigProperty = Ember.Object.extend({
  120. id: '', //either 'puppet var' or 'site property'
  121. name: '',
  122. displayName: '',
  123. value: '',
  124. retypedPassword: '',
  125. defaultValue: '',
  126. defaultDirectory: '',
  127. description: '',
  128. displayType: 'string', // string, digits, number, directories, custom
  129. unit: '',
  130. category: 'General',
  131. isRequired: true, // by default a config property is required
  132. isReconfigurable: true, // by default a config property is reconfigurable
  133. isEditable: true, // by default a config property is editable
  134. isVisible: true,
  135. isRequiredByAgent: true, // Setting it to true implies property will be stored in global configuration
  136. isSecureConfig: false,
  137. errorMessage: '',
  138. warnMessage: '',
  139. serviceConfig: null, // points to the parent App.ServiceConfig object
  140. filename: '',
  141. isOriginalSCP : true, // if true, then this is original SCP instance and its value is not overridden value.
  142. parentSCP: null, // This is the main SCP which is overridden by this. Set only when isOriginalSCP is false.
  143. selectedHostOptions : null, // contain array of hosts configured with overridden value
  144. overrides : null,
  145. group: null, // Contain group related to this property. Set only when isOriginalSCP is false.
  146. isUserProperty: null, // This property was added by user. Hence they get removal actions etc.
  147. isOverridable: true,
  148. showLabel: true,
  149. error: false,
  150. warn: false,
  151. overrideErrorTrigger: 0, //Trigger for overrridable property error
  152. isRestartRequired: false,
  153. restartRequiredMessage: 'Restart required',
  154. index: null, //sequence number in category
  155. editDone: false, //Text field: on focusOut: true, on focusIn: false
  156. serviceValidator: null,
  157. isNotSaved: false, // user property was added but not saved
  158. /**
  159. * On Overridable property error message, change overrideErrorTrigger value to recount number of errors service have
  160. */
  161. observeErrors: function () {
  162. this.set("overrideErrorTrigger", this.get("overrideErrorTrigger") + 1);
  163. }.observes("overrides.@each.errorMessage"),
  164. /**
  165. * No override capabilities for fields which are not edtiable
  166. * and fields which represent master hosts.
  167. */
  168. isPropertyOverridable: function () {
  169. var overrideable = this.get('isOverridable');
  170. var editable = this.get('isEditable');
  171. var overrides = this.get('overrides');
  172. var dt = this.get('displayType');
  173. return overrideable && (editable || !overrides || !overrides.length) && ("masterHost" != dt);
  174. }.property('isEditable', 'displayType', 'isOverridable', 'overrides.length'),
  175. isOverridden: function() {
  176. var overrides = this.get('overrides');
  177. return (overrides != null && overrides.get('length')>0) || !this.get('isOriginalSCP');
  178. }.property('overrides', 'overrides.length', 'isOriginalSCP'),
  179. isRemovable: function() {
  180. var isOriginalSCP = this.get('isOriginalSCP');
  181. var isUserProperty = this.get('isUserProperty');
  182. var isEditable = this.get('isEditable');
  183. var hasOverrides = this.get('overrides.length') > 0;
  184. // Removable when this is a user property, or it is not an original property and it is editable
  185. return isEditable && !hasOverrides && (isUserProperty || !isOriginalSCP);
  186. }.property('isUserProperty', 'isOriginalSCP', 'overrides.length'),
  187. init: function () {
  188. if(this.get("displayType")=="password"){
  189. this.set('retypedPassword', this.get('value'));
  190. }
  191. if ((this.get('id') === 'puppet var') && this.get('value') == '') {
  192. this.set('value', this.get('defaultValue'));
  193. }
  194. // TODO: remove mock data
  195. },
  196. /**
  197. * Indicates when value is not the default value.
  198. * Returns false when there is no default value.
  199. */
  200. isNotDefaultValue: function () {
  201. var value = this.get('value');
  202. var dValue = this.get('defaultValue');
  203. var isEditable = this.get('isEditable');
  204. return isEditable && dValue != null && value !== dValue;
  205. }.property('value', 'defaultValue', 'isEditable'),
  206. /**
  207. * Don't show "Undo" for hosts on Installer Step7
  208. */
  209. cantBeUndone: function() {
  210. var types = ["masterHost", "slaveHosts", "masterHosts", "slaveHost","radio button"];
  211. var displayType = this.get('displayType');
  212. var result = false;
  213. types.forEach(function(type) {
  214. if (type === displayType) {
  215. result = true;
  216. }
  217. });
  218. return result;
  219. }.property('displayType'),
  220. initialValue: function (localDB) {
  221. var masterComponentHostsInDB = localDB.masterComponentHosts;
  222. //console.log("value in initialvalue: " + JSON.stringify(masterComponentHostsInDB));
  223. var hostsInfo = localDB.hosts; // which we are setting in installerController in step3.
  224. var slaveComponentHostsInDB = localDB.slaveComponentHosts;
  225. var isOnlyFirstOneNeeded = true;
  226. switch (this.get('name')) {
  227. case 'namenode_host':
  228. this.set('value', masterComponentHostsInDB.filterProperty('component', 'NAMENODE').mapProperty('hostName'));
  229. break;
  230. case 'dfs.http.address':
  231. var nnHost = masterComponentHostsInDB.findProperty('component', 'NAMENODE').hostName;
  232. this.setDefaultValue("(\\w*)(?=:)",nnHost);
  233. break;
  234. case 'dfs.namenode.http-address':
  235. var nnHost = masterComponentHostsInDB.findProperty('component', 'NAMENODE').hostName;
  236. this.setDefaultValue("(\\w*)(?=:)",nnHost);
  237. break;
  238. case 'dfs.https.address':
  239. var nnHost = masterComponentHostsInDB.findProperty('component', 'NAMENODE').hostName;
  240. this.setDefaultValue("(\\w*)(?=:)",nnHost);
  241. break;
  242. case 'dfs.namenode.https-address':
  243. var nnHost = masterComponentHostsInDB.findProperty('component', 'NAMENODE').hostName;
  244. this.setDefaultValue("(\\w*)(?=:)",nnHost);
  245. break;
  246. case 'fs.default.name':
  247. var nnHost = masterComponentHostsInDB.filterProperty('component', 'NAMENODE').mapProperty('hostName');
  248. this.setDefaultValue(":\/\/(\\w*)(?=:)",'://' + nnHost);
  249. break;
  250. case 'fs.defaultFS':
  251. var nnHost = masterComponentHostsInDB.filterProperty('component', 'NAMENODE').mapProperty('hostName');
  252. this.setDefaultValue(":\/\/(\\w*)(?=:)",'://' + nnHost);
  253. break;
  254. case 'hbase.rootdir':
  255. var nnHost = masterComponentHostsInDB.filterProperty('component', 'NAMENODE').mapProperty('hostName');
  256. this.setDefaultValue(":\/\/(\\w*)(?=:)",'://' + nnHost);
  257. break;
  258. case 'snamenode_host':
  259. // Secondary NameNode does not exist when NameNode HA is enabled
  260. var snn = masterComponentHostsInDB.findProperty('component', 'SECONDARY_NAMENODE');
  261. if (snn) {
  262. this.set('value', snn.hostName);
  263. }
  264. break;
  265. case 'dfs.secondary.http.address':
  266. var snnHost = masterComponentHostsInDB.findProperty('component', 'SECONDARY_NAMENODE');
  267. if (snnHost) {
  268. this.setDefaultValue("(\\w*)(?=:)",snnHost.hostName);
  269. }
  270. break;
  271. case 'dfs.namenode.secondary.http-address':
  272. var snnHost = masterComponentHostsInDB.findProperty('component', 'SECONDARY_NAMENODE');
  273. if (snnHost) {
  274. this.setDefaultValue("(\\w*)(?=:)",snnHost.hostName);
  275. }
  276. break;
  277. case 'datanode_hosts':
  278. this.set('value', slaveComponentHostsInDB.findProperty('componentName', 'DATANODE').hosts.mapProperty('hostName'));
  279. break;
  280. case 'hs_host':
  281. this.set('value', masterComponentHostsInDB.filterProperty('component', 'HISTORYSERVER').mapProperty('hostName'));
  282. break;
  283. case 'yarn.log.server.url':
  284. var hsHost = masterComponentHostsInDB.filterProperty('component', 'HISTORYSERVER').mapProperty('hostName');
  285. this.setDefaultValue(":\/\/(\\w*)(?=:)",'://' + hsHost);
  286. break;
  287. case 'mapreduce.jobhistory.webapp.address':
  288. var hsHost = masterComponentHostsInDB.filterProperty('component', 'HISTORYSERVER').mapProperty('hostName');
  289. this.setDefaultValue("(\\w*)(?=:)",hsHost);
  290. break;
  291. case 'mapreduce.jobhistory.address':
  292. var hsHost = masterComponentHostsInDB.filterProperty('component', 'HISTORYSERVER').mapProperty('hostName');
  293. this.setDefaultValue("(\\w*)(?=:)",hsHost);
  294. break;
  295. case 'rm_host':
  296. this.set('value', masterComponentHostsInDB.findProperty('component', 'RESOURCEMANAGER').hostName);
  297. break;
  298. case 'ats_host':
  299. if (!App.supports.appTimelineServer) return; // @todo remove test mode check after App Timeline service integration
  300. this.set('value', masterComponentHostsInDB.findProperty('component', 'APP_TIMELINE_SERVER').hostName);
  301. break;
  302. case 'yarn.resourcemanager.hostname':
  303. var rmHost = masterComponentHostsInDB.findProperty('component', 'RESOURCEMANAGER').hostName;
  304. this.set('defaultValue',rmHost);
  305. this.set('value',this.get('defaultValue'));
  306. break;
  307. case 'yarn.resourcemanager.resource-tracker.address':
  308. var rmHost = masterComponentHostsInDB.findProperty('component', 'RESOURCEMANAGER').hostName;
  309. this.setDefaultValue("(\\w*)(?=:)",rmHost);
  310. break;
  311. case 'yarn.resourcemanager.webapp.address':
  312. var rmHost = masterComponentHostsInDB.findProperty('component', 'RESOURCEMANAGER').hostName;
  313. this.setDefaultValue("(\\w*)(?=:)",rmHost);
  314. break;
  315. case 'yarn.resourcemanager.scheduler.address':
  316. var rmHost = masterComponentHostsInDB.findProperty('component', 'RESOURCEMANAGER').hostName;
  317. this.setDefaultValue("(\\w*)(?=:)",rmHost);
  318. break;
  319. case 'yarn.resourcemanager.address':
  320. var rmHost = masterComponentHostsInDB.findProperty('component', 'RESOURCEMANAGER').hostName;
  321. this.setDefaultValue("(\\w*)(?=:)",rmHost);
  322. break;
  323. case 'yarn.resourcemanager.admin.address':
  324. var rmHost = masterComponentHostsInDB.findProperty('component', 'RESOURCEMANAGER').hostName;
  325. this.setDefaultValue("(\\w*)(?=:)",rmHost);
  326. break;
  327. case 'yarn.timeline-service.webapp.address':
  328. var hsHost = masterComponentHostsInDB.findProperty('component', 'APP_TIMELINE_SERVER').hostName;
  329. this.setDefaultValue("(0.0.0.0)(?=:)", hsHost);
  330. break;
  331. case 'yarn.timeline-service.webapp.https.address':
  332. var hsHost = masterComponentHostsInDB.findProperty('component', 'APP_TIMELINE_SERVER').hostName;
  333. this.setDefaultValue("(0.0.0.0)(?=:)", hsHost);
  334. break;
  335. case 'nm_hosts':
  336. this.set('value', slaveComponentHostsInDB.findProperty('componentName', 'NODEMANAGER').hosts.mapProperty('hostName'));
  337. break;
  338. case 'jobtracker_host':
  339. this.set('value', masterComponentHostsInDB.findProperty('component', 'JOBTRACKER').hostName);
  340. break;
  341. case 'mapred.job.tracker':
  342. var jtHost = masterComponentHostsInDB.findProperty('component', 'JOBTRACKER').hostName;
  343. this.setDefaultValue("(\\w*)(?=:)",jtHost);
  344. break;
  345. case 'mapred.job.tracker.http.address':
  346. var jtHost = masterComponentHostsInDB.findProperty('component', 'JOBTRACKER').hostName;
  347. this.setDefaultValue("(\\w*)(?=:)",jtHost);
  348. break;
  349. case 'mapreduce.history.server.http.address':
  350. var jtHost = masterComponentHostsInDB.findProperty('component', 'HISTORYSERVER').hostName;
  351. this.setDefaultValue("(\\w*)(?=:)",jtHost);
  352. break;
  353. case 'tasktracker_hosts':
  354. this.set('value', slaveComponentHostsInDB.findProperty('componentName', 'TASKTRACKER').hosts.mapProperty('hostName'));
  355. break;
  356. case 'hbasemaster_host':
  357. this.set('value', masterComponentHostsInDB.filterProperty('component', 'HBASE_MASTER').mapProperty('hostName'));
  358. break;
  359. case 'regionserver_hosts':
  360. this.set('value', slaveComponentHostsInDB.findProperty('componentName', 'HBASE_REGIONSERVER').hosts.mapProperty('hostName'));
  361. break;
  362. case 'hivemetastore_host':
  363. this.set('value', masterComponentHostsInDB.findProperty('component', 'HIVE_SERVER').hostName);
  364. break;
  365. case 'hive.metastore.uris':
  366. var hiveHost = masterComponentHostsInDB.findProperty('component', 'HIVE_SERVER').hostName;
  367. this.setDefaultValue(":\/\/(\\w*)(?=:)",'://' + hiveHost);
  368. break;
  369. case 'hive_ambari_host':
  370. this.set('value', masterComponentHostsInDB.findProperty('component', 'HIVE_SERVER').hostName);
  371. break;
  372. case 'oozieserver_host':
  373. this.set('value', masterComponentHostsInDB.findProperty('component', 'OOZIE_SERVER').hostName);
  374. break;
  375. case 'oozie.base.url':
  376. var oozieHost = masterComponentHostsInDB.findProperty('component', 'OOZIE_SERVER').hostName;
  377. this.setDefaultValue(":\/\/(\\w*)(?=:)",'://' + oozieHost);
  378. break;
  379. case 'webhcatserver_host':
  380. this.set('value', masterComponentHostsInDB.findProperty('component', 'WEBHCAT_SERVER').hostName);
  381. break;
  382. case 'hueserver_host':
  383. this.set('value', masterComponentHostsInDB.findProperty('component', 'HUE_SERVER').hostName);
  384. break;
  385. case 'oozie_ambari_host':
  386. this.set('value', masterComponentHostsInDB.findProperty('component', 'OOZIE_SERVER').hostName);
  387. break;
  388. case 'storm.zookeeper.servers':
  389. case 'zookeeperserver_hosts':
  390. this.set('value', masterComponentHostsInDB.filterProperty('component', 'ZOOKEEPER_SERVER').mapProperty('hostName'));
  391. break;
  392. case 'nimbus.host':
  393. this.set('value', masterComponentHostsInDB.findProperty('component', 'NIMBUS').hostName);
  394. break;
  395. case 'falconserver_host':
  396. this.set('value', masterComponentHostsInDB.findProperty('component', 'FALCON_SERVER').hostName);
  397. break;
  398. case 'drpcserver_host':
  399. this.set('value', masterComponentHostsInDB.findProperty('component', 'DRPC_SERVER').hostName);
  400. break;
  401. case 'stormuiserver_host':
  402. this.set('value', masterComponentHostsInDB.findProperty('component', 'STORM_UI_SERVER').hostName);
  403. break;
  404. case 'storm_rest_api_host':
  405. this.set('value', masterComponentHostsInDB.findProperty('component', 'STORM_REST_API').hostName);
  406. break;
  407. case 'supervisor_hosts':
  408. this.set('value', slaveComponentHostsInDB.findProperty('componentName', 'SUPERVISOR').hosts.mapProperty('hostName'));
  409. break;
  410. case 'hbase.zookeeper.quorum':
  411. var zkHosts = masterComponentHostsInDB.filterProperty('component', 'ZOOKEEPER_SERVER').mapProperty('hostName');
  412. this.setDefaultValue("(\\w*)", zkHosts);
  413. break;
  414. case 'templeton.zookeeper.hosts':
  415. var zkHosts = masterComponentHostsInDB.filterProperty('component', 'ZOOKEEPER_SERVER').mapProperty('hostName');
  416. var zkHostPort = zkHosts;
  417. var regex = "\\w*:(\\d+)"; //regex to fetch the port
  418. var portValue = this.get('defaultValue').match(new RegExp(regex));
  419. if (!portValue) return;
  420. if (portValue[1]) {
  421. for ( var i = 0; i < zkHosts.length; i++ ) {
  422. zkHostPort[i] = zkHosts[i] + ":" + portValue[1];
  423. }
  424. }
  425. this.setDefaultValue("(.*)", zkHostPort);
  426. break;
  427. case 'dfs.name.dir':
  428. case 'dfs.namenode.name.dir':
  429. case 'dfs.data.dir':
  430. case 'dfs.datanode.data.dir':
  431. case 'yarn.nodemanager.local-dirs':
  432. case 'yarn.nodemanager.log-dirs':
  433. case 'mapred.local.dir':
  434. this.unionAllMountPoints(!isOnlyFirstOneNeeded, localDB);
  435. break;
  436. case 'fs.checkpoint.dir':
  437. case 'dfs.namenode.checkpoint.dir':
  438. case 'zk_data_dir':
  439. case 'oozie_data_dir':
  440. case 'hbase.tmp.dir':
  441. this.unionAllMountPoints(isOnlyFirstOneNeeded, localDB);
  442. break;
  443. }
  444. },
  445. /**
  446. * @param regex : String
  447. * @param replaceWith : String
  448. */
  449. setDefaultValue: function(regex,replaceWith) {
  450. var defaultValue = this.get('defaultValue');
  451. var re = new RegExp(regex);
  452. defaultValue = defaultValue.replace(re,replaceWith);
  453. this.set('defaultValue',defaultValue);
  454. this.set('value',this.get('defaultValue'));
  455. },
  456. unionAllMountPoints: function (isOnlyFirstOneNeeded, localDB) {
  457. var hostname = '';
  458. var mountPointsPerHost = [];
  459. var mountPointAsRoot;
  460. var masterComponentHostsInDB = localDB.masterComponentHosts;
  461. var slaveComponentHostsInDB = localDB.slaveComponentHosts;
  462. var hostsInfo = localDB.hosts; // which we are setting in installerController in step3.
  463. App.Host.find().forEach(function(item){
  464. if(!hostsInfo[item.get('id')]){
  465. hostsInfo[item.get('id')] = {
  466. name: item.get('id'),
  467. cpu: item.get('cpu'),
  468. memory: item.get('memory'),
  469. disk_info: item.get('diskInfo'),
  470. bootStatus: "REGISTERED",
  471. isInstalled: true
  472. };
  473. }
  474. });
  475. var temp = '';
  476. var setOfHostNames = [];
  477. switch (this.get('name')) {
  478. case 'dfs.namenode.name.dir':
  479. case 'dfs.name.dir':
  480. var components = masterComponentHostsInDB.filterProperty('component', 'NAMENODE');
  481. components.forEach(function (component) {
  482. setOfHostNames.push(component.hostName);
  483. }, this);
  484. break;
  485. case 'fs.checkpoint.dir':
  486. case 'dfs.namenode.checkpoint.dir':
  487. var components = masterComponentHostsInDB.filterProperty('component', 'SECONDARY_NAMENODE');
  488. components.forEach(function (component) {
  489. setOfHostNames.push(component.hostName);
  490. }, this);
  491. break;
  492. case 'dfs.data.dir':
  493. case 'dfs.datanode.data.dir':
  494. temp = slaveComponentHostsInDB.findProperty('componentName', 'DATANODE');
  495. temp.hosts.forEach(function (host) {
  496. setOfHostNames.push(host.hostName);
  497. }, this);
  498. break;
  499. case 'mapred.local.dir':
  500. temp = slaveComponentHostsInDB.findProperty('componentName', 'TASKTRACKER') || slaveComponentHostsInDB.findProperty('componentName', 'NODEMANAGER');
  501. temp.hosts.forEach(function (host) {
  502. setOfHostNames.push(host.hostName);
  503. }, this);
  504. break;
  505. case 'yarn.nodemanager.log-dirs':
  506. case 'yarn.nodemanager.local-dirs':
  507. temp = slaveComponentHostsInDB.findProperty('componentName', 'NODEMANAGER');
  508. temp.hosts.forEach(function (host) {
  509. setOfHostNames.push(host.hostName);
  510. }, this);
  511. break;
  512. case 'zk_data_dir':
  513. var components = masterComponentHostsInDB.filterProperty('component', 'ZOOKEEPER_SERVER');
  514. components.forEach(function (component) {
  515. setOfHostNames.push(component.hostName);
  516. }, this);
  517. break;
  518. case 'oozie_data_dir':
  519. var components = masterComponentHostsInDB.filterProperty('component', 'OOZIE_SERVER');
  520. components.forEach(function (component) {
  521. setOfHostNames.push(component.hostName);
  522. }, this);
  523. break;
  524. case 'hbase.tmp.dir':
  525. var temp = slaveComponentHostsInDB.findProperty('componentName', 'HBASE_REGIONSERVER');
  526. temp.hosts.forEach(function (host) {
  527. setOfHostNames.push(host.hostName);
  528. }, this);
  529. break;
  530. }
  531. // In Add Host Wizard, if we did not select this slave component for any host, then we don't process any further.
  532. if (setOfHostNames.length === 0) {
  533. return;
  534. }
  535. var allMountPoints = [];
  536. for (var i = 0; i < setOfHostNames.length; i++) {
  537. hostname = setOfHostNames[i];
  538. mountPointsPerHost = hostsInfo[hostname].disk_info;
  539. mountPointAsRoot = mountPointsPerHost.findProperty('mountpoint', '/');
  540. // If Server does not send any host details information then atleast one mountpoint should be presumed as root
  541. // This happens in a single container Linux Docker environment.
  542. if (!mountPointAsRoot) {
  543. mountPointAsRoot = {mountpoint: '/'};
  544. }
  545. mountPointsPerHost = mountPointsPerHost.filter(function (mPoint) {
  546. return !(['/', '/home', '/boot'].contains(mPoint.mountpoint) || ['devtmpfs', 'tmpfs', 'vboxsf'].contains(mPoint.type));
  547. });
  548. mountPointsPerHost.forEach(function (mPoint) {
  549. if( !allMountPoints.findProperty("mountpoint", mPoint.mountpoint)) {
  550. allMountPoints.push(mPoint);
  551. }
  552. }, this);
  553. }
  554. if (allMountPoints.length == 0) {
  555. allMountPoints.push(mountPointAsRoot);
  556. }
  557. this.set('value', '');
  558. if (!isOnlyFirstOneNeeded) {
  559. allMountPoints.forEach(function (eachDrive) {
  560. var mPoint = this.get('value');
  561. if (!mPoint) {
  562. mPoint = "";
  563. }
  564. if (eachDrive.mountpoint === "/") {
  565. mPoint += this.get('defaultDirectory') + "\n";
  566. } else {
  567. mPoint += eachDrive.mountpoint + this.get('defaultDirectory') + "\n";
  568. }
  569. this.set('value', mPoint);
  570. this.set('defaultValue', mPoint);
  571. }, this);
  572. } else {
  573. var mPoint = allMountPoints[0].mountpoint;
  574. if (mPoint === "/") {
  575. mPoint = this.get('defaultDirectory') + "\n";
  576. } else {
  577. mPoint = mPoint + this.get('defaultDirectory') + "\n";
  578. }
  579. this.set('value', mPoint);
  580. this.set('defaultValue', mPoint);
  581. }
  582. },
  583. isValid: function () {
  584. return this.get('errorMessage') === '';
  585. }.property('errorMessage'),
  586. viewClass: function () {
  587. switch (this.get('displayType')) {
  588. case 'checkbox':
  589. return App.ServiceConfigCheckbox;
  590. case 'password':
  591. return App.ServiceConfigPasswordField;
  592. case 'combobox':
  593. return App.ServiceConfigComboBox;
  594. case 'radio button':
  595. return App.ServiceConfigRadioButtons;
  596. break;
  597. case 'directories':
  598. return App.ServiceConfigTextArea;
  599. break;
  600. case 'content':
  601. return App.ServiceConfigTextAreaContent;
  602. break;
  603. case 'multiLine':
  604. return App.ServiceConfigTextArea;
  605. break;
  606. case 'custom':
  607. return App.ServiceConfigBigTextArea;
  608. case 'masterHost':
  609. return App.ServiceConfigMasterHostView;
  610. case 'masterHosts':
  611. return App.ServiceConfigMasterHostsView;
  612. case 'slaveHosts':
  613. return App.ServiceConfigSlaveHostsView;
  614. default:
  615. if (this.get('unit')) {
  616. return App.ServiceConfigTextFieldWithUnit;
  617. } else {
  618. return App.ServiceConfigTextField;
  619. }
  620. }
  621. }.property('displayType'),
  622. validate: function () {
  623. var value = this.get('value');
  624. var valueRange = this.get('valueRange');
  625. var values = [];//value split by "," to check UNIX users, groups list
  626. var isError = false;
  627. var isWarn = false;
  628. if (typeof value === 'string' && value.length === 0) {
  629. if (this.get('isRequired')) {
  630. this.set('errorMessage', 'This is required');
  631. isError = true;
  632. } else {
  633. return;
  634. }
  635. }
  636. if (!isError) {
  637. switch (this.get('displayType')) {
  638. case 'int':
  639. if (!validator.isValidInt(value)) {
  640. this.set('errorMessage', 'Must contain digits only');
  641. isError = true;
  642. } else {
  643. if(valueRange){
  644. if(value < valueRange[0] || value > valueRange[1]){
  645. this.set('errorMessage', 'Must match the range');
  646. isError = true;
  647. }
  648. }
  649. }
  650. break;
  651. case 'float':
  652. if (!validator.isValidFloat(value)) {
  653. this.set('errorMessage', 'Must be a valid number');
  654. isError = true;
  655. }
  656. break;
  657. case 'UNIXList':
  658. if(value != '*'){
  659. values = value.split(',');
  660. for(var i = 0, l = values.length; i < l; i++){
  661. if(!validator.isValidUNIXUser(values[i])){
  662. if(this.get('type') == 'USERS'){
  663. this.set('errorMessage', 'Must be a valid list of user names');
  664. } else {
  665. this.set('errorMessage', 'Must be a valid list of group names');
  666. }
  667. isError = true;
  668. }
  669. }
  670. }
  671. break;
  672. case 'checkbox':
  673. break;
  674. case 'directories':
  675. case 'directory':
  676. if (!validator.isValidDir(value)) {
  677. this.set('errorMessage', 'Must be a slash at the start');
  678. isError = true;
  679. }
  680. else {
  681. if (!validator.isAllowedDir(value)) {
  682. this.set('errorMessage', 'Can\'t start with "home(s)"');
  683. isError = true;
  684. }
  685. }
  686. break;
  687. case 'custom':
  688. break;
  689. case 'user':
  690. if (!validator.isValidUserName(value)) {
  691. this.set('errorMessage', Em.I18n.t('users.userName.validationFail'));
  692. isError = true;
  693. }
  694. break;
  695. case 'email':
  696. if (!validator.isValidEmail(value)) {
  697. this.set('errorMessage', 'Must be a valid email address');
  698. isError = true;
  699. }
  700. break;
  701. case 'host':
  702. var hiveOozieHostNames = ['hive_hostname','hive_existing_mysql_host','hive_existing_oracle_host','hive_ambari_host',
  703. 'oozie_hostname','oozie_existing_mysql_host','oozie_existing_oracle_host','oozie_ambari_host'];
  704. if(hiveOozieHostNames.contains(this.get('name'))) {
  705. if (validator.hasSpaces(value)) {
  706. this.set('errorMessage', Em.I18n.t('host.spacesValidation'));
  707. isError = true;
  708. }
  709. } else {
  710. if (validator.isNotTrimmed(value)) {
  711. this.set('errorMessage', Em.I18n.t('host.trimspacesValidation'));
  712. isError = true;
  713. }
  714. }
  715. break;
  716. case 'advanced':
  717. if(this.get('name')=='javax.jdo.option.ConnectionURL' || this.get('name')=='oozie.service.JPAService.jdbc.url') {
  718. if (validator.isNotTrimmed(value)) {
  719. this.set('errorMessage', Em.I18n.t('host.trimspacesValidation'));
  720. isError = true;
  721. }
  722. }
  723. break;
  724. case 'password':
  725. // retypedPassword is set by the retypePasswordView child view of App.ServiceConfigPasswordField
  726. if (value !== this.get('retypedPassword')) {
  727. this.set('errorMessage', 'Passwords do not match');
  728. isError = true;
  729. }
  730. }
  731. }
  732. if (!isError) {
  733. // Check if this value is already in any of the overrides
  734. var self = this;
  735. var isOriginalSCP = this.get('isOriginalSCP');
  736. var parentSCP = this.get('parentSCP');
  737. if (!isOriginalSCP) {
  738. if (!isError && parentSCP != null) {
  739. if (value === parentSCP.get('value')) {
  740. this.set('errorMessage', 'Configuration overrides must have different value');
  741. isError = true;
  742. } else {
  743. var overrides = parentSCP.get('overrides');
  744. overrides.forEach(function (override) {
  745. if (self != override && value === override.get('value')) {
  746. self.set('errorMessage', 'Multiple configuration overrides cannot have same value');
  747. isError = true;
  748. }
  749. });
  750. }
  751. }
  752. }
  753. }
  754. var serviceValidator = this.get('serviceValidator');
  755. if (serviceValidator!=null) {
  756. var validationIssue = serviceValidator.validateConfig(this);
  757. if (validationIssue) {
  758. this.set('warnMessage', validationIssue);
  759. isWarn = true;
  760. }
  761. }
  762. if (!isWarn || isError) { // Errors get priority
  763. this.set('warnMessage', '');
  764. this.set('warn', false);
  765. } else {
  766. this.set('warn', true);
  767. }
  768. if (!isError) {
  769. this.set('errorMessage', '');
  770. this.set('error', false);
  771. } else {
  772. this.set('error', true);
  773. }
  774. }.observes('value', 'retypedPassword')
  775. });
  776. App.ConfigSiteTag = Ember.Object.extend({
  777. site: DS.attr('string'),
  778. tag: DS.attr('string'),
  779. /**
  780. * Object map of hostname->override-tag for overrides.
  781. * <b>Creators should set new object here.<b>
  782. */
  783. hostOverrides: null
  784. });