diff options
Diffstat (limited to 'src/ncm/pkg')
-rw-r--r-- | src/ncm/pkg/grpc/rsyncclient.go | 41 | ||||
-rw-r--r-- | src/ncm/pkg/module/cluster.go | 89 | ||||
-rw-r--r-- | src/ncm/pkg/module/module_definitions.go | 2 | ||||
-rw-r--r-- | src/ncm/pkg/module/network.go | 10 | ||||
-rw-r--r-- | src/ncm/pkg/module/providernet.go | 6 |
5 files changed, 127 insertions, 21 deletions
diff --git a/src/ncm/pkg/grpc/rsyncclient.go b/src/ncm/pkg/grpc/rsyncclient.go new file mode 100644 index 00000000..5eb870a7 --- /dev/null +++ b/src/ncm/pkg/grpc/rsyncclient.go @@ -0,0 +1,41 @@ +/* +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 grpc + +import ( + log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/rpc" + controller "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller" +) + +const RsyncName = "rsync" + +// InitRsyncClient initializes connctions to the Resource Synchronizer serivice +func InitRsyncClient() bool { + client := controller.NewControllerClient() + + vals, _ := client.GetControllers() + found := false + for _, v := range vals { + if v.Metadata.Name == RsyncName { + log.Info("Initializing RPC connection to resource synchronizer", log.Fields{ + "Controller": v.Metadata.Name, + }) + rpc.UpdateRpcConn(v.Metadata.Name, v.Spec.Host, v.Spec.Port) + found = true + break + } + } + return found +} diff --git a/src/ncm/pkg/module/cluster.go b/src/ncm/pkg/module/cluster.go index 2397a091..5d1f577f 100644 --- a/src/ncm/pkg/module/cluster.go +++ b/src/ncm/pkg/module/cluster.go @@ -17,9 +17,16 @@ package module import ( - "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext" + "context" + "encoding/json" + "time" + + "github.com/onap/multicloud-k8s/src/ncm/pkg/grpc" + appcontext "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext" "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db" log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/rpc" + installpb "github.com/onap/multicloud-k8s/src/rsync/pkg/grpc/installapp" "gopkg.in/yaml.v2" pkgerrors "github.com/pkg/errors" @@ -474,20 +481,20 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error { } // Make an app context for the network intent resources - context := appcontext.AppContext{} - ctxVal, err := context.InitAppContext() + ac := appcontext.AppContext{} + ctxVal, err := ac.InitAppContext() if err != nil { return pkgerrors.Wrap(err, "Error creating AppContext") } - handle, err := context.CreateCompositeApp() + handle, err := ac.CreateCompositeApp() if err != nil { return pkgerrors.Wrap(err, "Error creating AppContext CompositeApp") } // Add an app (fixed value) to the app context - apphandle, err := context.AddApp(handle, CONTEXT_CLUSTER_APP) + apphandle, err := ac.AddApp(handle, CONTEXT_CLUSTER_APP) if err != nil { - cleanuperr := context.DeleteCompositeApp() + cleanuperr := ac.DeleteCompositeApp() if cleanuperr != nil { log.Warn("Error cleaning AppContext CompositeApp create failure", log.Fields{ "cluster-provider": provider, @@ -497,10 +504,28 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error { return pkgerrors.Wrap(err, "Error adding App to AppContext") } + // Add an app order instruction + appinstr := struct { + Apporder []string `json:"apporder"` + }{ + []string{CONTEXT_CLUSTER_APP}, + } + jinstr, _ := json.Marshal(appinstr) + + appdepinstr := struct { + Appdep map[string]string `json:"appdependency"` + }{ + map[string]string{CONTEXT_CLUSTER_APP: "go"}, + } + jdep, _ := json.Marshal(appdepinstr) + + _, err = ac.AddInstruction(handle, "app", "order", string(jinstr)) + _, err = ac.AddInstruction(handle, "app", "dependency", string(jdep)) + // Add a cluster to the app - clusterhandle, err := context.AddCluster(apphandle, provider+SEPARATOR+name) + clusterhandle, err := ac.AddCluster(apphandle, provider+SEPARATOR+name) if err != nil { - cleanuperr := context.DeleteCompositeApp() + cleanuperr := ac.DeleteCompositeApp() if cleanuperr != nil { log.Warn("Error cleaning AppContext after add cluster failure", log.Fields{ "cluster-provider": provider, @@ -511,10 +536,20 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error { } // add the resources to the app context + + var orderinstr struct { + Resorder []string `json:"resorder"` + } + var depinstr struct { + Resdep map[string]string `json:"resdependency"` + } + resdep := make(map[string]string) for _, resource := range resources { - _, err = context.AddResource(clusterhandle, resource.name, resource.value) + orderinstr.Resorder = append(orderinstr.Resorder, resource.name) + resdep[resource.name] = "go" + _, err = ac.AddResource(clusterhandle, resource.name, resource.value) if err != nil { - cleanuperr := context.DeleteCompositeApp() + cleanuperr := ac.DeleteCompositeApp() if cleanuperr != nil { log.Warn("Error cleaning AppContext after add resource failure", log.Fields{ "cluster-provider": provider, @@ -525,6 +560,11 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error { return pkgerrors.Wrap(err, "Error adding Resource to AppContext") } } + jresord, _ := json.Marshal(orderinstr) + depinstr.Resdep = resdep + jresdep, _ := json.Marshal(depinstr) + _, err = ac.AddInstruction(clusterhandle, "resource", "order", string(jresord)) + _, err = ac.AddInstruction(clusterhandle, "resource", "dependency", string(jresdep)) // save the context in the cluster db record key := ClusterKey{ @@ -533,7 +573,7 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error { } err = db.DBconn.Insert(v.db.storeName, key, nil, v.db.tagContext, ctxVal) if err != nil { - cleanuperr := context.DeleteCompositeApp() + cleanuperr := ac.DeleteCompositeApp() if cleanuperr != nil { log.Warn("Error cleaning AppContext after DB insert failure", log.Fields{ "cluster-provider": provider, @@ -543,7 +583,32 @@ func (v *ClusterClient) ApplyNetworkIntents(provider, name string) error { return pkgerrors.Wrap(err, "Error adding AppContext to DB") } - // TODO: call resource synchronizer to instantiate the CRs in the cluster + // call resource synchronizer to instantiate the CRs in the cluster + conn := rpc.GetRpcConn(grpc.RsyncName) + if conn == nil { + grpc.InitRsyncClient() + conn = rpc.GetRpcConn(grpc.RsyncName) + } + + var rpcClient installpb.InstallappClient + var installRes *installpb.InstallAppResponse + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + if conn != nil { + rpcClient = installpb.NewInstallappClient(conn) + installReq := new(installpb.InstallAppRequest) + installReq.AppContext = ctxVal.(string) + installRes, err = rpcClient.InstallApp(ctx, installReq) + if err == nil { + log.Info("Response from InstappApp GRPC call", log.Fields{ + "Succeeded": installRes.AppContextInstalled, + "Message": installRes.AppContextInstallMessage, + }) + } + } else { + return pkgerrors.Errorf("InstallApp Failed - Could not get InstallAppClient: %v", grpc.RsyncName) + } return nil } diff --git a/src/ncm/pkg/module/module_definitions.go b/src/ncm/pkg/module/module_definitions.go index 36c865a5..8d4b3ad7 100644 --- a/src/ncm/pkg/module/module_definitions.go +++ b/src/ncm/pkg/module/module_definitions.go @@ -65,7 +65,7 @@ const VLAN_NODE_SPECIFIC = "specific" var VLAN_NODE_SELECTORS = [...]string{VLAN_NODE_ANY, VLAN_NODE_SPECIFIC} type Vlan struct { - VlanId int `json:"vlanID" yaml:"vlanId"` + VlanId string `json:"vlanID" yaml:"vlanId"` ProviderInterfaceName string `json:"providerInterfaceName" yaml:"providerInterfaceName"` LogicalInterfaceName string `json:"logicalInterfaceName" yaml:"logicalInterfaceName"` VlanNodeSelector string `json:"vlanNodeSelector" yaml:"vlanNodeSelector"` diff --git a/src/ncm/pkg/module/network.go b/src/ncm/pkg/module/network.go index cfb414c5..e753905e 100644 --- a/src/ncm/pkg/module/network.go +++ b/src/ncm/pkg/module/network.go @@ -29,8 +29,8 @@ type Network struct { } type NetworkSpec struct { - CniType string `json:"cniType"` - Ipv4Subnets []Ipv4Subnet `json:"ipv4Subnets"` + CniType string `json:"cniType" yaml:"cniType"` + Ipv4Subnets []Ipv4Subnet `json:"ipv4Subnets" yaml:"ipv4Subnets"` } // NetworkKey is the key structure that is used in the database @@ -42,9 +42,9 @@ type NetworkKey struct { // structure for the Network Custom Resource type CrNetwork struct { - ApiVersion string `yaml:"apiVersion"` - Kind string `yaml:"kind"` - Network Network + ApiVersion string `yaml:"apiVersion"` + Kind string `yaml:"kind"` + Network Network `yaml:",inline"` } const NETWORK_APIVERSION = "k8s.plugin.opnfv.org/v1alpha1" diff --git a/src/ncm/pkg/module/providernet.go b/src/ncm/pkg/module/providernet.go index 0435f2ba..a1cbe940 100644 --- a/src/ncm/pkg/module/providernet.go +++ b/src/ncm/pkg/module/providernet.go @@ -37,9 +37,9 @@ type ProviderNetSpec struct { // structure for the Network Custom Resource type CrProviderNet struct { - ApiVersion string `yaml:"apiVersion"` - Kind string `yaml:"kind"` - ProviderNet ProviderNet + ApiVersion string `yaml:"apiVersion"` + Kind string `yaml:"kind"` + ProviderNet ProviderNet `yaml:",inline"` } const PROVIDER_NETWORK_APIVERSION = "k8s.plugin.opnfv.org/v1alpha1" |