File tree Expand file tree Collapse file tree
cmd/plugin/apache-devlake Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "github.com/devstream-io/devstream/internal/pkg/plugin/apachedevlake"
5+ "github.com/devstream-io/devstream/pkg/util/log"
6+ )
7+
8+ // NAME is the name of this DevStream plugin.
9+ const NAME = "apache-devlake"
10+
11+ // Plugin is the type used by DevStream core. It's a string.
12+ type Plugin string
13+
14+ // Create implements the create of apache-devlake.
15+ func (p Plugin ) Create (options map [string ]interface {}) (map [string ]interface {}, error ) {
16+ return apachedevlake .Create (options )
17+ }
18+
19+ // Update implements the update of apache-devlake.
20+ func (p Plugin ) Update (options map [string ]interface {}) (map [string ]interface {}, error ) {
21+ return apachedevlake .Update (options )
22+ }
23+
24+ // Delete implements the delete of apache-devlake.
25+ func (p Plugin ) Delete (options map [string ]interface {}) (bool , error ) {
26+ return apachedevlake .Delete (options )
27+ }
28+
29+ // Read implements the read of apache-devlake.
30+ func (p Plugin ) Read (options map [string ]interface {}) (map [string ]interface {}, error ) {
31+ return apachedevlake .Read (options )
32+ }
33+
34+ // DevStreamPlugin is the exported variable used by the DevStream core.
35+ var DevStreamPlugin Plugin
36+
37+ func main () {
38+ log .Infof ("%T: %s is a plugin for DevStream. Use it with DevStream.\n " , DevStreamPlugin , NAME )
39+ }
Original file line number Diff line number Diff line change 1+ # apache-devlake plugin
2+
3+ TODO(dtm): Add your document here.
4+
5+ ## Usage
6+
7+ ``` yaml
8+ --8<-- "apache-devlake.yaml"
9+ ```
Original file line number Diff line number Diff line change 1+ # apache-devlake 插件
2+
3+ TODO(dtm): 在这里添加文档.
4+
5+ ## 用例
6+
7+ ``` yaml
8+ --8<-- "apache-devlake.yaml"
9+ ```
Original file line number Diff line number Diff line change 1+ package apachedevlake
2+
3+ // TODO(dtm): Add your logic here.
Original file line number Diff line number Diff line change 1+ package apachedevlake
2+
3+ import (
4+ "github.com/devstream-io/devstream/internal/pkg/plugininstaller"
5+ "github.com/devstream-io/devstream/internal/pkg/statemanager"
6+ "github.com/devstream-io/devstream/pkg/util/log"
7+ )
8+
9+ func Create (options map [string ]interface {}) (map [string ]interface {}, error ) {
10+ // Initialize Operator with Operations
11+ operator := & plugininstaller.Operator {
12+ PreExecuteOperations : plugininstaller.PreExecuteOperations {
13+ // TODO(dtm): Add your PreExecuteOperations here.
14+ },
15+ ExecuteOperations : plugininstaller.ExecuteOperations {
16+ // TODO(dtm): Add your ExecuteOperations here.
17+ },
18+ TerminateOperations : plugininstaller.TerminateOperations {
19+ // TODO(dtm): Add your TerminateOperations here.
20+ },
21+ GetStateOperation : func (options plugininstaller.RawOptions ) (statemanager.ResourceState , error ) {
22+ // TODO(dtm): Add your GetStateOperation here.
23+ return nil , nil
24+ },
25+ }
26+
27+ // Execute all Operations in Operator
28+ status , err := operator .Execute (plugininstaller .RawOptions (options ))
29+ if err != nil {
30+ return nil , err
31+ }
32+ log .Debugf ("Return map: %v" , status )
33+ return status , nil
34+ }
Original file line number Diff line number Diff line change 1+ package apachedevlake
2+
3+ import (
4+ "github.com/devstream-io/devstream/internal/pkg/plugininstaller"
5+ )
6+
7+ func Delete (options map [string ]interface {}) (bool , error ) {
8+ // Initialize Operator with Operations
9+ operator := & plugininstaller.Operator {
10+ PreExecuteOperations : plugininstaller.PreExecuteOperations {
11+ // TODO(dtm): Add your PreExecuteOperations here.
12+ },
13+ ExecuteOperations : plugininstaller.ExecuteOperations {
14+ // TODO(dtm): Add your ExecuteOperations here.
15+ },
16+ }
17+ _ , err := operator .Execute (plugininstaller .RawOptions (options ))
18+ if err != nil {
19+ return false , err
20+ }
21+
22+ // 2. return ture if all process success
23+ return true , nil
24+ }
Original file line number Diff line number Diff line change 1+ package apachedevlake
2+
3+ import (
4+ "github.com/mitchellh/mapstructure"
5+
6+ "github.com/devstream-io/devstream/internal/pkg/plugininstaller"
7+ )
8+
9+ // Options is the struct for configurations of the apache-devlake plugin.
10+ type Options struct {
11+ // TODO(dtm): Add your params here.
12+ Foo string
13+ }
14+
15+ // NewOptions create options by raw options
16+ func NewOptions (options plugininstaller.RawOptions ) (Options , error ) {
17+ var opts Options
18+ if err := mapstructure .Decode (options , & opts ); err != nil {
19+ return opts , err
20+ }
21+ return opts , nil
22+ }
Original file line number Diff line number Diff line change 1+ package apachedevlake
2+
3+ import (
4+ "github.com/devstream-io/devstream/internal/pkg/plugininstaller"
5+ "github.com/devstream-io/devstream/internal/pkg/statemanager"
6+ "github.com/devstream-io/devstream/pkg/util/log"
7+ )
8+
9+ func Read (options map [string ]interface {}) (map [string ]interface {}, error ) {
10+ // Initialize Operator with Operations
11+ operator := & plugininstaller.Operator {
12+ PreExecuteOperations : plugininstaller.PreExecuteOperations {
13+ // TODO(dtm): Add your PreExecuteOperations here.
14+ },
15+ GetStateOperation : func (options plugininstaller.RawOptions ) (statemanager.ResourceState , error ) {
16+ // TODO(dtm): Add your GetStateOperation here.
17+ return nil , nil
18+ },
19+ }
20+
21+ // Execute all Operations in Operator
22+ status , err := operator .Execute (plugininstaller .RawOptions (options ))
23+ if err != nil {
24+ return nil , err
25+ }
26+ log .Debugf ("Return map: %v" , status )
27+ return status , nil
28+ }
Original file line number Diff line number Diff line change 1+ package apachedevlake
2+
3+ import (
4+ "github.com/devstream-io/devstream/internal/pkg/plugininstaller"
5+ "github.com/devstream-io/devstream/internal/pkg/statemanager"
6+ "github.com/devstream-io/devstream/pkg/util/log"
7+ )
8+
9+ func Update (options map [string ]interface {}) (map [string ]interface {}, error ) {
10+ // Initialize Operator with Operations
11+ operator := & plugininstaller.Operator {
12+ PreExecuteOperations : plugininstaller.PreExecuteOperations {
13+ // TODO(dtm): Add your PreExecuteOperations here.
14+ },
15+ ExecuteOperations : plugininstaller.ExecuteOperations {
16+ // TODO(dtm): Add your ExecuteOperations here.
17+ },
18+ TerminateOperations : plugininstaller.TerminateOperations {
19+ // TODO(dtm): Add your TerminateOperations here.
20+ },
21+ GetStateOperation : func (options plugininstaller.RawOptions ) (statemanager.ResourceState , error ) {
22+ // TODO(dtm): Add your GetStateOperation here.
23+ return nil , nil
24+ },
25+ }
26+
27+ // Execute all Operations in Operator
28+ status , err := operator .Execute (plugininstaller .RawOptions (options ))
29+ if err != nil {
30+ return nil , err
31+ }
32+ log .Debugf ("Return map: %v" , status )
33+ return status , nil
34+ }
Original file line number Diff line number Diff line change 1+ package apachedevlake
2+
3+ import (
4+ "fmt"
5+
6+ "github.com/devstream-io/devstream/internal/pkg/plugininstaller"
7+ "github.com/devstream-io/devstream/pkg/util/log"
8+ "github.com/devstream-io/devstream/pkg/util/validator"
9+ )
10+
11+ // validate validates the options provided by the core.
12+ func validate (options plugininstaller.RawOptions ) (plugininstaller.RawOptions , error ) {
13+ opts , err := NewOptions (options )
14+ if err != nil {
15+ return nil , err
16+ }
17+ errs := validator .Struct (opts )
18+ if len (errs ) > 0 {
19+ for _ , e := range errs {
20+ log .Errorf ("Options error: %s." , e )
21+ }
22+ return nil , fmt .Errorf ("opts are illegal" )
23+ }
24+ return options , nil
25+ }
You can’t perform that action at this time.
0 commit comments