Exemplo n.º 1
0
    def __init__(self):
        LoggerMixin.configure()
        db.configure()
        Compute.configure()
        APIContainer.configure()

        JBoxAsyncJob.configure()
        JBoxAsyncJob.init(JBoxAsyncJob.MODE_PUB)

        self.application = tornado.web.Application(handlers=[
            (r"^/", APIInfoHandler),
            (r"^/.*/.*", APIHandler)
        ])

        self.application.settings["cookie_secret"] = JBoxCfg.get('sesskey')
        self.application.listen(JBoxCfg.get('api.manager_port'), address=socket.gethostname())
        self.application.listen(JBoxCfg.get('api.manager_port'), address='localhost')

        self.ioloop = ioloop.IOLoop.instance()

        # run container maintainence every 5 minutes
        run_interval = 5 * 60 * 1000
        self.log_info("Container maintenance every " + str(run_interval / (60 * 1000)) + " minutes")
        self.ct = ioloop.PeriodicCallback(JBoxAPI.do_housekeeping, run_interval, self.ioloop)
        self.sigct = ioloop.PeriodicCallback(JBoxAPI.do_signals, 1000, self.ioloop)
Exemplo n.º 2
0
    def do_housekeeping():
        terminating = False
        server_delete_timeout = JBoxCfg.get('interactive.expire')
        inactive_timeout = JBoxCfg.get('interactive.inactivity_timeout')
        SessContainer.maintain(max_timeout=server_delete_timeout, inactive_timeout=inactive_timeout)
        is_leader = is_cluster_leader()

        if is_leader:
            terminating = False
        else:
            try:
                terminating = JBoxAsyncJob.sync_is_terminating()
                if terminating['code'] == 0:
                    terminating = terminating['data']
                else:
                    JBox.log_error("Error checking if instance is terminating. Assuming False.")
                    terminating = False
            except:
                JBox.log_error("Exception checking if instance is terminating. Assuming False.")
                terminating = False

        if is_leader:
            JBox.log_info("I am the cluster leader")
            JBox.update_juliabox_status()
            JBox.monitor_registrations()
            if not JBoxDynConfig.is_stat_collected_within(Compute.get_install_id(), 1):
                JBoxAsyncJob.async_collect_stats()

        if terminating:
            JBox.log_warn("terminating to scale down")
        else:
            JBox.do_update_user_home_image()
            JBoxAsyncJob.async_plugin_maintenance(is_leader)
Exemplo n.º 3
0
    def __init__(self):
        LoggerMixin.configure()
        db.configure()
        Compute.configure()
        APIContainer.configure()

        JBoxAsyncJob.configure()
        JBoxAsyncJob.init(JBoxAsyncJob.MODE_PUB)

        self.application = tornado.web.Application(
            handlers=[(r"^/", APIInfoHandler), (r"^/.*/.*", APIHandler)])

        self.application.settings["cookie_secret"] = JBoxCfg.get('sesskey')
        self.application.listen(JBoxCfg.get('api.manager_port'),
                                address=socket.gethostname())
        self.application.listen(JBoxCfg.get('api.manager_port'),
                                address='localhost')

        self.ioloop = ioloop.IOLoop.instance()

        # run container maintainence every 5 minutes
        run_interval = 5 * 60 * 1000
        self.log_info("Container maintenance every " +
                      str(run_interval / (60 * 1000)) + " minutes")
        self.ct = ioloop.PeriodicCallback(JBoxAPI.do_housekeeping,
                                          run_interval, self.ioloop)
        self.sigct = ioloop.PeriodicCallback(JBoxAPI.do_signals, 1000,
                                             self.ioloop)
Exemplo n.º 4
0
    def __init__(self):
        LoggerMixin.configure()
        db.configure()
        Compute.configure()
        SessContainer.configure()
        VolMgr.configure()

        JBoxAsyncJob.configure()
        JBoxAsyncJob.init(JBoxAsyncJob.MODE_PUB)

        self.application = tornado.web.Application(handlers=[
            (r"/", MainHandler),
            (r"/jboxadmin/", AdminHandler),
            (r"/jboxping/", PingHandler),
            (r"/jboxcors/", CorsHandler)
        ])
        JBPluginHandler.add_plugin_handlers(self.application)
        JBPluginUI.create_include_files()

        # cookie_secret = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in xrange(32))
        # use sesskey as cookie secret to be able to span multiple tornado servers
        self.application.settings["cookie_secret"] = JBoxCfg.get('sesskey')
        self.application.settings["plugin_features"] = JBox.get_pluggedin_features()
        self.application.listen(JBoxCfg.get('interactive.manager_port'), address=socket.gethostname())
        self.application.listen(JBoxCfg.get('interactive.manager_port'), address='localhost')

        self.ioloop = tornado.ioloop.IOLoop.instance()

        # run container maintainence every 5 minutes
        run_interval = 5 * 60 * 1000
        self.log_info("Container maintenance every " + str(run_interval / (60 * 1000)) + " minutes")
        self.ct = tornado.ioloop.PeriodicCallback(JBox.do_housekeeping, run_interval, self.ioloop)
        self.sigct = tornado.ioloop.PeriodicCallback(JBox.do_signals, 1000, self.ioloop)
