Repository: bigtop
Updated Branches:
  refs/heads/master f7d471b41 -> 41eecb9a1


http://git-wip-us.apache.org/repos/asf/bigtop/blob/41eecb9a/bigtop-packages/src/charm/pig/layer-pig/layer.yaml
----------------------------------------------------------------------
diff --git a/bigtop-packages/src/charm/pig/layer-pig/layer.yaml 
b/bigtop-packages/src/charm/pig/layer-pig/layer.yaml
new file mode 100644
index 0000000..e41e233
--- /dev/null
+++ b/bigtop-packages/src/charm/pig/layer-pig/layer.yaml
@@ -0,0 +1,13 @@
+repo: 
https://github.com/apache/bigtop/tree/master/bigtop-packages/src/charm/pig/layer-pig
+includes:
+  - 'layer:apache-bigtop-base'
+  - 'layer:hadoop-client'
+options:
+  apache-bigtop-base:
+    dirs:
+      pig:
+        path: '/usr/lib/pig'
+      pig_conf:
+        path: '/etc/pig/conf'
+      hadoop_conf:
+        path: '/etc/hadoop/conf'

http://git-wip-us.apache.org/repos/asf/bigtop/blob/41eecb9a/bigtop-packages/src/charm/pig/layer-pig/lib/charms/layer/bigtop_pig.py
----------------------------------------------------------------------
diff --git 
a/bigtop-packages/src/charm/pig/layer-pig/lib/charms/layer/bigtop_pig.py 
b/bigtop-packages/src/charm/pig/layer-pig/lib/charms/layer/bigtop_pig.py
new file mode 100755
index 0000000..4a2ab92
--- /dev/null
+++ b/bigtop-packages/src/charm/pig/layer-pig/lib/charms/layer/bigtop_pig.py
@@ -0,0 +1,80 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from subprocess import CalledProcessError, check_output
+
+from charms.layer.apache_bigtop_base import Bigtop
+from charms import layer
+from charmhelpers.core import hookenv
+from jujubigdata import utils
+
+
+class Pig(object):
+    """
+    This class manages Pig.
+    """
+    def __init__(self):
+        self.dist_config = utils.DistConfig(
+            data=layer.options('apache-bigtop-base'))
+
+    def install_pig(self):
+        '''
+        Trigger the Bigtop puppet recipe that handles the Pig service.
+        '''
+        # Dirs are handled by the bigtop deb. No need to call out to
+        # dist_config to do that work.
+        roles = ['pig-client']
+
+        bigtop = Bigtop()
+        bigtop.render_site_yaml(roles=roles)
+        bigtop.trigger_puppet()
+
+        # Set app version for juju status output; pig --version looks like:
+        #   Apache Pig version 0.15.0 (r: unknown)
+        #   compiled Feb 06 2016, 23:00:40
+        try:
+            pig_out = check_output(['pig', '-x', 'local', 
'--version']).decode()
+        except CalledProcessError as e:
+            pig_out = e.output
+        lines = pig_out.splitlines()
+        parts = lines[0].split() if lines else []
+        if len(parts) < 4:
+            hookenv.log('Error getting Pig version: {}'.format(pig_out),
+                        hookenv.ERROR)
+            pig_ver = ''
+        else:
+            pig_ver = parts[3]
+        hookenv.application_version_set(pig_ver)
+
+    def initial_pig_config(self):
+        '''
+        Configure system-wide pig bits.
+        '''
+        pig_bin = self.dist_config.path('pig') / 'bin'
+        with utils.environment_edit_in_place('/etc/environment') as env:
+            if pig_bin not in env['PATH']:
+                env['PATH'] = ':'.join([env['PATH'], pig_bin])
+            env['PIG_CONF_DIR'] = self.dist_config.path('pig_conf')
+            env['PIG_HOME'] = self.dist_config.path('pig')
+            env['HADOOP_CONF_DIR'] = self.dist_config.path('hadoop_conf')
+
+    def update_config(self, mode):
+        """
+        Configure Pig with the correct classpath.  If Hadoop is available, use
+        HADOOP_CONF_DIR, otherwise use PIG_HOME.
+        """
+        with utils.environment_edit_in_place('/etc/environment') as env:
+            key = 'HADOOP_CONF_DIR' if mode == 'mapreduce' else 'PIG_HOME'
+            env['PIG_CLASSPATH'] = env[key]

