step1_controller.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. App.ajax.send({
  68. name: 'reassign.load_configs',
  69. sender: this,
  70. data: {
  71. urlParams: urlParams.join('|')
  72. },
  73. success: 'onLoadConfigs',
  74. error: ''
  75. });
  76. },
  77. onLoadConfigs: function (data) {
  78. var databaseProperty = null,
  79. databaseType = null,
  80. properties = {},
  81. isRemoteDB = null;
  82. data.items.forEach(function(item) {
  83. $.extend(properties, item.properties);
  84. });
  85. this.set('content.serviceProperties', properties);
  86. databaseProperty = properties[ this.dbProperty() ];
  87. databaseType = databaseProperty.match(/MySQL|PostgreS|Oracle|Derby|MSSQL/gi)[0];
  88. this.set('databaseType', databaseType);
  89. if (databaseType !== 'derby') {
  90. App.router.reassignMasterController.set('content.hasManualSteps', false);
  91. }
  92. var serviceDbProp = this.get('content.reassign.service_id').toLowerCase() + "_database";
  93. properties['is_remote_db'] = /Existing/ig.test( properties[serviceDbProp] );
  94. properties['database_hostname'] = this.getDatabaseHost();
  95. this.saveDatabaseType(databaseType);
  96. this.saveServiceProperties(properties);
  97. },
  98. saveDatabaseType: function(type) {
  99. if(type) {
  100. App.router.get(this.get('content.controllerName')).saveDatabaseType(type);
  101. }
  102. },
  103. saveServiceProperties: function(properties) {
  104. if(properties) {
  105. App.router.get(this.get('content.controllerName')).saveServiceProperties(properties);
  106. }
  107. },
  108. getDatabaseHost: function() {
  109. var db_type = this.get('databaseType');
  110. var connectionURLPRops = {
  111. 'HIVE': 'javax.jdo.option.ConnectionURL',
  112. 'OOZIE': 'oozie.service.JPAService.jdbc.url'
  113. };
  114. var service = this.get('content.reassign.service_id');
  115. var connectionURL = this.get('content.serviceProperties')[connectionURLPRops[service]];
  116. connectionURL = connectionURL.replace("jdbc:" + db_type + "://", "");
  117. connectionURL = connectionURL.replace("/hive?createDatabaseIfNotExist=true", "");
  118. connectionURL = connectionURL.replace("/oozie", "");
  119. return connectionURL;
  120. }
  121. });