Selaa lähdekoodia

HUE-3308 [editor] Jar snippet

Romain Rigaux 9 vuotta sitten
vanhempi
commit
53eb8a7

+ 17 - 24
apps/oozie/src/oozie/models2.py

@@ -797,7 +797,11 @@ class Node():
     _upgrade_older_node(self.data)
 
   def get_template_name(self):
-    return 'editor2/gen/workflow-%s.xml.mako' % self.data['type']
+    node_type = self.data['type']
+    if self.data['type'] == JavaDocumentAction.TYPE:
+      node_type = JavaAction.TYPE
+        
+    return 'editor2/gen/workflow-%s.xml.mako' % node_type
 
   def find_parameters(self):
     return find_parameters(self) + (find_parameters(self, ['sla']) if self.sla_enabled else [])
@@ -2038,21 +2042,7 @@ class JavaDocumentAction(Action):
           'label': _('Java program'),
           'value': '',
           'help_text': _('Select a saved Java program you want to schedule.'),
-          'type': 'hive'
-     },
-     'jar_path': {
-          'name': 'jar_path',
-          'label': _('Jar name'),
-          'value': '',
-          'help_text': _('Path to the jar on HDFS.'),
-          'type': ''
-     },
-     'main_class': {
-          'name': 'main_class',
-          'label': _('Main class'),
-          'value': '',
-          'help_text': _('Java class. e.g. org.apache.hadoop.examples.Grep'),
-          'type': 'text'
+          'type': 'java'
      },
      'arguments': {
           'name': 'arguments',
@@ -2924,7 +2914,7 @@ class WorkflowBuilder():
     if name is None:
       name = _('Schedule of ') + document.name or document.type
 
-    if document.type == 'java':
+    if document.type == 'query-java':
       node = self.get_java_document_node(document, name, document.uuid)
     else:
       node = self.get_hive_document_node(document, name, document.uuid, user)
@@ -2981,9 +2971,10 @@ class WorkflowBuilder():
         u'actionParameters': [],
     }
 
-  def get_java_document_node(self, document, node, name, doc_uuid, parameters):
+  def get_java_document_node(self, document, name, doc_uuid):
     credentials = []
 
