step7_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. /**
  20. * By Step 7, we have the following information stored in App.db and set on this
  21. * controller by the router.
  22. *
  23. * selectedServices: App.db.selectedServices (the services that the user selected in Step 4)
  24. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  25. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  26. *
  27. */
  28. App.WizardStep7Controller = Em.Controller.extend({
  29. name: 'wizardStep7Controller',
  30. stepConfigs: [], //contains all field properties that are viewed in this step
  31. selectedService: null,
  32. slaveHostToGroup: null,
  33. isSubmitDisabled: function () {
  34. return !this.stepConfigs.everyProperty('errorCount', 0);
  35. }.property('stepConfigs.@each.errorCount'),
  36. selectedServiceNames : function(){
  37. return this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  38. }.property('content.services').cacheable(),
  39. masterComponentHosts : function(){
  40. return this.get('content.masterComponentHosts');
  41. }.property('content.masterComponentHosts'),
  42. slaveComponentHosts : function(){
  43. return this.get('content.slaveComponentHosts');
  44. }.property('content.slaveComponentHosts'),
  45. serviceConfigs: require('data/service_configs'),
  46. clearStep: function () {
  47. this.get('stepConfigs').clear();
  48. },
  49. /**
  50. * On load function
  51. */
  52. loadStep: function () {
  53. console.log("TRACE: Loading step7: Configure Services");
  54. this.clearStep();
  55. this.renderServiceConfigs(this.serviceConfigs);
  56. var storedServices = this.get('content.serviceConfigProperties');
  57. if (storedServices) {
  58. var configs = new Ember.Set();
  59. // for all services`
  60. this.get('stepConfigs').forEach(function (_content) {
  61. //for all components
  62. _content.get('configs').forEach(function (_config) {
  63. var componentVal = storedServices.findProperty('name', _config.get('name'));
  64. //if we have config for specified component
  65. if(componentVal){
  66. //set it
  67. _config.set('value', componentVal.value)
  68. }
  69. }, this);
  70. }, this);
  71. }
  72. },
  73. /**
  74. * Render configs for active services
  75. * @param serviceConfigs
  76. */
  77. renderServiceConfigs: function (serviceConfigs) {
  78. serviceConfigs.forEach(function (_serviceConfig) {
  79. var serviceConfig = App.ServiceConfig.create({
  80. serviceName: _serviceConfig.serviceName,
  81. displayName: _serviceConfig.displayName,
  82. configCategories: _serviceConfig.configCategories,
  83. configs: []
  84. });
  85. if (this.get('selectedServiceNames').contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  86. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  87. console.log('pushing ' + serviceConfig.serviceName);
  88. this.get('stepConfigs').pushObject(serviceConfig);
  89. } else {
  90. console.log('skipping ' + serviceConfig.serviceName);
  91. }
  92. }, this);
  93. this.set('selectedService', this.get('stepConfigs').objectAt(0));
  94. },
  95. /**
  96. * Load child components to service config object
  97. * @param _componentConfig
  98. * @param componentConfig
  99. */
  100. loadComponentConfigs: function (_componentConfig, componentConfig) {
  101. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  102. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  103. serviceConfigProperty.serviceConfig = componentConfig;
  104. serviceConfigProperty.initialValue();
  105. componentConfig.configs.pushObject(serviceConfigProperty);
  106. serviceConfigProperty.validate();
  107. }, this);
  108. },
  109. submit: function () {
  110. if (!this.get('isSubmitDisabled')) {
  111. App.router.send('next');
  112. }
  113. }
  114. });