-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackAnnotation.eol
152 lines (116 loc) · 4.62 KB
/
backAnnotation.eol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import "operations.eol";
// Annotates all the UML!UseCase stereotyped with GaScenario
var scenarios = UML!UseCase.all().select(i | i.checkStereotypeApplication("GaScenario"));
for(scenario in scenarios)
scenario.annotateScenario();
// Annotates all the UML!Node stereotyped with GaExecHost
var processors = UML!Node.all().select(i | i.checkStereotypeApplication("GaExecHost"));
for(processor in processors)
processor.annotateNode();
// Annotates all the UML!Message stereotyped with GaStep
var activities = UML!Message.all().select(i | i.checkStereotypeApplication("GaStep"));
for(activity in activities)
activity.annotateActivity();
/**
* Collects the children of the tag indicate with the parameter 'name'
* @return a collection containing the elements in the subtree of a tag
*/
operation getChildren(processor, name : String)
{
return processor.children.flatten.select(i | i.tagName = name);
}
operation Collection getChildren(name : String)
{
return self.children.flatten.select(i | i.tagName = name);
}
/**
* Calculates the response time of a Scenario
* @return a double
*/
operation UML!UseCase getScenarioRespTime()
{
// Gets the names of the actors triggering a scenario
var lifelines = self.classifierBehavior.lifelines.select(i | i.checkStereotypeApplication("GaWorkloadEvent"));
if(lifelines.isEmpty())
throw "Error: GaWorkloadEvent not found in scenario's lifelines";
// Gets the type of a lifeline (e.g., UML!Component, UML! Actor)
var types = lifelines.represents.collect(i | i.getType().name);
// Gets all the reference tasks
//var referenceTasks = `t_task`.all().select(i | i.`a_scheduling` == "ref" and types.includes(i.`a_name`));
var referenceTasks = LQXO!`t_task`.all().select(i | i.`a_scheduling` == "ref" and types.includes(i.`a_name`));
var entries = referenceTasks.getChildren("entry");
var entryPhases = entries.getChildren("entry-phase-activities");
var activities = entryPhases.getChildren("activity");
// @Assumption the calls execues sequentially
var times = activities.getChildren("result-activity").`a_service-time`;
times = times.collect(i | i.asDouble());
return times.sum();
}
/**
* Given a Scenario, the function retrieves the response time calculated in the LQN;
* Calculates the throughput and annotates the source model
*/
operation UML!UseCase annotateScenario()
{
self.name.println();
var stereotype = self.getAppliedStereotypes().selectOne(i | i.name = "GaScenario");
// Sets Response Time
var resptime = self.getScenarioRespTime();
self.setValue(stereotype, "respT", Sequence{resptime.asString()});
// Sets Throughput
var root = self.getValue(stereotype, "root");
root.println("root: ");
// Calculates Throughput
var throughput = root.rep.asDouble() / resptime;
self.setValue(stereotype, "throughput", Sequence{throughput.asString()});
// Stores the values
UML.store().println("Scenario: " + self.name + " ResponseTime: " +
resptime + " Throughput: " + throughput + " Stored: ");
}
/**
* Retrieves and sets the utilization to a UML!Node
*/
operation UML!Node annotateNode()
{
var stereotype = self.getAppliedStereotypes().selectOne(i | i.name == "GaExecHost");
var clones = UML!Node.all().select(i | i.checkStereotypeApplication("GaExecHost"));
clones = clones.select(i | i.getSpeedFactor() = self.getSpeedFactor() and i.getDeployed() = self.getDeployed());
//var processor =`t_processor`.all().selectOne(i | i.`a_name` = self.name);
var processor = LQXO!`t_processor`.all().selectOne(i | i.`a_name` = self.name);
var utilization = Sequence{"0.0"};
/*
* If the node is actually transformed, then it retrieves and sets the utilization
* otherwise, the utilization is set to zero
*/
if(processor.isDefined())
{
// Sets the utilization
var subtree = getChildren(processor, "result-processor");
utilization = subtree.select(i | i.name = "result-processor").a_utilization;
}
if(utilization.first.asDouble() != 0.0)
{
for(element in clones)
{
element.setValue(stereotype, "utilization", utilization);
}
}
UML.store();
}
/**
* Adds the service time to a UML!Message
*/
operation UML!Message annotateActivity()
{
`t_activity`.all().println();
self.name.println();
var activity =`t_activity`.all().selectOne(i | i.`a_name` = self.name);
var stereotype = self.getAppliedStereotypes().selectOne(i | i.name == "GaStep");
self.println();
activity.println("activity: ");
var subtree = getChildren(activity, "result-activity");
var serviceTime = subtree.`a_service-time`;
self.setValue(stereotype, "respT", serviceTime);
UML.store().println("Activity: " + activity.a_name + " ServiceTime: " +
serviceTime.first + " Stored: ");
}