Exemplo n.º 5
0
    def update_juliabox_status():
        instances = Compute.get_all_instances()

        in_error = 0
        HTML = "<html><body><center><pre>\nJuliaBox is Up.\n\nLast updated: " + datetime.datetime.now().isoformat() + " UTC\n\nLoads: "

        for inst in instances:
            try:
                status = JBoxAsyncJob.sync_api_status(inst)['data']
                HTML += (str(status['load']) + '% ')
            except:
                in_error += 1
                pass

        HTML += ("\n\nErrors: " + str(in_error) + "\n\nAWS Status: <a href='http://status.aws.amazon.com/'>status.aws.amazon.com</a></pre></center></body></html>")

        plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_BUCKETSTORE)
        bkt = JBoxCfg.get("cloud_host.status_bucket")
        if plugin is not None and bkt is not None:
            try:
                f = open("/tmp/index.html", "w")
                f.write(HTML)
                f.close()
                plugin.push(bkt, "/tmp/index.html")
            finally:
                os.remove("/tmp/index.html")
        else:
            JBox.log_debug("Status: %s", HTML)

        return None
Exemplo n.º 6
0
    def update_juliabox_status():
        in_error = len(
            JBoxInstanceProps.get_stale_instances(Compute.get_install_id()))
        instance_status = JBoxInstanceProps.get_instance_status(
            Compute.get_install_id())

        HTML = "<html><body><center><pre>\nJuliaBox is Up.\n\nLast updated: " + datetime.datetime.now(
        ).isoformat() + " UTC\n\nLoads: "
        for iid in instance_status:
            HTML += (str(instance_status[iid]['load']) + '% ')

        HTML += (
            "\n\nErrors: " + str(in_error) +
            "\n\nAWS Status: <a href='http://status.aws.amazon.com/'>status.aws.amazon.com</a></pre></center></body></html>"
        )

        plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_BUCKETSTORE)
        bkt = JBoxCfg.get("cloud_host.status_bucket")
        if plugin is not None and bkt is not None:
            try:
                f = open("/tmp/index.html", "w")
                f.write(HTML)
                f.close()
                plugin.push(bkt, "/tmp/index.html")
            finally:
                os.remove("/tmp/index.html")
        else:
            JBox.log_debug("Status: %s", HTML)

        return None
Exemplo n.º 7
0
    def __init__(self):
        LoggerMixin.configure()
        db.configure()
        Compute.configure()
        SessContainer.configure()
        VolMgr.configure()

        JBoxAsyncJob.configure()
        JBoxAsyncJob.init(JBoxAsyncJob.MODE_PUB)

        self.application = tornado.web.Application(
            handlers=[(r"/", MainHandler), (
                r"/jboxadmin/",
                AdminHandler), (r"/jboxping/",
                                PingHandler), (r"/jboxcors/", CorsHandler)])
        JBPluginHandler.add_plugin_handlers(self.application)
        JBPluginUI.create_include_files()

        # cookie_secret = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in xrange(32))
        # use sesskey as cookie secret to be able to span multiple tornado servers
        self.application.settings["cookie_secret"] = JBoxCfg.get('sesskey')
        self.application.settings[
            "plugin_features"] = JBox.get_pluggedin_features()
        self.application.listen(JBoxCfg.get('interactive.manager_port'),
                                address=socket.gethostname())
        self.application.listen(JBoxCfg.get('interactive.manager_port'),
                                address='localhost')

        self.ioloop = tornado.ioloop.IOLoop.instance()

        # run container maintainence every 5 minutes
        run_interval = 5 * 60 * 1000
        self.log_info("Container maintenance every " +
                      str(run_interval / (60 * 1000)) + " minutes")
        self.ct = tornado.ioloop.PeriodicCallback(JBox.do_housekeeping,
                                                  run_interval, self.ioloop)
        self.sigct = tornado.ioloop.PeriodicCallback(JBox.do_signals, 1000,
                                                     self.ioloop)

        # or configure cacerts
        AsyncHTTPClient.configure(None, defaults=dict(validate_cert=None))
