-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathOperation.java
More file actions
106 lines (88 loc) · 3.31 KB
/
Operation.java
File metadata and controls
106 lines (88 loc) · 3.31 KB
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
package cambio.simulator.entities.microservice;
import java.util.Arrays;
import cambio.simulator.entities.NamedEntity;
import cambio.simulator.entities.networking.DependencyDescription;
import cambio.simulator.entities.networking.ServiceDependencyInstance;
import cambio.simulator.models.MiSimModel;
import com.google.gson.annotations.Expose;
import desmoj.core.dist.NumericalDist;
/**
* An {@code Operation} represents an endpoint of a service. It has a specific computational demand and may have
* dependencies.
*/
public class Operation extends NamedEntity {
private final transient Microservice ownerMS;
@Expose
private int demand;
@Expose
private DependencyDescription[] dependencies = new DependencyDescription[0];
/**
* Constructs a new endpoint for a microservice.
*
* @param ownerMS {@link Microservice} that owns this operation.
* @param demand CPU demand of this operation.
*/
public Operation(MiSimModel model, String name, boolean showInTrace, Microservice ownerMS, int demand) {
super(model, (ownerMS == null ? "" : ownerMS.getPlainName() + ".") + name, showInTrace);
this.demand = demand;
this.ownerMS = ownerMS;
}
public DependencyDescription[] getDependencyDescriptions() {
return dependencies;
}
public int getDemand() {
return demand;
}
public Microservice getOwnerMS() {
return ownerMS;
}
@Override
public String getQuotedName() {
return "'" + getPlainName() + "'";
}
@Override
public String toString() {
return getFullyQualifiedName();
}
public String getFullyQualifiedName() {
return ownerMS.getPlainName() + "." + getName();
}
public String getFullyQualifiedPlainName() {
return ownerMS.getPlainName() + "." + getPlainName();
}
public String getQuotedFullyQualifiedName() {
return "'" + getFullyQualifiedName() + "'";
}
/**
* Add additional delay to this operation.
*
* @param dist {@link NumericalDist} of the delay.
* @param operationTrg target {@link Operation} of this that should be affected, can be set to {@code null} to
* affect all outgoing {@link ServiceDependencyInstance}s
*/
public void applyExtraDelay(NumericalDist<Double> dist, Operation operationTrg) {
if (operationTrg == null) {
for (DependencyDescription dependencyDescription : dependencies) {
dependencyDescription.setExtraDelay(dist);
}
} else {
DependencyDescription targetDependency =
Arrays.stream(dependencies).filter(dependency -> dependency.getTargetOperation() == operationTrg)
.findFirst().orElse(null);
if (targetDependency == null) {
throw new IllegalStateException(String
.format("Operation %s is not a dependency of %s", operationTrg.getQuotedName(),
this.getQuotedName()));
}
targetDependency.setExtraDelay(dist);
}
}
/**
* Add extra delay to every dependency of this operation.
*
* @param dist {@link NumericalDist} of the delay.
*/
public void applyExtraDelay(NumericalDist<Double> dist) {
applyExtraDelay(dist, null);
}
}