You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by de...@apache.org on 2018/05/01 18:50:24 UTC

svn commit: r1830708 - in /uima/uima-ducc/trunk/src/main/scripts: ducc_job_specification.py ducc_service_specification.py

Author: degenaro
Date: Tue May  1 18:50:24 2018
New Revision: 1830708

URL: http://svn.apache.org/viewvc?rev=1830708&view=rev
Log:
UIMA-5770 DUCC user commands to retrieve job specification, service specification & get service status

Added:
    uima/uima-ducc/trunk/src/main/scripts/ducc_service_specification.py   (with props)
Modified:
    uima/uima-ducc/trunk/src/main/scripts/ducc_job_specification.py

Modified: uima/uima-ducc/trunk/src/main/scripts/ducc_job_specification.py
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/src/main/scripts/ducc_job_specification.py?rev=1830708&r1=1830707&r2=1830708&view=diff
==============================================================================
--- uima/uima-ducc/trunk/src/main/scripts/ducc_job_specification.py (original)
+++ uima/uima-ducc/trunk/src/main/scripts/ducc_job_specification.py Tue May  1 18:50:24 2018
@@ -27,6 +27,15 @@ import urllib2
 from optparse import OptionParser
 from HTMLParser import HTMLParser
 
+message = 'Python 2.7 or greater is required.'
+sysinfo = sys.version_info
+if(sysinfo[0] < 2):
+    print message
+    sys.exit(1)
+elif(sysinfo[1] < 7):
+    print message
+    sys.exit(1)
+    
 row = 0
 column = 0
 
@@ -55,7 +64,7 @@ class DuccServiceDeploymentsTabHTMLParse
                 else:
                     print job_spec_key, job_spec_value
             job_spec_provider = 'ducc'
-            job_spec_key=''
+            job_spec_key = ''
             job_spec_value = ''
             column = 0
             row = row + 1

Added: uima/uima-ducc/trunk/src/main/scripts/ducc_service_specification.py
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/src/main/scripts/ducc_service_specification.py?rev=1830708&view=auto
==============================================================================
--- uima/uima-ducc/trunk/src/main/scripts/ducc_service_specification.py (added)
+++ uima/uima-ducc/trunk/src/main/scripts/ducc_service_specification.py Tue May  1 18:50:24 2018
@@ -0,0 +1,144 @@
+#!/usr/bin/env python
+
+# -----------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF 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.
+# -----------------------------------------------------------------------
+
+# Retrieve a DUCC Service Specification from Webserver
+
+import sys
+import urllib2
+
+from optparse import OptionParser
+from HTMLParser import HTMLParser
+
+message = 'Python 2.7 or greater is required.'
+sysinfo = sys.version_info
+if(sysinfo[0] < 2):
+    print message
+    sys.exit(1)
+elif(sysinfo[1] < 7):
+    print message
+    sys.exit(1)
+
+row = 0
+column = 0
+
+service_spec_provider = 'ducc'
+service_spec_key = ''
+service_spec_value = ''
+
+service_spec_instances = ''
+
+class DuccServiceDeploymentsTabHTMLParser(HTMLParser):
+    
+    def handle_starttag(self, tag, attrs):
+        global options, row, column, service_spec_provider, service_spec_key, service_spec_value, service_spec_attrs
+        #print('Encountered a start tag:', tag)
+        if(tag == 'td'):
+            column = column + 1
+        service_spec_attrs = attrs
+        
+    def handle_endtag(self, tag):
+        global options, row, column, service_spec_provider, service_spec_key, service_spec_value, service_spec_instances
+        if(tag == 'tr'):
+            # we calculate instances from number of implementors
+            if(service_spec_key == 'implementors'):
+                try:
+                    service_spec_instances = len(service_spec_value.split())
+                except:
+                    pass
+            # we set instances from previously calculated number of implementors
+            if(service_spec_key == 'instances'):
+                service_spec_value = service_spec_instances
+            # display row
+            display = True
+            if(options.user):
+                if(service_spec_provider != 'user'):
+                    display = False
+            if(options.nocp):
+                if(service_spec_key == 'service_ping_classpath'):
+                    display = False
+            if(options.noargs):
+                if(service_spec_key == 'process_executable_args'):
+                    display = False
+            if(display):
+                if(options.provider):
+                    print service_spec_provider, service_spec_key, service_spec_value
+                else:
+                    print service_spec_key, service_spec_value
+            # set up for next row
+            service_spec_provider = 'ducc'
+            service_spec_key = ''
+            service_spec_value = ''
+            column = 0
+            row = row + 1
+        #print('Encountered an end tag :', tag)
+
+    def handle_data(self, data):
+        global options, row, column, service_spec_provider, service_spec_key, service_spec_value, service_spec_attrs
+        if(column == 1):
+            service_spec_provider = data
+        elif(column == 2):
+            service_spec_key = data
+        else:
+            append = True
+            if(service_spec_key == 'autostart'):
+                if(len(service_spec_attrs) < 2):
+                    append = False   
+            if(append):
+                service_spec_value = service_spec_value+' '+data
+            
+        #print('Encountered some data  :', str(row), str(column), data)
+
+class DuccServiceStatus():
+    
+    # parse command line
+    def parse_cmdline(self):
+        global options
+        parser = OptionParser()
+        parser.add_option('--scheme', action='store', dest='scheme', default='http', help='default = http')
+        parser.add_option('--host', action='store', dest='host', default=None, help='required (no default)')
+        parser.add_option('--port', action='store', dest='port', default='42133', help='default = 42133')
+        parser.add_option('--name', action='store', dest='name', default=None, help='required (no default)')
+        parser.add_option('--provider', action='store_true', dest='provider', default=False, help='display provider (optional)')
+        parser.add_option('--user', action='store_true', dest='user', default=False, help='display provider==user entries only (optional)')
+        parser.add_option('--nocp', action='store_true', dest='nocp', default=False, help='suppress display of service_ping_classpath (optional)')
+        parser.add_option('--noargs', action='store_true', dest='noargs', default=False, help='suppress display process_executable_args (optional)')
+        (options, args) = parser.parse_args()
+        
+        if(options.host == None):
+            parser.error('missing --host')
+    
+        if(options.name == None):
+            parser.error('missing --name')
+        
+    def main(self, argv):
+        servlet = '/ducc-servlet/service-registry-data'
+        self.parse_cmdline()
+        url_string = options.scheme+'://'+options.host+':'+options.port+servlet+'?name='+options.name
+        #print url_string
+        response = urllib2.urlopen(url_string)
+        html = response.read()
+        
+        parser = DuccServiceDeploymentsTabHTMLParser()
+        parser.feed(html)
+
+if __name__ == '__main__':
+    instance = DuccServiceStatus()
+    instance.main(sys.argv[1:])

Propchange: uima/uima-ducc/trunk/src/main/scripts/ducc_service_specification.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: uima/uima-ducc/trunk/src/main/scripts/ducc_service_specification.py
------------------------------------------------------------------------------
    svn:executable = *