This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
/
eprojects.go
89 lines (78 loc) · 2.68 KB
/
eprojects.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
package models
import (
"fmt"
"net"
"strings"
"time"
"go.dedis.ch/onet/v3/log"
"golang.org/x/xerrors"
)
// EProjectList holds all the projects
var EProjectList = make(map[string]*EProject)
const (
// EProjectStatusBootingEnclave is set when the enclave is booting
EProjectStatusBootingEnclave = "bootingEnclave"
// EProjectStatusSetupReady is set when the enclave is ready
EProjectStatusSetupReady = "setupReady"
// EProjectStatusSetupErrored is set when the enclave set up failed
EProjectStatusSetupErrored = "setupErrored"
// EProjectStatusUnlockingEnclave is set when trying to unlock the enclave
EProjectStatusUnlockingEnclave = "unlockingEnclave"
// EProjectStatusUnlockingEnclaveDone is set when the enclave is unlocked
EProjectStatusUnlockingEnclaveDone = "unlockingEnclaveDone"
// EProjectStatusUnlockingEnclaveErrored is set when unlocking the enclave
// failed
EProjectStatusUnlockingEnclaveErrored = "unlockingEnclaveErrored"
)
// EProjectStatus describes the status of a eproject
type EProjectStatus string
// EProject holds a project which is tied to a project instance ID and an
// enclave. "E" stands for "Enclave".
type EProject struct {
// This ProjectUID is intended to be the same as the ProjectID in the
// datascientist manager.
ProjectUID string
InstanceID string
EnclaveHref string
EnclaveName string
Status EProjectStatus
IPAddr net.IP
PubKey string
CloudEndpoint string
ReadInstIDs []string
WriteInstIDs []string
}
// ParseKey extract the public key, which is stored in the <type>:<key> format
func (e EProject) ParseKey() (string, error) {
keySlice := strings.Split(e.PubKey, ":")
if len(keySlice) != 2 {
return "", fmt.Errorf("failed to split the key '%s', "+
"got a lenght of %d", e.PubKey, len(keySlice))
}
return keySlice[1], nil
}
// UpdateProjectcStatus updates the status of the project instance. This should
// be put in the helpers package but since it is using Config, it would create a
// dependence cycle.
func UpdateProjectcStatus(conf *Config, status string, instanceID string) error {
args := []string{"./pcadmin", "-c", conf.ConfigPath, "contract",
"project", "invoke", "updateStatus", "-bc", conf.BCPath, "-sign",
conf.KeyID, "-status", status, "-i", instanceID}
_, err := conf.Executor.Run(args...)
retry := 4
for retry > 0 {
_, err = conf.Executor.Run(args...)
if err == nil {
break
}
retry--
log.Warnf("failed to update the projectc status, %d try left, "+
"sleeping for 7s...: %s", retry, err)
time.Sleep(7 * time.Second)
}
if err != nil {
return xerrors.Errorf("failed to update the project instance status "+
"after 4 tries, failed to run the command: %v", err)
}
return nil
}