http://git-wip-us.apache.org/repos/asf/bigtop/blob/41eecb9a/bigtop-packages/src/charm/pig/layer-pig/metadata.yaml
----------------------------------------------------------------------
diff --git a/bigtop-packages/src/charm/pig/layer-pig/metadata.yaml 
b/bigtop-packages/src/charm/pig/layer-pig/metadata.yaml
new file mode 100644
index 0000000..2898c6a
--- /dev/null
+++ b/bigtop-packages/src/charm/pig/layer-pig/metadata.yaml
@@ -0,0 +1,9 @@
+name: pig
+summary: Create Pig Latin programs for data warehouse analysis
+maintainer: Juju Big Data <[email protected]>
+description: |
+  Apache Pig is a platform for creating MapReduce programs used with Hadoop.
+  It consists of a high-level language (Pig Latin) for expressing data analysis
+  programs, coupled with infrastructure for evaluating these programs.
+  Learn more at http://pig.apache.org.
+tags: []

http://git-wip-us.apache.org/repos/asf/bigtop/blob/41eecb9a/bigtop-packages/src/charm/pig/layer-pig/reactive/pig.py
----------------------------------------------------------------------
diff --git a/bigtop-packages/src/charm/pig/layer-pig/reactive/pig.py 
b/bigtop-packages/src/charm/pig/layer-pig/reactive/pig.py
new file mode 100644
index 0000000..b239361
--- /dev/null
+++ b/bigtop-packages/src/charm/pig/layer-pig/reactive/pig.py
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from charmhelpers.core import hookenv
+from charms.layer.bigtop_pig import Pig
+from charms.reactive import is_state, set_state, when, when_not
+from charms.reactive.helpers import data_changed
+
+
+@when('bigtop.available')
+@when_not('pig.installed')
+def install_pig():
+    hookenv.status_set('maintenance', 'installing pig')
+    pig = Pig()
+    pig.install_pig()
+    pig.initial_pig_config()
+    set_state('pig.installed')
+
+
+@when('pig.installed')
+def check_config():
+    mode = 'mapreduce' if is_state('hadoop.ready') else 'local'
+    if data_changed('pig.mode', mode):
+        Pig().update_config(mode)
+        hookenv.status_set('active', 'ready (%s)' % mode)

http://git-wip-us.apache.org/repos/asf/bigtop/blob/41eecb9a/bigtop-packages/src/charm/pig/layer-pig/tests/01-deploy.py
----------------------------------------------------------------------
diff --git a/bigtop-packages/src/charm/pig/layer-pig/tests/01-deploy.py 
b/bigtop-packages/src/charm/pig/layer-pig/tests/01-deploy.py
new file mode 100755
index 0000000..c24617d
--- /dev/null
+++ b/bigtop-packages/src/charm/pig/layer-pig/tests/01-deploy.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import amulet
+import re
+import unittest
+
+
+class TestDeploy(unittest.TestCase):
+    """
+    Deployment and smoke test for the Apache Bigtop Pig service.
+    """
+    @classmethod
+    def setUpClass(cls):
+        cls.d = amulet.Deployment(series='xenial')
+        cls.d.add('pig', 'pig')
+
+        cls.d.setup(timeout=1800)
+        cls.d.sentry.wait_for_messages({'pig': re.compile('ready')}, 
timeout=1800)
+        cls.pig = cls.d.sentry['pig'][0]
+
+    def test_pig(self):
+        """
+        Validate Pig by running the smoke-test action.
+        """
+        uuid = self.pig.action_do('smoke-test')
+        result = self.d.action_fetch(uuid)
+        # pig smoke-test sets outcome=success on success
+        if (result['outcome'] != "success"):
+            error = "Pig smoke-test failed"
+            amulet.raise_status(amulet.FAIL, msg=error)
+
+
+if __name__ == '__main__':
+    unittest.main()

http://git-wip-us.apache.org/repos/asf/bigtop/blob/41eecb9a/bigtop-packages/src/charm/pig/layer-pig/tests/tests.yaml
----------------------------------------------------------------------
diff --git a/bigtop-packages/src/charm/pig/layer-pig/tests/tests.yaml 
b/bigtop-packages/src/charm/pig/layer-pig/tests/tests.yaml
new file mode 100644
index 0000000..3b6ce3e
--- /dev/null
+++ b/bigtop-packages/src/charm/pig/layer-pig/tests/tests.yaml
@@ -0,0 +1,3 @@
+reset: false
+packages:
+  - amulet

Reply via email to