Merge "mecm-mepm uninstall playbook added"
[ealt-edge.git] / mecm / mepm / applcm / broker / pkg / handlers / handlersImpl.go
index 83594ec..6867b2c 100644 (file)
@@ -23,6 +23,13 @@ import (
        "bytes"
        "encoding/json"
        "fmt"
+       "io"
+       "io/ioutil"
+       "net/http"
+       "os"
+       "path/filepath"
+       "strings"
+
        "github.com/buger/jsonparser"
        "github.com/ghodss/yaml"
        "github.com/google/uuid"
@@ -30,18 +37,12 @@ import (
        "github.com/sirupsen/logrus"
        "google.golang.org/grpc/codes"
        "google.golang.org/grpc/status"
-       "io"
-       "io/ioutil"
-       "net/http"
-       "os"
-       "path/filepath"
-       "strings"
 )
 
 // Handler of REST APIs
 type HandlerImpl struct {
-       logger     *logrus.Logger
-       dbAdapter  *dbAdapter.DbAdapter
+       logger    *logrus.Logger
+       dbAdapter *dbAdapter.DbAdapter
 }
 
 // Creates handler implementation
@@ -296,7 +297,8 @@ func (impl *HandlerImpl) InstantiateAppInstance(w http.ResponseWriter, r *http.R
                        respondError(w, http.StatusInternalServerError, "artifact not available in application package")
                        return
                }
-               pluginInfo = "helm.plugin" + ":" + os.Getenv("HELM_PLUGIN_PORT")
+               pluginInfo = "helmplugin" + ":" + 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 +314,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 +324,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
@@ -375,7 +381,7 @@ func (impl *HandlerImpl) QueryAppInstanceInfo(w http.ResponseWriter, r *http.Req
 
                switch appPackageInfo.DeployType {
                case "helm":
-                       pluginInfo = "helm.plugin" + ":" + os.Getenv("HELM_PLUGIN_PORT")
+                       pluginInfo = "helmplugin" + ":" + os.Getenv("HELM_PLUGIN_PORT")
                case "kubernetes":
                        pluginInfo = "kubernetes.plugin" + ":" + os.Getenv("KUBERNETES_PLUGIN_PORT")
                default:
@@ -429,7 +435,7 @@ func (impl *HandlerImpl) TerminateAppInstance(w http.ResponseWriter, r *http.Req
        var pluginInfo string
        switch appPackageInfo.DeployType {
        case "helm":
-               pluginInfo = "helm.plugin" + ":" + os.Getenv("HELM_PLUGIN_PORT")
+               pluginInfo = "helmplugin" + ":" + os.Getenv("HELM_PLUGIN_PORT")
        case "kubernetes":
                pluginInfo = "kubernetes.plugin" + ":" + os.Getenv("KUBERNETES_PLUGIN_PORT")
        default: