Skip to content

Commit

Permalink
add handling region in slaPlacementPolicies
Browse files Browse the repository at this point in the history
  • Loading branch information
lgiommi committed Jan 23, 2025
1 parent c1fa7e1 commit c6d8c02
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pipeline {

agent {
node { label 'jenkinsworker01' }
node { label 'jenkins-node-label-1' }
}

environment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@
package it.reply.orchestrator.dto.policies;

import com.fasterxml.jackson.annotation.JsonProperty;

import it.reply.orchestrator.utils.ToscaConstants.Policies.Types;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import javax.validation.constraints.NotNull;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

@Getter
@Setter
Expand All @@ -46,6 +42,10 @@ public class SlaPlacementPolicy extends GenericToscaPolicy {
@NotNull
private String slaId;

@Nullable
@JsonProperty("region")
private String slaRegion;

@JsonProperty("services_id")
@NonNull
@NotNull
Expand All @@ -71,11 +71,31 @@ protected SlaPlacementPolicy(
servicesId = new ArrayList<>();
}

protected SlaPlacementPolicy(
@NonNull String type,
@NonNull Set<String> targets,
@NonNull String slaId,
String slaRegion
) {
super(type, targets);
this.slaId = Objects.requireNonNull(slaId);
servicesId = new ArrayList<>();
this.slaRegion = slaRegion;
}

public SlaPlacementPolicy(
@NonNull Set<String> targets,
@NonNull String slaId
) {
this(Types.SLA_PLACEMENT, targets, slaId);
}

public SlaPlacementPolicy(
@NonNull Set<String> targets,
@NonNull String slaId,
String slaRegion
) {
this(Types.SLA_PLACEMENT, targets, slaId, slaRegion);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import it.reply.orchestrator.utils.ToscaConstants.Policies.Properties;
import it.reply.orchestrator.utils.ToscaConstants.Policies.Types;
import it.reply.orchestrator.utils.ToscaUtils;

import lombok.experimental.UtilityClass;

import org.alien4cloud.tosca.model.templates.PolicyTemplate;

@UtilityClass
Expand All @@ -41,7 +39,10 @@ public static ToscaPolicy fromToscaType(PolicyTemplate policyTemplate) {
String slaIdProperty = ToscaUtils
.extractScalar(policyTemplate.getProperties(), Properties.PLACEMENT_ID)
.orElse(null);
return new SlaPlacementPolicy(policyTemplate.getTargets(), slaIdProperty);
String slaRegionProperty = ToscaUtils
.extractScalar(policyTemplate.getProperties(), Properties.SLA_REGION)
.orElse(null);
return new SlaPlacementPolicy(policyTemplate.getTargets(), slaIdProperty, slaRegionProperty);
} else {
return new GenericToscaPolicy(policyTemplate.getType(), policyTemplate.getTargets());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ private void discardOnPlacementPolicies(Map<String, ToscaPolicy> placementPolici
.flatMap(policy -> policy.getServicesId().stream())
.anyMatch(serviceId -> serviceId.equals(cloudService.getId()));
boolean credentialsRequired = cloudService.isCredentialsRequired();
// If the SLA policy has a region, the service must be in that region
if (serviceIsInSlaPolicy) {
serviceIsInSlaPolicy = slaPlacementPolicies.get(0).getSlaRegion() == null
|| slaPlacementPolicies.get(0).getSlaRegion().isEmpty()
|| slaPlacementPolicies.get(0).getSlaRegion()
.equals(cloudService.getRegion());
}
if (!serviceIsInSlaPolicy && (slaPlacementRequired || credentialsRequired)) {
LOG.debug(
"Discarded service {} of provider {} because it doesn't match SLA policies",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ public boolean doDeploy(DeploymentMessage deploymentMessage) {
? ar.getArchive().getTags().get(0).getValue()
: null);
logData.put("provider_name", deployment.getCloudProviderName());
logData.put("provider_region", deployment.getCloudProviderEndpoint().getRegion().orElse(null));
logData.put("user_group", deployment.getUserGroup());

// Print information about the submission of the deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static class Types {
public static class Properties {

public static final String PLACEMENT_ID = "sla_id";
public static final String SLA_REGION = "region";
}
}
}

0 comments on commit c6d8c02

Please sign in to comment.