3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 "objType": "container",
29 "objType": "container",
38 "objType": "container",
55 "objType": "leaf-list"
59 "objType": "container",
63 "trusted-execution": {
66 "cpu-pinning-policy": {
69 "cpu-thread-pinning-policy": {
76 "objType": "container",
84 module
.exports
= function aggregateEPA(vdur
, data
) {
85 var data
= data
|| {};
86 var schema
= EpaSchema
;
87 var findLeaf = function(obj
, schema
, data
) {
89 var epaSchema
= schema
[k
];
90 //if key exists in schema
95 switch (epaSchema
.objType
) {
97 findLeaf(obj
[k
], epaSchema
, data
[k
]);
100 aggregateValue(obj
[k
].toString(), data
[k
]);
103 aggregateLeafListValue(obj
[k
], data
[k
]);
106 aggregateListValue(k
, obj
[k
], data
[k
]);
109 aggregateChoiceValue(obj
[k
], data
[k
]);
117 vdur
.map(function(vm
) {
118 findLeaf(vm
, schema
, data
)
127 function aggregateChoiceValue(obj
, data
) {
129 aggregateValue(k
, data
)
133 function aggregateValue(value
, data
) {
134 value
= value
.toString();
135 if (!data
[value
]) data
[value
] = {};
136 var total
= data
[value
];
137 total
.total
= (!total
.total
) ? 1 : total
.total
+ 1;
140 function aggregateListValue(k
, value
, data
) {
141 if (value
.length
> 0) {
142 aggregateValue(k
, data
);
146 function aggregateLeafListValue(obj
, data
) {
147 if (obj
.constructor.name
== "Array") {
148 obj
.map(function(p
) {
149 aggregateValue(p
, data
);
152 console
.log("Oops, something went wrong here. An object was passed that wasn't an Array. Are you sure it was leaf-list?")