app.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // Application bootstrapper
  19. module.exports = Em.Application.create({
  20. name: 'Ambari Web',
  21. rootElement: '#wrapper',
  22. store: DS.Store.create({
  23. revision: 4,
  24. adapter: DS.FixtureAdapter.create({
  25. simulateRemoteResponse: false
  26. })
  27. }),
  28. isAdmin: false,
  29. /**
  30. * return url prefix with number value of version of HDP stack
  31. */
  32. stackVersionURL:function(){
  33. var stackVersion = this.get('currentStackVersion') || this.get('defaultStackVersion');
  34. if(stackVersion.indexOf('HDPLocal') !== -1){
  35. return '/stacks/HDPLocal/version/' + stackVersion.replace(/HDPLocal-/g, '');
  36. }
  37. return '/stacks/HDP/version/' + stackVersion.replace(/HDP-/g, '');
  38. }.property('currentStackVersion'),
  39. /**
  40. * return url prefix with number value of version of HDP stack
  41. */
  42. stack2VersionURL:function(){
  43. var stackVersion = this.get('currentStackVersion') || this.get('defaultStackVersion');
  44. if(stackVersion.indexOf('HDPLocal') !== -1){
  45. return '/stacks2/HDPLocal/versions/' + stackVersion.replace(/HDPLocal-/g, '');
  46. }
  47. return '/stacks2/HDP/versions/' + stackVersion.replace(/HDP-/g, '');
  48. }.property('currentStackVersion'),
  49. clusterName: null,
  50. currentStackVersion: '',
  51. currentStackVersionNumber: function(){
  52. return this.get('currentStackVersion').replace(/HDP(Local)?-/, '');
  53. }.property('currentStackVersion')
  54. });
  55. /**
  56. * Ambari overrides the default date transformer.
  57. * This is done because of the non-standard data
  58. * sent. For example Nagios sends date as "12345678".
  59. * The problem is that it is a String and is represented
  60. * only in seconds whereas Javascript's Date needs
  61. * milliseconds representation.
  62. */
  63. DS.attr.transforms.date = {
  64. from: function (serialized) {
  65. var type = typeof serialized;
  66. if (type === "string") {
  67. serialized = parseInt(serialized);
  68. type = typeof serialized;
  69. }
  70. if (type === "number") {
  71. // The number could be seconds or milliseconds.
  72. // If seconds, then multiplying with 1000 should still
  73. // keep it below the current time.
  74. if (serialized * 1000 < new Date().getTime()) {
  75. serialized = serialized * 1000;
  76. }
  77. return new Date(serialized);
  78. } else if (serialized === null || serialized === undefined) {
  79. // if the value is not present in the data,
  80. // return undefined, not null.
  81. return serialized;
  82. } else {
  83. return null;
  84. }
  85. },
  86. to: function (deserialized) {
  87. if (deserialized instanceof Date) {
  88. return deserialized.getTime();
  89. } else if (deserialized === undefined) {
  90. return undefined;
  91. } else {
  92. return null;
  93. }
  94. }
  95. }
  96. DS.attr.transforms.object = {
  97. from: function(serialized) {
  98. return Ember.none(serialized) ? null : Object(serialized);
  99. },
  100. to: function(deserialized) {
  101. return Ember.none(deserialized) ? null : Object(deserialized);
  102. }
  103. };