-
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.
- Loading branch information
AbdulRahman AlHamali
committed
Mar 22, 2021
1 parent
fa7d423
commit 40ecffd
Showing
11 changed files
with
524 additions
and
9 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
61 changes: 61 additions & 0 deletions
61
...in/java/com/netflix/spinnaker/orca/interlink/events/IgnoreStageFailureInterlinkEvent.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,61 @@ | ||
/* | ||
* Copyright 2020 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.interlink.events; | ||
|
||
import static com.netflix.spinnaker.orca.interlink.events.InterlinkEvent.EventType.IGNORE_FAILURE; | ||
|
||
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionType; | ||
import com.netflix.spinnaker.orca.pipeline.CompoundExecutionOperator; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* This event is published on the interlink as a result of a user IGNORING THE FAILURE of a stage on | ||
* an orca instance that can't handle the partition for the given execution. | ||
* | ||
* <p>The event is then handled by an orca instance (listening on interlink) whose partition matches | ||
* that of the execution. The resulting repository mutations of this event will then be peered by | ||
* the PeeringAgent | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class IgnoreStageFailureInterlinkEvent implements InterlinkEvent { | ||
final EventType eventType = IGNORE_FAILURE; | ||
@Nullable String partition; | ||
@Nonnull ExecutionType executionType; | ||
@Nonnull String executionId; | ||
@Nonnull String stageId; | ||
|
||
public IgnoreStageFailureInterlinkEvent( | ||
@Nonnull ExecutionType executionType, @Nonnull String executionId, @Nonnull String stageId) { | ||
// for the moment, only ExecutionType.PIPELINE can have ignored stages | ||
// but since we are defining the protocol on the wire here, let's be a bit future proof and | ||
// accept potentially different execution types | ||
this.executionType = executionType; | ||
this.executionId = executionId; | ||
this.stageId = stageId; | ||
} | ||
|
||
@Override | ||
public void applyTo(CompoundExecutionOperator executionOperator) { | ||
executionOperator.ignoreStageFailure(executionId, stageId); | ||
} | ||
} |
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
83 changes: 83 additions & 0 deletions
83
orca-queue/src/main/kotlin/com/netflix/spinnaker/orca/q/handler/IgnoreStageFailureHandler.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,83 @@ | ||
/* | ||
* Copyright 2017 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.q.handler | ||
|
||
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus.* | ||
import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution | ||
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilderFactory | ||
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository | ||
import com.netflix.spinnaker.orca.q.IgnoreStageFailure | ||
import com.netflix.spinnaker.orca.q.pending.PendingExecutionService | ||
import com.netflix.spinnaker.q.Queue | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.stereotype.Component | ||
import java.time.Clock | ||
|
||
@Component | ||
class IgnoreStageFailureHandler( | ||
override val queue: Queue, | ||
override val repository: ExecutionRepository, | ||
override val stageDefinitionBuilderFactory: StageDefinitionBuilderFactory, | ||
private val pendingExecutionService: PendingExecutionService, | ||
private val clock: Clock | ||
) : OrcaMessageHandler<IgnoreStageFailure>, StageBuilderAware { | ||
|
||
override val messageType = IgnoreStageFailure::class.java | ||
|
||
private val log: Logger get() = LoggerFactory.getLogger(javaClass) | ||
|
||
override fun handle(message: IgnoreStageFailure) { | ||
message.withStage { stage -> | ||
if (!stage.status.isHalt) { | ||
log.warn("Attempting to ignore the failure of stage $stage which is not halted. Will ignore") | ||
} else if (stage.execution.shouldQueue()) { | ||
// this pipeline is already running and has limitConcurrent = true | ||
stage.execution.pipelineConfigId?.let { | ||
log.info("Queueing IgnoreStageFailure of {} {} {}", stage.execution.application, stage.execution.name, stage.execution.id) | ||
pendingExecutionService.enqueue(it, message) | ||
} | ||
} else { | ||
stage.status = FAILED_CONTINUE | ||
stage.addIgnoreFailureDetails(message.user) | ||
repository.storeStage(stage) | ||
|
||
val topLevelStage = stage.topLevelStage | ||
if (topLevelStage != stage) { | ||
topLevelStage.status = RUNNING | ||
repository.storeStage(topLevelStage) | ||
} | ||
|
||
val execution = topLevelStage.execution | ||
if (execution.status.isHalt) { | ||
stage.execution.updateStatus(RUNNING) | ||
repository.updateStatus(execution) | ||
} | ||
|
||
stage.startNext() | ||
} | ||
} | ||
} | ||
|
||
private fun StageExecution.addIgnoreFailureDetails(user: String?) { | ||
context["ignoreFailureDetails"] = mapOf( | ||
"failureIgnoredBy" to (user ?: "anonymous"), | ||
"failureIgnoreTime" to clock.millis(), | ||
"previousException" to context.remove("exception") | ||
) | ||
} | ||
} |
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
Oops, something went wrong.