This repository has been archived by the owner on Aug 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '15-as-a-user-i-want-to-be-able-to-stop-packs-entire-job…
…s' into 'master' Resolve "As a User I want to be able to stop Packs (entire jobs)" Closes #15 See merge request Qm64/backpack!13
- Loading branch information
Showing
12 changed files
with
154 additions
and
24 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
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,100 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"text/tabwriter" | ||
|
||
"github.com/spf13/cobra" | ||
"gitlab.com/qm64/backpack/conn" | ||
"gitlab.com/qm64/backpack/pkg" | ||
"gitlab.com/qm64/backpack/templating" | ||
) | ||
|
||
// stopCmd represents the run command | ||
var stopCmd = &cobra.Command{ | ||
Use: "stop [path]", | ||
Aliases: []string{"uninstall", "delete"}, | ||
Args: cobra.ExactArgs(1), | ||
Short: "Stop all the jobs in a pack", | ||
Long: ` | ||
`, | ||
Run: stopRun, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(stopCmd) | ||
stopCmd.Flags().BoolP("purge", "p", false, "Delete the jobs, without waiting for the GC to fully delete them") | ||
stopCmd.Flags().BoolP("unpacked", "u", false, "instead of reading from a file, read from a directory") | ||
} | ||
|
||
// This is the actual command.. | ||
func stopRun(cmd *cobra.Command, args []string) { | ||
b := getPackFromCLIInput(cmd, args) | ||
var err error | ||
|
||
client, err := conn.NewClient() | ||
if err != nil { | ||
log.Fatalf("Error creating new Nomad Client: %s", err) | ||
} | ||
|
||
purgeJob, err := cmd.Flags().GetBool("purge") | ||
if err != nil { | ||
log.Fatalf("Error parsing CLI flags (purge): %s", err) | ||
} | ||
|
||
// Populate the template into job files 💪 | ||
bts, err := templating.BuildHCL(&b, pkg.ValuesType{}) | ||
if err != nil { | ||
log.Fatalf("Error building the HCL files: %s", err) | ||
} | ||
|
||
// Prepare a table for the output in a buffer. This is done so that we can | ||
// have a table after outputting the Plans for each job | ||
rt, wt, err := os.Pipe() | ||
if err != nil { | ||
log.Fatal("Error preparing the output table:", err) | ||
} | ||
|
||
defer rt.Close() | ||
w := tabwriter.NewWriter(wt, 3, 0, 4, ' ', 0) | ||
fmt.Fprintf(w, "Recap of stopping jobs in \"%s\" backpack:\n", b.Name) | ||
fmt.Fprintln(w, "File Name\tJob ID\tStatus\tError if any") | ||
// For each job file go and stop 🚀 | ||
for name, hcl := range bts { | ||
job, err := client.GetJobFromCode(string(hcl)) | ||
if err != nil { | ||
log.Fatalf("Error obtaining job %s: %s", name, err) | ||
} | ||
|
||
// Stop the job | ||
_, err = client.Stop(*job.ID, purgeJob) | ||
if err != nil { | ||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t\n", name, *job.ID, *job.Status, err) | ||
continue | ||
} | ||
|
||
if !purgeJob { | ||
jobAfter, err := client.GetJobStatus(*job.ID) | ||
if err != nil { | ||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t\n", name, *job.ID, *job.Status, err) | ||
continue | ||
} | ||
|
||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t\n", name, *jobAfter.ID, *jobAfter.Status, "") | ||
} else { | ||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t\n", name, *job.ID, "purged", "") | ||
} | ||
|
||
} | ||
// Flushes all the table output after all the plans output. | ||
w.Flush() | ||
wt.Close() | ||
output, err := ioutil.ReadAll(rt) | ||
if err != nil { | ||
log.Fatal("Error reading the output table after operation completed:", err) | ||
} | ||
os.Stdout.Write(output) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package conn | ||
|
||
// Stop stops a specific Job | ||
func (co *Client) Stop(jobID string, purge bool) (evalID string, err error) { | ||
evalID, _, err = co.jobs.Deregister(jobID, purge, nil) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return evalID, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
# How to deploy FabioLB | ||
|
||
This backpack allows to deploy [FabioLB](http://fabiolb.net/). | ||
Please check the values inline documentation for more information | ||
This pack allows to deploy [FabioLB](http://fabiolb.net/). | ||
Please check the values inline documentation for more information. If you | ||
have unpacked the documentation only, unpack the whole package to check | ||
the YAML and HCL files! 😉 | ||
|
||
If you see something missing, feel free to open an Issue or to submit a | ||
pull request / merge request on [our repository](http://gitlab.com/Qm64/backpack) | ||
pull request / merge request on [our repository](http://gitlab.com/Qm64/backpack) | ||
or [join Qm64's chatroom on Matrix](https://matrix.to/#/#qm64:matrix.org?via=matrix.org) |
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# How to deploy Redis | ||
|
||
This backpack allows to deploy [Redis](http://redis.io/). | ||
This pack allows to deploy [Redis](http://redis.io/). | ||
Please check the values inline documentation for more information | ||
|
||
The version of this backpack is following the major version of Redis | ||
The version of this pack is following the major version of Redis | ||
|
||
If you see something missing, feel free to open an Issue or to submit a | ||
pull request / merge request on [our repository](http://gitlab.com/Qm64/backpack) | ||
pull request / merge request on [our repository](http://gitlab.com/Qm64/backpack) | ||
or [join Qm64's chatroom on Matrix](https://matrix.to/#/#qm64:matrix.org?via=matrix.org) |