Example #1
0
def callback(ch, method, properties, body):
    date_time = DateTime()
    print "------------->\n" + str(date_time.get_now_as_human_creadeble(
    )) + " recieved: " + body + "\n<-------------"
    logger.info("received " + body)
    if not body:
        logger.warning("received " + body + "empty!")
        return 1
    t = threading.Thread(target=return_main, args=(body, ))
    t.start()
Example #2
0
def return_main(body):
    if not is_json(body):
        logger.error("Recieve: %s not json fortmat --> break" % (str(body)))
        print "Not json %s" % (str(body))
        return 1
    data = json.loads(body)
    if data["status"] != 1:
        logger.warning(
            "Job(%s)single status is %s --> not ok --> not return main" %
            (str(data)))
    jid = int(data["jid"])
    target_host = data["host"]
    account = None
    for i in THOMSON_HOST:
        if THOMSON_HOST[i]["host"] == target_host:
            account = THOMSON_HOST[i]
            break
    if not account:
        logger.error("Host %s not found on setting list: %s" %
                     (target_host, str(THOMSON_HOST)))
        print "Host: %s not found!" % (target_host)
        return 1
    jd = JobDetail(account["host"], account["user"], account["passwd"], jid)
    is_auto = is_auto_return_main(data)
    is_not_overwork = is_not_overworked(data)
    is_running_backup = is_running_backup_on_thomson(data)
    if not is_running_backup:
        time.sleep(10)
        is_running_backup = is_running_backup_on_thomson(data)
    if not is_running_backup:
        time.sleep(10)
        is_running_backup = is_running_backup_on_thomson(data)
    if not (is_auto and is_running_backup and is_not_overwork):
        logger.warning(
            "Job(%s) is not auto --> check your config: is_auto(%s), is_not_overwork(%s), is_running_backup(%s)"
            % (str(data), str(is_auto), str(is_not_overwork),
               str(is_running_backup)))
        date_time = DateTime()
        print "%s Job: %d from thomson %s not auto" % (str(
            date_time.get_now_as_human_creadeble()), jid, target_host)
        return 0
    if not SYSTEM["auto"]["RETURN_MAIN"]:
        logger.warning("System auto return main not active check your config!")
        return 1
    job_status = get_job_status(jd)
    logger.info("Job(%s) status --> |%s|" % (str(data), job_status))
    if job_status.upper() == "OK":
        origin_source_backup, origin_udp_port = get_job_backup_info(jd)
        disable_backup = deactive_backup(jd)
        time.sleep(2)
        enable_backup = active_backup(jd)
        if enable_backup.upper() == "NOTOK":
            stop = stop_job(jd)
            #logger.warning("Job(%s) STOP --> %s"%(str(data), stop))
            time.sleep(1)
            enable_backup = active_backup(jd)
            logger.warning("Job(%s) enable backup --> %s" %
                           (str(data), enable_backup))
            time.sleep(1)
            start = start_job(jd)
            #logger.warning("Job(%s) START --> %s"%(str(data), start))
        logger.critical(
            "Tool just returned the main source by disable and enable Active backup: Job(%s)"
            % (str(data)))
        source_backup, udp_port = get_job_backup_info(jd)
        if origin_source_backup != source_backup:
            set_backup = set_backup_ip(jd, origin_source_backup)
            logger.warning(
                "Job(%s) thomson tool change value ip backup from %s to %s --> %s"
                % (str(data), source_backup, origin_source_backup, set_backup))
        if origin_udp_port != udp_port:
            set_backup_port = set_backup_udp_port(jd, origin_udp_port)
            logger.warning(
                "Job(%s) thomson tool change value udp port backup from %s to %s --> %s"
                % (str(data), str(source_backup), str(origin_source_backup),
                   set_backup_port))
    elif job_status.upper() == "MAJOR":
        stop = stop_job(jd)
        time.sleep(2)
        start = start_job(jd)
        logger.critical(
            "Tool just returned the main source by stop and start job: Job(%s)"
            % (str(data)))
    return 0