From 246be669d7a8109bfc7ce3d7101268a248854be4 Mon Sep 17 00:00:00 2001 From: agrawalgaurav Date: Fri, 15 May 2020 02:56:13 +0530 Subject: [PATCH] Bug fixes Change-Id: If4b2675e14a33901862b54a55c0950a7275aa62d --- .../pkg/handlers/adapter/dbAdapter/dbAdapter.go | 4 ++-- .../adapter/pluginAdapter/pluginAdapter.go | 24 +++++++++++----------- mecm/mepm/applcm/broker/pkg/handlers/handlers.go | 2 +- .../applcm/broker/pkg/handlers/handlersImpl.go | 11 +++++++--- mecm/mepm/applcm/broker/pkg/plugin/grpcclient.go | 6 +++--- mecm/mepm/applcm/broker/pkg/util/logger.go | 2 +- mecm/mepm/applcm/k8shelm/pkg/plugin/grpcserver.go | 7 ++++--- mecm/mepm/applcm/k8shelm/pkg/plugin/helmclient.go | 4 ++-- mecm/mepm/applcm/k8shelm/pkg/plugin/logger.go | 2 +- mecm/mepm/applcm/resources/Build-Run.sh | 1 - 10 files changed, 34 insertions(+), 29 deletions(-) diff --git a/mecm/mepm/applcm/broker/pkg/handlers/adapter/dbAdapter/dbAdapter.go b/mecm/mepm/applcm/broker/pkg/handlers/adapter/dbAdapter/dbAdapter.go index 8af5e51..d2d8ab7 100644 --- a/mecm/mepm/applcm/broker/pkg/handlers/adapter/dbAdapter/dbAdapter.go +++ b/mecm/mepm/applcm/broker/pkg/handlers/adapter/dbAdapter/dbAdapter.go @@ -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 diff --git a/mecm/mepm/applcm/broker/pkg/handlers/adapter/pluginAdapter/pluginAdapter.go b/mecm/mepm/applcm/broker/pkg/handlers/adapter/pluginAdapter/pluginAdapter.go index 822d7cc..19983e7 100644 --- a/mecm/mepm/applcm/broker/pkg/handlers/adapter/pluginAdapter/pluginAdapter.go +++ b/mecm/mepm/applcm/broker/pkg/handlers/adapter/pluginAdapter/pluginAdapter.go @@ -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 } diff --git a/mecm/mepm/applcm/broker/pkg/handlers/handlers.go b/mecm/mepm/applcm/broker/pkg/handlers/handlers.go index 9d871ab..0cea2fb 100644 --- a/mecm/mepm/applcm/broker/pkg/handlers/handlers.go +++ b/mecm/mepm/applcm/broker/pkg/handlers/handlers.go @@ -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) diff --git a/mecm/mepm/applcm/broker/pkg/handlers/handlersImpl.go b/mecm/mepm/applcm/broker/pkg/handlers/handlersImpl.go index 83594ec..282d5b0 100644 --- a/mecm/mepm/applcm/broker/pkg/handlers/handlersImpl.go +++ b/mecm/mepm/applcm/broker/pkg/handlers/handlersImpl.go @@ -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 diff --git a/mecm/mepm/applcm/broker/pkg/plugin/grpcclient.go b/mecm/mepm/applcm/broker/pkg/plugin/grpcclient.go index 0d83530..2c3bb28 100644 --- a/mecm/mepm/applcm/broker/pkg/plugin/grpcclient.go +++ b/mecm/mepm/applcm/broker/pkg/plugin/grpcclient.go @@ -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 diff --git a/mecm/mepm/applcm/broker/pkg/util/logger.go b/mecm/mepm/applcm/broker/pkg/util/logger.go index cfe4d56..ba2df97 100644 --- a/mecm/mepm/applcm/broker/pkg/util/logger.go +++ b/mecm/mepm/applcm/broker/pkg/util/logger.go @@ -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 diff --git a/mecm/mepm/applcm/k8shelm/pkg/plugin/grpcserver.go b/mecm/mepm/applcm/k8shelm/pkg/plugin/grpcserver.go index 2bcdc47..00bbb1c 100644 --- a/mecm/mepm/applcm/k8shelm/pkg/plugin/grpcserver.go +++ b/mecm/mepm/applcm/k8shelm/pkg/plugin/grpcserver.go @@ -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 } diff --git a/mecm/mepm/applcm/k8shelm/pkg/plugin/helmclient.go b/mecm/mepm/applcm/k8shelm/pkg/plugin/helmclient.go index 109a92c..2ec2328 100644 --- a/mecm/mepm/applcm/k8shelm/pkg/plugin/helmclient.go +++ b/mecm/mepm/applcm/k8shelm/pkg/plugin/helmclient.go @@ -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 } diff --git a/mecm/mepm/applcm/k8shelm/pkg/plugin/logger.go b/mecm/mepm/applcm/k8shelm/pkg/plugin/logger.go index 265bd68..919a4d2 100644 --- a/mecm/mepm/applcm/k8shelm/pkg/plugin/logger.go +++ b/mecm/mepm/applcm/k8shelm/pkg/plugin/logger.go @@ -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 diff --git a/mecm/mepm/applcm/resources/Build-Run.sh b/mecm/mepm/applcm/resources/Build-Run.sh index 55f14c7..d15d99c 100644 --- a/mecm/mepm/applcm/resources/Build-Run.sh +++ b/mecm/mepm/applcm/resources/Build-Run.sh @@ -2,7 +2,6 @@ cd ../broker . docker-build.sh - #helmplugin compile and build docker image cd ../k8shelm . docker-build.sh -- 2.16.6