123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /**
- * 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.
- */
- var App = require('app');
- App.statusMapper = App.QuickDataMapper.create({
- model: App.HostComponent,
- componentServiceMap: {
- 'NAMENODE': 'HDFS',
- 'SECONDARY_NAMENODE': 'HDFS',
- 'DATANODE': 'HDFS',
- 'HDFS_CLIENT': 'HDFS',
- 'JOBTRACKER': 'MAPREDUCE',
- 'TASKTRACKER': 'MAPREDUCE',
- 'MAPREDUCE_CLIENT': 'MAPREDUCE',
- 'MAPREDUCE2_CLIENT': 'MAPREDUCE2',
- 'HISTORYSERVER': 'MAPREDUCE2',
- 'TEZ_CLIENT': 'TEZ',
- 'RESOURCEMANAGER': 'YARN',
- 'YARN_CLIENT': 'YARN',
- 'NODEMANAGER': 'YARN',
- 'ZOOKEEPER_SERVER': 'ZOOKEEPER',
- 'ZOOKEEPER_CLIENT': 'ZOOKEEPER',
- 'HBASE_MASTER': 'HBASE',
- 'HBASE_REGIONSERVER': 'HBASE',
- 'HBASE_CLIENT': 'HBASE',
- 'PIG': 'PIG',
- 'SQOOP': 'SQOOP',
- 'OOZIE_SERVER': 'OOZIE',
- 'OOZIE_CLIENT': 'OOZIE',
- 'HIVE_SERVER': 'HIVE',
- 'HIVE_METASTORE': 'HIVE',
- 'HIVE_CLIENT': 'HIVE',
- 'MYSQL_SERVER': 'HIVE',
- 'HCAT': 'HCATALOG',
- 'WEBHCAT_SERVER': 'WEBHCAT',
- 'NAGIOS_SERVER': 'NAGIOS',
- 'GANGLIA_SERVER': 'GANGLIA',
- 'GANGLIA_MONITOR': 'GANGLIA',
- 'KERBEROS_SERVER': 'KERBEROS',
- 'KERBEROS_ADMIN_CLIENT': 'KERBEROS',
- 'KERBEROS_CLIENT': 'KERBEROS',
- 'HUE_SERVER': 'HUE',
- 'HCFS_CLIENT': 'HCFS'
- },
- map: function (json) {
- console.time('App.statusMapper execution time');
- if (json.items) {
- var hostsCache = App.cache['Hosts'];
- var hostStatuses = {};
- var hostComponentStatuses = {};
- var addedHostComponents = [];
- var componentServiceMap = this.get('componentServiceMap');
- var currentComponentStatuses = {};
- var currentHostStatuses = {};
- var previousHostStatuses = App.cache['previousHostStatuses'];
- var previousComponentStatuses = App.cache['previousComponentStatuses'];
- var hostComponentsOnService = {};
- json.items.forEach(function (host) {
- //update hosts, which have status changed
- if (previousHostStatuses[host.Hosts.host_name] !== host.Hosts.host_status) {
- hostStatuses[host.Hosts.host_name] = host.Hosts.host_status;
- }
- currentHostStatuses[host.Hosts.host_name] = host.Hosts.host_status;
- var hostComponentsOnHost = [];
- host.host_components.forEach(function (host_component) {
- host_component.id = host_component.HostRoles.component_name + "_" + host_component.HostRoles.host_name;
- var existedComponent = previousComponentStatuses[host_component.id];
- var service = componentServiceMap[host_component.HostRoles.component_name];
- if (existedComponent) {
- //update host-components, which have status changed
- if (existedComponent !== host_component.HostRoles.state) {
- hostComponentStatuses[host_component.id] = host_component.HostRoles.state;
- }
- } else {
- addedHostComponents.push({
- id: host_component.id,
- component_name: host_component.HostRoles.component_name,
- work_status: host_component.HostRoles.state,
- host_id: host.Hosts.host_name,
- service_id: service
- });
- //update host-components only on adding due to Ember Data features
- if (hostsCache[host.Hosts.host_name]) hostsCache[host.Hosts.host_name].is_modified = true;
- }
- currentComponentStatuses[host_component.id] = host_component.HostRoles.state;
- //host-components to host relations
- hostComponentsOnHost.push(host_component.id);
- //host-component to service relations
- if (!hostComponentsOnService[service]) {
- hostComponentsOnService[service] = {
- host_components: [],
- running_host_components: [],
- unknown_host_components: []
- };
- }
- if (host_component.HostRoles.state === App.HostComponentStatus.started) {
- hostComponentsOnService[service].running_host_components.push(host_component.id);
- }
- if (host_component.HostRoles.state === App.HostComponentStatus.unknown) {
- hostComponentsOnService[service].unknown_host_components.push(host_component.id);
- }
- hostComponentsOnService[service].host_components.push(host_component.id);
- }, this);
- /**
- * updating relation between Host and his host-components
- */
- if (hostsCache[host.Hosts.host_name]) {
- hostsCache[host.Hosts.host_name].host_components = hostComponentsOnHost;
- }
- }, this);
- var hostComponents = App.HostComponent.find();
- var hosts = App.Host.find();
- hostComponents.forEach(function (hostComponent) {
- if (hostComponent) {
- var status = currentComponentStatuses[hostComponent.get('id')];
- //check whether component present in current response
- if (status) {
- //check whether component has status changed
- if (hostComponentStatuses[hostComponent.get('id')]) {
- hostComponent.set('workStatus', status);
- }
- } else {
- hostComponent.deleteRecord();
- App.store.commit();
- hostComponent.get('stateManager').transitionTo('loading');
- }
- }
- }, this);
- if (addedHostComponents.length) {
- App.store.loadMany(this.get('model'), addedHostComponents);
- }
- App.cache['previousHostStatuses'] = currentHostStatuses;
- App.cache['previousComponentStatuses'] = currentComponentStatuses;
- App.cache['hostComponentsOnService'] = hostComponentsOnService;
- hosts.forEach(function (host) {
- var status = hostStatuses[host.get('id')];
- if (status) {
- host.set('healthStatus', status);
- }
- });
- }
- console.timeEnd('App.statusMapper execution time');
- }
- });
|