4fee9dab9975808c55a4d889b8db44359d6b0fd0
[ccsdk/features.git] /
1 /**
2  * Copyright 2010-2013 Ben Birch
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this software except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16         (function( app ) {
17
18         var services = app.ns("services");
19         var ux = app.ns("ux");
20
21         services.ClusterState = ux.Observable.extend({
22                 defaults: {
23                         cluster: null
24                 },
25                 init: function() {
26                         this._super();
27                         this.cluster = this.config.cluster;
28                         this.clusterState = null;
29                         this.status = null;
30                         this.nodeStats = null;
31                         this.clusterNodes = null;
32                 },
33                 refresh: function() {
34                         var self = this, clusterState, status, nodeStats, clusterNodes, clusterHealth;
35                         function updateModel() {
36                                 if( clusterState && status && nodeStats && clusterNodes && clusterHealth ) {
37                                         this.clusterState = clusterState;
38                                         this.status = status;
39                                         this.nodeStats = nodeStats;
40                                         this.clusterNodes = clusterNodes;
41                                         this.clusterHealth = clusterHealth;
42                                         this.fire( "data", this );
43                                 }
44                         }
45                         this.cluster.get("_cluster/state", function( data ) {
46                                 clusterState = data;
47                                 updateModel.call( self );
48                         });
49                         this.cluster.get("_stats", function( data ) {
50                                 status = data;
51                                 updateModel.call( self );
52                         });
53                         this.cluster.get("_nodes/stats", function( data ) {
54                                 nodeStats = data;
55                                 updateModel.call( self );
56                         });
57                         this.cluster.get("_nodes", function( data ) {
58                                 clusterNodes = data;
59                                 updateModel.call( self );
60                         });
61                         this.cluster.get("_cluster/health", function( data ) {
62                                 clusterHealth = data;
63                                 updateModel.call( self );
64                         });
65                 },
66                 _clusterState_handler: function(state) {
67                         this.clusterState = state;
68                         this.redraw("clusterState");
69                 },
70                 _status_handler: function(status) {
71                         this.status = status;
72                         this.redraw("status");
73                 },
74                 _clusterNodeStats_handler: function(stats) {
75                         this.nodeStats = stats;
76                         this.redraw("nodeStats");
77                 },
78                 _clusterNodes_handler: function(nodes) {
79                         this.clusterNodes = nodes;
80                         this.redraw("clusterNodes");
81                 },
82                 _clusterHealth_handler: function(health) {
83                         this.clusterHealth = health;
84                         this.redraw("status");
85                 }
86         });
87
88 })( this.app );