Created
December 1, 2014 21:23
-
-
Save kapilt/9d245bb81c1b7c71def1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
import yaml | |
from charmhelpers.core import hookenv | |
LATEST = "latest" | |
class Service(dict): | |
def __init__(self, installer): | |
self.installer = installer | |
def get_package(self): | |
pass | |
def get_config_map(self): | |
pass | |
def start(self): | |
pass | |
def stop(self): | |
pass | |
class YarnResourceManager(Service): | |
pass | |
class YarnNodeManager(Service): | |
pass | |
class YarnProxyServer(Service): | |
pass | |
class HdfsNameNode(Service): | |
pass | |
class HdfsDataNode(Service): | |
pass | |
class MapReduceWorker(Service): | |
pass | |
class MapReduceHistory(Service): | |
pass | |
class Zookeeper(Service): | |
ports = [2181] | |
class Hive(Service): | |
""" | |
Requires Metastore | |
""" | |
class HiveMetastore(Service): | |
""" | |
Requires Mysql|Postgresql | |
""" | |
class Imapala(Service): | |
""" | |
Requires Hive Metastore and Mysql|Postgresql | |
Currently only has precise repo | |
http://goo.gl/NoeHWj | |
""" | |
class ImapalaCatalog(Service): | |
""" | |
""" | |
class HBase(Service): | |
""" | |
Requires Zookeeper | |
""" | |
pass | |
class Hue(Service): | |
""" | |
Requires EVERYTHING :-) | |
""" | |
def InstallFactory(config): | |
if config['origin'] == 'cloudera': | |
return ClouderaInstall(config) | |
raise ValueError("unknown origin %s" % config['origin']) | |
class Install(object): | |
pass | |
class HortonWorks(Install): | |
fingerprint = "B9733A7A07513CAD" | |
class ClouderaInstall(Install): | |
fingerprint = "F36A89E33CC1BD0F71079007327574EE02A818DD" | |
archive_template = """\ | |
deb [arch=amd64] http://archive.cloudera.com/cdh5/ubuntu/%s/amd64/%s-cdh cdh5 contrib | |
deb-src http://archive.cloudera.com/cdh5/ubuntu/%s/amd64/%s-cdh cdh5 contrib | |
""" | |
archive_extras_template = """\ | |
# LZO on Ubuntu 14.04 amd64 | |
deb [arch=amd64] %s/ubuntu/trusty/amd64/gplextras trusty-gplextras5 contrib | |
deb-src %s/trusty/amd64/gplextras trusty-gplextras5 contrib | |
""" % ("http://archive.cloudera.com/gplextras5/ubuntu", | |
"http://archive.cloudera.com/gplextras5/ubuntu") | |
services = { | |
'yarn-resourcemanager': { | |
'factory': YarnResourceManager, | |
'charm': 'hadoop-manager', | |
'packages': ['hadoop-lzo'], | |
'service': 'hadoop-yarn-resourcemanager'}, | |
'yarn-nodemanager': { | |
'factory': YarnNodeManager, | |
'charm': 'hadoop-node', | |
'packages': ['hadoop-lzo'], | |
'service': 'hadoop-yarn-nodemanager'}, | |
'yarn-proxyserver': { | |
'factory': YarnProxyServer, | |
'charm': 'hadoop-util', | |
'packages': ['hadoop-lzo'], | |
'service': 'hadoop-yarn-proxyserver'}, | |
'hdfs-namenode': { | |
'factory': HdfsNameNode, | |
'charm': 'hadoop-manager', | |
'packages': ['hadoop-lzo'], | |
'service': 'hadoop-hdfs-namenode'}, | |
'hdfs-datanode': { | |
'factory': HdfsDataNode, | |
'charm': 'hadoop-node', | |
'packages': ['hadoop-lzo'], | |
'service': 'hadoop-hdfs-datanode'}, | |
'hadoop-mapreduce': { | |
'factory': MapReduceWorker, | |
'charm': 'hadoop-node', | |
'packages': ['hadoop-lzo'], | |
'service': 'hadoop-mapreduce'}, | |
'mapreduce-historyserver': { | |
'factory': MapReduceHistory, | |
'charm': 'hadoop-util', | |
'packages': ['hadoop-lzo'], | |
'service': 'hadoop-mapreduce-historyserver'}, | |
'hbase': { | |
'factory': HBase, | |
'charm': 'hbase-master'}, | |
'hive-metastore': { | |
'factory': HiveMetastore, | |
'charm': 'hive-metastore', | |
'packages': []}, | |
'zookeeper': { | |
'factory': Zookeeper, | |
'charm': 'zookeeper', | |
'packages': ['zookeeper']}} | |
def __init__(self, config): | |
self.series = "trusty" | |
def run(self): | |
self.install_packages() | |
def install_packages(self): | |
subprocess.check_output( | |
['apt-key', 'add', | |
os.path.join( | |
hookenv.charm_dir(), "files", "cloudera-cdh5.key")]) | |
with open('/etc/apt/sources.list.d/cloudera.list') as fh: | |
fh.write(self.archive_template % ((self.series,) * 4)) | |
with open('/etc/apt/sources.list.d/cloudera-extras.list') as fh: | |
fh.write(self.archive_extras_template) | |
subprocess.check_output( | |
['apt-get', 'update', '-qq']) | |
def get_services(self): | |
charm = charm_name() | |
for k, v in self.services.items(): | |
if v['charm'] != charm: | |
continue | |
yield self.get_service(k) | |
def get_service(self, name): | |
return self.services[name](self) | |
def charm_name(): | |
with open(os.path.join(hookenv.charm_dir(), 'metadata.yaml')) as fh: | |
data = fh.read() | |
return yaml.safe_load(data)['name'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment