blueprint.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 blueprintUtils = require('utils/blueprint');
  20. var dataManipulation = require('utils/data_manipulation');
  21. App.BlueprintMixin = Em.Mixin.create({
  22. /**
  23. * returns blueprint for all currently installed master, slave and client components
  24. * @method getCurrentMasterSlaveBlueprint
  25. */
  26. getCurrentMasterSlaveBlueprint: function () {
  27. var components = App.HostComponent.find();
  28. var hosts = components.mapProperty("hostName").uniq();
  29. var mappedComponents = dataManipulation.groupPropertyValues(components, 'hostName');
  30. var res = {
  31. blueprint: { host_groups: [] },
  32. blueprint_cluster_binding: { host_groups: [] }
  33. };
  34. hosts.forEach(function (host, i) {
  35. var group_name = 'host-group-' + (i + 1);
  36. res.blueprint.host_groups.push({
  37. name: group_name,
  38. components: mappedComponents[host] ? mappedComponents[host].map(function (c) {
  39. return { name: Em.get(c, 'componentName') };
  40. }) : []
  41. });
  42. res.blueprint_cluster_binding.host_groups.push({
  43. name: group_name,
  44. hosts: [
  45. { fqdn: host }
  46. ]
  47. });
  48. });
  49. return res;
  50. },
  51. /**
  52. * Returns blueprint for all currently installed slave and client components
  53. */
  54. getCurrentSlaveBlueprint: function () {
  55. var self = this;
  56. var fullBlueprint = self.getCurrentMasterSlaveBlueprint();
  57. var components = App.StackServiceComponent.find().filter(function (c) {
  58. return c.get('isSlave') || c.get('isClient');
  59. }).mapProperty("componentName");
  60. return blueprintUtils.filterByComponents(fullBlueprint, components);
  61. }
  62. });