4242import org .diskproject .shared .classes .adapters .MethodAdapter ;
4343import org .diskproject .shared .classes .util .KBConstants ;
4444import org .diskproject .shared .classes .workflow .WorkflowVariable ;
45+ import org .diskproject .shared .classes .workflow .Execution ;
4546import org .diskproject .shared .classes .workflow .VariableBinding ;
4647import org .diskproject .shared .classes .workflow .WorkflowInstantiation ;
4748import org .diskproject .shared .classes .workflow .WorkflowTemplate ;
48- import org .diskproject .shared .classes .workflow .WorkflowRun ;
49- import org .diskproject .shared .classes .workflow .WorkflowRun .RunBinding ;
50- import org .diskproject .shared .classes .workflow .WorkflowRun .RuntimeInfo ;
51- import org .diskproject .shared .classes .common .Status ;
52- import org .diskproject .shared .classes .common .Value ;
5349
5450import com .google .gson .Gson ;
5551import com .google .gson .JsonArray ;
@@ -355,129 +351,7 @@ private boolean login() {
355351 return false ;
356352 }
357353
358- private WorkflowRun parseExecutionDetails (String details ) {
359- JsonObject runobj = jsonParser .parse (details ).getAsJsonObject ();
360- JsonObject execution = null , variables = null ;//, constraints = null;
361- WorkflowRun curRun = new WorkflowRun ();
362-
363- try {
364- JsonElement xw = runobj .get ("execution" );
365- execution = xw .getAsJsonObject ();
366- } catch (Exception e ) {
367- System .err .println ("Error parsing execution details: Cannot parse execution." );
368- }
369- if (execution == null )
370- return null ;
371-
372- // Get run info.
373- RuntimeInfo runInfo = null ;
374- JsonObject runInfoJson = execution .get ("runtimeInfo" ).getAsJsonObject ();
375- JsonElement id = execution .get ("id" );
376- JsonElement status = runInfoJson .get ("status" );
377- JsonElement log = runInfoJson .get ("log" );
378- JsonElement tsStart = runInfoJson .get ("startTime" );
379- JsonElement tsEnd = runInfoJson .get ("endTime" );
380- if (status != null && id != null ) {
381- curRun .setId (id .getAsString ());
382- runInfo = new RuntimeInfo ();
383- runInfo .status = getStatusFromString (status .getAsString ());
384- runInfo .log = log == null ? "" : log .getAsString ();
385- if (tsStart != null ) runInfo .startTime = tsStart .getAsInt ();
386- if (tsEnd != null ) runInfo .endTime = tsEnd .getAsInt ();
387- } else {
388- System .err .println ("Error parsing execution details: Cannot get run status." );
389- }
390- if (runInfo == null )
391- return null ;
392- curRun .setExecutionInfo (runInfo );
393-
394- // Get steps info.
395- List <RuntimeInfo > stepInfo = null ;
396- if (execution != null ) {
397- JsonObject queueJson = execution .get ("queue" ).getAsJsonObject ();
398- JsonArray stepsArray = queueJson .get ("steps" ).getAsJsonArray ();
399- stepInfo = new ArrayList <RuntimeInfo >();
400- for (JsonElement step : stepsArray ) {
401- RuntimeInfo info = new RuntimeInfo ();
402- JsonObject rInfo = step .getAsJsonObject ().get ("runtimeInfo" ).getAsJsonObject ();
403- JsonElement stepStatus = rInfo .get ("status" );
404- JsonElement stepLog = rInfo .get ("log" );
405- JsonElement stepStart = rInfo .get ("startTime" );
406- JsonElement stepEnd = rInfo .get ("endTime" );
407- if (stepStatus != null ) {
408- info .status = getStatusFromString (stepStatus .getAsString ());
409- info .log = stepLog == null ? "" : stepLog .getAsString ();
410- if (stepStart != null ) info .startTime = stepStart .getAsInt ();
411- if (stepEnd != null ) info .endTime = stepEnd .getAsInt ();
412- } else {
413- System .err .println ("Error parsing execution details: Cannot get step status." );
414- }
415- }
416- }
417-
418- if (stepInfo != null )
419- curRun .setStepsInfo (stepInfo );
420-
421- try {
422- variables = runobj .get ("variables" ).getAsJsonObject ();
423- } catch (Exception e ) {
424- System .out .println (details );
425- }
426-
427- Map <String , RunBinding > input = null , output = null ;
428- if (variables != null ) {
429- input = new HashMap <String , RunBinding >();
430- JsonArray inputArray = variables .get ("input" ).getAsJsonArray ();
431- for (JsonElement cur : inputArray ) {
432- JsonObject curObj = cur .getAsJsonObject ();
433- JsonElement bindingObj = curObj .get ("binding" ); //.getAsJsonObject();
434- JsonElement inputTypeObj = curObj .get ("type" );//.getAsInt();
435- JsonElement nameObj = curObj .get ("id" );
436- if (nameObj != null && inputTypeObj != null && bindingObj != null ) {
437- RunBinding curInput = new RunBinding ();
438- JsonObject bindingsJson = bindingObj .getAsJsonObject ();
439- String name = nameObj .getAsString ().replaceAll ("^.*\\ #" , "" );
440- curInput .type = inputTypeObj .getAsInt () == 1 ? Value .Type .URI : Value .Type .LITERAL ;
441- // --
442- JsonElement idObj = bindingsJson .get ("id" );
443- if (idObj != null ) curInput .id = idObj .getAsString ();
444- JsonElement valueJson = bindingsJson .get ("value" );
445- if (valueJson != null ) curInput .value = valueJson .getAsString ();
446- JsonElement datatypeJson = bindingsJson .get ("datatype" );
447- if (datatypeJson != null ) curInput .datatype = datatypeJson .getAsString ();
448- input .put (name , curInput );
449- }
450- }
451-
452- output = new HashMap <String , RunBinding >();
453- JsonArray outputArray = variables .get ("output" ).getAsJsonArray ();
454- for (JsonElement cur : outputArray ) {
455- JsonObject curObj = cur .getAsJsonObject ();
456- JsonElement bindingObj = curObj .get ("binding" ); //.getAsJsonObject();
457- JsonElement inputTypeObj = curObj .get ("type" );//.getAsInt();
458- JsonElement nameObj = curObj .get ("id" );
459- if (nameObj != null && inputTypeObj != null && bindingObj != null ) {
460- RunBinding curOutput = new RunBinding ();
461- JsonObject bindingsJson = bindingObj .getAsJsonObject ();
462- String name = nameObj .getAsString ().replaceAll ("^.*\\ #" , "" );
463- curOutput .type = inputTypeObj .getAsInt () == 1 ? Value .Type .URI : Value .Type .LITERAL ;
464- // --
465- JsonElement idObj = bindingsJson .get ("id" );
466- if (idObj != null ) curOutput .id = idObj .getAsString ();
467- JsonElement valueJson = bindingsJson .get ("value" );
468- if (valueJson != null ) curOutput .value = valueJson .getAsString ();
469- JsonElement datatypeJson = bindingsJson .get ("datatype" );
470- if (datatypeJson != null ) curOutput .datatype = datatypeJson .getAsString ();
471- output .put (name , curOutput );
472- }
473- }
474- }
475- if (input != null ) curRun .setInputs (input );
476- if (output != null ) curRun .setOutputs (output );
477- return curRun ;
478- }
479-
480- public WorkflowRun getWorkflowRunStatus (String runid ) {
354+ public Execution getWorkflowRunStatus (String runid ) {
481355 String execId = RUNID (runid );
482356 String runjson = null ;
483357 try {
@@ -492,7 +366,7 @@ public WorkflowRun getWorkflowRunStatus(String runid) {
492366 if (runjson == null )
493367 return null ;
494368
495- WorkflowRun wfRunStatus = parseExecutionDetails (runjson );
369+ Execution wfRunStatus = WingsParser . parseExecution (runjson );
496370 if (wfRunStatus == null ) {
497371 System .out .println (runjson );
498372 return null ;
@@ -506,16 +380,6 @@ public WorkflowRun getWorkflowRunStatus(String runid) {
506380 wfRunStatus .setLink (link );
507381 return wfRunStatus ;
508382 }
509-
510- public Status getStatusFromString (String statusStr ) {
511- try {
512- return Status .valueOf (statusStr );
513- } catch (Exception e ) {
514- if (statusStr != null && statusStr .equals ("SUCCESS" ))
515- return Status .SUCCESSFUL ;
516- return Status .PENDING ;
517- }
518- }
519383
520384 // TODO: Hackish function. Fix it !!!! *IMPORTANT*
521385 private String getWorkflowRunWithSameBindings (String templateId , List <VariableBinding > vBindings ) {
@@ -622,6 +486,7 @@ private boolean isPartOfCollection(String key) {
622486 return true ;
623487 }
624488
489+ //TODO
625490 public List <String > runWorkflow (WorkflowInstantiation wf ) {
626491 String wfURI = WFLOWID (wf .getName ());
627492 System .out .println (wfURI + " == " + wf .getLink ());
@@ -1431,7 +1296,7 @@ public String addData(String url, String name, String dType) throws Exception {
14311296 }
14321297
14331298 @ Override
1434- public WorkflowRun getRunStatus (String runId ) {
1299+ public Execution getRunStatus (String runId ) {
14351300 return this .getWorkflowRunStatus (runId );
14361301 }
14371302
@@ -1440,7 +1305,6 @@ public FileAndMeta fetchData(String dataId) {
14401305 return this .fetchDataFromWings (dataId );
14411306 }
14421307
1443-
14441308 @ Override
14451309 public boolean registerData (String id , String type ) {
14461310 String fullId = getDataUri (id );
0 commit comments