From 1f95a44857b00e59cccb626f11e79f50ccb417ca Mon Sep 17 00:00:00 2001 From: Sonali Wale <86949270+sonali523@users.noreply.github.com> Date: Mon, 31 Jan 2022 12:43:26 +0530 Subject: [PATCH] API to fetch the status of the migration (#6637) * Get migrations status API added Signed-off-by: sonali wale * Added minor changes Signed-off-by: sonali wale --- .studio/common | 4 + .../infra_proxy/migrations/migrations.pb.go | 144 +++++++++++++- .../migrations/migrations.pb.gw.go | 184 ++++++++++++++++++ .../migrations/migrations.pb.policy.go | 25 +++ .../infra_proxy/migrations/migrations.proto | 15 ++ .../migrations/migrations.swagger.json | 98 ++++++++++ .../migrations/request/migrations.pb.go | 81 +++++++- .../migrations/request/migrations.proto | 4 + .../migrations/response/migrations.pb.go | 104 +++++++++- .../migrations/response/migrations.proto | 9 + .../migrations/request/migrations.pb.go | 81 +++++++- .../migrations/request/migrations.proto | 5 + .../migrations/response/migrations.pb.go | 104 +++++++++- .../migrations/response/migrations.proto | 9 + .../migrations/service/migrations.pb.go | 78 ++++++-- .../migrations/service/migrations.proto | 2 + .../infra_proxy/response/servers.pb.go | 2 +- .../api/migrations.pb.swagger.go | 103 ++++++++++ .../automate-gateway/gateway/clients.go | 2 + .../automate-gateway/gateway/services.go | 14 +- .../handler/infra_proxy/infra_proxy.go | 9 +- .../migrations/infra_proxy_migrations.go | 15 ++ .../infra_proxy/migrations/migrations.go | 25 +++ .../infra-proxy-service/server/migration.go | 38 ---- .../infra-proxy-service/server/migrations.go | 131 ++----------- .../server/migrations/migrations.go | 161 +++++++++++++++ .../server/migrations/migrations_test.go | 45 +++++ .../server/migrations/server.go | 16 ++ components/infra-proxy-service/server/orgs.go | 9 - .../infra-proxy-service/server/server.go | 12 +- .../infra-proxy-service/server/servers.go | 4 +- .../storage/postgres/migrations.go | 30 ++- .../infra-proxy-service/storage/storage.go | 17 +- 33 files changed, 1334 insertions(+), 246 deletions(-) create mode 100644 api/external/infra_proxy/migrations/migrations.pb.gw.go create mode 100644 api/external/infra_proxy/migrations/migrations.pb.policy.go create mode 100644 api/external/infra_proxy/migrations/migrations.swagger.json create mode 100644 components/automate-gateway/api/migrations.pb.swagger.go create mode 100644 components/automate-gateway/handler/infra_proxy/migrations/infra_proxy_migrations.go delete mode 100644 components/infra-proxy-service/server/migration.go create mode 100644 components/infra-proxy-service/server/migrations/migrations_test.go create mode 100644 components/infra-proxy-service/server/migrations/server.go diff --git a/.studio/common b/.studio/common index 7db2e8f8d3c..72ea5955009 100644 --- a/.studio/common +++ b/.studio/common @@ -58,6 +58,10 @@ function compile_client_mocks() { pushd /src/api/external || return 1 mockgen_debug -source infra_proxy/infra_proxy.pb.go -destination infra_proxy/infra_proxy.pb.client_mock.go -package infra_proxy -self_package github.com/chef/automate/api/external/infra_proxy popd || return 1 + + pushd /src/api/external || return 1 + mockgen_debug -source infra_proxy/migrations/migrations.pb.go -destination infra_proxy/migrations/migrations.pb.client_mock.go -package migrations -self_package github.com/chef/automate/api/external/infra_proxy/migrations + popd || return 1 ) } diff --git a/api/external/infra_proxy/migrations/migrations.pb.go b/api/external/infra_proxy/migrations/migrations.pb.go index c66891bb32e..4b8df6e4e8c 100644 --- a/api/external/infra_proxy/migrations/migrations.pb.go +++ b/api/external/infra_proxy/migrations/migrations.pb.go @@ -7,7 +7,15 @@ package migrations import ( + context "context" + _ "github.com/chef/automate/api/external/annotations/iam" + request "github.com/chef/automate/api/external/infra_proxy/migrations/request" + response "github.com/chef/automate/api/external/infra_proxy/migrations/response" proto "github.com/golang/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -32,18 +40,54 @@ var file_external_infra_proxy_migrations_migrations_proto_rawDesc = []byte{ 0x73, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x28, 0x63, 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, - 0x79, 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42, 0x3e, 0x5a, 0x3c, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, 0x66, 0x2f, - 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x65, 0x78, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, - 0x79, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x79, 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0x1c, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2a, 0x65, 0x78, 0x74, 0x65, + 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2f, 0x69, 0x61, 0x6d, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x38, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6d, 0x69, 0x67, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2f, + 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x39, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, + 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0xad, 0x02, 0x0a, 0x13, + 0x49, 0x6e, 0x66, 0x72, 0x61, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x12, 0x95, 0x02, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x4d, 0x69, 0x67, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x44, 0x2e, 0x63, 0x68, 0x65, + 0x66, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x69, + 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x47, 0x65, + 0x74, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x1a, 0x45, 0x2e, 0x63, 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, + 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, + 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x72, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x72, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x38, 0x12, + 0x36, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x30, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x2f, 0x73, + 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x2f, 0x7b, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x7d, 0x8a, 0xb5, 0x18, 0x14, 0x0a, 0x12, 0x69, 0x6e, 0x66, + 0x72, 0x61, 0x3a, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x8a, + 0xb5, 0x18, 0x18, 0x12, 0x16, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x3a, 0x69, 0x6e, 0x66, 0x72, 0x61, + 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x3a, 0x67, 0x65, 0x74, 0x42, 0x3e, 0x5a, 0x3c, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, 0x66, 0x2f, 0x61, + 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x65, 0x78, 0x74, 0x65, + 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, + 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } -var file_external_infra_proxy_migrations_migrations_proto_goTypes = []interface{}{} +var file_external_infra_proxy_migrations_migrations_proto_goTypes = []interface{}{ + (*request.GetMigrationStatus)(nil), // 0: chef.automate.api.infra_proxy.migrations.request.GetMigrationStatus + (*response.GetMigrationStatus)(nil), // 1: chef.automate.api.infra_proxy.migrations.response.GetMigrationStatus +} var file_external_infra_proxy_migrations_migrations_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type + 0, // 0: chef.automate.api.infra_proxy.migrations.InfraProxyMigration.GetMigrationStatus:input_type -> chef.automate.api.infra_proxy.migrations.request.GetMigrationStatus + 1, // 1: chef.automate.api.infra_proxy.migrations.InfraProxyMigration.GetMigrationStatus:output_type -> chef.automate.api.infra_proxy.migrations.response.GetMigrationStatus + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -62,7 +106,7 @@ func file_external_infra_proxy_migrations_migrations_proto_init() { NumEnums: 0, NumMessages: 0, NumExtensions: 0, - NumServices: 0, + NumServices: 1, }, GoTypes: file_external_infra_proxy_migrations_migrations_proto_goTypes, DependencyIndexes: file_external_infra_proxy_migrations_migrations_proto_depIdxs, @@ -72,3 +116,83 @@ func file_external_infra_proxy_migrations_migrations_proto_init() { file_external_infra_proxy_migrations_migrations_proto_goTypes = nil file_external_infra_proxy_migrations_migrations_proto_depIdxs = nil } + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// InfraProxyMigrationClient is the client API for InfraProxyMigration service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type InfraProxyMigrationClient interface { + GetMigrationStatus(ctx context.Context, in *request.GetMigrationStatus, opts ...grpc.CallOption) (*response.GetMigrationStatus, error) +} + +type infraProxyMigrationClient struct { + cc grpc.ClientConnInterface +} + +func NewInfraProxyMigrationClient(cc grpc.ClientConnInterface) InfraProxyMigrationClient { + return &infraProxyMigrationClient{cc} +} + +func (c *infraProxyMigrationClient) GetMigrationStatus(ctx context.Context, in *request.GetMigrationStatus, opts ...grpc.CallOption) (*response.GetMigrationStatus, error) { + out := new(response.GetMigrationStatus) + err := c.cc.Invoke(ctx, "/chef.automate.api.infra_proxy.migrations.InfraProxyMigration/GetMigrationStatus", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// InfraProxyMigrationServer is the server API for InfraProxyMigration service. +type InfraProxyMigrationServer interface { + GetMigrationStatus(context.Context, *request.GetMigrationStatus) (*response.GetMigrationStatus, error) +} + +// UnimplementedInfraProxyMigrationServer can be embedded to have forward compatible implementations. +type UnimplementedInfraProxyMigrationServer struct { +} + +func (*UnimplementedInfraProxyMigrationServer) GetMigrationStatus(context.Context, *request.GetMigrationStatus) (*response.GetMigrationStatus, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetMigrationStatus not implemented") +} + +func RegisterInfraProxyMigrationServer(s *grpc.Server, srv InfraProxyMigrationServer) { + s.RegisterService(&_InfraProxyMigration_serviceDesc, srv) +} + +func _InfraProxyMigration_GetMigrationStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(request.GetMigrationStatus) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(InfraProxyMigrationServer).GetMigrationStatus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/chef.automate.api.infra_proxy.migrations.InfraProxyMigration/GetMigrationStatus", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(InfraProxyMigrationServer).GetMigrationStatus(ctx, req.(*request.GetMigrationStatus)) + } + return interceptor(ctx, in, info, handler) +} + +var _InfraProxyMigration_serviceDesc = grpc.ServiceDesc{ + ServiceName: "chef.automate.api.infra_proxy.migrations.InfraProxyMigration", + HandlerType: (*InfraProxyMigrationServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetMigrationStatus", + Handler: _InfraProxyMigration_GetMigrationStatus_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "external/infra_proxy/migrations/migrations.proto", +} diff --git a/api/external/infra_proxy/migrations/migrations.pb.gw.go b/api/external/infra_proxy/migrations/migrations.pb.gw.go new file mode 100644 index 00000000000..cef01fcd68c --- /dev/null +++ b/api/external/infra_proxy/migrations/migrations.pb.gw.go @@ -0,0 +1,184 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: external/infra_proxy/migrations/migrations.proto + +/* +Package migrations is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package migrations + +import ( + "context" + "io" + "net/http" + + "github.com/chef/automate/api/external/infra_proxy/migrations/request" + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage + +func request_InfraProxyMigration_GetMigrationStatus_0(ctx context.Context, marshaler runtime.Marshaler, client InfraProxyMigrationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq request.GetMigrationStatus + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["migration_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "migration_id") + } + + protoReq.MigrationId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "migration_id", err) + } + + msg, err := client.GetMigrationStatus(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_InfraProxyMigration_GetMigrationStatus_0(ctx context.Context, marshaler runtime.Marshaler, server InfraProxyMigrationServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq request.GetMigrationStatus + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["migration_id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "migration_id") + } + + protoReq.MigrationId, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "migration_id", err) + } + + msg, err := server.GetMigrationStatus(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterInfraProxyMigrationHandlerServer registers the http handlers for service InfraProxyMigration to "mux". +// UnaryRPC :call InfraProxyMigrationServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +func RegisterInfraProxyMigrationHandlerServer(ctx context.Context, mux *runtime.ServeMux, server InfraProxyMigrationServer) error { + + mux.Handle("GET", pattern_InfraProxyMigration_GetMigrationStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_InfraProxyMigration_GetMigrationStatus_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_InfraProxyMigration_GetMigrationStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterInfraProxyMigrationHandlerFromEndpoint is same as RegisterInfraProxyMigrationHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterInfraProxyMigrationHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterInfraProxyMigrationHandler(ctx, mux, conn) +} + +// RegisterInfraProxyMigrationHandler registers the http handlers for service InfraProxyMigration to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterInfraProxyMigrationHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterInfraProxyMigrationHandlerClient(ctx, mux, NewInfraProxyMigrationClient(conn)) +} + +// RegisterInfraProxyMigrationHandlerClient registers the http handlers for service InfraProxyMigration +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "InfraProxyMigrationClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "InfraProxyMigrationClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "InfraProxyMigrationClient" to call the correct interceptors. +func RegisterInfraProxyMigrationHandlerClient(ctx context.Context, mux *runtime.ServeMux, client InfraProxyMigrationClient) error { + + mux.Handle("GET", pattern_InfraProxyMigration_GetMigrationStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_InfraProxyMigration_GetMigrationStatus_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_InfraProxyMigration_GetMigrationStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_InfraProxyMigration_GetMigrationStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 2, 5, 1, 0, 4, 1, 5, 6}, []string{"api", "v0", "infra", "servers", "migrations", "status", "migration_id"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_InfraProxyMigration_GetMigrationStatus_0 = runtime.ForwardResponseMessage +) diff --git a/api/external/infra_proxy/migrations/migrations.pb.policy.go b/api/external/infra_proxy/migrations/migrations.pb.policy.go new file mode 100644 index 00000000000..2314cad9cea --- /dev/null +++ b/api/external/infra_proxy/migrations/migrations.pb.policy.go @@ -0,0 +1,25 @@ +// Code generated by protoc-gen-policy. DO NOT EDIT. +// source: external/infra_proxy/migrations/migrations.proto + +package migrations + +import ( + policy "github.com/chef/automate/api/external/iam/v2/policy" + request "github.com/chef/automate/api/external/infra_proxy/migrations/request" +) + +func init() { + policy.MapMethodTo("/chef.automate.api.infra_proxy.migrations.InfraProxyMigration/GetMigrationStatus", "infra:infraServers", "infra:infraServers:get", "GET", "/api/v0/infra/servers/migrations/status/{migration_id}", func(unexpandedResource string, input interface{}) string { + if m, ok := input.(*request.GetMigrationStatus); ok { + return policy.ExpandParameterizedResource(unexpandedResource, func(want string) string { + switch want { + case "migration_id": + return m.MigrationId + default: + return "" + } + }) + } + return "" + }) +} diff --git a/api/external/infra_proxy/migrations/migrations.proto b/api/external/infra_proxy/migrations/migrations.proto index 619ced976b5..87d540dfabe 100644 --- a/api/external/infra_proxy/migrations/migrations.proto +++ b/api/external/infra_proxy/migrations/migrations.proto @@ -2,3 +2,18 @@ syntax = "proto3"; package chef.automate.api.infra_proxy.migrations; option go_package = "github.com/chef/automate/api/external/infra_proxy/migrations"; + +import "google/api/annotations.proto"; +import "external/annotations/iam/annotations.proto"; + +import "external/infra_proxy/migrations/request/migrations.proto"; + +import "external/infra_proxy/migrations/response/migrations.proto"; + +service InfraProxyMigration { + rpc GetMigrationStatus (infra_proxy.migrations.request.GetMigrationStatus) returns (infra_proxy.migrations.response.GetMigrationStatus) { + option (google.api.http).get = "/api/v0/infra/servers/migrations/status/{migration_id}"; + option (chef.automate.api.iam.policy).resource = "infra:infraServers"; + option (chef.automate.api.iam.policy).action = "infra:infraServers:get"; + }; +} diff --git a/api/external/infra_proxy/migrations/migrations.swagger.json b/api/external/infra_proxy/migrations/migrations.swagger.json new file mode 100644 index 00000000000..859bbe3be83 --- /dev/null +++ b/api/external/infra_proxy/migrations/migrations.swagger.json @@ -0,0 +1,98 @@ +{ + "swagger": "2.0", + "info": { + "title": "external/infra_proxy/migrations/migrations.proto", + "version": "version not set" + }, + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/api/v0/infra/servers/migrations/status/{migration_id}": { + "get": { + "operationId": "InfraProxyMigration_GetMigrationStatus", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/chef.automate.api.infra_proxy.migrations.response.GetMigrationStatus" + } + }, + "default": { + "description": "An unexpected error response", + "schema": { + "$ref": "#/definitions/grpc.gateway.runtime.Error" + } + } + }, + "parameters": [ + { + "name": "migration_id", + "description": "Migration ID.", + "in": "path", + "required": true, + "type": "string" + } + ], + "tags": [ + "InfraProxyMigration" + ] + } + } + }, + "definitions": { + "chef.automate.api.infra_proxy.migrations.response.GetMigrationStatus": { + "type": "object", + "properties": { + "migration_id": { + "type": "string", + "description": "Migration ID." + }, + "migration_type": { + "type": "string", + "title": "Migration type" + }, + "migration_status": { + "type": "string", + "title": "Migration status" + } + } + }, + "google.protobuf.Any": { + "type": "object", + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "type": "string", + "format": "byte" + } + } + }, + "grpc.gateway.runtime.Error": { + "type": "object", + "properties": { + "error": { + "type": "string" + }, + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/google.protobuf.Any" + } + } + } + } + } +} diff --git a/api/external/infra_proxy/migrations/request/migrations.pb.go b/api/external/infra_proxy/migrations/request/migrations.pb.go index 2ada9f7a503..8e3d1625b61 100644 --- a/api/external/infra_proxy/migrations/request/migrations.pb.go +++ b/api/external/infra_proxy/migrations/request/migrations.pb.go @@ -206,6 +206,54 @@ func (x *Chunk) GetPosition() int64 { return 0 } +type GetMigrationStatus struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Migration ID. + MigrationId string `protobuf:"bytes,1,opt,name=migration_id,json=migrationId,proto3" json:"migration_id,omitempty"` +} + +func (x *GetMigrationStatus) Reset() { + *x = GetMigrationStatus{} + if protoimpl.UnsafeEnabled { + mi := &file_external_infra_proxy_migrations_request_migrations_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetMigrationStatus) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetMigrationStatus) ProtoMessage() {} + +func (x *GetMigrationStatus) ProtoReflect() protoreflect.Message { + mi := &file_external_infra_proxy_migrations_request_migrations_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetMigrationStatus.ProtoReflect.Descriptor instead. +func (*GetMigrationStatus) Descriptor() ([]byte, []int) { + return file_external_infra_proxy_migrations_request_migrations_proto_rawDescGZIP(), []int{3} +} + +func (x *GetMigrationStatus) GetMigrationId() string { + if x != nil { + return x.MigrationId + } + return "" +} + var File_external_infra_proxy_migrations_request_migrations_proto protoreflect.FileDescriptor var file_external_infra_proxy_migrations_request_migrations_proto_rawDesc = []byte{ @@ -236,12 +284,16 @@ var file_external_infra_proxy_migrations_request_migrations_proto_rawDesc = []by 0x70, 0x65, 0x22, 0x37, 0x0a, 0x05, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x03, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x46, 0x5a, 0x44, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, 0x66, 0x2f, 0x61, - 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x65, 0x78, 0x74, 0x65, - 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, - 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x03, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x37, 0x0a, 0x12, 0x47, + 0x65, 0x74, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x49, 0x64, 0x42, 0x46, 0x5a, 0x44, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, 0x66, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x69, 0x6e, + 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -256,11 +308,12 @@ func file_external_infra_proxy_migrations_request_migrations_proto_rawDescGZIP() return file_external_infra_proxy_migrations_request_migrations_proto_rawDescData } -var file_external_infra_proxy_migrations_request_migrations_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_external_infra_proxy_migrations_request_migrations_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_external_infra_proxy_migrations_request_migrations_proto_goTypes = []interface{}{ (*UploadZipFileRequest)(nil), // 0: chef.automate.api.infra_proxy.migrations.request.UploadZipFileRequest (*Metadata)(nil), // 1: chef.automate.api.infra_proxy.migrations.request.Metadata (*Chunk)(nil), // 2: chef.automate.api.infra_proxy.migrations.request.Chunk + (*GetMigrationStatus)(nil), // 3: chef.automate.api.infra_proxy.migrations.request.GetMigrationStatus } var file_external_infra_proxy_migrations_request_migrations_proto_depIdxs = []int32{ 2, // 0: chef.automate.api.infra_proxy.migrations.request.UploadZipFileRequest.chunk:type_name -> chef.automate.api.infra_proxy.migrations.request.Chunk @@ -314,6 +367,18 @@ func file_external_infra_proxy_migrations_request_migrations_proto_init() { return nil } } + file_external_infra_proxy_migrations_request_migrations_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetMigrationStatus); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -321,7 +386,7 @@ func file_external_infra_proxy_migrations_request_migrations_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_external_infra_proxy_migrations_request_migrations_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 4, NumExtensions: 0, NumServices: 0, }, diff --git a/api/external/infra_proxy/migrations/request/migrations.proto b/api/external/infra_proxy/migrations/request/migrations.proto index bc47a0e82e5..c6b033a61f2 100644 --- a/api/external/infra_proxy/migrations/request/migrations.proto +++ b/api/external/infra_proxy/migrations/request/migrations.proto @@ -26,3 +26,7 @@ message Chunk { // Stream pointer int64 position = 2; } +message GetMigrationStatus { + // Migration ID. + string migration_id = 1; +} diff --git a/api/external/infra_proxy/migrations/response/migrations.pb.go b/api/external/infra_proxy/migrations/response/migrations.pb.go index ccf8298643f..ee0ca8ee25e 100644 --- a/api/external/infra_proxy/migrations/response/migrations.pb.go +++ b/api/external/infra_proxy/migrations/response/migrations.pb.go @@ -91,6 +91,72 @@ func (x *UploadZipFileResponse) GetErrors() []string { return nil } +type GetMigrationStatus struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Migration ID. + MigrationId string `protobuf:"bytes,1,opt,name=migration_id,json=migrationId,proto3" json:"migration_id,omitempty"` + // Migration type + MigrationType string `protobuf:"bytes,2,opt,name=migration_type,json=migrationType,proto3" json:"migration_type,omitempty"` + // Migration status + MigrationStatus string `protobuf:"bytes,3,opt,name=migration_status,json=migrationStatus,proto3" json:"migration_status,omitempty"` +} + +func (x *GetMigrationStatus) Reset() { + *x = GetMigrationStatus{} + if protoimpl.UnsafeEnabled { + mi := &file_external_infra_proxy_migrations_response_migrations_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetMigrationStatus) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetMigrationStatus) ProtoMessage() {} + +func (x *GetMigrationStatus) ProtoReflect() protoreflect.Message { + mi := &file_external_infra_proxy_migrations_response_migrations_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetMigrationStatus.ProtoReflect.Descriptor instead. +func (*GetMigrationStatus) Descriptor() ([]byte, []int) { + return file_external_infra_proxy_migrations_response_migrations_proto_rawDescGZIP(), []int{1} +} + +func (x *GetMigrationStatus) GetMigrationId() string { + if x != nil { + return x.MigrationId + } + return "" +} + +func (x *GetMigrationStatus) GetMigrationType() string { + if x != nil { + return x.MigrationType + } + return "" +} + +func (x *GetMigrationStatus) GetMigrationStatus() string { + if x != nil { + return x.MigrationStatus + } + return "" +} + var File_external_infra_proxy_migrations_response_migrations_proto protoreflect.FileDescriptor var file_external_infra_proxy_migrations_response_migrations_proto_rawDesc = []byte{ @@ -107,12 +173,21 @@ var file_external_infra_proxy_migrations_response_migrations_proto_rawDesc = []b 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x18, 0x03, 0x20, - 0x03, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x42, 0x47, 0x5a, 0x45, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, 0x66, 0x2f, 0x61, - 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x65, 0x78, 0x74, 0x65, - 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, - 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x03, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x22, 0x89, 0x01, 0x0a, 0x12, + 0x47, 0x65, 0x74, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x25, 0x0a, 0x0e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6d, + 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x29, 0x0a, 0x10, + 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x47, 0x5a, 0x45, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, 0x66, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x6d, + 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6d, 0x69, 0x67, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -127,9 +202,10 @@ func file_external_infra_proxy_migrations_response_migrations_proto_rawDescGZIP( return file_external_infra_proxy_migrations_response_migrations_proto_rawDescData } -var file_external_infra_proxy_migrations_response_migrations_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_external_infra_proxy_migrations_response_migrations_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_external_infra_proxy_migrations_response_migrations_proto_goTypes = []interface{}{ (*UploadZipFileResponse)(nil), // 0: chef.automate.api.infra_proxy.migrations.response.UploadZipFileResponse + (*GetMigrationStatus)(nil), // 1: chef.automate.api.infra_proxy.migrations.response.GetMigrationStatus } var file_external_infra_proxy_migrations_response_migrations_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type @@ -157,6 +233,18 @@ func file_external_infra_proxy_migrations_response_migrations_proto_init() { return nil } } + file_external_infra_proxy_migrations_response_migrations_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetMigrationStatus); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -164,7 +252,7 @@ func file_external_infra_proxy_migrations_response_migrations_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_external_infra_proxy_migrations_response_migrations_proto_rawDesc, NumEnums: 0, - NumMessages: 1, + NumMessages: 2, NumExtensions: 0, NumServices: 0, }, diff --git a/api/external/infra_proxy/migrations/response/migrations.proto b/api/external/infra_proxy/migrations/response/migrations.proto index 6badc66c175..2b76007d31a 100644 --- a/api/external/infra_proxy/migrations/response/migrations.proto +++ b/api/external/infra_proxy/migrations/response/migrations.proto @@ -12,3 +12,12 @@ message UploadZipFileResponse { // Error data in case of failure. repeated string errors = 3; } + +message GetMigrationStatus { + // Migration ID. + string migration_id = 1; + // Migration type + string migration_type = 2; + // Migration status + string migration_status = 3; +} diff --git a/api/interservice/infra_proxy/migrations/request/migrations.pb.go b/api/interservice/infra_proxy/migrations/request/migrations.pb.go index 125a579a1b4..da5fc87781b 100644 --- a/api/interservice/infra_proxy/migrations/request/migrations.pb.go +++ b/api/interservice/infra_proxy/migrations/request/migrations.pb.go @@ -206,6 +206,54 @@ func (x *Chunk) GetPosition() int64 { return 0 } +type GetMigrationStatus struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Migration ID. + MigrationId string `protobuf:"bytes,1,opt,name=migration_id,json=migrationId,proto3" json:"migration_id,omitempty" toml:"migration_id,omitempty" mapstructure:"migration_id,omitempty"` +} + +func (x *GetMigrationStatus) Reset() { + *x = GetMigrationStatus{} + if protoimpl.UnsafeEnabled { + mi := &file_interservice_infra_proxy_migrations_request_migrations_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetMigrationStatus) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetMigrationStatus) ProtoMessage() {} + +func (x *GetMigrationStatus) ProtoReflect() protoreflect.Message { + mi := &file_interservice_infra_proxy_migrations_request_migrations_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetMigrationStatus.ProtoReflect.Descriptor instead. +func (*GetMigrationStatus) Descriptor() ([]byte, []int) { + return file_interservice_infra_proxy_migrations_request_migrations_proto_rawDescGZIP(), []int{3} +} + +func (x *GetMigrationStatus) GetMigrationId() string { + if x != nil { + return x.MigrationId + } + return "" +} + var File_interservice_infra_proxy_migrations_request_migrations_proto protoreflect.FileDescriptor var file_interservice_infra_proxy_migrations_request_migrations_proto_rawDesc = []byte{ @@ -237,12 +285,16 @@ var file_interservice_infra_proxy_migrations_request_migrations_proto_rawDesc = 0x37, 0x0a, 0x05, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, - 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x4a, 0x5a, 0x48, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, 0x66, 0x2f, 0x61, 0x75, 0x74, 0x6f, - 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x73, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, - 0x79, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x37, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x4d, + 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x21, + 0x0a, 0x0c, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, + 0x64, 0x42, 0x4a, 0x5a, 0x48, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x63, 0x68, 0x65, 0x66, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x69, + 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -257,11 +309,12 @@ func file_interservice_infra_proxy_migrations_request_migrations_proto_rawDescGZ return file_interservice_infra_proxy_migrations_request_migrations_proto_rawDescData } -var file_interservice_infra_proxy_migrations_request_migrations_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_interservice_infra_proxy_migrations_request_migrations_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_interservice_infra_proxy_migrations_request_migrations_proto_goTypes = []interface{}{ (*UploadZipFileRequest)(nil), // 0: chef.automate.domain.infra_proxy.migrations.request.UploadZipFileRequest (*Metadata)(nil), // 1: chef.automate.domain.infra_proxy.migrations.request.Metadata (*Chunk)(nil), // 2: chef.automate.domain.infra_proxy.migrations.request.Chunk + (*GetMigrationStatus)(nil), // 3: chef.automate.domain.infra_proxy.migrations.request.GetMigrationStatus } var file_interservice_infra_proxy_migrations_request_migrations_proto_depIdxs = []int32{ 2, // 0: chef.automate.domain.infra_proxy.migrations.request.UploadZipFileRequest.chunk:type_name -> chef.automate.domain.infra_proxy.migrations.request.Chunk @@ -315,6 +368,18 @@ func file_interservice_infra_proxy_migrations_request_migrations_proto_init() { return nil } } + file_interservice_infra_proxy_migrations_request_migrations_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetMigrationStatus); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -322,7 +387,7 @@ func file_interservice_infra_proxy_migrations_request_migrations_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_interservice_infra_proxy_migrations_request_migrations_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 4, NumExtensions: 0, NumServices: 0, }, diff --git a/api/interservice/infra_proxy/migrations/request/migrations.proto b/api/interservice/infra_proxy/migrations/request/migrations.proto index 800c571b7ed..f8ed4f9cd82 100644 --- a/api/interservice/infra_proxy/migrations/request/migrations.proto +++ b/api/interservice/infra_proxy/migrations/request/migrations.proto @@ -26,3 +26,8 @@ message Chunk { // Stream pointer int64 position = 2; } + +message GetMigrationStatus { + // Migration ID. + string migration_id = 1; +} diff --git a/api/interservice/infra_proxy/migrations/response/migrations.pb.go b/api/interservice/infra_proxy/migrations/response/migrations.pb.go index 887d7d0fef7..d174d716e29 100644 --- a/api/interservice/infra_proxy/migrations/response/migrations.pb.go +++ b/api/interservice/infra_proxy/migrations/response/migrations.pb.go @@ -91,6 +91,72 @@ func (x *UploadZipFileResponse) GetErrors() []string { return nil } +type GetMigrationStatus struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Migration ID. + MigrationId string `protobuf:"bytes,1,opt,name=migration_id,json=migrationId,proto3" json:"migration_id,omitempty" toml:"migration_id,omitempty" mapstructure:"migration_id,omitempty"` + // Migration type + MigrationType string `protobuf:"bytes,2,opt,name=migration_type,json=migrationType,proto3" json:"migration_type,omitempty" toml:"migration_type,omitempty" mapstructure:"migration_type,omitempty"` + // Migration status + MigrationStatus string `protobuf:"bytes,3,opt,name=migration_status,json=migrationStatus,proto3" json:"migration_status,omitempty" toml:"migration_status,omitempty" mapstructure:"migration_status,omitempty"` +} + +func (x *GetMigrationStatus) Reset() { + *x = GetMigrationStatus{} + if protoimpl.UnsafeEnabled { + mi := &file_interservice_infra_proxy_migrations_response_migrations_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetMigrationStatus) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetMigrationStatus) ProtoMessage() {} + +func (x *GetMigrationStatus) ProtoReflect() protoreflect.Message { + mi := &file_interservice_infra_proxy_migrations_response_migrations_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetMigrationStatus.ProtoReflect.Descriptor instead. +func (*GetMigrationStatus) Descriptor() ([]byte, []int) { + return file_interservice_infra_proxy_migrations_response_migrations_proto_rawDescGZIP(), []int{1} +} + +func (x *GetMigrationStatus) GetMigrationId() string { + if x != nil { + return x.MigrationId + } + return "" +} + +func (x *GetMigrationStatus) GetMigrationType() string { + if x != nil { + return x.MigrationType + } + return "" +} + +func (x *GetMigrationStatus) GetMigrationStatus() string { + if x != nil { + return x.MigrationStatus + } + return "" +} + var File_interservice_infra_proxy_migrations_response_migrations_proto protoreflect.FileDescriptor var file_interservice_infra_proxy_migrations_response_migrations_proto_rawDesc = []byte{ @@ -108,12 +174,21 @@ var file_interservice_infra_proxy_migrations_response_migrations_proto_rawDesc = 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x6f, - 0x72, 0x73, 0x42, 0x4b, 0x5a, 0x49, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x63, 0x68, 0x65, 0x66, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, - 0x70, 0x69, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, - 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6d, 0x69, 0x67, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x73, 0x22, 0x89, 0x01, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x69, 0x67, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x25, 0x0a, 0x0e, + 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x6d, + 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x4b, + 0x5a, 0x49, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, + 0x66, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, + 0x6e, 0x74, 0x65, 0x72, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x69, 0x6e, 0x66, 0x72, + 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -128,9 +203,10 @@ func file_interservice_infra_proxy_migrations_response_migrations_proto_rawDescG return file_interservice_infra_proxy_migrations_response_migrations_proto_rawDescData } -var file_interservice_infra_proxy_migrations_response_migrations_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_interservice_infra_proxy_migrations_response_migrations_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_interservice_infra_proxy_migrations_response_migrations_proto_goTypes = []interface{}{ (*UploadZipFileResponse)(nil), // 0: chef.automate.domain.infra_proxy.migrations.response.UploadZipFileResponse + (*GetMigrationStatus)(nil), // 1: chef.automate.domain.infra_proxy.migrations.response.GetMigrationStatus } var file_interservice_infra_proxy_migrations_response_migrations_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type @@ -158,6 +234,18 @@ func file_interservice_infra_proxy_migrations_response_migrations_proto_init() { return nil } } + file_interservice_infra_proxy_migrations_response_migrations_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetMigrationStatus); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -165,7 +253,7 @@ func file_interservice_infra_proxy_migrations_response_migrations_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_interservice_infra_proxy_migrations_response_migrations_proto_rawDesc, NumEnums: 0, - NumMessages: 1, + NumMessages: 2, NumExtensions: 0, NumServices: 0, }, diff --git a/api/interservice/infra_proxy/migrations/response/migrations.proto b/api/interservice/infra_proxy/migrations/response/migrations.proto index f00ae4003e9..14f771a4e32 100644 --- a/api/interservice/infra_proxy/migrations/response/migrations.proto +++ b/api/interservice/infra_proxy/migrations/response/migrations.proto @@ -11,3 +11,12 @@ message UploadZipFileResponse { // Error data in case of failure. repeated string errors = 3; } + +message GetMigrationStatus { + // Migration ID. + string migration_id = 1; + // Migration type + string migration_type = 2; + // Migration status + string migration_status = 3; +} diff --git a/api/interservice/infra_proxy/migrations/service/migrations.pb.go b/api/interservice/infra_proxy/migrations/service/migrations.pb.go index f80872b76d1..eb25b11d6f5 100644 --- a/api/interservice/infra_proxy/migrations/service/migrations.pb.go +++ b/api/interservice/infra_proxy/migrations/service/migrations.pb.go @@ -50,8 +50,8 @@ var file_interservice_infra_proxy_migrations_service_migrations_proto_rawDesc = 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, - 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0xc1, - 0x01, 0x0a, 0x14, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x61, 0x74, 0x61, + 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0xed, + 0x02, 0x0a, 0x14, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x61, 0x74, 0x61, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0xa8, 0x01, 0x0a, 0x0a, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x49, 0x2e, 0x63, 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x69, 0x6e, @@ -63,23 +63,38 @@ var file_interservice_infra_proxy_migrations_service_migrations_proto_rawDesc = 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x5a, 0x69, 0x70, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x28, 0x01, 0x42, 0x4a, 0x5a, 0x48, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x63, 0x68, 0x65, 0x66, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, - 0x70, 0x69, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, - 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6d, 0x69, 0x67, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x28, 0x01, 0x12, 0xa9, 0x01, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x47, 0x2e, 0x63, 0x68, 0x65, 0x66, + 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, + 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x6d, 0x69, 0x67, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, + 0x47, 0x65, 0x74, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x1a, 0x48, 0x2e, 0x63, 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, + 0x74, 0x65, 0x2e, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, + 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x69, 0x67, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x00, 0x42, 0x4a, + 0x5a, 0x48, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, + 0x66, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, + 0x6e, 0x74, 0x65, 0x72, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x69, 0x6e, 0x66, 0x72, + 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var file_interservice_infra_proxy_migrations_service_migrations_proto_goTypes = []interface{}{ (*request.UploadZipFileRequest)(nil), // 0: chef.automate.domain.infra_proxy.migrations.request.UploadZipFileRequest - (*response.UploadZipFileResponse)(nil), // 1: chef.automate.domain.infra_proxy.migrations.response.UploadZipFileResponse + (*request.GetMigrationStatus)(nil), // 1: chef.automate.domain.infra_proxy.migrations.request.GetMigrationStatus + (*response.UploadZipFileResponse)(nil), // 2: chef.automate.domain.infra_proxy.migrations.response.UploadZipFileResponse + (*response.GetMigrationStatus)(nil), // 3: chef.automate.domain.infra_proxy.migrations.response.GetMigrationStatus } var file_interservice_infra_proxy_migrations_service_migrations_proto_depIdxs = []int32{ 0, // 0: chef.automate.domain.infra_proxy.migrations.service.MigrationDataService.UploadFile:input_type -> chef.automate.domain.infra_proxy.migrations.request.UploadZipFileRequest - 1, // 1: chef.automate.domain.infra_proxy.migrations.service.MigrationDataService.UploadFile:output_type -> chef.automate.domain.infra_proxy.migrations.response.UploadZipFileResponse - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type + 1, // 1: chef.automate.domain.infra_proxy.migrations.service.MigrationDataService.GetMigrationStatus:input_type -> chef.automate.domain.infra_proxy.migrations.request.GetMigrationStatus + 2, // 2: chef.automate.domain.infra_proxy.migrations.service.MigrationDataService.UploadFile:output_type -> chef.automate.domain.infra_proxy.migrations.response.UploadZipFileResponse + 3, // 3: chef.automate.domain.infra_proxy.migrations.service.MigrationDataService.GetMigrationStatus:output_type -> chef.automate.domain.infra_proxy.migrations.response.GetMigrationStatus + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -122,6 +137,7 @@ const _ = grpc.SupportPackageIsVersion6 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MigrationDataServiceClient interface { UploadFile(ctx context.Context, opts ...grpc.CallOption) (MigrationDataService_UploadFileClient, error) + GetMigrationStatus(ctx context.Context, in *request.GetMigrationStatus, opts ...grpc.CallOption) (*response.GetMigrationStatus, error) } type migrationDataServiceClient struct { @@ -166,9 +182,19 @@ func (x *migrationDataServiceUploadFileClient) CloseAndRecv() (*response.UploadZ return m, nil } +func (c *migrationDataServiceClient) GetMigrationStatus(ctx context.Context, in *request.GetMigrationStatus, opts ...grpc.CallOption) (*response.GetMigrationStatus, error) { + out := new(response.GetMigrationStatus) + err := c.cc.Invoke(ctx, "/chef.automate.domain.infra_proxy.migrations.service.MigrationDataService/GetMigrationStatus", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MigrationDataServiceServer is the server API for MigrationDataService service. type MigrationDataServiceServer interface { UploadFile(MigrationDataService_UploadFileServer) error + GetMigrationStatus(context.Context, *request.GetMigrationStatus) (*response.GetMigrationStatus, error) } // UnimplementedMigrationDataServiceServer can be embedded to have forward compatible implementations. @@ -178,6 +204,9 @@ type UnimplementedMigrationDataServiceServer struct { func (*UnimplementedMigrationDataServiceServer) UploadFile(MigrationDataService_UploadFileServer) error { return status.Errorf(codes.Unimplemented, "method UploadFile not implemented") } +func (*UnimplementedMigrationDataServiceServer) GetMigrationStatus(context.Context, *request.GetMigrationStatus) (*response.GetMigrationStatus, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetMigrationStatus not implemented") +} func RegisterMigrationDataServiceServer(s *grpc.Server, srv MigrationDataServiceServer) { s.RegisterService(&_MigrationDataService_serviceDesc, srv) @@ -209,10 +238,33 @@ func (x *migrationDataServiceUploadFileServer) Recv() (*request.UploadZipFileReq return m, nil } +func _MigrationDataService_GetMigrationStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(request.GetMigrationStatus) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MigrationDataServiceServer).GetMigrationStatus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/chef.automate.domain.infra_proxy.migrations.service.MigrationDataService/GetMigrationStatus", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MigrationDataServiceServer).GetMigrationStatus(ctx, req.(*request.GetMigrationStatus)) + } + return interceptor(ctx, in, info, handler) +} + var _MigrationDataService_serviceDesc = grpc.ServiceDesc{ ServiceName: "chef.automate.domain.infra_proxy.migrations.service.MigrationDataService", HandlerType: (*MigrationDataServiceServer)(nil), - Methods: []grpc.MethodDesc{}, + Methods: []grpc.MethodDesc{ + { + MethodName: "GetMigrationStatus", + Handler: _MigrationDataService_GetMigrationStatus_Handler, + }, + }, Streams: []grpc.StreamDesc{ { StreamName: "UploadFile", diff --git a/api/interservice/infra_proxy/migrations/service/migrations.proto b/api/interservice/infra_proxy/migrations/service/migrations.proto index e5a7e28566a..edb31667683 100644 --- a/api/interservice/infra_proxy/migrations/service/migrations.proto +++ b/api/interservice/infra_proxy/migrations/service/migrations.proto @@ -10,5 +10,7 @@ import "google/api/annotations.proto"; service MigrationDataService{ rpc UploadFile (stream chef.automate.domain.infra_proxy.migrations.request.UploadZipFileRequest) returns (chef.automate.domain.infra_proxy.migrations.response.UploadZipFileResponse) {}; + rpc GetMigrationStatus (chef.automate.domain.infra_proxy.migrations.request.GetMigrationStatus) returns (chef.automate.domain.infra_proxy.migrations.response.GetMigrationStatus) {}; } + diff --git a/api/interservice/infra_proxy/response/servers.pb.go b/api/interservice/infra_proxy/response/servers.pb.go index 546e79f62cf..0ac18af3c8c 100644 --- a/api/interservice/infra_proxy/response/servers.pb.go +++ b/api/interservice/infra_proxy/response/servers.pb.go @@ -282,7 +282,7 @@ type Server struct { OrgsCount int32 `protobuf:"varint,6,opt,name=orgs_count,json=orgsCount,proto3" json:"orgs_count,omitempty" toml:"orgs_count,omitempty" mapstructure:"orgs_count,omitempty"` //Migration Id for active Chef Infra server migration MigrationId string `protobuf:"bytes,7,opt,name=migration_id,json=migrationId,proto3" json:"migration_id,omitempty" toml:"migration_id,omitempty" mapstructure:"migration_id,omitempty"` - //Migration Id for active Chef Infra server migration + //Migration type for active Chef Infra server migration MigrationStatus string `protobuf:"bytes,8,opt,name=migration_status,json=migrationStatus,proto3" json:"migration_status,omitempty" toml:"migration_status,omitempty" mapstructure:"migration_status,omitempty"` } diff --git a/components/automate-gateway/api/migrations.pb.swagger.go b/components/automate-gateway/api/migrations.pb.swagger.go new file mode 100644 index 00000000000..db6cc2e2ce8 --- /dev/null +++ b/components/automate-gateway/api/migrations.pb.swagger.go @@ -0,0 +1,103 @@ +package api + +func init() { + Swagger.Add("migrations", `{ + "swagger": "2.0", + "info": { + "title": "external/infra_proxy/migrations/migrations.proto", + "version": "version not set" + }, + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/api/v0/infra/servers/migrations/status/{migration_id}": { + "get": { + "operationId": "InfraProxyMigration_GetMigrationStatus", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/chef.automate.api.infra_proxy.migrations.response.GetMigrationStatus" + } + }, + "default": { + "description": "An unexpected error response", + "schema": { + "$ref": "#/definitions/grpc.gateway.runtime.Error" + } + } + }, + "parameters": [ + { + "name": "migration_id", + "description": "Migration ID.", + "in": "path", + "required": true, + "type": "string" + } + ], + "tags": [ + "InfraProxyMigration" + ] + } + } + }, + "definitions": { + "chef.automate.api.infra_proxy.migrations.response.GetMigrationStatus": { + "type": "object", + "properties": { + "migration_id": { + "type": "string", + "description": "Migration ID." + }, + "migration_type": { + "type": "string", + "title": "Migration type" + }, + "migration_status": { + "type": "string", + "title": "Migration status" + } + } + }, + "google.protobuf.Any": { + "type": "object", + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "type": "string", + "format": "byte" + } + } + }, + "grpc.gateway.runtime.Error": { + "type": "object", + "properties": { + "error": { + "type": "string" + }, + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/google.protobuf.Any" + } + } + } + } + } +} +`) +} diff --git a/components/automate-gateway/gateway/clients.go b/components/automate-gateway/gateway/clients.go index 5e6bce4cedd..d552c684090 100644 --- a/components/automate-gateway/gateway/clients.go +++ b/components/automate-gateway/gateway/clients.go @@ -2,6 +2,7 @@ package gateway import ( "fmt" + "github.com/chef/automate/api/interservice/user_settings" grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" @@ -35,6 +36,7 @@ import ( "github.com/chef/automate/api/interservice/teams" notifications "github.com/chef/automate/components/notifications-client/api" "github.com/chef/automate/components/notifications-client/notifier" + "github.com/chef/automate/lib/grpc/secureconn" "github.com/chef/automate/lib/tracing" ) diff --git a/components/automate-gateway/gateway/services.go b/components/automate-gateway/gateway/services.go index 65e229a7f22..20fbae8fb85 100644 --- a/components/automate-gateway/gateway/services.go +++ b/components/automate-gateway/gateway/services.go @@ -37,6 +37,8 @@ import ( pb_iam "github.com/chef/automate/api/external/iam/v2" policy "github.com/chef/automate/api/external/iam/v2/policy" pb_infra_proxy "github.com/chef/automate/api/external/infra_proxy" + pb_infra_proxy_migrations "github.com/chef/automate/api/external/infra_proxy/migrations" + pb_ingest "github.com/chef/automate/api/external/ingest" pb_nodes "github.com/chef/automate/api/external/nodes" pb_nodes_manager "github.com/chef/automate/api/external/nodes/manager" @@ -68,6 +70,7 @@ import ( handler_tokens "github.com/chef/automate/components/automate-gateway/handler/iam/v2/tokens" handler_users "github.com/chef/automate/components/automate-gateway/handler/iam/v2/users" handler_infra_proxy "github.com/chef/automate/components/automate-gateway/handler/infra_proxy" + handler_infra_proxy_migration "github.com/chef/automate/components/automate-gateway/handler/infra_proxy/migrations" // anything else "github.com/chef/automate/components/automate-gateway/gateway/middleware" @@ -316,13 +319,17 @@ func (s *Server) RegisterGRPCServices(grpcServer *grpc.Server) error { pb_data_lifecycle.RegisterDataLifecycleServer(grpcServer, dataLifecycleServer) infraProxyClient, err := clients.InfraProxyClient() + if err != nil { + return errors.Wrap(err, "create client for infra proxy service") + } infraProxyMigrationClient, err := clients.InfraProxyMigrationClient() - if err != nil { - return errors.Wrap(err, "create client for infra proxy service") + return errors.Wrap(err, "create client for infra proxy migration service") } - pb_infra_proxy.RegisterInfraProxyServer(grpcServer, handler_infra_proxy.NewInfraProxyHandler(infraProxyClient, infraProxyMigrationClient)) + pb_infra_proxy.RegisterInfraProxyServer(grpcServer, handler_infra_proxy.NewInfraProxyHandler(infraProxyClient)) + + pb_infra_proxy_migrations.RegisterInfraProxyMigrationServer(grpcServer, handler_infra_proxy_migration.NewInfraProxyMigrationHandler(infraProxyMigrationClient)) userSettingsClient, err := clients.UserSettingsClient() if err != nil { @@ -377,6 +384,7 @@ func unversionedRESTMux(grpcURI string, dopts []grpc.DialOption) (http.Handler, "data-lifecycle": pb_data_lifecycle.RegisterDataLifecycleHandlerFromEndpoint, "applications": pb_apps.RegisterApplicationsServiceHandlerFromEndpoint, "infra-proxy": pb_infra_proxy.RegisterInfraProxyHandlerFromEndpoint, + "infra-proxy-migrations": pb_infra_proxy_migrations.RegisterInfraProxyMigrationHandlerFromEndpoint, "user-settings": pb_user_settings.RegisterUserSettingsServiceHandlerFromEndpoint, }) } diff --git a/components/automate-gateway/handler/infra_proxy/infra_proxy.go b/components/automate-gateway/handler/infra_proxy/infra_proxy.go index f04a9cf96d2..b644290016c 100644 --- a/components/automate-gateway/handler/infra_proxy/infra_proxy.go +++ b/components/automate-gateway/handler/infra_proxy/infra_proxy.go @@ -1,20 +1,17 @@ package infra_proxy import ( - migrations "github.com/chef/automate/api/interservice/infra_proxy/migrations/service" infra_proxy "github.com/chef/automate/api/interservice/infra_proxy/service" ) // InfraProxyServer stores client type InfraProxyServer struct { - client infra_proxy.InfraProxyServiceClient - migrationClient migrations.MigrationDataServiceClient + client infra_proxy.InfraProxyServiceClient } // NewInfraProxyHandler initializes InfraProxyServer with client -func NewInfraProxyHandler(client infra_proxy.InfraProxyServiceClient, migrationClient migrations.MigrationDataServiceClient) *InfraProxyServer { +func NewInfraProxyHandler(client infra_proxy.InfraProxyServiceClient) *InfraProxyServer { return &InfraProxyServer{ - client: client, - migrationClient: migrationClient, + client: client, } } diff --git a/components/automate-gateway/handler/infra_proxy/migrations/infra_proxy_migrations.go b/components/automate-gateway/handler/infra_proxy/migrations/infra_proxy_migrations.go new file mode 100644 index 00000000000..d4b0ee777ac --- /dev/null +++ b/components/automate-gateway/handler/infra_proxy/migrations/infra_proxy_migrations.go @@ -0,0 +1,15 @@ +package migrations + +import migrations "github.com/chef/automate/api/interservice/infra_proxy/migrations/service" + +// InfraProxyMigrationServer stores client +type InfraProxyMigrationServer struct { + migrationClient migrations.MigrationDataServiceClient +} + +// NewInfraProxyMigrationHandler initializes InfraProxyMigrationServer with client +func NewInfraProxyMigrationHandler(migrationClient migrations.MigrationDataServiceClient) *InfraProxyMigrationServer { + return &InfraProxyMigrationServer{ + migrationClient: migrationClient, + } +} diff --git a/components/automate-gateway/handler/infra_proxy/migrations/migrations.go b/components/automate-gateway/handler/infra_proxy/migrations/migrations.go index a6ea3eef7b6..f5889750aee 100644 --- a/components/automate-gateway/handler/infra_proxy/migrations/migrations.go +++ b/components/automate-gateway/handler/infra_proxy/migrations/migrations.go @@ -1 +1,26 @@ package migrations + +import ( + "context" + + gwreq "github.com/chef/automate/api/external/infra_proxy/migrations/request" + gwres "github.com/chef/automate/api/external/infra_proxy/migrations/response" + infra_req "github.com/chef/automate/api/interservice/infra_proxy/migrations/request" +) + +// GetMigrationStatus fetches the latest migration status against migration id +func (a *InfraProxyMigrationServer) GetMigrationStatus(ctx context.Context, r *gwreq.GetMigrationStatus) (*gwres.GetMigrationStatus, error) { + req := &infra_req.GetMigrationStatus{ + MigrationId: r.MigrationId, + } + res, err := a.migrationClient.GetMigrationStatus(ctx, req) + if err != nil { + return nil, err + } + + return &gwres.GetMigrationStatus{ + MigrationId: res.GetMigrationId(), + MigrationType: res.GetMigrationType(), + MigrationStatus: res.GetMigrationStatus(), + }, nil +} diff --git a/components/infra-proxy-service/server/migration.go b/components/infra-proxy-service/server/migration.go deleted file mode 100644 index 5e37dbf09b4..00000000000 --- a/components/infra-proxy-service/server/migration.go +++ /dev/null @@ -1,38 +0,0 @@ -package server - -import ( - "context" - "errors" - - secrets "github.com/chef/automate/api/external/secrets" - "github.com/chef/automate/components/infra-proxy-service/service" -) - -var IsMigrationAlreadyRunning bool - -func setMigrationStatus(status bool) { - IsMigrationAlreadyRunning = status -} - -// getChefClient: creates the chef client -func (s *Server) getChefClient(ctx context.Context, serverId string) (*ChefClient, error) { - // Get the credential ID from servers table - server, err := s.service.Storage.GetServer(ctx, serverId) - if err != nil { - return nil, service.ParseStorageError(err, serverId, "server") - } - if server.CredentialID == "" { - return nil, errors.New("webui key is not available with server") - } - // Get web ui key from secrets service - secret, err := s.service.Secrets.Read(ctx, &secrets.Id{Id: server.CredentialID}) - if err != nil { - return nil, err - } - - c, err := s.createChefServerClient(ctx, serverId, GetAdminKeyFrom(secret), "pivotal", true) - if err != nil { - return nil, err - } - return c, nil -} diff --git a/components/infra-proxy-service/server/migrations.go b/components/infra-proxy-service/server/migrations.go index 6af1a6b03b9..d4a835103f0 100644 --- a/components/infra-proxy-service/server/migrations.go +++ b/components/infra-proxy-service/server/migrations.go @@ -1,133 +1,32 @@ package server import ( - "bytes" "context" - "io" - "os" - "path" - uuid "github.com/chef/automate/lib/uuid4" - log "github.com/sirupsen/logrus" + "github.com/pkg/errors" - "github.com/chef/automate/api/interservice/infra_proxy/migrations/response" - "github.com/chef/automate/api/interservice/infra_proxy/migrations/service" + secrets "github.com/chef/automate/api/external/secrets" ) -// Takes up file name from service.MigrationDataService_UploadFileServer.MigrationId and creates the file in the same directory -func saveFile(migrationId string, filename string, fileData bytes.Buffer) error { - folderPath := path.Join("/hab/svc/infra-proxy-service/data", migrationId) - err := os.Mkdir(folderPath, 0777) +// getChefClient: creates the chef client +func (s *Server) getChefClient(ctx context.Context, serverId string) (*ChefClient, error) { + // Get the credential ID from servers table + server, err := s.service.Storage.GetServer(ctx, serverId) if err != nil { - log.WithError(err).Error("Unable to create directory for migration id", migrationId) - return err + return nil, err } - filePath := path.Join(folderPath, filename) - file, err := os.Create(filePath) - if err != nil { - log.WithError(err).Error("Unable to create zipped file for migration id", migrationId) - return err + if server.CredentialID == "" { + return nil, errors.New("webui key is not available with server") } - _, err = fileData.WriteTo(file) + // Get web ui key from secrets service + secret, err := s.service.Secrets.Read(ctx, &secrets.Id{Id: server.CredentialID}) if err != nil { - return err + return nil, err } - return nil - -} -// UploadFile Takes the stream of data to upload a file -func (s *Server) UploadFile(stream service.MigrationDataService_UploadFileServer) error { - log.Info("Starting the with the request to upload file") - req, err := stream.Recv() - serverId := req.ServerId - fileName := req.GetMeta().GetName() - ctx := context.Background() - migrationId, err := createMigrationId() + c, err := s.createChefServerClient(ctx, serverId, GetAdminKeyFrom(secret), "pivotal", true) if err != nil { - log.WithError(err).Error("Unable to create migration id") - res := handleErrorForUploadFileAndMigration(err, migrationId, serverId, s, ctx) - stream.SendAndClose(res) - return err - } - log.Info("Starting with migration phase with the upload filei for migration id: ", migrationId) - _, err = s.service.Migration.StartMigration(ctx, migrationId, serverId) - fileData := bytes.Buffer{} - s.service.Migration.StartFileUpload(ctx, migrationId, serverId) - for { - req, err := stream.Recv() - - if err == io.EOF { - break - } - - if err != nil { - log.Errorf("Failed to upload file for migration id %s : %s", migrationId, err.Error()) - res := handleErrorForUploadFileAndMigration(err, migrationId, serverId, s, ctx) - stream.SendAndClose(res) - return err - } - - chunk := req.GetChunk().Data - _, err = fileData.Write(chunk) - if err != nil { - log.Errorf("Failed to upload file for migration id %s : %s", migrationId, err.Error()) - res := handleErrorForUploadFileAndMigration(err, migrationId, serverId, s, ctx) - stream.SendAndClose(res) - return err - } - } - - err = saveFile(migrationId, fileName, fileData) - if err != nil { - log.Errorf("Failed to save uploaded file for migration id %s : %s", migrationId, err.Error()) - res := handleErrorForUploadFileAndMigration(err, migrationId, serverId, s, ctx) - stream.SendAndClose(res) - return err - } - log.Info("File successfully saved in the directory for the requested file for migration id: ", migrationId) - - res := &response.UploadZipFileResponse{ - MigrationId: migrationId, - Success: true, - } - s.service.Migration.CompleteFileUpload(ctx, migrationId, serverId, 0, 0, 0) - log.Info("File successfully uploaded in the directory for the requested file for migration id: ", migrationId) - err = stream.SendAndClose(res) - if err != nil { - handleErrorForUploadFileAndMigration(err, migrationId, serverId, s, ctx) - log.Errorf("Failed to send the response for migration id %s : %s", migrationId, err.Error()) - return err - } - - return nil -} - -func createMigrationId() (string, error) { - uuid, err := uuid.NewV4() - if err != nil { - log.WithError(err).Error("Failed to make a V4 UUID") - return "", err - } - return uuid.String(), nil -} - -//handleErrorForUploadFileAndMigration handles the error for the file upload -func handleErrorForUploadFileAndMigration(err error, migrationId string, serviceId string, s *Server, ctx context.Context) *response.UploadZipFileResponse { - response := createResponseWithErrors(err, migrationId) - s.service.Migration.FailedFileUpload(ctx, migrationId, serviceId, err.Error(), 0, 0, 0) - //ToDo to add the Failed migration status as well - s.service.Migration.FailedMigration(ctx, migrationId, serviceId, err.Error(), 0, 0, 0) - return response - -} - -//createResponseWithErrors created a response with errors -func createResponseWithErrors(err error, migrationId string) *response.UploadZipFileResponse { - errors := []string{err.Error()} - return &response.UploadZipFileResponse{ - Success: false, - MigrationId: migrationId, - Errors: errors, + return nil, err } + return c, nil } diff --git a/components/infra-proxy-service/server/migrations/migrations.go b/components/infra-proxy-service/server/migrations/migrations.go index a6ea3eef7b6..e651c350378 100644 --- a/components/infra-proxy-service/server/migrations/migrations.go +++ b/components/infra-proxy-service/server/migrations/migrations.go @@ -1 +1,162 @@ package migrations + +import ( + "bytes" + "context" + "io" + "os" + "path" + + "github.com/chef/automate/api/interservice/infra_proxy/migrations/request" + "github.com/chef/automate/api/interservice/infra_proxy/migrations/response" + "github.com/chef/automate/api/interservice/infra_proxy/migrations/service" + "github.com/chef/automate/components/infra-proxy-service/validation" + "github.com/gofrs/uuid" + log "github.com/sirupsen/logrus" +) + +// UploadFile Takes the stream of data to upload a file +func (s *MigrationServer) UploadFile(stream service.MigrationDataService_UploadFileServer) error { + log.Info("Starting the with the request to upload file") + req, err := stream.Recv() + serverId := req.ServerId + fileName := req.GetMeta().GetName() + ctx := context.Background() + migrationId, err := createMigrationId() + if err != nil { + log.WithError(err).Error("Unable to create migration id") + res := handleErrorForUploadFileAndMigration(err, migrationId, serverId, s, ctx) + stream.SendAndClose(res) + return err + } + log.Info("Starting with migration phase with the upload filei for migration id: ", migrationId) + _, err = s.service.Migration.StartMigration(ctx, migrationId, serverId) + fileData := bytes.Buffer{} + s.service.Migration.StartFileUpload(ctx, migrationId, serverId) + for { + req, err := stream.Recv() + + if err == io.EOF { + break + } + + if err != nil { + log.Errorf("Failed to upload file for migration id %s : %s", migrationId, err.Error()) + res := handleErrorForUploadFileAndMigration(err, migrationId, serverId, s, ctx) + stream.SendAndClose(res) + return err + } + + chunk := req.GetChunk().Data + _, err = fileData.Write(chunk) + if err != nil { + log.Errorf("Failed to upload file for migration id %s : %s", migrationId, err.Error()) + res := handleErrorForUploadFileAndMigration(err, migrationId, serverId, s, ctx) + stream.SendAndClose(res) + return err + } + } + + err = saveFile(migrationId, fileName, fileData) + if err != nil { + log.Errorf("Failed to save uploaded file for migration id %s : %s", migrationId, err.Error()) + res := handleErrorForUploadFileAndMigration(err, migrationId, serverId, s, ctx) + stream.SendAndClose(res) + return err + } + log.Info("File successfully saved in the directory for the requested file for migration id: ", migrationId) + + res := &response.UploadZipFileResponse{ + MigrationId: migrationId, + Success: true, + } + s.service.Migration.CompleteFileUpload(ctx, migrationId, serverId, 0, 0, 0) + log.Info("File successfully uploaded in the directory for the requested file for migration id: ", migrationId) + err = stream.SendAndClose(res) + if err != nil { + handleErrorForUploadFileAndMigration(err, migrationId, serverId, s, ctx) + log.Errorf("Failed to send the response for migration id %s : %s", migrationId, err.Error()) + return err + } + + return nil +} + +// GetMigrationStatus fetch migration status against migration id +func (s *MigrationServer) GetMigrationStatus(ctx context.Context, req *request.GetMigrationStatus) (*response.GetMigrationStatus, error) { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + + // Validate all request fields are required + err := validation.New(validation.Options{ + Target: "server", + Request: *req, + RequiredDefault: true, + }).Validate() + + if err != nil { + return nil, err + } + + migration, err := s.service.Migration.GetMigrationStatus(ctx, req.MigrationId) + if err != nil { + return nil, err + } + + return &response.GetMigrationStatus{ + MigrationId: migration.MigrationID, + MigrationType: migration.MigrationType, + MigrationStatus: migration.MigrationStatus, + }, nil +} + +// Takes up file name from service.MigrationDataService_UploadFileServer.MigrationId and creates the file in the same directory +func saveFile(migrationId string, filename string, fileData bytes.Buffer) error { + folderPath := path.Join("/hab/svc/infra-proxy-service/data", migrationId) + err := os.Mkdir(folderPath, 0777) + if err != nil { + log.WithError(err).Error("Unable to create directory for migration id", migrationId) + return err + } + filePath := path.Join(folderPath, filename) + file, err := os.Create(filePath) + if err != nil { + log.WithError(err).Error("Unable to create zipped file for migration id", migrationId) + return err + } + _, err = fileData.WriteTo(file) + if err != nil { + return err + } + return nil + +} + +func createMigrationId() (string, error) { + uuid, err := uuid.NewV4() + if err != nil { + log.WithError(err).Error("Failed to make a V4 UUID") + return "", err + } + return uuid.String(), nil +} + +//handleErrorForUploadFileAndMigration handles the error for the file upload +func handleErrorForUploadFileAndMigration(err error, migrationId string, serviceId string, s *MigrationServer, ctx context.Context) *response.UploadZipFileResponse { + response := createResponseWithErrors(err, migrationId) + s.service.Migration.FailedFileUpload(ctx, migrationId, serviceId, err.Error(), 0, 0, 0) + //ToDo to add the Failed migration status as well + s.service.Migration.FailedMigration(ctx, migrationId, serviceId, err.Error(), 0, 0, 0) + return response + +} + +//createResponseWithErrors created a response with errors +func createResponseWithErrors(err error, migrationId string) *response.UploadZipFileResponse { + errors := []string{err.Error()} + return &response.UploadZipFileResponse{ + Success: false, + MigrationId: migrationId, + Errors: errors, + } +} diff --git a/components/infra-proxy-service/server/migrations/migrations_test.go b/components/infra-proxy-service/server/migrations/migrations_test.go new file mode 100644 index 00000000000..4f14b4e8b2e --- /dev/null +++ b/components/infra-proxy-service/server/migrations/migrations_test.go @@ -0,0 +1,45 @@ +package migrations_test + +import ( + "context" + "errors" + "testing" + + "github.com/chef/automate/api/external/infra_proxy/migrations/request" + "github.com/chef/automate/api/external/infra_proxy/migrations/response" + + "github.com/golang/mock/gomock" + + infra_migrations "github.com/chef/automate/api/external/infra_proxy/migrations" + "github.com/chef/automate/components/infra-proxy-service/test" +) + +func TestMigrations(t *testing.T) { + ctx := context.Background() + _, serviceRef, _, close, _, _ := test.SetupInfraProxyService(ctx, t) + infraMigrationMockClient := infra_migrations.NewMockInfraProxyMigrationClient(gomock.NewController(t)) + + defer close() + + t.Run("GetMigrationStatus", func(t *testing.T) { + test.ResetState(ctx, t, serviceRef) + + res := &response.GetMigrationStatus{ + MigrationId: "Fake id", + MigrationType: "Migration Completed", + MigrationStatus: "Failed", + } + req := request.GetMigrationStatus{ + MigrationId: "Fake id", + } + t.Run("when a migration id which exist in migration table is submitted, then return the latest status.", func(t *testing.T) { + infraMigrationMockClient.EXPECT().GetMigrationStatus(gomock.Any(), req, gomock.Any()).Return(res, nil) + + }) + + t.Run("when a migration id is not exist in migration table is submitted, then return an error", func(t *testing.T) { + infraMigrationMockClient.EXPECT().GetMigrationStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("sql: no rows in result set")) + + }) + }) +} diff --git a/components/infra-proxy-service/server/migrations/server.go b/components/infra-proxy-service/server/migrations/server.go new file mode 100644 index 00000000000..6034bfd1545 --- /dev/null +++ b/components/infra-proxy-service/server/migrations/server.go @@ -0,0 +1,16 @@ +package migrations + +import ( + "github.com/chef/automate/components/infra-proxy-service/service" +) + +type MigrationServer struct { + service *service.Service +} + +// NewMigrationServer returns an infra-proxy migration server +func NewMigrationServer(service *service.Service) *MigrationServer { + return &MigrationServer{ + service: service, + } +} diff --git a/components/infra-proxy-service/server/orgs.go b/components/infra-proxy-service/server/orgs.go index 2071cca608f..d00eaedc31e 100644 --- a/components/infra-proxy-service/server/orgs.go +++ b/components/infra-proxy-service/server/orgs.go @@ -3,7 +3,6 @@ package server import ( "context" "encoding/json" - "errors" "github.com/chef/automate/api/external/common/query" secrets "github.com/chef/automate/api/external/secrets" @@ -216,20 +215,12 @@ func (s *Server) ResetOrgAdminKey(ctx context.Context, req *request.ResetOrgAdmi //GetInfraServerOrgs: Fetches the list of automate infra server organisations from the chef server and save it into the automate back end DB func (s *Server) GetInfraServerOrgs(ctx context.Context, req *request.GetInfraServerOrgs) (*response.GetInfraServerOrgs, error) { - // Check whether any migration is in progress or not - if IsMigrationAlreadyRunning { - return nil, errors.New("Migration is already in process") - } - // Get chef client client, err := s.getChefClient(ctx, req.ServerId) if err != nil { return nil, err } - setMigrationStatus(true) - defer setMigrationStatus(false) - // This is only for reference to use the migration_stage storage functions parsedData, err := json.Marshal(&storage.Org{ID: "1234", Name: "demo_org"}) if err != nil { diff --git a/components/infra-proxy-service/server/server.go b/components/infra-proxy-service/server/server.go index a1fcb4642a4..332f1e5e4c3 100644 --- a/components/infra-proxy-service/server/server.go +++ b/components/infra-proxy-service/server/server.go @@ -4,17 +4,21 @@ import ( "context" "crypto/tls" "fmt" + "net" + "net/http" + grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/reflection" "google.golang.org/grpc/status" - "net" - "net/http" - grpc_migration "github.com/chef/automate/api/interservice/infra_proxy/migrations/service" grpc_s "github.com/chef/automate/api/interservice/infra_proxy/service" + + grpc_migration "github.com/chef/automate/api/interservice/infra_proxy/migrations/service" + migrations "github.com/chef/automate/components/infra-proxy-service/server/migrations" + "github.com/chef/automate/components/infra-proxy-service/service" "github.com/chef/automate/lib/grpc/health" "github.com/chef/automate/lib/tracing" @@ -85,7 +89,7 @@ func NewGRPCServer(s *service.Service) *grpc.Server { ) health.RegisterHealthServer(g, health.NewService()) grpc_s.RegisterInfraProxyServiceServer(g, NewServer(s)) - grpc_migration.RegisterMigrationDataServiceServer(g, NewServer(s)) + grpc_migration.RegisterMigrationDataServiceServer(g, migrations.NewMigrationServer(s)) reflection.Register(g) return g } diff --git a/components/infra-proxy-service/server/servers.go b/components/infra-proxy-service/server/servers.go index ed583dd6975..2d51612b9f6 100644 --- a/components/infra-proxy-service/server/servers.go +++ b/components/infra-proxy-service/server/servers.go @@ -386,14 +386,14 @@ func fromStorageToListServers(sl []storage.Server) []*response.Server { } // Create a response.Server from a storage.Server with migration -func fromStorageServerWithMigrationDetails(s storage.Server, m storage.ActiveMigration) *response.Server { +func fromStorageServerWithMigrationDetails(s storage.Server, m storage.MigrationStatus) *response.Server { return &response.Server{ Id: s.ID, Name: s.Name, Fqdn: s.Fqdn, IpAddress: s.IPAddress, OrgsCount: s.OrgsCount, - MigrationId: m.MigrationId, + MigrationId: m.MigrationID, MigrationStatus: m.MigrationType, } } diff --git a/components/infra-proxy-service/storage/postgres/migrations.go b/components/infra-proxy-service/storage/postgres/migrations.go index 036575a8733..a581dd35315 100644 --- a/components/infra-proxy-service/storage/postgres/migrations.go +++ b/components/infra-proxy-service/storage/postgres/migrations.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "github.com/chef/automate/components/infra-proxy-service/constants" "github.com/chef/automate/components/infra-proxy-service/storage" ) @@ -210,15 +211,34 @@ func (p *postgres) insertMigration(ctx context.Context, migrationId, serverId, m } //GetActiveMigration gets the Migration ID and Migration Status for a server id -func (p *postgres) GetActiveMigration(ctx context.Context, serverId string) (storage.ActiveMigration, error) { - var m storage.ActiveMigration - query := "select m.id,t.type from migration m join migration_type t on m.type_id=t.id and t.id < 5000 and m.server_id=$1 order by updated_timestamp desc FETCH FIRST ROW ONLY" +func (p *postgres) GetActiveMigration(ctx context.Context, serverId string) (storage.MigrationStatus, error) { + var m storage.MigrationStatus + query := "select m.migration_id,t.type from migration m join migration_type t on m.type_id=t.id and t.id < 5000 and m.server_id=$1 order by updated_timestamp desc FETCH FIRST ROW ONLY" err := p.db.QueryRowContext(ctx, query, serverId). - Scan(&m.MigrationId, &m.MigrationType) + Scan(&m.MigrationID, &m.MigrationType) + + if err != nil { + return storage.MigrationStatus{}, err + } + + return m, nil +} + +// GetMigrationStatus Fetches migration status against migration id +func (p *postgres) GetMigrationStatus(ctx context.Context, migrationId string) (storage.MigrationStatus, error) { + var m storage.MigrationStatus + query := `select m.migration_id,t.type,s.status_message + from migration m + join migration_type t on m.type_id=t.id + join migration_status s on m.status_id=s.id + and t.id <= 5000 and m.migration_id=$1 order by updated_timestamp desc FETCH FIRST ROW ONLY` + err := p.db.QueryRowContext(ctx, + query, migrationId). + Scan(&m.MigrationID, &m.MigrationType, &m.MigrationStatus) if err != nil { - return storage.ActiveMigration{}, err + return storage.MigrationStatus{}, err } return m, nil diff --git a/components/infra-proxy-service/storage/storage.go b/components/infra-proxy-service/storage/storage.go index b7ec1937029..c60ee036d10 100644 --- a/components/infra-proxy-service/storage/storage.go +++ b/components/infra-proxy-service/storage/storage.go @@ -66,10 +66,13 @@ type MigrationStorage interface { FailedPermissionMigration(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) CompleteMigration(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) FailedMigration(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) - GetActiveMigration(ctx context.Context, serverId string) (ActiveMigration, error) + StoreMigrationStage(ctx context.Context, migrationId string, parsedData interface{}) (MigrationStage, error) GetMigrationStage(ctx context.Context, migrationId string) (MigrationStage, error) DeleteMigrationStage(ctx context.Context, migrationId string) (MigrationStage, error) + + GetActiveMigration(ctx context.Context, serverId string) (MigrationStatus, error) + GetMigrationStatus(ctx context.Context, migrationId string) (MigrationStatus, error) } // Resetter is, if exposed, used for tests to reset the storage backend to a @@ -128,12 +131,6 @@ type Migration struct { Message string `json:"message"` UpdatedTimestamp time.Time `json:"updated_timestamp"` } - -type ActiveMigration struct { - MigrationId string - MigrationType string -} - type MigrationStage struct { ID string `json:"id"` MigrationID string `json:"migration_id"` @@ -142,6 +139,12 @@ type MigrationStage struct { UpdatedAt time.Time `json:"updated_at"` } +type MigrationStatus struct { + MigrationID string + MigrationType string + MigrationStatus string +} + // Errors returned from the backend var ( // ErrNotFound is returned when a requested server wasn't found