Exemplo n.º 1
0
    def run(self, args):
        """
            Main method called via app.main() below.
            
            The Ice.Application is set to callbackOnInterrupt so that it can be
            shutdown cleanly by the callback above.
            
            :param args: Arguments required by the ICE system.
            :return: Exit state.
            :rtype: int
        """

        props = self.communicator().getProperties()
        configure_server_logging(props)

        # Create a FileServer, its adapter and activate it.
        try:
            serverIdString = self.getServerIdString(props)
            serverAdapterName = self.getServerAdapterName(props)
            mServer = fsFileServer.FileServerI()
            adapter = self.communicator().createObjectAdapter(serverAdapterName)
            mServerPrx = adapter.add(mServer, self.communicator().stringToIdentity(serverIdString))
            adapter.activate() 
        except:
            log.exception("Failed create OMERO.fs FileServer: \n")
            return -1
            
        log.info('Started OMERO.fs FileServer')
        
        # Wait for an interrupt.
        self.communicator().waitForShutdown()
        
        log.info('Stopping OMERO.fs FileServer')
        return 0
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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