def workflow_jobsub_actions(request, workflow): if request.method not in ['GET', 'POST']: raise StructuredException(code="METHOD_NOT_ALLOWED_ERROR", message=_('Must be GET or POST request.'), error_code=405) available_actions = OozieDesign.objects.all() if request.method == 'POST': form = ImportJobsubDesignForm(data=request.POST, choices=[(action.id, action.name) for action in available_actions]) if form.is_valid(): try: design = OozieDesign.objects.get(id=form.cleaned_data['jobsub_id']) action = convert_jobsub_design(design) action.workflow = workflow response = { 'status': 0, 'data': { 'node': model_to_dict(action) } } response['data']['node']['child_links'] = [] return HttpResponse(json.dumps(response), mimetype="application/json") except OozieDesign.DoesNotExist, e: raise StructuredException(code="INVALID_REQUEST_ERROR", message=_('Job Designer design does not exist.'), data={'exception': str(e)}, error_code=400) except (Mapreduce.DoesNotExist, Streaming.DoesNotExist, Java.DoesNotExist), e: raise StructuredException(code="INVALID_REQUEST_ERROR", message=_('Could not convert Job Designer design.'), data={'exception': str(e)}, error_code=400) except Exception, e: raise StructuredException(code="INVALID_REQUEST_ERROR", message=_('Error importing node from Job Designer'), data={'exception': str(e)}, error_code=400)
def import_action(request, workflow, parent_action_id): available_actions = OozieDesign.objects.all() if request.method == 'POST': form = ImportJobsubDesignForm(data=request.POST, choices=[(action.id, action.name) for action in available_actions ]) if form.is_valid(): try: design = OozieDesign.objects.get( id=form.cleaned_data['action_id']) action = convert_jobsub_design(design) action.workflow = workflow action.save() workflow.add_action(action, parent_action_id) except OozieDesign.DoesNotExist: request.error(_('Jobsub design doesn\'t exist.')) except (Mapreduce.DoesNotExist, Streaming.DoesNotExist, Java.DoesNotExist): request.error(_('Could not convert jobsub design')) except: request.error( _('Could not convert jobsub design or add action to workflow' )) return redirect( reverse('oozie:edit_workflow', kwargs={'workflow': action.workflow.id})) return render( 'editor/import_workflow_action.mako', request, { 'workflow': workflow, 'available_actions': available_actions, 'form_url': reverse('oozie:import_action', kwargs={ 'workflow': workflow.id, 'parent_action_id': parent_action_id }), })