Skip to content

Improvements to install/uninstall process #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "unity-cs-manager"]
path = unity-cs-manager
url = https://github.com/unity-sds/unity-cs-manager.git
[submodule "src/stellar"]
path = src/stellar
url = [email protected]:nasa-jpl/stellar.git
10 changes: 10 additions & 0 deletions backend/internal/database/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ type Deployment struct {
Creator string
CreationDate time.Time
}

type InstalledMarketplaceApplication struct {
gorm.Model
Name string
DeploymentName string
Version string
Source string
Status string
PackageName string
}
73 changes: 70 additions & 3 deletions backend/internal/database/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/unity-sds/unity-management-console/backend/internal/application/config"
"github.com/unity-sds/unity-management-console/backend/internal/database/models"
"gorm.io/gorm/clause"
"gorm.io/gorm"
)

// StoreConfig stores the given configuration in the database. It uses a
Expand Down Expand Up @@ -133,6 +134,29 @@ func (g GormDatastore) FetchDeploymentIDByName(deploymentID string) (uint, error
return deployment.ID, nil
}

func (g GormDatastore) GetInstalledApplicationByName(name string) (*models.InstalledMarketplaceApplication, error) {
var application models.InstalledMarketplaceApplication
result := g.db.Where("name = ?", name).Where("status != 'UNINSTALLED'").First(&application)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound){
return nil, nil
}

log.WithError(result.Error).Error("Error finding application")
return nil, result.Error
}
return &application, nil
}

func (g GormDatastore) FetchDeploymentIDByApplicationName(deploymentName string) (uint, error) {
var application models.Application
result := g.db.Where("display_name = ?", deploymentName).First(&application)
if result.Error != nil {
return 0, fmt.Errorf("error finding application: %v", result.Error)
}
return application.DeploymentID, nil
}

func (g GormDatastore) UpdateApplicationStatus(deploymentID uint, targetAppName string, displayName string, newStatus string) error {
var deployment models.Deployment
result := g.db.Preload("Applications").First(&deployment, deploymentID)
Expand Down Expand Up @@ -167,6 +191,15 @@ func (g GormDatastore) FetchAllApplicationStatus() ([]models.Deployment, error)
return deployments, nil
}

func (g GormDatastore) FetchAllInstalledMarketplaceApplications() ([]models.InstalledMarketplaceApplication, error) {
var applications []models.InstalledMarketplaceApplication
result := g.db.Find(&applications)
if result.Error != nil {
return nil, result.Error
}
return applications, nil
}

func (g GormDatastore) FetchAllApplicationStatusByDeployment(deploymentid uint) ([]models.Application, error) {
var deployments models.Deployment
result := g.db.Preload("Applications").First(&deployments, deploymentid)
Expand Down Expand Up @@ -223,11 +256,45 @@ func (g GormDatastore) RemoveApplicationByName(deploymentName string, applicatio
return fmt.Errorf("error deleting application: %v", err)
}

// Delete the deployment
err = g.db.Delete(&deployment).Error
return nil
}

func (g GormDatastore) StoreInstalledMarketplaceApplication(model models.InstalledMarketplaceApplication) (error) {
if err := g.db.Save(&model).Error; err != nil {
// Handle error for Save
log.WithError(err).Error("Problem saving record to database")
return err
}
return nil
}

func (g GormDatastore) GetInstalledMarketplaceApplicationStatusByName(appName string, deploymentName string) (*models.InstalledMarketplaceApplication, error) {
var application models.InstalledMarketplaceApplication
err := g.db.Where("Name = ? AND deployment_name = ?", appName, deploymentName).First(&application).Error
if err != nil {
return fmt.Errorf("error deleting deployment: %v", err)
log.WithError(err).Error("Problem getting application status")
return nil, err
}
return &application, nil
}

func (g GormDatastore) UpdateInstalledMarketplaceApplicationStatusByName(appName string, deploymentName string, status string) (error) {
var app models.InstalledMarketplaceApplication

g.db.Where("name = ? AND deployment_name = ?", appName, deploymentName).First(&app)
app.Status = status

if err := g.db.Save(&app).Error; err != nil {
// Handle error for Save
log.WithError(err).Error("Problem saving record to database")
return err
}
return nil
}

func (g GormDatastore) RemoveInstalledMarketplaceApplicationByName(appName string) (error) {
if err := g.db.Where("name != ?", appName).Delete(&models.InstalledMarketplaceApplication{}).Error; err != nil {
return err
}
return nil
}
13 changes: 13 additions & 0 deletions backend/internal/database/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func NewGormDatastore() (Datastore, error) {
if err != nil {
return nil, err
}

err = db.AutoMigrate(&models.InstalledMarketplaceApplication{})
if err != nil {
return nil, err
}

return &GormDatastore{
db: db,
}, nil
Expand All @@ -120,4 +126,11 @@ type Datastore interface {
FetchDeploymentNames() ([]string, error)
RemoveDeploymentByName(name string) error
RemoveApplicationByName(deploymentName string, applicationName string) error
FetchDeploymentIDByApplicationName(deploymentName string) (uint, error)
GetInstalledApplicationByName(name string) (*models.InstalledMarketplaceApplication, error)
StoreInstalledMarketplaceApplication(model models.InstalledMarketplaceApplication) error
UpdateInstalledMarketplaceApplicationStatusByName(appName string,displayName string, status string) error
RemoveInstalledMarketplaceApplicationByName(appName string) error
GetInstalledMarketplaceApplicationStatusByName(appName string, displayName string) (*models.InstalledMarketplaceApplication, error)
FetchAllInstalledMarketplaceApplications() ([]models.InstalledMarketplaceApplication, error)
}
2 changes: 1 addition & 1 deletion backend/internal/processes/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func BootstrapEnv(appconf *config.AppConfig) {
}
return
}

err = installHealthStatusLambda(store, appconf)
if err != nil {
log.WithError(err).Error("Error installing Health Status ")
Expand Down
Loading
Loading