This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
CLI: Update Detector Configurations #233
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
31d789a
CLI: Update Detector Gateway
VijayanB 17c1a99
CLI: Update Detector Entity
VijayanB 609edfc
CLI: Update Detector Mapper
VijayanB 7ba6ab8
CLI: Update Detector Controller
VijayanB a0b8dac
CLI: Update Detector Input/Output Handler
VijayanB 643f595
CLI: Update Command
VijayanB d7ce418
Address Feedback
VijayanB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* or in the "license" file accompanying this file. This file 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 cmd | ||
|
||
import ( | ||
handler "esad/internal/handler/ad" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
commandUpdate = "update" | ||
flagForce = "force" | ||
flagStart = "start" | ||
) | ||
|
||
//updateCmd updates detectors based on file configuration | ||
var updateCmd = &cobra.Command{ | ||
Use: commandUpdate + " [list of file-path] [flags]", | ||
Short: "Updates detectors based on configurations", | ||
Long: `Updates detectors based on configurations specified by file path`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
//If no args, display usage | ||
if len(args) < 1 { | ||
if err := cmd.Usage(); err != nil { | ||
fmt.Println(err) | ||
} | ||
return | ||
} | ||
force, _ := cmd.Flags().GetBool(flagForce) | ||
restart, _ := cmd.Flags().GetBool(flagStart) | ||
err := updateDetectors(args, force, restart) | ||
if err != nil { | ||
fmt.Println(commandUpdate, "command failed") | ||
fmt.Println("Reason:", err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
esadCmd.AddCommand(updateCmd) | ||
updateCmd.Flags().BoolP(flagForce, "f", false, "Will stop detector and update it") | ||
updateCmd.Flags().BoolP(flagStart, "r", false, "Will start detector if update is successful") | ||
} | ||
|
||
func updateDetectors(fileNames []string, force bool, restart bool) error { | ||
commandHandler, err := getCommandHandler() | ||
if err != nil { | ||
return err | ||
} | ||
for _, name := range fileNames { | ||
err = handler.UpdateAnomalyDetector(commandHandler, name, force, restart) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if detector is running? If detector is running and
force
is false, we should fail immediately.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack.