blob: 8883bcbbf70331c53793702272dd5068891c4dfa [file] [log] [blame]
Carsten Ziegelerdb301862011-11-18 09:40:49 +00001<!--
2/*
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 */
20-->
Arjun Panday594e8242011-12-29 20:57:25 +000021<html>
Carsten Ziegelerdb301862011-11-18 09:40:49 +000022<header>
Arjun Panday594e8242011-12-29 20:57:25 +000023 <script type="text/javascript" src="/servicegraph/js/jquery-1.7.1.min.js"></script>
24 <script type="text/javascript" src="/servicegraph/js/raphael-1.3.1.min.js"></script>
25 <script type="text/javascript" src="/servicegraph/js/graffle-1.3.1.js"></script>
Carsten Ziegelerdb301862011-11-18 09:40:49 +000026 <script type="text/javascript" src="/servicegraph/js/graph.js"></script>
Carsten Ziegelerdb301862011-11-18 09:40:49 +000027 <script type="text/javascript">
28<!--
29
30var _redraw;
31var height = 600;
32var width = 1000;
33
34DEBUG = false;
35debug = function (obj) { if(DEBUG && console) console.debug(obj); }
36
37var services;
38
39// from graph demo @ http://blog.ameisenbar.de/en/2010/03/02/dracula/
40function graphUnavail(json) {
41 var g = new Graph();
42
43 var empty = true;
Arjun Panday0462b392012-11-07 18:55:10 +000044 notavail = json.notavail;
45 for (s in notavail) {
Carsten Ziegelerdb301862011-11-18 09:40:49 +000046 empty = false;
Arjun Panday0462b392012-11-07 18:55:10 +000047 for (i = 0; i < notavail[s].length; i++) {
Carsten Ziegelerdb301862011-11-18 09:40:49 +000048 // point unregistered service to dependency name
Arjun Panday0462b392012-11-07 18:55:10 +000049 var dep = notavail[s][i];
Arjun Panday594e8242011-12-29 20:57:25 +000050 g.addNode(dep, {
51 getShape : function(r,x,y) {
52 // create a dashed square shape to differentiate the missing dependency
53 return r.rect(x-30, y-13, 62, 33, 5).attr({
54 "fill": "#f00",
55 "stroke": "gray",
56 "stroke-width": 2,
57 "stroke-dasharray": "--"
58 });
59 }
60 });
61 g.addEdge(s, dep, { directed : true } );
Carsten Ziegelerdb301862011-11-18 09:40:49 +000062 }
63 }
Arjun Panday0462b392012-11-07 18:55:10 +000064 // show unresolved
65 var unresolved = json.unresolved
66 if (unresolved) for (s in unresolved) {
Arjun Pandaybbc976e2012-11-08 16:25:44 +000067 $("#warning").html("circular dependencies detected!");
Arjun Panday0462b392012-11-07 18:55:10 +000068 for (i = 0; i < unresolved[s].length; i++) {
69 g.addEdge(s, unresolved[s][i], { directed : true } );
70 }
71 }
Carsten Ziegelerdb301862011-11-18 09:40:49 +000072
73 if (empty) {
74 $("#canvas").empty().append($("<h1>").html("Service Registry status OK: No unresolved service found."));
75 }
76 else showGraph(g)
77}
78
79function graphAllServices(json) {
80 var g = new Graph();
81
82 var empty = true;
83 for (s in json) {
84 empty = false;
85 for (i = 0; i < json[s].length; i++) {
86 // point using bundle to service name
Arjun Panday594e8242011-12-29 20:57:25 +000087 var bundle = json[s][i];
88 g.addNode(bundle, {
89 getShape : function(r,x,y) {
90 // create a square shape to differentiate bundles from services
91 return r.rect(x-30, y-13, 62, 33, 5).attr({"fill": "#f00", "stroke-width": 2});
92 }
93 });
94 g.addEdge(bundle, s, { directed : true } );
Carsten Ziegelerdb301862011-11-18 09:40:49 +000095 }
96 }
97
98 if (empty) {
99 $("#canvas").empty().append($("<h1>").html("Service Registry empty: no service found."));
100 }
101 else showGraph(g)
102}
103
104function showGraph(g) {
105 debug(g);
106
107 /* layout the graph using the Spring layout implementation */
108 var layouter = new Graph.Layout.Spring(g);
109 layouter.layout();
110
111 /* draw the graph using the RaphaelJS draw implementation */
112 $("#canvas").empty();
113 var renderer = new Graph.Renderer.Raphael('canvas', g, width, height);
114 renderer.draw();
115
116 _redraw = function() {
117 layouter.layout();
118 renderer.draw();
119 };
120}
121
122function redraw() {
123 var filter = $("#filter").val();
124 if (filter) {
125 var grep = {};
126 for (s in services) if (s.indexOf(filter) >= 0) grep[s] = services[s];
127 graphAllServices(grep);
128 } else {
129 graphAllServices(services);
130 }
131}
132
133function loadUnavail() {
134 $("#canvas").html("Loading data. Please wait...");
135 $.ajax({
136 url: "/servicegraph/json/notavail",
137 dataType: "json",
138 success: function(json){
139 services = json;
140 debug("Got services");
141 debug(json);
142 graphUnavail(json);
143 }
144 });
145}
146
147function loadAllServices() {
148 $("#canvas").html("Loading data. Please wait...");
149 $.ajax({
150 url: "/servicegraph/json/all",
151 dataType: "json",
152 success: function(json){
153 services = json;
154 debug("Got services");
155 debug(json);
156 graphAllServices(json);
157 }
158 });
159}
160
161/* only do all this when document has finished loading (needed for RaphaelJS) */
162$(document).ready(function(){
163 $("#actions")
Arjun Panday0462b392012-11-07 18:55:10 +0000164 .append($("<a>").attr("href", "javascript:loadAllServices()").html("Show Service Registry"))
Arjun Panday594e8242011-12-29 20:57:25 +0000165 .append($("<span>").html("&nbsp;|&nbsp;"))
Arjun Panday0462b392012-11-07 18:55:10 +0000166 .append($("<a>").attr("href", "javascript:loadUnavail()").html("Show Not Avail"))
Carsten Ziegelerdb301862011-11-18 09:40:49 +0000167});
168
169-->
170 </script>
Arjun Panday0462b392012-11-07 18:55:10 +0000171 <style>
172 #actions a { color:black; font-weight:bold; text-decoration:none; }
173 #warning { color:red; font-weight:bold; }
174 </style>
Carsten Ziegelerdb301862011-11-18 09:40:49 +0000175</header>
176<body>
177Filter:&nbsp;<input type="text" id="filter"/><button id="redraw" onclick="redraw();">redraw</button>
178&nbsp;&nbsp;<span id="actions"></span>
Arjun Panday0462b392012-11-07 18:55:10 +0000179&nbsp;&nbsp;<span id="warning"></span>
Carsten Ziegelerdb301862011-11-18 09:40:49 +0000180<div id="canvas"></div>
181</body>
Arjun Panday594e8242011-12-29 20:57:25 +0000182</html>