step1_controller.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. App.ReassignMasterWizardStep1Controller = Em.Controller.extend({
  20. name: 'reassignMasterWizardStep1Controller',
  21. databaseType: null,
  22. /**
  23. * @type {object}
  24. */
  25. dbPropertyMap: {
  26. 'HIVE_SERVER': 'javax.jdo.option.ConnectionDriverName',
  27. 'HIVE_METASTORE': 'javax.jdo.option.ConnectionDriverName',
  28. 'OOZIE_SERVER': 'oozie.service.JPAService.jdbc.driver'
  29. },
  30. loadConfigsTags: function () {
  31. App.ajax.send({
  32. name: 'config.tags',
  33. sender: this,
  34. success: 'onLoadConfigsTags',
  35. error: ''
  36. });
  37. },
  38. /**
  39. * construct URL parameters for config call
  40. * @param componentName
  41. * @param data
  42. * @return {Array}
  43. */
  44. getConfigUrlParams: function (componentName, data) {
  45. var urlParams = [];
  46. switch (componentName) {
  47. case 'OOZIE_SERVER':
  48. urlParams.push('(type=oozie-site&tag=' + data.Clusters.desired_configs['oozie-site'].tag + ')');
  49. urlParams.push('(type=oozie-env&tag=' + data.Clusters.desired_configs['oozie-env'].tag + ')');
  50. break;
  51. case 'HIVE_SERVER':
  52. case 'HIVE_METASTORE':
  53. urlParams.push('(type=hive-site&tag=' + data.Clusters.desired_configs['hive-site'].tag + ')');
  54. urlParams.push('(type=hive-env&tag=' + data.Clusters.desired_configs['hive-env'].tag + ')');
  55. break;
  56. }
  57. return urlParams;
  58. },
  59. onLoadConfigsTags: function (data) {
  60. var urlParams = this.getConfigUrlParams(this.get('content.reassign.component_name'), data);
  61. if (urlParams.length > 0) {
  62. App.ajax.send({
  63. name: 'reassign.load_configs',
  64. sender: this,
  65. data: {
  66. urlParams: urlParams.join('|')
  67. },
  68. success: 'onLoadConfigs',
  69. error: ''
  70. });
  71. }
  72. },
  73. onLoadConfigs: function (data) {
  74. var databaseProperty = null,
  75. databaseType = null,
  76. properties = {},
  77. isRemoteDB = null;
  78. data.items.forEach(function(item) {
  79. $.extend(properties, item.properties);
  80. });
  81. this.set('content.serviceProperties', properties);
  82. databaseProperty = properties[ Em.getWithDefault(this.get('dbPropertyMap'), this.get('content.reassign.component_name'), null) ];
  83. databaseType = databaseProperty.match(/MySQL|PostgreS|Oracle|Derby|MSSQL|Anywhere/gi)[0];
  84. this.set('databaseType', databaseType);
  85. if (this.get('content.reassign.component_name') == 'OOZIE_SERVER' && databaseType !== 'derby') {
  86. App.router.reassignMasterController.set('content.hasManualSteps', false);
  87. }
  88. var serviceDbProp = this.get('content.reassign.service_id').toLowerCase() + "_database";
  89. properties['is_remote_db'] = /Existing/ig.test( properties[serviceDbProp] );
  90. properties['database_hostname'] = this.getDatabaseHost();
  91. this.saveDatabaseType(databaseType);
  92. this.saveServiceProperties(properties);
  93. },
  94. saveDatabaseType: function(type) {
  95. if(type) {
  96. App.router.get(this.get('content.controllerName')).saveDatabaseType(type);
  97. }
  98. },
  99. saveServiceProperties: function(properties) {
  100. if(properties) {
  101. App.router.get(this.get('content.controllerName')).saveServiceProperties(properties);
  102. }
  103. },
  104. getDatabaseHost: function() {
  105. var db_type = this.get('databaseType');
  106. var connectionURLPRops = {
  107. 'HIVE': 'javax.jdo.option.ConnectionURL',
  108. 'OOZIE': 'oozie.service.JPAService.jdbc.url'
  109. };
  110. var service = this.get('content.reassign.service_id');
  111. var connectionURL = this.get('content.serviceProperties')[connectionURLPRops[service]];
  112. connectionURL = connectionURL.replace("jdbc:" + db_type + "://", "");
  113. connectionURL = connectionURL.replace("/hive?createDatabaseIfNotExist=true", "");
  114. connectionURL = connectionURL.replace("/oozie", "");
  115. return connectionURL;
  116. }
  117. });