summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-1.6/modules/domain-manager/src/main/resources/cloud-gadget.html
blob: 1936f9896caf99fde49b7d4d863e59f3907842fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<!--
    * 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.    
-->
<html>
<head>
<title>SCA Domain - Cloud</title>

<script type="text/javascript" src="../cloud-gadget/cloud-gadget.js"></script>
<script type="text/javascript" src="utils.js"></script>

<link rel="stylesheet" type="text/css" href="manager.css">
</head>

<body>
  <div id="cloudComposite">
  
  <form id="cloudCompositeForm">
    <div id="composites" ></div>
    <br>
    &gt;<a href="" id="addNodeLink">Add</a>
    &nbsp;<a href="" id="deleteNodeLink">Delete</a>
    &nbsp;&nbsp;
    <a href="" id="startNodeLink">Start</a>
    &nbsp;<a href="" id="stopNodeLink">Stop</a>
  </form>

  <div id="newNode" style="visibility: hidden;">
  <form id="newNodeForm">
    <table width="100%">
    <tr><th>Add a Node</th></tr>
    <tr><td>Add a node to the cloud. The node will run the SCA components declared in the specified composite.</td></tr>
    </table>
    <br>
    <table>
    <tr><td>Node name:</td><td><input type="text" name="nodeName" size="50"/></td><td>e.g. YourNode</td></tr>
    <tr><td>Node URI:</td><td><input type="text" name="nodeURI" size="50"/></td></td><td>e.g. http://yourhost:8080</td></tr>
    <tr><td>Composite namespace:</td><td><input type="text" name="compositeNamespace" size="50"/></td></td><td>e.g. http://your/namespace</td></tr>
    <tr><td>Composite name:</td><td><input type="text" name="compositeName" size="50"/></td></td><td>e.g. yourcomposite</td></tr>
    <tr><td>Contribution URI:</td><td><input type="text" name="contributionURI" size="50"/></td></td><td>e.g. yourcontrib, http://yourcontrib</td></tr>
    </table>
    <input id="addNodeButton" type="button" value="Add" />
  </form>
  </div>
  
  </div>
</body>

