Skip to content

Commit

Permalink
Feb/pipeline(unzip, pipeline log for error and success) (#6678)
Browse files Browse the repository at this point in the history
* Zip file

* Zip file and migration done status

Signed-off-by: Pappu Kumar <pappu.kumar@progress.com>

* PR Changes

* PR Changes

Signed-off-by: Pappu Kumar <pappu.kumar@progress.com>

* PR Commect fixed

Signed-off-by: Pappu Kumar <pappu.kumar@progress.com>

* Code smell Fixed

Signed-off-by: Pappu Kumar <pappu.kumar@progress.com>

* Update utility.go

* Unzip Destination change

Signed-off-by: Pappu Kumar <pappu.kumar@progress.com>

* Some fixes

Signed-off-by: Pappu Kumar <pappu.kumar@progress.com>

* Changes Issues and PR comments

Signed-off-by: Pappu Kumar <pappu.kumar@progress.com>

* Error log modified

Signed-off-by: Pappu Kumar <pappu.kumar@progress.com>

* Code smell fixed

Signed-off-by: Pappu Kumar <pappu.kumar@progress.com>
  • Loading branch information
GorillaGigabytes authored and vinay033 committed Mar 29, 2022
1 parent bb4d0a6 commit 24e53fe
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 178 deletions.
3 changes: 2 additions & 1 deletion components/infra-proxy-service/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"os"
"path"

"github.com/chef/automate/components/infra-proxy-service/pipeline"

"github.com/chef/automate/api/interservice/infra_proxy/migrations/request"
"github.com/chef/automate/api/interservice/infra_proxy/migrations/response"
"github.com/chef/automate/api/interservice/infra_proxy/migrations/service"
"github.com/chef/automate/components/infra-proxy-service/constants"
"github.com/chef/automate/components/infra-proxy-service/migrations/pipeline"
pipeline_model "github.com/chef/automate/components/infra-proxy-service/pipeline"

"github.com/chef/automate/components/infra-proxy-service/validation"
Expand Down
127 changes: 0 additions & 127 deletions components/infra-proxy-service/migrations/pipeline/models.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ package pipeline
import (
"context"
"fmt"

log "github.com/sirupsen/logrus"

"github.com/chef/automate/components/infra-proxy-service/pipeline"
"github.com/chef/automate/components/infra-proxy-service/storage"
)

var (
Storage storage.Storage
Mig storage.MigrationStorage
)

type PipelineData struct {
Result Result
Result pipeline.Result
Done chan<- error
Ctx context.Context
}
Expand Down Expand Up @@ -189,7 +199,7 @@ func adminUsers(result <-chan PipelineData) <-chan PipelineData {

func migrationPipeline(source <-chan PipelineData, pipes ...PhaseOnePipelineProcessor) {
fmt.Println("Pipeline started...")

status := make(chan string)
go func() {
for _, pipe := range pipes {
source = pipe(source)
Expand All @@ -198,7 +208,9 @@ func migrationPipeline(source <-chan PipelineData, pipes ...PhaseOnePipelineProc
for s := range source {
s.Done <- nil
}
status <- "Done"
}()
<-status
}

func SetupPhaseOnePipeline() PhaseOnePipleine {
Expand All @@ -214,7 +226,8 @@ func SetupPhaseOnePipeline() PhaseOnePipleine {
return PhaseOnePipleine{in: c}
}

func (p *PhaseOnePipleine) Run(result Result) {
func (p *PhaseOnePipleine) Run(result pipeline.Result) {
status := make(chan string)
go func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -224,8 +237,25 @@ func (p *PhaseOnePipleine) Run(result Result) {
}
err := <-done
if err != nil {
fmt.Println("received error")
MigrationError(err, Mig, ctx, result.Meta.MigrationID, result.Meta.ServerID)
log.Errorf("Phase one pipeline received error for migration %s: %s", result.Meta.MigrationID, err)
}
fmt.Println("received done")
log.Println("received done")
status <- "Done"
}()
<-status
}

func MigrationError(err error, st storage.MigrationStorage, ctx context.Context, migrationId, serviceId string) {
_, err = st.FailedMigration(ctx, migrationId, serviceId, err.Error(), 0, 0, 0)
if err != nil {
log.Errorf("received error while updating for migration id %s: %s", migrationId, err)
}
}

func MigrationSuccess(st storage.MigrationStorage, ctx context.Context, migrationId, serviceId string) {
_, err := st.CompleteMigration(ctx, migrationId, serviceId, 0, 0, 0)
if err != nil {
log.Errorf("received error while updating for migration id %s: %s", migrationId, err)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package pipeline
import (
"context"
"fmt"

log "github.com/sirupsen/logrus"

"github.com/chef/automate/components/infra-proxy-service/pipeline"
)

type PhaseTwoPipleine struct {
Expand Down Expand Up @@ -143,7 +147,7 @@ func populateMembersPolicy(result <-chan PipelineData) <-chan PipelineData {

func migrationTwoPipeline(source <-chan PipelineData, pipes ...PhaseTwoPipelineProcessor) {
fmt.Println("Pipeline started...")

status := make(chan string)
go func() {
for _, pipe := range pipes {
source = pipe(source)
Expand All @@ -152,7 +156,9 @@ func migrationTwoPipeline(source <-chan PipelineData, pipes ...PhaseTwoPipelineP
for s := range source {
s.Done <- nil
}
status <- "Done"
}()
<-status
}

func SetupPhaseTwoPipeline() PhaseTwoPipleine {
Expand All @@ -167,7 +173,7 @@ func SetupPhaseTwoPipeline() PhaseTwoPipleine {
return PhaseTwoPipleine{in: c}
}

func (p *PhaseTwoPipleine) Run(result Result) {
func (p *PhaseTwoPipleine) Run(result pipeline.Result) {
status := make(chan string)
go func() {
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -178,9 +184,11 @@ func (p *PhaseTwoPipleine) Run(result Result) {
}
err := <-done
if err != nil {
fmt.Println("received error")
MigrationError(err, Mig, ctx, result.Meta.MigrationID, result.Meta.ServerID)
log.Errorf("Phase two pipeline received error for migration %s: %s", result.Meta.MigrationID, err)
}
fmt.Println("received done")
MigrationSuccess(Mig, ctx, result.Meta.MigrationID, result.Meta.ServerID)
log.Println("received done")
status <- "Done"
}()
<-status
Expand Down
Loading

0 comments on commit 24e53fe

Please sign in to comment.