示例#1
0
    def __init__(self, secret=None):
        # locate the docs, so that the /docs url will point to the appropriate
        # docs, either for the current release or the current development build
        if is_dev_build():
            idxpath = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs',
                                   '_build', 'html')
            doc_handler = web.StaticFileHandler
            doc_handler_options = { 'path': idxpath, 'default_filename': 'index.html' }
        else:
            # look for docs online
            import openmdao.util.releaseinfo
            version = openmdao.util.releaseinfo.__version__
            idxpath = 'http://openmdao.org/releases/%s/docs/index.html' % version
            doc_handler = web.RedirectHandler
            doc_handler_options = { 'url': idxpath, 'permanent': False }
            
        handlers = [
            web.url(r'/login',  LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit',   ExitHandler),
            web.url(r'/docs/plugins/(.*)',  PluginDocsHandler, { 'route': '/docs/plugins/' }),
            web.url(r'/docs/(.*)',  doc_handler, doc_handler_options ),
            web.url(r'/',       web.RedirectHandler, { 'url':'/projects', 'permanent':False })
        ]
        handlers.extend(proj.handlers)
        handlers.extend(wksp.handlers)

        if secret is None:
            secret = os.urandom(1024)

        app_path     = os.path.dirname(os.path.abspath(__file__))
        app_settings = {
            'login_url':         '/login',
            'static_path':       os.path.join(app_path, 'static'),
            'template_path':     os.path.join(app_path, 'templates'),
            'cookie_secret':     secret,
            'debug':             True,
        }

        user_dir = get_user_dir()

        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)

        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)

        self.session_manager = TornadoSessionManager(secret, session_dir)
        self.server_manager  = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer')

        super(App, self).__init__(handlers, **app_settings)
示例#2
0
class App(web.Application):
    ''' openmdao web application
        extends tornado web app with URL mappings, settings and server manager
    '''

    def __init__(self, secret=None):
        from openmdao.gui.handlers import LoginHandler, LogoutHandler, ExitHandler
        handlers = [
            web.url(r'/login',  LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit',   ExitHandler),
            web.url(r'/',       web.RedirectHandler, {'url':'/projects', 'permanent':False}),           
        ]        
        
        import openmdao.gui.handlers_projectdb as proj
        handlers.extend(proj.handlers)
        
        import openmdao.gui.handlers_workspace as wksp
        handlers.extend(wksp.handlers)
        
        if secret is None:
            secret = os.urandom(1024)
            
        app_path     = os.path.dirname(os.path.abspath(__file__))
        app_settings = { 
            'login_url':         '/login',
            'static_path':       os.path.join(app_path, 'static'),
            'template_path':     os.path.join(app_path, 'templates'),
            'cookie_secret':     secret,
            'debug':             True,
        }
        
        user_dir = get_user_dir()
        
        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)
        
        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)
            
        self.session_manager = TornadoSessionManager(secret,session_dir)
        self.server_manager  = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer')
        
        super(App, self).__init__(handlers, **app_settings)

    def exit(self):
        self.server_manager.cleanup()
        DEBUG('Exit requested, shutting down....\n')
        ioloop.IOLoop.instance().add_timeout(time.time()+5, sys.exit) 
示例#3
0
def run_simple():
    ''' create a ZMQServer for simple model, run & query it
    '''
    server_id = 'OptimizationUnconstrained'
    classpath = 'openmdao.examples.simple.optimization_unconstrained.OptimizationUnconstrained'
    mgr = ZMQServerManager(classpath)
    srv = mgr.server(server_id)
    if srv is not None:
        out_url = mgr.get_out_socket_url(server_id)
        out_rdr = OutStreamRedirector('OPT OUT', out_url,
                                      'OptimizationUnconstrained.out')
        out_rdr.start()

        pub_url = mgr.get_pub_socket_url(server_id)
        pub_rdr = OutStreamRedirector('OPT PUB', pub_url,
                                      'OptimizationUnconstrained.pub')
        pub_rdr.start()

        time.sleep(5)  # give them time to start up

        srv.dir()
        srv.register_published_vars(
            ['paraboloid.x', 'paraboloid.y', 'paraboloid.f_xy'])
        srv.run()

        print 'x =', srv.get('paraboloid.x')
        print 'y =', srv.get('paraboloid.y')
        print 'f_xy =', srv.get('paraboloid.f_xy')

        time.sleep(15)  # give it time to finish
        mgr.delete_server('OptimizationUnconstrained')
        out_rdr.terminate()
        pub_rdr.terminate()