+    # To pick up from props
     java_class = 'org.apache.solr.hadoop.MapReduceIndexerTool'
     arguments = [
         {"value": "--morphline-file"},
@@ -3008,11 +2999,11 @@ class WorkflowBuilder():
     return {
          "id":"0aec471d-2b7c-d93d-b22c-2110fd17ea2c",
          "name":"doc-1",
-         "type":"java-widget",
+         "type":"java-document-widget",
          "properties":{
               "files": files,
               "job_xml":[],
-              "jar_path":"jar",
+              "jar_path": "",
               "java_opts":[],
               "retry_max":[],
               "retry_interval":[],
@@ -3034,8 +3025,11 @@ class WorkflowBuilder():
     
     
 
-  def get_workflow(self, name, doc_uuid, user, managed=False):    
-    
+  def get_workflow(self, node, name, doc_uuid, user, managed=False):    
+    parameters = [{u'name': u'oozie.use.system.libpath', u'value': True}]
+    parameters.append({u'name': u'oozie.libpath', u'value': '/tmp/smart_indexer_lib'})
+
+
     data = json.dumps({'workflow': {
       u'name': name,
       u'versions': [u'uri:oozie:workflow:0.4', u'uri:oozie:workflow:0.4.5'
@@ -3110,8 +3104,7 @@ class WorkflowBuilder():
               {u'key': u'upstream-apps', u'value': u''},
               ],
           u'show_arrows': True,
-          u'parameters': [{u'name': u'oozie.use.system.libpath',
-                          u'value': True}],
+          u'parameters': parameters,
           u'properties': [],
           },
       u'nodeNamesMapping': {

+ 27 - 11
apps/oozie/src/oozie/static/oozie/js/workflow-editor.ko.js

@@ -499,15 +499,25 @@ var WorkflowEditorViewModel = function (layout_json, workflow_json, credentials_
     loadLayout(self, layout_json);
     self.workflow.loadNodes(workflow_json);
 
-    $.get('/desktop/api2/docs/?type=query-hive&include_trashed=false&sort=-last_modified&limit=100', function(data) {
-      if (data && data.documents) {
-        var queries = [];
-        $.each(data.documents, function(index, query) {
-          queries.push(ko.mapping.fromJS(query));
-        });
-        self.hiveQueries(queries);
-      }
-    });
+    self.getDocuments('query-hive', self.hiveQueries);
+    self.getDocuments('query-java', self.javaQueries);
+  };
+
+  self.getDocuments = function(type, destination) {
+	$.get('/desktop/api2/docs/', {
+	    type: type,
+	    include_trashed: false,
+	    sort: '-last_modified',
+	    limit: 100
+	}, function(data) {
+	  if (data && data.documents) {
+	    var queries = [];
+	    $.each(data.documents, function(index, query) {
+	      queries.push(ko.mapping.fromJS(query));
+	    });
+	    destination(queries);
+	  }
+	});
   };
 
   self.addActionProperties = ko.observableArray([]);
@@ -534,11 +544,17 @@ var WorkflowEditorViewModel = function (layout_json, workflow_json, credentials_
 
   self.subworkflows = ko.observableArray(getOtherSubworkflows(self, subworkflows_json));
   self.hiveQueries = ko.observableArray();
+  self.javaQueries = ko.observableArray();
   self.history = ko.mapping.fromJS(history_json);
 
-  self.getHiveQueryById = function (uuid) {
+  self.getDocumentById = function (type, uuid) {
     var _query = null;
-    $.each(self.hiveQueries(), function (index, query) {
+    if (type == 'java') {
+      data = self.javaQueries();
+    } else {
+      data = self.hiveQueries();
+    }
+    $.each(data, function (index, query) {
       if (query.uuid() == uuid) {
         _query = query;
         return false;

+ 9 - 9
apps/oozie/src/oozie/templates/editor2/common_workflow.mako

@@ -949,8 +949,8 @@
 
     <div data-bind="visible: ! $root.isEditing()">
       <span data-bind="template: { name: 'logs-icon' }"></span>
-      <!-- ko if: $root.getHiveQueryById(properties.uuid()) -->
-      <!-- ko with: $root.getHiveQueryById(properties.uuid()) -->
+      <!-- ko if: $root.getDocumentById(type(), properties.uuid()) -->
+      <!-- ko with: $root.getDocumentById(type(), properties.uuid()) -->
         <a data-bind="attr: { href: absoluteUrl() }" target="_blank"><span data-bind='text: name'></span></a>
         <br/>
         <span data-bind='text: description' class="muted"></span>
@@ -960,8 +960,8 @@
 
     <div data-bind="visible: $root.isEditing">
       <div data-bind="visible: ! $parent.ooziePropertiesExpanded()" class="nowrap">
-        <!-- ko if: $root.getHiveQueryById(properties.uuid()) -->
-        <!-- ko with: $root.getHiveQueryById(properties.uuid()) -->
+        <!-- ko if: $root.getDocumentById(type(), properties.uuid()) -->
+        <!-- ko with: $root.getDocumentById(type(), properties.uuid()) -->
           <select data-bind="options: $root.hiveQueries, optionsText: 'name', optionsValue: 'uuid', value: $parent.properties.uuid, select2Version4:{ placeholder: '${ _ko('Hive query name...')}'}"></select>
           <a href="#" data-bind="attr: { href: absoluteUrl() }" target="_blank" title="${ _('Open') }">
             <i class="fa fa-external-link-square"></i>
@@ -1022,8 +1022,8 @@
 
     <div data-bind="visible: ! $root.isEditing()">
       <span data-bind="template: { name: 'logs-icon' }"></span>
-      <!-- ko if: $root.getHiveQueryById(properties.uuid()) -->
-      <!-- ko with: $root.getHiveQueryById(properties.uuid()) -->
+      <!-- ko if: $root.getDocumentById(type(), properties.uuid()) -->
+      <!-- ko with: $root.getDocumentById(type(), properties.uuid()) -->
         <a data-bind="attr: { href: absoluteUrl() }" target="_blank"><span data-bind='text: name'></span></a>
         <br/>
         <span data-bind='text: description' class="muted"></span>
@@ -1033,9 +1033,9 @@
 
     <div data-bind="visible: $root.isEditing">
       <div data-bind="visible: ! $parent.ooziePropertiesExpanded()" class="nowrap">
-        <!-- ko if: $root.getHiveQueryById(properties.uuid()) -->
-        <!-- ko with: $root.getHiveQueryById(properties.uuid()) -->
-          <select data-bind="options: $root.hiveQueries, optionsText: 'name', optionsValue: 'uuid', value: $parent.properties.uuid, select2Version4:{ placeholder: '${ _ko('Hive query name...')}'}"></select>
+        <!-- ko if: $root.getDocumentById(type(), properties.uuid()) -->
+        <!-- ko with: $root.getDocumentById(type(), properties.uuid()) -->
+          <select data-bind="options: $root.javaQueries, optionsText: 'name', optionsValue: 'uuid', value: $parent.properties.uuid, select2Version4:{ placeholder: '${ _ko('Hive query name...')}'}"></select>
           <a href="#" data-bind="attr: { href: absoluteUrl() }" target="_blank" title="${ _('Open') }">
             <i class="fa fa-external-link-square"></i>
           </a>

+ 4 - 4
apps/oozie/src/oozie/templates/editor2/workflow_editor.mako

@@ -276,10 +276,10 @@ ${ workflow.render() }
           <!-- ko if: type() == 'workflow' -->
           <select data-bind="options: $root.subworkflows, optionsText: 'name', optionsValue: 'value', value: value"></select>
           <!-- /ko -->
-          <!-- ko if: type() == 'hive' -->
-          <select data-bind="options: $root.hiveQueries, optionsText: 'name', optionsValue: 'uuid', value: value, select2Version4:{ placeholder: '${ _ko('Hive query name...')}'}"></select>
-          <!-- ko if: $root.getHiveQueryById(value()) -->
-            <!-- ko with: $root.getHiveQueryById(value()) -->
+          <!-- ko if: type() == 'hive' || type() == 'java' -->
+          <select data-bind="options: type() == 'java' ? $root.javaQueries() : $root.hiveQueries(), optionsText: 'name', optionsValue: 'uuid', value: value, select2Version4:{ placeholder: '${ _ko('Document name...')}'}"></select>
+          <!-- ko if: $root.getDocumentById(type(), value()) -->
+            <!-- ko with: $root.getDocumentById(type(), value()) -->
               <a href="#" data-bind="attr: { href: $data.absoluteUrl() }" target="_blank" title="${ _('Open') }">
                 <i class="fa fa-external-link-square"></i>
               </a>

+ 1 - 1
desktop/core/src/desktop/api2.py

@@ -76,7 +76,7 @@ def search_documents(request):
     page=<n>           - Controls pagination. Defaults to 1.
     limit=<n>          - Controls limit per page. Defaults to all.
     type=<type>        - Show documents of given type(s) (directory, query-hive, query-impala, query-mysql, etc).
-                         Defaults to all.
+                         Defaults to all. Can appear multiple times.
     sort=<key>         - Sort by the attribute <key>, which is one of: "name", "type", "owner", "last_modified"
                          Accepts the form "-last_modified", which sorts in descending order.
                          Defaults to "-last_modified".

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

@@ -199,7 +199,8 @@ class Submission(object):
           notebook = Notebook(document=Document2.objects.get_by_uuid(user=self.user, uuid=action.data['properties']['uuid']))
 
           self._create_file(deployment_dir, action.data['name'] + '.sql', notebook.get_str())
-          #self.data['properties']['script_path'] = _generate_hive_script(self.data['uuid']) #'workspace_%s' % workflow.uui
+        elif action.data['type'] == 'java-document':
+          print action.data['properties']
 
     oozie_xml = self.job.to_xml(self.properties)
     self._do_as(self.user.username, self._copy_files, deployment_dir, oozie_xml, self.properties)

+ 1 - 1
desktop/libs/notebook/src/notebook/api.py

@@ -106,7 +106,7 @@ def execute(request):
 
   notebook = json.loads(request.POST.get('notebook', '{}'))
   snippet = json.loads(request.POST.get('snippet', '{}'))
-  is_query = notebook['type'].startswith('query-')
+  is_query = notebook['type'].startswith('query-') or snippet['type'] == 'java'
 
   try:
     try:

+ 0 - 4
desktop/libs/notebook/src/notebook/connectors/oozie_batch.py

@@ -61,10 +61,6 @@ class OozieApi(Api):
 
     notebook_doc = Document2.objects.get_by_uuid(user=self.user, uuid=notebook['uuid'], perm_type='read')
 
-    # Verify that the document is a valid Oozie batch type
-    if not notebook_doc.type == 'query-hive':
-      raise PopupException(_('Oozie batch submission only accepts Hive queries at this time.'))
-
     # Create a managed workflow from the notebook doc
     workflow_doc = WorkflowBuilder().create_workflow(document=notebook_doc, user=self.user, managed=True, name=_("Batch job for %s") % notebook_doc.name or notebook_doc.type)
     workflow = Workflow(document=workflow_doc)

+ 9 - 5
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -293,11 +293,15 @@ ${ hueIcons.symbols() }
                 <img src="${ static('pig/art/icon_pig_48.png') }" class="app-icon" />
                 Pig
               <!-- /ko -->
+              <!-- ko if: editorType() == 'java' -->
+                <i class="fa fa-file-code-o app-icon" style="vertical-align: middle"></i>
+                Java
+              <!-- /ko -->
               <!-- ko if: editorType() == 'beeswax' || editorType() == 'hive' -->
                 <img src="${ static('beeswax/art/icon_beeswax_48.png') }" class="app-icon" />
                 Hive
               <!-- /ko -->
-              <!-- ko if: ['impala', 'pig', 'hive', 'beeswax', 'rdbms'].indexOf(editorType()) == -1 -->
+              <!-- ko if: ['impala', 'pig', 'hive', 'beeswax', 'rdbms', 'java'].indexOf(editorType()) == -1 -->
                 <img src="${ static('rdbms/art/icon_rdbms_48.png') }" class="app-icon" />
                 SQL
               <!-- /ko -->
@@ -1405,7 +1409,7 @@ ${ hueIcons.symbols() }
             </div>
           </div>
           <!-- ko template: { if: ['text', 'markdown'].indexOf(type()) == -1, name: 'snippet-execution-status' } --><!-- /ko -->
-          <!-- ko template: { if: $root.editorMode(), name: 'snippet-code-resizer' } --><!-- /ko -->
+          <!-- ko template: { if: $root.editorMode() && type() != 'java', name: 'snippet-code-resizer' } --><!-- /ko -->
           <!-- ko if: $root.editorMode() -->
           <!-- ko template: 'snippet-log' --><!-- /ko -->
           <!-- ko template: 'query-tabs' --><!-- /ko -->
@@ -1761,13 +1765,13 @@ ${ hueIcons.symbols() }
       <div class="control-group">
         <label class="control-label">${_('Path')}</label>
         <div class="controls">
-          <input type="text" class="input-xxlarge filechooser-input" data-bind="value: properties().app_jar, valueUpdate:'afterkeydown', filechooser: properties().app_jar" placeholder="${ _('Path to application jar, e.g. hdfs://localhost:8020/user/hue/oozie-examples.jar') }"/>
+          <input type="text" class="input-xxlarge filechooser-input" data-bind="value: properties().app_jar, valueUpdate: 'afterkeydown', filechooser: properties().app_jar" placeholder="${ _('Path to application jar, e.g. hdfs://localhost:8020/user/hue/oozie-examples.jar') }"/>
         </div>
       </div>
       <div class="control-group">
         <label class="control-label">${_('Class')}</label>
         <div class="controls">
-          <input type="text" class="input-xxlarge" data-bind="value: properties().class" placeholder="${ _('Class name of application, e.g. org.apache.oozie.example.SparkFileCopy') }"/>
+          <input type="text" class="input-xxlarge" data-bind="value: properties().class, valueUpdate: 'afterkeydown'" placeholder="${ _('Class name of application, e.g. org.apache.oozie.example.SparkFileCopy') }"/>
         </div>
       </div>
       <!-- /ko -->
@@ -1775,7 +1779,7 @@ ${ hueIcons.symbols() }
       <div class="control-group">
         <label class="control-label">${_('Path')}</label>
         <div class="controls">
-          <input type="text" class="input-xxlarge" data-bind="value: properties().py_file, valueUpdate:'afterkeydown', filechooser: properties().py_file" placeholder="${ _('Path to python file, e.g. script.py') }"/>
+          <input type="text" class="input-xxlarge" data-bind="value: properties().py_file, valueUpdate: 'afterkeydown', filechooser: properties().py_file" placeholder="${ _('Path to python file, e.g. script.py') }"/>
         </div>
       </div>
       <!-- /ko -->