service_config.js 33 KB

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