示例#4
0
    def __init__(self, secret=None, external=False):
        # locate the docs, so that the /docs url will point to the appropriate
        # docs, either for the current release or the current development build
        if is_dev_build():
            docpath = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs',
                                   '_build', 'html')
        else:
            import openmdao.main
            docpath = os.path.join(os.path.dirname(openmdao.main.__file__), 'docs')

        handlers = [
            web.url(r'/',       web.RedirectHandler, {'url': '/projects', 'permanent': False}),
            web.url(r'/login',  LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit',   ExitHandler),
            web.url(r'/docs/plugins/(.*)', PluginDocsHandler, {'route': '/docs/plugins/'}),
            web.url(r'/docs/(.*)', web.StaticFileHandler, {'path': docpath, 'default_filename': 'index.html'}),
        ]
        handlers.extend(proj.handlers)
        handlers.extend(wksp.handlers)

        if secret is None:
            secret = os.urandom(1024)

        app_path     = os.path.dirname(os.path.abspath(__file__))
        app_settings = {
            'login_url':         '/login',
            'static_path':       os.path.join(app_path, 'static'),
            'template_path':     os.path.join(app_path, 'templates'),
            'cookie_secret':     secret,
            'debug':             True,
        }

        user_dir = get_user_dir()

        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)

        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)

        self.session_manager = TornadoSessionManager(secret, session_dir)
        self.server_manager  = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer', external)

        # External termination normally only used during GUI testing.
        if sys.platform == 'win32':
            # Fake SIGTERM by polling for a .sigterm file.
            self._exit_requested = False
            self._poller = threading.Thread(target=self._sigterm_poller,
                                            name='SIGTERM poller')
            self._poller.daemon = True
            self._poller.start()
        else:
            signal.signal(signal.SIGTERM, self._sigterm_handler)

        super(App, self).__init__(handlers, **app_settings)
示例#5
0
    def __init__(self, secret=None):
        # locate the docs, so that the /docs url will point to the appropriate
        # docs, either for the current release or the current development build
        if is_dev_build():
            idxpath = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs',
                                   '_build', 'html')
            doc_handler = web.StaticFileHandler
            doc_handler_options = { 'path': idxpath, 'default_filename': 'index.html' }
        else:
            # look for docs online
            import openmdao.util.releaseinfo
            version = openmdao.util.releaseinfo.__version__
            idxpath = 'http://openmdao.org/releases/%s/docs/index.html' % version
            doc_handler = web.RedirectHandler
            doc_handler_options = { 'url': idxpath, 'permanent': False }
            
        handlers = [
            web.url(r'/login',  LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit',   ExitHandler),
            web.url(r'/docs/plugins/(.*)',  PluginDocsHandler, { 'route': '/docs/plugins/' }),
            web.url(r'/docs/(.*)',  doc_handler, doc_handler_options ),
            web.url(r'/',       web.RedirectHandler, { 'url':'/projects', 'permanent':False })
        ]
        handlers.extend(proj.handlers)
        handlers.extend(wksp.handlers)

        if secret is None:
            secret = os.urandom(1024)

        app_path     = os.path.dirname(os.path.abspath(__file__))
        app_settings = {
            'login_url':         '/login',
            'static_path':       os.path.join(app_path, 'static'),
            'template_path':     os.path.join(app_path, 'templates'),
            'cookie_secret':     secret,
            'debug':             True,
        }

        user_dir = get_user_dir()

        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)

        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)

        self.session_manager = TornadoSessionManager(secret, session_dir)
        self.server_manager  = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer')

        global _MGR
        _MGR = self.server_manager
        signal.signal(signal.SIGTERM, self._sigterm_handler)
        super(App, self).__init__(handlers, **app_settings)
