forked from raystack/optimus
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add upstream identifier for maxcompute
- Loading branch information
1 parent
541691f
commit 8dedad5
Showing
11 changed files
with
280 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
plugin/upstream_identifier/maxcompute_upstream_identifier.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package upstreamidentifier | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/goto/optimus/core/resource" | ||
"github.com/goto/optimus/plugin/upstream_identifier/parser" | ||
"github.com/goto/salt/log" | ||
) | ||
|
||
type MaxcomputeUpstreamIdentifier struct { | ||
logger log.Logger | ||
parserFunc ParserFunc | ||
evaluatorFuncs []EvalAssetFunc | ||
} | ||
|
||
func NewMaxcomputeUpstreamIdentifier(logger log.Logger, parserFunc ParserFunc, evaluatorFuncs ...EvalAssetFunc) (*MaxcomputeUpstreamIdentifier, error) { | ||
return &MaxcomputeUpstreamIdentifier{ | ||
logger: logger, | ||
parserFunc: parser.MaxcomputeURNDecorator(parserFunc), | ||
evaluatorFuncs: evaluatorFuncs, | ||
}, nil | ||
} | ||
|
||
func (g MaxcomputeUpstreamIdentifier) IdentifyResources(ctx context.Context, assets map[string]string) ([]resource.URN, error) { | ||
resourceURNs := []resource.URN{} | ||
|
||
// generate resource urn with upstream from each evaluator | ||
for _, evaluatorFunc := range g.evaluatorFuncs { | ||
query := evaluatorFunc(assets) | ||
if query == "" { | ||
continue | ||
} | ||
resources := g.identifyResources(query) | ||
resourceURNs = append(resourceURNs, resources...) | ||
} | ||
return resourceURNs, nil | ||
} | ||
|
||
func (g MaxcomputeUpstreamIdentifier) identifyResources(query string) []resource.URN { | ||
resources := g.parserFunc(query) | ||
resourceURNs := make([]resource.URN, len(resources)) | ||
for _, r := range resources { | ||
resourceURN, _ := resource.NewURN("maxcompute", r) // TODO: use dedicated function new resource from string | ||
resourceURNs = append(resourceURNs, resourceURN) | ||
} | ||
return resourceURNs | ||
} |
3 changes: 3 additions & 0 deletions
3
plugin/upstream_identifier/maxcompute_upstream_identifier_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package upstreamidentifier_test | ||
|
||
// TODO: Implement test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.