Skip to content

Commit

Permalink
Launch discovery for imported applications
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Lucidi <[email protected]>
  • Loading branch information
mansam committed Jun 20, 2024
1 parent 634ad47 commit 0208bcf
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 33 deletions.
3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ func main() {
//
// Application import.
importManager := importer.Manager{
DB: db,
DB: db,
Tasking: &taskManager,
}
importManager.Run(context.Background())
//
Expand Down
28 changes: 27 additions & 1 deletion importer/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
62 changes: 31 additions & 31 deletions settings/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
}
Expand Down

0 comments on commit 0208bcf

Please sign in to comment.