public int getExecuteExperimentProgress() {
TestbedManager testbedMan = (TestbedManager) JSFUtil.getManagedObject("TestbedManager");
ExperimentBean expBean = (ExperimentBean)JSFUtil.getManagedObject("ExperimentBean");
refreshExperimentBean();
Experiment exp = expBean.getExperiment();
if( exp.getExperimentExecutable() != null ) {
log.info("Looking for experiment status... "+exp.getExperimentExecutable().getBatchExecutionIdentifier());
}
log.info("Invoked: "+exp.getExperimentExecutable().isExecutableInvoked());
log.info("Complete: "+exp.getExperimentExecutable().isExecutionCompleted());
// If this exp has never been run, return -1:
if( exp.getExperimentExecutable().isExecutableInvoked() == false ) return -1;
// If this exp has been run, and is currently 'completed', return 101:
if( exp.getExperimentExecutable().isExecutionCompleted() ) return 101;
log.info("Still looking for..."+exp.getExperimentExecutable().getBatchExecutionIdentifier());
//get the batch processor that's responsible for this job
BatchProcessor pb = TestbedBatchProcessorManager.getInstance().getBatchProcessor(exp.getExperimentExecutable().getBatchSystemIdentifier());
String job_key = exp.getExperimentExecutable().getBatchExecutionIdentifier();
log.info("Looking for experiment progress under job key: "+job_key+" : " + pb.getJobStatus(job_key));
if( pb.getJobStatus(job_key).equals(TestbedBatchJob.NO_SUCH_JOB ) ) {
log.info("Got No Such Job for key: "+job_key);
exp.getExperimentExecutable().setExecutionSuccess(false);
exp.getExperimentExecutable().setExecutionCompleted(true);
exp.getExperimentExecution().setState(Experiment.STATE_COMPLETED);
exp.getExperimentEvaluation().setState(Experiment.STATE_IN_PROGRESS);
testbedMan.updateExperiment(exp);
return -1;
} else if( pb.getJobStatus(job_key).equals(TestbedBatchJob.NOT_STARTED) ) {
log.info("Got NOT STARTED for key: "+job_key);
return 0;
} else if( pb.getJobStatus(job_key).equals(TestbedBatchJob.RUNNING) ) {
int percent = pb.getJobPercentComplete(job_key);
// Return percentage:
log.info("Got percent complete:" + percent+" for key: "+job_key);
return percent;
} else {
log.info("Got job complete.");
exp.getExperimentExecution().setState(Experiment.STATE_COMPLETED);
exp.getExperimentEvaluation().setState(Experiment.STATE_IN_PROGRESS);
testbedMan.updateExperiment(exp);
// Appears to need to return a number greater that 100 in order to force the progress bar to refresh properly.
return 101;
}
}