aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Multanen <eric.w.multanen@intel.com>2020-04-23 12:46:35 -0700
committerEric Multanen <eric.w.multanen@intel.com>2020-04-30 16:55:52 -0700
commitea7b430a700a12cbde9e78acb3a993ad4257b12c (patch)
tree6345485d6440b3600a191360659df9036f0b5a09 /src
parent4100bfb764c40e2a788d28691b0f891e2ae86b74 (diff)
Add gRPC framework to orchestrator
Adds proto and generated go files for a healtcheck, contextupdate and installapp rpc services. Adds framework for orchestrator as an rpc client to connect to configured controllers. Issue-ID: MULTICLOUD-1019 Signed-off-by: Eric Multanen <eric.w.multanen@intel.com> Change-Id: Ie66865789fe2146258c91e168cfb8d5933905814
Diffstat (limited to 'src')
-rw-r--r--src/orchestrator/api/controllerhandler_test.go4
-rw-r--r--src/orchestrator/cmd/main.go5
-rw-r--r--src/orchestrator/go.mod6
-rw-r--r--src/orchestrator/pkg/grpc/contextupdate/contextupdate.pb.go217
-rw-r--r--src/orchestrator/pkg/grpc/contextupdate/contextupdate.proto32
-rw-r--r--src/orchestrator/pkg/grpc/installapp/installapp.pb.go346
-rw-r--r--src/orchestrator/pkg/grpc/installapp/installapp.proto45
-rw-r--r--src/orchestrator/pkg/infra/config/config.go62
-rwxr-xr-xsrc/orchestrator/pkg/infra/rpc/rpc.go199
-rw-r--r--src/orchestrator/pkg/module/controller.go31
10 files changed, 910 insertions, 37 deletions
diff --git a/src/orchestrator/api/controllerhandler_test.go b/src/orchestrator/api/controllerhandler_test.go
index a2f93ea7..b88fc1e7 100644
--- a/src/orchestrator/api/controllerhandler_test.go
+++ b/src/orchestrator/api/controllerhandler_test.go
@@ -68,6 +68,10 @@ func (m *mockControllerManager) DeleteController(name string) error {
return m.Err
}
+func (m *mockControllerManager) InitControllers() {
+ return
+}
+
func TestControllerCreateHandler(t *testing.T) {
testCases := []struct {
label string
diff --git a/src/orchestrator/cmd/main.go b/src/orchestrator/cmd/main.go
index 001903a7..7f258bbf 100644
--- a/src/orchestrator/cmd/main.go
+++ b/src/orchestrator/cmd/main.go
@@ -28,6 +28,8 @@ import (
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/config"
contextDb "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/contextdb"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/rpc"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module"
)
func main() {
@@ -56,12 +58,15 @@ func main() {
Addr: ":" + config.GetConfiguration().ServicePort,
}
+ module.NewControllerClient().InitControllers()
+
connectionsClose := make(chan struct{})
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
httpServer.Shutdown(context.Background())
+ rpc.CloseAllRpcConn()
close(connectionsClose)
}()
diff --git a/src/orchestrator/go.mod b/src/orchestrator/go.mod
index 39d28d5c..47796626 100644
--- a/src/orchestrator/go.mod
+++ b/src/orchestrator/go.mod
@@ -4,6 +4,7 @@ require (
github.com/coreos/etcd v3.3.12+incompatible
github.com/ghodss/yaml v1.0.0
github.com/gogo/protobuf v1.3.1 // indirect
+ github.com/golang/protobuf v1.3.4
github.com/golang/snappy v0.0.1 // indirect
github.com/gorilla/handlers v1.3.0
github.com/gorilla/mux v1.6.2
@@ -13,8 +14,11 @@ require (
github.com/sirupsen/logrus v1.4.2
go.etcd.io/etcd v3.3.12+incompatible
go.mongodb.org/mongo-driver v1.0.0
- golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297
+ golang.org/x/net v0.0.0-20200301022130-244492dfa37a
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
+ golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
+ google.golang.org/genproto v0.0.0-20200305110556-506484158171 // indirect
+ google.golang.org/grpc v1.27.1
k8s.io/apimachinery v0.0.0-20190831074630-461753078381
k8s.io/helm v2.14.3+incompatible
k8s.io/klog v1.0.0 // indirect
diff --git a/src/orchestrator/pkg/grpc/contextupdate/contextupdate.pb.go b/src/orchestrator/pkg/grpc/contextupdate/contextupdate.pb.go
new file mode 100644
index 00000000..72226224
--- /dev/null
+++ b/src/orchestrator/pkg/grpc/contextupdate/contextupdate.pb.go
@@ -0,0 +1,217 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// source: contextupdate.proto
+
+package contextupdate
+
+import (
+ context "context"
+ fmt "fmt"
+ proto "github.com/golang/protobuf/proto"
+ grpc "google.golang.org/grpc"
+ codes "google.golang.org/grpc/codes"
+ status "google.golang.org/grpc/status"
+ math "math"
+)
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ = proto.Marshal
+var _ = fmt.Errorf
+var _ = math.Inf
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the proto package it is being compiled against.
+// A compilation error at this line likely means your copy of the
+// proto package needs to be updated.
+const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
+
+type ContextUpdateRequest struct {
+ AppContext string `protobuf:"bytes,1,opt,name=app_context,json=appContext,proto3" json:"app_context,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized []byte `json:"-"`
+ XXX_sizecache int32 `json:"-"`
+}
+
+func (m *ContextUpdateRequest) Reset() { *m = ContextUpdateRequest{} }
+func (m *ContextUpdateRequest) String() string { return proto.CompactTextString(m) }
+func (*ContextUpdateRequest) ProtoMessage() {}
+func (*ContextUpdateRequest) Descriptor() ([]byte, []int) {
+ return fileDescriptor_8ebb57f5310873be, []int{0}
+}
+
+func (m *ContextUpdateRequest) XXX_Unmarshal(b []byte) error {
+ return xxx_messageInfo_ContextUpdateRequest.Unmarshal(m, b)
+}
+func (m *ContextUpdateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+ return xxx_messageInfo_ContextUpdateRequest.Marshal(b, m, deterministic)
+}
+func (m *ContextUpdateRequest) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_ContextUpdateRequest.Merge(m, src)
+}
+func (m *ContextUpdateRequest) XXX_Size() int {
+ return xxx_messageInfo_ContextUpdateRequest.Size(m)
+}
+func (m *ContextUpdateRequest) XXX_DiscardUnknown() {
+ xxx_messageInfo_ContextUpdateRequest.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_ContextUpdateRequest proto.InternalMessageInfo
+
+func (m *ContextUpdateRequest) GetAppContext() string {
+ if m != nil {
+ return m.AppContext
+ }
+ return ""
+}
+
+type ContextUpdateResponse struct {
+ AppContextUpdated bool `protobuf:"varint,1,opt,name=app_context_updated,json=appContextUpdated,proto3" json:"app_context_updated,omitempty"`
+ AppContextUpdateMessage string `protobuf:"bytes,2,opt,name=app_context_update_message,json=appContextUpdateMessage,proto3" json:"app_context_update_message,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized []byte `json:"-"`
+ XXX_sizecache int32 `json:"-"`
+}
+
+func (m *ContextUpdateResponse) Reset() { *m = ContextUpdateResponse{} }
+func (m *ContextUpdateResponse) String() string { return proto.CompactTextString(m) }
+func (*ContextUpdateResponse) ProtoMessage() {}
+func (*ContextUpdateResponse) Descriptor() ([]byte, []int) {
+ return fileDescriptor_8ebb57f5310873be, []int{1}
+}
+
+func (m *ContextUpdateResponse) XXX_Unmarshal(b []byte) error {
+ return xxx_messageInfo_ContextUpdateResponse.Unmarshal(m, b)
+}
+func (m *ContextUpdateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+ return xxx_messageInfo_ContextUpdateResponse.Marshal(b, m, deterministic)
+}
+func (m *ContextUpdateResponse) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_ContextUpdateResponse.Merge(m, src)
+}
+func (m *ContextUpdateResponse) XXX_Size() int {
+ return xxx_messageInfo_ContextUpdateResponse.Size(m)
+}
+func (m *ContextUpdateResponse) XXX_DiscardUnknown() {
+ xxx_messageInfo_ContextUpdateResponse.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_ContextUpdateResponse proto.InternalMessageInfo
+
+func (m *ContextUpdateResponse) GetAppContextUpdated() bool {
+ if m != nil {
+ return m.AppContextUpdated
+ }
+ return false
+}
+
+func (m *ContextUpdateResponse) GetAppContextUpdateMessage() string {
+ if m != nil {
+ return m.AppContextUpdateMessage
+ }
+ return ""
+}
+
+func init() {
+ proto.RegisterType((*ContextUpdateRequest)(nil), "ContextUpdateRequest")
+ proto.RegisterType((*ContextUpdateResponse)(nil), "ContextUpdateResponse")
+}
+
+func init() {
+ proto.RegisterFile("contextupdate.proto", fileDescriptor_8ebb57f5310873be)
+}
+
+var fileDescriptor_8ebb57f5310873be = []byte{
+ // 176 bytes of a gzipped FileDescriptorProto
+ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4e, 0xce, 0xcf, 0x2b,
+ 0x49, 0xad, 0x28, 0x29, 0x2d, 0x48, 0x49, 0x2c, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x57,
+ 0x32, 0xe7, 0x12, 0x71, 0x86, 0x08, 0x87, 0x82, 0x85, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b,
+ 0x84, 0xe4, 0xb9, 0xb8, 0x13, 0x0b, 0x0a, 0xe2, 0xa1, 0x5a, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38,
+ 0x83, 0xb8, 0x12, 0x0b, 0x0a, 0xa0, 0xaa, 0x95, 0x5a, 0x18, 0xb9, 0x44, 0xd1, 0x74, 0x16, 0x17,
+ 0xe4, 0xe7, 0x15, 0xa7, 0x0a, 0xe9, 0x71, 0x09, 0x23, 0x69, 0x8d, 0x87, 0x58, 0x97, 0x02, 0x36,
+ 0x82, 0x23, 0x48, 0x10, 0x61, 0x04, 0x44, 0x5b, 0x8a, 0x90, 0x35, 0x97, 0x14, 0xa6, 0xfa, 0xf8,
+ 0xdc, 0xd4, 0xe2, 0xe2, 0xc4, 0xf4, 0x54, 0x09, 0x26, 0xb0, 0xcd, 0xe2, 0xe8, 0xda, 0x7c, 0x21,
+ 0xd2, 0x46, 0x21, 0x5c, 0xbc, 0x28, 0xde, 0x12, 0x72, 0xe6, 0x12, 0x80, 0xa8, 0x70, 0x84, 0xeb,
+ 0x10, 0x12, 0xd5, 0xc3, 0xe6, 0x47, 0x29, 0x31, 0x3d, 0xac, 0x1e, 0x50, 0x62, 0x48, 0x62, 0x03,
+ 0x07, 0x8e, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x75, 0x78, 0xc0, 0x4d, 0x33, 0x01, 0x00, 0x00,
+}
+
+// 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
+
+// ContextupdateClient is the client API for Contextupdate service.
+//
+// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
+type ContextupdateClient interface {
+ // Controllers
+ UpdateAppContext(ctx context.Context, in *ContextUpdateRequest, opts ...grpc.CallOption) (*ContextUpdateResponse, error)
+}
+
+type contextupdateClient struct {
+ cc grpc.ClientConnInterface
+}
+
+func NewContextupdateClient(cc grpc.ClientConnInterface) ContextupdateClient {
+ return &contextupdateClient{cc}
+}
+
+func (c *contextupdateClient) UpdateAppContext(ctx context.Context, in *ContextUpdateRequest, opts ...grpc.CallOption) (*ContextUpdateResponse, error) {
+ out := new(ContextUpdateResponse)
+ err := c.cc.Invoke(ctx, "/contextupdate/UpdateAppContext", in, out, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+// ContextupdateServer is the server API for Contextupdate service.
+type ContextupdateServer interface {
+ // Controllers
+ UpdateAppContext(context.Context, *ContextUpdateRequest) (*ContextUpdateResponse, error)
+}
+
+// UnimplementedContextupdateServer can be embedded to have forward compatible implementations.
+type UnimplementedContextupdateServer struct {
+}
+
+func (*UnimplementedContextupdateServer) UpdateAppContext(ctx context.Context, req *ContextUpdateRequest) (*ContextUpdateResponse, error) {
+ return nil, status.Errorf(codes.Unimplemented, "method UpdateAppContext not implemented")
+}
+
+func RegisterContextupdateServer(s *grpc.Server, srv ContextupdateServer) {
+ s.RegisterService(&_Contextupdate_serviceDesc, srv)
+}
+
+func _Contextupdate_UpdateAppContext_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+ in := new(ContextUpdateRequest)
+ if err := dec(in); err != nil {
+ return nil, err
+ }
+ if interceptor == nil {
+ return srv.(ContextupdateServer).UpdateAppContext(ctx, in)
+ }
+ info := &grpc.UnaryServerInfo{
+ Server: srv,
+ FullMethod: "/contextupdate/UpdateAppContext",
+ }
+ handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ return srv.(ContextupdateServer).UpdateAppContext(ctx, req.(*ContextUpdateRequest))
+ }
+ return interceptor(ctx, in, info, handler)
+}
+
+var _Contextupdate_serviceDesc = grpc.ServiceDesc{
+ ServiceName: "contextupdate",
+ HandlerType: (*ContextupdateServer)(nil),
+ Methods: []grpc.MethodDesc{
+ {
+ MethodName: "UpdateAppContext",
+ Handler: _Contextupdate_UpdateAppContext_Handler,
+ },
+ },
+ Streams: []grpc.StreamDesc{},
+ Metadata: "contextupdate.proto",
+}
diff --git a/src/orchestrator/pkg/grpc/contextupdate/contextupdate.proto b/src/orchestrator/pkg/grpc/contextupdate/contextupdate.proto
new file mode 100644
index 00000000..ac305ba6
--- /dev/null
+++ b/src/orchestrator/pkg/grpc/contextupdate/contextupdate.proto
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2020 Intel Corporation, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+service contextupdate {
+ // Controllers
+ rpc UpdateAppContext(ContextUpdateRequest) returns (ContextUpdateResponse) {
+ }
+}
+
+message ContextUpdateRequest {
+ string app_context = 1;
+}
+
+message ContextUpdateResponse {
+ bool app_context_updated = 1;
+ string app_context_update_message = 2;
+}
diff --git a/src/orchestrator/pkg/grpc/installapp/installapp.pb.go b/src/orchestrator/pkg/grpc/installapp/installapp.pb.go
new file mode 100644
index 00000000..edb25b16
--- /dev/null
+++ b/src/orchestrator/pkg/grpc/installapp/installapp.pb.go
@@ -0,0 +1,346 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// source: installapp.proto
+
+package installapp
+
+import (
+ context "context"
+ fmt "fmt"
+ proto "github.com/golang/protobuf/proto"
+ grpc "google.golang.org/grpc"
+ codes "google.golang.org/grpc/codes"
+ status "google.golang.org/grpc/status"
+ math "math"
+)
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ = proto.Marshal
+var _ = fmt.Errorf
+var _ = math.Inf
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the proto package it is being compiled against.
+// A compilation error at this line likely means your copy of the
+// proto package needs to be updated.
+const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
+
+type InstallAppRequest struct {
+ AppContext string `protobuf:"bytes,1,opt,name=app_context,json=appContext,proto3" json:"app_context,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized []byte `json:"-"`
+ XXX_sizecache int32 `json:"-"`
+}
+
+func (m *InstallAppRequest) Reset() { *m = InstallAppRequest{} }
+func (m *InstallAppRequest) String() string { return proto.CompactTextString(m) }
+func (*InstallAppRequest) ProtoMessage() {}
+func (*InstallAppRequest) Descriptor() ([]byte, []int) {
+ return fileDescriptor_e16b1077a28418a8, []int{0}
+}
+
+func (m *InstallAppRequest) XXX_Unmarshal(b []byte) error {
+ return xxx_messageInfo_InstallAppRequest.Unmarshal(m, b)
+}
+func (m *InstallAppRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+ return xxx_messageInfo_InstallAppRequest.Marshal(b, m, deterministic)
+}
+func (m *InstallAppRequest) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_InstallAppRequest.Merge(m, src)
+}
+func (m *InstallAppRequest) XXX_Size() int {
+ return xxx_messageInfo_InstallAppRequest.Size(m)
+}
+func (m *InstallAppRequest) XXX_DiscardUnknown() {
+ xxx_messageInfo_InstallAppRequest.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_InstallAppRequest proto.InternalMessageInfo
+
+func (m *InstallAppRequest) GetAppContext() string {
+ if m != nil {
+ return m.AppContext
+ }
+ return ""
+}
+
+type InstallAppResponse struct {
+ AppContextInstalled bool `protobuf:"varint,1,opt,name=app_context_installed,json=appContextInstalled,proto3" json:"app_context_installed,omitempty"`
+ AppContextInstallMessage string `protobuf:"bytes,2,opt,name=app_context_install_message,json=appContextInstallMessage,proto3" json:"app_context_install_message,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized []byte `json:"-"`
+ XXX_sizecache int32 `json:"-"`
+}
+
+func (m *InstallAppResponse) Reset() { *m = InstallAppResponse{} }
+func (m *InstallAppResponse) String() string { return proto.CompactTextString(m) }
+func (*InstallAppResponse) ProtoMessage() {}
+func (*InstallAppResponse) Descriptor() ([]byte, []int) {
+ return fileDescriptor_e16b1077a28418a8, []int{1}
+}
+
+func (m *InstallAppResponse) XXX_Unmarshal(b []byte) error {
+ return xxx_messageInfo_InstallAppResponse.Unmarshal(m, b)
+}
+func (m *InstallAppResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+ return xxx_messageInfo_InstallAppResponse.Marshal(b, m, deterministic)
+}
+func (m *InstallAppResponse) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_InstallAppResponse.Merge(m, src)
+}
+func (m *InstallAppResponse) XXX_Size() int {
+ return xxx_messageInfo_InstallAppResponse.Size(m)
+}
+func (m *InstallAppResponse) XXX_DiscardUnknown() {
+ xxx_messageInfo_InstallAppResponse.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_InstallAppResponse proto.InternalMessageInfo
+
+func (m *InstallAppResponse) GetAppContextInstalled() bool {
+ if m != nil {
+ return m.AppContextInstalled
+ }
+ return false
+}
+
+func (m *InstallAppResponse) GetAppContextInstallMessage() string {
+ if m != nil {
+ return m.AppContextInstallMessage
+ }
+ return ""
+}
+
+type UninstallAppRequest struct {
+ AppContext string `protobuf:"bytes,1,opt,name=app_context,json=appContext,proto3" json:"app_context,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized []byte `json:"-"`
+ XXX_sizecache int32 `json:"-"`
+}
+
+func (m *UninstallAppRequest) Reset() { *m = UninstallAppRequest{} }
+func (m *UninstallAppRequest) String() string { return proto.CompactTextString(m) }
+func (*UninstallAppRequest) ProtoMessage() {}
+func (*UninstallAppRequest) Descriptor() ([]byte, []int) {
+ return fileDescriptor_e16b1077a28418a8, []int{2}
+}
+
+func (m *UninstallAppRequest) XXX_Unmarshal(b []byte) error {
+ return xxx_messageInfo_UninstallAppRequest.Unmarshal(m, b)
+}
+func (m *UninstallAppRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+ return xxx_messageInfo_UninstallAppRequest.Marshal(b, m, deterministic)
+}
+func (m *UninstallAppRequest) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_UninstallAppRequest.Merge(m, src)
+}
+func (m *UninstallAppRequest) XXX_Size() int {
+ return xxx_messageInfo_UninstallAppRequest.Size(m)
+}
+func (m *UninstallAppRequest) XXX_DiscardUnknown() {
+ xxx_messageInfo_UninstallAppRequest.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_UninstallAppRequest proto.InternalMessageInfo
+
+func (m *UninstallAppRequest) GetAppContext() string {
+ if m != nil {
+ return m.AppContext
+ }
+ return ""
+}
+
+type UninstallAppResponse struct {
+ AppContextUninstalled bool `protobuf:"varint,1,opt,name=app_context_uninstalled,json=appContextUninstalled,proto3" json:"app_context_uninstalled,omitempty"`
+ AppContextUninstallMessage string `protobuf:"bytes,2,opt,name=app_context_uninstall_message,json=appContextUninstallMessage,proto3" json:"app_context_uninstall_message,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized []byte `json:"-"`
+ XXX_sizecache int32 `json:"-"`
+}
+
+func (m *UninstallAppResponse) Reset() { *m = UninstallAppResponse{} }
+func (m *UninstallAppResponse) String() string { return proto.CompactTextString(m) }
+func (*UninstallAppResponse) ProtoMessage() {}
+func (*UninstallAppResponse) Descriptor() ([]byte, []int) {
+ return fileDescriptor_e16b1077a28418a8, []int{3}
+}
+
+func (m *UninstallAppResponse) XXX_Unmarshal(b []byte) error {
+ return xxx_messageInfo_UninstallAppResponse.Unmarshal(m, b)
+}
+func (m *UninstallAppResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+ return xxx_messageInfo_UninstallAppResponse.Marshal(b, m, deterministic)
+}
+func (m *UninstallAppResponse) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_UninstallAppResponse.Merge(m, src)
+}
+func (m *UninstallAppResponse) XXX_Size() int {
+ return xxx_messageInfo_UninstallAppResponse.Size(m)
+}
+func (m *UninstallAppResponse) XXX_DiscardUnknown() {
+ xxx_messageInfo_UninstallAppResponse.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_UninstallAppResponse proto.InternalMessageInfo
+
+func (m *UninstallAppResponse) GetAppContextUninstalled() bool {
+ if m != nil {
+ return m.AppContextUninstalled
+ }
+ return false
+}
+
+func (m *UninstallAppResponse) GetAppContextUninstallMessage() string {
+ if m != nil {
+ return m.AppContextUninstallMessage
+ }
+ return ""
+}
+
+func init() {
+ proto.RegisterType((*InstallAppRequest)(nil), "InstallAppRequest")
+ proto.RegisterType((*InstallAppResponse)(nil), "InstallAppResponse")
+ proto.RegisterType((*UninstallAppRequest)(nil), "UninstallAppRequest")
+ proto.RegisterType((*UninstallAppResponse)(nil), "UninstallAppResponse")
+}
+
+func init() {
+ proto.RegisterFile("installapp.proto", fileDescriptor_e16b1077a28418a8)
+}
+
+var fileDescriptor_e16b1077a28418a8 = []byte{
+ // 246 bytes of a gzipped FileDescriptorProto
+ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xc8, 0xcc, 0x2b, 0x2e,
+ 0x49, 0xcc, 0xc9, 0x49, 0x2c, 0x28, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x57, 0x32, 0xe1, 0x12,
+ 0xf4, 0x84, 0x88, 0x39, 0x16, 0x14, 0x04, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x08, 0xc9, 0x73,
+ 0x71, 0x27, 0x16, 0x14, 0xc4, 0x27, 0xe7, 0xe7, 0x95, 0xa4, 0x56, 0x94, 0x48, 0x30, 0x2a, 0x30,
+ 0x6a, 0x70, 0x06, 0x71, 0x25, 0x16, 0x14, 0x38, 0x43, 0x44, 0x94, 0xda, 0x19, 0xb9, 0x84, 0x90,
+ 0xb5, 0x15, 0x17, 0xe4, 0xe7, 0x15, 0xa7, 0x0a, 0x19, 0x71, 0x89, 0x22, 0xe9, 0x8b, 0x87, 0x5a,
+ 0x96, 0x9a, 0x02, 0x36, 0x81, 0x23, 0x48, 0x18, 0x61, 0x82, 0x27, 0x4c, 0x4a, 0xc8, 0x96, 0x4b,
+ 0x1a, 0x8b, 0x9e, 0xf8, 0xdc, 0xd4, 0xe2, 0xe2, 0xc4, 0xf4, 0x54, 0x09, 0x26, 0xb0, 0xdd, 0x12,
+ 0x18, 0x3a, 0x7d, 0x21, 0xf2, 0x4a, 0x66, 0x5c, 0xc2, 0xa1, 0x79, 0x99, 0xa4, 0xfb, 0x60, 0x22,
+ 0x23, 0x97, 0x08, 0xaa, 0x46, 0xa8, 0x1f, 0xcc, 0xb8, 0xc4, 0x91, 0xdd, 0x53, 0x9a, 0x87, 0xee,
+ 0x0b, 0x51, 0x84, 0x29, 0xa1, 0x08, 0x49, 0x21, 0x47, 0x2e, 0x59, 0xac, 0xfa, 0xd0, 0x7c, 0x22,
+ 0x85, 0x45, 0x37, 0xd4, 0x2f, 0x46, 0x2d, 0x8c, 0x5c, 0x5c, 0x88, 0x08, 0x12, 0x32, 0xe7, 0xe2,
+ 0x42, 0x84, 0xb1, 0x90, 0x90, 0x1e, 0x46, 0x3c, 0x49, 0x09, 0xeb, 0x61, 0x46, 0x82, 0x12, 0x83,
+ 0x90, 0x2d, 0x17, 0x0f, 0xb2, 0xd7, 0x84, 0x44, 0xf4, 0xb0, 0x04, 0x91, 0x94, 0xa8, 0x1e, 0x36,
+ 0xff, 0x2b, 0x31, 0x24, 0xb1, 0x81, 0x53, 0x86, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x1a, 0x14,
+ 0x31, 0x29, 0x2d, 0x02, 0x00, 0x00,
+}
+
+// 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
+
+// InstallappClient is the client API for Installapp service.
+//
+// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
+type InstallappClient interface {
+ // Sync
+ InstallApp(ctx context.Context, in *InstallAppRequest, opts ...grpc.CallOption) (*InstallAppResponse, error)
+ UninstallApp(ctx context.Context, in *UninstallAppRequest, opts ...grpc.CallOption) (*UninstallAppResponse, error)
+}
+
+type installappClient struct {
+ cc grpc.ClientConnInterface
+}
+
+func NewInstallappClient(cc grpc.ClientConnInterface) InstallappClient {
+ return &installappClient{cc}
+}
+
+func (c *installappClient) InstallApp(ctx context.Context, in *InstallAppRequest, opts ...grpc.CallOption) (*InstallAppResponse, error) {
+ out := new(InstallAppResponse)
+ err := c.cc.Invoke(ctx, "/installapp/InstallApp", in, out, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+func (c *installappClient) UninstallApp(ctx context.Context, in *UninstallAppRequest, opts ...grpc.CallOption) (*UninstallAppResponse, error) {
+ out := new(UninstallAppResponse)
+ err := c.cc.Invoke(ctx, "/installapp/UninstallApp", in, out, opts...)
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+// InstallappServer is the server API for Installapp service.
+type InstallappServer interface {
+ // Sync
+ InstallApp(context.Context, *InstallAppRequest) (*InstallAppResponse, error)
+ UninstallApp(context.Context, *UninstallAppRequest) (*UninstallAppResponse, error)
+}
+
+// UnimplementedInstallappServer can be embedded to have forward compatible implementations.
+type UnimplementedInstallappServer struct {
+}
+
+func (*UnimplementedInstallappServer) InstallApp(ctx context.Context, req *InstallAppRequest) (*InstallAppResponse, error) {
+ return nil, status.Errorf(codes.Unimplemented, "method InstallApp not implemented")
+}
+func (*UnimplementedInstallappServer) UninstallApp(ctx context.Context, req *UninstallAppRequest) (*UninstallAppResponse, error) {
+ return nil, status.Errorf(codes.Unimplemented, "method UninstallApp not implemented")
+}
+
+func RegisterInstallappServer(s *grpc.Server, srv InstallappServer) {
+ s.RegisterService(&_Installapp_serviceDesc, srv)
+}
+
+func _Installapp_InstallApp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+ in := new(InstallAppRequest)
+ if err := dec(in); err != nil {
+ return nil, err
+ }
+ if interceptor == nil {
+ return srv.(InstallappServer).InstallApp(ctx, in)
+ }
+ info := &grpc.UnaryServerInfo{
+ Server: srv,
+ FullMethod: "/installapp/InstallApp",
+ }
+ handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ return srv.(InstallappServer).InstallApp(ctx, req.(*InstallAppRequest))
+ }
+ return interceptor(ctx, in, info, handler)
+}
+
+func _Installapp_UninstallApp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+ in := new(UninstallAppRequest)
+ if err := dec(in); err != nil {
+ return nil, err
+ }
+ if interceptor == nil {
+ return srv.(InstallappServer).UninstallApp(ctx, in)
+ }
+ info := &grpc.UnaryServerInfo{
+ Server: srv,
+ FullMethod: "/installapp/UninstallApp",
+ }
+ handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+ return srv.(InstallappServer).UninstallApp(ctx, req.(*UninstallAppRequest))
+ }
+ return interceptor(ctx, in, info, handler)
+}
+
+var _Installapp_serviceDesc = grpc.ServiceDesc{
+ ServiceName: "installapp",
+ HandlerType: (*InstallappServer)(nil),
+ Methods: []grpc.MethodDesc{
+ {
+ MethodName: "InstallApp",
+ Handler: _Installapp_InstallApp_Handler,
+ },
+ {
+ MethodName: "UninstallApp",
+ Handler: _Installapp_UninstallApp_Handler,
+ },
+ },
+ Streams: []grpc.StreamDesc{},
+ Metadata: "installapp.proto",
+}
diff --git a/src/orchestrator/pkg/grpc/installapp/installapp.proto b/src/orchestrator/pkg/grpc/installapp/installapp.proto
new file mode 100644
index 00000000..cd213567
--- /dev/null
+++ b/src/orchestrator/pkg/grpc/installapp/installapp.proto
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2020 Intel Corporation, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+service installapp {
+ // Sync
+ rpc InstallApp(InstallAppRequest) returns (InstallAppResponse) {
+ }
+
+ rpc UninstallApp(UninstallAppRequest) returns (UninstallAppResponse) {
+ }
+}
+
+message InstallAppRequest {
+ string app_context = 1;
+}
+
+message InstallAppResponse {
+ bool app_context_installed = 1;
+ string app_context_install_message = 2;
+}
+
+message UninstallAppRequest {
+ string app_context = 1;
+}
+
+message UninstallAppResponse {
+ bool app_context_uninstalled = 1;
+ string app_context_uninstall_message = 2;
+}
+
diff --git a/src/orchestrator/pkg/infra/config/config.go b/src/orchestrator/pkg/infra/config/config.go
index df9cec92..fca8bfbd 100644
--- a/src/orchestrator/pkg/infra/config/config.go
+++ b/src/orchestrator/pkg/infra/config/config.go
@@ -26,19 +26,24 @@ import (
// Configuration loads up all the values that are used to configure
// backend implementations
type Configuration struct {
- CAFile string `json:"ca-file"`
- ServerCert string `json:"server-cert"`
- ServerKey string `json:"server-key"`
- Password string `json:"password"`
- DatabaseIP string `json:"database-ip"`
- DatabaseType string `json:"database-type"`
- PluginDir string `json:"plugin-dir"`
- EtcdIP string `json:"etcd-ip"`
- EtcdCert string `json:"etcd-cert"`
- EtcdKey string `json:"etcd-key"`
- EtcdCAFile string `json:"etcd-ca-file"`
- ServicePort string `json:"service-port"`
- KubernetesLabelName string `json:"kubernetes-label-name"`
+ CAFile string `json:"ca-file"`
+ ServerCert string `json:"server-cert"`
+ ServerKey string `json:"server-key"`
+ Password string `json:"password"`
+ DatabaseIP string `json:"database-ip"`
+ DatabaseType string `json:"database-type"`
+ PluginDir string `json:"plugin-dir"`
+ EtcdIP string `json:"etcd-ip"`
+ EtcdCert string `json:"etcd-cert"`
+ EtcdKey string `json:"etcd-key"`
+ EtcdCAFile string `json:"etcd-ca-file"`
+ GrpcServerCert string `json:"grpc-server-cert"`
+ GrpcServerKey string `json:"grpc-server-key"`
+ GrpcCAFile string `json:"grpc-ca-file"`
+ GrpcEnableTLS string `json:"grpc-enable-tls"`
+ GrpcServerNameOverride string `json:"grpc-server-name-override"`
+ ServicePort string `json:"service-port"`
+ KubernetesLabelName string `json:"kubernetes-label-name"`
}
// Config is the structure that stores the configuration
@@ -75,19 +80,24 @@ func defaultConfiguration() *Configuration {
}
return &Configuration{
- CAFile: "ca.cert",
- ServerCert: "server.cert",
- ServerKey: "server.key",
- Password: "",
- DatabaseIP: "127.0.0.1",
- DatabaseType: "mongo",
- PluginDir: cwd,
- EtcdIP: "127.0.0.1",
- EtcdCert: "",
- EtcdKey: "",
- EtcdCAFile: "",
- ServicePort: "9015",
- KubernetesLabelName: "orchestrator.io/rb-instance-id",
+ CAFile: "ca.cert",
+ ServerCert: "server.cert",
+ ServerKey: "server.key",
+ Password: "",
+ DatabaseIP: "127.0.0.1",
+ DatabaseType: "mongo",
+ PluginDir: cwd,
+ EtcdIP: "127.0.0.1",
+ EtcdCert: "",
+ EtcdKey: "",
+ EtcdCAFile: "",
+ GrpcServerCert: "",
+ GrpcServerKey: "",
+ GrpcCAFile: "",
+ GrpcEnableTLS: "disable",
+ GrpcServerNameOverride: "",
+ ServicePort: "9015",
+ KubernetesLabelName: "orchestrator.io/rb-instance-id",
}
}
diff --git a/src/orchestrator/pkg/infra/rpc/rpc.go b/src/orchestrator/pkg/infra/rpc/rpc.go
new file mode 100755
index 00000000..a9c97bff
--- /dev/null
+++ b/src/orchestrator/pkg/infra/rpc/rpc.go
@@ -0,0 +1,199 @@
+/*
+Copyright 2020 Intel Corporation.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package rpc
+
+import (
+ "context"
+ "strconv"
+ "strings"
+ "sync"
+ "time"
+
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/config"
+ log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
+ pkgerrors "github.com/pkg/errors"
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/connectivity"
+ "google.golang.org/grpc/credentials"
+ "google.golang.org/grpc/testdata"
+)
+
+type ContextUpdateRequest interface {
+}
+
+type ContextUpdateResponse interface {
+}
+
+type InstallAppRequest interface {
+}
+
+type InstallAppResponse interface {
+}
+
+type rpcInfo struct {
+ conn *grpc.ClientConn
+ host string
+ port int
+}
+
+var mutex = &sync.Mutex{}
+var rpcConnections = make(map[string]rpcInfo)
+
+// GetRpcConn is used by RPC client code which needs the connection for a
+// given controller for doing RPC calls with that controller.
+func GetRpcConn(name string) *grpc.ClientConn {
+ mutex.Lock()
+ defer mutex.Unlock()
+ if val, ok := rpcConnections[name]; ok {
+ if val.conn.GetState() == connectivity.TransientFailure {
+ val.conn.ResetConnectBackoff()
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
+ if !val.conn.WaitForStateChange(ctx, connectivity.TransientFailure) {
+ log.Warn("Error re-establishing RPC connection", log.Fields{
+ "Server": name,
+ "Host": val.host,
+ "Port": val.port,
+ })
+ }
+ cancel()
+ }
+ return val.conn
+ }
+ return nil
+}
+
+func UpdateRpcConn(name, host string, port int) {
+ mutex.Lock()
+ defer mutex.Unlock()
+ if val, ok := rpcConnections[name]; ok {
+ // close connection if mismatch in update vs cached connect info
+ if val.host != host || val.port != port {
+ log.Info("Closing RPC connection due to mismatch", log.Fields{
+ "Server": name,
+ "Old Host": val.host,
+ "Old Port": val.port,
+ "New Host": host,
+ "New Port": port,
+ })
+ err := val.conn.Close()
+ if err != nil {
+ log.Warn("Error closing RPC connection", log.Fields{
+ "Server": name,
+ "Host": val.host,
+ "Port": val.port,
+ "Error": err,
+ })
+ }
+ } else {
+ if val.conn.GetState() == connectivity.TransientFailure {
+ val.conn.ResetConnectBackoff()
+ }
+ return
+ }
+ }
+ // connect and update rpcConnection list - for new or modified connection
+ conn, err := createClientConn(host, port)
+ if err != nil {
+ log.Warn("Failed to create RPC Client connection", log.Fields{
+ "Error": err,
+ })
+ delete(rpcConnections, name)
+ } else {
+ log.Info("Added RPC Client connection", log.Fields{
+ "Controller": name,
+ })
+ rpcConnections[name] = rpcInfo{
+ conn: conn,
+ host: host,
+ port: port,
+ }
+ }
+}
+
+// CloseAllRpcConn closes all connections
+func CloseAllRpcConn() {
+ mutex.Lock()
+ for k, v := range rpcConnections {
+ err := v.conn.Close()
+ if err != nil {
+ log.Warn("Error closing RPC connection", log.Fields{
+ "Server": k,
+ "Host": v.host,
+ "Port": v.port,
+ "Error": err,
+ })
+ }
+ }
+ mutex.Unlock()
+}
+
+// RemoveRpcConn closes the connection and removes from map
+func RemoveRpcConn(name string) {
+ mutex.Lock()
+ if val, ok := rpcConnections[name]; ok {
+ err := val.conn.Close()
+ if err != nil {
+ log.Warn("Error closing RPC connection", log.Fields{
+ "Server": name,
+ "Host": val.host,
+ "Port": val.port,
+ "Error": err,
+ })
+ }
+ delete(rpcConnections, name)
+ }
+ mutex.Unlock()
+}
+
+// createConn creates the Rpc Client Connection
+func createClientConn(Host string, Port int) (*grpc.ClientConn, error) {
+ var err error
+ var tls bool
+ var opts []grpc.DialOption
+
+ serverAddr := Host + ":" + strconv.Itoa(Port)
+ serverNameOverride := config.GetConfiguration().GrpcServerNameOverride
+
+ if strings.Contains(config.GetConfiguration().GrpcEnableTLS, "enable") {
+ tls = true
+ } else {
+ tls = false
+ }
+
+ caFile := config.GetConfiguration().GrpcCAFile
+
+ if tls {
+ if caFile == "" {
+ caFile = testdata.Path("ca.pem")
+ }
+ creds, err := credentials.NewClientTLSFromFile(caFile, serverNameOverride)
+ if err != nil {
+ log.Error("Failed to create TLS credentials", log.Fields{
+ "Error": err,
+ "Host": Host,
+ "Port": Port,
+ })
+ }
+ opts = append(opts, grpc.WithTransportCredentials(creds))
+ } else {
+ opts = append(opts, grpc.WithInsecure())
+ }
+
+ conn, err := grpc.Dial(serverAddr, opts...)
+ if err != nil {
+ pkgerrors.Wrap(err, "Grpc Client Initialization failed with error")
+ }
+
+ return conn, err
+}
diff --git a/src/orchestrator/pkg/module/controller.go b/src/orchestrator/pkg/module/controller.go
index 976b8988..6827af87 100644
--- a/src/orchestrator/pkg/module/controller.go
+++ b/src/orchestrator/pkg/module/controller.go
@@ -20,7 +20,8 @@ import (
"encoding/json"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
-
+ log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
+ rpc "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/rpc"
pkgerrors "github.com/pkg/errors"
)
@@ -66,6 +67,7 @@ type ControllerManager interface {
CreateController(ms Controller, mayExist bool) (Controller, error)
GetController(name string) (Controller, error)
GetControllers() ([]Controller, error)
+ InitControllers()
DeleteController(name string) error
}
@@ -104,6 +106,9 @@ func (mc *ControllerClient) CreateController(m Controller, mayExist bool) (Contr
return Controller{}, pkgerrors.Wrap(err, "Creating DB Entry")
}
+ // send message to create/update the rpc connection
+ rpc.UpdateRpcConn(m.Metadata.Name, m.Spec.Host, m.Spec.Port)
+
return m, nil
}
@@ -152,15 +157,6 @@ func (mc *ControllerClient) GetControllers() ([]Controller, error) {
return []Controller{}, pkgerrors.Wrap(err, "Unmarshaling Value")
}
- // run healthcheck
- /*
- err = mc.HealthCheck(microserv.Name)
- if err != nil {
- log.Warn("HealthCheck Failed", log.Fields{
- "Controller": microserv.Name,
- })
- }
- */
resp = append(resp, microserv)
}
@@ -178,5 +174,20 @@ func (mc *ControllerClient) DeleteController(name string) error {
if err != nil {
return pkgerrors.Wrap(err, "Delete Controller Entry;")
}
+
+ // send message to close rpc connection
+ rpc.RemoveRpcConn(name)
+
return nil
}
+
+// InitControllers initializes connctions for controllers in the DB
+func (mc *ControllerClient) InitControllers() {
+ vals, _ := mc.GetControllers()
+ for _, v := range vals {
+ log.Info("Initializing RPC connection for controller", log.Fields{
+ "Controller": v.Metadata.Name,
+ })
+ rpc.UpdateRpcConn(v.Metadata.Name, v.Spec.Host, v.Spec.Port)
+ }
+}