示例#1
0
    def get_allow_registration(cluster):
        try:
            record = JBoxDynConfig(JBoxDB.qual(cluster, "allow_registration"))
        except JBoxDBItemNotFound:
            return True

        return record.get_value() == "True"
示例#2
0
 def set_course(cluster, course_id, course_details):
     val = json.dumps(course_details)
     course_key = "|".join(["course", course_id])
     record = JBoxDynConfig(JBoxDB.qual(cluster, course_key), create=True, value=val)
     if not record.is_new:
         record.set_value(val)
         record.save()
示例#3
0
 def set_user_home_image(cluster, bucket, pkg_file, home_file):
     img = {"bucket": bucket, "pkg_file": pkg_file, "home_file": home_file}
     img = json.dumps(img)
     record = JBoxDynConfig(JBoxDB.qual(cluster, "user_home_image"), create=True, value=img)
     if not record.is_new:
         record.set_value(img)
         record.save()
示例#4
0
 def set_course(cluster, course_id, course_details):
     val = json.dumps(course_details)
     course_key = '|'.join(['course', course_id])
     record = JBoxDynConfig(JBoxDB.qual(cluster, course_key), create=True, value=val)
     if not record.is_new:
         record.set_value(val)
         record.save()
示例#5
0
    def get_allow_registration(cluster):
        try:
            record = JBoxDynConfig(JBoxDB.qual(cluster, 'allow_registration'))
        except JBoxDBItemNotFound:
            return True

        return record.get_value() == 'True'
示例#6
0
 def get_course(cluster, course_id):
     try:
         course_key = "|".join(["course", course_id])
         record = JBoxDynConfig(JBoxDB.qual(cluster, course_key))
     except JBoxDBItemNotFound:
         return None
     return json.loads(record.get_value())
示例#7
0
 def get_course(cluster, course_id):
     try:
         course_key = '|'.join(['course', course_id])
         record = JBoxDynConfig(JBoxDB.qual(cluster, course_key))
     except JBoxDBItemNotFound:
         return None
     return json.loads(record.get_value())
示例#8
0
 def get_user_home_image(cluster):
     try:
         record = JBoxDynConfig(JBoxDB.qual(cluster, 'user_home_image'))
     except JBoxDBItemNotFound:
         return None, None, None
     img = json.loads(record.get_value())
     pkg_file = img['pkg_file'] if 'pkg_file' in img else None
     home_file = img['home_file'] if 'home_file' in img else None
     return img['bucket'], pkg_file, home_file
示例#9
0
 def get_user_home_image(cluster):
     try:
         record = JBoxDynConfig(JBoxDB.qual(cluster, "user_home_image"))
     except JBoxDBItemNotFound:
         return None, None, None
     img = json.loads(record.get_value())
     pkg_file = img["pkg_file"] if "pkg_file" in img else None
     home_file = img["home_file"] if "home_file" in img else None
     return img["bucket"], pkg_file, home_file
示例#10
0
 def get_stale_instances(cluster):
     now = datetime.datetime.now(pytz.utc)
     nowsecs = JBoxInstanceProps.datetime_to_epoch_secs(now)
     valid_time = nowsecs - JBoxInstanceProps.SESS_UPDATE_INTERVAL
     stale = []
     for record in JBoxInstanceProps.scan(instance_id__beginswith=JBoxDB.qual(cluster, ''),
                                          publish_time__lt=valid_time):
         stale.append(record.get('instance_id').split('.', 1)[1])
     return stale
示例#11
0
    def set_message(cluster, message, valid_delta):
        tnow = datetime.datetime.now(pytz.utc)
        tvalid = tnow + valid_delta

        msg = {"msg": message, "valid_till": isodate.datetime_isoformat(tvalid)}
        msg = json.dumps(msg)
        record = JBoxDynConfig(JBoxDB.qual(cluster, "message"), create=True, value=msg)
        if not record.is_new:
            record.set_value(msg)
            record.save()
示例#12
0
 def get_stale_instances(cluster):
     now = datetime.datetime.now(pytz.utc)
     nowsecs = JBoxInstanceProps.datetime_to_epoch_secs(now)
     valid_time = nowsecs - JBoxInstanceProps.SESS_UPDATE_INTERVAL
     stale = []
     for record in JBoxInstanceProps.scan(
             instance_id__beginswith=JBoxDB.qual(cluster, ''),
             publish_time__lt=valid_time):
         stale.append(record.get('instance_id').split('.', 1)[1])
     return stale
