step1_controller.js 4.7 KB

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