github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/verrazzano-backup-hook/opensearch/interface.go (about) 1 // Copyright (c) 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package opensearch 5 6 import ( 7 "context" 8 "github.com/verrazzano/verrazzano-monitoring-operator/verrazzano-backup-hook/types" 9 "go.uber.org/zap" 10 "io" 11 "net/http" 12 ) 13 14 // Opensearch Interface implements methods needed for backup and restore of Opensearch 15 // These methods are used with the hook to save and restore Opensearch data 16 type Opensearch interface { 17 // HTTPHelper Http wrapper to make REST based method calls 18 HTTPHelper(ctx context.Context, method, requestURL string, body io.Reader, data interface{}) error 19 20 // EnsureOpenSearchIsReachable Keep alive check with retry 21 EnsureOpenSearchIsReachable() error 22 23 // EnsureOpenSearchIsHealthy Health status check with retry 24 EnsureOpenSearchIsHealthy() error 25 26 // ReloadOpensearchSecureSettings updates Opensearch keystore with credentials 27 ReloadOpensearchSecureSettings() error 28 29 // RegisterSnapshotRepository creates a new S3 based repository 30 RegisterSnapshotRepository() error 31 32 // TriggerSnapshot starts the snapshot(backup) of the Opensearch data streams 33 TriggerSnapshot() error 34 35 // CheckSnapshotProgress checks the status of the backup process 36 CheckSnapshotProgress() error 37 38 // DeleteData deletes all data streams and indices 39 DeleteData() error 40 41 // TriggerRestore starts the snapshot restore of the Opensearch data streams 42 TriggerRestore() error 43 44 // CheckRestoreProgress checks the progress of the restore progress 45 CheckRestoreProgress() error 46 47 // Backup Toplevel method to start the backup operation 48 Backup() error 49 50 // Restore Toplevel method to start the restore operation 51 Restore() error 52 } 53 54 // OpensearchImpl struct for Opensearch interface 55 type OpensearchImpl struct { 56 Client *http.Client 57 Timeout string //Timeout for HTTP calls 58 BaseURL string 59 SecretData *types.ConnectionData 60 Log *zap.SugaredLogger 61 } 62 63 // New Opensearch Impl constructor 64 func New(baseURL string, timeout string, client *http.Client, secretData *types.ConnectionData, log *zap.SugaredLogger) *OpensearchImpl { 65 return &OpensearchImpl{ 66 Client: client, 67 Timeout: timeout, 68 BaseURL: baseURL, 69 SecretData: secretData, 70 Log: log, 71 } 72 }