Merge pull request #3 from madhanrm/dr

Add Recovery Agent
This commit is contained in:
Madhan Raj Mookkandy 2020-09-10 14:21:10 -07:00 коммит произвёл GitHub
Родитель 8765dd1222 bdd08d32d5
Коммит 99f2e43e37
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 95 добавлений и 1 удалений

2
go.mod
Просмотреть файл

@ -6,7 +6,7 @@ require (
github.com/Azure/go-autorest/autorest v0.9.0
github.com/Azure/go-autorest/autorest/date v0.2.0
github.com/golang/protobuf v1.3.3 // indirect
github.com/microsoft/moc v0.10.1-alpha.2
github.com/microsoft/moc v0.10.1-alpha.4
github.com/satori/go.uuid v1.2.0
github.com/spf13/viper v1.6.2
google.golang.org/grpc v1.27.1

3
go.sum
Просмотреть файл

@ -70,6 +70,7 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
@ -88,6 +89,8 @@ github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/microsoft/moc v0.10.1-alpha.2 h1:LQaxvX00vcNafq0TIXibOLHByybo3T+Olo8g9DAAlxg=
github.com/microsoft/moc v0.10.1-alpha.2/go.mod h1:FXDFQa7/tOXZBMSWpVnzVahSpCDVgdSkEdz9rOmT3G0=
github.com/microsoft/moc v0.10.1-alpha.4 h1:5P6UR+2kq+X9dsjVA2OBDPLNBg0YOgGsqqURIej774E=
github.com/microsoft/moc v0.10.1-alpha.4/go.mod h1:oK8iLrb4IOdvmokCAgbMWzPj2m7PcARZnCa3g3tNrFI=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=

Просмотреть файл

@ -8,6 +8,7 @@ import (
"github.com/microsoft/moc/pkg/auth"
admin_pb "github.com/microsoft/moc/rpc/cloudagent/admin"
cadmin_pb "github.com/microsoft/moc/rpc/common/admin"
)
// GetLogClient returns the log client to communicate with the wssdcloud agent
@ -19,3 +20,13 @@ func GetLogClient(serverAddress *string, authorizer auth.Authorizer) (admin_pb.L
return admin_pb.NewLogAgentClient(conn), nil
}
// GetRecoveryClient returns the log client to communicate with the wssdcloud agent
func GetRecoveryClient(serverAddress *string, authorizer auth.Authorizer) (cadmin_pb.RecoveryAgentClient, error) {
conn, err := getClientConnection(serverAddress, authorizer)
if err != nil {
log.Fatalf("Unable to get RecoveryClient. Failed to dial: %v", err)
}
return cadmin_pb.NewRecoveryAgentClient(conn), nil
}

Просмотреть файл

@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license
package recovery
import (
"context"
"github.com/microsoft/moc-sdk-for-go/services/admin/recovery/internal"
"github.com/microsoft/moc/pkg/auth"
)
// Service interfacetype Service interface {
type Service interface {
Backup(context.Context, string) error
Restore(context.Context, string) error
}
// Client structure
type RecoveryClient struct {
internal Service
}
// NewClient method returns new client
func NewRecoveryClient(cloudFQDN string, authorizer auth.Authorizer) (*RecoveryClient, error) {
c, err := internal.NewRecoveryClient(cloudFQDN, authorizer)
return &RecoveryClient{c}, err
}
// Backupo
func (c *RecoveryClient) Backup(ctx context.Context, path string) error {
return c.internal.Backup(ctx, path)
}
// Restore
func (c *RecoveryClient) Restore(ctx context.Context, path string) error {
return c.internal.Restore(ctx, path)
}

Просмотреть файл

@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license
package internal
import (
"context"
mocclient "github.com/microsoft/moc-sdk-for-go/pkg/client"
"github.com/microsoft/moc/pkg/auth"
mocadmin "github.com/microsoft/moc/rpc/common/admin"
)
type client struct {
mocadmin.RecoveryAgentClient
}
// NewRecoveryClient - creates a client session with the backend moc agent
func NewRecoveryClient(subID string, authorizer auth.Authorizer) (*client, error) {
c, err := mocclient.GetRecoveryClient(&subID, authorizer)
if err != nil {
return nil, err
}
return &client{c}, nil
}
// Backup
func (c *client) Backup(ctx context.Context, path string) error {
request := getRecoveryRequest(mocadmin.Operation_BACKUP, path)
_, err := c.RecoveryAgentClient.Invoke(ctx, request)
return err
}
// Restore
func (c *client) Restore(ctx context.Context, path string) error {
request := getRecoveryRequest(mocadmin.Operation_RESTORE, path)
_, err := c.RecoveryAgentClient.Invoke(ctx, request)
return err
}
func getRecoveryRequest(operation mocadmin.Operation, path string) *mocadmin.RecoveryRequest {
return &mocadmin.RecoveryRequest{OperationType: operation, Path: path}
}