app.js 4.2 KB

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