diff --git a/maestro/cli/commands.py b/maestro/cli/commands.py index c8987dc..076670a 100644 --- a/maestro/cli/commands.py +++ b/maestro/cli/commands.py @@ -17,6 +17,7 @@ from openai import OpenAI from jsonschema.exceptions import ValidationError, SchemaError +from src.deploy import Deploy from src.workflow import Workflow, create_agents from cli.common import Console, parse_yaml @@ -32,13 +33,13 @@ def __init__(self, args): def command(self): if self.args.get('validate') and self.args['validate']: - return Validate(self.args) + return ValidateCmd(self.args) elif self.args.get('create') and self.args['create']: - return Create(self.args) + return CreateCmd(self.args) elif self.args.get('run') and self.args['run']: - return Run(self.args) + return RunCmd(self.args) elif self.args.get('deploy') and self.args['deploy']: - return Deploy(self.args) + return DeployCmd(self.args) else: raise Exception("Invalid command") @@ -97,7 +98,7 @@ def dispatch(self): # validate command group # maestro validate SCHEMA_FILE YAML_FILE [options] -class Validate(Command): +class ValidateCmd(Command): def __init__(self, args): self.args = args super().__init__(self.args) @@ -134,7 +135,7 @@ def validate(self): # Create command group # maestro create AGENTS_FILE [options] -class Create(Command): +class CreateCmd(Command): def __init__(self, args): self.args = args super().__init__(self.args) @@ -163,7 +164,7 @@ def create(self): # Run command group # maestro run AGENTS_FILE WORKFLOW_FILE [options] -class Run(Command): +class RunCmd(Command): def __init__(self, args): self.args = args super().__init__(self.args) @@ -201,14 +202,42 @@ def run(self): # Deploy command group # maestro deploy AGENTS_FILE WORKFLOW_FILE [options] -class Deploy(Command): +class DeployCmd(Command): def __init__(self, args): self.args = args super().__init__(self.args) def __deploy_agents_workflow(self, agents_yaml, workflow_yaml): - # TODO: complete this - pass + bee_api_key = os.getenv("BEE_API_KEY") + bee_api = os.getenv("BEE_API_KEY", "http://192.168.86.45:4000") + + try: + if self.docker(): + deploy = Deploy(agents_yaml, workflow_yaml, bee_api_key, bee_api, self.url()) + deploy.deploy_to_docker() + elif self.k8s(): + deploy = Deploy(agents_yaml, workflow_yaml, ) + deploy.deploy_to_kubernetes() + else: + Console.error("Need to specify --docker or --k8s | --kubernetes") + Console,ok(f"Workflow deployed: {self.url}") + except Exception as e: + self._check_verbose() + raise RuntimeError(f"Unable to run workflow: {str(e)}") from e + return 0 + + def url(self): + if self.args['--url'] == "" or self.args['--url'] == None: + return "127.0.0.1:5000" + return self.args['--url'] + + def k8s(self): + if self.args['--k8s'] != "": + return self.args['--k8s'] + return self.args['--kubernetes'] + + def docker(self): + return self.args['--docker'] def AGENTS_FILE(self): return self.args['AGENTS_FILE'] diff --git a/maestro/cli/maestro.py b/maestro/cli/maestro.py index 5ac6d0a..b17dc61 100755 --- a/maestro/cli/maestro.py +++ b/maestro/cli/maestro.py @@ -26,11 +26,16 @@ maestro (-v | --version) Options: - --verbose Show all output. - --dry-run Mocks agents and other parts of workflow execution. + --verbose Show all output. + --dry-run Mocks agents and other parts of workflow execution. - -h --help Show this screen. - -v --version Show version. + --url The deployment URL, default: 127.0.0.1:5000 + --k8s Deploys to Kubernetes + --kubernetes + --docker Deploys to Docker + + -h --help Show this screen. + -v --version Show version. """ @@ -52,7 +57,7 @@ def __execute(command): return 1 def __run_cli(): - args = docopt(__doc__, version='Maestro CLI v0.0.2') + args = docopt(__doc__, version='Maestro CLI v0.0.3') command = CLI(args).command() rc = __execute(command) sys.exit(rc) diff --git a/maestro/src/workflow.py b/maestro/src/workflow.py index 8b87f67..e72a412 100755 --- a/maestro/src/workflow.py +++ b/maestro/src/workflow.py @@ -79,6 +79,7 @@ def create_or_restore_agents(self, agent_defs, workflow): for agent in workflow["spec"]["template"]["agents"]: self.agents[agent] = restore_agent(agent) + #TODO: why is this public? It should be private by naming: _find_index(...) @aki def find_index(self, steps, name): for step in steps: if step.get("name") == name: diff --git a/maestro/tests/cli/test_commands.py b/maestro/tests/cli/test_commands.py index 6dea176..b5463fc 100755 --- a/maestro/tests/cli/test_commands.py +++ b/maestro/tests/cli/test_commands.py @@ -38,6 +38,10 @@ def setUp(self): '--help': False, '--verbose': False, '--version': False, + '--url': "127.0.0.1:5000", + '--k8s': False, + '--kubernetes': False, + '--docker': False, 'AGENTS_FILE': self.get_fixture('yamls/agents/simple_agent.yaml'), 'SCHEMA_FILE': None, 'WORKFLOW_FILE': self.get_fixture('yamls/workflows/simple_workflow.yaml'), @@ -53,9 +57,22 @@ def tearDown(self): self.args = {} self.command = None - def test_deploy__dry_run(self): + def test_deploy__dry_run_k8s(self): + self.args["--k8s"] = True + self.command = CLI(self.args).command() + self.assertTrue(self.command.name() == 'deploy') + self.assertTrue(self.command.execute() == 0) + + def test_deploy__dry_run_kubernetes(self): + self.args["--kubernetes"] = True + self.command = CLI(self.args).command() + self.assertTrue(self.command.name() == 'deploy') + self.assertTrue(self.command.execute() == 0) + + def test_deploy__dry_run_docker(self): + self.args["--docker"] = True + self.command = CLI(self.args).command() self.assertTrue(self.command.name() == 'deploy') - #TODO: complete test for deploy and check deployment server self.assertTrue(self.command.execute() == 0) # `run` commmand tests