Browse Source

HUE-4954 [editor] Generate and submit the coordinator

Romain Rigaux 9 years ago
parent
commit
d140821

+ 12 - 2
apps/oozie/src/oozie/models2.py

@@ -3205,8 +3205,18 @@ class Coordinator(Job):
   def workflow(self):
     if self.document is None:
       raise PopupException(_('Cannot return workflow since document attribute is None.'))
-    wf_doc = Document2.objects.get_by_uuid(user=self.document.owner, uuid=self.data['properties']['workflow'])
-    return Workflow(document=wf_doc)
+
+    if self.data['properties']['document']:
+      document = Document2.objects.get_by_uuid(user=self.document.owner, uuid=self.data['properties']['document'])
+      wf_doc = WorkflowBuilder().create_workflow(document=document, user=self.document.owner, managed=True)
+      wf = Workflow(data=wf_doc.data)
+      wf_doc.delete()
+      return wf
+    else:
+      wf_doc = Document2.objects.get_by_uuid(user=self.document.owner, uuid=self.data['properties']['workflow'])
+      return Workflow(document=wf_doc)
+
+    #return Workflow(document=wf_doc)
 
   def get_absolute_url(self):
     return reverse('oozie:edit_coordinator') + '?coordinator=%s' % self.id

+ 18 - 6
apps/oozie/src/oozie/views/editor2.py

@@ -490,6 +490,7 @@ def list_editor_coordinators(request):
 @check_document_access_permission()
 def edit_coordinator(request):
   coordinator_id = request.GET.get('coordinator', request.GET.get('uuid'))
+  #scheduled_doc_uuid = request.GET.get('document')
   doc = None
   workflow_uuid = None
 
@@ -520,9 +521,11 @@ def edit_coordinator(request):
     LOG.error(smart_str(e))
 
   if USE_NEW_EDITOR.get():
-    document = Document2.objects.get(uuid=coordinator.data['properties']['workflow'] or coordinator.data['properties']['document'])
-    if not document.can_read(request.user):
-      raise PopupException(_('You don\'t have access to the workflow or document of this coordinator.'))
+    scheduled_uuid = coordinator.data['properties']['workflow'] or coordinator.data['properties']['document']
+    if scheduled_uuid:
+      document = Document2.objects.get(uuid=scheduled_uuid) #  or scheduled_doc_uuid
+      if 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')]
@@ -644,7 +647,7 @@ def save_coordinator(request):
   response['status'] = 0
   response['id'] = coordinator_doc.id
   response['uuid'] = coordinator_doc.uuid
-  response['message'] = _('Saved !')
+  response['message'] = _('Saved!') if coordinator_data.get('id') else _('Updated!')
 
   return JsonResponse(response)
 
@@ -721,8 +724,17 @@ def submit_coordinator(request, doc_id):
 
 def _submit_coordinator(request, coordinator, mapping):
   try:
-    wf_doc = Document2.objects.get_by_uuid(user=request.user, uuid=coordinator.data['properties']['workflow'])
-    wf_dir = Submission(request.user, Workflow(document=wf_doc), request.fs, request.jt, mapping, local_tz=coordinator.data['properties']['timezone']).deploy()
+#     if coordinator.data['properties']['workflow']:
+#       wf_doc = Document2.objects.get_by_uuid(user=request.user, uuid=coordinator.data['properties']['workflow'])
+#       wf = Workflow(document=wf_doc)
+#     else:
+#       print 111
+#       document = Document2.objects.get_by_uuid(user=request.user, uuid=coordinator.data['properties']['document'])
+#       wf_doc = WorkflowBuilder().create_workflow(document=document, user=request.user, managed=True)
+    wf = coordinator.workflow
+      
+      #wf_doc.delete() or set to History
+    wf_dir = Submission(request.user, wf, request.fs, request.jt, mapping, local_tz=coordinator.data['properties']['timezone']).deploy()
 
     properties = {'wf_application_path': request.fs.get_hdfs_path(wf_dir)}
     properties.update(mapping)

+ 1 - 1
desktop/libs/liboozie/src/liboozie/submission2.py

@@ -296,7 +296,7 @@ class Submission(object):
     create_directories(self.fs)
 
     # Case of a shared job
-    if self.user != self.job.document.owner:
+    if self.job.document and self.user != self.job.document.owner:
       path = REMOTE_DEPLOYMENT_DIR.get().replace('$USER', self.user.username).replace('$TIME', str(time.time())).replace('$JOBID', str(self.job.id))
       # Shared coords or bundles might not have any existing workspaces
       if self.fs.exists(self.job.deployment_dir):

+ 1 - 1
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1856,6 +1856,7 @@
     self.saveScheduler = function() {
       if (self.isBatchable() && (! self.coordinatorUuid() || self.schedulerViewModel.coordinator.isDirty())) {
         self.schedulerViewModel.coordinator.isManaged(true);
+        self.schedulerViewModel.coordinator.properties.document(self.uuid()); console.log(self.uuid());
         self.schedulerViewModel.save(function(data) {
           self.coordinatorUuid(data.uuid);
         });
@@ -1872,7 +1873,6 @@
       });
     };
 
-
     self.viewSchedulerId = ko.observable(typeof notebook.viewSchedulerId != "undefined" && notebook.viewSchedulerId != null ? notebook.viewSchedulerId : '');
     self.viewSchedulerId.subscribe(function(newVal) {
       self.save();