diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/helpers/get-from-map.js b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/helpers/get-from-map.js new file mode 100644 index 0000000000000..440a9a0cab0a7 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/helpers/get-from-map.js @@ -0,0 +1,72 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Ember from 'ember'; + + +function getNestedValue(obj, path) { + return path.split('.').reduce((acc, key) => { + if (acc === null || acc === undefined) { + return undefined; + } + + /* Handle array indexing. + Sample input data: + { + "partitionKey": { + "configuredMinResource": { + "resourceInformations": { + "resourceInformation": [ + { + "maximumAllocation": 1024 + }, + { + "maximumAllocation": 88 + } + ] + } + } + } + } + */ + const arrayMatch = key.match(/(\w+)\[(\d+)\]/); + if (arrayMatch) { + const arrayKey = arrayMatch[1]; + const arrayIndex = parseInt(arrayMatch[2], 10); + return acc[arrayKey] && acc[arrayKey][arrayIndex]; + } + + return acc[key]; + }, obj); +} + +export function getFromMap(params, hash) { + /* + Extract map values based on the key provided and the path to the nested value + Example: + XPATH from the metrics: /scheduler/schedulerInfo/capacities/queueCapacitiesByPartition[3]/configuredMinResource/resourceInformations/resourceInformation[2]/maximumAllocation + The partition map is: queueCapacitiesByPartition and accessed as "partitionMap" from the code defined in the models/yarn-queue/capacity-queue.js + The supplied hash.map is partitionMap + The supplied key is the partition name (nodelabel), e.g. "customPartition" + The parameter is "configuredMinResource/resourceInformations/resourceInformation[2]/maximumAllocation" + The returned value is the value of the maximumAllocation, which in this case will be the number of vCores present. + */ + return getNestedValue(hash.map[hash.key], hash.parameter); +} + +export default Ember.Helper.helper(getFromMap); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/templates/components/partition-usage.hbs b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/templates/components/partition-usage.hbs new file mode 100644 index 0000000000000..8d6246e699eaa --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/templates/components/partition-usage.hbs @@ -0,0 +1,66 @@ +{! + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +}} +
+
+
+
+ {{model.firstObject.type}} scheduler - Partition usage overview +
+
+ {{log module.exports}} + {{#if (eq model.firstObject.type "capacity")}} + + + + + + + + + + + + + {{#each model.firstObject.partitions as |part|}} + + + + + + + {{/each}} + +
Partition NameResource Used from the PartitionTotal Resource in the Partition
{{part}}{{getFromMap map=model.firstObject.partitionMap key=part parameter="usedCapacity" }}% + {{#each (getFromMap map=model.firstObject.partitionMap key=part parameter="effectiveMaxResource.resourceInformations.resourceInformation") as |resource|}} + + {{resource.name}} + {{resource.value}} + + {{/each}} +
+ + {{/if}} +
+
+
+
+ +{{yield}} \ No newline at end of file diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/templates/components/yarn-queue/capacity-queue.hbs b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/templates/components/yarn-queue/capacity-queue.hbs index 6615b1dbd4a22..d9f79e98005a0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/templates/components/yarn-queue/capacity-queue.hbs +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/app/templates/components/yarn-queue/capacity-queue.hbs @@ -16,6 +16,8 @@ * limitations under the License. }} +{{partition-usage model=model.queues}} + {{queue-navigator model=model.queues selected=model.selected used="usedCapacity" max="absMaxCapacity" setFilter=(action setFilter)}} @@ -32,7 +34,7 @@ {{/if}} - {{yarn-queue-partition-capacity-labels partitionMap=model.selectedQueue.partitionMap queue=model.selectedQueue filteredPartition=filteredPartition}} + {{yarn-queue-partition-capacity-labels partitionMap=model.selectedQueue.partitionMap resourceUsagesByPartitionMap=model.selectedQueue.resourceUsagesByPartitionMap queue=model.selectedQueue filteredPartition=filteredPartition}}
Running Apps From All Users in Queue
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/tests/unit/helpers/get-from-map-test.js b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/tests/unit/helpers/get-from-map-test.js new file mode 100644 index 0000000000000..499a205f82b91 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-ui/src/main/webapp/tests/unit/helpers/get-from-map-test.js @@ -0,0 +1,28 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { getFromMap } from '../../../helpers/get-from-map'; +import { module, test } from 'qunit'; + +module('Unit | Helper | get from map'); + +// Replace this with your real tests. +test('it works', function(assert) { + let result = getFromMap(42); + assert.ok(result); +}); \ No newline at end of file