示例#13
0
 def get_available_instances(cluster):
     now = datetime.datetime.now(pytz.utc)
     nowsecs = JBoxInstanceProps.datetime_to_epoch_secs(now)
     valid_time = nowsecs - JBoxInstanceProps.SESS_UPDATE_INTERVAL
     result = list()
     for record in JBoxInstanceProps.scan(instance_id__beginswith=JBoxDB.qual(cluster, ''),
                                          publish_time__gte=valid_time,
                                          accept__eq=1):
         result.append(record.get('instance_id').split('.', 1)[1])
     return result
示例#14
0
 def get_available_instances(cluster):
     now = datetime.datetime.now(pytz.utc)
     nowsecs = JBoxInstanceProps.datetime_to_epoch_secs(now)
     valid_time = nowsecs - JBoxInstanceProps.SESS_UPDATE_INTERVAL
     result = list()
     for record in JBoxInstanceProps.scan(
             instance_id__beginswith=JBoxDB.qual(cluster, ''),
             publish_time__gte=valid_time,
             accept__eq=1):
         result.append(record.get('instance_id').split('.', 1)[1])
     return result
示例#15
0
 def set_user_home_image(cluster, bucket, pkg_file, home_file):
     img = {
         'bucket': bucket,
         'pkg_file': pkg_file,
         'home_file': home_file
     }
     img = json.dumps(img)
     record = JBoxDynConfig(JBoxDB.qual(cluster, 'user_home_image'), create=True, value=img)
     if not record.is_new:
         record.set_value(img)
         record.save()
示例#16
0
 def __init__(self, cluster, instance_id, create=False):
     qinstance_id = JBoxDB.qual(cluster, instance_id)
     try:
         self.item = self.fetch(instance_id=qinstance_id)
         self.is_new = False
     except JBoxDBItemNotFound:
         if create:
             data = {'instance_id': qinstance_id}
             self.create(data)
             self.item = self.fetch(instance_id=qinstance_id)
             self.is_new = True
         else:
             raise
示例#17
0
    def set_message(cluster, message, valid_delta):
        tnow = datetime.datetime.now(pytz.utc)
        tvalid = tnow + valid_delta

        msg = {
            'msg': message,
            'valid_till': isodate.datetime_isoformat(tvalid)
        }
        msg = json.dumps(msg)
        record = JBoxDynConfig(JBoxDB.qual(cluster, 'message'), create=True, value=msg)
        if not record.is_new:
            record.set_value(msg)
            record.save()
示例#18
0
 def get_instance_status(cluster):
     now = datetime.datetime.now(pytz.utc)
     nowsecs = JBoxInstanceProps.datetime_to_epoch_secs(now)
     valid_time = nowsecs - JBoxInstanceProps.SESS_UPDATE_INTERVAL
     result = dict()
     for record in JBoxInstanceProps.scan(instance_id__beginswith=JBoxDB.qual(cluster, ''),
                                          publish_time__gte=valid_time):
         iid = record.get('instance_id').split('.', 1)[1]
         props = {
             'load': float(record.get('load', '0.0')),
             'accept': bool(record.get('accept', 0)),
             'api_status': json.loads(record.get('api_status', '{}'))
         }
         result[iid] = props
     return result
示例#19
0
 def __init__(self, cluster, instance_id, create=False):
     qinstance_id = JBoxDB.qual(cluster, instance_id)
     try:
         self.item = self.fetch(instance_id=qinstance_id)
         self.is_new = False
     except JBoxDBItemNotFound:
         if create:
             data = {
                 'instance_id': qinstance_id
             }
             self.create(data)
             self.item = self.fetch(instance_id=qinstance_id)
             self.is_new = True
         else:
             raise
示例#20
0
 def get_instance_status(cluster):
     now = datetime.datetime.now(pytz.utc)
     nowsecs = JBoxInstanceProps.datetime_to_epoch_secs(now)
     valid_time = nowsecs - JBoxInstanceProps.SESS_UPDATE_INTERVAL
     result = dict()
     for record in JBoxInstanceProps.scan(
             instance_id__beginswith=JBoxDB.qual(cluster, ''),
             publish_time__gte=valid_time):
         iid = record.get('instance_id').split('.', 1)[1]
         props = {
             'load': float(record.get('load', '0.0')),
             'accept': bool(record.get('accept', 0)),
             'api_status': json.loads(record.get('api_status', '{}'))
         }
         result[iid] = props
     return result
