فهرست منبع

[oozie] Fix the install of the examples from the editor

Renamed old demo directory
Adding tests for 'install_examples' and 'edit_workflow'
Romain Rigaux 13 سال پیش
والد
کامیت
8f2652194a

+ 0 - 0
apps/oozie/demo/lib/hadoop-examples.jar → apps/oozie/examples/lib/hadoop-examples.jar


+ 0 - 0
apps/oozie/demo/pig/aggregate.pig → apps/oozie/examples/pig/aggregate.pig


+ 0 - 86
apps/oozie/src/oozie/management/commands/oozie_demo_setup.py

@@ -1,86 +0,0 @@
-#!/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.
-
-import logging
-import os
-import posixpath
-import shutil
-
-from django.core.management.base import NoArgsCommand
-
-from hadoop import cluster
-
-from oozie.conf import LOCAL_SAMPLE_DATA_DIR, LOCAL_SAMPLE_DIR
-from oozie.models import Workflow
-
-
-LOG = logging.getLogger(__name__)
-
-
-class Command(NoArgsCommand):
-  def handle_noargs(self, **options):
-    remote_fs = cluster.get_hdfs()
-    remote_dir = Workflow.objects.create_data_dir(remote_fs)
-
-    # Demo binaries
-    for demo in ('lib', 'pig'):
-      local_dir = posixpath.join(LOCAL_SAMPLE_DIR.get(), demo)
-      remote_data_dir = posixpath.join(remote_dir, demo)
-      self.stdout.write('Copying workflows %s to %s\n' % (local_dir, remote_data_dir))
-      copy_dir(local_dir, remote_fs, remote_data_dir)
-
-    # Demo data
-    local_dir = LOCAL_SAMPLE_DATA_DIR.get()
-    remote_data_dir = posixpath.join(remote_dir, 'data')
-    self.stdout.write('Copying data %s to %s\n' % (local_dir, remote_data_dir))
-    copy_dir(local_dir, remote_fs, remote_data_dir)
-
-  def has_been_setup(self):
-    return False
-
-# TODO refactor with Jobsub and move this to a utility in WebHdfs
-def copy_dir(local_dir, remote_fs, remote_dir):
-  remote_fs.mkdir(remote_dir)
-
-  for f in os.listdir(local_dir):
-    local_src = os.path.join(local_dir, f)
-    remote_dst = posixpath.join(remote_dir, f)
-    copy_file(local_src, remote_fs, remote_dst)
-
-
-CHUNK_SIZE = 65536
-
-def copy_file(local_src, remote_fs, remote_dst):
-  if remote_fs.exists(remote_dst):
-    LOG.info('%s already exists.  Skipping.' % remote_dst)
-    return
-  else:
-    LOG.info('%s does not exist. trying to copy' % remote_dst)
-
-  if os.path.isfile(local_src):
-    src = file(local_src)
-    try:
-      dst = remote_fs.open(remote_dst, 'w')
-      try:
-        shutil.copyfileobj(src, dst, CHUNK_SIZE)
-        LOG.info('Copied %s -> %s' % (local_src, remote_dst))
-      finally:
-        dst.close()
-    finally:
-      src.close()
-  else:
-    LOG.info('Skipping %s (not a file)' % local_src)

+ 45 - 9
apps/oozie/src/oozie/tests.py

@@ -102,7 +102,7 @@ class TestEditor:
     self.wf = create_workflow()
 
 
-  def test_find_paramters(self):
+  def test_find_parameters(self):
     jobs = [Job(name="$a"),
             Job(name="foo ${b} $$"),
             Job(name="${foo}", description="xxx ${foo}")]
@@ -291,6 +291,26 @@ class TestEditor:
         '</workflow-app>'.split(), self.wf.to_xml().split())
 
 
+  def test_edit_workflow(self):
+    response = self.c.get(reverse('oozie:edit_workflow', args=[self.wf.id]))
+    assert_true('Editor' in response.content, response.content)
+
+    # Edit
+    finish = SHARE_JOBS.set_for_testing(True)
+    try:
+      response = self.c.post(reverse('oozie:edit_workflow', args=[self.wf.id]), {})
+      assert_true('wf-name-1' in response.content, response.content)
+    finally:
+      finish()
+
+    finish = SHARE_JOBS.set_for_testing(True)
+    try:
+      response = self.c.post(reverse('oozie:edit_workflow', args=[self.wf.id]), WORKFLOW_DICT)
+      assert_true('wf-name-1' in response.content, response.content)
+    finally:
+      finish()
+
+
   def test_workflow_permissions(self):
     response = self.c.get(reverse('oozie:edit_workflow', args=[self.wf.id]))
     assert_true('Editor' in response.content, response.content)
@@ -345,9 +365,8 @@ class TestEditor:
     # Edit
     finish = SHARE_JOBS.set_for_testing(True)
     try:
