| 1 | package de.uka.ipd.sdq.pcmsolver; |
| 2 | |
| 3 | import org.apache.log4j.Logger; |
| 4 | import org.eclipse.core.runtime.IProgressMonitor; |
| 5 | |
| 6 | import de.uka.ipd.sdq.pcmsolver.models.PCMInstance; |
| 7 | import de.uka.ipd.sdq.pcmsolver.runconfig.MessageStrings; |
| 8 | import de.uka.ipd.sdq.pcmsolver.runconfig.PCMSolverWorkflowRunConfiguration; |
| 9 | import de.uka.ipd.sdq.pcmsolver.transformations.SolverStrategy; |
| 10 | import de.uka.ipd.sdq.pcmsolver.transformations.pcm2lqn.Pcm2LqnStrategy; |
| 11 | import de.uka.ipd.sdq.pcmsolver.transformations.pcm2regex.Pcm2RegExStrategy; |
| 12 | import de.uka.ipd.sdq.probfunction.math.IProbabilityFunctionFactory; |
| 13 | import de.uka.ipd.sdq.probfunction.math.PDFConfiguration; |
| 14 | import de.uka.ipd.sdq.workflow.IBlackboardInteractingJob; |
| 15 | import de.uka.ipd.sdq.workflow.exceptions.JobFailedException; |
| 16 | import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException; |
| 17 | import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException; |
| 18 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard; |
| 19 | import de.uka.ipd.sdq.workflow.pcm.blackboard.PCMResourceSetPartition; |
| 20 | import de.uka.ipd.sdq.workflow.pcm.jobs.LoadPCMModelsIntoBlackboardJob; |
| 21 | |
| 22 | /** |
| 23 | * The central class that controls the PCM Solver process when launched from the |
| 24 | * eclipse UI. |
| 25 | * |
| 26 | * @author koziolek, brosch, becker |
| 27 | * |
| 28 | */ |
| 29 | public class RunPCMAnalysisJob implements |
| 30 | IBlackboardInteractingJob<MDSDBlackboard> { |
| 31 | |
| 32 | /** |
| 33 | * Enables log4j logging for this class. |
| 34 | */ |
| 35 | private static Logger logger = Logger.getLogger(RunPCMAnalysisJob.class |
| 36 | .getName()); |
| 37 | |
| 38 | /** |
| 39 | * Indicates the actual type of the PCM solving process. The user can choose |
| 40 | * between different types through the launch configuration. |
| 41 | */ |
| 42 | private SolverStrategy strategy; |
| 43 | |
| 44 | /** |
| 45 | * Blackboard for passing EMF model resources between jobs in the workflow. |
| 46 | */ |
| 47 | private MDSDBlackboard blackboard; |
| 48 | |
| 49 | /** |
| 50 | * The constructor. |
| 51 | * |
| 52 | * Configures the PCM Solver process according to the launch configuration |
| 53 | * defined by the user. |
| 54 | * |
| 55 | * @param configuration |
| 56 | * the solver configuration object |
| 57 | */ |
| 58 | public RunPCMAnalysisJob( |
| 59 | final PCMSolverWorkflowRunConfiguration configuration) { |
| 60 | |
| 61 | // Configure the PCM Solver process: |
| 62 | PDFConfiguration.setCurrentConfiguration(configuration.getDomainSize(), |
| 63 | configuration.getDistance(), |
| 64 | IProbabilityFunctionFactory.eINSTANCE.createDefaultUnit()); |
| 65 | if (configuration.isReliabilityAnalysis()) { |
| 66 | throw new RuntimeException( |
| 67 | "Invoked reliability analysis using wrong job class!"); |
| 68 | } else if (configuration.getSolver().equals(MessageStrings.SRE_SOLVER)) { |
| 69 | strategy = new Pcm2RegExStrategy(configuration); |
| 70 | } else if (configuration.getSolver().equals(MessageStrings.LQNS_SOLVER)) { |
| 71 | strategy = new Pcm2LqnStrategy(configuration); |
| 72 | } else if (configuration.getSolver() |
| 73 | .equals(MessageStrings.LQSIM_SOLVER)) { |
| 74 | strategy = new Pcm2LqnStrategy(configuration); |
| 75 | } |
| 76 | |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Executes the Solver workflow. |
| 81 | * |
| 82 | * @param monitor |
| 83 | * the progress monitor |
| 84 | * @throws JobFailedException |
| 85 | * indicates that one of the jobs in the workflow was not |
| 86 | * successfully completed |
| 87 | * @throws UserCanceledException |
| 88 | * indicates that the user has canceled the workflow before |
| 89 | * completion |
| 90 | */ |
| 91 | public void execute(final IProgressMonitor monitor) |
| 92 | throws JobFailedException, UserCanceledException { |
| 93 | |
| 94 | // Determine the PCM model parts from the launch configuration: |
| 95 | PCMInstance currentModel = new PCMInstance( |
| 96 | (PCMResourceSetPartition) this.blackboard |
| 97 | .getPartition(LoadPCMModelsIntoBlackboardJob.PCM_MODELS_PARTITION_ID)); |
| 98 | |
| 99 | // Check the model for being valid: |
| 100 | if (!currentModel.isValid()) { |
| 101 | logger.error("PCM Instance invalid! Check filenames."); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | // Only a very coarse progress monitoring is supported, which assigns |
| 106 | // 50% progress to the execution of the involved transformation(s), and |
| 107 | // 50% to the final solving: |
| 108 | monitor.beginTask("Analysis", 100); |
| 109 | strategy.transform(currentModel); |
| 110 | monitor.worked(50); |
| 111 | strategy.solve(); |
| 112 | monitor.worked(50); |
| 113 | } |
| 114 | |
| 115 | public SolverStrategy getStrategy() { |
| 116 | return strategy; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public void setBlackboard(MDSDBlackboard blackboard) { |
| 121 | this.blackboard = blackboard; |
| 122 | } |
| 123 | |
| 124 | public String getName() { |
| 125 | return "Run PCM Analysis"; |
| 126 | } |
| 127 | |
| 128 | public void rollback(IProgressMonitor monitor) |
| 129 | throws RollbackFailedException { |
| 130 | // Nothing to do here |
| 131 | } |
| 132 | } |