def monitor_registrations(): max_rate = JBoxDynConfig.get_registration_hourly_rate( CloudHost.INSTALL_ID) rate = JBoxUserV2.count_created(1) reg_allowed = JBoxDynConfig.get_allow_registration( CloudHost.INSTALL_ID) CloudHost.log_debug( "registration allowed: %r, rate: %d, max allowed: %d", reg_allowed, rate, max_rate) if (reg_allowed and (rate > max_rate * 1.1)) or ((not reg_allowed) and (rate < max_rate * 0.9)): reg_allowed = not reg_allowed CloudHost.log_info("Changing registration allowed to %r", reg_allowed) JBoxDynConfig.set_allow_registration(CloudHost.INSTALL_ID, reg_allowed) if reg_allowed: num_pending_activations = JBoxUserV2.count_pending_activations() if num_pending_activations > 0: CloudHost.log_info( "scheduling activations for %d pending activations", num_pending_activations) JBoxContainer.async_schedule_activations()
def test(): yday = datetime.datetime.now() - datetime.timedelta(hours=24) stats = JBoxAccountingV2.get_stats(dates=(yday, )) TestDBTables.log_debug("stats for yesterday: %s", repr(stats)) stats = JBoxAccountingV2.get_stats() TestDBTables.log_debug("stats for today: %s", repr(stats)) sprops = JBoxSessionProps(unique_sessname('*****@*****.**')) TestDBTables.log_debug( "JBoxSessionProps. user_id: %s, snapshot_id: %s, message: %s", sprops.get_user_id(), sprops.get_snapshot_id(), sprops.get_message()) JBoxDynConfig.set_cluster_leader(TESTCLSTR, 'testinstance') assert JBoxDynConfig.get_cluster_leader(TESTCLSTR) == 'testinstance' JBoxDynConfig.unset_cluster_leader(TESTCLSTR) assert JBoxDynConfig.get_cluster_leader(TESTCLSTR) is None assert JBoxDynConfig.get_allow_registration(TESTCLSTR) JBoxDynConfig.set_allow_registration(TESTCLSTR, False) assert not JBoxDynConfig.get_allow_registration(TESTCLSTR) JBoxDynConfig.set_allow_registration(TESTCLSTR, True) assert JBoxDynConfig.get_allow_registration(TESTCLSTR) assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 60 JBoxDynConfig.set_registration_hourly_rate(TESTCLSTR, 20) assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 20 JBoxDynConfig.set_registration_hourly_rate(TESTCLSTR, 60) assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 60 assert JBoxDynConfig.get_message(TESTCLSTR) is None JBoxDynConfig.set_message(TESTCLSTR, "hello world", datetime.timedelta(minutes=1)) assert JBoxDynConfig.get_message(TESTCLSTR) == "hello world" JBoxDynConfig.set_user_home_image(TESTCLSTR, "juliabox-user-home-templates", "user_home_28Nov2014.tar.gz") assert JBoxDynConfig.get_user_home_image(TESTCLSTR) == ( "juliabox-user-home-templates", "user_home_28Nov2014.tar.gz") num_pending_activations = JBoxUserV2.count_pending_activations() TestDBTables.log_debug("pending activations: %d", num_pending_activations) resultset = JBoxInvite.table().scan() result_arr = [obj for obj in resultset] TestDBTables.log_debug("got array: %r", result_arr) count_created = JBoxUserV2.count_created(48) TestDBTables.log_debug("accounts created in last 1 hour: %d", count_created)
def monitor_registrations(): max_rate = JBoxDynConfig.get_registration_hourly_rate(CloudHost.INSTALL_ID) rate = JBoxUserV2.count_created(1) reg_allowed = JBoxDynConfig.get_allow_registration(CloudHost.INSTALL_ID) CloudHost.log_debug("registration allowed: %r, rate: %d, max allowed: %d", reg_allowed, rate, max_rate) if (reg_allowed and (rate > max_rate*1.1)) or ((not reg_allowed) and (rate < max_rate*0.9)): reg_allowed = not reg_allowed CloudHost.log_warn("Changing registration allowed to %r", reg_allowed) JBoxDynConfig.set_allow_registration(CloudHost.INSTALL_ID, reg_allowed) if reg_allowed: num_pending_activations = JBoxUserV2.count_pending_activations() if num_pending_activations > 0: CloudHost.log_info("scheduling activations for %d pending activations", num_pending_activations) JBoxContainer.async_schedule_activations()
def monitor_registrations(): max_rate = JBoxDynConfig.get_registration_hourly_rate(Compute.get_install_id()) rate = JBoxUserV2.count_created(1) reg_allowed = JBoxDynConfig.get_allow_registration(Compute.get_install_id()) JBox.log_debug("registration allowed: %r, rate: %d, max allowed: %d", reg_allowed, rate, max_rate) if (reg_allowed and (rate > max_rate*1.1)) or ((not reg_allowed) and (rate < max_rate*0.9)): reg_allowed = not reg_allowed JBox.log_warn("Changing registration allowed to %r", reg_allowed) JBoxDynConfig.set_allow_registration(Compute.get_install_id(), reg_allowed) if reg_allowed: num_pending_activations = JBoxUserV2.count_pending_activations() if num_pending_activations > 0: JBox.log_info("scheduling activations for %d pending activations", num_pending_activations) JBoxAsyncJob.async_schedule_activations()
def test(): yday = datetime.datetime.now() - datetime.timedelta(hours=24) stats = JBoxAccountingV2.get_stats(dates=(yday,)) TestDBTables.log_debug("stats for yesterday: %s", repr(stats)) stats = JBoxAccountingV2.get_stats() TestDBTables.log_debug("stats for today: %s", repr(stats)) sprops = JBoxSessionProps(unique_sessname('*****@*****.**')) TestDBTables.log_debug("JBoxSessionProps. user_id: %s, snapshot_id: %s, message: %s", sprops.get_user_id(), sprops.get_snapshot_id(), sprops.get_message()) JBoxDynConfig.set_cluster_leader(TESTCLSTR, 'testinstance') assert JBoxDynConfig.get_cluster_leader(TESTCLSTR) == 'testinstance' JBoxDynConfig.unset_cluster_leader(TESTCLSTR) assert JBoxDynConfig.get_cluster_leader(TESTCLSTR) is None assert JBoxDynConfig.get_allow_registration(TESTCLSTR) JBoxDynConfig.set_allow_registration(TESTCLSTR, False) assert not JBoxDynConfig.get_allow_registration(TESTCLSTR) JBoxDynConfig.set_allow_registration(TESTCLSTR, True) assert JBoxDynConfig.get_allow_registration(TESTCLSTR) assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 60 JBoxDynConfig.set_registration_hourly_rate(TESTCLSTR, 20) assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 20 JBoxDynConfig.set_registration_hourly_rate(TESTCLSTR, 60) assert JBoxDynConfig.get_registration_hourly_rate(TESTCLSTR) == 60 assert JBoxDynConfig.get_message(TESTCLSTR) is None JBoxDynConfig.set_message(TESTCLSTR, "hello world", datetime.timedelta(minutes=1)) assert JBoxDynConfig.get_message(TESTCLSTR) == "hello world" JBoxDynConfig.set_user_home_image(TESTCLSTR, "juliabox-user-home-templates", "user_home_28Nov2014.tar.gz") assert JBoxDynConfig.get_user_home_image(TESTCLSTR) == ("juliabox-user-home-templates", "user_home_28Nov2014.tar.gz") num_pending_activations = JBoxUserV2.count_pending_activations() TestDBTables.log_debug("pending activations: %d", num_pending_activations) resultset = JBoxInvite.table().scan() result_arr = [obj for obj in resultset] TestDBTables.log_debug("got array: %r", result_arr) count_created = JBoxUserV2.count_created(48) TestDBTables.log_debug("accounts created in last 1 hour: %d", count_created)
def monitor_registrations(): max_rate = JBoxDynConfig.get_registration_hourly_rate( Compute.get_install_id()) rate = JBoxUserV2.count_created(1) reg_allowed = JBoxDynConfig.get_allow_registration( Compute.get_install_id()) JBox.log_debug("registration allowed: %r, rate: %d, max allowed: %d", reg_allowed, rate, max_rate) if (reg_allowed and (rate > max_rate * 1.1)) or ((not reg_allowed) and (rate < max_rate * 0.9)): reg_allowed = not reg_allowed JBox.log_warn("Changing registration allowed to %r", reg_allowed) JBoxDynConfig.set_allow_registration(Compute.get_install_id(), reg_allowed) if reg_allowed: num_pending_activations = JBoxUserV2.count_pending_activations() if num_pending_activations > 0: JBox.log_info( "scheduling activations for %d pending activations", num_pending_activations) JBoxAsyncJob.async_schedule_activations()