-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(disable): add an optional waitForDisabledServerGroup task (#3943)
* feat(disable): add an optional waitForDisabledServerGroup task When we disable a server group, we disable and also take instances down, but only wait for instances to become down. This means that it is possible to finish a DisableServerGroupStage successfully with down instances but a server group that does not yet appear disabled. This creates poor interactions, for instance if the stage that follows is a resize.
- Loading branch information
Showing
12 changed files
with
180 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
.../netflix/spinnaker/orca/clouddriver/tasks/servergroup/WaitForDisabledServerGroupTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.netflix.spinnaker.orca.clouddriver.tasks.servergroup; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.netflix.spinnaker.orca.api.pipeline.RetryableTask; | ||
import com.netflix.spinnaker.orca.api.pipeline.TaskResult; | ||
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus; | ||
import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution; | ||
import com.netflix.spinnaker.orca.clouddriver.OortService; | ||
import com.netflix.spinnaker.orca.clouddriver.pipeline.servergroup.support.TargetServerGroup; | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.AbstractCloudProviderAwareTask; | ||
import com.netflix.spinnaker.orca.clouddriver.utils.ServerGroupDescriptor; | ||
import com.netflix.spinnaker.orca.retrofit.exceptions.RetrofitExceptionHandler; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import retrofit.RetrofitError; | ||
|
||
@Component | ||
@Slf4j | ||
public class WaitForDisabledServerGroupTask extends AbstractCloudProviderAwareTask | ||
implements RetryableTask { | ||
private final OortService oortService; | ||
private final ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
WaitForDisabledServerGroupTask(OortService oortService, ObjectMapper objectMapper) { | ||
this.oortService = oortService; | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
@Override | ||
public long getBackoffPeriod() { | ||
return 10000; | ||
} | ||
|
||
@Override | ||
public long getTimeout() { | ||
return 1800000; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public TaskResult execute(@NotNull StageExecution stage) { | ||
val serverGroupDescriptor = getServerGroupDescriptor(stage); | ||
try { | ||
var serverGroup = fetchServerGroup(serverGroupDescriptor); | ||
return serverGroup.isDisabled() ? TaskResult.SUCCEEDED : TaskResult.RUNNING; | ||
} catch (RetrofitError e) { | ||
val retrofitErrorResponse = new RetrofitExceptionHandler().handle(stage.getName(), e); | ||
log.error("Unexpected retrofit error {}", retrofitErrorResponse, e); | ||
return TaskResult.builder(ExecutionStatus.RUNNING) | ||
.context(Collections.singletonMap("lastRetrofitException", retrofitErrorResponse)) | ||
.build(); | ||
} catch (IOException e) { | ||
log.error("Unexpected exception", e); | ||
return TaskResult.builder(ExecutionStatus.RUNNING) | ||
.context(Collections.singletonMap("lastException", e)) | ||
.build(); | ||
} | ||
} | ||
|
||
private TargetServerGroup fetchServerGroup(ServerGroupDescriptor serverGroupDescriptor) | ||
throws IOException { | ||
val response = | ||
oortService.getServerGroup( | ||
serverGroupDescriptor.getAccount(), | ||
serverGroupDescriptor.getRegion(), | ||
serverGroupDescriptor.getName()); | ||
var serverGroupData = | ||
(Map<String, Object>) objectMapper.readValue(response.getBody().in(), Map.class); | ||
return new TargetServerGroup(serverGroupData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
orca-core/src/main/java/com/netflix/spinnaker/orca/clouddriver/utils/Descriptors.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.netflix.spinnaker.orca.clouddriver.utils | ||
|
||
data class ClusterDescriptor(val app: String, val account: String, val name: String, val cloudProvider: String) | ||
data class ServerGroupDescriptor(val account: String, val name: String, val region: String) |