Skip to content
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

feature. change interface for init workflow #10

Merged
merged 1 commit into from
Apr 3, 2023
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
15 changes: 11 additions & 4 deletions internal/repository/app-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions internal/repository/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions internal/repository/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/usecase/app-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/usecase/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/usecase/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down