1d7334e0fe3d16d50cf4e5fa7591dc1669d27f9d
[ccsdk/features.git] /
1         (function( app ) {
2
3         var services = app.ns("services");
4         var ux = app.ns("ux");
5
6         services.ClusterState = ux.Observable.extend({
7                 defaults: {
8                         cluster: null
9                 },
10                 init: function() {
11                         this._super();
12                         this.cluster = this.config.cluster;
13                         this.clusterState = null;
14                         this.status = null;
15                         this.nodeStats = null;
16                         this.clusterNodes = null;
17                 },
18                 refresh: function() {
19                         var self = this, clusterState, status, nodeStats, clusterNodes, clusterHealth;
20                         function updateModel() {
21                                 if( clusterState && status && nodeStats && clusterNodes && clusterHealth ) {
22                                         this.clusterState = clusterState;
23                                         this.status = status;
24                                         this.nodeStats = nodeStats;
25                                         this.clusterNodes = clusterNodes;
26                                         this.clusterHealth = clusterHealth;
27                                         this.fire( "data", this );
28                                 }
29                         }
30                         this.cluster.get("_cluster/state", function( data ) {
31                                 clusterState = data;
32                                 updateModel.call( self );
33                         });
34                         this.cluster.get("_stats", function( data ) {
35                                 status = data;
36                                 updateModel.call( self );
37                         });
38                         this.cluster.get("_nodes/stats", function( data ) {
39                                 nodeStats = data;
40                                 updateModel.call( self );
41                         });
42                         this.cluster.get("_nodes", function( data ) {
43                                 clusterNodes = data;
44                                 updateModel.call( self );
45                         });
46                         this.cluster.get("_cluster/health", function( data ) {
47                                 clusterHealth = data;
48                                 updateModel.call( self );
49                         });
50                 },
51                 _clusterState_handler: function(state) {
52                         this.clusterState = state;
53                         this.redraw("clusterState");
54                 },
55                 _status_handler: function(status) {
56                         this.status = status;
57                         this.redraw("status");
58                 },
59                 _clusterNodeStats_handler: function(stats) {
60                         this.nodeStats = stats;
61                         this.redraw("nodeStats");
62                 },
63                 _clusterNodes_handler: function(nodes) {
64                         this.clusterNodes = nodes;
65                         this.redraw("clusterNodes");
66                 },
67                 _clusterHealth_handler: function(health) {
68                         this.clusterHealth = health;
69                         this.redraw("status");
70                 }
71         });
72
73 })( this.app );