Skip to content

Commit

Permalink
SDK-376: Revert the refactoring of cluster_cmd_line (#286)
Browse files Browse the repository at this point in the history
Revert the refactoring of cluster_cmd_line
  • Loading branch information
tarrygo authored and chattarajoy committed Nov 12, 2019
1 parent 4075523 commit ab247ba
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 128 deletions.
2 changes: 1 addition & 1 deletion bin/qds.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from qds_sdk.nezha import NezhaCmdLine
from qds_sdk.user import UserCmdLine
from qds_sdk.template import TemplateCmdLine
from qds_sdk.cluster_cmd_line import ClusterCmdLine
from qds_sdk.clusterv2 import ClusterCmdLine
from qds_sdk.sensors import *
import os
import sys
Expand Down
110 changes: 0 additions & 110 deletions qds_sdk/cluster_cmd_line.py

This file was deleted.

17 changes: 0 additions & 17 deletions qds_sdk/cluster_info_factory.py

This file was deleted.

114 changes: 114 additions & 0 deletions qds_sdk/clusterv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from qds_sdk.resource import Resource
from qds_sdk.cloud.cloud import Cloud
from qds_sdk.engine import Engine
from qds_sdk.cluster_info_v22 import ClusterInfoV22
from qds_sdk import util
import argparse
import json
Expand All @@ -10,6 +11,119 @@
def str2bool(v):
return v.lower() in ("yes", "true", "t", "1")

class ClusterCmdLine:

@staticmethod
def parsers(action):
argparser = argparse.ArgumentParser(
prog="qds.py cluster",
description="Cluster Operations for Qubole Data Service.")
subparsers = argparser.add_subparsers(title="Cluster operations")
if Qubole.version is not None:
ClusterV2.api_version = Qubole.version
if action == "create":
create = subparsers.add_parser("create", help="Create a new cluster")
ClusterCmdLine.create_update_clone_parser(create, action="create")
create.set_defaults(func=ClusterV2.create)

if action == "update":
update = subparsers.add_parser("update", help="Update the settings of an existing cluster")
ClusterCmdLine.create_update_clone_parser(update, action="update")
update.set_defaults(func=ClusterV2.update)

if action == "clone":
clone = subparsers.add_parser("clone", help="Clone a cluster from an existing one")
ClusterCmdLine.create_update_clone_parser(clone, action="clone")
clone.set_defaults(func=ClusterV2.clone)

if action == "list":
li = subparsers.add_parser("list", help="list clusters from existing clusters depending upon state")
ClusterCmdLine.list_parser(li, action="list")
li.set_defaults(func=ClusterV2.list)
return argparser

@staticmethod
def list_parser(subparser, action=None, ):

# cluster info parser
cluster_info_cls = ClusterInfoFactory.get_cluster_info_cls()
cluster_info_cls.list_info_parser(subparser, action)

@staticmethod
def create_update_clone_parser(subparser, action=None):
# cloud config parser
cloud = Qubole.get_cloud()
cloud.create_parser(subparser)

# cluster info parser
cluster_info_cls = ClusterInfoFactory.get_cluster_info_cls()
cluster_info_cls.cluster_info_parser(subparser, action)

# engine config parser
Engine.engine_parser(subparser)

@staticmethod
def run(args):
parser = ClusterCmdLine.parsers(args[0])
arguments = parser.parse_args(args)
if args[0] in ["create", "clone", "update"]:
ClusterCmdLine.get_cluster_create_clone_update(arguments, args[0])
else:
return arguments.func(arguments.label, arguments.cluster_id, arguments.state,
arguments.page, arguments.per_page)

@staticmethod
def get_cluster_create_clone_update(arguments, action):

# This will set cluster info and monitoring settings
cluster_info_cls = ClusterInfoFactory.get_cluster_info_cls()
cluster_info = cluster_info_cls(arguments.label)
cluster_info.set_cluster_info_from_arguments(arguments)

# This will set cloud config settings
cloud_config = Qubole.get_cloud()
cloud_config.set_cloud_config_from_arguments(arguments)

# This will set engine settings
engine_config = Engine(flavour=arguments.flavour)
engine_config.set_engine_config_settings(arguments)
cluster_request = ClusterCmdLine.get_cluster_request_parameters(cluster_info, cloud_config, engine_config)

action = action
if action == "create":
return arguments.func(cluster_request)
else:
return arguments.func(arguments.cluster_id_label, cluster_request)

@staticmethod
def get_cluster_request_parameters(cluster_info, cloud_config, engine_config):
'''
Use this to return final minimal request from cluster_info, cloud_config or engine_config objects
Alternatively call util._make_minimal if only one object needs to be implemented
'''

cluster_request = {}
cloud_config = util._make_minimal(cloud_config.__dict__)
if bool(cloud_config): cluster_request['cloud_config'] = cloud_config

engine_config = util._make_minimal(engine_config.__dict__)
if bool(engine_config): cluster_request['engine_config'] = engine_config

cluster_request.update(util._make_minimal(cluster_info.__dict__))
return cluster_request

class ClusterInfoFactory:

@staticmethod
def get_cluster_info_cls(api_version=None):
if api_version is None:
api_version = Qubole.version
if api_version == "v2":
return ClusterInfoV2
elif api_version == "v2.2":
return ClusterInfoV22
else:
return ClusterInfoV2

class ClusterInfoV2(object):
"""
Expand Down

0 comments on commit ab247ba

Please sign in to comment.