diff --git a/capten/common-pkg/plugin-store/plugin_deployment_handler.go b/capten/common-pkg/plugin-store/plugin_deployment_handler.go index 82b2b333..bac354e0 100644 --- a/capten/common-pkg/plugin-store/plugin_deployment_handler.go +++ b/capten/common-pkg/plugin-store/plugin_deployment_handler.go @@ -3,6 +3,7 @@ package pluginstore import ( "bytes" "context" + "encoding/json" "fmt" "text/template" @@ -48,10 +49,43 @@ func (p *PluginStore) UnDeployClusterPlugin(ctx context.Context, request *cluste return nil } +// func (p *PluginStore) deployPluginWithWorkflow(pluginData *clusterpluginspb.Plugin) { +// wd := workers.NewDeployment(p.tc, p.log) +// _, err := wd.SendEventV2(context.TODO(), wd.GetPluginWorkflowName(), string(model.AppInstallAction), pluginData) +// if err != nil { +// // pluginConfig.InstallStatus = string(model.AppIntallFailedStatus) +// // if err := a.pas.UpsertPluginConfig(pluginConfig); err != nil { +// // a.log.Errorf("failed to update plugin config for plugin %s, %v", pluginConfig.PluginName, err) +// // return +// // } +// p.log.Errorf("sendEventV2 failed, plugin: %s, reason: %v", pluginData.PluginName, err) +// return +// } +// // TODO: workflow will update the final status +// // Write a periodic scheduler which will go through all apps not in installed status and check the status till either success or failed. +// // Make SendEventV2 asynchrounous so that periodic scheduler will take care of monitoring. +// } + func (p *PluginStore) deployPluginWithWorkflow(pluginData *clusterpluginspb.Plugin) { wd := workers.NewDeployment(p.tc, p.log) - _, err := wd.SendEventV2(context.TODO(), wd.GetPluginWorkflowName(), string(model.AppInstallAction), pluginData) + + // Convert pluginData to a JSON string + pluginDataJSON, err := json.Marshal(pluginData) + if err != nil { + p.log.Errorf("failed to marshal pluginData: %s, reason: %v", pluginData.PluginName, err) + return + } + + // Create a PluginDeployRequest instance + pluginDeployRequest := &model.PluginDeployRequest{ + Data: string(pluginDataJSON), + } + //log.Println("Plugin Deploy Req", pluginDeployRequest.String()) + + // Ensure the payload is a model.DeployRequest + _, err = wd.SendEventV2(context.TODO(), wd.GetPluginWorkflowName(), string(model.AppInstallAction), pluginDeployRequest) if err != nil { + // Uncomment and update the plugin configuration if needed // pluginConfig.InstallStatus = string(model.AppIntallFailedStatus) // if err := a.pas.UpsertPluginConfig(pluginConfig); err != nil { // a.log.Errorf("failed to update plugin config for plugin %s, %v", pluginConfig.PluginName, err) @@ -60,9 +94,6 @@ func (p *PluginStore) deployPluginWithWorkflow(pluginData *clusterpluginspb.Plug p.log.Errorf("sendEventV2 failed, plugin: %s, reason: %v", pluginData.PluginName, err) return } - // TODO: workflow will update the final status - // Write a periodic scheduler which will go through all apps not in installed status and check the status till either success or failed. - // Make SendEventV2 asynchrounous so that periodic scheduler will take care of monitoring. } func (p *PluginStore) unInstallPluginWithWorkflow(request *clusterpluginspb.UnDeployClusterPluginRequest, plugin *clusterpluginspb.Plugin) { diff --git a/capten/common-pkg/workers/deployment.go b/capten/common-pkg/workers/deployment.go index 81902094..29a4396b 100644 --- a/capten/common-pkg/workers/deployment.go +++ b/capten/common-pkg/workers/deployment.go @@ -95,7 +95,7 @@ func (d *Deployment) SendEventV2( return nil, err } - d.log.Infof("Sending event to temporal: workflow: %s, action: %s", workflowName, action) + d.log.Infof("Sending event to temporal: workflow: %s, action: %s, payload: %s", workflowName, action, string(deployPayloadJSON)) run, err := d.client.ExecuteWorkflow(ctx, options, workflowName, action, json.RawMessage(deployPayloadJSON)) if err != nil { d.log.Errorf("failed to send event to workflow for plugin %s, %v", deployPayload.String(), err) diff --git a/capten/model/app_types.go b/capten/model/app_types.go index 27dda68c..8153d413 100644 --- a/capten/model/app_types.go +++ b/capten/model/app_types.go @@ -31,6 +31,15 @@ type DeployRequest interface { String() string } + +type PluginDeployRequest struct { + Data string +} + +func (p *PluginDeployRequest) String() string { + return p.Data +} + type AppConfig struct { AppName string `json:"AppName,omitempty"` Version string `json:"Version,omitempty"`