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