def copy_coordinator(request): if request.method != 'POST': raise PopupException(_('A POST request is required.')) jobs = json.loads(request.POST.get('selection')) for job in jobs: doc2 = Document2.objects.get(type='oozie-coordinator2', id=job['id']) doc = doc2.doc.get() name = doc2.name + '-copy' doc2 = doc2.copy(name=name, owner=request.user) doc.copy(content_object=doc2, name=name, owner=request.user) coord = Coordinator(document=doc2) coordinator_data = coord.get_data_for_json() coordinator_data['name'] = name _import_workspace(request.fs, request.user, coord) doc2.update_data(coordinator_data) doc2.save() response = {} request.info(_('Coordinator copied.') if len(jobs) > 1 else _('Coordinator copied.')) return JsonResponse(response)
def copy_coordinator(request): if request.method != 'POST': raise PopupException(_('A POST request is required.')) jobs = json.loads(request.POST.get('selection')) for job in jobs: doc2 = Document2.objects.get(type='oozie-coordinator2', id=job['id']) doc = doc2.doc.get() name = doc2.name + '-copy' doc2 = doc2.copy(name=name, owner=request.user) doc.copy(content_object=doc2, name=name, owner=request.user) coord = Coordinator(document=doc2) coordinator_data = coord.get_data_for_json() coordinator_data['name'] = name _import_workspace(request.fs, request.user, coord) doc2.update_data(coordinator_data) doc2.save() response = {} request.info( _('Coordinator copied.') if len(jobs) > 1 else _('Coordinator copied.') ) return JsonResponse(response)
def edit_coordinator(request): coordinator_id = request.GET.get('coordinator', request.GET.get('uuid')) doc = None workflow_uuid = None if coordinator_id: cid = {} if coordinator_id.isdigit(): cid['id'] = coordinator_id else: cid['uuid'] = coordinator_id doc = Document2.objects.get(**cid) coordinator = Coordinator(document=doc) else: coordinator = Coordinator() coordinator.set_workspace(request.user) if request.GET.get('workflow'): workflow_uuid = request.GET.get('workflow') if workflow_uuid: coordinator.data['properties']['workflow'] = workflow_uuid api = get_oozie(request.user) credentials = Credentials() try: credentials.fetch(api) except Exception as e: LOG.error(smart_str(e)) if USE_NEW_EDITOR.get(): scheduled_uuid = coordinator.data['properties'][ 'workflow'] or coordinator.data['properties']['document'] if scheduled_uuid: try: document = Document2.objects.get(uuid=scheduled_uuid) except Document2.DoesNotExist as e: document = None coordinator.data['properties']['workflow'] = '' LOG.warning("Workflow with uuid %s doesn't exist: %s" % (scheduled_uuid, e)) if document and document.is_trashed: raise PopupException( _('Your workflow %s has been trashed!') % (document.name if document.name else '')) if document and not document.can_read(request.user): raise PopupException( _('You don\'t have access to the workflow or document of this coordinator.' )) else: workflows = [ dict([('uuid', d.content_object.uuid), ('name', d.content_object.name)]) for d in Document.objects.available_docs( Document2, request.user).filter(extra='workflow2') ] if coordinator_id and not [ a for a in workflows if a['uuid'] == coordinator.data['properties']['workflow'] ]: raise PopupException( _('You don\'t have access to the workflow of this coordinator.' )) if USE_NEW_EDITOR.get(): # In Hue 4, merge with above workflows = [ dict([('uuid', d.uuid), ('name', d.name)]) for d in Document2.objects.documents( request.user, include_managed=False).search_documents( types=['oozie-workflow2']) ] can_edit = doc is None or (doc.can_write(request.user) if USE_NEW_EDITOR.get() else doc.doc.get().is_editable(request.user)) if request.GET.get('format') == 'json': # For Editor return JsonResponse({ 'coordinator': coordinator.get_data_for_json(), 'credentials': list(credentials.credentials.keys()), 'workflows': workflows, 'doc_uuid': doc.uuid if doc else '', 'is_embeddable': request.GET.get('is_embeddable', False), 'can_edit': can_edit, 'layout': django_mako.render_to_string( 'editor2/common_scheduler.mako', {'coordinator_json': coordinator.to_json_for_html()}) }) else: return render( 'editor2/coordinator_editor.mako', request, { 'coordinator_json': coordinator.to_json_for_html(), 'credentials_json': json.dumps(list(credentials.credentials.keys()), cls=JSONEncoderForHTML), 'workflows_json': json.dumps(workflows, cls=JSONEncoderForHTML), 'doc_uuid': doc.uuid if doc else '', 'is_embeddable': request.GET.get('is_embeddable', False), 'can_edit_json': json.dumps(can_edit) })