-      response = client_not_me.get(reverse('oozie:edit_workflow', args=[self.wf.id]))
-      assert_equal(200, response.status_code)
-      assert_true('wf-name-1' in response.content, response.content)
+      response = client_not_me.post(reverse('oozie:edit_workflow', args=[self.wf.id]))
+      assert_true('Not allowed' in response.content, response.content)
     finally:
       finish()
 
@@ -414,6 +433,15 @@ class TestEditor:
     response = self.c.get(reverse('oozie:edit_coordinator', args=[coord.id]))
     assert_true('Editor' in response.content, response.content)
 
+    # Edit
+    finish = SHARE_JOBS.set_for_testing(True)
+    try:
+      response = self.c.post(reverse('oozie:edit_coordinator', args=[coord.id]))
+      assert_true('MyCoord' in response.content, response.content)
+      assert_false('Permission denied' in response.content, response.content)
+    finally:
+      finish()
+
     # Login as someone else
     client_not_me = make_logged_in_client(username='not_me', is_superuser=False, groupname='test')
     grant_access("not_me", "test", "oozie")
@@ -449,6 +477,8 @@ class TestEditor:
     # Share it !
     coord.is_shared = True
     coord.save()
+    coord.workflow.is_shared = True
+    coord.workflow.save()
 
     # List
     finish = SHARE_JOBS.set_for_testing(True)
@@ -462,9 +492,9 @@ class TestEditor:
     # Edit
     finish = SHARE_JOBS.set_for_testing(True)
     try:
-      response = client_not_me.get(reverse('oozie:edit_coordinator', args=[coord.id]))
-      assert_equal(200, response.status_code)
-      assert_true('MyCoord' in response.content, response.content)
+      response = client_not_me.post(reverse('oozie:edit_coordinator', args=[coord.id]))
+      assert_false('MyCoord' in response.content, response.content)
+      assert_true('Not allowed' in response.content, response.content)
     finally:
       finish()
 
@@ -537,9 +567,15 @@ class TestEditor:
     data = json.loads(response.content)
     assert_equal(0, data['status'], data['data'])
 
+  def test_install_examples(self):
+    self.c.post(reverse('oozie:install_examples'))
+
+
+# Utils
+WORKFLOW_DICT = {u'deployment_dir': [u''], u'name': [u'wf-name-1'], u'description': [u'']}
 
 
-# Beware: client not consistent with TestEditor.c
+# Beware: client not consistent with self.c in TestEditor
 def add_action(workflow, action, name):
   c = make_logged_in_client()
 
@@ -557,7 +593,7 @@ def create_workflow():
   response = c.get(reverse('oozie:create_workflow'))
   assert_equal(workflow_count, Workflow.objects.count(), response)
 
-  response = c.post(reverse('oozie:create_workflow'), {u'deployment_dir': [u''], u'name': [u'wf-name-1'], u'description': [u'']}, follow=True)
+  response = c.post(reverse('oozie:create_workflow'), WORKFLOW_DICT, follow=True)
   assert_equal(200, response.status_code)
   assert_equal(workflow_count + 1, Workflow.objects.count(), response)
 

+ 1 - 1
apps/oozie/src/oozie/views/dashboard.py

@@ -14,7 +14,6 @@
 # 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.log.access import access_warn
 
 try:
   import json
@@ -28,6 +27,7 @@ from django.utils.translation import ugettext as _
 
 from desktop.lib.django_util import render, PopupException
 from desktop.lib.rest.http_client import RestException
+from desktop.log.access import access_warn
 from liboozie.oozie_api import get_oozie
 
 from oozie.models import History

+ 5 - 4
apps/oozie/src/oozie/views/editor.py

@@ -106,7 +106,7 @@ def check_job_access_permission(view_func):
 
 def can_edit_job(user, job):
   """Only owners or admins can modify a job."""
-  return user.is_superuser or job.owner.id == user.id
+  return user.is_superuser or job.owner == user
 
 
 def can_edit_job_or_exception(request, job):
@@ -218,10 +218,10 @@ def edit_workflow(request, workflow):
   history = History.objects.filter(submitter=request.user, job=workflow)
 
   if request.method == 'POST' and can_edit_job_or_exception(request, workflow):
-    try:
-      workflow_form = WorkflowForm(request.POST, instance=workflow)
-      actions_formset = WorkflowFormSet(request.POST, request.FILES, instance=workflow)
+    workflow_form = WorkflowForm(request.POST, instance=workflow)
+    actions_formset = WorkflowFormSet(request.POST, request.FILES, instance=workflow)
 
+    try:
       if 'clone_action' in request.POST: return clone_action(request, action=request.POST['clone_action'])
       if 'delete_action' in request.POST: return delete_action(request, action=request.POST['delete_action'])
       if 'move_up_action' in request.POST: return move_up_action(request, action=request.POST['move_up_action'])
@@ -668,6 +668,7 @@ def install_examples(request):
     raise PopupException(_('A POST request is required.'))
   try:
     oozie_setup.Command().handle_noargs()
+    request.info(_('Examples installed!'))
   except WebHdfsException, e:
     raise PopupException(_('The examples could not be installed.'), detail=e)
   return redirect(reverse('oozie:list_workflows'))