示例#21
0
 def __init__(self, cluster, session_id, create=False, user_id=None):
     if session_id.startswith("/"):
         session_id = session_id[1:]
     qsession_id = JBoxDB.qual(cluster, session_id)
     try:
         self.item = self.fetch(session_id=qsession_id)
         self.is_new = False
     except JBoxDBItemNotFound:
         if create:
             data = {"session_id": qsession_id}
             if user_id is not None:
                 data["user_id"] = user_id
             self.create(data)
             self.item = self.fetch(session_id=qsession_id)
             self.is_new = True
         else:
             raise
示例#22
0
 def __init__(self, cluster, session_id, create=False, user_id=None):
     if session_id.startswith("/"):
         session_id = session_id[1:]
     qsession_id = JBoxDB.qual(cluster, session_id)
     try:
         self.item = self.fetch(session_id=qsession_id)
         self.is_new = False
     except JBoxDBItemNotFound:
         if create:
             data = {
                 'session_id': qsession_id
             }
             if user_id is not None:
                 data['user_id'] = user_id
             self.create(data)
             self.item = self.fetch(session_id=qsession_id)
             self.is_new = True
         else:
             raise
示例#23
0
    def get_message(cluster, del_expired=True):
        try:
            record = JBoxDynConfig(JBoxDB.qual(cluster, 'message'))
        except JBoxDBItemNotFound:
            return None

        msg = record.get_value()
        if msg is None:
            return None

        msg = json.loads(msg)

        tnow = datetime.datetime.now(pytz.utc)
        tvalid = parse_iso_time(msg['valid_till'])
        # JBoxDynConfig.log_debug("tnow: %s, tvalid: %s", str(tnow), str(tvalid))
        if tvalid >= tnow:
            return msg['msg']

        if del_expired:
            record.delete()

        return None
示例#24
0
    def get_message(cluster, del_expired=True):
        try:
            record = JBoxDynConfig(JBoxDB.qual(cluster, "message"))
        except JBoxDBItemNotFound:
            return None

        msg = record.get_value()
        if msg is None:
            return None

        msg = json.loads(msg)

        tnow = datetime.datetime.now(pytz.utc)
        tvalid = parse_iso_time(msg["valid_till"])
        # JBoxDynConfig.log_debug("tnow: %s, tvalid: %s", str(tnow), str(tvalid))
        if tvalid >= tnow:
            return msg["msg"]

        if del_expired:
            record.delete()

        return None
示例#25
0
 def set_stat_collected_date(cluster):
     dt = datetime.datetime.now(pytz.utc).isoformat()
     record = JBoxDynConfig(JBoxDB.qual(cluster, "stat_date"), create=True, value=dt)
     if not record.is_new:
         record.set_value(dt)
         record.save()
示例#26
0
 def get_stat_collected_date(cluster):
     try:
         record = JBoxDynConfig(JBoxDB.qual(cluster, "stat_date"))
     except JBoxDBItemNotFound:
         return None
     return parse_iso_time(record.get_value())
示例#27
0
 def get_stat(cluster, stat_name):
     try:
         record = JBoxDynConfig(JBoxDB.qual(cluster, stat_name))
     except JBoxDBItemNotFound:
         return None
     return json.loads(record.get_value())
示例#28
0
 def get_registration_hourly_rate(cluster):
     try:
         return int(JBoxDynConfig(JBoxDB.qual(cluster, "registrations_hourly_rate")).get_value())
     except JBoxDBItemNotFound:
         return JBoxDynConfig.DEFAULT_REGISTRATION_RATE
示例#29
0
 def set_registration_hourly_rate(cluster, rate):
     record = JBoxDynConfig(JBoxDB.qual(cluster, "registrations_hourly_rate"), create=True, value=str(rate))
     if not record.is_new:
         record.set_value(str(rate))
         record.save()
示例#30
0
 def unset_cluster_leader(cluster):
     try:
         record = JBoxDynConfig(JBoxDB.qual(cluster, 'leader'))
         record.delete()
     except JBoxDBItemNotFound:
         return
示例#31
0
 def get_cluster_leader(cluster):
     try:
         return JBoxDynConfig(JBoxDB.qual(cluster, 'leader')).get_value()
     except JBoxDBItemNotFound:
         return None
