def __init__(self, eventTypes, pathMode, pathString, whitelist, blacklist, ignoreSysFiles, ignoreDirEvents, platformCheck, proxy, monitorId): """ Initialise Monitor. """ self.log = logging.getLogger("fsclient." + __name__) # Now try to import the correct MonitorServer package import fsUtil PlatformMonitor = __import__(fsUtil.monitorPackage(platformCheck)) self.proxy = proxy self.monitorId = monitorId self.pMonitor = PlatformMonitor.PlatformMonitor( eventTypes, pathMode, pathString, whitelist, blacklist, ignoreSysFiles, ignoreDirEvents, self)
def run(self, args): # Configure our communicator ofr.registerObjectFactory(self.communicator()) for of in list(omero.rtypes.ObjectFactories.values()): of.register(self.communicator()) retVal = -1 props = self.communicator().getProperties() configure_server_logging(props) log.debug("Grid Properties:\n%s", str(props)) testConfig = props.getPropertyWithDefault("omero.fstest.config", "") isTestClient = bool(testConfig) if isTestClient: props.load(testConfig) log.info("Updated Test Properties:\n%s", str(props)) # This tests if the FSServer is supported by the platform # if not there's no point starting the FSDropBox client import fsUtil try: checkString = props.getPropertyWithDefault( "omero.fs.platformCheck", "True") platformCheck = not (checkString == "False") fsUtil.monitorPackage(platformCheck) except: log.exception("System requirements not met: \n") log.error("Quitting") return retVal try: host, port = self.getHostAndPort(props) omero.client(host, port) except: log.exception("Failed to get client: \n") log.error("Quitting") return retVal try: self.maxRetries = int( props.getPropertyWithDefault("omero.fs.maxRetries", "5")) self.retryInterval = int( props.getPropertyWithDefault("omero.fs.retryInterval", "3")) sf = omero.util.internal_service_factory( self.communicator(), "root", "system", retries=self.maxRetries, interval=self.retryInterval) except: log.exception("Failed to get Session: \n") log.error("Quitting") return retVal try: configService = sf.getConfigService() except: log.exception("Failed to get configService: \n") log.error("Quitting") return retVal try: monitorParameters = self.getMonitorParameters(props) log.info("Monitor parameters = %s", str(monitorParameters)) except: log.exception("Failed get properties from templates.xml: \n", ) log.error("Quitting") return retVal try: if 'default' in list(monitorParameters.keys()): if not monitorParameters['default']['watchDir']: dataDir = configService.getConfigValue("omero.data.dir") defaultDropBoxDir = props.getPropertyWithDefault( "omero.fs.defaultDropBoxDir", "DropBox") monitorParameters['default']['watchDir'] = os.path.join( dataDir, defaultDropBoxDir) watchDir = pathModule.path( monitorParameters['default']['watchDir']) if not watchDir.exists(): log.info("Creating default dropbox directory: " + monitorParameters['default']['watchDir']) watchDir.mkdir() except OSError: log.exception("Failed to create default dropbox directory : \n") except: log.exception("Failed to use a query service : \n") log.error("Quitting") return retVal try: sf.destroy() except: log.exception("Failed to get close session: \n") log.error("Quitting") return retVal try: serverIdString = self.getServerIdString(props) fsServer = self.communicator().stringToProxy(serverIdString) fsServer = monitors.MonitorServerPrx.checkedCast( fsServer.ice_twoway()) clientAdapterName = self.getClientAdapterName(props) clientIdString = self.getClientIdString(props) adapter = self.communicator().createObjectAdapter( clientAdapterName) mClient = {} monitorId = {} for user in list(monitorParameters.keys()): if isTestClient: self.callbackOnInterrupt() log.info("Creating test client for user: %s", user) testUser = user mClient[user] = fsDropBoxMonitorClient.TestMonitorClient( user, monitorParameters[user]['watchDir'], self.communicator(), worker_wait=monitorParameters[user]['fileWait'], worker_batch=monitorParameters[user]['fileBatch']) else: log.info("Creating client for user: %s", user) if user == 'default': mClient[user] = fsDropBoxMonitorClient.MonitorClientI( monitorParameters[user]['watchDir'], self.communicator(), worker_wait=monitorParameters[user]['fileWait'], worker_batch=monitorParameters[user]['fileBatch']) else: mClient[user] = \ fsDropBoxMonitorClient.SingleUserMonitorClient( user, monitorParameters[user]['watchDir'], self.communicator(), worker_wait=monitorParameters[ user]['fileWait'], worker_batch=monitorParameters[ user]['fileBatch']) identity = self.communicator().stringToIdentity( clientIdString + "." + user) adapter.add(mClient[user], identity) mClientProxy = monitors.MonitorClientPrx.uncheckedCast( adapter.createProxy(identity)) monitorType = monitors.MonitorType.__dict__["Persistent"] try: monitorId[user] = fsServer.createMonitor( monitorType, monitorParameters[user]['eventTypes'], monitorParameters[user]['pathMode'], monitorParameters[user]['watchDir'], monitorParameters[user]['whitelist'], monitorParameters[user]['blacklist'], monitorParameters[user]['timeout'], monitorParameters[user]['blockSize'], monitorParameters[user]['ignoreSysFiles'], monitorParameters[user]['ignoreDirEvents'], platformCheck, mClientProxy) log.info("Created monitor with id = %s", str(monitorId[user])) mClient[user].setId(monitorId[user]) mClient[user].setServerProxy(fsServer) mClient[user].setSelfProxy(mClientProxy) mClient[user].setDirImportWait( monitorParameters[user]['dirImportWait']) mClient[user].setThrottleImport( monitorParameters[user]['throttleImport']) mClient[user].setTimeouts( monitorParameters[user]['timeToLive'], monitorParameters[user]['timeToIdle']) mClient[user].setReaders( monitorParameters[user]['readers']) mClient[user].setImportArgs( monitorParameters[user]['importArgs']) mClient[user].setHostAndPort(host, port) mClient[user].setMaster(self) fsServer.startMonitor(monitorId[user]) except: log.exception("Failed create or start monitor : \n") adapter.activate() except: log.exception("Failed to access proxy : \n") return retVal if not mClient: log.error("Failed to create any monitors.") log.error("Quitting") return retVal log.info('Started OMERO.fs DropBox client') try: # If this is TestDropBox then try to copy and import a file. if isTestClient: timeout = int( props.getPropertyWithDefault("omero.fstest.timeout", "120")) srcFiles = list( props.getPropertyWithDefault("omero.fstest.srcFile", "").split(';')) targetDir = monitorParameters[testUser]['watchDir'] if not srcFiles or not targetDir: log.error("Bad configuration") else: log.info("Copying test file(s) %s to %s" % (srcFiles, targetDir)) retVal = self.injectTestFile(srcFiles, targetDir, timeout) else: self.communicator().waitForShutdown() except: # Catching here guarantees cleanup. log.exception("Executor error") for user in list(mClient.keys()): try: fsServer.stopMonitor(monitorId[user]) try: fsServer.destroyMonitor(monitorId[user]) except: log.warn( "Failed to destroy MonitorClient for : %s " "FSServer may have already stopped.", user) retVal = 0 except: log.warn( "Failed to stop and destroy MonitorClient for : %s " "FSServer may have already stopped.", user) retVal = 0 try: mClient[user].stop() except: log.exception("Failed to stop DropBoxMonitorClient for: %s", user) log.info('Stopping OMERO.fs DropBox client') log.info("Exiting with exit code: %d", retVal) if retVal != 0: log.error("Quitting") return retVal
Use is subject to license terms supplied in LICENSE.txt """ import logging import threading import os, sys, traceback # Third party path package. It provides much of the # functionality of os.path but without the complexity. # Imported as pathModule to avoid clashes. import path as pathModule # Now try to import the correct MonitorServer package import fsUtil try: PlatformMonitor = __import__(fsUtil.monitorPackage()) except: raise import omero.all import omero.grid.monitors as monitors class MonitorFactory(object): @staticmethod def createMonitor(mType, eTypes, pMode, pathString, whitelist, blacklist, timeout, blockSize, ignoreSysFiles, ignoreDirEvents, proxy, monitorId): if str(mType) == 'Persistent': return PersistentMonitor(eTypes, pMode, pathString, whitelist, blacklist, timeout, blockSize,
def run(self, args): # Configure our communicator ofr.registerObjectFactory(self.communicator()) for of in omero.rtypes.ObjectFactories.values(): of.register(self.communicator()) retVal = -1 props = self.communicator().getProperties() configure_server_logging(props) log.debug("Grid Properties:\n%s",str(props)) testConfig = props.getPropertyWithDefault("omero.fstest.config", "") isTestClient = bool(testConfig) if isTestClient: props.load(testConfig) log.info("Updated Test Properties:\n%s",str(props)) # This tests if the FSServer is supported by the platform # if not there's no point starting the FSDropBox client import fsUtil try: fsUtil.monitorPackage() except: log.exception("System requirements not met: \n") log.error("Quitting") return retVal try: host, port = self.getHostAndPort(props) omero.client(host, port) except: log.exception("Failed to get client: \n") log.error("Quitting") return retVal try: self.maxRetries = int(props.getPropertyWithDefault("omero.fs.maxRetries","5")) self.retryInterval = int(props.getPropertyWithDefault("omero.fs.retryInterval","3")) sf = omero.util.internal_service_factory( self.communicator(), "root", "system", retries=self.maxRetries, interval=self.retryInterval) except: log.exception("Failed to get Session: \n") log.error("Quitting") return retVal try: configService = sf.getConfigService() except: log.exception("Failed to get configService: \n") log.error("Quitting") return retVal try: monitorParameters = self.getMonitorParameters(props) log.info("Monitor parameters = %s", str(monitorParameters)) except: log.exception("Failed get properties from templates.xml: \n", ) log.error("Quitting") return retVal try: if 'default' in monitorParameters.keys(): if not monitorParameters['default']['watchDir']: dataDir = configService.getConfigValue("omero.data.dir") defaultDropBoxDir = props.getPropertyWithDefault("omero.fs.defaultDropBoxDir","DropBox") monitorParameters['default']['watchDir'] = os.path.join(dataDir, defaultDropBoxDir) watchDir = pathModule.path(monitorParameters['default']['watchDir']) if not watchDir.exists(): log.info("Creating default dropbox directory: " + monitorParameters['default']['watchDir']) watchDir.mkdir() except OSError: log.exception("Failed to create default dropbox directory : \n") except: log.exception("Failed to use a query service : \n") log.error("Quitting") return retVal try: sf.destroy() except: log.exception("Failed to get close session: \n") log.error("Quitting") return retVal try: serverIdString = self.getServerIdString(props) fsServer = self.communicator().stringToProxy(serverIdString) fsServer = monitors.MonitorServerPrx.checkedCast(fsServer.ice_twoway()) clientAdapterName = self.getClientAdapterName(props) clientIdString = self.getClientIdString(props) adapter = self.communicator().createObjectAdapter(clientAdapterName) mClient = {} monitorId = {} for user in monitorParameters.keys(): if isTestClient: self.callbackOnInterrupt() log.info("Creating test client for user: %s", user) testUser = user mClient[user] = fsDropBoxMonitorClient.TestMonitorClient(user, monitorParameters[user]['watchDir'], self.communicator(),\ worker_wait=monitorParameters[user]['fileWait'], worker_batch=monitorParameters[user]['fileBatch']) else: log.info("Creating client for user: %s", user) if user == 'default': mClient[user] = fsDropBoxMonitorClient.MonitorClientI(monitorParameters[user]['watchDir'], self.communicator(),\ worker_wait=monitorParameters[user]['fileWait'], worker_batch=monitorParameters[user]['fileBatch']) else: mClient[user] = fsDropBoxMonitorClient.SingleUserMonitorClient(user, monitorParameters[user]['watchDir'], self.communicator(),\ worker_wait=monitorParameters[user]['fileWait'], worker_batch=monitorParameters[user]['fileBatch']) identity = self.communicator().stringToIdentity(clientIdString + "." + user) adapter.add(mClient[user], identity) mClientProxy = monitors.MonitorClientPrx.uncheckedCast(adapter.createProxy(identity)) monitorType = monitors.MonitorType.__dict__["Persistent"] try: monitorId[user] = fsServer.createMonitor(monitorType, monitorParameters[user]['eventTypes'], monitorParameters[user]['pathMode'], monitorParameters[user]['watchDir'], monitorParameters[user]['whitelist'], monitorParameters[user]['blacklist'], monitorParameters[user]['timeout'], monitorParameters[user]['blockSize'], monitorParameters[user]['ignoreSysFiles'], monitorParameters[user]['ignoreDirEvents'], mClientProxy) log.info("Created monitor with id = %s",str(monitorId[user])) mClient[user].setId(monitorId[user]) mClient[user].setServerProxy(fsServer) mClient[user].setSelfProxy(mClientProxy) mClient[user].setDirImportWait(monitorParameters[user]['dirImportWait']) mClient[user].setThrottleImport(monitorParameters[user]['throttleImport']) mClient[user].setTimeouts(monitorParameters[user]['timeToLive'],monitorParameters[user]['timeToIdle']) mClient[user].setReaders(monitorParameters[user]['readers']) mClient[user].setImportArgs(monitorParameters[user]['importArgs']) mClient[user].setHostAndPort(host,port) mClient[user].setMaster(self) fsServer.startMonitor(monitorId[user]) except: log.exception("Failed create or start monitor : \n") adapter.activate() except: log.exception("Failed to access proxy : \n") return retVal if not mClient: log.error("Failed to create any monitors.") log.error("Quitting") return retVal log.info('Started OMERO.fs DropBox client') try: # If this is TestDropBox then try to copy and import a file. if isTestClient: timeout = int(props.getPropertyWithDefault("omero.fstest.timeout","120")) srcFiles = list(props.getPropertyWithDefault("omero.fstest.srcFile","").split(';')) targetDir = monitorParameters[testUser]['watchDir'] if not srcFiles or not targetDir: log.error("Bad configuration") else: log.info("Copying test file(s) %s to %s" % (srcFiles, targetDir)) retVal = self.injectTestFile(srcFiles, targetDir, timeout) else: self.communicator().waitForShutdown() except: # Catching here guarantees cleanup. log.exception("Executor error") for user in mClient.keys(): try: fsServer.stopMonitor(monitorId[user]) try: fsServer.destroyMonitor(monitorId[user]) except: log.warn("Failed to destroy MonitorClient for : %s FSServer may have already stopped.", user) retVal = 0 except: log.warn("Failed to stop and destroy MonitorClient for : %s FSServer may have already stopped.", user) retVal = 0 try: mClient[user].stop() except: log.exception("Failed to stop DropBoxMonitorClient for: %s", user) log.info('Stopping OMERO.fs DropBox client') log.info("Exiting with exit code: %d", retVal) if retVal != 0: log.error("Quitting") return retVal
Use is subject to license terms supplied in LICENSE.txt """ import logging import threading import os, sys, traceback # Third party path package. It provides much of the # functionality of os.path but without the complexity. # Imported as pathModule to avoid clashes. import path as pathModule # Now try to import the correct MonitorServer package import fsUtil try: PlatformMonitor = __import__(fsUtil.monitorPackage()) except: raise import omero.all import omero.grid.monitors as monitors class MonitorFactory(object): @staticmethod def createMonitor(mType, eTypes, pMode, pathString, whitelist, blacklist, timeout, blockSize, ignoreSysFiles, ignoreDirEvents, proxy, monitorId): if str(mType) == 'Persistent': return PersistentMonitor(eTypes, pMode, pathString, whitelist,