/
backend.go
87 lines (64 loc) · 2.64 KB
/
backend.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
package backends
import (
"fmt"
"github.com/TimeIncOSS/ape-dev-rt/deploymentstate/schema"
)
type BackendFactory struct {
Name string
Backend Backend
Meta interface{}
}
func (b *BackendFactory) Initialize(config map[string]interface{}) error {
meta, err := b.Backend.Configure(config)
if err != nil {
return fmt.Errorf("Unable to initalize backend with config: %q: %s",
config, err)
}
b.Meta = meta
return nil
}
type SlotNotFound struct {
SlotName string
OriginalErr error
}
func (s *SlotNotFound) Error() string {
return fmt.Sprintf("Slot %q was not found.", s.SlotName)
}
type AppNotFound struct {
AppName string
OriginalErr error
}
func (s *AppNotFound) Error() string {
return fmt.Sprintf("Application %q was not found.", s.AppName)
}
type Backend interface {
Configure(config map[string]interface{}) (interface{}, error)
SupportsWriteLock() bool
// IsReady can perform any kind of preliminar
// check (e.g. is TCP port open, are credentials valid,
// are permissions sufficient) to verify the backend
// is ready to persist our data
IsReady(meta interface{}) (bool, error)
// ListApplications returns all existing applications
// (no matter if they have any slots/deployments or not)
ListApplications(meta interface{}) ([]*schema.ApplicationData, error)
// GetApplication returns application metadata for a given app name
GetApplication(meta interface{}, name string) (*schema.ApplicationData, error)
// SaveApplication saves any given application data
SaveApplication(meta interface{}, name string, data *schema.ApplicationData) error
// ListSlots returns all existing slots (active+inactive)
ListSlots(meta interface{}, appName string) ([]*schema.SlotData, error)
// DeleteSlot deletes all slot data available in the backend
DeleteSlot(meta interface{}, appName, slotId string) error
// SaveSlot saves any given slot data into backend
SaveSlot(meta interface{}, appName, slotId string, slot *schema.SlotData) error
// GetSlot returns any existing data for a given slotId
GetSlot(meta interface{}, appName, slotId string) (*schema.SlotData, error)
// ListSortedDeploymentsForSlotId returns n last deployments
ListSortedDeploymentsForSlotId(meta interface{}, appName, slotId string, limitPerSlot int) ([]*schema.DeploymentData, error)
// SaveDeployment saves any given deployment data into backend
SaveDeployment(meta interface{}, appName, slotId, deploymentId string, data *schema.DeploymentData) error
// GetDeployment returns deployment data
// for a given slotId & deploymentId saved previously in the backend
GetDeployment(meta interface{}, appName, slotId, deploymentId string) (*schema.DeploymentData, error)
}