otsdaq_utilities  v2_04_02
ArtdaqConfigurationAPI.js
1 //=====================================================================================
2 //
3 // Created August, 2019
4 // by Ryan Rivera ((rrivera at fnal.gov))
5 //
6 // ArtdaqConfigurationAPI.js
7 //
8 // Requirements:
9 // 1. paste the following:
10 //
11 // <script type="text/JavaScript" src="/WebPath/js/Globals.js"></script>
12 // <script type="text/JavaScript" src="/WebPath/js/Debug.js"></script>
13 // <script type="text/JavaScript" src="/WebPath/js/DesktopWindowContentCode.js"></script>
14 // <script type="text/JavaScript" src="/WebPath/js/js_lib/ConfiguraitonAPI.js"></script>
15 // <link rel="stylesheet" type="text/css" href="/WebPath/css/ConfigurationAPI.css">
16 // <script type="text/JavaScript" src="/WebPath/js/js_lib/ArtdaqConfiguraitonAPI.js"></script>
17 //
18 // ...anywhere inside the <head></head> tag of a window content html page
19 // 2. for proper functionality certain handlers are used:
20 // cannot overwrite handlers for window: onfocus, onscroll, onblur, onmousemove
21 // (if you must overwrite, try to call the DesktopContent handlers from your handlers)
22 //
23 // Recommendations:
24 // 1. use Debug to output status and errors, e.g.:
25 // Debug.log("this is my status",Debug.LOW_PRIORITY); //LOW_PRIORITY, MED_PRIORITY, INFO_PRIORITY, WARN_PRIORITY, HIGH_PRIORITY
26 // 2. call window.focus() to bring your window to the front of the Desktop
27 //
28 // The code of Requirement #1 should be inserted in the header of each page that will be
29 // the content of a window in the ots desktop.
30 //
31 // This code handles bringing the window to the front when the content
32 // is clicked or scrolled.
33 //
34 // Example usage: /WebPath/html/ConfigurationGUI_artdaq.html
35 //
36 //=====================================================================================
37 
38 var ArtdaqConfigurationAPI = ArtdaqConfigurationAPI || {}; //define ArtdaqConfigurationAPI namespace
39 
40 if (typeof Debug == 'undefined')
41  alert('ERROR: Debug is undefined! Must include Debug.js before ConfigurationAPI.js');
42 if (typeof Globals == 'undefined')
43  alert('ERROR: Globals is undefined! Must include Globals.js before ConfigurationAPI.js');
44 if (typeof DesktopContent == 'undefined' &&
45  typeof Desktop == 'undefined')
46  alert('ERROR: DesktopContent is undefined! Must include DesktopContent.js before ConfigurationAPI.js');
47 
48 
49 //"public" function list:
50 // ArtdaqConfigurationAPI.getArtdaqNodes(responseHandler,modifiedTables)
51 
52 //"public" helpers:
53 
54 //"public" members:
55 
56 //"public" constants:
57 ArtdaqConfigurationAPI.NODE_TYPES = ["reader","builder",
58  "logger","dispacher","monitor"];
59 
60 //"private" function list:
61 
62 //"private" constants:
63 
64 //=====================================================================================
65 //getArtdaqNodes ~~
66 // get currently active artdaq nodes
67 //
68 // when complete, the responseHandler is called with an object parameter.
69 // on failure, the object will be empty.
70 // on success, the object of Active artdaq nodes
71 // artdaqNodes := {}
72 // artdaqNodes.<nodeType> = {}
73 // artdaqNodes.<nodeType>.<nodeName> = {} //for now node empty, but could put context url/etc., or just look it up as needed with server
74 // ...
75 //
76 // <nodeType> = reader, builder, aggregator, dispatcher
77 //
78 ArtdaqConfigurationAPI.getArtdaqNodes = function(responseHandler,
79  modifiedTables)
80 {
81  var modifiedTablesListStr = "";
82  for(var i=0;modifiedTables && i<modifiedTables.length;++i)
83  {
84  if(i) modifiedTablesListStr += ",";
85  modifiedTablesListStr += modifiedTables[i].tableName + "," +
86  modifiedTables[i].tableVersion;
87  }
88 
89  //get active configuration group
90  DesktopContent.XMLHttpRequest("Request?RequestType=getArtdaqNodes",
91  "modifiedTables=" + modifiedTablesListStr, //end post data,
92  function(req)
93  {
94  responseHandler(localExtractActiveArtdaqNodes(req));
95  },
96  0,0,true //reqParam, progressHandler, callHandlerOnErr
97  ); //end of getActiveTableGroups handler
98 
99  return;
100 
101  //=================
102  function localExtractActiveArtdaqNodes(req)
103  {
104  Debug.log("localExtractActiveArtdaqNodes");
105 
106  //can call this at almost all API handlers
107  try
108  {
109  var types = ArtdaqConfigurationAPI.NODE_TYPES;
110 
111  var i,j;
112  var retObj = {};
113 
114 
115  retObj.nodeCount = 0;
116 
117  for(i=0;i<types.length;++i)
118  {
119  Debug.log("Extracting " + types[i]);
120  var nodes = req.responseXML.getElementsByTagName(
121  types[i]);
122  var addresses = req.responseXML.getElementsByTagName(
123  types[i] + "-contextAddress");
124  var ports = req.responseXML.getElementsByTagName(
125  types[i] + "-contextPort");
126 
127  retObj[types[i]] = {};
128 
129  for(j=0;j<nodes.length;++j)
130  retObj[types[i]][nodes[j].getAttribute('value')] =
131  {
132  "address": addresses[j].getAttribute('value'),
133  "port": ports[j].getAttribute('value'),
134  };
135 
136  Debug.log("Extracted " +
137  nodes.length + " " +
138  types[i]);
139 
140  retObj.nodeCount += nodes.length;
141 
142  } //end type extraction loop
143 
144  Debug.log("Total nodes extracted " +
145  retObj.nodeCount);
146  }
147  catch(e)
148  {
149  Debug.log("Error extracting active artdaq nodes: " + e);
150  return undefined;
151  }
152 
153  return retObj;
154  } // end localExtractActiveArtdaqNodes()
155 
156 } // end getArtdaqNodes()
157 
158 
159 
160 
161 
162 
163 
164 
165 
166 
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177