Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdk-376: Adding support for multiple API versions in clusters #284

Merged
merged 24 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cluster v2 changes
  • Loading branch information
Tarun Goyal committed Sep 30, 2019
commit 9ca11df90754dd3b85a09a67ece20a85cf007d56
108 changes: 108 additions & 0 deletions qds_sdk/cluster_cmd_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from qds_sdk.qubole import Qubole
from qds_sdk.resource import Resource
from qds_sdk.cloud.cloud import Cloud
from qds_sdk.engine import Engine
from qds_sdk import util
import argparse
import json

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 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 = cluster_info_factory.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 = cluster_info_factory.get_cluster_info_cls()
cluster_info_obj.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):
customer_ssh_key = util._read_file(arguments.customer_ssh_key_file)
# This will set cluster info and monitoring settings
cluster_info_cls = cluster_info_factory.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
20 changes: 20 additions & 0 deletions qds_sdk/cluster_info_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from qds_sdk.qubole import Qubole
from qds_sdk.clusterv2 import ClusterInfoV2
from qds_sdk.cluster_info_v22 import ClusterInfoV22

class ClusterInfoFactory:

@staticmethod
def get_cluster_info_cls(api_version=None):
if api_version is None:
api_version = Qubole.get_api_version()

if api_version == 2.0:
return ClusterInfoV2
elif api_version == 2.2:
return ClusterInfoV22
else:
return ClusterInfoV2



Loading