yarn-component-instance.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. import DS from 'ember-data';
  19. export default DS.JSONAPISerializer.extend({
  20. internalNormalizeSingleResponse(store, primaryModelClass, payload) {
  21. var info = payload.info;
  22. var fixedPayload = {
  23. id: 'yarn_component_instance_' + payload.id,
  24. type: primaryModelClass.modelName,
  25. attributes: {
  26. containerId: payload.id,
  27. component: info.COMPONENT_NAME,
  28. instanceName: info.COMPONENT_NAME + '_' + payload.instanceId,
  29. state: info.STATE,
  30. createdTimestamp: payload.createdtime,
  31. startedTimestamp: info.LAUNCH_TIME,
  32. host: info.HOSTNAME,
  33. node: info.BARE_HOST,
  34. hostUrl: 'N/A',
  35. ipAddr: info.IP,
  36. exitStatusCode: info.EXIT_STATUS_CODE
  37. }
  38. };
  39. return fixedPayload;
  40. },
  41. normalizeArrayResponse(store, primaryModelClass, payload/*, id, requestType*/) {
  42. var normalizedResponse = {data: []};
  43. var instanceUid = {};
  44. if (payload && Array.isArray(payload)) {
  45. this.sortPayloadByCreatedTimeAscending(payload);
  46. payload.forEach(function(container) {
  47. let componentName = container.info.COMPONENT_NAME;
  48. if (!instanceUid[componentName]) {
  49. instanceUid[componentName] = 0;
  50. }
  51. container.instanceId = ++instanceUid[componentName];
  52. var pl = this.internalNormalizeSingleResponse(store, primaryModelClass, container);
  53. normalizedResponse.data.push(pl);
  54. }.bind(this));
  55. }
  56. return normalizedResponse;
  57. },
  58. sortPayloadByCreatedTimeAscending(payload) {
  59. payload.sort(function(inst1, inst2) {
  60. return inst1.createdtime - inst2.createdtime;
  61. });
  62. }
  63. });