<script type="text/javascript">

	//@Reference
	var cloudComposite = new tuscany.sca.Reference("cloudComposite");
	
	//@Reference
	var domainComposite = new tuscany.sca.Reference("domainComposite");
	
	//@Reference
	var processCollection = new tuscany.sca.Reference("processCollection");
	
	var gadget = gadget(window, document);
	if (gadget.showStatus == null) {
		gadget.showStatus = true;
	}
	if (gadget.showConfigurations == null) {
		gadget.showConfigurations = true;
	}

	var cloudCompositeForm = elementByID(gadget, 'cloudCompositeForm');
	var compositesElement = elementByID(gadget, 'composites');
	var newNodeElement = elementByID(gadget, 'newNode');
	var newNodeForm = elementByID(gadget, 'newNodeForm');
	
	var nodeNames;
	var deployedComposites = new Array();
	
	function getNodes() {
		cloudComposite.get("", getNodesResponse);
	}
	
	function contributionURI(id) {
       var i = id.indexOf(';');
       return id.substring(10, i);
	}
	
	function compositeName(id) {
       var i = id.indexOf(';');
       return id.substring(i + 1);
	}
	
	function compositeLocalName(id) {
		name = compositeName(id); 
    	var i = name.indexOf(';');
    	return name.substring(i + 1);
	}
	
	function getNodesResponse(feed) {
		nodeNames = new Array();      
		if (feed != null) {
			var entries = feed.getElementsByTagName("entry");
			var composites = "";
			composites += '<table width="100%">';
			composites += '<tr><th>Node</th>';
			if (gadget.showStatus) {
				composites += '<th>Status</th>';
			}
			if (gadget.showComposites) {
				composites += '<th>Composite</th>';
			}
			if (gadget.showContributions) {
				composites += '<th>Contribution</th>';
			}
			if (gadget.showConfigurations) {
				composites += '<th>Node Config</th>';
			}
			composites += '</tr>';
			
			for (var i=0; i<entries.length; i++) {
				var nodeId = entries[i].getElementsByTagName("id")[0].firstChild.nodeValue;
				var links = entries[i].getElementsByTagName("link");
				var nodeLink = undefined;
				var compositeLink = undefined;
				var compositeId = "composite:undefined;undefined;undefined";
				var uri = '<span style="color: red">unknown</span>';
				var qname = undefined;
				for (var l = 0; l < links.length; l++) {
					var a = links[l].getAttribute('rel');
					if (a == undefined) {
					  nodeLink = links[l].getAttribute('href');
					} else if (a == 'related') {
					  compositeLink = links[l].getAttribute('href');
					  var c = compositeLink.indexOf('composite:');
					  compositeId = compositeLink.substring(c);
					  uri = contributionURI(compositeId);
					  qname = compositeName(compositeId);
					}
				}

				var nodeName = compositeLocalName(nodeId);
				nodeNames[i] = nodeName;
				
				var content = "";
				if (entries[i].getElementsByTagName("content")[0].firstChild != null) {
					content = entries[i].getElementsByTagName("content")[0].firstChild.nodeValue;
				}

				composites += '<tr>'
				if (content.indexOf('<span id="problem"') != -1) {
					composites += '<td><input name="composites" type="checkbox" value="' + nodeId + '">' +
											'<a href=\"' + nodeLink + '\">' + nodeName + '</a></td>';
					if (gadget.showStatus) {
						composites += '<td><span id="status_' + nodeName + '">unknown</span></td>';
					}
					if (gadget.showComposites) {
						composites += '<td>' + content + '</td>';
					}
					if (gadget.showContributions) {
						composites += '<td>' + uri + '</td>';
					}
				} else {
					composites += '<td><input name="composites" type="checkbox" value="' + nodeId + '">' +
											'<a href=\"' + nodeLink + '\">' + nodeName + '</a></td>';
					if (gadget.showStatus) {
						composites += '<td><span id="status_' + nodeName + '">unknown</span></td>';
					}
					if (gadget.showComposites) {
						composites += '<td><a href=\"' + compositeLink + '\">' + qname + '</a></td>';
					}
					if (gadget.showContributions) {
						composites += '<td><a href="/contribution/' + uri + '">' + uri + '</a></td>';
					}
				}
				if (gadget.showConfigurations) {
					composites += '<td><a href="/node-config/' + nodeName + '"><img src="icons/feed-icon.png" border="0"></a></td>';
				}
				composites += '</tr>';
			}
			composites += '</table>';
			compositesElement.innerHTML = composites;

			processCollection.get("", getProcessesResponse);
		}
	}
	
	function getProcessesResponse(feed) {
		if (feed != null) {
			var nodeStatus = new Array();
			
			var entries = feed.getElementsByTagName("entry");
			for (var i=0; i<entries.length; i++) {
				var nodeName = entries[i].getElementsByTagName("id")[0].firstChild.nodeValue;
				nodeStatus[nodeName] = 'started';
			}

			if (gadget.showStatus) {
				for (var i = 0; i < nodeNames.length; i++) {
					var element = elementByID(gadget, 'status_' + nodeNames[i]);
					var nodeName = nodeNames[i];
					if (nodeStatus[nodeName] == null) {
						element.innerHTML = '<span>stopped</span>';
					} else {
						element.innerHTML = '<span><a style="color: green" href="/processes/?node=' + nodeName + '">started</a></span>';
					}
				}
			}
		}
	}

	function deleteNode() {
		var composites  = array(cloudCompositeForm.composites);
		for (var i = 0; i < composites.length; i++) {
			if (composites[i].checked) {
			    var id = composites[i].value;
				cloudComposite.del(id, deleteNodeResponse);
			}
		}
		return false;
	}

	function deleteNodeResponse() {
	    getNodes();
	}	

	function addNode() {
		var nodeName = newNodeForm.nodeName.value;
		var nodeURI = newNodeForm.nodeURI.value;			
		var compositeNamespace = newNodeForm.compositeNamespace.value;
		var compositeName = newNodeForm.compositeName.value;
		var contributionURI = newNodeForm.contributionURI.value;
		var id  = 'composite:' +
			'http://tuscany.apache.org/cloud' + ';' +
			'http://tuscany.apache.org/cloud' + ';' +
			nodeName;
			
		var entry = '<entry xmlns="http://www.w3.org/2005/Atom">\n' +
              	'<id>' + id + '</id>\n' +
              	'<content type="text/xml">\n' + 
  				'<composite	xmlns="http://www.osoa.org/xmlns/sca/1.0"\n' +
				'	xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"\n' +
				'	targetNamespace="http://tuscany.apache.org/cloud"\n' +
				'	xmlns:c="' + compositeNamespace + '"\n' +
				'	name="' + nodeName + '">\n' +
				'\n' +
				'	<component name="' + nodeName + '">\n' +
				'		<t:implementation.node uri="' + contributionURI + '" composite="c:' + compositeName + '"/>\n' +
				'		<service name="Node">\n' +
				'			<binding.ws uri="' + nodeURI + '"/>\n' +
				'			<t:binding.http uri="' + nodeURI + '"/>\n' +
				'			<t:binding.jsonrpc uri="' + nodeURI + '"/>\n' +
				'			<t:binding.atom uri="' + nodeURI + '"/>\n' +
				'		</service>\n' +
				'	</component>\n' + 
				'</composite>' +
              	'</content>' +
               	'</entry>';
		cloudComposite.post(entry, addNodeResponse);
	}

	function addNodeResponse() {
		newNodeForm.nodeName.value = "";
		newNodeForm.nodeURI.value = "";
		newNodeForm.compositeNamespace.value = "";
		newNodeForm.compositeName.value = "";
		newNodeForm.contributionURI.value = "";
	    getNodes();
	}	

	function startNode() {
		var composites  = array(cloudCompositeForm.composites);
		for (var i = 0; i < composites.length; i++) {
			if (composites[i].checked) {
			    var id = nodeNames[i];
			    
				var entry = '<entry xmlns="http://www.w3.org/2005/Atom">' +
              	'<id>' + id + '</id>' +
               	'</entry>';
				processCollection.post(entry, startNodeResponse);
			}
		}
		return false;
	}

	function startNodeResponse() {
		processCollection.get("", getProcessesResponse);
		
		var composites  = array(cloudCompositeForm.composites);
		for (var i = 0; i < composites.length; i++) {
			if (composites[i].checked) {
			  composites[i].checked = false;
			}
		}
	}	

	function stopNode() {
		var composites  = array(cloudCompositeForm.composites);
		for (var i = 0; i < composites.length; i++) {
			if (composites[i].checked) {
			    var id = nodeNames[i];
				processCollection.del(id, stopNodeResponse);
			}
		}
		return false;
	}

	function stopNodeResponse() {
		processCollection.get("", getProcessesResponse);
		
		var composites  = array(cloudCompositeForm.composites);
		for (var i = 0; i < composites.length; i++) {
			if (composites[i].checked) {
			  composites[i].checked = false;
			}
		}
	}	

	function getComposites() {
		domainComposite.get("", getCompositesResponse);
	}
	
	function getCompositesResponse(feed) {
		if (feed != null) {
			var entries = feed.getElementsByTagName("entry");              
			for (var i=0; i<entries.length; i++) {
				var id = entries[i].getElementsByTagName("id")[0].firstChild.nodeValue;
				deployedComposites[id] = id;
			}
		}
	}

	function suggestCompositeNamespaces() {
		var namespaces = new Array();
		for (var uri in deployedComposites) {
			var qname = compositeName(uri);
			var ns = qname.substring(0, qname.indexOf(';'));
			namespaces[ns] = ns;
		}
		return array(namespaces);
	}	

	function suggestCompositeNames() {
		var inputns = newNodeForm.compositeNamespace.value;
		var names = new Array();
		for (var uri in deployedComposites) {
			var qname = compositeName(uri);
			var sc = qname.indexOf(';');
			var ns = qname.substring(0, sc);
			var name = qname.substring(sc + 1);
			if (ns == inputns || inputns == "") {
				names[name] = name;
			}
		}
		return array(names);
	}	

	function suggestContributionURIs() {
		var inputns = newNodeForm.compositeNamespace.value;
		var inputname = newNodeForm.compositeName.value;
		var uris = new Array();
		for (var uri in deployedComposites) {
			var qname = compositeName(uri);
			var sc = qname.indexOf(';');
			var ns = qname.substring(0, sc);
			var name = qname.substring(sc + 1);
			if ((ns == inputns || inputns == "") && (name == inputname || inputname == "")) {
				var curi = contributionURI(uri);
				uris[curi] = curi;
			}
		}
		return array(uris);
	}

	function toggleNewNode() {
		var visibility = newNodeElement.style.visibility;
		if (visibility == 'hidden') {
			newNodeElement.style.visibility = 'visible';
		} else {
			newNodeElement.style.visibility = 'hidden';
		}
		return false;
	}

	elementByID(gadget, 'deleteNodeLink').onclick = deleteNode; 
	elementByID(gadget, 'addNodeLink').onclick = toggleNewNode; 
	elementByID(gadget, 'startNodeLink').onclick = startNode; 
	elementByID(gadget, 'stopNodeLink').onclick = stopNode; 
	elementByID(gadget, 'addNodeButton').onclick = addNode; 

	getNodes();
	getComposites();
	suggest(newNodeForm.compositeNamespace, suggestCompositeNamespaces);
	suggest(newNodeForm.compositeName, suggestCompositeNames);
	suggest(newNodeForm.contributionURI, suggestContributionURIs);
	
</script>
</html>