blueprint.js 2.3 KB

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