Using the DRMAA interface to Son of Grid Engine I would like to get the name of a host running a particular job. I would like something like the following (using the drmaa-python interface)
>>> import drmaa
>>> s = drmaa.Session()
>>> s.initialize()
>>> jt = s.createJobTemplate()
>>> jt.remoteCommand = 'sleep'
>>> jt.args = ['100']
>>> jobid = s.runJob(jt)
>>> jobid
'1'
>>> s.jobStatus(jobid)
'running'
>>> s.the_function_I_want(jobid)
'worker-host-123'
Questions
Is this possible through the DRMAA interface? Looking at the spec it seems not, but I thought I'd ask anyway
If so, how?
Short answer: You are right, this is not possible.
Long answer:
The drmaa-python library acts as wrapper for an underlying C implementation of the DRMAAv1 API (see https://www.ogf.org/documents/GFD.130.pdf). Such a C library usually comes together with your cluster framework. DRMAAv1 does not support a standardized monitoring of jobs, and therefore both the DRMAAv1 C and Python library can't get this information.
If you wonder about that lack of functionality, please note that the original API design is from 2004.
The second version of DRMAA (https://www.ogf.org/documents/GFD.231.pdf) does support monitoring. At the time of writing, the only known implementation comes with Univa GridEngine, and there is no existing Python wrapper implementation for it.
You could try to parse the job log file by yourself to extract the execution host name. If you need to pass special options to qsub for getting such a file, you can use the nativeSpecification field in the job template.
Related
I am currently implementing the Aerospike Python Client in order to benchmark it along with our Redis implementation, to see which is faster and/or more stable.
I'm still on baby steps, currently Unit-Testing basic functionality, for example if I correctly add records in my Set. For that reason, I want to create a function to count them.
I saw in Aerospike's Documentation, that :
"to perform an aggregation on query, you first need to register a UDF
with the database".
It seems that this is the suggested way that aggregations, counting and other custom functionality should be run in Aerospike.
Therefore, to count the records in a set I have, I created the following module:
# "counter.lua"
function count(s)
return s : map(function() return 1 end) : reduce (function(a,b) return a+b end)
end
I'm trying to use aerospike python client's function to register a UDF(User Defined Function) module:
udf_put(filename, udf_type, policy)
My code is as follows:
# aerospike_client.py:
# "udf_put" parameters
policy = {'timeout': 1000}
lua_module = os.path.join(os.path.dirname(os.path.realpath(__file__)), "counter.lua") #same folder
udf_type = aerospike.UDF_TYPE_LUA # equals to "0", which is for "Lua"
self.client.udf_put(lua_module, udf_type, policy) # Exception is thrown here
query = self.client.query(self.aero_namespace, self.aero_set)
query.select()
result = query.apply('counter', 'count')
an exception is thrown:
exceptions.Exception: (-2L, 'Filename should be a string', 'src/main/client/udf.c', 82)
Is there anything I'm missing or doing wrong?
Is there a way to "debug" it without compiling C code?
Is there any other suggested way to count the records in my set? Or I'm fine with the Lua module?
First, I'm not seeing that exception, but I am seeing a bug with udf_put where the module is registered but the python process hangs. I can see the module appear on the server using AQL's show modules.
I opened a bug with the Python client's repo on Github, aerospike/aerospike-client-python.
There's a best practices document regarding UDF development here: https://www.aerospike.com/docs/udf/best_practices.html
In general using the stream-UDF to aggregate the records through the count function is the correct way to go about it. There are examples here and here.
I'm building an application that needs to use the Linux group keyring to share some sensitive data between processes with different owners. Whenever I try to access the group keyring (e.g."#g" or "-6") using either the keyctl command or the underlying API, I get an error.
I'm guessing I have to set some kind of state to let it know which of my groups to get the keyring for, but documentation on this kernel feature is sparse. Anybody know how to make it work for groups?
The method call (currently using Python's ctypes, which will directly call shared library functions, which works fine for all other keyrings):
>>> import ctypes
>>> keyutils = ctypes.CDLL('libkeyutils.so.1')
>>> key_id = 'foo'
>>> key_value = 'bar'
>>> keyutils.add_key('user', key_id, key_value, len(key_value), -5)
268186515
>>> keyutils.add_key('user', key_id, key_value, len(key_value), -6)
-1
Based on looking at the man page for keyctl it would seem that group based keyrings aren't implemented in the kernel yet.
(*) Group specific keyring: #g or -6
This is a place holder for a group specific keyring, but is not actually implemented yet in the kernel.
Taking a look at the most recent stable kernel source it also backs up what the man page says:
http://lxr.linux.no/#linux+v3.2.9/security/keys/process_keys.c#L641
So your code is correct... but it's attempting to use functionality that isn't there yet.
I have a django (Python) project that needs to know what version its code is on in Bazaar for deployment purposes. This is a web application, so I don't want to do this because it fires off a new subprocess and that's not going to scale.
import subprocess
subprocess.Popen(["bzr", "revno"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
Is there a way to parse Bazaar repositories to calculate the version number? Bazaar itself is written in Python and contains this code for calculating the revno, which makes me think it isn't exactly trivial.
rh = self.revision_history()
revno = len(rh)
Edit: Final fix
from bzrlib.branch import BzrBranch
branch = BzrBranch.open_containing('.')[0]
revno = len(branch.revision_history())
Edit: Final fix but for real this time
from bzrlib.branch import BzrBranch
branch = BzrBranch.open_containing('.')[0]
revno = branch.last_revision_info()[0]
You can use Bazaar's bzrlib API to get information about any given Bazaar repository.
>>> from bzrlib.branch import BzrBranch
>>> branch = BzrBranch.open('.')
>>> branch.last_revision_info()
More examples are available here.
Do it once and cache the result (in a DB/file, if need be)? I doubt the version is going to change that much.
I'm trying to create a python program (using pyUNO ) to make some changes on a OpenOffice calc sheet.
I've launched previously OpenOffice on "accept" mode to be able to connect from an external program. Apparently, should be as easy as:
import uno
# get the uno component context from the PyUNO runtime
localContext = uno.getComponentContext()
# create the UnoUrlResolver
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext)
# connect to the running office
ctx = resolver.resolve("uno:socket,host=localhost,port=2002;"
"urp;StarOffice.ComponentContext")
smgr = ctx.ServiceManager
# get the central desktop object
DESKTOP =smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
#The calling it's not exactly this way, just to simplify the code
DESKTOP.loadComponentFromURL('file.ods')
But I get an AttributeError when I try to access loadComponentFromURL. If I make a dir(DESKTOP), I've see only the following attributes/methods:
['ActiveFrame', 'DispatchRecorderSupplier', 'ImplementationId', 'ImplementationName',
'IsPlugged', 'PropertySetInfo', 'SupportedServiceNames', 'SuspendQuickstartVeto',
'Title', 'Types', 'addEventListener', 'addPropertyChangeListener',
'addVetoableChangeListener', 'dispose', 'disposing', 'getImplementationId',
'getImplementationName', 'getPropertySetInfo', 'getPropertyValue',
'getSupportedServiceNames', 'getTypes', 'handle', 'queryInterface',
'removeEventListener', 'removePropertyChangeListener', 'removeVetoableChangeListener',
'setPropertyValue', 'supportsService']
I've read that there are where a bug doing the same, but on OpenOffice 3.0 (I'm using OpenOffice 3.1 over Red Hat5.3). I've tried to use the workaround stated here, but they don't seems to be working.
Any ideas?
It has been a long time since I did anything with PyUNO, but looking at the code that worked last time I ran it back in '06, I did my load document like this:
def urlify(path):
return uno.systemPathToFileUrl(os.path.realpath(path))
desktop.loadComponentFromURL(
urlify(tempfilename), "_blank", 0, ())
Your example is a simplified version, and I'm not sure if you've removed the extra arguments intentionally or not intentionally.
If loadComponentFromURL isn't there, then the API has changed or there's something else wrong, I've read through your code and it looks like you're doing all the same things I have.
I don't believe that the dir() of the methods on the desktop object will be useful, as I think there's a __getattr__ method being used to proxy through the requests, and all the methods you've printed out are utility methods used for the stand-in object for the com.sun.star.frame.Desktop.
I think perhaps the failure could be that there's no method named loadComponentFromURL that has exactly 1 argument. Perhaps giving the 4 argument version will result in the method being found and used. This could simply be an impedance mismatch between Python and Java, where Java has call-signature method overloading.
This looks like issue 90701: http://www.openoffice.org/issues/show_bug.cgi?id=90701
See also http://piiis.blogspot.com/2008/10/pyuno-broken-in-ooo-30-with-system.html and http://udk.openoffice.org/python/python-bridge.html
I am using web2py (v1.63) and Flex 3. web2py v1.61 introduced the #service decorators, which allow you to tag a controller function with #service.amfrpc. You can then call that function remotely using http://..../app/default/call/amfrpc/[function]. See http://www.web2py.com/examples/default/tools#services. Does anybody have an example of how you would set up a Flex 3 to call a function like this? Here is what I have tried so far:
<mx:RemoteObject id="myRemote" destination="amfrpc" source="amfrpc"
endpoint="http://{mysite}/{myapp}/default/call/amfrpc/">
<mx:method name="getContacts"
result="show_results(event)"
fault="on_fault(event)" />
</mx:RemoteObject>
In my scenario, what should be the value of the destination and source attributes? I have read a couple of articles on non-web2py implementations, such as http://corlan.org/2008/10/10/flex-and-php-remoting-with-amfphp/, but they use a .../gateway.php file instead of having a URI that maps directly to the function.
Alternatively, I have been able to use flash.net.NetConnection to successfully call my remote function, but most of the documentation I have found considers this to be the old, pre-Flex 3 way of doing AMF. See http://pyamf.org/wiki/HelloWorld/Flex. Here is the NetConnection code:
gateway = new NetConnection();
gateway.connect("http://{mysite}/{myapp}/default/call/amfrpc/");
resp = new Responder(show_results, on_fault);
gateway.call("getContacts", resp);
-Rob
I have not found a way to use a RemoteObject with the #service.amfrpc decorator. However, I can use the older ActionScript code using a NetConnection (similar to what I posted originally) and pair that with a #service.amfrpc function on the web2py side. This seems to work fine. The one thing that you would want to change in the NetConnection code I shared originally, is adding an event listener for connection status. You can add more listeners if you feel the need, but I found that NetStatusEvent was a must. This status will be fired if the server is not responding. You connection set up would look like:
gateway = new NetConnection();
gateway.addEventListener(NetStatusEvent.NET_STATUS, gateway_status);
gateway.connect("http://127.0.0.1:8000/robs_amf/default/call/amfrpc/");
resp = new Responder(show_results, on_fault);
gateway.call("getContacts", resp);
-Rob