Exemplo n.º 8
0
    def do_housekeeping():
        terminating = False
        server_delete_timeout = JBoxCfg.get('interactive.expire')
        inactive_timeout = JBoxCfg.get('interactive.inactivity_timeout')
        SessContainer.maintain(max_timeout=server_delete_timeout,
                               inactive_timeout=inactive_timeout)
        is_leader = is_cluster_leader()

        if is_leader:
            terminating = False
        else:
            try:
                terminating = JBoxAsyncJob.sync_is_terminating()
                if terminating['code'] == 0:
                    terminating = terminating['data']
                else:
                    JBox.log_error(
                        "Error checking if instance is terminating. Assuming False."
                    )
                    terminating = False
            except:
                JBox.log_error(
                    "Exception checking if instance is terminating. Assuming False."
                )
                terminating = False

        if is_leader:
            JBox.log_info("I am the cluster leader")
            JBox.update_juliabox_status()
            JBox.monitor_registrations()
            if not JBoxDynConfig.is_stat_collected_within(
                    Compute.get_install_id(), 1):
                JBoxAsyncJob.async_collect_stats()

        if terminating:
            JBox.log_warn("terminating to scale down")
        else:
            JBox.do_update_user_home_image()
            JBoxAsyncJob.async_plugin_maintenance(is_leader)
Exemplo n.º 9
0
    def is_terminating():
        if not JBoxCfg.get('cloud_host.scale_down'):
            return False

        num_active = BaseContainer.num_active()
        terminate = (num_active == 0) and Compute.can_terminate(is_proposed_cluster_leader())

        if terminate:
            JBoxd.log_warn("terminating to scale down")
            try:
                Compute.deregister_instance_dns()
            except:
                JBoxd.log_error("Error deregistering instance dns")
            Compute.terminate_instance()

        return terminate
Exemplo n.º 10
0
    def __init__(self):
        LoggerMixin.configure()
        db.configure()
        Compute.configure()
        SessContainer.configure()
        APIContainer.configure()
        VolMgr.configure()

        JBoxAsyncJob.configure()
        JBoxAsyncJob.init(JBoxAsyncJob.MODE_SUB)

        self.log_debug("Container manager listening on ports: %s", repr(JBoxCfg.get('container_manager_ports')))
        JBoxd.QUEUE = JBoxAsyncJob.get()

        JBoxd.MAX_ACTIVATIONS_PER_SEC = JBoxCfg.get('user_activation.max_activations_per_sec')
        JBoxd.MAX_AUTO_ACTIVATIONS_PER_RUN = JBoxCfg.get('user_activation.max_activations_per_run')
        JBoxd.ACTIVATION_SUBJECT = JBoxCfg.get('user_activation.mail_subject')
        JBoxd.ACTIVATION_BODY = JBoxCfg.get('user_activation.mail_body')
        JBoxd.ACTIVATION_SENDER = JBoxCfg.get('user_activation.sender')
Exemplo n.º 11
0
import datetime
import os
import docker

from jbox_util import JBoxCfg, LoggerMixin, unique_sessname
from juliabox import db
from juliabox.db import JBoxDynConfig, JBoxSessionProps, JBoxUserV2
from juliabox.cloud import JBPluginCloud
from juliabox.cloud import Compute

conf_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../conf'))
conf_file = os.path.join(conf_dir, 'tornado.conf')
user_conf_file = os.path.join(conf_dir, 'jbox.user')

JBoxCfg.read(conf_file, user_conf_file)
JBoxCfg.dckr = docker.Client()

LoggerMixin.configure()
db.configure()
Compute.configure()

TESTCLSTR = 'testcluster'


class TestDBTables(LoggerMixin):
    @staticmethod
    def test():
        sprops = JBoxSessionProps(TESTCLSTR, unique_sessname('*****@*****.**'))
        TestDBTables.log_debug("JBoxSessionProps. user_id: %s, snapshot_id: %s, message: %s",
                               sprops.get_user_id(),
                               sprops.get_snapshot_id(),
Exemplo n.º 12
0
 def configure():
     JBoxAsyncJob.PORTS = JBoxCfg.get('container_manager_ports')
     JBoxAsyncJob.ENCKEY = JBoxCfg.get('sesskey')
Exemplo n.º 13
0
 def configure():
     JBoxAsyncJob.PORTS = JBoxCfg.get('container_manager_ports')
     JBoxAsyncJob.ENCKEY = JBoxCfg.get('sesskey')
Exemplo n.º 14
0
 def configure():
     JBoxAsyncJob.PORTS = JBoxCfg.get("container_manager_ports")
     JBoxAsyncJob.ENCKEY = JBoxCfg.get("sesskey")