Skip to content

Commit

Permalink
refactor: task/hook plugins server should have constructor (#11)
Browse files Browse the repository at this point in the history
Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma authored Jun 16, 2021
1 parent 95372d6 commit ab07ea2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
4 changes: 1 addition & 3 deletions api/handler/v1/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ func (sv *RuntimeServiceServer) DeployJobSpecification(req *pb.DeployJobSpecific
log: logrus.New(),
})

// delete specs not sent for deployment
// currently we don't support deploying a single dag at a time so this will change
// once we do that
// delete specs not sent for deployment from internal repository
if err := sv.jobSvc.KeepOnly(namespaceSpec, jobsToKeep, observers); err != nil {
return status.Error(codes.Internal, fmt.Sprintf("%s: failed to delete jobs", err.Error()))
}
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Basic building blocks of Optimus are

### Overview

![Overview](OptimusArchitecture_dark_07June2021.png?raw=true "OptimusArchitecture")
![Overview](https://github.com/odpf/optimus/blob/95372d614af47dc0140f6b96f819bf08eb62a189/docs/concepts/OptimusArchitecture_dark_07June2021.png?raw=true "OptimusArchitecture")

### Optimus CLI

Expand Down
16 changes: 8 additions & 8 deletions job/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,17 +425,17 @@ func (srv *Service) notifyProgress(po progress.Observer, event progress.Event) {
po.Notify(event)
}

func setSubstract(left []string, right []string) []string {
rightMap := make(map[string]struct{})
for _, item := range right {
rightMap[item] = struct{}{}
// remove items present in from
func setSubstract(from []string, remove []string) []string {
removeMap := make(map[string]bool)
for _, item := range remove {
removeMap[item] = true
}

res := make([]string, 0)
for _, leftKey := range left {
_, exists := rightMap[leftKey]
if !exists {
res = append(res, leftKey)
for _, fromKey := range from {
if _, exists := removeMap[fromKey]; !exists {
res = append(res, fromKey)
}
}

Expand Down
16 changes: 16 additions & 0 deletions plugin/hook/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package hook
import (
"context"

v1 "github.com/odpf/optimus/api/handler/v1"

"github.com/odpf/optimus/models"

"github.com/hashicorp/go-plugin"
Expand Down Expand Up @@ -39,3 +41,17 @@ func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *g
projectSpecAdapter: p.ProjectSpecAdapter,
}, nil
}

func NewPlugin(impl models.HookPlugin) *Plugin {
return &Plugin{
Impl: impl,
ProjectSpecAdapter: v1.NewAdapter(nil, nil, nil),
}
}

func NewPluginWithAdapter(impl models.HookPlugin, projAdapt ProjectSpecAdapter) *Plugin {
return &Plugin{
Impl: impl,
ProjectSpecAdapter: projAdapt,
}
}
16 changes: 16 additions & 0 deletions plugin/task/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package task
import (
"context"

v1 "github.com/odpf/optimus/api/handler/v1"

"github.com/odpf/optimus/models"

"github.com/hashicorp/go-plugin"
Expand Down Expand Up @@ -39,3 +41,17 @@ func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *g
projectSpecAdapter: p.ProjectSpecAdapter,
}, nil
}

func NewPlugin(impl models.TaskPlugin) *Plugin {
return &Plugin{
Impl: impl,
ProjectSpecAdapter: v1.NewAdapter(nil, nil, nil),
}
}

func NewPluginWithAdapter(impl models.TaskPlugin, projAdapt ProjectSpecAdapter) *Plugin {
return &Plugin{
Impl: impl,
ProjectSpecAdapter: projAdapt,
}
}
2 changes: 1 addition & 1 deletion store/gcs/job_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (repo *JobRepository) pathFor(j models.Job) string {

func (repo *JobRepository) jobNameFromPath(filePath string) string {
jobFileName := path.Base(filePath)
return strings.TrimRight(jobFileName, repo.Suffix)
return strings.TrimSuffix(jobFileName, repo.Suffix)
}

func cleanPrefix(prefix string) string {
Expand Down

0 comments on commit ab07ea2

Please sign in to comment.