This repository has been archived by the owner on Mar 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathactions.go
139 lines (119 loc) · 3.28 KB
/
actions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package main
import (
"fmt"
"github.com/RSE-Cambridge/data-acc/internal/pkg/dacctl"
"github.com/RSE-Cambridge/data-acc/internal/pkg/dacctl/actions_impl"
"github.com/RSE-Cambridge/data-acc/internal/pkg/fileio"
"github.com/RSE-Cambridge/data-acc/internal/pkg/store"
"github.com/RSE-Cambridge/data-acc/internal/pkg/store_impl"
"github.com/urfave/cli"
)
var testKeystore store.Keystore
var testDisk fileio.Disk
var testActions dacctl.DacctlActions
func getKeystore() store.Keystore {
// TODO must be a better way to test this, proper factory?
if testKeystore != nil {
return testKeystore
}
return store_impl.NewKeystore()
}
func getActions(keystore store.Keystore) dacctl.DacctlActions {
if testActions != nil {
return testActions
}
disk := fileio.NewDisk()
return actions_impl.NewDacctlActions(keystore, disk)
}
func createPersistent(c *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
err := getActions(keystore).CreatePersistentBuffer(c)
if err == nil {
// Slurm is looking for the string "created" to know this worked
fmt.Printf("created %s\n", c.String("token"))
}
return err
}
func printOutput(function func() (string, error)) error {
sessions, err := function()
if err != nil {
return err
}
fmt.Println(sessions)
return nil
}
func showInstances(_ *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return printOutput(getActions(keystore).ShowInstances)
}
func showSessions(_ *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return printOutput(getActions(keystore).ShowSessions)
}
func listPools(_ *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return printOutput(getActions(keystore).ListPools)
}
func showConfigurations(_ *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return printOutput(getActions(keystore).ShowConfigurations)
}
func teardown(c *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return getActions(keystore).DeleteBuffer(c)
}
func jobProcess(c *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return getActions(keystore).ValidateJob(c)
}
func setup(c *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return getActions(keystore).CreatePerJobBuffer(c)
}
func realSize(c *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return printOutput(func() (s string, e error) {
return getActions(keystore).RealSize(c)
})
}
func dataIn(c *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return getActions(keystore).DataIn(c)
}
func paths(c *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return getActions(keystore).Paths(c)
}
func preRun(c *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return getActions(keystore).PreRun(c)
}
func postRun(c *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return getActions(keystore).PostRun(c)
}
func dataOut(c *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return getActions(keystore).DataOut(c)
}
func generateAnsible(c *cli.Context) error {
keystore := getKeystore()
defer keystore.Close()
return printOutput(func() (s string, e error) {
return getActions(keystore).GenerateAnsible(c)
})
}