def run_simple():
    """ create a ZMQServer for simple model, run & query it
    """
    server_id = "OptimizationUnconstrained"
    classpath = "openmdao.examples.simple.optimization_unconstrained.OptimizationUnconstrained"
    mgr = ZMQServerManager(classpath)
    srv = mgr.server(server_id)
    if srv is not None:
        out_url = mgr.get_out_socket_url(server_id)
        out_rdr = OutStreamRedirector("OPT OUT", out_url, "OptimizationUnconstrained.out")
        out_rdr.start()

        pub_url = mgr.get_pub_socket_url(server_id)
        pub_rdr = OutStreamRedirector("OPT PUB", pub_url, "OptimizationUnconstrained.pub")
        pub_rdr.start()

        time.sleep(5)  # give them time to start up

        srv.dir()
        srv.register_published_vars(["paraboloid.x", "paraboloid.y", "paraboloid.f_xy"])
        srv.run()

        print "x =", srv.get("paraboloid.x")
        print "y =", srv.get("paraboloid.y")
        print "f_xy =", srv.get("paraboloid.f_xy")

        time.sleep(15)  # give it time to finish
        mgr.delete_server("OptimizationUnconstrained")
        out_rdr.terminate()
        pub_rdr.terminate()
示例#7
0
 def setUp(self):
     self.server_mgr = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer')
     self.cserver = self.server_mgr.server('test')
     
     out_url = self.server_mgr.get_out_socket_url('test')
     self.out_rdr = OutStreamRedirector('OUT',out_url,'test.out')
     self.out_rdr.start()
         
     pub_url = self.server_mgr.get_pub_socket_url('test')
     self.pub_rdr = OutStreamRedirector('PUB',pub_url,'test.pub')
     self.pub_rdr.start()
     
     time.sleep(2)   # give them time to start up 
示例#8
0
 def __init__(self, secret=None):
     from openmdao.gui.handlers import LoginHandler, LogoutHandler, ExitHandler
     handlers = [
         web.url(r'/login',  LoginHandler),
         web.url(r'/logout', LogoutHandler),
         web.url(r'/exit',   ExitHandler),
         web.url(r'/',       web.RedirectHandler, {'url':'/projects', 'permanent':False}),           
     ]        
     
     import openmdao.gui.handlers_projectdb as proj
     handlers.extend(proj.handlers)
     
     import openmdao.gui.handlers_workspace as wksp
     handlers.extend(wksp.handlers)
     
     if secret is None:
         secret = os.urandom(1024)
         
     app_path     = os.path.dirname(os.path.abspath(__file__))
     app_settings = { 
         'login_url':         '/login',
         'static_path':       os.path.join(app_path, 'static'),
         'template_path':     os.path.join(app_path, 'templates'),
         'cookie_secret':     secret,
         'debug':             True,
     }
     
     user_dir = get_user_dir()
     
     self.project_dir = os.path.join(user_dir, 'projects')
     ensure_dir(self.project_dir)
     
     session_dir = os.path.join(user_dir, 'sessions')
     ensure_dir(session_dir)
         
     self.session_manager = TornadoSessionManager(secret,session_dir)
     self.server_manager  = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer')
     
     super(App, self).__init__(handlers, **app_settings)
示例#9
0
    def __init__(self, secret=None, external=False):
        # locate the docs, so that the /docs url will point to the appropriate
        # docs, either for the current release or the current development build
        if is_dev_build():
            docpath = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs',
                                   '_build', 'html')
        else:
            import openmdao.main
            docpath = os.path.join(os.path.dirname(openmdao.main.__file__),
                                   'docs')

        handlers = [
            web.url(r'/', web.RedirectHandler, {
                'url': '/projects',
                'permanent': False
            }),
            web.url(r'/login', LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit', ExitHandler),
            web.url(r'/docs/plugins/(.*)', PluginDocsHandler,
                    {'route': '/docs/plugins/'}),
            web.url(r'/docs/(.*)', web.StaticFileHandler, {
                'path': docpath,
                'default_filename': 'index.html'
            })
        ]
        handlers.extend(proj.handlers)
        handlers.extend(wksp.handlers)

        if secret is None:
            secret = os.urandom(1024)

        app_path = os.path.dirname(os.path.abspath(__file__))
        app_settings = {
            'login_url': '/login',
            'static_path': os.path.join(app_path, 'static'),
            'template_path': os.path.join(app_path, 'templates'),
            'cookie_secret': secret,
            'debug': True,
        }

        user_dir = get_user_dir()

        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)

        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)

        self.session_manager = TornadoSessionManager(secret, session_dir)
        self.server_manager = ZMQServerManager(
            'openmdao.gui.consoleserver.ConsoleServer', external)

        # External termination normally only used during GUI testing.
        if sys.platform == 'win32':
            # Fake SIGTERM by polling for a .sigterm file.
            self._exit_requested = False
            self._poller = threading.Thread(target=self._sigterm_poller,
                                            name='SIGTERM poller')
            self._poller.daemon = True
            self._poller.start()
        else:
            signal.signal(signal.SIGTERM, self._sigterm_handler)

        super(App, self).__init__(handlers, **app_settings)
