diff --git a/internal/repository/app-group.go b/internal/repository/app-group.go index 4ae3d0a7..22809ed7 100644 --- a/internal/repository/app-group.go +++ b/internal/repository/app-group.go @@ -21,7 +21,7 @@ type IAppGroupRepository interface { GetApplications(appGroupID string) (applications []domain.Application, err error) GetApplication(appGroupId string, applicationType string) (out domain.Application, err error) UpsertApplication(appGroupID string, appType string, endpoint, metadata string) error - InitWorkflow(appGroupId string, workflowId string) error + InitWorkflow(appGroupId string, workflowId string, status domain.AppGroupStatus) error } type AppGroupRepository struct { @@ -96,7 +96,14 @@ func (r *AppGroupRepository) Get(id string) (domain.AppGroup, error) { } func (r *AppGroupRepository) Create(clusterId string, name string, appGroupType string, creator uuid.UUID, description string) (appGroupId string, err error) { - appGroup := AppGroup{ClusterId: clusterId, AppGroupType: appGroupType, Name: name, Creator: creator, Description: description} + appGroup := AppGroup{ + ClusterId: clusterId, + AppGroupType: appGroupType, + Name: name, + Creator: creator, + Description: description, + Status: domain.AppGroupStatus_PENDING, + } res := r.db.Create(&appGroup) if res.Error != nil { log.Error(res.Error) @@ -152,10 +159,10 @@ func (r *AppGroupRepository) UpsertApplication(appGroupId string, appType string return nil } -func (r *AppGroupRepository) InitWorkflow(appGroupId string, workflowId string) error { +func (r *AppGroupRepository) InitWorkflow(appGroupId string, workflowId string, status domain.AppGroupStatus) error { res := r.db.Model(&AppGroup{}). Where("ID = ?", appGroupId). - Updates(map[string]interface{}{"Status": domain.AppGroupStatus_INSTALLING, "WorkflowId": workflowId}) + Updates(map[string]interface{}{"Status": status, "WorkflowId": workflowId}) if res.Error != nil || res.RowsAffected == 0 { return fmt.Errorf("nothing updated in appgroup with id %s", appGroupId) diff --git a/internal/repository/cluster.go b/internal/repository/cluster.go index bd58424c..306ffceb 100644 --- a/internal/repository/cluster.go +++ b/internal/repository/cluster.go @@ -20,7 +20,7 @@ type IClusterRepository interface { Get(id string) (domain.Cluster, error) Create(organizationId string, templateId string, name string, cloudSettingId uuid.UUID, conf *domain.ClusterConf, creator uuid.UUID, description string) (clusterId string, err error) Delete(id string) error - InitWorkflow(clusterId string, workflowId string) error + InitWorkflow(clusterId string, workflowId string, status domain.ClusterStatus) error } type ClusterRepository struct { @@ -157,6 +157,7 @@ func (r *ClusterRepository) Create(organizationId string, templateId string, nam MachineType: conf.MachineType, MinSizePerAz: conf.MinSizePerAz, MaxSizePerAz: conf.MaxSizePerAz, + Status: domain.ClusterStatus_PENDING, } res := r.db.Create(&cluster) if res.Error != nil { @@ -175,10 +176,10 @@ func (r *ClusterRepository) Delete(clusterId string) error { return nil } -func (r *ClusterRepository) InitWorkflow(clusterId string, workflowId string) error { +func (r *ClusterRepository) InitWorkflow(clusterId string, workflowId string, status domain.ClusterStatus) error { res := r.db.Model(&Cluster{}). Where("ID = ?", clusterId). - Updates(map[string]interface{}{"Status": domain.ClusterStatus_INSTALLING, "WorkflowId": workflowId}) + Updates(map[string]interface{}{"Status": status, "WorkflowId": workflowId}) if res.Error != nil || res.RowsAffected == 0 { return fmt.Errorf("nothing updated in cluster with id %s", clusterId) diff --git a/internal/repository/organization.go b/internal/repository/organization.go index fed91f9e..1f4a3e05 100644 --- a/internal/repository/organization.go +++ b/internal/repository/organization.go @@ -16,7 +16,7 @@ type IOrganizationRepository interface { Get(organizationId string) (res domain.Organization, err error) Update(organizationId string, in domain.UpdateOrganizationRequest) (domain.Organization, error) Delete(organizationId string) (err error) - InitWorkflow(organizationId string, workflowId string) error + InitWorkflow(organizationId string, workflowId string, status domain.OrganizationStatus) error } type OrganizationRepository struct { @@ -57,6 +57,7 @@ func (r *OrganizationRepository) Create(organizationId string, name string, crea Creator: creator, Phone: phone, Description: description, + Status: domain.OrganizationStatus_PENDING, } res := r.db.Create(&organization) if res.Error != nil { @@ -126,10 +127,10 @@ func (r *OrganizationRepository) Delete(organizationId string) error { return nil } -func (r *OrganizationRepository) InitWorkflow(organizationId string, workflowId string) error { +func (r *OrganizationRepository) InitWorkflow(organizationId string, workflowId string, status domain.OrganizationStatus) error { res := r.db.Model(&Organization{}). Where("ID = ?", organizationId). - Updates(map[string]interface{}{"Status": domain.OrganizationStatus_PENDING, "WorkflowId": workflowId}) + Updates(map[string]interface{}{"Status": status, "WorkflowId": workflowId}) if res.Error != nil { log.Error("error is :%s(%T)", res.Error.Error(), res.Error) return res.Error diff --git a/internal/usecase/app-group.go b/internal/usecase/app-group.go index bc1ab580..1cca4da7 100644 --- a/internal/usecase/app-group.go +++ b/internal/usecase/app-group.go @@ -112,7 +112,7 @@ func (u *AppGroupUsecase) Create(clusterId string, name string, appGroupType str log.Debug("submited workflow name : ", workflowId) - if err := u.repo.InitWorkflow(appGroupId, workflowId); err != nil { + if err := u.repo.InitWorkflow(appGroupId, workflowId, domain.AppGroupStatus_INSTALLING); err != nil { return "", fmt.Errorf("Failed to initialize appGroup status. err : %s", err) } @@ -167,7 +167,7 @@ func (u *AppGroupUsecase) Delete(appGroupId string) (err error) { log.Debug("submited workflow name : ", workflowId) - if err := u.repo.InitWorkflow(appGroupId, workflowId); err != nil { + if err := u.repo.InitWorkflow(appGroupId, workflowId, domain.AppGroupStatus_DELETING); err != nil { return fmt.Errorf("Failed to initialize appGroup status. err : %s", err) } diff --git a/internal/usecase/cluster.go b/internal/usecase/cluster.go index e4679a32..711c2d17 100644 --- a/internal/usecase/cluster.go +++ b/internal/usecase/cluster.go @@ -143,7 +143,7 @@ func (u *ClusterUsecase) Create(session user.Info, in domain.CreateClusterReques } log.Info("Successfully submited workflow: ", workflowId) - if err := u.repo.InitWorkflow(clusterId, workflowId); err != nil { + if err := u.repo.InitWorkflow(clusterId, workflowId, domain.ClusterStatus_INSTALLING); err != nil { return "", errors.Wrap(err, "Failed to initialize status") } @@ -195,7 +195,7 @@ func (u *ClusterUsecase) Delete(clusterId string) (err error) { log.Debug("submited workflow name : ", workflowId) - if err := u.repo.InitWorkflow(clusterId, workflowId); err != nil { + if err := u.repo.InitWorkflow(clusterId, workflowId, domain.ClusterStatus_DELETING); err != nil { return errors.Wrap(err, "Failed to initialize status") } diff --git a/internal/usecase/organization.go b/internal/usecase/organization.go index d8ae7bdd..650ff519 100644 --- a/internal/usecase/organization.go +++ b/internal/usecase/organization.go @@ -77,7 +77,7 @@ func (u *OrganizationUsecase) Create(ctx context.Context, in *domain.Organizatio } log.Info("submited workflow :", workflowId) - if err := u.repo.InitWorkflow(organizationId, workflowId); err != nil { + if err := u.repo.InitWorkflow(organizationId, workflowId, domain.OrganizationStatus_CREATING); err != nil { return "", errors.Wrap(err, "Failed to init workflow") }