Bug fixes 57/3457/1
authoragrawalgaurav <gaurav.agrawal@huawei.com>
Thu, 14 May 2020 21:26:13 +0000 (02:56 +0530)
committeragrawalgaurav <gaurav.agrawal@huawei.com>
Thu, 14 May 2020 21:26:13 +0000 (02:56 +0530)
Change-Id: If4b2675e14a33901862b54a55c0950a7275aa62d

mecm/mepm/applcm/broker/pkg/handlers/adapter/dbAdapter/dbAdapter.go
mecm/mepm/applcm/broker/pkg/handlers/adapter/pluginAdapter/pluginAdapter.go
mecm/mepm/applcm/broker/pkg/handlers/handlers.go
mecm/mepm/applcm/broker/pkg/handlers/handlersImpl.go
mecm/mepm/applcm/broker/pkg/plugin/grpcclient.go
mecm/mepm/applcm/broker/pkg/util/logger.go
mecm/mepm/applcm/k8shelm/pkg/plugin/grpcserver.go
mecm/mepm/applcm/k8shelm/pkg/plugin/helmclient.go
mecm/mepm/applcm/k8shelm/pkg/plugin/logger.go
mecm/mepm/applcm/resources/Build-Run.sh

index 8af5e51..d2d8ab7 100644 (file)
@@ -37,7 +37,7 @@ func NewDbAdapter(logger *logrus.Logger) *DbAdapter {
 
 // Creates database
 func (adapter *DbAdapter) CreateDatabase() {
-       adapter.logger.Info("creating Database...")
+       adapter.logger.Infof("creating Database...")
 
        usrpswd := os.Getenv("MYSQL_USER") + ":" + os.Getenv("MYSQL_PASSWORD")
        host := "@tcp(" + "dbhost" + ":3306)/"
@@ -51,7 +51,7 @@ func (adapter *DbAdapter) CreateDatabase() {
        db.Exec("USE applcmDB")
        gorm.DefaultCallback.Create().Remove("mysql:set_identity_insert")
 
-       adapter.logger.Info("Migrating models...")
+       adapter.logger.Infof("Migrating models...")
        db.AutoMigrate(&model.AppPackageInfo{})
        db.AutoMigrate(&model.AppInstanceInfo{})
        adapter.db = db
index 822d7cc..19983e7 100644 (file)
@@ -40,31 +40,31 @@ func NewPluginAdapter(pluginInfo string, logger *logrus.Logger) *PluginAdapter {
 }
 
 // Instantiate application
-func (c *PluginAdapter) Instantiate(pluginInfo string, host string, deployArtifact string) (workloadId string, error error) {
-       c.logger.Info("Instantation started")
-       clientConfig := plugin.ClientGRPCConfig{Address: pluginInfo, ChunkSize: chunkSize, RootCertificate: rootCertificate}
+func (c *PluginAdapter) Instantiate(pluginInfo string, host string, deployArtifact string) (workloadId string, error error, status string) {
+       c.logger.Infof("Instantation started")
+       clientConfig := plugin.ClientGRPCConfig{Address: pluginInfo, ChunkSize: chunkSize, RootCertificate: rootCertificate, Logger: c.logger}
        var client, err = plugin.NewClientGRPC(clientConfig)
        if err != nil {
                c.logger.Errorf("failed to create client: %v", err)
-               return "", err
+               return "", err, "Failure"
        }
 
        ctx, cancel := context.WithTimeout(context.Background(), 50*time.Second)
        defer cancel()
 
        //Instantiate
-       workloadId, status, err := client.Instantiate(ctx, deployArtifact, host)
+       workloadId, status, err = client.Instantiate(ctx, deployArtifact, host)
        if err != nil {
                c.logger.Errorf("server failed to respond %s", err.Error())
-               return "", err
+               return "", err, "Failure"
        }
-       c.logger.Info("Instantiation success with workloadId %s, status: %s ", workloadId, status)
-       return workloadId, nil
+       c.logger.Infof("Instantiation completed with workloadId %s, status: %s ", workloadId, status)
+       return workloadId, nil, status
 }
 
 // Query application
 func (c *PluginAdapter) Query(pluginInfo string, host string, workloadId string) (status string, error error) {
-       c.logger.Info("Query started")
+       c.logger.Infof("Query started")
        clientConfig := plugin.ClientGRPCConfig{Address: pluginInfo, ChunkSize: chunkSize, RootCertificate: rootCertificate}
        var client, err = plugin.NewClientGRPC(clientConfig)
        if err != nil {
@@ -81,13 +81,13 @@ func (c *PluginAdapter) Query(pluginInfo string, host string, workloadId string)
                c.logger.Errorf("failed to query: %v", err)
                return "", err
        }
-       c.logger.Info("query status: ", status)
+       c.logger.Infof("query status: ", status)
        return status, nil
 }
 
 // Terminate application
 func (c *PluginAdapter) Terminate(pluginInfo string, host string, workloadId string) (status string, error error) {
-       c.logger.Info("Terminate started")
+       c.logger.Infof("Terminate started")
        clientConfig := plugin.ClientGRPCConfig{Address: pluginInfo, ChunkSize: chunkSize, RootCertificate: rootCertificate}
        var client, err = plugin.NewClientGRPC(clientConfig)
        if err != nil {
@@ -106,6 +106,6 @@ func (c *PluginAdapter) Terminate(pluginInfo string, host string, workloadId str
                return "Failure", err
        }
 
-       c.logger.Info("termination success with status: ", status)
+       c.logger.Infof("termination success with status: ", status)
        return status, nil
 }
index 9d871ab..0cea2fb 100644 (file)
@@ -56,7 +56,7 @@ func (hdlr *Handlers) Initialize(logger *logrus.Logger) {
 
 // Run on it's router
 func (hdlr *Handlers) Run(host string) {
-       hdlr.logger.Info("Server is running on port %s", host)
+       hdlr.logger.Infof("Server is running on port %s", host)
        err := http.ListenAndServe(host, hdlr.router)
        if err != nil {
                hdlr.logger.Fatalf("Server couldn't run on port %s", host)
index 83594ec..282d5b0 100644 (file)
@@ -297,6 +297,7 @@ func (impl *HandlerImpl) InstantiateAppInstance(w http.ResponseWriter, r *http.R
                        return
                }
                pluginInfo = "helm.plugin" + ":" + os.Getenv("HELM_PLUGIN_PORT")
+               impl.logger.Infof("Plugin Info ", pluginInfo)
        case "kubernetes":
                pkgPath := PackageFolderPath + packageName + PackageArtifactPath + "Kubernetes"
                artifact = impl.getDeploymentArtifact(pkgPath, "*.yaml")
@@ -312,7 +313,7 @@ func (impl *HandlerImpl) InstantiateAppInstance(w http.ResponseWriter, r *http.R
        impl.logger.Infof("Artifact to deploy:", artifact)
 
        adapter := pluginAdapter.NewPluginAdapter(pluginInfo, impl.logger)
-       workloadId, err := adapter.Instantiate(pluginInfo, req.SelectedMECHostInfo.HostID, artifact)
+       workloadId, err, resStatus := adapter.Instantiate(pluginInfo, req.SelectedMECHostInfo.HostID, artifact)
        if err != nil {
                st, ok := status.FromError(err)
                if ok && st.Code() == codes.InvalidArgument {
@@ -322,9 +323,13 @@ func (impl *HandlerImpl) InstantiateAppInstance(w http.ResponseWriter, r *http.R
                        respondError(w, http.StatusInternalServerError, err.Error())
                }
        }
-       impl.dbAdapter.UpdateAppInstanceInfoInstStatusHostAndWorkloadId(appInstanceId, "INSTANTIATED", req.SelectedMECHostInfo.HostID, workloadId)
 
-       respondJSON(w, http.StatusAccepted, json.NewEncoder(w).Encode(""))
+       if resStatus == "Failure" {
+               respondError(w, http.StatusInternalServerError, err.Error())
+       }
+
+       impl.dbAdapter.UpdateAppInstanceInfoInstStatusHostAndWorkloadId(appInstanceId, "INSTANTIATED", req.SelectedMECHostInfo.HostID, workloadId)
+       respondJSON(w, http.StatusAccepted, json.NewEncoder(w).Encode(workloadId))
 }
 
 // Gets deployment artifact
index 0d83530..2c3bb28 100644 (file)
@@ -82,7 +82,7 @@ func (c *ClientGRPC) Instantiate(ctx context.Context, deployArtifact string, hos
                n       int
                file    *os.File
        )
-       c.logger.Info("deployArtifact: ", deployArtifact)
+       c.logger.Infof("deployArtifact: ", deployArtifact)
 
        // Get a file handle for the file we
        // want to upload
@@ -154,8 +154,8 @@ func (c *ClientGRPC) Instantiate(ctx context.Context, deployArtifact string, hos
                c.logger.Errorf("failed to receive upstream status response: ", err)
                return "","Failure", err
        }
-       c.logger.Info("Instantiation Completed")
-       return res.WorkloadId, res.Status, err
+       c.logger.Infof("Instantiation Completed with workloadId %s and status", res.GetWorkloadId(), res.GetStatus())
+       return res.GetWorkloadId(), res.GetStatus(), err
 }
 
 // Query application
index cfe4d56..ba2df97 100644 (file)
@@ -29,6 +29,6 @@ func GetLogger(logFile string, loggerLevel logrus.Level, file *os.File) *logrus.
                FullTimestamp: true,
        })
        logger.SetLevel(loggerLevel)
-       logger.Info("logger created")
+       logger.Infof("logger created")
        return logger
 }
\ No newline at end of file
index 2bcdc47..00bbb1c 100644 (file)
@@ -167,7 +167,7 @@ func (s *ServerGRPC) Instantiate(stream lcmservice.AppLCM_InstantiateServer) (er
        }
 
        hostIP := req.GetHostIp()
-       s.logger.Info("Recieved instantiate request")
+       s.logger.Infof("Recieved instantiate request")
 
        // Host validation
        if (hostIP == "") {
@@ -196,7 +196,7 @@ func (s *ServerGRPC) Instantiate(stream lcmservice.AppLCM_InstantiateServer) (er
                // Receive chunk and write to helm package
                chunk := req.GetPackage()
 
-               s.logger.Info("Recieved chunk")
+               s.logger.Infof("Recieved chunk")
 
                _, err = helmPkg.Write(chunk)
                if err != nil {
@@ -218,15 +218,16 @@ func (s *ServerGRPC) Instantiate(stream lcmservice.AppLCM_InstantiateServer) (er
 
        if (err != nil) {
                res.Status = "Failure"
+               s.logger.Infof("Instantiation Failed")
        } else {
                res.Status = "Success"
+               s.logger.Infof("Successful Instantiation")
        }
 
        err = stream.SendAndClose(&res)
        if err != nil {
                return s.logError(status.Errorf(codes.Unknown, "cannot send response: %v", err))
        }
-       s.logger.Info("Successful Instantiation")
        return
 }
 
index 109a92c..2ec2328 100644 (file)
@@ -101,7 +101,7 @@ func (hc *HelmClient) installChart(helmPkg bytes.Buffer) (string, error) {
                hc.logger.Errorf("Unable to install chart with release name: %s. Err: %s", relName, err)
                return "", err
        }
-       hc.logger.Info("Successfully create chart with release name: %s", relName)
+       hc.logger.Infof("Successfully create chart with release name: %s", relName)
        return rel.Name, err
 }
 
@@ -123,7 +123,7 @@ func (hc *HelmClient) uninstallChart(relName string) (error) {
                hc.logger.Errorf("Unable to uninstall chart with release name: %s. Err: %s", relName, err)
                return err
        }
-       hc.logger.Info("Successfully uninstalled chart with release name: %s. Response Info: %s", res.Release.Name, res.Info)
+       hc.logger.Infof("Successfully uninstalled chart with release name: %s. Response Info: %s", res.Release.Name, res.Info)
        return nil
 }
 
index 265bd68..919a4d2 100644 (file)
@@ -29,6 +29,6 @@ func GetLogger(logFile string, loggerLevel logrus.Level, file *os.File) *logrus.
                FullTimestamp: true,
        })
        logger.SetLevel(loggerLevel)
-       logger.Info("logger created")
+       logger.Infof("logger created")
        return logger
 }
\ No newline at end of file
index 55f14c7..d15d99c 100644 (file)
@@ -2,7 +2,6 @@
 cd ../broker
 . docker-build.sh
 
-
 #helmplugin compile and build docker image
 cd ../k8shelm
 . docker-build.sh