It translates snapshot keys into metadata structure
This commit is contained in:
parent
1a107e2a28
commit
dae67e6be6
@ -249,6 +249,20 @@ func (s *SnapshotProcessor) ListAppsSnapshotsByLabel(desiredLabel string) ([]Sna
|
||||
return snapshots, nil
|
||||
}
|
||||
|
||||
// GetSnapshot returns a single snapshot's metadata for given key.
|
||||
// In fact this is just key translation method. It parses the key and returns
|
||||
// what's inside. Doesn't check if the snapshot actually exist.
|
||||
func (s *SnapshotProcessor) GetSnapshot(key string) (Snapshot, error) {
|
||||
snapshot := Snapshot{}
|
||||
|
||||
snapshot, err := DecodeKeyName(key)
|
||||
if err != nil {
|
||||
return snapshot, err
|
||||
}
|
||||
|
||||
return snapshot, nil
|
||||
}
|
||||
|
||||
// DeleteSnapshot delete's one snapshot
|
||||
func (s *SnapshotProcessor) DeleteSnapshot(key string) error {
|
||||
err := s.Driver.Delete(key)
|
||||
|
@ -154,6 +154,12 @@ func TestCreateRestoreListSnapshot(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestGetSnapshot(t *testing.T) {
|
||||
snapshot, err := snapshotProcessor.GetSnapshot("app_0102:1634510035:eyJhcHBfbmFtZSI6ImFwcF8wMTAyIiwidHMiOjE2MzQ1MTAwMzUsImxhYmVscyI6WyJ1c2VyaWQ6MSJdfQ==")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "app_0102", snapshot.AppName)
|
||||
}
|
||||
|
||||
func TestListAppsSnapshotsByLabel(t *testing.T) {
|
||||
appName := "app_0102"
|
||||
|
||||
|
@ -64,6 +64,7 @@ func _messageHandler(m *nats.Msg) error {
|
||||
"list_snapshots": listSnapshotsEventHandler,
|
||||
"list_apps_snapshots": listAppsSnapshotsEventHandler,
|
||||
"list_snapshots_by_label": listSnapshotsByLabelEventHandler,
|
||||
"get_snapshot": getSnapshotEventHandler,
|
||||
"delete_snapshot": deleteSnapshotEventHandler,
|
||||
"delete_app_snapshots": deleteAppSnapshotsEventHandler,
|
||||
}
|
||||
@ -1049,6 +1050,48 @@ func listSnapshotsByLabelEventHandler(m *nats.Msg, message *RequestMessage) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
getSnapshotEventHandler returns a single snapshot for given key from the request payload.
|
||||
|
||||
Payload: snapshot's key
|
||||
Response: snapshot metadata
|
||||
*/
|
||||
func getSnapshotEventHandler(m *nats.Msg, message *RequestMessage) error {
|
||||
processor := apps.SnapshotProcessor{
|
||||
AppsPath: config.AppsPath,
|
||||
TmpSnapshotPath: config.SnapshotsPath,
|
||||
|
||||
Driver: drivers.S3Driver{
|
||||
S3AccessKey: config.SnapshotsS3AccessKey,
|
||||
S3SecretKey: config.SnapshotsS3SecretKey,
|
||||
S3Endpoint: config.SnapshotsS3Endpoint,
|
||||
S3SSL: config.SnapshotsS3SSL,
|
||||
Bucket: config.SnapshotsS3Bucket,
|
||||
},
|
||||
}
|
||||
|
||||
snapshot, err := processor.GetSnapshot(message.Payload)
|
||||
if err != nil {
|
||||
return errorReplyFormater(m, "backend error", err)
|
||||
}
|
||||
output := SnapshotMetadata{
|
||||
Key: snapshot.KeyName(),
|
||||
Metadata: snapshot,
|
||||
}
|
||||
|
||||
data, err := json.Marshal(output)
|
||||
if err != nil {
|
||||
return errorReplyFormater(m, "reply formatter error", err)
|
||||
}
|
||||
|
||||
err = m.Respond(data)
|
||||
if err != nil {
|
||||
log.Println("ERROR: get snapshot:", err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
deleteSnapshotEventHandler delete a single snapshot. This is not bound to application name.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user