From 0208bcf081f8c8e3861de47559571460224d1853 Mon Sep 17 00:00:00 2001 From: Sam Lucidi Date: Thu, 20 Jun 2024 14:08:12 -0400 Subject: [PATCH] Launch discovery for imported applications Signed-off-by: Sam Lucidi --- cmd/main.go | 3 ++- importer/manager.go | 28 +++++++++++++++++++- settings/hub.go | 62 ++++++++++++++++++++++----------------------- 3 files changed, 60 insertions(+), 33 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 5ee541d12..d5bdba2c2 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -176,7 +176,8 @@ func main() { // // Application import. importManager := importer.Manager{ - DB: db, + DB: db, + Tasking: &taskManager, } importManager.Run(context.Background()) // diff --git a/importer/manager.go b/importer/manager.go index 651eedf15..fb35601b5 100644 --- a/importer/manager.go +++ b/importer/manager.go @@ -12,13 +12,20 @@ import ( liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/api" "github.com/konveyor/tackle2-hub/model" + "github.com/konveyor/tackle2-hub/settings" + tasking "github.com/konveyor/tackle2-hub/task" "gorm.io/gorm" ) +var ( + Settings = &settings.Settings +) + // Manager for processing application imports. type Manager struct { // DB - DB *gorm.DB + DB *gorm.DB + Tasking *tasking.Manager } // Run the manager. @@ -334,11 +341,30 @@ func (m *Manager) createApplication(imp *model.Import) (ok bool) { imp.ErrorMessage = result.Error.Error() return } + // best effort + _ = m.discover(app) ok = true return } +func (m *Manager) discover(application *model.Application) (err error) { + kinds := []string{Settings.Hub.Task.Kinds.Discovery.Language, Settings.Hub.Task.Kinds.Discovery.Technology} + for _, kind := range kinds { + t := model.Task{} + task := tasking.Task{Task: &t} + task.Kind = kind + task.Name = fmt.Sprintf("%s-%s", application.Name, kind) + task.ApplicationID = &application.ID + task.State = tasking.Ready + err = m.Tasking.Create(m.DB, &task) + if err != nil { + return + } + } + return +} + func (m *Manager) createStakeholder(name string, email string) (stakeholder model.Stakeholder, err error) { stakeholder.Name = name stakeholder.Email = email diff --git a/settings/hub.go b/settings/hub.go index 6e1001490..c8d07e3d1 100644 --- a/settings/hub.go +++ b/settings/hub.go @@ -7,35 +7,35 @@ import ( ) const ( - EnvNamespace = "NAMESPACE" - EnvDbPath = "DB_PATH" - EnvDbSeedPath = "DB_SEED_PATH" - EnvBucketPath = "BUCKET_PATH" - EnvRwxSupported = "RWX_SUPPORTED" - EnvCachePath = "CACHE_PATH" - EnvCachePvc = "CACHE_PVC" - EnvSharedPath = "SHARED_PATH" - EnvPassphrase = "ENCRYPTION_PASSPHRASE" - EnvTaskReapCreated = "TASK_REAP_CREATED" - EnvTaskReapSucceeded = "TASK_REAP_SUCCEEDED" - EnvTaskReapFailed = "TASK_REAP_FAILED" - EnvTaskSA = "TASK_SA" - EnvTaskRetries = "TASK_RETRIES" - EnvTaskPreemptEnabled = "TASK_PREEMPT_ENABLED" - EnvTaskPreemptDelayed = "TASK_PREEMPT_DELAYED" - EnvTaskPreemptPostponed = "TASK_PREEMPT_POSTPONED" - EnvTaskPreemptRate = "TASK_PREEMPT_RATE" - EnvFrequencyTask = "FREQUENCY_TASK" - EnvFrequencyReaper = "FREQUENCY_REAPER" - EnvDevelopment = "DEVELOPMENT" - EnvBucketTTL = "BUCKET_TTL" - EnvFileTTL = "FILE_TTL" - EnvAppName = "APP_NAME" - EnvDisconnected = "DISCONNECTED" - EnvAnalysisReportPath = "ANALYSIS_REPORT_PATH" - EnvAnalysisArchiverEnabled = "ANALYSIS_ARCHIVER_ENABLED" - EnvLanguageDiscoveryTask = "LANGUAGE_DISCOVERY_TASK" - EnvTechnologyDiscoveryTask = "TECHNOLOGY_DISCOVERY_TASK" + EnvNamespace = "NAMESPACE" + EnvDbPath = "DB_PATH" + EnvDbSeedPath = "DB_SEED_PATH" + EnvBucketPath = "BUCKET_PATH" + EnvRwxSupported = "RWX_SUPPORTED" + EnvCachePath = "CACHE_PATH" + EnvCachePvc = "CACHE_PVC" + EnvSharedPath = "SHARED_PATH" + EnvPassphrase = "ENCRYPTION_PASSPHRASE" + EnvTaskReapCreated = "TASK_REAP_CREATED" + EnvTaskReapSucceeded = "TASK_REAP_SUCCEEDED" + EnvTaskReapFailed = "TASK_REAP_FAILED" + EnvTaskSA = "TASK_SA" + EnvTaskRetries = "TASK_RETRIES" + EnvTaskPreemptEnabled = "TASK_PREEMPT_ENABLED" + EnvTaskPreemptDelayed = "TASK_PREEMPT_DELAYED" + EnvTaskPreemptPostponed = "TASK_PREEMPT_POSTPONED" + EnvTaskPreemptRate = "TASK_PREEMPT_RATE" + EnvFrequencyTask = "FREQUENCY_TASK" + EnvFrequencyReaper = "FREQUENCY_REAPER" + EnvDevelopment = "DEVELOPMENT" + EnvBucketTTL = "BUCKET_TTL" + EnvFileTTL = "FILE_TTL" + EnvAppName = "APP_NAME" + EnvDisconnected = "DISCONNECTED" + EnvAnalysisReportPath = "ANALYSIS_REPORT_PATH" + EnvAnalysisArchiverEnabled = "ANALYSIS_ARCHIVER_ENABLED" + EnvTaskKindDiscoveryLanguage = "TASK_KIND_DISCOVERY_LANGUAGE" + EnvTaskKindDiscoveryTechnology = "TASK_KIND_DISCOVERY_TECHNOLOGY" ) type Hub struct { @@ -267,11 +267,11 @@ func (r *Hub) Load() (err error) { r.Analysis.ArchiverEnabled = true } - r.Task.Kinds.Discovery.Language, found = os.LookupEnv(EnvLanguageDiscoveryTask) + r.Task.Kinds.Discovery.Language, found = os.LookupEnv(EnvTaskKindDiscoveryLanguage) if !found { r.Task.Kinds.Discovery.Language = "language-discovery" } - r.Task.Kinds.Discovery.Technology, found = os.LookupEnv(EnvTechnologyDiscoveryTask) + r.Task.Kinds.Discovery.Technology, found = os.LookupEnv(EnvTaskKindDiscoveryTechnology) if !found { r.Task.Kinds.Discovery.Technology = "tech-discovery" }