def create(deployment_path: str, **kwargs): # Late import. import yaml from maro.cli.grass.executors.grass_azure_executor import GrassAzureExecutor from maro.cli.grass.executors.grass_local_executor import GrassLocalExecutor from maro.cli.grass.executors.grass_on_premises_executor import GrassOnPremisesExecutor from maro.utils.exception.cli_exception import BadRequestError, FileOperationError, InvalidDeploymentTemplateError try: with open(deployment_path, "r") as fr: create_deployment = yaml.safe_load(fr) if create_deployment["mode"] == "grass/azure": GrassAzureExecutor.create(create_deployment=create_deployment) elif create_deployment["mode"] == "grass/on-premises": GrassOnPremisesExecutor.create(create_deployment=create_deployment) elif create_deployment["mode"] == "grass/local": executor = GrassLocalExecutor( cluster_name=create_deployment["name"], cluster_details=create_deployment) executor.create() else: raise BadRequestError( f"Unsupported operation in mode '{create_deployment['mode']}'." ) except KeyError as e: raise InvalidDeploymentTemplateError(f"Missing key '{e.args[0]}'.") except FileNotFoundError: raise FileOperationError("Invalid template file path.")
def node_leave(cluster_name: str, node_name: str, **kwargs): cluster_details = load_cluster_details(cluster_name) if cluster_details["mode"] != "grass/on-premises": raise BadRequestError("Node join cluster interrupted: Invalid mode.") executor = GrassOnPremisesExecutor(cluster_name) executor.node_leave_cluster(node_name)
def node_join(node_join_path: str, **kwargs): try: with open(node_join_path, "r") as fr: node_join_info = yaml.safe_load(fr) fr.close() if node_join_info["mode"] != "grass/on-premises": raise BadRequestError( f"Node join cluster interrupted: Invalid mode: {node_join_info['mode']}" ) executor = GrassOnPremisesExecutor(node_join_info["cluster"]) executor.node_join_cluster(node_join_info) except FileNotFoundError: raise FileOperationError("Invalid template file path.")
def delete(cluster_name: str, **kwargs): cluster_details = load_cluster_details(cluster_name=cluster_name) if cluster_details["mode"] == "grass/azure": executor = GrassAzureExecutor(cluster_name=cluster_name) executor.delete() elif cluster_details["mode"] == "grass/on-premises": executor = GrassOnPremisesExecutor(cluster_name=cluster_name) executor.delete() else: raise BadRequestError( f"Unsupported command in mode '{cluster_details['mode']}'.")
def join_cluster(deployment_path: str, **kwargs): # Late import. import yaml from maro.cli.grass.executors.grass_on_premises_executor import GrassOnPremisesExecutor from maro.utils.exception.cli_exception import BadRequestError, FileOperationError, InvalidDeploymentTemplateError try: with open(deployment_path, "r") as fr: join_cluster_deployment = yaml.safe_load(stream=fr) if join_cluster_deployment["mode"] == "grass/on-premises": GrassOnPremisesExecutor.join_cluster( join_cluster_deployment=join_cluster_deployment) else: raise BadRequestError( f"Unsupported operation in mode '{join_cluster_deployment['mode']}'." ) except KeyError as e: raise InvalidDeploymentTemplateError(f"Missing key '{e.args[0]}'.") except FileNotFoundError: raise FileOperationError("Invalid template file path.")
def create(deployment_path: str, **kwargs): try: with open(deployment_path, "r") as fr: create_deployment = yaml.safe_load(fr) if create_deployment["mode"] == "grass/azure": GrassAzureExecutor.build_cluster_details( create_deployment=create_deployment) executor = GrassAzureExecutor( cluster_name=create_deployment["name"]) executor.create() elif create_deployment["mode"] == "grass/on-premises": GrassOnPremisesExecutor.build_cluster_details( create_deployment=create_deployment) executor = GrassOnPremisesExecutor( cluster_name=create_deployment["name"]) executor.create() else: raise BadRequestError( f"Unsupported command in mode '{create_deployment['mode']}'.") except KeyError as e: raise InvalidDeploymentTemplateError(f"Missing key '{e.args[0]}'.") except FileNotFoundError: raise FileOperationError("Invalid template file path.")
def status(cluster_name: str, resource_name: str, **kwargs): # Late import. from maro.cli.grass.executors.grass_azure_executor import GrassAzureExecutor from maro.cli.grass.executors.grass_on_premises_executor import GrassOnPremisesExecutor from maro.cli.utils.details_reader import DetailsReader from maro.utils.exception.cli_exception import BadRequestError cluster_details = DetailsReader.load_cluster_details(cluster_name=cluster_name) if cluster_details["mode"] == "grass/azure": executor = GrassAzureExecutor(cluster_name=cluster_name) executor.status(resource_name=resource_name) elif cluster_details["mode"] == "grass/on-premises": executor = GrassOnPremisesExecutor(cluster_name=cluster_name) executor.status(resource_name=resource_name) else: raise BadRequestError(f"Unsupported operation in mode '{cluster_details['mode']}'.")
def load_executor(cluster_name): if cluster_name == "process": from maro.cli.process.executor import ProcessExecutor executor = ProcessExecutor() cluster_type = DashboardType.PROCESS else: from maro.cli.utils.details_reader import DetailsReader cluster_details = DetailsReader.load_cluster_details( cluster_name=cluster_name) if cluster_details["mode"] == "grass/azure": from maro.cli.grass.executors.grass_azure_executor import GrassAzureExecutor executor = GrassAzureExecutor(cluster_name=cluster_name) cluster_type = DashboardType.AZURE elif cluster_details["mode"] == "grass/on-premises": from maro.cli.grass.executors.grass_on_premises_executor import GrassOnPremisesExecutor executor = GrassOnPremisesExecutor(cluster_name=cluster_name) cluster_type = DashboardType.ONPREMISES elif cluster_details["mode"] == "grass/local": from maro.cli.grass.executors.grass_local_executor import GrassLocalExecutor executor = GrassLocalExecutor(cluster_name=cluster_name) cluster_type = DashboardType.LOCAL return executor, cluster_type
def start_schedule(cluster_name: str, deployment_path: str, **kwargs): # Late import. from maro.cli.grass.executors.grass_azure_executor import GrassAzureExecutor from maro.cli.grass.executors.grass_local_executor import GrassLocalExecutor from maro.cli.grass.executors.grass_on_premises_executor import GrassOnPremisesExecutor from maro.cli.utils.details_reader import DetailsReader from maro.utils.exception.cli_exception import BadRequestError # Load details cluster_details = DetailsReader.load_cluster_details( cluster_name=cluster_name) if cluster_details["mode"] == "grass/azure": executor = GrassAzureExecutor(cluster_name=cluster_name) executor.start_schedule(deployment_path=deployment_path) elif cluster_details["mode"] == "grass/local": executor = GrassLocalExecutor(cluster_name=cluster_name) executor.start_schedule(deployment_path=deployment_path) elif cluster_details["mode"] == "grass/on-premises": executor = GrassOnPremisesExecutor(cluster_name=cluster_name) executor.start_schedule(deployment_path=deployment_path) else: raise BadRequestError( f"Unsupported operation in mode '{cluster_details['mode']}'.")