Skip to content

Commit

Permalink
chore(core): removing clusterLock feature (#3136)
Browse files Browse the repository at this point in the history
  • Loading branch information
asher committed Sep 16, 2019
1 parent 2eb465a commit f3e3db0
Show file tree
Hide file tree
Showing 34 changed files with 20 additions and 2,322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.AbstractClusterWideClouddriverTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.AbstractWaitForClusterWideClouddriverTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.servergroup.ServerGroupCacheForceRefreshTask;
import com.netflix.spinnaker.orca.clouddriver.utils.ClusterLockHelper;
import com.netflix.spinnaker.orca.clouddriver.utils.MonikerHelper;
import com.netflix.spinnaker.orca.clouddriver.utils.TrafficGuard;
import com.netflix.spinnaker.orca.locks.LockingConfigurationProperties;
import com.netflix.spinnaker.orca.pipeline.AcquireLockStage;
import com.netflix.spinnaker.orca.pipeline.ReleaseLockStage;
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder;
import com.netflix.spinnaker.orca.pipeline.TaskNode;
import com.netflix.spinnaker.orca.pipeline.graph.StageGraphBuilder;
Expand All @@ -45,16 +40,10 @@
public abstract class AbstractClusterWideClouddriverOperationStage
implements StageDefinitionBuilder {

private final TrafficGuard trafficGuard;
private final LockingConfigurationProperties lockingConfigurationProperties;
private final DynamicConfigService dynamicConfigService;

protected AbstractClusterWideClouddriverOperationStage(
TrafficGuard trafficGuard,
LockingConfigurationProperties lockingConfigurationProperties,
DynamicConfigService dynamicConfigService) {
this.trafficGuard = Objects.requireNonNull(trafficGuard);
this.lockingConfigurationProperties = Objects.requireNonNull(lockingConfigurationProperties);
this.dynamicConfigService = dynamicConfigService;
}

Expand All @@ -69,53 +58,9 @@ protected static String getStepName(String taskClassSimpleName) {
return taskClassSimpleName;
}

@Override
public final void beforeStages(@Nonnull Stage parent, @Nonnull StageGraphBuilder graph) {
if (lockingConfigurationProperties.isEnabled()) {
List<Location> locations = locationsFromStage(parent.getContext());
ClusterSelection clusterSelection = parent.mapTo(ClusterSelection.class);
for (Location location : locations) {
String lockName =
ClusterLockHelper.clusterLockName(
clusterSelection.getMoniker(), clusterSelection.getCredentials(), location);
if (trafficGuard.hasDisableLock(
clusterSelection.getMoniker(), clusterSelection.getCredentials(), location)) {
graph.add(
stage -> {
stage.setType(AcquireLockStage.PIPELINE_TYPE);
stage.getContext().put("lock", Collections.singletonMap("lockName", lockName));
});
}
}
}
addAdditionalBeforeStages(parent, graph);
}

protected void addAdditionalBeforeStages(
@Nonnull Stage parent, @Nonnull StageGraphBuilder graph) {}

@Override
public final void afterStages(@Nonnull Stage parent, @Nonnull StageGraphBuilder graph) {
addAdditionalAfterStages(parent, graph);
if (lockingConfigurationProperties.isEnabled()) {
List<Location> locations = locationsFromStage(parent.getContext());
ClusterSelection clusterSelection = parent.mapTo(ClusterSelection.class);
for (Location location : locations) {
String lockName =
ClusterLockHelper.clusterLockName(
clusterSelection.getMoniker(), clusterSelection.getCredentials(), location);
if (trafficGuard.hasDisableLock(
clusterSelection.getMoniker(), clusterSelection.getCredentials(), location)) {
graph.append(
stage -> {
stage.setType(ReleaseLockStage.PIPELINE_TYPE);
stage.getContext().put("lock", Collections.singletonMap("lockName", lockName));
});
}
}
}
}

protected void addAdditionalAfterStages(
@Nonnull Stage parent, @Nonnull StageGraphBuilder graph) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.AbstractWaitForClusterWideClouddriverTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.DisableClusterTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.WaitForClusterDisableTask;
import com.netflix.spinnaker.orca.clouddriver.utils.TrafficGuard;
import com.netflix.spinnaker.orca.locks.LockingConfigurationProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -32,11 +30,8 @@ public class DisableClusterStage extends AbstractClusterWideClouddriverOperation
public static final String STAGE_TYPE = "disableCluster";

@Autowired
public DisableClusterStage(
TrafficGuard trafficGuard,
LockingConfigurationProperties lockingConfigurationProperties,
DynamicConfigService dynamicConfigService) {
super(trafficGuard, lockingConfigurationProperties, dynamicConfigService);
public DisableClusterStage(DynamicConfigService dynamicConfigService) {
super(dynamicConfigService);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@

package com.netflix.spinnaker.orca.clouddriver.pipeline.cluster;

import com.netflix.spinnaker.moniker.Moniker;
import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.RollbackServerGroupStage;
import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support.Location;
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.DetermineRollbackCandidatesTask;
import com.netflix.spinnaker.orca.clouddriver.utils.ClusterLockHelper;
import com.netflix.spinnaker.orca.clouddriver.utils.TrafficGuard;
import com.netflix.spinnaker.orca.locks.LockingConfigurationProperties;
import com.netflix.spinnaker.orca.pipeline.*;
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder;
import com.netflix.spinnaker.orca.pipeline.TaskNode;
import com.netflix.spinnaker.orca.pipeline.WaitStage;
import com.netflix.spinnaker.orca.pipeline.graph.StageGraphBuilder;
import com.netflix.spinnaker.orca.pipeline.model.Stage;
import java.util.Collections;
Expand All @@ -32,23 +29,12 @@
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RollbackClusterStage implements StageDefinitionBuilder {
public static final String PIPELINE_CONFIG_TYPE = "rollbackCluster";

private final TrafficGuard trafficGuard;
private final LockingConfigurationProperties lockingConfigurationProperties;

@Autowired
public RollbackClusterStage(
TrafficGuard trafficGuard, LockingConfigurationProperties lockingConfigurationProperties) {
this.trafficGuard = trafficGuard;
this.lockingConfigurationProperties = lockingConfigurationProperties;
}

@Override
public void taskGraph(@Nonnull Stage stage, @Nonnull TaskNode.Builder builder) {
builder.withTask("determineRollbackCandidates", DetermineRollbackCandidatesTask.class);
Expand All @@ -68,24 +54,6 @@ public void afterStages(@Nonnull Stage parent, @Nonnull StageGraphBuilder graph)
stageData.regions.stream().filter(rollbackTypes::containsKey).collect(Collectors.toList());

for (String region : regionsToRollback) {
boolean addLocking = false;
String lockName;
if (lockingConfigurationProperties.isEnabled()) {
final Location location = Location.region(region);
addLocking =
trafficGuard.hasDisableLock(stageData.moniker, stageData.credentials, location);
lockName =
ClusterLockHelper.clusterLockName(stageData.moniker, stageData.credentials, location);
if (addLocking) {
graph.append(
stage -> {
stage.setType(AcquireLockStage.PIPELINE_TYPE);
stage.getContext().put("lock", Collections.singletonMap("lockName", lockName));
});
}
} else {
lockName = null;
}
Map<String, Object> context = new HashMap<>();
context.put("rollbackType", ((Map) parent.getOutputs().get("rollbackTypes")).get(region));

Expand All @@ -110,14 +78,6 @@ public void afterStages(@Nonnull Stage parent, @Nonnull StageGraphBuilder graph)
it.setContext(context);
});

if (addLocking) {
graph.append(
stage -> {
stage.setType(ReleaseLockStage.PIPELINE_TYPE);
stage.getContext().put("lock", Collections.singletonMap("lockName", lockName));
});
}

if (stageData.waitTimeBetweenRegions != null
&& regionsToRollback.indexOf(region) < regionsToRollback.size() - 1) {
// only add the waitStage if we're not the very last region!
Expand Down Expand Up @@ -162,7 +122,6 @@ private static Map<String, Object> propagateParentStageContext(Stage parent) {
static class StageData {
public String credentials;
public String cloudProvider;
public Moniker moniker;

public List<String> regions;
public Long waitTimeBetweenRegions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.AbstractWaitForClusterWideClouddriverTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.ScaleDownClusterTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.WaitForScaleDownClusterTask;
import com.netflix.spinnaker.orca.clouddriver.utils.TrafficGuard;
import com.netflix.spinnaker.orca.locks.LockingConfigurationProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ScaleDownClusterStage extends AbstractClusterWideClouddriverOperationStage {

@Autowired
public ScaleDownClusterStage(
TrafficGuard trafficGuard,
LockingConfigurationProperties lockingConfigurationProperties,
DynamicConfigService dynamicConfigService) {
super(trafficGuard, lockingConfigurationProperties, dynamicConfigService);
public ScaleDownClusterStage(DynamicConfigService dynamicConfigService) {
super(dynamicConfigService);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.AbstractWaitForClusterWideClouddriverTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.ShrinkClusterTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.cluster.WaitForClusterShrinkTask;
import com.netflix.spinnaker.orca.clouddriver.utils.TrafficGuard;
import com.netflix.spinnaker.orca.locks.LockingConfigurationProperties;
import com.netflix.spinnaker.orca.pipeline.graph.StageGraphBuilder;
import com.netflix.spinnaker.orca.pipeline.model.Stage;
import java.util.HashMap;
Expand All @@ -41,11 +39,8 @@ public class ShrinkClusterStage extends AbstractClusterWideClouddriverOperationS

@Autowired
public ShrinkClusterStage(
TrafficGuard trafficGuard,
LockingConfigurationProperties lockingConfigurationProperties,
DynamicConfigService dynamicConfigService,
DisableClusterStage disableClusterStage) {
super(trafficGuard, lockingConfigurationProperties, dynamicConfigService);
DynamicConfigService dynamicConfigService, DisableClusterStage disableClusterStage) {
super(dynamicConfigService);
this.disableClusterStage = disableClusterStage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ package com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.strategies
import com.netflix.spinnaker.moniker.Moniker
import com.netflix.spinnaker.orca.clouddriver.pipeline.AbstractCloudProviderAwareStage
import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support.Location
import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support.TargetServerGroup
import com.netflix.spinnaker.orca.clouddriver.tasks.DetermineHealthProvidersTask
import com.netflix.spinnaker.orca.clouddriver.utils.ClusterLockHelper
import com.netflix.spinnaker.orca.clouddriver.utils.MonikerHelper
import com.netflix.spinnaker.orca.clouddriver.utils.TrafficGuard
import com.netflix.spinnaker.orca.kato.pipeline.strategy.DetermineSourceServerGroupTask
import com.netflix.spinnaker.orca.kato.pipeline.support.StageData
import com.netflix.spinnaker.orca.kato.tasks.DiffTask
import com.netflix.spinnaker.orca.locks.LockingConfigurationProperties
import com.netflix.spinnaker.orca.pipeline.AcquireLockStage
import com.netflix.spinnaker.orca.pipeline.ReleaseLockStage

import com.netflix.spinnaker.orca.pipeline.TaskNode
import com.netflix.spinnaker.orca.pipeline.graph.StageGraphBuilder
import com.netflix.spinnaker.orca.pipeline.model.Stage
Expand Down Expand Up @@ -59,9 +54,6 @@ abstract class AbstractDeployStrategyStage extends AbstractCloudProviderAwareSta
@Autowired
TrafficGuard trafficGuard

@Autowired
LockingConfigurationProperties lockingConfigurationProperties

AbstractDeployStrategyStage(String name) {
super(name)
}
Expand Down Expand Up @@ -118,19 +110,6 @@ abstract class AbstractDeployStrategyStage extends AbstractCloudProviderAwareSta
def preProcessors = deployStagePreProcessors.findAll { it.supports(stage) }
def stageData = stage.mapTo(StageData)
def stages = []
boolean addLocking = false
String lockName = null
if (lockingConfigurationProperties.isEnabled()) {
def moniker = stageData.moniker?.cluster ? stageData.moniker : MonikerHelper.friggaToMoniker(stageData.cluster)
def location = TargetServerGroup.Support.locationFromStageData(stageData)
lockName = ClusterLockHelper.clusterLockName(moniker, stageData.account, location)
addLocking = trafficGuard.hasDisableLock(moniker, stageData.account, location)
if (addLocking) {
def lockCtx = [lock: [lockName: lockName]]
def lockStage = newStage(stage.execution, AcquireLockStage.PIPELINE_TYPE, "acquireLock", lockCtx, stage, SyntheticStageOwner.STAGE_BEFORE)
stages << lockStage
}
}
stages.addAll(strategy.composeFlow(stage))

preProcessors.each {
Expand Down Expand Up @@ -159,16 +138,6 @@ abstract class AbstractDeployStrategyStage extends AbstractCloudProviderAwareSta
)
}
}
if (addLocking) {
stages << newStage(
stage.execution,
ReleaseLockStage.PIPELINE_TYPE,
'releaseLock',
[lock: [lockName: lockName]],
stage,
SyntheticStageOwner.STAGE_AFTER
)
}

return stages
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ package com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support
import com.netflix.spinnaker.orca.clouddriver.utils.ClusterLockHelper
import com.netflix.spinnaker.orca.clouddriver.utils.MonikerHelper
import com.netflix.spinnaker.orca.clouddriver.utils.TrafficGuard
import com.netflix.spinnaker.orca.locks.LockingConfigurationProperties
import com.netflix.spinnaker.orca.pipeline.AcquireLockStage
import com.netflix.spinnaker.orca.pipeline.ReleaseLockStage

import groovy.transform.stc.ClosureParams
import groovy.transform.stc.SimpleType

Expand All @@ -44,7 +42,6 @@ abstract class TargetServerGroupLinearStageSupport implements StageDefinitionBui

@Autowired TargetServerGroupResolver resolver
@Autowired TrafficGuard trafficGuard
@Autowired LockingConfigurationProperties lockingConfigurationProperties

/**
* Override to supply tasks that individual target stages will run. The top level
Expand Down Expand Up @@ -118,14 +115,6 @@ abstract class TargetServerGroupLinearStageSupport implements StageDefinitionBui
} else if (isTopLevel(parent.parent)) {
// a non top level stage operates on a single target and may have its own
// synthetic stages
withGuard(parent) { moniker, account, location ->
graph.add {
it.type = AcquireLockStage.PIPELINE_TYPE
it.name = 'acquireLock'
it.context = [lock: [lockName: ClusterLockHelper.clusterLockName(moniker, account, location)]]
}
}

if (isDynamicallyBound(parent)) {
preDynamic(parent.context, graph)
} else {
Expand All @@ -134,24 +123,6 @@ abstract class TargetServerGroupLinearStageSupport implements StageDefinitionBui
}
}

void withGuard(Stage parent,
@ClosureParams(
value = SimpleType,
options = [
'com.netflix.spinnaker.moniker.Moniker',
'java.lang.String',
'com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support.Location'
]) Closure handleGuard) {
if (lockingConfigurationProperties.isEnabled()) {
def param = TargetServerGroup.Params.fromStage(parent)
def moniker = param.moniker ?: MonikerHelper.friggaToMoniker(param.cluster ?: param.serverGroupName)
def location = param.locations[0]
if (trafficGuard.hasDisableLock(moniker, param.credentials, location)) {
handleGuard.call(moniker, param.credentials, location)
}
}
}

@Override
final void afterStages(
@Nonnull Stage parent,
Expand All @@ -167,14 +138,6 @@ abstract class TargetServerGroupLinearStageSupport implements StageDefinitionBui
} else {
postStatic(parent.context, graph)
}

withGuard(parent) { moniker, account, location ->
graph.append {
it.type = ReleaseLockStage.PIPELINE_TYPE
it.name = 'releaseLock'
it.context = [lock: [lockName: ClusterLockHelper.clusterLockName(moniker, account, location)]]
}
}
}
}

Expand Down
Loading

0 comments on commit f3e3db0

Please sign in to comment.