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