示例#10
0
class App(web.Application):
    ''' Openmdao web application.
        Extends tornado web app with URL mappings, settings and server manager.
    '''
    def __init__(self, secret=None, external=False):
        # locate the docs, so that the /docs url will point to the appropriate
        # docs, either for the current release or the current development build
        if is_dev_build():
            docpath = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs',
                                   '_build', 'html')
        else:
            import openmdao.main
            docpath = os.path.join(os.path.dirname(openmdao.main.__file__),
                                   'docs')

        handlers = [
            web.url(r'/', web.RedirectHandler, {
                'url': '/projects',
                'permanent': False
            }),
            web.url(r'/login', LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit', ExitHandler),
            web.url(r'/docs/plugins/(.*)', PluginDocsHandler,
                    {'route': '/docs/plugins/'}),
            web.url(r'/docs/(.*)', web.StaticFileHandler, {
                'path': docpath,
                'default_filename': 'index.html'
            })
        ]
        handlers.extend(proj.handlers)
        handlers.extend(wksp.handlers)

        if secret is None:
            secret = os.urandom(1024)

        app_path = os.path.dirname(os.path.abspath(__file__))
        app_settings = {
            'login_url': '/login',
            'static_path': os.path.join(app_path, 'static'),
            'template_path': os.path.join(app_path, 'templates'),
            'cookie_secret': secret,
            'debug': True,
        }

        user_dir = get_user_dir()

        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)

        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)

        self.session_manager = TornadoSessionManager(secret, session_dir)
        self.server_manager = ZMQServerManager(
            'openmdao.gui.consoleserver.ConsoleServer', external)

        # External termination normally only used during GUI testing.
        if sys.platform == 'win32':
            # Fake SIGTERM by polling for a .sigterm file.
            self._exit_requested = False
            self._poller = threading.Thread(target=self._sigterm_poller,
                                            name='SIGTERM poller')
            self._poller.daemon = True
            self._poller.start()
        else:
            signal.signal(signal.SIGTERM, self._sigterm_handler)

        super(App, self).__init__(handlers, **app_settings)

    def _sigterm_poller(self):
        """ On Windows, poll for an external termination request file. """
        sigfile = os.path.join(os.getcwd(), 'SIGTERM.txt')
        while not self._exit_requested:
            time.sleep(1)
            if os.path.exists(sigfile):
                DEBUG('Detected SIGTERM, shutting down...')
                self._shutdown()
                break

    def _sigterm_handler(self, signum, frame):
        """ On Linux/OS X, handle SIGTERM signal. """
        DEBUG('Received SIGTERM, shutting down...')
        self._shutdown()

    def exit(self):
        """ Shutdown. """
        DEBUG('Exit requested, shutting down...')
        if sys.platform == 'win32':
            self._exit_requested = True
            self._poller.join(3)
        self._shutdown()

    def _shutdown(self):
        """ Stop all subprocesses and exit. """
        self.server_manager.cleanup()
        ioloop.IOLoop.instance().add_timeout(time.time() + 5, sys.exit)
