From 66a7a8a2fcaaf2c38a9b48e0f8fc129d8417772a Mon Sep 17 00:00:00 2001 From: aman-agrawal <9412470@gmail.com> Date: Fri, 6 Oct 2023 12:45:48 +0530 Subject: [PATCH] Reverted - Added Interactive component for manual judgement awaited and callback --- .../spinnaker/orca/echo/EchoService.groovy | 38 ---------- .../ManualJudgementCallbackHandler.groovy | 70 ------------------- .../echo/pipeline/ManualJudgmentStage.groovy | 35 +--------- .../NotificationCallbackController.groovy | 47 ------------- 4 files changed, 3 insertions(+), 187 deletions(-) delete mode 100644 orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/notification/ManualJudgementCallbackHandler.groovy delete mode 100644 orca-web/src/main/groovy/com/netflix/spinnaker/orca/controllers/NotificationCallbackController.groovy diff --git a/orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/EchoService.groovy b/orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/EchoService.groovy index 98186d5067..87a028a164 100644 --- a/orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/EchoService.groovy +++ b/orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/EchoService.groovy @@ -17,9 +17,6 @@ package com.netflix.spinnaker.orca.echo import com.fasterxml.jackson.annotation.JsonInclude -import com.fasterxml.jackson.annotation.JsonSubTypes -import com.fasterxml.jackson.annotation.JsonTypeInfo -import groovy.transform.Canonical import retrofit.client.Response import retrofit.http.Body import retrofit.http.GET @@ -49,8 +46,6 @@ interface EchoService { Source source Map additionalContext = [:] - InteractiveActions interactiveActions - Boolean useInteractiveBot = false static class Source { String executionType @@ -76,39 +71,6 @@ interface EchoService { NORMAL, HIGH } - static class InteractiveActions { - String callbackServiceId - String callbackMessageId - String color = '#cccccc' - List actions = [] - } - - @JsonTypeInfo( - include = JsonTypeInfo.As.EXISTING_PROPERTY, - use = JsonTypeInfo.Id.NAME, - property = "type") - @JsonSubTypes( - @JsonSubTypes.Type(value = ButtonAction.class, name = "button") - ) - abstract static class InteractiveAction { - String type - String name - String value - } - - @Canonical - static class ButtonAction extends InteractiveAction { - String type = "button" - String label - } - - @Canonical - static class InteractiveActionCallback { - InteractiveAction actionPerformed - String serviceId - String messageId - String user - } } } diff --git a/orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/notification/ManualJudgementCallbackHandler.groovy b/orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/notification/ManualJudgementCallbackHandler.groovy deleted file mode 100644 index 24e1283d0b..0000000000 --- a/orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/notification/ManualJudgementCallbackHandler.groovy +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2022 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.echo.notification - -import com.google.common.base.Preconditions -import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionType -import com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution -import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution -import com.netflix.spinnaker.orca.pipeline.CompoundExecutionOperator -import com.netflix.spinnaker.security.AuthenticatedRequest -import org.apache.commons.lang3.StringUtils -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.http.RequestEntity -import org.springframework.http.ResponseEntity -import org.springframework.stereotype.Component - -import static com.netflix.spinnaker.orca.echo.EchoService.Notification.InteractiveActionCallback - -@Component -class ManualJudgementCallbackHandler { - @Autowired - CompoundExecutionOperator executionOperator - - ResponseEntity processCallback(RequestEntity request) { - InteractiveActionCallback interactiveActionCallback = request.getBody() - String judgement = interactiveActionCallback.getActionPerformed().getValue() - String messageId = interactiveActionCallback.getMessageId() - String user = interactiveActionCallback.getUser() - String[] ids = StringUtils.split(messageId, "-") - Preconditions.checkArgument(ids.length == 3, "Unexpected message id") - ExecutionType executionType = getExecutionType(ids[0]) - String executionId = ids[1] - String stageId = ids[2] - PipelineExecution pipelineExecution = executionOperator.updateStage(executionType, executionId, stageId, - { stage -> - stage.context.putAll(Map.of("judgmentStatus", judgement.toLowerCase())) - stage.lastModified = new StageExecution.LastModifiedDetails( - user: user, - allowedAccounts: AuthenticatedRequest.getSpinnakerAccounts().orElse(null)?.split(",") ?: [], - lastModifiedTime: System.currentTimeMillis() - ) - stage.context["lastModifiedBy"] = stage.lastModified.user - }) - String pipelineName = pipelineExecution.getName() - return ResponseEntity.ok("pipeline $pipelineName updated successfully") as ResponseEntity - } - - private static ExecutionType getExecutionType(String name) { - for (ExecutionType executionType : ExecutionType.values()) { - if (executionType.toString().equalsIgnoreCase(name)) { - return executionType; - } - } - throw new IllegalArgumentException(); - } -} diff --git a/orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/pipeline/ManualJudgmentStage.groovy b/orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/pipeline/ManualJudgmentStage.groovy index f6fd2c69b0..16b5109093 100644 --- a/orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/pipeline/ManualJudgmentStage.groovy +++ b/orca-echo/src/main/groovy/com/netflix/spinnaker/orca/echo/pipeline/ManualJudgmentStage.groovy @@ -19,11 +19,6 @@ package com.netflix.spinnaker.orca.echo.pipeline import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonIgnore -import com.google.common.collect.ImmutableList -import com.fasterxml.jackson.core.type.TypeReference -import com.fasterxml.jackson.databind.ObjectMapper -import com.google.common.base.Strings -import com.netflix.spinnaker.fiat.shared.FiatStatus import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus import com.netflix.spinnaker.orca.api.pipeline.OverridableTimeoutRetryableTask import com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution @@ -41,7 +36,6 @@ import com.netflix.spinnaker.orca.api.pipeline.graph.TaskNode import groovy.util.logging.Slf4j import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component -import static com.netflix.spinnaker.orca.echo.EchoService.Notification.InteractiveActions @Component class ManualJudgmentStage implements StageDefinitionBuilder, AuthenticatedStage { @@ -68,13 +62,13 @@ class ManualJudgmentStage implements StageDefinitionBuilder, AuthenticatedStage return Optional.of( new PipelineExecution.AuthenticationDetails( stage.lastModified.user, - stage.lastModified.allowedAccounts)) + stage.lastModified.allowedAccounts)); } @Slf4j @Component @VisibleForTesting - static class WaitForManualJudgmentTask implements OverridableTimeoutRetryableTask { + public static class WaitForManualJudgmentTask implements OverridableTimeoutRetryableTask { final long backoffPeriod = 15000 final long timeout = TimeUnit.DAYS.toMillis(3) @@ -224,7 +218,6 @@ class ManualJudgmentStage implements StageDefinitionBuilder, AuthenticatedStage } void notify(EchoService echoService, StageExecution stage, String notificationState) { - boolean useInteractiveBot = ("manualJudgment".equalsIgnoreCase(notificationState)) echoService.create(new EchoService.Notification( notificationType: EchoService.Notification.Type.valueOf(type.toUpperCase()), to: address ? [address] : (publisherName ? [publisherName] : null), @@ -246,31 +239,9 @@ class ManualJudgmentStage implements StageDefinitionBuilder, AuthenticatedStage judgmentInputs : stage.context.judgmentInputs, judgmentInput : stage.context.judgmentInput, judgedBy : stage.context.lastModifiedBy - ], - useInteractiveBot: useInteractiveBot, - interactiveActions: useInteractiveBot ? getInteractiveActions(stage) : null + ] )) lastNotifiedByNotificationState[notificationState] = new Date() } - - private static InteractiveActions getInteractiveActions(StageExecution stage) { - new InteractiveActions( - callbackServiceId: "orca", - callbackMessageId: "${stage.getExecution().getType()}-${stage.getExecution().getId()}-${stage.getId()}", - color: '#fcba03', - actions: ImmutableList.of( - new EchoService.Notification.ButtonAction( - name: "manual-judgement", - label: "Approve", - value: StageData.State.CONTINUE.name() - ), - new EchoService.Notification.ButtonAction( - name: "manual-judgement", - label: "Reject", - value: StageData.State.STOP.name() - ) - ) - ) - } } } diff --git a/orca-web/src/main/groovy/com/netflix/spinnaker/orca/controllers/NotificationCallbackController.groovy b/orca-web/src/main/groovy/com/netflix/spinnaker/orca/controllers/NotificationCallbackController.groovy deleted file mode 100644 index 5bb6587b8e..0000000000 --- a/orca-web/src/main/groovy/com/netflix/spinnaker/orca/controllers/NotificationCallbackController.groovy +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2022 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.controllers - -import com.netflix.spinnaker.orca.echo.notification.ManualJudgementCallbackHandler -import groovy.util.logging.Slf4j -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.http.MediaType -import org.springframework.http.RequestEntity -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestMethod -import org.springframework.web.bind.annotation.RestController - -import static com.netflix.spinnaker.orca.echo.EchoService.Notification.InteractiveActionCallback - -@RequestMapping("/notifications") -@RestController -@Slf4j -class NotificationCallbackController { - - @Autowired - ManualJudgementCallbackHandler manualJudgementCallbackHandler; - - @RequestMapping( - value = "/callback", - method = RequestMethod.POST, - consumes = MediaType.APPLICATION_JSON_VALUE, - produces = MediaType.APPLICATION_JSON_VALUE) - ResponseEntity processCallback(RequestEntity request) { - return manualJudgementCallbackHandler.processCallback(request) - } -}