Skip to content

Commit

Permalink
feat: add cloud field to refresh request (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalo-rodrigues authored Aug 8, 2022
1 parent 3e55ab1 commit a28e8d1
Show file tree
Hide file tree
Showing 6 changed files with 803 additions and 737 deletions.
5 changes: 0 additions & 5 deletions api/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,6 @@ func (d DeploymentExecutor) RefreshState(ctx context.Context, configPrefix strin
}

func (d DeploymentExecutor) refresh(ctx context.Context, configPrefix string) error {
start := time.Now()
defer func() {
log.Printf("[DEBUG] refresh finished in %s", time.Since(start))
}()

tmpDir := GetTempDirForUser(configPrefix)
return d.TfCmd.Refresh(ctx, tmpDir)
}
Expand Down
1,493 changes: 780 additions & 713 deletions api/proto/multy_service.pb.go

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion api/proto/multy_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,15 @@ service MultyResourceService {
rpc UpdateVirtualMachine (resources.UpdateVirtualMachineRequest) returns (resources.VirtualMachineResource) {}
rpc DeleteVirtualMachine (resources.DeleteVirtualMachineRequest) returns (common.Empty) {}

rpc RefreshState(common.Empty) returns (common.Empty) {}
rpc RefreshState(RefreshStateRequest) returns (common.Empty) {}
rpc ListResources(common.Empty) returns (common.ListResourcesResponse) {}
rpc DeleteResource(DeleteResourceRequest) returns (common.Empty) {}
}

message RefreshStateRequest {
common.CloudProvider cloud = 1;
}

message DeleteResourceRequest {
string resource_id = 1;
}
Expand Down
12 changes: 6 additions & 6 deletions api/proto/multy_service_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,16 @@ func (s *Server) DeleteVirtualMachine(ctx context.Context, in *resourcespb.Delet
return s.VirtualMachineService.Delete(ctx, in)
}

func (s *Server) RefreshState(ctx context.Context, _ *commonpb.Empty) (_ *commonpb.Empty, err error) {
func (s *Server) RefreshState(ctx context.Context, in *proto.RefreshStateRequest) (_ *commonpb.Empty, err error) {
defer func() {
if err != nil {
go s.AwsClient.UpdateErrorMetric("refresh", "refresh", errors.ErrorCode(err))
}
}()
return errors.WrappingErrors(s.refresh)(ctx, &commonpb.Empty{})
return errors.WrappingErrors(s.refresh)(ctx, in)
}

func (s *Server) refresh(ctx context.Context, _ *commonpb.Empty) (*commonpb.Empty, error) {
func (s *Server) refresh(ctx context.Context, in *proto.RefreshStateRequest) (*commonpb.Empty, error) {
log.Println("[INFO] Refreshing state")
key, err := util.ExtractApiKey(ctx)
if err != nil {
Expand All @@ -372,15 +372,15 @@ func (s *Server) refresh(ctx context.Context, _ *commonpb.Empty) (*commonpb.Empt
if err != nil {
return nil, err
}
configPrefix := services.GetConfigPrefixForCloud(userId, in.GetCloud())

lock, err := s.Database.LockConfig(ctx, userId, userId)
lock, err := s.Database.LockConfig(ctx, userId, configPrefix)
if err != nil {
return nil, err
}
defer s.Database.UnlockConfig(ctx, lock)

// TODO: ask for cloud in request
c, err := s.Database.LoadUserConfig(ctx, userId, userId, lock)
c, err := s.Database.LoadUserConfig(ctx, userId, configPrefix, lock)
if err != nil {
return nil, err
}
Expand All @@ -389,12 +389,12 @@ func (s *Server) refresh(ctx context.Context, _ *commonpb.Empty) (*commonpb.Empt
return nil, err
}

err = s.ResourceServiceContext.DeploymentExecutor.RefreshState(ctx, userId, mconfig)
err = s.ResourceServiceContext.DeploymentExecutor.RefreshState(ctx, configPrefix, mconfig)
if err != nil {
return nil, err
}

err = s.Database.StoreUserConfig(ctx, c, userId, lock)
err = s.Database.StoreUserConfig(ctx, c, configPrefix, lock)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions api/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (s Service[Arg, OutT]) create(ctx context.Context, in CreateRequest[Arg]) (
}
defer s.ServiceContext.UnlockConfig(ctx, lock)

c, err := s.getConfig(ctx, configPrefix, lock, configPrefix)
c, err := s.getConfig(ctx, userId, lock, configPrefix)
if err != nil {
return
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func (s Service[Arg, OutT]) read(ctx context.Context, in WithResourceId) (OutT,
}
defer s.ServiceContext.UnlockConfig(ctx, lock)

c, err := s.getConfig(ctx, configPrefix, lock, configPrefix)
c, err := s.getConfig(ctx, userId, lock, configPrefix)
if err != nil {
return *new(OutT), err
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func (s Service[Arg, OutT]) update(ctx context.Context, in UpdateRequest[Arg]) (
}
defer s.ServiceContext.UnlockConfig(ctx, lock)

c, err := s.getConfig(ctx, configPrefix, lock, configPrefix)
c, err := s.getConfig(ctx, userId, lock, configPrefix)
if err != nil {
return
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (s Service[Arg, OutT]) delete(ctx context.Context, in WithResourceId) (out
return
}
defer s.ServiceContext.UnlockConfig(ctx, lock)
c, err := s.getConfig(ctx, configPrefix, lock, configPrefix)
c, err := s.getConfig(ctx, userId, lock, configPrefix)
if err != nil {
return
}
Expand Down

0 comments on commit a28e8d1

Please sign in to comment.