示例#11
0
class App(web.Application):
    ''' Openmdao web application.
        Extends tornado web app with URL mappings, settings and server manager.
    '''

    def __init__(self, secret=None, external=False):
        # locate the docs, so that the /docs url will point to the appropriate
        # docs, either for the current release or the current development build
        if is_dev_build():
            docpath = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs',
                                   '_build', 'html')
        else:
            import openmdao.main
            docpath = os.path.join(os.path.dirname(openmdao.main.__file__), 'docs')

        handlers = [
            web.url(r'/',       web.RedirectHandler, {'url': '/projects', 'permanent': False}),
            web.url(r'/login',  LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit',   ExitHandler),
            web.url(r'/docs/plugins/(.*)', PluginDocsHandler, {'route': '/docs/plugins/'}),
            web.url(r'/docs/(.*)', web.StaticFileHandler, {'path': docpath, 'default_filename': 'index.html'}),
        ]
        handlers.extend(proj.handlers)
        handlers.extend(wksp.handlers)

        if secret is None:
            secret = os.urandom(1024)

        app_path     = os.path.dirname(os.path.abspath(__file__))
        app_settings = {
            'login_url':         '/login',
            'static_path':       os.path.join(app_path, 'static'),
            'template_path':     os.path.join(app_path, 'templates'),
            'cookie_secret':     secret,
            'debug':             True,
        }

        user_dir = get_user_dir()

        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)

        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)

        self.session_manager = TornadoSessionManager(secret, session_dir)
        self.server_manager  = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer', external)

        # External termination normally only used during GUI testing.
        if sys.platform == 'win32':
            # Fake SIGTERM by polling for a .sigterm file.
            self._exit_requested = False
            self._poller = threading.Thread(target=self._sigterm_poller,
                                            name='SIGTERM poller')
            self._poller.daemon = True
            self._poller.start()
        else:
            signal.signal(signal.SIGTERM, self._sigterm_handler)

        super(App, self).__init__(handlers, **app_settings)

    def _sigterm_poller(self):
        """ On Windows, poll for an external termination request file. """
        sigfile = os.path.join(os.getcwd(), 'SIGTERM.txt')
        while not self._exit_requested:
            time.sleep(1)
            if os.path.exists(sigfile):
                DEBUG('Detected SIGTERM, shutting down...')
                self._shutdown()
                break

    def _sigterm_handler(self, signum, frame):
        """ On Linux/OS X, handle SIGTERM signal. """
        DEBUG('Received SIGTERM, shutting down...')
        self._shutdown()

    def exit(self):
        """ Shutdown. """
        DEBUG('Exit requested, shutting down...')
        if sys.platform == 'win32':
            self._exit_requested = True
            self._poller.join(3)
        self._shutdown()

    def _shutdown(self):
        """ Stop all subprocesses and exit. """
        self.server_manager.cleanup()
        ioloop.IOLoop.instance().add_timeout(time.time() + 5, sys.exit)
示例#12
0
class App(web.Application):
    ''' openmdao web application
        extends tornado web app with URL mappings, settings and server manager
    '''
    def __init__(self, secret=None):
        # locate the docs, so that the /docs url will point to the appropriate
        # docs, either for the current release or the current development build
        if is_dev_build():
            idxpath = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs',
                                   '_build', 'html')
            doc_handler = web.StaticFileHandler
            doc_handler_options = {
                'path': idxpath,
                'default_filename': 'index.html'
            }
        else:
            # look for docs online
            import openmdao.util.releaseinfo
            version = openmdao.util.releaseinfo.__version__
            idxpath = 'http://openmdao.org/releases/%s/docs/index.html' % version
            doc_handler = web.RedirectHandler
            doc_handler_options = {'url': idxpath, 'permanent': False}

        handlers = [
            web.url(r'/login', LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit', ExitHandler),
            web.url(r'/docs/plugins/(.*)', PluginDocsHandler,
                    {'route': '/docs/plugins/'}),
            web.url(r'/docs/(.*)', doc_handler, doc_handler_options),
            web.url(r'/', web.RedirectHandler, {
                'url': '/projects',
                'permanent': False
            })
        ]
        handlers.extend(proj.handlers)
        handlers.extend(wksp.handlers)

        if secret is None:
            secret = os.urandom(1024)

        app_path = os.path.dirname(os.path.abspath(__file__))
        app_settings = {
            'login_url': '/login',
            'static_path': os.path.join(app_path, 'static'),
            'template_path': os.path.join(app_path, 'templates'),
            'cookie_secret': secret,
            'debug': True,
        }

        user_dir = get_user_dir()

        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)

        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)

        self.session_manager = TornadoSessionManager(secret, session_dir)
        self.server_manager = ZMQServerManager(
            'openmdao.gui.consoleserver.ConsoleServer')

        global _MGR
        _MGR = self.server_manager
        signal.signal(signal.SIGTERM, self._sigterm_handler)
        super(App, self).__init__(handlers, **app_settings)

    def _sigterm_handler(self, signum, frame):
        DEBUG('Received SIGTERM, shutting down....\n')
        _MGR.cleanup()
        ioloop.IOLoop.instance().add_timeout(time.time() + 5, sys.exit)

    def exit(self):
        self.server_manager.cleanup()
        DEBUG('Exit requested, shutting down....\n')
        ioloop.IOLoop.instance().add_timeout(time.time() + 5, sys.exit)
