forked from spinnaker/orca
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Interactive component for manual judgement awaited and callback…
… handler.
- Loading branch information
1 parent
dcc439a
commit d964031
Showing
4 changed files
with
187 additions
and
4 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
70 changes: 70 additions & 0 deletions
70
...groovy/com/netflix/spinnaker/orca/echo/notification/ManualJudgementCallbackHandler.groovy
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,70 @@ | ||
/* | ||
* 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<String> processCallback(RequestEntity<InteractiveActionCallback> 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<String> | ||
} | ||
|
||
private static ExecutionType getExecutionType(String name) { | ||
for (ExecutionType executionType : ExecutionType.values()) { | ||
if (executionType.toString().equalsIgnoreCase(name)) { | ||
return executionType; | ||
} | ||
} | ||
throw new IllegalArgumentException(); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
.../main/groovy/com/netflix/spinnaker/orca/controllers/NotificationCallbackController.groovy
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,47 @@ | ||
/* | ||
* 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<String> processCallback(RequestEntity<InteractiveActionCallback> request) { | ||
return manualJudgementCallbackHandler.processCallback(request) | ||
} | ||
} |