Skip to content

Commit

Permalink
remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Leader committed Oct 31, 2023
1 parent de794a2 commit b794404
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 178 deletions.
50 changes: 24 additions & 26 deletions internal/step/plugin/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,26 @@ const errorStr = "error"
// For more info, see `config/schema.go`
func New(logger log.Logger, deployerRegistry registry.Registry, localDeployerConfigs map[string]any) (step.Provider, error) {
localDeployers := make(map[deployer.DeploymentType]deployer.Connector)

Check failure on line 30 in internal/step/plugin/provider.go

View workflow job for this annotation

GitHub Actions / go test

undefined: deployer.DeploymentType
for _, deploymentType := range deployerRegistry.DeploymentTypes() {
_, configHasType := localDeployerConfigs[string(deploymentType)]
if !configHasType {
logger.Infof("Config does not have config for deployment type '%s'. This type will not be usable.", deploymentType)
continue
}
localDeployerConfig, configPresent := localDeployerConfigs[string(deploymentType)]
var unserializedLocalDeployerConfig any
var err error
if configPresent {
unserializedLocalDeployerConfig, err = deployerRegistry.DeployConfigSchema(deploymentType).Unserialize(localDeployerConfig)
if err != nil {
return nil, fmt.Errorf("failed to load local deployer configuration, please check your Arcaflow configuration file (%w)", err)
}
} else {
logger.Warningf("No deployer configuration for type '%s' (%w). The workflow will fail if this type is needed",
deploymentType, err)

// Build local deployers from requested deployers in engine workflow config.
for reqDeploymentType, deployerConfig := range localDeployerConfigs {
reqDeploymentTypeType := deployer.DeploymentType(reqDeploymentType)

Check failure on line 34 in internal/step/plugin/provider.go

View workflow job for this annotation

GitHub Actions / go test

undefined: deployer.DeploymentType
// Unserialize config using deployer's schema in registry.
// This will return an error if the requested deployment type
// is not in the registry.
unserializedLocalDeployerConfig, err := deployerRegistry.DeployConfigSchema(

Check failure on line 38 in internal/step/plugin/provider.go

View workflow job for this annotation

GitHub Actions / go test

deployerRegistry.DeployConfigSchema undefined (type registry.Registry has no field or method DeployConfigSchema)
reqDeploymentTypeType).Unserialize(deployerConfig)
if err != nil {
return nil, fmt.Errorf("failed to load requested deployer type %s from workflow config (%w)",
reqDeploymentType, err)
}

localDeployer, err := deployerRegistry.Create(deploymentType, unserializedLocalDeployerConfig, logger.WithLabel("source", "deployer"))
localDeployer, err := deployerRegistry.Create(reqDeploymentTypeType,
unserializedLocalDeployerConfig, logger.WithLabel("source", "deployer"))
if err != nil {
return nil, fmt.Errorf("invalid local deployer configuration, please check your Arcaflow configuration file (%w)", err)
}
localDeployers[deploymentType] = localDeployer
localDeployers[reqDeploymentTypeType] = localDeployer
}

return &pluginProvider{
Expand Down Expand Up @@ -79,10 +75,10 @@ var DeploymentTypes = map[string]struct{}{
"python": struct{}{},
}

func KeysString(m map[string]struct{}) string {
func KeysString(m []deployer.DeploymentType) string {

Check failure on line 78 in internal/step/plugin/provider.go

View workflow job for this annotation

GitHub Actions / go test

undefined: deployer.DeploymentType
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
for _, k := range m {
keys = append(keys, string(k))
}
return "[" + strings.Join(keys, ", ") + "]"
}
Expand Down Expand Up @@ -115,8 +111,8 @@ func (p *pluginProvider) ProviderSchema() map[string]*schema.PropertySchema {
schema.NewDisplayValue(
schema.PointerTo("Type"),
schema.PointerTo(
fmt.Sprintf("Deployment type %s",
fmt.Sprintf(KeysString(DeploymentTypes)))),
fmt.Sprintf("Deployment type [%s]",
fmt.Sprintf(KeysString(p.deployerRegistry.DeploymentTypes()), ","))),

Check failure on line 115 in internal/step/plugin/provider.go

View workflow job for this annotation

GitHub Actions / go test

p.deployerRegistry.DeploymentTypes undefined (type registry.Registry has no field or method DeploymentTypes)
nil,
),
true,
Expand Down Expand Up @@ -266,8 +262,10 @@ func (p *pluginProvider) LoadSchema(inputs map[string]any, _ map[string][]byte)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

applicableLocalDeployer := p.localDeployers[requestedDeploymentType]

applicableLocalDeployer, ok := p.localDeployers[requestedDeploymentType]
if !ok {
return nil, fmt.Errorf("missing local deployer for requested type %s", requestedDeploymentType)
}
plugin_connector, err := applicableLocalDeployer.Deploy(ctx, pluginSource)
if err != nil {
cancel()
Expand Down
96 changes: 35 additions & 61 deletions internal/step/plugin/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
deployer_registry "go.flow.arcalot.io/deployer/registry"
"go.flow.arcalot.io/engine/internal/step"
"go.flow.arcalot.io/engine/internal/step/plugin"

Check failure on line 10 in internal/step/plugin/provider_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

could not import go.flow.arcalot.io/engine/internal/step/plugin (-: # go.flow.arcalot.io/engine/internal/step/plugin
python "go.flow.arcalot.io/pythondeployer"
testdeployer "go.flow.arcalot.io/testdeployer"
"sync"
"testing"
Expand Down Expand Up @@ -118,7 +119,8 @@ func TestProvider_MultipleDeployers(t *testing.T) {
},
)
deployerRegistry := deployer_registry.New(
deployer.Any(testdeployer.NewFactory()))
deployer.Any(testdeployer.NewFactory()),
deployer.Any(python.NewFactory()))
deployTimeMs := 20
workflowDeployerCfg := map[string]any{
"builtin": map[string]any{
Expand All @@ -127,15 +129,11 @@ func TestProvider_MultipleDeployers(t *testing.T) {
"deploy_succeed": true,
},
"python": map[string]any{
"deployer_id": "test-impl",
"deployer_id": "python",
},
}

plp, err := plugin.New(
logger,
deployerRegistry,
workflowDeployerCfg,
)
plp, err := plugin.New(logger, deployerRegistry, workflowDeployerCfg)
assert.NoError(t, err)
assert.Equals(t, plp.Kind(), "plugin")
assert.NotNil(t, plp.ProviderSchema())
Expand Down Expand Up @@ -171,17 +169,13 @@ func TestProvider_Utility(t *testing.T) {
"builtin": map[string]any{"deployer_id": "test-impl"},
}

plp, err := plugin.New(
log.New(
log.Config{
Level: log.LevelError,
Destination: log.DestinationStdout,
},
),
deployer_registry.New(
deployer.Any(testdeployer.NewFactory())),
workflowDeployerCfg,
)
plp, err := plugin.New(log.New(
log.Config{
Level: log.LevelError,
Destination: log.DestinationStdout,
},
), deployer_registry.New(
deployer.Any(testdeployer.NewFactory())), workflowDeployerCfg)
assert.NoError(t, err)
assert.Equals(t, plp.Kind(), "plugin")
assert.NotNil(t, plp.ProviderSchema())
Expand Down Expand Up @@ -227,31 +221,19 @@ func TestProvider_HappyError(t *testing.T) {
deployerRegistry := deployer_registry.New(
deployer.Any(testdeployer.NewFactory()))

_, err := plugin.New(
logger,
deployerRegistry,
map[string]any{
"wrong": map[string]any{
"deployer_id": "test-impl",
}},
)
_, err := plugin.New(logger, deployerRegistry, map[string]any{
"wrong": map[string]any{
"deployer_id": "test-impl",
}})
assert.Error(t, err)

_, err = plugin.New(
logger,
deployerRegistry,
map[string]any{
"builtin": map[string]any{
"deployer_id": "bad",
}},
)
_, err = plugin.New(logger, deployerRegistry, map[string]any{
"builtin": map[string]any{
"deployer_id": "bad",
}})
assert.Error(t, err)

plp, err := plugin.New(
logger,
deployerRegistry,
workflowDeployerCfg,
)
plp, err := plugin.New(logger, deployerRegistry, workflowDeployerCfg)
assert.NoError(t, err)

stepSchema := map[string]any{
Expand Down Expand Up @@ -358,11 +340,7 @@ func TestProvider_VerifyCancelSignal(t *testing.T) {
deployerRegistry := deployer_registry.New(
deployer.Any(testdeployer.NewFactory()))

plp, err := plugin.New(
logger,
deployerRegistry,
workflowDeployerCfg,
)
plp, err := plugin.New(logger, deployerRegistry, workflowDeployerCfg)
assert.NoError(t, err)

runnable, err := plp.LoadSchema(
Expand Down Expand Up @@ -413,16 +391,14 @@ func TestProvider_DeployFail(t *testing.T) {
deployer.Any(testdeployer.NewFactory()))
deployTimeMs := 20
workflowDeployerCfg := map[string]any{
"builtin": map[string]any{"deployer_id": "test-impl"},
"deploy_time": deployTimeMs,
"deploy_succeed": true,
"builtin": map[string]any{
"deployer_id": "test-impl",
"deploy_time": deployTimeMs,
"deploy_succeed": true,
},
}

plp, err := plugin.New(
logger,
deployerRegistry,
workflowDeployerCfg,
)
plp, err := plugin.New(logger, deployerRegistry, workflowDeployerCfg)
assert.NoError(t, err)

stepSchema := map[string]any{
Expand Down Expand Up @@ -484,17 +460,15 @@ func TestProvider_StartFail(t *testing.T) {
)
deployTimeMs := 20
workflowDeployerCfg := map[string]any{
"builtin": map[string]any{"deployer_id": "test-impl"},
"deploy_time": deployTimeMs,
"deploy_succeed": true,
"builtin": map[string]any{
"deployer_id": "test-impl",
"deploy_time": deployTimeMs,
"deploy_succeed": true,
},
}

plp, err := plugin.New(
logger,
deployer_registry.New(
deployer.Any(testdeployer.NewFactory())),
workflowDeployerCfg,
)
plp, err := plugin.New(logger, deployer_registry.New(
deployer.Any(testdeployer.NewFactory())), workflowDeployerCfg)
assert.NoError(t, err)

stepSchema := map[string]any{
Expand Down
88 changes: 3 additions & 85 deletions new.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package engine

import (
"fmt"
log "go.arcalot.io/log/v2"
"go.flow.arcalot.io/deployer"
"go.flow.arcalot.io/deployer/registry"
docker "go.flow.arcalot.io/dockerdeployer"
"go.flow.arcalot.io/engine/config"
kubernetes "go.flow.arcalot.io/kubernetesdeployer"
podman "go.flow.arcalot.io/podmandeployer"
python "go.flow.arcalot.io/pythondeployer"
testimpl "go.flow.arcalot.io/testdeployer"
)

// New creates a new workflow engine with the provided configuration. The passed deployerRegistry is responsible for
Expand All @@ -19,22 +11,9 @@ func New(
config *config.Config,
) (WorkflowEngine, error) {
logger := log.New(config.Log)
// TODO: Create new registry function
// need to build/create new deployer registry based on
// deployer_ids in config.LocalDeployers
// use registry.Create and its reflection as inspo
//for key, value := range config.LocalDeployers {
//
//}
reg, err := BuildRegistry(config.LocalDeployers)
if err != nil {
return nil, err
}
stepRegistry, err := NewDefaultStepRegistry(
logger,
reg,
config,
)

stepRegistry, err := NewDefaultStepRegistry(logger,
DefaultDeployerRegistry, config)
if err != nil {
return nil, err
}
Expand All @@ -44,64 +23,3 @@ func New(
stepRegistry: stepRegistry,
}, nil
}

func BuildRegistry(config map[string]any) (registry.Registry, error) {
if config == nil {
return nil, fmt.Errorf("the deployer configuration cannot be nil")
}

factories := make([]deployer.AnyConnectorFactory, 0)

//workshops := make([]deployer.AnyConnectorFactory, 0)

for deploymentType, value := range config {
schemas := DefaultDeployerRegistry.DeployConfigSchema(deployer.DeploymentType(deploymentType))
//v2 := make(map[string]any)
//for k, v := range value.(map[any]any) {
// v2[k.(string)] = v
//}

//var f deployer.AnyConnectorFactory
//switch v2[schemas.DiscriminatorFieldName()] {
//case "docker":
// f = deployer.Any(docker.NewFactory())
//case "podman":
// f = deployer.Any(podman.NewFactory())
//case "kubernetes":
// f = deployer.Any(kubernetes.NewFactory())
//case "python":
// f = deployer.Any(python.NewFactory())
//}
//
//factories = append(factories, f)

unserializedConfig, err := schemas.Unserialize(value)
if err != nil {
return nil, err
}

//fmt.Printf("%v\n", unserializedConfig.(*docker.Config))
//var f2 deployer.AnyConnectorFactory
switch unserializedConfig.(type) {
case *docker.Config:
//f2 = deployer.Any(docker.NewFactory())
factories = append(factories, deployer.Any(docker.NewFactory()))
case *podman.Config:
//f2 = deployer.Any(podman.NewFactory())
factories = append(factories, deployer.Any(podman.NewFactory()))
case *kubernetes.Config:
//f2 = deployer.Any(kubernetes.NewFactory())
factories = append(factories, deployer.Any(kubernetes.NewFactory()))
case *python.Config:
//f2 = deployer.Any(python.NewFactory())
factories = append(factories, deployer.Any(python.NewFactory()))
default: // deployer stub config
factories = append(factories, deployer.Any(testimpl.NewFactory()))
}

//workshops = append(workshops, f2)
//factories = append(factories, f2)
}

return registry.New(factories...), nil
}
7 changes: 1 addition & 6 deletions steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package engine

import (
"fmt"

"go.arcalot.io/log/v2"
deployerRegistry "go.flow.arcalot.io/deployer/registry"
"go.flow.arcalot.io/engine/config"
Expand All @@ -14,11 +13,7 @@ import (
)

// NewDefaultStepRegistry creates a registry with the default step types applied.
func NewDefaultStepRegistry(
logger log.Logger,
deployerRegistry deployerRegistry.Registry,
config *config.Config,
) (step.Registry, error) {
func NewDefaultStepRegistry(logger log.Logger, deployerRegistry deployerRegistry.Registry, config *config.Config) (step.Registry, error) {
pluginProvider, err := plugin.New(logger, deployerRegistry, config.LocalDeployers)
if err != nil {
return nil, fmt.Errorf("failed to create plugin step provider (%w)", err)
Expand Down

0 comments on commit b794404

Please sign in to comment.