def run_cserver():
    """ create a ZMQ-based console server & exercise it
    """
    server_id = "ConsoleServer"
    classpath = "openmdao.gui.consoleserver.ConsoleServer"
    mgr = ZMQServerManager(classpath)
    cserver = mgr.server(server_id)
    if cserver is not None:
        print "=============================================================="
        print "================= started cserver ============================"
        print "=============================================================="
        # print cserver.onecmd("!!!!!!!!!!!!!!!!!!!  I'm Alive   !!!!!!!!!!!!!")
        print cserver.getcwd()
        # print 'types:'
        # print cserver.get_available_types()

        print "=============================================================="
        print "================= redirecting streams ========================"
        print "=============================================================="
        # subscriber to the cserver output & print to stdout
        out_url = mgr.get_out_socket_url(server_id)
        out_rdr = OutStreamRedirector("CSERVER OUT", out_url, "cserver.out")
        out_rdr.start()

        pub_url = mgr.get_pub_socket_url(server_id)
        pub_rdr = OutStreamRedirector("CSERVER PUB", pub_url, "cserver.pub")
        pub_rdr.start()

        time.sleep(5)  # give them time to start up

        print "=============================================================="
        print "================ load project ================================"
        print "=============================================================="
        path = os.path.dirname(os.path.abspath(__file__))
        proj_file = os.path.join(path, "sellar.proj")
        print cserver.load_project(proj_file)
        print_dict(cserver.get_files())

        print "=============================================================="
        print "================ import from  file ==========================="
        print "=============================================================="
        print cserver.onecmd("from sellar_CO import SellarCO")
        print_dict(cserver.get_workingtypes())
        # print cserver.onecmd('trace')

        print "=============================================================="
        print "=============== execute script to set up the problem ========="
        print "=============================================================="
        script = """
top = SellarCO()
top.z1_t = 5.0
top.dis1.z1 = 5.0
top.dis2.z1 = 5.0

top.z2_t = 2.0
top.dis1.z2 = 2.0
top.dis2.z2 = 2.0

top.x1_t = 1.0
top.dis1.x1 = 1.0

top.y1_t = 3.16
top.y2_t = 0.0
top.dis1.y2 = 0.0
top.dis2.y1 = 3.16
"""
        cserver.onecmd(script)
        # print cserver.onecmd('trace')

        print cserver.onecmd("print dir(top)")
        print_json(cserver.get_structure(""))
        print_json(cserver.get_workflow("top"))
        print cserver.get_value("top.dis1.z1")
        print cserver.get_value("top.dis1.z2")
        print cserver.get_value("top.dis1.x1")

        print "=============================================================="
        print "================= register published vars and run ============"
        print "=============================================================="
        cserver.onecmd("top.register_published_vars(['dis1.z1', 'dis1.z2', 'dis1.x1'])")
        cserver.run()

        print "=============================================================="
        print "================ get results ================================="
        print "=============================================================="
        print cserver.onecmd("trace")
        print cserver.get_value("top.dis1.z1")
        print cserver.get_value("top.dis1.z2")
        print cserver.get_value("top.dis1.x1")

        print "=============================================================="
        print "================ delete server ==============================="
        print "=============================================================="
        time.sleep(15)  # give it time to finish
        mgr.delete_server(server_id)
        out_rdr.terminate()
        pub_rdr.terminate()
