def main(): if is_mesos_leader(): print True exit(0) else: print False exit(1)
def main(): if is_mesos_leader(): paasta_print(True) exit(0) else: paasta_print(False) exit(1)
synapse_host=synapse_host, synapse_port=smartstack_tools.DEFAULT_SYNAPSE_PORT, services=[full_name] ) replication_info[value] = repl_info return replication_info def main(): args = parse_args() soa_dir = args.soa_dir logging.basicConfig() if args.verbose: log.setLevel(logging.DEBUG) else: log.setLevel(logging.WARNING) cluster = load_system_paasta_config().get_cluster() service_instances = get_services_for_cluster(cluster=cluster, instance_type="marathon", soa_dir=args.soa_dir) config = marathon_tools.load_marathon_config() client = marathon_tools.get_marathon_client(config.get_url(), config.get_username(), config.get_password()) for service, instance in service_instances: check_service_replication(client=client, service=service, instance=instance, cluster=cluster, soa_dir=soa_dir) if __name__ == "__main__": if mesos_tools.is_mesos_leader(): main()
def main(): args = parse_args() soa_dir = args.soa_dir logging.basicConfig() if args.verbose: log.setLevel(logging.DEBUG) else: log.setLevel(logging.WARNING) cluster = load_system_paasta_config().get_cluster() service_instances = get_services_for_cluster( cluster=cluster, instance_type='marathon', soa_dir=args.soa_dir) config = marathon_tools.load_marathon_config() client = marathon_tools.get_marathon_client(config.get_url(), config.get_username(), config.get_password()) for service, instance in service_instances: check_service_replication( client=client, service=service, instance=instance, cluster=cluster, soa_dir=soa_dir, ) if __name__ == "__main__": if mesos_tools.is_mesos_leader(): main()
def test_is_mesos_leader(mock_get_mesos_leader): fake_host = "toast.host.roast" mock_get_mesos_leader.return_value = fake_host assert mesos_tools.is_mesos_leader(fake_host) mock_get_mesos_leader.assert_called_once_with(fake_host)
def test_is_mesos_leader_substring(mock_get_mesos_leader): fake_host = 'toast.host.roast' mock_get_mesos_leader.return_value = "fake_prefix." + fake_host + ".fake_suffix" assert not mesos_tools.is_mesos_leader(fake_host) mock_get_mesos_leader.assert_called_once_with()
def test_is_mesos_leader(mock_get_mesos_leader): fake_host = 'toast.host.roast' mock_get_mesos_leader.return_value = fake_host assert mesos_tools.is_mesos_leader(fake_host) mock_get_mesos_leader.assert_called_once_with()
else: output += "OK: Memory usage is under %d%%. (Currently at %f%%)\n" % mem_print_tuple if current_cpu >= percent: output += "CRITICAL: CPU usage is over %d%%! Currently at %f%%!\n" % cpu_print_tuple over_threshold = True else: output += "OK: CPU usage is under %d%%. (Currently at %f%%)\n" % cpu_print_tuple if over_threshold is True: status = 2 else: status = 0 send_event(status, output) return output def main(): args = parse_args() if args.verbose: log.setLevel(logging.DEBUG) else: log.setLevel(logging.WARNING) print check_thresholds(args.percent) if __name__ == "__main__": if is_mesos_leader(): main() else: print "No the leader. Exiting 0." sys.exit(0)
log.info("Connecting to marathon") client = marathon_tools.get_marathon_client(marathon_config.get_url(), marathon_config.get_username(), marathon_config.get_password()) valid_services = get_services_for_cluster(instance_type='marathon', soa_dir=soa_dir) running_app_ids = marathon_tools.list_all_marathon_app_ids(client) for app_id in running_app_ids: log.debug("Checking app id %s", app_id) try: service, instance, _, __ = marathon_tools.deformat_job_id(app_id) except InvalidJobNameError: log.warn("%s doesn't conform to paasta naming conventions? Skipping." % app_id) continue if (service, instance) not in valid_services: delete_app(app_id, client) def main(): args = parse_args() soa_dir = args.soa_dir if args.verbose: log.setLevel(logging.DEBUG) else: log.setLevel(logging.WARNING) cleanup_apps(soa_dir) if __name__ == "__main__" and is_mesos_leader(): main()
for app_id in running_app_ids: log.debug("Checking app id %s", app_id) try: service, instance, _, __ = marathon_tools.deformat_job_id(app_id) except InvalidJobNameError: log.warn( "%s doesn't conform to paasta naming conventions? Skipping." % app_id) continue if (service, instance) not in valid_services: delete_app( app_id=app_id, client=client, soa_dir=soa_dir, ) def main(): args = parse_args() soa_dir = args.soa_dir if args.verbose: log.setLevel(logging.DEBUG) else: log.setLevel(logging.WARNING) cleanup_apps(soa_dir) if __name__ == "__main__" and is_mesos_leader(): main()