Commits

Peter Rudenko committed 2262915

Templeton API initial

  • Participants

Comments (0)

Files changed (16)

+*.log
+*.pot
+*.pyc
+*.py[cod]
+
+# C extensions
+*.so
+
+# Translations
+*.mo
+
+#emacs temp files
+*~
+\#*\#
+.\#*

File templeton/Makefile

+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. 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.
+ifeq ($(ROOT),)
+  $(error "Error: Expect the environment variable $$ROOT to point to the Desktop installation")
+endif
+
+include $(ROOT)/Makefile.sdk

File templeton/setup.py

+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. 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 setuptools import setup, find_packages
+import os
+
+def expand_package_data(src_dirs, strip=""):
+  ret = []
+  for src_dir in src_dirs:
+    for path, dnames, fnames in os.walk(src_dir):
+      for fname in fnames:
+        ret.append(os.path.join(path, fname).replace(strip, ""))
+  return ret
+
+os.chdir(os.path.dirname(os.path.abspath(__file__)))
+setup(
+  name = "templeton",
+  version = "0.1",
+  url = 'TODO',
+  description = 'TODO',
+  author = 'TODO',
+  packages = find_packages('src'),
+  package_dir = {'': 'src'},
+  install_requires = ['setuptools', 'desktop'],
+  entry_points = { 'desktop.sdk.application': 'templeton=templeton' },
+  zip_safe = False,
+  package_data = {
+    # Include static resources.  Package_data doesn't
+    # deal well with directory globs, so we enumerate
+    # the files manually.
+    'templeton': expand_package_data(
+      ["src/templeton/templates", "src/templeton/static"],
+      "src/templeton/")
+  }
+)

File templeton/src/templeton/__init__.py

+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. 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.

File templeton/src/templeton/api.py

+# -*- coding: utf-8 -*-
+import urllib
+import urllib2
+import simplejson as json
+
+
+TEMPLETON_URL = "http://ec2-75-101-199-141.compute-1.amazonaws.com:50111/templeton/v1/"
+
+
+class Templeton(object):
+
+    def get_query(self, url, data):
+        """
+        Make GET query to templeton url.
+        """
+        data = urllib.urlencode(data)
+        response = urllib2.urlopen(TEMPLETON_URL + url + "?" + data)
+        return json.loads(response.read())
+
+    def post_query(self, url, data):
+        """
+        Make POST query to templeton url.
+        """
+        data = urllib.urlencode(data)
+        req = urllib2.Request(TEMPLETON_URL + url, data)
+        response = urllib2.urlopen(req)
+        return json.loads(response.read()) 
+
+
+    def pig_query(self, user="hdfs", execute=None, pig_file=None, statusdir=None, callback=None):
+        """
+        Create and queue a Pig job.
+
+        Keyword arguments:
+        user -- Hue/Hadoop user
+        execute -- String containing an entire, short pig program to run. (e.g. pwd)
+        file -- HDFS file name of a pig program to run. (One of either "execcute" or "file" is required )
+        statusdir -- A directory where Templeton will write the status of the Pig job. If
+                     provided, it is the caller's responsibility to remove this directory when done.
+        callback -- Define a URL to Optional be called upon job completion. You may embed a specific job
+                    ID into this URL using $jobId. This tag will be replaced in the callback URL with this job's job
+                    ID.
+
+        Returns dict:
+        id -- A string containing the job ID similar to "job_201110132141_0001".
+        info -- A JSON object containing the information returned when the job was queued.
+        """
+        if not any([execute, pig_file]):
+            raise Exception("""One of either "execcute" or "file" is required""")
+        data = {"user.name": user}
+        if execute:
+            data['execute'] = execute
+        if pig_file:
+            data['file'] = pig_file
+        if statusdir:
+            data['statusdir'] = statusdir
+        if callback:
+            data['callback'] = callback
+        return self.post_query("pig", data)
+
+    def check_job(self, job_id, user="hdfs"):
+        """
+        Check the status of a job and get related job information given its job ID.
+        """
+        data = {'user.name': user}
+        return self.get_query("queue/%s" % job_id, data)
+
+
+if __name__ == "__main__":
+    t = Templeton()
+    pig_query = t.pig_query(user="hdfs", execute="pwd")
+    job = t.check_job(pig_query['id'])
+    print job

File templeton/src/templeton/forms.py

+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. 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.

File templeton/src/templeton/models.py

+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. 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.

File templeton/src/templeton/settings.py

+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. 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.
+DJANGO_APPS = [ "templeton" ]
+REQUIRES_HADOOP = False
+MENU_INDEX = 100
+ICON = "/templeton/static/art/templeton.png"

File templeton/src/templeton/static/art/templeton.png

Added
New image

File templeton/src/templeton/static/css/templeton.css

+/* 
+	templeton styles
+	important: these should be namespaced
+	example:
+		let's say you are creating an app called "calculator"; you should prefix all your styles with your application's name like so
+		
+		.calculator img {
+			border: 1px solid #000;
+		}
+		.calculator p {
+			margin: 10px 0px;
+		}
+		etc...
+
+	other notes:
+	* don't use ids - there may be more than one of your apps open; use classes!
+	* the toolbar element is absolutely positioned and 100% wide (and therefor 0px high);
+	  any elements inside it should also be absolutely positioned
+*/
+
+.templeton img.templeton_icon {
+	width: 55px;
+	height: 55px;
+	position: absolute;
+	top: 27px;
+	left: 3px;
+}

File templeton/src/templeton/static/help/index.md

+Help for your app, written in [MarkDown](http://daringfireball.net/projects/markdown/syntax) syntax.

File templeton/src/templeton/static/js/templeton.js

Empty file added.

File templeton/src/templeton/templates/index.mako

+<%!from desktop.views import commonheader, commonfooter %>
+<%namespace name="shared" file="shared_components.mako" />
+
+${commonheader("Templeton", "templeton", "100px")}
+${shared.menubar(section='mytab')}
+
+## Use double hashes for a mako template comment
+## Main body
+
+<div class="container-fluid">
+  <h2>Templeton app is successfully setup!</h2>
+  <p>It's now ${date}.</p>
+</div>
+${commonfooter()}

File templeton/src/templeton/templates/shared_components.mako

+
+<%!
+def is_selected(section, matcher):
+  if section == matcher:
+    return "active"
+  else:
+    return ""
+%>
+
+<%def name="menubar(section='')">
+  <div class="subnav subnav-fixed">
+    <div class="container-fluid">
+      <ul class="nav nav-pills">
+        <li class="${is_selected(section, 'mytab')}"><a href="#">Tab 1</a></li>
+        <li class="${is_selected(section, 'mytab2')}"><a href="#">Tab 2</a></li>
+      </ul>
+    </div>
+  </div>
+</%def>

File templeton/src/templeton/urls.py

+#!/usr/bin/env python
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. 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 django.conf.urls.defaults import patterns, url
+
+urlpatterns = patterns('templeton',
+  url(r'^$', 'views.index'),
+)

File templeton/src/templeton/views.py

+#!/usr/bin/env python
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. 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 desktop.lib.django_util import render
+import datetime
+
+def index(request):
+  return render('index.mako', request, dict(date=datetime.datetime.now()))