def run(self,args): from omero.rtypes import ObjectFactories as rFactories from omero.columns import ObjectFactories as cFactories props = self.communicator().getProperties() configure_server_logging(props) self.logger = logging.getLogger("omero.util.Server") self.logger.info("*"*80) self.waitOnStartup() self.logger.info("Starting") failures = 0 for x in self.dependencies: if not x.check(self.logger): failures += 1 if failures: self.logger.error("Missing dependencies: %s" % failures) sys.exit(50) self.shutdownOnInterrupt() try: ofr.registerObjectFactory(self.communicator(), None) # No client for of in rFactories.values() + cFactories.values(): of.register(self.communicator()) try: serverid = self.communicator().getProperties().getProperty("Ice.ServerId") ctx = ServerContext(serverid, self.communicator(), self.stop_event) self.impl = self.impl_class(ctx) getattr(self.impl, "cleanup") # Required per docs except: self.logger.error("Failed initialization", exc_info=1) sys.exit(100) try: self.adapter = self.communicator().createObjectAdapter(self.adapter_name) self.adapter.activate() ctx.add_servant(self.adapter, self.impl, self.identity) # calls setProxy prx = self.adapter.createDirectProxy(self.identity) # ticket:1978 for non-collocated registries add_grid_object(self.communicator(), prx) # This must happen _after_ activation except: self.logger.error("Failed activation", exc_info=1) sys.exit(200) self.logger.info("Entering main loop") self.communicator().waitForShutdown() finally: self.stop_event.set() # Let's all waits shutdown self.logger.info("Cleanup") self.cleanup() self.logger.info("Stopped") self.logger.info("*"*80)
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
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