示例#14
0
def run_cserver():
    ''' create a ZMQ-based console server & exercise it
    '''
    server_id = 'ConsoleServer'
    classpath = 'openmdao.gui.consoleserver.ConsoleServer'
    mgr = ZMQServerManager(classpath)
    cserver = mgr.server(server_id)
    if cserver is not None:
        print '=============================================================='
        print '================= started cserver ============================'
        print '=============================================================='
        #print cserver.onecmd("!!!!!!!!!!!!!!!!!!!  I'm Alive   !!!!!!!!!!!!!")
        print cserver.getcwd()
        #print 'types:'
        #print cserver.get_available_types()

        print '=============================================================='
        print '================= redirecting streams ========================'
        print '=============================================================='
        # subscriber to the cserver output & print to stdout
        out_url = mgr.get_out_socket_url(server_id)
        out_rdr = OutStreamRedirector('CSERVER OUT', out_url, 'cserver.out')
        out_rdr.start()

        pub_url = mgr.get_pub_socket_url(server_id)
        pub_rdr = OutStreamRedirector('CSERVER PUB', pub_url, 'cserver.pub')
        pub_rdr.start()

        time.sleep(5)  # give them time to start up

        print '=============================================================='
        print '================ load project ================================'
        print '=============================================================='
        path = os.path.dirname(os.path.abspath(__file__))
        proj_file = os.path.join(path, 'sellar.proj')
        print cserver.load_project(proj_file)
        print_dict(cserver.get_files())

        print '=============================================================='
        print '================ import from  file ==========================='
        print '=============================================================='
        print cserver.onecmd('from sellar_CO import SellarCO')
        print_dict(cserver.get_workingtypes())
        #print cserver.onecmd('trace')

        print '=============================================================='
        print '=============== execute script to set up the problem ========='
        print '=============================================================='
        script = """
top = SellarCO()
top.z1_t = 5.0
top.dis1.z1 = 5.0
top.dis2.z1 = 5.0

top.z2_t = 2.0
top.dis1.z2 = 2.0
top.dis2.z2 = 2.0

top.x1_t = 1.0
top.dis1.x1 = 1.0

top.y1_t = 3.16
top.y2_t = 0.0
top.dis1.y2 = 0.0
top.dis2.y1 = 3.16
"""
        cserver.onecmd(script)
        #print cserver.onecmd('trace')

        print cserver.onecmd('print dir(top)')
        print_json(cserver.get_structure(''))
        print_json(cserver.get_workflow('top'))
        print cserver.get_value('top.dis1.z1')
        print cserver.get_value('top.dis1.z2')
        print cserver.get_value('top.dis1.x1')

        print '=============================================================='
        print '================= register published vars and run ============'
        print '=============================================================='
        cserver.onecmd(
            "top.register_published_vars(['dis1.z1', 'dis1.z2', 'dis1.x1'])")
        cserver.run()

        print '=============================================================='
        print '================ get results ================================='
        print '=============================================================='
        print cserver.onecmd('trace')
        print cserver.get_value('top.dis1.z1')
        print cserver.get_value('top.dis1.z2')
        print cserver.get_value('top.dis1.x1')

        print '=============================================================='
        print '================ delete server ==============================='
        print '=============================================================='
        time.sleep(15)  # give it time to finish
        mgr.delete_server(server_id)
        out_rdr.terminate()
        pub_rdr.terminate()
示例#15
0
class test_cserver(unittest.TestCase):
    
    def setUp(self):
        self.server_mgr = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer')
        self.cserver = self.server_mgr.server('test')
        
        out_url = self.server_mgr.get_out_socket_url('test')
        self.out_rdr = OutStreamRedirector('OUT',out_url,'test.out')
        self.out_rdr.start()
            
        pub_url = self.server_mgr.get_pub_socket_url('test')
        self.pub_rdr = OutStreamRedirector('PUB',pub_url,'test.pub')
        self.pub_rdr.start()
        
        time.sleep(2)   # give them time to start up 

    def test_conmin(self):
        div = '-'*70
        
        print div
        print 'LOAD PROJECT'
        path = os.path.dirname(os.path.abspath(__file__))
        self.cserver.load_project(os.path.join(path,'simple_1.proj'))
            
        print div
        print 'CHECK FILES (note paraboloid.py defining Paraboloid)'
        print_dict(self.cserver.get_files())
        
        print div
        print 'IMPORT PARABOLOID'
        self.cserver.onecmd('from paraboloid import Paraboloid')

        print div
        print 'WORKING TYPES'
        print_dict(self.cserver.get_workingtypes())

        print div
        print 'CREATE ASSEMBLY'
        print self.cserver.add_component('prob','openmdao.main.assembly.Assembly','');
        
        print div
        print 'COMPONENTS'
        print_json(self.cserver.get_components())
        
        print div
        print 'ADD CONMIN DRIVER'
        print self.cserver.add_component('driver',
           'openmdao.lib.drivers.conmindriver.CONMINdriver','prob');
        
        print div
        print 'CHECK DRIVER ATTRIBUTES'
        print_json(self.cserver.get_attributes('prob.driver'))

        print div
        print 'CREATE PARABOLOID'
        self.cserver.add_component('p','Paraboloid','prob');
        
        print div
        print 'COMPONENTS'
        print_json(self.cserver.get_components())

        print div
        print 'STRUCTURE'
        print print_json(self.cserver.get_structure('prob'))

        print div
        print 'dir()'
        print self.cserver.onecmd('dir()')
        
    def tearDown(self):
        time.sleep(2)
        self.out_rdr.terminate()
        self.pub_rdr.terminate()
        self.cserver.terminate()