Skip to content

Commit c6d8c02

Browse files
committed
add handling region in slaPlacementPolicies
1 parent c1fa7e1 commit c6d8c02

File tree

6 files changed

+39
-9
lines changed

6 files changed

+39
-9
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pipeline {
22

33
agent {
4-
node { label 'jenkinsworker01' }
4+
node { label 'jenkins-node-label-1' }
55
}
66

77
environment {

src/main/java/it/reply/orchestrator/dto/policies/SlaPlacementPolicy.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,18 @@
1818
package it.reply.orchestrator.dto.policies;
1919

2020
import com.fasterxml.jackson.annotation.JsonProperty;
21-
2221
import it.reply.orchestrator.utils.ToscaConstants.Policies.Types;
23-
2422
import java.util.ArrayList;
2523
import java.util.List;
2624
import java.util.Objects;
2725
import java.util.Set;
28-
2926
import javax.validation.constraints.NotNull;
30-
3127
import lombok.EqualsAndHashCode;
3228
import lombok.Getter;
3329
import lombok.Setter;
3430
import lombok.ToString;
35-
3631
import org.checkerframework.checker.nullness.qual.NonNull;
32+
import org.checkerframework.checker.nullness.qual.Nullable;
3733

3834
@Getter
3935
@Setter
@@ -46,6 +42,10 @@ public class SlaPlacementPolicy extends GenericToscaPolicy {
4642
@NotNull
4743
private String slaId;
4844

45+
@Nullable
46+
@JsonProperty("region")
47+
private String slaRegion;
48+
4949
@JsonProperty("services_id")
5050
@NonNull
5151
@NotNull
@@ -71,11 +71,31 @@ protected SlaPlacementPolicy(
7171
servicesId = new ArrayList<>();
7272
}
7373

74+
protected SlaPlacementPolicy(
75+
@NonNull String type,
76+
@NonNull Set<String> targets,
77+
@NonNull String slaId,
78+
String slaRegion
79+
) {
80+
super(type, targets);
81+
this.slaId = Objects.requireNonNull(slaId);
82+
servicesId = new ArrayList<>();
83+
this.slaRegion = slaRegion;
84+
}
85+
7486
public SlaPlacementPolicy(
7587
@NonNull Set<String> targets,
7688
@NonNull String slaId
7789
) {
7890
this(Types.SLA_PLACEMENT, targets, slaId);
7991
}
8092

93+
public SlaPlacementPolicy(
94+
@NonNull Set<String> targets,
95+
@NonNull String slaId,
96+
String slaRegion
97+
) {
98+
this(Types.SLA_PLACEMENT, targets, slaId, slaRegion);
99+
}
100+
81101
}

src/main/java/it/reply/orchestrator/dto/policies/ToscaPolicyFactory.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
import it.reply.orchestrator.utils.ToscaConstants.Policies.Properties;
2121
import it.reply.orchestrator.utils.ToscaConstants.Policies.Types;
2222
import it.reply.orchestrator.utils.ToscaUtils;
23-
2423
import lombok.experimental.UtilityClass;
25-
2624
import org.alien4cloud.tosca.model.templates.PolicyTemplate;
2725

2826
@UtilityClass
@@ -41,7 +39,10 @@ public static ToscaPolicy fromToscaType(PolicyTemplate policyTemplate) {
4139
String slaIdProperty = ToscaUtils
4240
.extractScalar(policyTemplate.getProperties(), Properties.PLACEMENT_ID)
4341
.orElse(null);
44-
return new SlaPlacementPolicy(policyTemplate.getTargets(), slaIdProperty);
42+
String slaRegionProperty = ToscaUtils
43+
.extractScalar(policyTemplate.getProperties(), Properties.SLA_REGION)
44+
.orElse(null);
45+
return new SlaPlacementPolicy(policyTemplate.getTargets(), slaIdProperty, slaRegionProperty);
4546
} else {
4647
return new GenericToscaPolicy(policyTemplate.getType(), policyTemplate.getTargets());
4748
}

src/main/java/it/reply/orchestrator/service/commands/PrefilterCloudProviders.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ private void discardOnPlacementPolicies(Map<String, ToscaPolicy> placementPolici
318318
.flatMap(policy -> policy.getServicesId().stream())
319319
.anyMatch(serviceId -> serviceId.equals(cloudService.getId()));
320320
boolean credentialsRequired = cloudService.isCredentialsRequired();
321+
// If the SLA policy has a region, the service must be in that region
322+
if (serviceIsInSlaPolicy) {
323+
serviceIsInSlaPolicy = slaPlacementPolicies.get(0).getSlaRegion() == null
324+
|| slaPlacementPolicies.get(0).getSlaRegion().isEmpty()
325+
|| slaPlacementPolicies.get(0).getSlaRegion()
326+
.equals(cloudService.getRegion());
327+
}
321328
if (!serviceIsInSlaPolicy && (slaPlacementRequired || credentialsRequired)) {
322329
LOG.debug(
323330
"Discarded service {} of provider {} because it doesn't match SLA policies",

src/main/java/it/reply/orchestrator/service/deployment/providers/ImServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ public boolean doDeploy(DeploymentMessage deploymentMessage) {
537537
? ar.getArchive().getTags().get(0).getValue()
538538
: null);
539539
logData.put("provider_name", deployment.getCloudProviderName());
540+
logData.put("provider_region", deployment.getCloudProviderEndpoint().getRegion().orElse(null));
540541
logData.put("user_group", deployment.getUserGroup());
541542

542543
// Print information about the submission of the deployment

src/main/java/it/reply/orchestrator/utils/ToscaConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public static class Types {
120120
public static class Properties {
121121

122122
public static final String PLACEMENT_ID = "sla_id";
123+
public static final String SLA_REGION = "region";
123124
}
124125
}
125126
}

0 commit comments

Comments
 (0)