示例#32
0
 def get_user_cluster_config(cluster):
     try:
         record = JBoxDynConfig(JBoxDB.qual(cluster, "user_cluster"))
     except JBoxDBItemNotFound:
         return None
     return json.loads(record.get_value())
示例#33
0
 def get_user_cluster_config(cluster):
     try:
         record = JBoxDynConfig(JBoxDB.qual(cluster, 'user_cluster'))
     except JBoxDBItemNotFound:
         return None
     return json.loads(record.get_value())
示例#34
0
 def set_registration_hourly_rate(cluster, rate):
     record = JBoxDynConfig(JBoxDB.qual(cluster, 'registrations_hourly_rate'), create=True, value=str(rate))
     if not record.is_new:
         record.set_value(str(rate))
         record.save()
示例#35
0
 def set_user_cluster_config(cluster, cfg):
     val = json.dumps(cfg)
     record = JBoxDynConfig(JBoxDB.qual(cluster, "user_cluster"), create=True, value=val)
     if not record.is_new:
         record.set_value(val)
         record.save()
示例#36
0
 def unset_cluster_leader(cluster):
     try:
         record = JBoxDynConfig(JBoxDB.qual(cluster, "leader"))
         record.delete()
     except JBoxDBItemNotFound:
         return
示例#37
0
 def set_cluster_leader(cluster, instance):
     record = JBoxDynConfig(JBoxDB.qual(cluster, "leader"), create=True, value=instance)
     if not record.is_new:
         record.set_value(instance)
         record.save()
示例#38
0
 def get_cluster_leader(cluster):
     try:
         return JBoxDynConfig(JBoxDB.qual(cluster, "leader")).get_value()
     except JBoxDBItemNotFound:
         return None
示例#39
0
 def set_user_cluster_config(cluster, cfg):
     val = json.dumps(cfg)
     record = JBoxDynConfig(JBoxDB.qual(cluster, 'user_cluster'), create=True, value=val)
     if not record.is_new:
         record.set_value(val)
         record.save()
示例#40
0
 def get_stat(cluster, stat_name):
     try:
         record = JBoxDynConfig(JBoxDB.qual(cluster, stat_name))
     except JBoxDBItemNotFound:
         return None
     return json.loads(record.get_value())
示例#41
0
 def set_cluster_leader(cluster, instance):
     record = JBoxDynConfig(JBoxDB.qual(cluster, 'leader'), create=True, value=instance)
     if not record.is_new:
         record.set_value(instance)
         record.save()
示例#42
0
 def set_stat(cluster, stat_name, stat):
     val = json.dumps(stat)
     record = JBoxDynConfig(JBoxDB.qual(cluster, stat_name), create=True, value=val)
     if not record.is_new:
         record.set_value(val)
         record.save()
示例#43
0
 def set_allow_registration(cluster, allow):
     record = JBoxDynConfig(JBoxDB.qual(cluster, 'allow_registration'), create=True, value=str(allow))
     if not record.is_new:
         record.set_value(str(allow))
         record.save()
示例#44
0
 def set_stat_collected_date(cluster):
     dt = datetime.datetime.now(pytz.utc).isoformat()
     record = JBoxDynConfig(JBoxDB.qual(cluster, 'stat_date'), create=True, value=dt)
     if not record.is_new:
         record.set_value(dt)
         record.save()
示例#45
0
 def get_registration_hourly_rate(cluster):
     try:
         return int(JBoxDynConfig(JBoxDB.qual(cluster, 'registrations_hourly_rate')).get_value())
     except JBoxDBItemNotFound:
         return JBoxDynConfig.DEFAULT_REGISTRATION_RATE
示例#46
0
 def get_stat_collected_date(cluster):
     try:
         record = JBoxDynConfig(JBoxDB.qual(cluster, 'stat_date'))
     except JBoxDBItemNotFound:
         return None
     return parse_iso_time(record.get_value())
示例#47
0
 def set_stat(cluster, stat_name, stat):
     val = json.dumps(stat)
     record = JBoxDynConfig(JBoxDB.qual(cluster, stat_name), create=True, value=val)
     if not record.is_new:
         record.set_value(val)
         record.save()
示例#48
0
 def set_allow_registration(cluster, allow):
     record = JBoxDynConfig(JBoxDB.qual(cluster, "allow_registration"), create=True, value=str(allow))
     if not record.is_new:
         record.set_value(str(allow))
         record.save()