1 | #include "workflow_graph.hpp" |
---|
2 | #include "cxios.hpp" |
---|
3 | |
---|
4 | namespace xios |
---|
5 | { |
---|
6 | |
---|
7 | std::vector<graph_node_object> *CWorkflowGraph::vectorOfNodes_ = 0; |
---|
8 | std::vector<graph_edge_object> *CWorkflowGraph::vectorOfEdges_ = 0; |
---|
9 | std::vector<StdString> *CWorkflowGraph::vectorOfContexts_ = 0; |
---|
10 | |
---|
11 | std::vector<graph_node_object> *CWorkflowGraph::vectorOfNodes_srv_ = 0; |
---|
12 | std::vector<graph_edge_object> *CWorkflowGraph::vectorOfEdges_srv_ = 0; |
---|
13 | std::vector<StdString> *CWorkflowGraph::vectorOfContexts_srv_ = 0; |
---|
14 | |
---|
15 | bool CWorkflowGraph::clientGraphBuilt = false; |
---|
16 | bool CWorkflowGraph::serverGraphBuilt = false; |
---|
17 | bool CWorkflowGraph::build_begin = false; |
---|
18 | |
---|
19 | |
---|
20 | CWorkflowGraph::CWorkflowGraph() |
---|
21 | { } |
---|
22 | |
---|
23 | |
---|
24 | //****************************************************** |
---|
25 | |
---|
26 | void CWorkflowGraph::outputWorkflowGraph_client_stdout() |
---|
27 | { |
---|
28 | std::cout<<"\n\nbuild workflow graph ..."<<std::endl; |
---|
29 | for(int i=0; i<vectorOfNodes_->size(); i++) |
---|
30 | { |
---|
31 | info(100)<<"Node["<<i<<"] is "<<(*vectorOfNodes_)[i].filter_name<<std::endl; |
---|
32 | } |
---|
33 | |
---|
34 | for(int i=0; i<vectorOfEdges_->size(); i++) |
---|
35 | { |
---|
36 | info(100)<<"Edge["<<i<<"] from "<<(*vectorOfEdges_)[i].from<<" to "<<(*vectorOfEdges_)[i].to<<std::endl; |
---|
37 | } |
---|
38 | std::cout<<"\nend workflow graph ...\n\n"<<std::endl; |
---|
39 | } |
---|
40 | |
---|
41 | void CWorkflowGraph::outputWorkflowGraph_server_stdout() |
---|
42 | { |
---|
43 | std::cout<<"\n\nServer side : build workflow graph ..."<<std::endl; |
---|
44 | for(int i=0; i<vectorOfNodes_srv_->size(); i++) |
---|
45 | { |
---|
46 | info(100)<<"Node["<<i<<"] is "<<(*vectorOfNodes_srv_)[i].filter_name<<std::endl; |
---|
47 | } |
---|
48 | |
---|
49 | for(int i=0; i<vectorOfEdges_srv_->size(); i++) |
---|
50 | { |
---|
51 | info(100)<<"Edge["<<i<<"] from "<<(*vectorOfEdges_srv_)[i].from<<" to "<<(*vectorOfEdges_srv_)[i].to<<std::endl; |
---|
52 | } |
---|
53 | std::cout<<"\nend workflow graph ...\n\n"<<std::endl; |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | void CWorkflowGraph::drawWorkFlowGraph_client() |
---|
58 | TRY |
---|
59 | { |
---|
60 | if(vectorOfNodes_ && vectorOfEdges_) |
---|
61 | { |
---|
62 | outputWorkflowGraph_client(); |
---|
63 | } |
---|
64 | else info(100)<<"Client side : no graph information"<<std::endl; |
---|
65 | } |
---|
66 | CATCH |
---|
67 | |
---|
68 | |
---|
69 | void CWorkflowGraph::drawWorkFlowGraph_server() |
---|
70 | TRY |
---|
71 | { |
---|
72 | if(vectorOfNodes_srv_ && vectorOfEdges_srv_) |
---|
73 | { |
---|
74 | outputWorkflowGraph_server(); |
---|
75 | } |
---|
76 | else info(100)<<"Server side : no graph information"<<std::endl; |
---|
77 | } |
---|
78 | CATCH |
---|
79 | |
---|
80 | void CWorkflowGraph::addEdge(int from, int to, CDataPacketPtr packet) |
---|
81 | TRY |
---|
82 | { |
---|
83 | if(from<0) return; |
---|
84 | |
---|
85 | if(CXios::isClient) |
---|
86 | { |
---|
87 | if(!vectorOfEdges_) vectorOfEdges_ = new std::vector<graph_edge_object>; |
---|
88 | std::string currentContextId = CContext::getCurrent()->getId(); |
---|
89 | |
---|
90 | graph_edge_object edge_obj; |
---|
91 | edge_obj.from = from; |
---|
92 | edge_obj.to = to; |
---|
93 | edge_obj.date = packet->date; |
---|
94 | edge_obj.timestamp = packet->timestamp; |
---|
95 | edge_obj.field = packet->graphPackage->currentField; |
---|
96 | edge_obj.show = true; |
---|
97 | |
---|
98 | if(vectorOfNodes_->at(from).filter_class == 2) // from pass through filter |
---|
99 | { |
---|
100 | edge_obj.label_info = vectorOfNodes_->at(from).label_field_id; |
---|
101 | } |
---|
102 | |
---|
103 | if(vectorOfNodes_->at(to).filter_class == 3) // to temporal filter |
---|
104 | { |
---|
105 | vectorOfNodes_->at(to).expected_entry_nb++; |
---|
106 | } |
---|
107 | |
---|
108 | for(int i=0; i<vectorOfContexts_->size(); i++) |
---|
109 | { |
---|
110 | if(vectorOfContexts_->at(i) == currentContextId) |
---|
111 | { |
---|
112 | edge_obj.context = i; |
---|
113 | edge_obj.context_id = currentContextId; |
---|
114 | break; |
---|
115 | } |
---|
116 | } |
---|
117 | edge_obj.attributes = packet->graphPackage->currentField->recordXiosAttributes(); |
---|
118 | |
---|
119 | vectorOfEdges_->push_back(edge_obj); |
---|
120 | //info(100)<<"****************** Add Edge from "<<from<<" to "<<to<<std::endl; |
---|
121 | vectorOfNodes_->at(from).filter_filled = true; |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | if(!vectorOfEdges_srv_) vectorOfEdges_srv_ = new std::vector<graph_edge_object>; |
---|
126 | std::string currentContextId = CContext::getCurrent()->getId(); |
---|
127 | |
---|
128 | graph_edge_object edge_obj; |
---|
129 | edge_obj.from = from; |
---|
130 | edge_obj.to = to; |
---|
131 | edge_obj.date = packet->date; |
---|
132 | edge_obj.timestamp = packet->timestamp; |
---|
133 | edge_obj.field = packet->graphPackage->currentField; |
---|
134 | edge_obj.show = true; |
---|
135 | for(int i=0; i<vectorOfContexts_srv_->size(); i++) |
---|
136 | { |
---|
137 | if(vectorOfContexts_srv_->at(i) == currentContextId) |
---|
138 | { |
---|
139 | edge_obj.context = i; |
---|
140 | edge_obj.context_id = currentContextId; |
---|
141 | break; |
---|
142 | } |
---|
143 | } |
---|
144 | edge_obj.attributes = packet->graphPackage->currentField->recordXiosAttributes(); |
---|
145 | |
---|
146 | vectorOfEdges_srv_->push_back(edge_obj); |
---|
147 | //info(100)<<"****************** Server side : Add Edge from "<<from<<" to "<<to<<std::endl; |
---|
148 | vectorOfNodes_srv_->at(from).filter_filled = true; |
---|
149 | |
---|
150 | } |
---|
151 | } |
---|
152 | CATCH |
---|
153 | |
---|
154 | |
---|
155 | void CWorkflowGraph::addNode(StdString filterName, int filterClass, bool filterFilled, int entryNb, CDataPacketPtr packet) |
---|
156 | TRY |
---|
157 | { |
---|
158 | if(CXios::isClient) |
---|
159 | { |
---|
160 | if(!vectorOfNodes_) vectorOfNodes_ = new std::vector<graph_node_object>; |
---|
161 | if(!vectorOfContexts_) vectorOfContexts_ = new std::vector<StdString>; |
---|
162 | std::string currentContextId = CContext::getCurrent()->getId(); |
---|
163 | if ( std::find(vectorOfContexts_->begin(), vectorOfContexts_->end(), currentContextId) == vectorOfContexts_->end() ) |
---|
164 | vectorOfContexts_->push_back(currentContextId); |
---|
165 | |
---|
166 | |
---|
167 | graph_node_object node_obj; |
---|
168 | node_obj.filter_name = filterName; |
---|
169 | node_obj.filter_class = filterClass; |
---|
170 | node_obj.filter_filled = filterFilled; |
---|
171 | node_obj.expected_entry_nb = entryNb; |
---|
172 | node_obj.date = packet->date; |
---|
173 | node_obj.timestamp = packet->timestamp; |
---|
174 | for(int i=0; i<vectorOfContexts_->size(); i++) |
---|
175 | { |
---|
176 | if(vectorOfContexts_->at(i) == currentContextId) |
---|
177 | { |
---|
178 | node_obj.context = i; |
---|
179 | node_obj.context_id = currentContextId; |
---|
180 | break; |
---|
181 | } |
---|
182 | } |
---|
183 | node_obj.attributes = packet->graphPackage->currentField->recordXiosAttributes(); |
---|
184 | |
---|
185 | vectorOfNodes_->push_back(node_obj); |
---|
186 | //info(100)<<"****************** Add node "<<filterName<<std::endl; |
---|
187 | } |
---|
188 | else |
---|
189 | { |
---|
190 | if(!vectorOfNodes_srv_) vectorOfNodes_srv_ = new std::vector<graph_node_object>; |
---|
191 | if(!vectorOfContexts_srv_) vectorOfContexts_srv_ = new std::vector<StdString>; |
---|
192 | std::string currentContextId = CContext::getCurrent()->getId(); |
---|
193 | if ( std::find(vectorOfContexts_srv_->begin(), vectorOfContexts_srv_->end(), currentContextId) == vectorOfContexts_srv_->end() ) |
---|
194 | vectorOfContexts_srv_->push_back(currentContextId); |
---|
195 | |
---|
196 | graph_node_object node_obj; |
---|
197 | node_obj.filter_name = filterName; |
---|
198 | node_obj.filter_class = filterClass; |
---|
199 | node_obj.filter_filled = filterFilled; |
---|
200 | node_obj.expected_entry_nb = entryNb; |
---|
201 | node_obj.date = packet->date; |
---|
202 | node_obj.timestamp = packet->timestamp; |
---|
203 | for(int i=0; i<vectorOfContexts_srv_->size(); i++) |
---|
204 | { |
---|
205 | if(vectorOfContexts_srv_->at(i) == currentContextId) |
---|
206 | { |
---|
207 | node_obj.context = i; |
---|
208 | node_obj.context_id = currentContextId; |
---|
209 | break; |
---|
210 | } |
---|
211 | } |
---|
212 | node_obj.attributes = packet->graphPackage->currentField->recordXiosAttributes(); |
---|
213 | |
---|
214 | vectorOfNodes_srv_->push_back(node_obj); |
---|
215 | //info(100)<<"******************Server side : Add node "<<filterName<<std::endl; |
---|
216 | } |
---|
217 | |
---|
218 | } |
---|
219 | CATCH |
---|
220 | |
---|
221 | int CWorkflowGraph::getNodeSize() |
---|
222 | TRY |
---|
223 | { |
---|
224 | if(CXios::isClient) |
---|
225 | { |
---|
226 | return !vectorOfNodes_? 0 : vectorOfNodes_->size(); |
---|
227 | } |
---|
228 | else |
---|
229 | { |
---|
230 | return !vectorOfNodes_srv_? 0 : vectorOfNodes_srv_->size(); |
---|
231 | } |
---|
232 | } |
---|
233 | CATCH |
---|
234 | |
---|
235 | |
---|
236 | |
---|
237 | void CWorkflowGraph::outputWorkflowGraph_client() |
---|
238 | { |
---|
239 | int graph_rank; |
---|
240 | MPI_Comm_rank(MPI_COMM_WORLD, &graph_rank); |
---|
241 | std::ofstream *outfiles; |
---|
242 | |
---|
243 | outfiles = new std::ofstream[vectorOfContexts_->size()]; |
---|
244 | |
---|
245 | for(int ctx=0; ctx<vectorOfContexts_->size(); ctx++) |
---|
246 | { |
---|
247 | StdString graphFileName="graph_data_"+vectorOfContexts_->at(ctx)+"_client_"+to_string(graph_rank)+".json"; |
---|
248 | outfiles[ctx].open(graphFileName); |
---|
249 | |
---|
250 | outfiles[ctx] << "{\"nodes\":["<<std::endl; |
---|
251 | } |
---|
252 | for(int i=0; i<vectorOfNodes_->size(); i++) |
---|
253 | { |
---|
254 | int ctx = vectorOfNodes_->at(i).context; |
---|
255 | if(i!=0) outfiles[ctx] << ","; |
---|
256 | outfiles[ctx] << "{\"id\":"<<i<<","<<std::endl; |
---|
257 | outfiles[ctx] << "\"label\":"<<"\""<<vectorOfNodes_->at(i).filter_name<<"\","<<std::endl; |
---|
258 | outfiles[ctx] << "\"class\":"<<vectorOfNodes_->at(i).filter_class<<","<<std::endl; |
---|
259 | outfiles[ctx] << "\"filled\":"<<!(vectorOfNodes_->at(i).filter_filled)<<","<<std::endl; |
---|
260 | outfiles[ctx] << "\"context\":"<<"\""<<vectorOfNodes_->at(i).context_id<<"\","<<std::endl; |
---|
261 | outfiles[ctx] << "\"entry\":"<<"\""<<vectorOfNodes_->at(i).expected_entry_nb<<"\","<<std::endl; |
---|
262 | outfiles[ctx] << "\"attributes\":"<<"\""<<vectorOfNodes_->at(i).attributes<<"\","<<std::endl; |
---|
263 | outfiles[ctx] << "\"type\":"<<"\"\"}"<<std::endl; |
---|
264 | } |
---|
265 | for(int ctx=0; ctx<vectorOfContexts_->size(); ctx++) |
---|
266 | { |
---|
267 | outfiles[ctx] << std::endl<<"],"<<std::endl<<"\"edges\" : ["<<std::endl; |
---|
268 | } |
---|
269 | for(int i=0; i<vectorOfEdges_->size(); i++) |
---|
270 | { |
---|
271 | int ctx = vectorOfEdges_->at(i).context; |
---|
272 | if(i!=0) outfiles[ctx] << ","; |
---|
273 | outfiles[ctx] << "{\"id\":"<<i<<","<<std::endl; |
---|
274 | outfiles[ctx] << "\"from\":"<<vectorOfEdges_->at(i).from<<","<<std::endl; |
---|
275 | outfiles[ctx] << "\"to\":"<<vectorOfEdges_->at(i).to<<","<<std::endl; |
---|
276 | if(vectorOfEdges_->at(i).label_info != "none") |
---|
277 | { |
---|
278 | if(vectorOfEdges_->at(i).show) outfiles[ctx] << "\"label\":"<<"\""<<vectorOfEdges_->at(i).label_info<<"\\n"<<vectorOfEdges_->at(i).date<<"\","<<std::endl; |
---|
279 | else outfiles[ctx] << "\"label\":"<<"\"\\n"<<vectorOfEdges_->at(i).date<<"\","<<std::endl; |
---|
280 | } |
---|
281 | else |
---|
282 | { |
---|
283 | if(vectorOfEdges_->at(i).show) outfiles[ctx] << "\"label\":"<<"\""<<vectorOfEdges_->at(i).field->getId()<<"\\n"<<vectorOfEdges_->at(i).date<<"\","<<std::endl; |
---|
284 | else outfiles[ctx] << "\"label\":"<<"\"\\n"<<vectorOfEdges_->at(i).date<<"\","<<std::endl; |
---|
285 | } |
---|
286 | outfiles[ctx] << "\"context\":"<<"\""<<vectorOfEdges_->at(i).context_id<<"\","<<std::endl; |
---|
287 | outfiles[ctx] << "\"attributes\":"<<"\""<<vectorOfEdges_->at(i).attributes<<"\","<<std::endl; |
---|
288 | outfiles[ctx] << "\"date\":"<<"\""<<vectorOfEdges_->at(i).date<<"\"}"<<std::endl; |
---|
289 | } |
---|
290 | for(int ctx=0; ctx<vectorOfContexts_->size(); ctx++) |
---|
291 | { |
---|
292 | outfiles[ctx] << std::endl<<"]}"<<std::endl; |
---|
293 | outfiles[ctx].close(); |
---|
294 | } |
---|
295 | } |
---|
296 | |
---|
297 | |
---|
298 | void CWorkflowGraph::outputWorkflowGraph_server() |
---|
299 | { |
---|
300 | int graph_rank; |
---|
301 | MPI_Comm_rank(MPI_COMM_WORLD, &graph_rank); |
---|
302 | std::ofstream *outfiles; |
---|
303 | |
---|
304 | outfiles = new std::ofstream[vectorOfContexts_srv_->size()]; |
---|
305 | |
---|
306 | for(int ctx=0; ctx<vectorOfContexts_srv_->size(); ctx++) |
---|
307 | { |
---|
308 | StdString graphFileName="graph_data_"+vectorOfContexts_srv_->at(ctx)+"_client_"+to_string(graph_rank)+".json"; |
---|
309 | outfiles[ctx].open(graphFileName); |
---|
310 | |
---|
311 | outfiles[ctx] << "{\"nodes\":["<<std::endl; |
---|
312 | } |
---|
313 | for(int i=0; i<vectorOfNodes_srv_->size(); i++) |
---|
314 | { |
---|
315 | int ctx = vectorOfNodes_srv_->at(i).context; |
---|
316 | if(i!=0) outfiles[ctx] << ","; |
---|
317 | outfiles[ctx] << "{\"id\":"<<i<<","<<std::endl; |
---|
318 | outfiles[ctx] << "\"label\":"<<"\""<<vectorOfNodes_srv_->at(i).filter_name<<"\","<<std::endl; |
---|
319 | outfiles[ctx] << "\"class\":"<<vectorOfNodes_srv_->at(i).filter_class<<","<<std::endl; |
---|
320 | outfiles[ctx] << "\"filled\":"<<!(vectorOfNodes_srv_->at(i).filter_filled)<<","<<std::endl; |
---|
321 | outfiles[ctx] << "\"context\":"<<"\""<<vectorOfNodes_srv_->at(i).context_id<<"\","<<std::endl; |
---|
322 | outfiles[ctx] << "\"entry\":"<<"\""<<vectorOfNodes_srv_->at(i).expected_entry_nb<<"\","<<std::endl; |
---|
323 | outfiles[ctx] << "\"attributes\":"<<"\""<<vectorOfNodes_srv_->at(i).attributes<<"\","<<std::endl; |
---|
324 | outfiles[ctx] << "\"type\":"<<"\"\"}"<<std::endl; |
---|
325 | } |
---|
326 | for(int ctx=0; ctx<vectorOfContexts_srv_->size(); ctx++) |
---|
327 | { |
---|
328 | outfiles[ctx] << std::endl<<"],"<<std::endl<<"\"edges\" : ["<<std::endl; |
---|
329 | } |
---|
330 | for(int i=0; i<vectorOfEdges_srv_->size(); i++) |
---|
331 | { |
---|
332 | int ctx = vectorOfEdges_srv_->at(i).context; |
---|
333 | if(i!=0) outfiles[ctx] << ","; |
---|
334 | outfiles[ctx] << "{\"id\":"<<i<<","<<std::endl; |
---|
335 | outfiles[ctx] << "\"from\":"<<vectorOfEdges_srv_->at(i).from<<","<<std::endl; |
---|
336 | outfiles[ctx] << "\"to\":"<<vectorOfEdges_srv_->at(i).to<<","<<std::endl; |
---|
337 | if(vectorOfEdges_srv_->at(i).show) outfiles[ctx] << "\"label\":"<<"\""<<vectorOfEdges_srv_->at(i).field->getId()<<"\\n"<<vectorOfEdges_srv_->at(i).date<<"\","<<std::endl; |
---|
338 | else outfiles[ctx] << "\"label\":"<<"\"\\n"<<vectorOfEdges_srv_->at(i).date<<"\","<<std::endl; |
---|
339 | outfiles[ctx] << "\"context\":"<<"\""<<vectorOfEdges_srv_->at(i).context_id<<"\","<<std::endl; |
---|
340 | outfiles[ctx] << "\"attributes\":"<<"\""<<vectorOfEdges_srv_->at(i).attributes<<"\","<<std::endl; |
---|
341 | outfiles[ctx] << "\"date\":"<<"\""<<vectorOfEdges_srv_->at(i).date<<"\"}"<<std::endl; |
---|
342 | } |
---|
343 | for(int ctx=0; ctx<vectorOfContexts_srv_->size(); ctx++) |
---|
344 | { |
---|
345 | outfiles[ctx] << std::endl<<"]}"<<std::endl; |
---|
346 | outfiles[ctx].close(); |
---|
347 | } |
---|
348 | } |
---|
349 | } |
---|
350 | |
---|