From ca5294a801104fa5ea859b7b3762ba2f4c5e607b Mon Sep 17 00:00:00 2001 From: Artem Osadchyi Date: Wed, 30 Sep 2015 17:25:22 +0300 Subject: [PATCH] Removed redundant metaclass declarations in MapR plugin Change-Id: Ifad8f7521be49c5564f43e6df78f2d49fb753ba0 Implements: blueprint mapr-refactor-singleton --- sahara/plugins/mapr/domain/service.py | 12 +++--------- sahara/plugins/mapr/services/drill/drill.py | 7 ------- sahara/plugins/mapr/services/flume/flume.py | 3 --- sahara/plugins/mapr/services/hbase/hbase.py | 6 ------ sahara/plugins/mapr/services/hive/hive.py | 3 --- sahara/plugins/mapr/services/httpfs/httpfs.py | 3 --- sahara/plugins/mapr/services/hue/hue.py | 5 ----- sahara/plugins/mapr/services/impala/impala.py | 3 --- sahara/plugins/mapr/services/mahout/mahout.py | 5 ----- .../plugins/mapr/services/management/management.py | 3 --- sahara/plugins/mapr/services/mapreduce/mapreduce.py | 3 --- sahara/plugins/mapr/services/maprfs/maprfs.py | 2 -- sahara/plugins/mapr/services/mysql/mysql.py | 1 - sahara/plugins/mapr/services/oozie/oozie.py | 4 ---- sahara/plugins/mapr/services/pig/pig.py | 5 ----- sahara/plugins/mapr/services/spark/spark.py | 1 - sahara/plugins/mapr/services/sqoop/sqoop2.py | 3 --- sahara/plugins/mapr/services/swift/swift.py | 2 -- sahara/plugins/mapr/services/yarn/yarn.py | 5 ----- sahara/plugins/mapr/util/general.py | 11 +++++++++++ 20 files changed, 14 insertions(+), 73 deletions(-) diff --git a/sahara/plugins/mapr/domain/service.py b/sahara/plugins/mapr/domain/service.py index 6e1abd59..8f30a02c 100644 --- a/sahara/plugins/mapr/domain/service.py +++ b/sahara/plugins/mapr/domain/service.py @@ -14,11 +14,13 @@ from oslo_serialization import jsonutils as json +import six from sahara import context import sahara.exceptions as e from sahara.i18n import _ import sahara.plugins.exceptions as ex +from sahara.plugins.mapr.util import general as g from sahara.plugins.mapr.util import service_utils as su import sahara.plugins.provisioning as p from sahara.utils import files as files @@ -26,6 +28,7 @@ from sahara.utils import files as files _INSTALL_PACKAGES_TIMEOUT = 3600 +@six.add_metaclass(g.Singleton) class Service(object): def __init__(self): self._name = None @@ -219,12 +222,3 @@ class Service(object): def post_configure_sh(self, cluster_context, instances): pass - - -class Single(type): - _instances = {} - - def __call__(cls, *args, **kwargs): - if cls not in cls._instances: - cls._instances[cls] = super(Single, cls).__call__(*args, **kwargs) - return cls._instances[cls] diff --git a/sahara/plugins/mapr/services/drill/drill.py b/sahara/plugins/mapr/services/drill/drill.py index d6560030..c39604dc 100644 --- a/sahara/plugins/mapr/services/drill/drill.py +++ b/sahara/plugins/mapr/services/drill/drill.py @@ -13,8 +13,6 @@ # under the License. -import six - import sahara.plugins.mapr.domain.node_process as np import sahara.plugins.mapr.domain.service as s import sahara.plugins.mapr.util.commands as cmd @@ -29,7 +27,6 @@ DRILL = np.NodeProcess( ) -@six.add_metaclass(s.Single) class Drill(s.Service): def __init__(self): super(Drill, self).__init__() @@ -51,28 +48,24 @@ class Drill(s.Service): cmd.re_configure_sh(instance, cluster_context) -@six.add_metaclass(s.Single) class DrillV07(Drill): def __init__(self): super(DrillV07, self).__init__() self._version = '0.7' -@six.add_metaclass(s.Single) class DrillV08(Drill): def __init__(self): super(DrillV08, self).__init__() self._version = '0.8' -@six.add_metaclass(s.Single) class DrillV09(Drill): def __init__(self): super(DrillV09, self).__init__() self._version = '0.9' -@six.add_metaclass(s.Single) class DrillV11(Drill): def __init__(self): super(DrillV11, self).__init__() diff --git a/sahara/plugins/mapr/services/flume/flume.py b/sahara/plugins/mapr/services/flume/flume.py index de4b30e1..8844a63f 100755 --- a/sahara/plugins/mapr/services/flume/flume.py +++ b/sahara/plugins/mapr/services/flume/flume.py @@ -13,8 +13,6 @@ # under the License. -import six - import sahara.plugins.mapr.domain.node_process as np import sahara.plugins.mapr.domain.service as s import sahara.plugins.mapr.util.validation_utils as vu @@ -28,7 +26,6 @@ FLUME = np.NodeProcess( ) -@six.add_metaclass(s.Single) class Flume(s.Service): def __init__(self): super(Flume, self).__init__() diff --git a/sahara/plugins/mapr/services/hbase/hbase.py b/sahara/plugins/mapr/services/hbase/hbase.py index e1bc2a10..fe93f009 100644 --- a/sahara/plugins/mapr/services/hbase/hbase.py +++ b/sahara/plugins/mapr/services/hbase/hbase.py @@ -13,8 +13,6 @@ # under the License. -import six - import sahara.plugins.mapr.domain.configuration_file as bcf import sahara.plugins.mapr.domain.node_process as np import sahara.plugins.mapr.domain.service as s @@ -75,7 +73,6 @@ class HBase(s.Service): return [hbase_site] -@six.add_metaclass(s.Single) class HBaseV094(HBase): def __init__(self): super(HBaseV094, self).__init__() @@ -83,7 +80,6 @@ class HBaseV094(HBase): self._dependencies = [('mapr-hbase', self.version)] -@six.add_metaclass(s.Single) class HBaseV0987(HBase): def __init__(self): super(HBaseV0987, self).__init__() @@ -91,7 +87,6 @@ class HBaseV0987(HBase): self._dependencies = [('mapr-hbase', self.version)] -@six.add_metaclass(s.Single) class HBaseV0989(HBase): def __init__(self): super(HBaseV0989, self).__init__() @@ -103,7 +98,6 @@ class HBaseV0989(HBase): ) -@six.add_metaclass(s.Single) class HBaseV09812(HBase): def __init__(self): super(HBaseV09812, self).__init__() diff --git a/sahara/plugins/mapr/services/hive/hive.py b/sahara/plugins/mapr/services/hive/hive.py index 7c5c7866..46d7238f 100644 --- a/sahara/plugins/mapr/services/hive/hive.py +++ b/sahara/plugins/mapr/services/hive/hive.py @@ -14,7 +14,6 @@ from oslo_log import log as logging -import six import sahara.plugins.mapr.domain.configuration_file as bcf import sahara.plugins.mapr.domain.node_process as np @@ -121,7 +120,6 @@ class Hive(s.Service): return self.SCHEMA_PATH_TEMPLATE % args -@six.add_metaclass(s.Single) class HiveV013(Hive): def __init__(self): super(HiveV013, self).__init__() @@ -129,7 +127,6 @@ class HiveV013(Hive): self._dependencies = [('mapr-hive', self.version)] -@six.add_metaclass(s.Single) class HiveV10(Hive): def __init__(self): super(HiveV10, self).__init__() diff --git a/sahara/plugins/mapr/services/httpfs/httpfs.py b/sahara/plugins/mapr/services/httpfs/httpfs.py index 74f51867..b896c3d4 100644 --- a/sahara/plugins/mapr/services/httpfs/httpfs.py +++ b/sahara/plugins/mapr/services/httpfs/httpfs.py @@ -13,8 +13,6 @@ # under the License. -import six - import sahara.plugins.mapr.domain.node_process as np import sahara.plugins.mapr.domain.service as s import sahara.plugins.mapr.util.commands as cmd @@ -29,7 +27,6 @@ HTTP_FS = np.NodeProcess( ) -@six.add_metaclass(s.Single) class HttpFS(s.Service): def __init__(self): super(HttpFS, self).__init__() diff --git a/sahara/plugins/mapr/services/hue/hue.py b/sahara/plugins/mapr/services/hue/hue.py index 450ecf4b..ffdd7b9a 100755 --- a/sahara/plugins/mapr/services/hue/hue.py +++ b/sahara/plugins/mapr/services/hue/hue.py @@ -18,7 +18,6 @@ import random import string from oslo_log import log as logging -import six import sahara.plugins.mapr.domain.configuration_file as bcf import sahara.plugins.mapr.domain.node_process as np @@ -53,7 +52,6 @@ HUE_LIVY = np.NodeProcess( ) -@six.add_metaclass(s.Single) class Hue(s.Service): def __init__(self): super(Hue, self).__init__() @@ -208,21 +206,18 @@ class Hue(s.Service): return ''.join(generator.choice(ascii_alphanum) for _ in range(length)) -@six.add_metaclass(s.Single) class HueV360(Hue): def __init__(self): super(HueV360, self).__init__() self._version = '3.6.0' -@six.add_metaclass(s.Single) class HueV370(Hue): def __init__(self): super(HueV370, self).__init__() self._version = '3.7.0' -@six.add_metaclass(s.Single) class HueV381(Hue): def __init__(self): super(HueV381, self).__init__() diff --git a/sahara/plugins/mapr/services/impala/impala.py b/sahara/plugins/mapr/services/impala/impala.py index 98f77c90..cdc61cce 100755 --- a/sahara/plugins/mapr/services/impala/impala.py +++ b/sahara/plugins/mapr/services/impala/impala.py @@ -13,8 +13,6 @@ # under the License. -import six - import sahara.plugins.mapr.domain.configuration_file as bcf import sahara.plugins.mapr.domain.node_process as np import sahara.plugins.mapr.domain.service as s @@ -76,7 +74,6 @@ class Impala(s.Service): cmd.chown(instance, 'mapr:mapr', self.service_dir(cluster_context)) -@six.add_metaclass(s.Single) class ImpalaV141(Impala): def __init__(self): super(ImpalaV141, self).__init__() diff --git a/sahara/plugins/mapr/services/mahout/mahout.py b/sahara/plugins/mapr/services/mahout/mahout.py index aec89636..b9712294 100644 --- a/sahara/plugins/mapr/services/mahout/mahout.py +++ b/sahara/plugins/mapr/services/mahout/mahout.py @@ -13,8 +13,6 @@ # under the License. -import six - import sahara.plugins.mapr.domain.node_process as np import sahara.plugins.mapr.domain.service as s import sahara.plugins.mapr.util.validation_utils as vu @@ -27,7 +25,6 @@ MAHOUT = np.NodeProcess( ) -@six.add_metaclass(s.Single) class Mahout(s.Service): def __init__(self): super(Mahout, self).__init__() @@ -37,14 +34,12 @@ class Mahout(s.Service): self._validation_rules = [vu.at_least(1, MAHOUT)] -@six.add_metaclass(s.Single) class MahoutV09(Mahout): def __init__(self): super(MahoutV09, self).__init__() self._version = '0.9' -@six.add_metaclass(s.Single) class MahoutV010(Mahout): def __init__(self): super(MahoutV010, self).__init__() diff --git a/sahara/plugins/mapr/services/management/management.py b/sahara/plugins/mapr/services/management/management.py index 0ed08f92..a445e1c7 100644 --- a/sahara/plugins/mapr/services/management/management.py +++ b/sahara/plugins/mapr/services/management/management.py @@ -13,8 +13,6 @@ # under the License. -import six - import sahara.plugins.mapr.domain.node_process as np import sahara.plugins.mapr.domain.service as s import sahara.plugins.mapr.util.validation_utils as vu @@ -44,7 +42,6 @@ METRICS = np.NodeProcess( ) -@six.add_metaclass(s.Single) class Management(s.Service): def __init__(self): super(Management, self).__init__() diff --git a/sahara/plugins/mapr/services/mapreduce/mapreduce.py b/sahara/plugins/mapr/services/mapreduce/mapreduce.py index d01d1f3e..c2b1b6e8 100644 --- a/sahara/plugins/mapr/services/mapreduce/mapreduce.py +++ b/sahara/plugins/mapr/services/mapreduce/mapreduce.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - import sahara.plugins.mapr.domain.configuration_file as bcf import sahara.plugins.mapr.domain.node_process as np import sahara.plugins.mapr.domain.service as s @@ -42,7 +40,6 @@ JACKSON_MAPPER_ASL = ('plugins/mapr/services/swift/resources/' 'jackson-mapper-asl-1.9.13.jar') -@six.add_metaclass(s.Single) class MapReduce(s.Service): cluster_mode = 'classic' diff --git a/sahara/plugins/mapr/services/maprfs/maprfs.py b/sahara/plugins/mapr/services/maprfs/maprfs.py index bea23fe3..2b2d5a7a 100644 --- a/sahara/plugins/mapr/services/maprfs/maprfs.py +++ b/sahara/plugins/mapr/services/maprfs/maprfs.py @@ -14,7 +14,6 @@ from oslo_log import log as logging -import six from sahara import context from sahara.i18n import _ @@ -50,7 +49,6 @@ NFS = np.NodeProcess( ) -@six.add_metaclass(s.Single) class MapRFS(s.Service): _CREATE_DISK_LIST = 'plugins/mapr/resources/create_disk_list_file.sh' _DISK_SETUP_CMD = '/opt/mapr/server/disksetup -F /tmp/disk.list' diff --git a/sahara/plugins/mapr/services/mysql/mysql.py b/sahara/plugins/mapr/services/mysql/mysql.py index 578ab102..e4eae915 100644 --- a/sahara/plugins/mapr/services/mysql/mysql.py +++ b/sahara/plugins/mapr/services/mysql/mysql.py @@ -30,7 +30,6 @@ LOG = logging.getLogger(__name__) db_spec = c.namedtuple('DatabaseSpec', ['db_name', 'user', 'password']) -@six.add_metaclass(s.Single) class MySQL(s.Service): METRICS_SPECS = db_spec('metrics', 'maprmetrics', 'mapr') HUE_SPECS = db_spec('hue', 'maprhue', 'mapr') diff --git a/sahara/plugins/mapr/services/oozie/oozie.py b/sahara/plugins/mapr/services/oozie/oozie.py index 22e87246..eefda6d6 100644 --- a/sahara/plugins/mapr/services/oozie/oozie.py +++ b/sahara/plugins/mapr/services/oozie/oozie.py @@ -14,7 +14,6 @@ from oslo_log import log as logging -import six import sahara.plugins.mapr.domain.configuration_file as bcf import sahara.plugins.mapr.domain.node_process as np @@ -34,7 +33,6 @@ OOZIE = np.NodeProcess( ) -@six.add_metaclass(s.Single) class Oozie(s.Service): def __init__(self): super(Oozie, self).__init__() @@ -116,7 +114,6 @@ class Oozie(s.Service): OOZIE.start(instances) -@six.add_metaclass(s.Single) class OozieV401(Oozie): def __init__(self): super(OozieV401, self).__init__() @@ -124,7 +121,6 @@ class OozieV401(Oozie): self._dependencies = [('mapr-oozie-internal', self.version)] -@six.add_metaclass(s.Single) class OozieV410(Oozie): def __init__(self): super(OozieV410, self).__init__() diff --git a/sahara/plugins/mapr/services/pig/pig.py b/sahara/plugins/mapr/services/pig/pig.py index 8fd69438..88d03c59 100644 --- a/sahara/plugins/mapr/services/pig/pig.py +++ b/sahara/plugins/mapr/services/pig/pig.py @@ -13,8 +13,6 @@ # under the License. -import six - import sahara.plugins.mapr.domain.node_process as np import sahara.plugins.mapr.domain.service as s import sahara.plugins.mapr.util.validation_utils as vu @@ -27,7 +25,6 @@ PIG = np.NodeProcess( ) -@six.add_metaclass(s.Single) class Pig(s.Service): def __init__(self): super(Pig, self).__init__() @@ -37,14 +34,12 @@ class Pig(s.Service): self._validation_rules = [vu.at_least(1, PIG)] -@six.add_metaclass(s.Single) class PigV013(Pig): def __init__(self): super(PigV013, self).__init__() self._version = '0.13' -@six.add_metaclass(s.Single) class PigV014(Pig): def __init__(self): super(PigV014, self).__init__() diff --git a/sahara/plugins/mapr/services/spark/spark.py b/sahara/plugins/mapr/services/spark/spark.py index 26f19ec0..df83abb1 100755 --- a/sahara/plugins/mapr/services/spark/spark.py +++ b/sahara/plugins/mapr/services/spark/spark.py @@ -74,7 +74,6 @@ SPARK_SLAVE = SparkWorker( ) -@six.add_metaclass(s.Single) class Spark(s.Service): def __init__(self): super(Spark, self).__init__() diff --git a/sahara/plugins/mapr/services/sqoop/sqoop2.py b/sahara/plugins/mapr/services/sqoop/sqoop2.py index a345a11f..51df0f04 100755 --- a/sahara/plugins/mapr/services/sqoop/sqoop2.py +++ b/sahara/plugins/mapr/services/sqoop/sqoop2.py @@ -13,8 +13,6 @@ # under the License. -import six - import sahara.plugins.mapr.domain.node_process as np import sahara.plugins.mapr.domain.service as s import sahara.plugins.mapr.util.commands as cmd @@ -34,7 +32,6 @@ SQOOP_2_CLIENT = np.NodeProcess( ) -@six.add_metaclass(s.Single) class Sqoop2(s.Service): def __init__(self): super(Sqoop2, self).__init__() diff --git a/sahara/plugins/mapr/services/swift/swift.py b/sahara/plugins/mapr/services/swift/swift.py index 8a274e0f..6446a922 100644 --- a/sahara/plugins/mapr/services/swift/swift.py +++ b/sahara/plugins/mapr/services/swift/swift.py @@ -14,7 +14,6 @@ from oslo_log import log as logging -import six import sahara.plugins.mapr.domain.service as s import sahara.plugins.mapr.services.maprfs.maprfs as maprfs @@ -23,7 +22,6 @@ import sahara.utils.files as f LOG = logging.getLogger(__name__) -@six.add_metaclass(s.Single) class Swift(s.Service): HADOOP_SWIFT_JAR = ('plugins/mapr/services/swift/' 'resources/hadoop-swift-latest.jar') diff --git a/sahara/plugins/mapr/services/yarn/yarn.py b/sahara/plugins/mapr/services/yarn/yarn.py index 028ad926..5a646101 100644 --- a/sahara/plugins/mapr/services/yarn/yarn.py +++ b/sahara/plugins/mapr/services/yarn/yarn.py @@ -13,8 +13,6 @@ # under the License. -import six - import sahara.plugins.mapr.domain.configuration_file as bcf import sahara.plugins.mapr.domain.node_process as np import sahara.plugins.mapr.domain.service as s @@ -111,7 +109,6 @@ class YARN(s.Service): return template % file_name -@six.add_metaclass(s.Single) class YARNv241(YARN): def __init__(self): super(YARNv241, self).__init__() @@ -123,7 +120,6 @@ class YARNv241(YARN): ] -@six.add_metaclass(s.Single) class YARNv251(YARN): def __init__(self): super(YARNv251, self).__init__() @@ -135,7 +131,6 @@ class YARNv251(YARN): ] -@six.add_metaclass(s.Single) class YARNv270(YARN): def __init__(self): super(YARNv270, self).__init__() diff --git a/sahara/plugins/mapr/util/general.py b/sahara/plugins/mapr/util/general.py index 9249e15d..7edc8dda 100644 --- a/sahara/plugins/mapr/util/general.py +++ b/sahara/plugins/mapr/util/general.py @@ -190,3 +190,14 @@ def download(remote, url, output=None, run_as=None): args = {'url': url, 'output': '-O %s' % output if output else ''} command = _run_as(run_as, 'wget -q %(output)s %(url)s' % args) remote.execute_command(command, timeout=600) + + +class Singleton(type): + instances = {} + + def __call__(cls, *args, **kwargs): + if cls not in cls.instances: + new_instance = super(Singleton, cls).__call__(*args, **kwargs) + cls.instances[cls] = new_instance + + return cls.instances[cls]