Example #1
0
def main():
    my_logger.info("\nInitial setup complete...")
    my_logger.info("In main()...")
    
    """****************************************************************************************************************"""
    """ Collecting arguments into variables based on the format:
        db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target.suffix (for 'copy' only)]
        start
        """
    my_logger.info("Collecting arguments into variables...")
    
    if length_of_args == 4:
        target_env = sys.argv[3]
    elif length_of_args==3:
        target_env = " "    
    else:
        my_logger.error("Arguments format mismatch.  Exiting! \nUse: db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target_env (for 'copy' only)].")
        sys.exit("Arguments format mismatch.  Exiting! \nUse: db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target_env (for 'copy' only)].")
    
    my_logger.info("Received target_env: %s"%target_env)
    
    db_operation = sys.argv[1]
    my_logger.info("Received db_operation: %s"%db_operation)
    
    db_service = sys.argv[2]
    my_logger.info("Received db_service: %s"%db_service)
    
    """Collecting arguments into variables...stop"""
    """****************************************************************************************************************"""
    """ calling validate_args()...start"""
    
    my_logger.info("Calling \"validate_args(%s, %s, %s)"%(db_operation, db_service, target_env))
    try:
        validate_args(db_operation, db_service, target_env)
    except:
        my_logger.error("Error encountered: Calling \"validate_args(%s, %s, %s)\"...failed. Exiting!"%(db_operation, db_service, target_env))
        sys.exit("Error encountered: Calling \"validate_args(%s, %s, %s)\"...failed. Exiting!"%(db_operation, db_service, target_env))
    my_logger.info("validate_args(%s, %s, %s)... successful!"%(db_operation, db_service, target_env))
    
    """ calling validate_args()...stop"""
    """****************************************************************************************************************"""
    """ calling set_env()...start"""
    
    my_logger.info("Calling \"(source_env, target_env)=set_env(%s, %s)\" "%(db_operation, target_env))
    try:
        (source_env, target_env)=set_env(db_operation, target_env)
    except:
        my_logger.error("Error encountered: Calling \"(source_env, target_env)=set_env(%s, %s)\" ...failed. Exiting!"%(db_operation, target_env))
        sys.exit("Error encountered: Calling \"(source_env, target_env)=set_env(%s, %s)\" ...failed. Exiting!"%(db_operation, target_env))
    my_logger.info("(source_env, target_env) = set_env(%s, %s) successful."%(db_operation, target_env))
    
    """ calling set_env()...stop"""
    """****************************************************************************************************************"""
    """Start download of ttSettings based on source and target env start"""
    
    my_logger.info("Calling \"dict_source_ttSettings = env_ttSettings(%s)"%(source_env))
    try:
        dict_source_ttSettings = env_ttSettings(source_env)
    except:
        my_logger.error("Error encountered: Calling \"dict_source_ttSettings = env_ttSettings(%s)...failed. Exiting!"%(source_env))
        sys.exit("Error encountered: Calling \"dict_source_ttSettings = env_ttSettings(%s)...failed. Exiting!"%(source_env))
    my_logger.info("\"dict_source_ttSettings = env_ttSettings(%s) successful!"%(source_env))
    
    my_logger.info("Calling \"dict_source_ttSettings = env_ttSettings(%s)"%(target_env))
    try:
        dict_target_ttSettings = env_ttSettings(target_env)
    except:
        my_logger.error("Error encountered: Calling \"dict_target_ttSettings = env_ttSettings(%s)...failed. Exiting!"%(target_env))
        sys.exit("Error encountered: Calling \"dict_target_ttSettings = env_ttSettings(%s)...failed. Exiting!"%(target_env))
    my_logger.info("\"dict_target_ttSettings = env_ttSettings(%s) successful!"%(target_env))
    
    ttVirtuoso.dict_source_ttSettings = dict_source_ttSettings
    ttVirtuoso.dict_target_ttSettings = dict_target_ttSettings
    
    
    """Stop download of ttSettings based on source and target env stop""" 
    """****************************************************************************************************************"""
    """ validate AWS MYSQL CERT location...start"""
    
    if db_service == "mysql":
        if ("aws.3top.com" in source_env):
            my_logger.info("Received \"aws.3top.com\" in %s"%source_env)
            mysql_source_cert = dict_source_ttSettings["mysql"]["certs"]["public"]
            #print mysql_source_cert
            my_logger.debug("Calling validate_cert_loc() for mysql_source_cert: %s" %(mysql_source_cert))
            try:
                """The location of cert in target has to be verified as MySQL does direct clone from source to target without need of admin"""
                validate_cert_loc(mysql_source_cert)
            except:
                my_logger.error("Error encountered: \"Calling validate_cert_loc() with mysql_source_cert: %s\"...failed. Exiting!"%(mysql_source_cert))
                sys.exit("Error encountered: \"Calling validate_cert_loc() with mysql_source_cert: %s\"...failed. Exiting!"%(mysql_source_cert))
            my_logger.info("validate_cert_loc() with mysql_source_cert: %s successful for %s!"%(mysql_source_cert, source_env))
        if ("aws.3top.com" in target_env):
            my_logger.info("Received \"aws.3top.com\" in %s"%target_env)
            mysql_target_cert = dict_target_ttSettings["mysql"]["certs"]["public"]
            my_logger.debug("Calling validate_cert_loc() for mysql_target_cert: %s" %(mysql_target_cert))
            try:
                validate_cert_loc(mysql_target_cert)
            except:
                my_logger.error("Error encountered: \"Calling validate_cert_loc() with mysql_target_cert: %s\"...failed. Exiting!"%(mysql_target_cert))
                sys.exit("Error encountered: \"Calling validate_cert_loc() with mysql_target_cert: %s\"...failed. Exiting!"%(mysql_target_cert))
            my_logger.info("validate_cert_loc() with mysql_target_cert: %s successful for %s!"%(mysql_target_cert, target_env))
    
    """ validate AWS MYSQL CERT location...stop"""
    """****************************************************************************************************************"""
    """ validate AWS CERT location...start"""
    
    """ SOURCE_ENV"""
    if ("aws.3top.com" in source_env):
        aws_source_cert = os.path.expanduser(dict_source_ttSettings["ec2"]["cert_private_key"])
        my_logger.info("Received \"aws.3top.com\" in %s"%source_env)
        my_logger.info("Calling validate_cert_loc() for aws_source_cert: %s"%(aws_source_cert))
        try:
            validate_cert_loc(aws_source_cert)
        except:
            my_logger.error("Error encountered: \"validate_cert_loc() with cert_name: %s\"...failed. Exiting!"%(aws_source_cert))
            sys.exit("Error encountered: \"validate_cert_loc() with cert_name: %s\"...failed. Exiting!"%(aws_source_cert))
        my_logger.info("validate_cert_loc() with cert_name: %s successful for %s!"%(aws_source_cert, source_env))
    elif("aws.3top.com" not in source_env):
        my_logger.error("\"aws.3top.com\" not in %s. Exiting!"%source_env)
        sys.exit("\"aws.3top.com\" not in %s. Exiting!"%source_env)
    
    """ TARGET_ENV"""   
    if ("aws.3top.com" in target_env):
        #print("Calling \"validate_cert_loc()\"...")
        aws_target_cert = os.path.expanduser(dict_target_ttSettings["ec2"]["cert_private_key"])
        my_logger.info("Received \"aws.3top.com\" in %s"%target_env)
        my_logger.info("Calling validate_cert_loc() for aws_cert_name: %s"%(aws_target_cert))
        try:
            validate_cert_loc(aws_target_cert)
        except:
            my_logger.error("Error encountered: \"validate_cert_loc() with cert_name: %s\"...failed. Exiting!"%(aws_target_cert))
            sys.exit("Error encountered: \"validate_cert_loc() with cert_name: %s\"...failed. Exiting!"%(aws_target_cert))
        my_logger.info("validate_cert_loc() with cert_name: %s successful for %s!"%(aws_target_cert, target_env))
    elif ("nyc.3top.com" in target_env):
        my_logger.info("Received \"nyc.3top.com\" in %s"%target_env)
    
       
    
    """ calling validate_cert_loc()...stop"""
    """****************************************************************************************************************"""
    """ calling set_host()...start"""
    
    if db_service == 'mysql':
        my_logger.info("Setting hosts for db_service %s"%db_service)
        my_logger.info("Calling \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)..."%(db_service, source_env,target_env))
        try:
            (mysql_source_host, mysql_target_host) = set_mysql_host(db_service, source_env,target_env)
        except:
            my_logger.error("Error encountered: \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...failed. Exiting!"%(db_service, source_env,target_env))
            sys.exit("Error encountered: \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...failed. Exiting!"%(db_service, source_env,target_env))
        my_logger.info("\"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...successful!"%(db_service, source_env,target_env))
    
    elif db_service == 'mongodb':
        my_logger.info("Setting hosts for db_service %s"%db_service)
        my_logger.info("Calling \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)..."%(db_service, source_env,target_env))
        try:
            (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service, source_env, target_env)
        except:
            my_logger.error("Error encountered: \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...failed. Exiting!"%(db_service, source_env,target_env))
            sys.exit("Error encountered: \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...failed. Exiting!"%(db_service, source_env,target_env))
        my_logger.info("\"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...successful!"%(db_service, source_env,target_env))
    
    elif db_service == 'neo4j':
        my_logger.info("Setting hosts for db_service %s"%db_service)
        my_logger.info("Calling \"(neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)..."%(db_service, source_env,target_env))
        try:
            (neo4j_source_host, neo4j_target_host)=set_neo4j_host(db_service, source_env, target_env)
        except:
            my_logger.error("Error encountered: \"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...failed. Exiting!"%(db_service, source_env,target_env))
            sys.exit("Error encountered: \"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...failed. Exiting!"%(db_service, source_env,target_env))
        my_logger.info("\"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...successful!"%(db_service, source_env,target_env))
    
    elif db_service == 'virtuoso':
        my_logger.info("Setting hosts for db_service %s"%db_service)
        my_logger.info("Calling \"(virtuoso_source_host, virtuoso_target_host)=set_virtuoso_host(%s, %s, %s)..."%(db_service, source_env,target_env))
        try:
            (virtuoso_source_host, virtuoso_target_host)=set_virtuoso_host(db_service, source_env, target_env)
        except:
            my_logger.error("Error encountered: \"virtuoso_source_host, virtuoso_target_host)=set_virtuoso_host(%s, %s, %s)...failed. Exiting!"%(db_service, source_env,target_env))
            sys.exit("Error encountered: \"virtuoso_source_host, virtuoso_target_host)=set_virtuoso_host(%s, %s, %s)...failed. Exiting!"%(db_service, source_env,target_env))
        my_logger.info("\"virtuoso_source_host, virtuoso_target_host)=set_virtuoso_host(%s, %s, %s)...successful!"%(db_service, source_env,target_env))
    
    elif db_service == 'all':
        
        """MYSQL"""
        db_service1 = "mysql"
        my_logger.info("Setting hosts for db_service %s"%db_service1)
        my_logger.info("Calling \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)..."%(db_service1, source_env,target_env))
        try:
            (mysql_source_host, mysql_target_host) = set_mysql_host(db_service1, source_env,target_env)
        except:
            my_logger.error("Error encountered: \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...failed. Exiting!"%(db_service1, source_env,target_env))
            sys.exit("Error encountered: \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...failed. Exiting!"%(db_service1, source_env,target_env))
        my_logger.info("\"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...successful!"%(db_service1, source_env,target_env))
        
        """MONGODB"""
        db_service2 = "mongodb"
        my_logger.info("Setting hosts for db_service %s"%db_service2)
        my_logger.info("Calling \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)..."%(db_service2, source_env,target_env))
        try:
            (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service2, source_env, target_env)
        except:
            my_logger.error("Error encountered: \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...failed. Exiting!"%(db_service2, source_env,target_env))
            sys.exit("Error encountered: \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...failed. Exiting!"%(db_service2, source_env,target_env))
        my_logger.info("\"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...successful!"%(db_service2, source_env,target_env))
        
        """NEO4J"""
        db_service3 = "neo4j"
        my_logger.info("Setting hosts for db_service %s"%db_service3)
        my_logger.info("Calling \"(neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)..."%(db_service3, source_env,target_env))
        try:
            (neo4j_source_host, neo4j_target_host)=set_neo4j_host(db_service3, source_env, target_env)
        except:
            my_logger.error("Error encountered: \"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...failed. Exiting!"%(db_service3, source_env,target_env))
            sys.exit("Error encountered: \"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...failed. Exiting!"%(db_service3, source_env,target_env))
        my_logger.info("\"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...successful!"%(db_service3, source_env,target_env))
        
        """VIRTUOSO"""
        db_service4 = 'virtuoso'
        my_logger.info("Setting hosts for db_service %s"%db_service4)
        my_logger.info("Calling \"(virtuoso_source_host, virtuoso_target_host)=set_virtuoso_host(%s, %s, %s)..."%(db_service4, source_env,target_env))
        try:
            (virtuoso_source_host, virtuoso_target_host)=set_virtuoso_host(db_service4, source_env, target_env)
        except:
            my_logger.error("Error encountered: \"virtuoso_source_host, virtuoso_target_host)=set_virtuoso_host(%s, %s, %s)...failed. Exiting!"%(db_service4, source_env,target_env))
            sys.exit("Error encountered: \"virtuoso_source_host, virtuoso_target_host)=set_virtuoso_host(%s, %s, %s)...failed. Exiting!"%(db_service4, source_env,target_env))
        my_logger.info("\"virtuoso_source_host, virtuoso_target_host)=set_virtuoso_host(%s, %s, %s)...successful!"%(db_service4, source_env,target_env))
        
    """ calling set_host()...stop"""
    """****************************************************************************************************************"""
    """ Validate DB Accounts... start"""
    
    """ Validate Source Accounts... start"""
    print("Validating source host..."),
    if db_service == 'mysql':
        my_logger.info("Validating source host for db_service %s"%db_service)
        my_logger.info("Calling \"validate_mysql_source(dict_source_ttSettings, %s)..."%(mysql_source_host))
        try:
            validate_mysql_source(dict_source_ttSettings, mysql_source_host)
        except:
            my_logger.error("Error encountered: \"validate_mysql_source(dict_source_ttSettings, %s)...failed. Exiting!"%(mysql_source_host))
            sys.exit("Error encountered: \"validate_mysql_source(dict_source_ttSettings, %s)...failed. Exiting!"%(mysql_source_host))
        my_logger.info("\"validate_mysql_source(dict_source_ttSettings, %s)...successful!"%(mysql_source_host))
        
    elif db_service == 'mongodb':
        my_logger.info("Validating source host for db_service %s"%db_service)
        my_logger.info("Calling \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)..."%(mongodb_source_host))
        try:
            validate_mongodb_source_accounts(mongodb_source_host, dict_source_ttSettings)
        except:
            my_logger.error("Error encountered: \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...failed. Exiting!"%(mongodb_source_host))
            sys.exit("Error encountered: \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...failed. Exiting!"%(mongodb_source_host))
        my_logger.info("\"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...successful!"%(mongodb_source_host))
        
    elif db_service == 'neo4j':
        my_logger.info("Validating source host for db_service %s"%db_service)
        my_logger.info("Calling \"validate_neo4j_aws_accounts(%s, dict_source_ttSettings)..."%(neo4j_source_host))
        try:
            neo4j_source_username = validate_neo4j_aws_accounts(neo4j_source_host, dict_source_ttSettings)
        except:
            my_logger.error("Error encountered: \"validate_neo4j_aws_accounts(%s, dict_source_ttSettings))...failed. Exiting!"%(neo4j_source_host))
            sys.exit("Error encountered: \"validate_neo4j_aws_accounts(%s, dict_source_ttSettings)...failed. Exiting!"%(neo4j_source_host))
        my_logger.info("\"validate_neo4j_aws_accounts(%s, dict_source_ttSettings)...successful!"%(neo4j_source_host))
    
    elif db_service == 'virtuoso':
        my_logger.info("Validating source host for db_service %s"%db_service)
        my_logger.info("Calling \"validate_virtuoso_aws_accounts(%s, dict_source_ttSettings)..."%(virtuoso_source_host))
        try:
            validate_virtuoso_aws_accounts(virtuoso_source_host, dict_source_ttSettings)
        except:
            my_logger.error("Error encountered: \"validate_virtuoso_aws_accounts(%s, dict_source_ttSettings))...failed. Exiting!"%(virtuoso_source_host))
            sys.exit("Error encountered: \"validate_virtuoso_aws_accounts(%s, dict_source_ttSettings)...failed. Exiting!"%(virtuoso_source_host))
        my_logger.info("\"validate_virtuoso_aws_accounts(%s, dict_source_ttSettings)...successful!"%(virtuoso_source_host))
        
    elif db_service == 'all':
        db_service1 = 'mysql'
        my_logger.info("Validating source host for db_service %s"%db_service1)
        my_logger.info("Calling \"validate_mysql_source(dict_source_ttSettings, %s)..."%(mysql_source_host))
        try:
            validate_mysql_source(dict_source_ttSettings, mysql_source_host)
        except:
            my_logger.error("Error encountered: \"validate_mysql_source(dict_source_ttSettings, %s)...failed. Exiting!"%(mysql_source_host))
            sys.exit("Error encountered: \"validate_mysql_source(dict_source_ttSettings, %s)...failed. Exiting!"%(mysql_source_host))
        my_logger.info("\"validate_mysql_source(dict_source_ttSettings, %s)...successful!"%(mysql_source_host))
        
        db_service2 = 'mongodb'
        my_logger.info("Validating source host for db_service %s"%db_service2)
        my_logger.info("Calling \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)..."%(mongodb_source_host))
        try:
            validate_mongodb_source_accounts(mongodb_source_host, dict_source_ttSettings)
        except:
            my_logger.error("Error encountered: \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...failed. Exiting!"%(mongodb_source_host))
            sys.exit("Error encountered: \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...failed. Exiting!"%(mongodb_source_host))
        my_logger.info("\"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...successful!"%(mongodb_source_host))
        
        db_service3 = 'neo4j'
        my_logger.info("Validating source host for db_service %s"%db_service3)
        my_logger.info("Calling \"validate_neo4j_aws_accounts(%s, dict_source_ttSettings)..."%(neo4j_source_host))
        try:
            neo4j_source_username = validate_neo4j_aws_accounts(neo4j_source_host, dict_source_ttSettings)
        except:
            my_logger.error("Error encountered: \"validate_neo4j_aws_accounts(%s, dict_source_ttSettings))...failed. Exiting!"%(neo4j_source_host))
            sys.exit("Error encountered: \"validate_neo4j_aws_accounts(%s_host, dict_source_ttSettings)...failed. Exiting!"%(neo4j_source_host))
        my_logger.info("\"validate_neo4j_aws_accounts(%s, dict_source_ttSettings)...successful!"%(neo4j_source_host))
        
        db_service4 = 'virtuoso'
        my_logger.info("Validating source host for db_service %s"%db_service4)
        my_logger.info("Calling \"validate_virtuoso_aws_accounts(%s, dict_source_ttSettings)..."%(virtuoso_source_host))
        try:
            validate_virtuoso_aws_accounts(virtuoso_source_host, dict_source_ttSettings)
        except:
            my_logger.error("Error encountered: \"validate_virtuoso_aws_accounts(%s, dict_source_ttSettings))...failed. Exiting!"%(virtuoso_source_host))
            sys.exit("Error encountered: \"validate_virtuoso_aws_accounts(%s, dict_source_ttSettings)...failed. Exiting!"%(virtuoso_source_host))
        my_logger.info("\"validate_virtuoso_aws_accounts(%s, dict_source_ttSettings)...successful!"%(virtuoso_source_host))
        
    print "Complete!"
    """ Validate Source Accounts... stop"""
    
    """ Validate Target Accounts... start"""
    #print("Validating target host..."),
    if db_service == 'mysql':
        if "aws.3top.com" in mysql_target_host:
            my_logger.info("Found \"aws.3top.com\" in target host")
            my_logger.info("Validating target host for %s"%(db_service))
            my_logger.info("Calling \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)..."%(mysql_target_host))
            try:
                validate_mysql_aws_accounts(dict_target_ttSettings, mysql_target_host)
            except:
                my_logger.error("Error encountered: \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...failed. Exiting!"%(mysql_target_host))
                sys.exit("Error encountered: \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...failed. Exiting!"%(mysql_target_host))
            my_logger.info("\"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...successful!"%(mysql_target_host))
        
        elif "nyc.3top.com" in mysql_target_host:
            my_logger.info("Found \"nyc.3top.com\" in target host")
            my_logger.info("Validating target host for db_service %s"%db_service)
            my_logger.info("Calling \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)..."%(mysql_target_host))
            try:
                validate_mysql_nyc_accounts(dict_target_ttSettings, mysql_target_host)
            except:
                my_logger.error("Error encountered: \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...failed. Exiting!"%(mysql_target_host))
                sys.exit("Error encountered: \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...failed. Exiting!"%(mysql_target_host))
            my_logger.info("\"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...successful!"%(mysql_target_host))
        
    elif db_service == 'mongodb':
        my_logger.info("Validating source host for db_service %s"%db_service)
        my_logger.info("Calling \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)..."%(mongodb_target_host))
        try:
            validate_mongodb_target_accounts(mongodb_target_host, dict_target_ttSettings)
        except:
            my_logger.error("Error encountered: \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(mongodb_target_host))
            sys.exit("Error encountered: \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(mongodb_target_host))
        my_logger.info("\"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...successful!"%(mongodb_target_host))
        
    elif db_service == 'neo4j':
        if "nyc.3top.com" in neo4j_target_host:
            my_logger.info("Found \"nyc.3top.com\" in target host")
            my_logger.info("calling \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)\"..."%(neo4j_target_host))
            #print dict_target_ttSettings
            try:
                neo4j_target_username = validate_neo4j_nyc_target(neo4j_target_host, dict_target_ttSettings)
            except:
                my_logger.error("Error encountered: \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"%(neo4j_target_host))
                sys.exit("Error encountered: \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"%(neo4j_target_host))
            my_logger.info("\"validate_neo4j_nyc_target(%s, dict_target_ttSettings)\"...successful!")
        
        elif "aws.3top.com" in neo4j_target_host:
            my_logger.info("Found \"aws.3top.com\" in target host")
            my_logger.info("calling \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)\"..."%(neo4j_target_host))
            try:
                neo4j_target_username = validate_neo4j_aws_accounts(neo4j_target_host, dict_target_ttSettings)
            except:
                my_logger.error("Error encountered: \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(neo4j_target_host))
                sys.exit("Error encountered: \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(neo4j_target_host))
            my_logger.info("\"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)\"...successful!")
            
    elif db_service == 'virtuoso':
        if "nyc.3top.com" in virtuoso_target_host:
            my_logger.info("Found \"nyc.3top.com\" in target host")
            my_logger.info("calling \"validate_virtuoso_nyc_target(%s, dict_target_ttSettings)\"..."%(virtuoso_target_host))
            #print dict_target_ttSettings
            try:
                validate_virtuoso_nyc_target(virtuoso_target_host, dict_target_ttSettings)
            except:
                my_logger.error("Error encountered: \"validate_virtuoso_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"%(virtuoso_target_host))
                sys.exit("Error encountered: \"validate_virtuoso_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"%(virtuoso_target_host))
            my_logger.info("\"validate_virtuoso_nyc_target(%s, dict_target_ttSettings)\"...successful!")
        
        elif "aws.3top.com" in virtuoso_target_host:
            my_logger.info("Found \"aws.3top.com\" in target host")
            my_logger.info("calling \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)\"..."%(virtuoso_target_host))
            try:
                validate_virtuoso_aws_accounts(virtuoso_target_host, dict_target_ttSettings)
            except:
                my_logger.error("Error encountered: \"validate_virtuoso_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(virtuoso_target_host))
                sys.exit("Error encountered: \"validate_virtuoso_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(virtuoso_target_host))
            my_logger.info("\"validate_virtuoso_aws_accounts(%s, dict_target_ttSettings)\"...successful!")
            

    elif db_service == 'all':
        if "aws.3top.com" in mysql_target_host:
            my_logger.info("Found \"aws.3top.com\" in target host")
            my_logger.info("Validating target host for %s"%(mysql_target_host))
            my_logger.info("Calling \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)..."%(mysql_target_host))
            try:
                validate_mysql_aws_accounts(dict_target_ttSettings, mysql_target_host)
            except:
                my_logger.error("Error encountered: \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...failed. Exiting!"%(mysql_target_host))
                sys.exit("Error encountered: \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...failed. Exiting!"%(mysql_target_host))
            my_logger.info("\"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...successful!"%(mysql_target_host))
        
        elif "nyc.3top.com" in mysql_target_host:
            my_logger.info("Found \"nyc.3top.com\" in target host")
            my_logger.info("Validating target host for db_service %s"%db_service)
            my_logger.info("Calling \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)..."%(mysql_target_host))
            try:
                validate_mysql_nyc_accounts(dict_target_ttSettings, mysql_target_host)
            except:
                my_logger.error("Error encountered: \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...failed. Exiting!"%(mysql_target_host))
                sys.exit("Error encountered: \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...failed. Exiting!"%(mysql_target_host))
            my_logger.info("\"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...successful!"%(mysql_target_host))
        
    
        my_logger.info("Validating source host for db_service %s"%db_service)
        my_logger.info("Calling \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)..."%(mongodb_target_host))
        try:
            validate_mongodb_target_accounts(mongodb_target_host, dict_target_ttSettings)
        except:
            my_logger.error("Error encountered: \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(mongodb_target_host))
            sys.exit("Error encountered: \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(mongodb_target_host))
        my_logger.info("\"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...successful!"%(mongodb_target_host))
        
   
        if "nyc.3top.com" in neo4j_target_host:
            my_logger.info("Found \"nyc.3top.com\" in target host")
            my_logger.info("calling \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)\"..."%(neo4j_target_host))
            try:
                neo4j_target_username = validate_neo4j_nyc_target(neo4j_target_host, dict_target_ttSettings)
            except:
                my_logger.error("Error encountered: \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"%(neo4j_target_host))
                sys.exit("Error encountered: \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"%(neo4j_target_host))
            my_logger.info("\"validate_neo4j_nyc_target(%s, dict_target_ttSettings)\"...successful!")
        
        elif "aws.3top.com" in neo4j_target_host:
            my_logger.info("Found \"aws.3top.com\" in target host")
            my_logger.info("calling \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)\"..."%(neo4j_target_host))
            try:
                neo4j_target_username = validate_neo4j_aws_accounts(neo4j_target_host, dict_target_ttSettings)
            except:
                my_logger.error("Error encountered: \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(neo4j_target_host))
                sys.exit("Error encountered: \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(neo4j_target_host))
            my_logger.info("\"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)\"...successful!")
        
        if "nyc.3top.com" in virtuoso_target_host:
            my_logger.info("Found \"nyc.3top.com\" in target host")
            my_logger.info("calling \"validate_virtuoso_nyc_target(%s, dict_target_ttSettings)\"..."%(virtuoso_target_host))
            #print dict_target_ttSettings
            try:
                validate_virtuoso_nyc_target(virtuoso_target_host, dict_target_ttSettings)
            except:
                my_logger.error("Error encountered: \"validate_virtuoso_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"%(virtuoso_target_host))
                sys.exit("Error encountered: \"validate_virtuoso_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"%(virtuoso_target_host))
            my_logger.info("\"validate_virtuoso_nyc_target(%s, dict_target_ttSettings)\"...successful!")
        
        elif "aws.3top.com" in virtuoso_target_host:
            my_logger.info("Found \"aws.3top.com\" in target host")
            my_logger.info("calling \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)\"..."%(virtuoso_target_host))
            try:
                validate_virtuoso_aws_accounts(virtuoso_target_host, dict_target_ttSettings)
            except:
                my_logger.error("Error encountered: \"validate_virtuoso_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(virtuoso_target_host))
                sys.exit("Error encountered: \"validate_virtuoso_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"%(virtuoso_target_host))
            my_logger.info("\"validate_virtuoso_aws_accounts(%s, dict_target_ttSettings)\"...successful!")
            
    """ Validate Target Accounts... stop"""
    
    """ Validate DB Accounts... stop"""    
    """****************************************************************************************************************"""
    """ Find current working directory path: python_root...start"""
    
    global python_root
    my_logger.debug("Finding real path (working directory)...")
    python_root = os.path.dirname(os.path.realpath(__file__)) + "/"
    my_logger.debug("python_root:%s"%python_root)
    #print "found."
    
    """ Find current working directory path: python_root...stop"""
    """********************************************************************************************************************"""
    """ Executing db_operation"""
    #Region = dict_ttSettings["aws"]["REGION_NAME"]
    if db_service == 'mysql':
        print "Executing mysql_operations..."
        my_logger.debug("calling mysql_operations() with source: %s, target: %s..."%(mysql_source_host, mysql_target_host))
        mysql_operations(db_operation, db_service, dict_source_ttSettings, dict_target_ttSettings, mysql_source_host, mysql_target_host, my_logger,log_file_abs_path)
        my_logger.info("MySQL operations completed successfully")
    elif db_service== "mongodb":
        print "Executing mongo_operations..."
        my_logger.debug("calling mongo_operations() with source: %s, target: %s..."%(mongodb_source_host, mongodb_target_host))
        mongo_operations(db_operation, db_service, dict_source_ttSettings, dict_target_ttSettings, mongodb_source_host, mongodb_target_host, my_logger,log_file_abs_path)
        my_logger.info("MongoDB operations completed successfully")
    elif db_service == 'neo4j':
        print "Executing neo4j_operations..."
        my_logger.debug("calling neo4j_operations() with source: %s , target: %s..."%(neo4j_source_host, neo4j_target_host))
        neo4j_operations(dict_source_ttSettings, dict_target_ttSettings, neo4j_source_username, neo4j_target_username, neo4j_source_host, neo4j_target_host)
        my_logger.info("Neo4j operations completed successfully")
    elif db_service == 'virtuoso':
        print "Executing virtuoso_operations..."
        my_logger.debug("calling virtuoso_operations() with source: %s , target: %s..."%(virtuoso_source_host, virtuoso_target_host))
        virtuoso_operations(dict_source_ttSettings, dict_target_ttSettings)
        my_logger.info("Virtuoso operations completed successfully")
    elif db_service == 'all':
        print "Executing mysql_operations..."
        my_logger.debug("calling mysql_operations() with source: %s, target: %s..."%(mysql_source_host, mysql_target_host))
        mysql_operations(db_operation, db_service, dict_source_ttSettings, dict_target_ttSettings, mysql_source_host, mysql_target_host, my_logger,log_file_abs_path)
        my_logger.info("MySQL operations completed successfully")
        print "Executing mongo_operations..."
        my_logger.debug("calling mongo_operations() with source: %s, target: %s..."%(mongodb_source_host, mongodb_target_host))
        mongo_operations(db_operation, db_service, dict_source_ttSettings, dict_target_ttSettings, mongodb_source_host, mongodb_target_host, my_logger,log_file_abs_path)
        my_logger.info("MongoDB operations completed successfully")
        print "Executing neo4j_operations..."
        my_logger.debug("calling neo4j_operations() with source: %s , target: %s..."%(neo4j_source_host, neo4j_target_host))
        neo4j_operations(dict_source_ttSettings, dict_target_ttSettings, neo4j_source_username, neo4j_target_username, neo4j_source_host, neo4j_target_host)
        my_logger.info("Neo4j operations completed successfully")
        print "Executing virtuoso_operations..."
        my_logger.debug("calling virtuoso_operations() with source: %s , target: %s..."%(virtuoso_source_host, virtuoso_target_host))
        virtuoso_operations(dict_source_ttSettings, dict_target_ttSettings)
        my_logger.info("Virtuoso operations completed successfully")
    """main() Module definition... start"""
    """main() Module definition... stop"""
    
    my_logger.info("Program execution complete. Exiting!")
    print "Program execution complete. Exiting!\nLogfile location: %s" %log_file_abs_path
Example #2
0
def main():
    my_logger.info("\nInitial setup complete...")
    my_logger.info("In main()...")
    """****************************************************************************************************************"""
    """ Collecting arguments into variables based on the format:
        db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target.suffix (for 'copy' only)]
        start
        """
    my_logger.info("Collecting arguments into variables...")

    if length_of_args == 4:
        target_env = sys.argv[3]
    elif length_of_args == 3:
        target_env = " "
    else:
        my_logger.error(
            "Arguments format mismatch.  Exiting! \nUse: db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target_env (for 'copy' only)]."
        )
        sys.exit(
            "Arguments format mismatch.  Exiting! \nUse: db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target_env (for 'copy' only)]."
        )

    my_logger.info("Received target_env: %s" % target_env)

    db_operation = sys.argv[1]
    my_logger.info("Received db_operation: %s" % db_operation)

    db_service = sys.argv[2]
    my_logger.info("Received db_service: %s" % db_service)
    """Collecting arguments into variables...stop"""
    """****************************************************************************************************************"""
    """ calling validate_args()...start"""

    my_logger.info("Calling \"validate_args(%s, %s, %s)" %
                   (db_operation, db_service, target_env))
    try:
        validate_args(db_operation, db_service, target_env)
    except:
        my_logger.error(
            "Error encountered: %s. Calling \"validate_args(%s, %s, %s)\"...failed. Exiting!"
            % (str(sys.exc_info()), db_operation, db_service, target_env))
        sys.exit(
            "Error encountered: %s. Calling \"validate_args(%s, %s, %s)\"...failed. Exiting!"
            % (str(sys.exc_info()), db_operation, db_service, target_env))
    my_logger.info("validate_args(%s, %s, %s)... successful!" %
                   (db_operation, db_service, target_env))
    """ calling validate_args()...stop"""
    """****************************************************************************************************************"""
    """ calling set_env()...start"""

    my_logger.info("Calling \"(source_env, target_env)=set_env(%s, %s)\" " %
                   (db_operation, target_env))
    try:
        (source_env, target_env) = set_env(db_operation, target_env)
    except:
        my_logger.error(
            "Error encountered: %s. Calling \"(source_env, target_env)=set_env(%s, %s)\" ...failed. Exiting!"
            % (str(sys.exc_info()), db_operation, target_env))
        sys.exit(
            "Error encountered: %s. Calling \"(source_env, target_env)=set_env(%s, %s)\" ...failed. Exiting!"
            % (str(sys.exc_info()), db_operation, target_env))
    my_logger.info("(source_env, target_env) = set_env(%s, %s) successful." %
                   (db_operation, target_env))
    """ calling set_env()...stop"""
    """****************************************************************************************************************"""
    """Start download of ttSettings based on source and target env start"""

    my_logger.info("Calling \"dict_source_ttSettings = env_ttSettings(%s)" %
                   (source_env))
    try:
        dict_source_ttSettings = env_ttSettings(source_env)
    except:
        my_logger.error(
            "Error encountered: %s. Calling \"dict_source_ttSettings = env_ttSettings(%s)...failed. Exiting!"
            % (str(sys.exc_info()), source_env))
        sys.exit(
            "Error encountered: %s. Calling \"dict_source_ttSettings = env_ttSettings(%s)...failed. Exiting!"
            % (str(sys.exc_info()), source_env))
    my_logger.info(
        "\"dict_source_ttSettings = env_ttSettings(%s) successful!" %
        (source_env))

    my_logger.info("Calling \"dict_source_ttSettings = env_ttSettings(%s)" %
                   (target_env))
    try:
        dict_target_ttSettings = env_ttSettings(target_env)
    except:
        my_logger.error(
            "Error encountered: %s. Calling \"dict_source_ttSettings = env_ttSettings(%s)...failed. Exiting!"
            % (str(sys.exc_info()), target_env))
        sys.exit(
            "Error encountered: %s. Calling \"dict_source_ttSettings = env_ttSettings(%s)...failed. Exiting!"
            % (str(sys.exc_info()), target_env))
    my_logger.info(
        "\"dict_source_ttSettings = env_ttSettings(%s) successful!" %
        (target_env))
    """Stop download of ttSettings based on source and target env stop"""
    """****************************************************************************************************************"""
    """ validate AWS MYSQL CERT location...start"""

    if db_service == "mysql":
        if ("aws.3top.com" in source_env):
            my_logger.info("Received \"aws.3top.com\" in %s" % source_env)
            mysql_source_cert = dict_source_ttSettings["mysql"]["certs"][
                "public"]
            #print mysql_source_cert
            my_logger.debug(
                "Calling validate_cert_loc() for mysql_source_cert: %s" %
                (mysql_source_cert))
            try:
                """The location of cert in target has to be verified as MySQL does direct clone from source to target without need of admin"""
                validate_cert_loc(mysql_source_cert)
            except:
                my_logger.error(
                    "Error encountered: %s. \"Calling validate_cert_loc() with mysql_source_cert: %s\"...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_source_cert))
                sys.exit(
                    "Error encountered: %s. \"Calling validate_cert_loc() with mysql_source_cert: %s\"...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_source_cert))
            my_logger.info(
                "validate_cert_loc() with mysql_source_cert: %s successful for %s!"
                % (mysql_source_cert, source_env))
        if ("aws.3top.com" in target_env):
            my_logger.info("Received \"aws.3top.com\" in %s" % target_env)
            mysql_target_cert = dict_target_ttSettings["mysql"]["certs"][
                "public"]
            my_logger.debug(
                "Calling validate_cert_loc() for mysql_target_cert: %s" %
                (mysql_target_cert))
            try:
                validate_cert_loc(mysql_target_cert)
            except:
                my_logger.error(
                    "Error encountered: %s. \"Calling validate_cert_loc() with mysql_target_cert: %s\"...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_target_cert))
                sys.exit(
                    "Error encountered: %s. \"Calling validate_cert_loc() with mysql_target_cert: %s\"...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_target_cert))
            my_logger.info(
                "validate_cert_loc() with mysql_target_cert: %s successful for %s!"
                % (mysql_target_cert, target_env))
    """ validate AWS MYSQL CERT location...stop"""
    """****************************************************************************************************************"""
    """ validate AWS CERT location...start"""
    """ SOURCE_ENV"""
    if ("aws.3top.com" in source_env):
        aws_source_cert = os.path.expanduser(
            dict_source_ttSettings["ec2"]["cert_private_key"])
        my_logger.info("Received \"aws.3top.com\" in %s" % source_env)
        my_logger.info("Calling validate_cert_loc() for aws_source_cert: %s" %
                       (aws_source_cert))
        try:
            validate_cert_loc(aws_source_cert)
        except:
            my_logger.error(
                "Error encountered: %s. \"validate_cert_loc() with cert_name: %s\"...failed. Exiting!"
                % (str(sys.exc_info()), aws_source_cert))
            sys.exit(
                "Error encountered: %s. \"validate_cert_loc() with cert_name: %s\"...failed. Exiting!"
                % (str(sys.exc_info()), aws_source_cert))
        my_logger.info(
            "validate_cert_loc() with cert_name: %s successful for %s!" %
            (aws_source_cert, source_env))
    elif ("aws.3top.com" not in source_env):
        my_logger.error("\"aws.3top.com\" not in %s. Exiting!" % source_env)
        sys.exit("\"aws.3top.com\" not in %s. Exiting!" % source_env)
    """ TARGET_ENV"""
    if ("aws.3top.com" in target_env):
        #print("Calling \"validate_cert_loc()\"...")
        aws_target_cert = os.path.expanduser(
            dict_target_ttSettings["ec2"]["cert_private_key"])
        my_logger.info("Received \"aws.3top.com\" in %s" % target_env)
        my_logger.info("Calling validate_cert_loc() for aws_cert_name: %s" %
                       (aws_target_cert))
        try:
            validate_cert_loc(aws_target_cert)
        except:
            my_logger.error(
                "Error encountered: %s. \"validate_cert_loc() with cert_name: %s\"...failed. Exiting!"
                % (str(sys.exc_info()), aws_target_cert))
            sys.exit(
                "Error encountered: %s. \"validate_cert_loc() with cert_name: %s\"...failed. Exiting!"
                % (str(sys.exc_info()), aws_target_cert))
        my_logger.info(
            "validate_cert_loc() with cert_name: %s successful for %s!" %
            (aws_target_cert, target_env))
    elif ("nyc.3top.com" in target_env):
        my_logger.info("Received \"nyc.3top.com\" in %s" % target_env)
    """ calling validate_cert_loc()...stop"""
    """****************************************************************************************************************"""
    """ calling set_host()...start"""

    if db_service == 'mysql':
        my_logger.info("Setting hosts for db_service %s" % db_service)
        my_logger.info(
            "Calling \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)..."
            % (db_service, source_env, target_env))
        try:
            (mysql_source_host,
             mysql_target_host) = set_mysql_host(db_service, source_env,
                                                 target_env)
        except:
            my_logger.error(
                "Error encountered: %s. \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service, source_env, target_env))
            sys.exit(
                "Error encountered: %s. \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service, source_env, target_env))
        my_logger.info(
            "\"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...successful!"
            % (db_service, source_env, target_env))

    elif db_service == 'mongodb':
        my_logger.info("Setting hosts for db_service %s" % db_service)
        my_logger.info(
            "Calling \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)..."
            % (db_service, source_env, target_env))
        try:
            (mongodb_source_host,
             mongodb_target_host) = set_mongodb_host(db_service, source_env,
                                                     target_env)
        except:
            my_logger.error(
                "Error encountered: %s. \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service, source_env, target_env))
            sys.exit(
                "Error encountered: %s. \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service, source_env, target_env))
        my_logger.info(
            "\"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...successful!"
            % (db_service, source_env, target_env))

    elif db_service == 'neo4j':
        my_logger.info("Setting hosts for db_service %s" % db_service)
        my_logger.info(
            "Calling \"(neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)..."
            % (db_service, source_env, target_env))
        try:
            (neo4j_source_host,
             neo4j_target_host) = set_neo4j_host(db_service, source_env,
                                                 target_env)
        except:
            my_logger.error(
                "Error encountered: %s. \"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service, source_env, target_env))
            sys.exit(
                "Error encountered: %s. \"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service, source_env, target_env))
        my_logger.info(
            "\"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...successful!"
            % (db_service, source_env, target_env))

    elif db_service == 'all':
        """MYSQL"""
        db_service1 = "mysql"
        my_logger.info("Setting hosts for db_service %s" % db_service1)
        my_logger.info(
            "Calling \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)..."
            % (db_service1, source_env, target_env))
        try:
            (mysql_source_host,
             mysql_target_host) = set_mysql_host(db_service1, source_env,
                                                 target_env)
        except:
            my_logger.error(
                "Error encountered: %s. \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service1, source_env, target_env))
            sys.exit(
                "Error encountered: %s. \"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service1, source_env, target_env))
        my_logger.info(
            "\"(mysql_source_host, mysql_target_host) = set_mysql_host(%s, %s, %s)...successful!"
            % (db_service1, source_env, target_env))
        """MONGODB"""
        db_service2 = "mongodb"
        my_logger.info("Setting hosts for db_service %s" % db_service2)
        my_logger.info(
            "Calling \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)..."
            % (db_service2, source_env, target_env))
        try:
            (mongodb_source_host,
             mongodb_target_host) = set_mongodb_host(db_service2, source_env,
                                                     target_env)
        except:
            my_logger.error(
                "Error encountered: %s. \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service2, source_env, target_env))
            sys.exit(
                "Error encountered: %s. \"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service2, source_env, target_env))
        my_logger.info(
            "\"mongodb_source_host, mongodb_target_host)=set_mongodb_host(%s, %s, %s)...successful!"
            % (db_service2, source_env, target_env))
        """NEO4J"""
        db_service3 = "neo4j"
        my_logger.info("Setting hosts for db_service %s" % db_service3)
        my_logger.info(
            "Calling \"(neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)..."
            % (db_service3, source_env, target_env))
        try:
            (neo4j_source_host,
             neo4j_target_host) = set_neo4j_host(db_service3, source_env,
                                                 target_env)
        except:
            my_logger.error(
                "Error encountered: %s. \"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service3, source_env, target_env))
            sys.exit(
                "Error encountered: %s. \"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...failed. Exiting!"
                % (str(sys.exc_info()), db_service3, source_env, target_env))
        my_logger.info(
            "\"neo4j_source_host, neo4j_target_host)=set_neo4j_host(%s, %s, %s)...successful!"
            % (db_service3, source_env, target_env))
    """ calling set_host()...stop"""
    """****************************************************************************************************************"""
    """ Validate DB Accounts... start"""
    """ Validate Source Accounts... start"""
    print("Validating source host..."),
    if db_service == 'mysql':
        my_logger.info("Validating source host for db_service %s" % db_service)
        my_logger.info(
            "Calling \"validate_mysql_source(dict_source_ttSettings, %s)..." %
            (mysql_source_host))
        try:
            validate_mysql_source(dict_source_ttSettings, mysql_source_host)
        except:
            my_logger.error(
                "Error encountered: %s. \"validate_mysql_source(dict_source_ttSettings, %s)...failed. Exiting!"
                % (str(sys.exc_info()), mysql_source_host))
            sys.exit(
                "Error encountered: %s. \"validate_mysql_source(dict_source_ttSettings, %s)...failed. Exiting!"
                % (str(sys.exc_info()), mysql_source_host))
        my_logger.info(
            "\"validate_mysql_source(dict_source_ttSettings, %s)...successful!"
            % (mysql_source_host))

    elif db_service == 'mongodb':
        my_logger.info("Validating source host for db_service %s" % db_service)
        my_logger.info(
            "Calling \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)..."
            % (mongodb_source_host))
        try:
            validate_mongodb_source_accounts(mongodb_source_host,
                                             dict_source_ttSettings)
        except:
            my_logger.error(
                "Error encountered: %s. \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...failed. Exiting!"
                % (str(sys.exc_info()), mongodb_source_host))
            sys.exit(
                "Error encountered: %s. \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...failed. Exiting!"
                % (str(sys.exc_info()), mongodb_source_host))
        my_logger.info(
            "\"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...successful!"
            % (mongodb_source_host))

    elif db_service == 'neo4j':
        my_logger.info("Validating source host for db_service %s" % db_service)
        my_logger.info(
            "Calling \"validate_neo4j_aws_accounts(%s, dict_source_ttSettings)..."
            % (neo4j_source_host))
        try:
            validate_neo4j_aws_accounts(neo4j_source_host,
                                        dict_source_ttSettings)
        except:
            my_logger.error(
                "Error encountered: %s. \"validate_neo4j_aws_accounts(%s, dict_source_ttSettings))...failed. Exiting!"
                % (str(sys.exc_info()), neo4j_source_host))
            sys.exit(
                "Error encountered: %s. \"validate_neo4j_aws_accounts(%s, dict_source_ttSettings)...failed. Exiting!"
                % (str(sys.exc_info()), neo4j_source_host))
        my_logger.info(
            "\"validate_neo4j_aws_accounts(%s, dict_source_ttSettings)...successful!"
            % (neo4j_source_host))

    elif db_service == 'all':
        db_service1 = 'mysql'
        my_logger.info("Validating source host for db_service %s" %
                       db_service1)
        my_logger.info(
            "Calling \"validate_mysql_source(dict_source_ttSettings, %s)..." %
            (mysql_source_host))
        try:
            validate_mysql_source(dict_source_ttSettings, mysql_source_host)
        except:
            my_logger.error(
                "Error encountered: %s. \"validate_mysql_source(dict_source_ttSettings, %s)...failed. Exiting!"
                % (str(sys.exc_info()), mysql_source_host))
            sys.exit(
                "Error encountered: %s. \"validate_mysql_source(dict_source_ttSettings, %s)...failed. Exiting!"
                % (str(sys.exc_info()), mysql_source_host))
        my_logger.info(
            "\"validate_mysql_source(dict_source_ttSettings, %s)...successful!"
            % (mysql_source_host))

        db_service2 = 'mongodb'
        my_logger.info("Validating source host for db_service %s" %
                       db_service2)
        my_logger.info(
            "Calling \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)..."
            % (mongodb_source_host))
        try:
            validate_mongodb_source_accounts(mongodb_source_host,
                                             dict_source_ttSettings)
        except:
            my_logger.error(
                "Error encountered: %s. \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...failed. Exiting!"
                % (str(sys.exc_info()), mongodb_source_host))
            sys.exit(
                "Error encountered: %s. \"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...failed. Exiting!"
                % (str(sys.exc_info()), mongodb_source_host))
        my_logger.info(
            "\"validate_mongodb_source_accounts(%s, dict_source_ttSettings)...successful!"
            % (mongodb_source_host))

        db_service2 = 'neo4j'
        my_logger.info("Validating source host for db_service %s" %
                       db_service3)
        my_logger.info(
            "Calling \"validate_neo4j_aws_accounts(%s, dict_source_ttSettings)..."
            % (neo4j_source_host))
        try:
            validate_neo4j_aws_accounts(neo4j_source_host,
                                        dict_source_ttSettings)
        except:
            my_logger.error(
                "Error encountered: %s. \"validate_neo4j_aws_accounts(%s, dict_source_ttSettings))...failed. Exiting!"
                % (str(sys.exc_info()), neo4j_source_host))
            sys.exit(
                "Error encountered: %s. \"validate_neo4j_aws_accounts(%s_host, dict_source_ttSettings)...failed. Exiting!"
                % (str(sys.exc_info()), neo4j_source_host))
        my_logger.info(
            "\"validate_neo4j_aws_accounts(%s, dict_source_ttSettings)...successful!"
            % (neo4j_source_host))
    print "Complete!"
    """ Validate Source Accounts... stop"""
    """ Validate Target Accounts... start"""
    #print("Validating target host..."),
    if db_service == 'mysql':
        if "aws.3top.com" in mysql_target_host:
            my_logger.info("Found \"aws.3top.com\" in target host")
            my_logger.info("Validating target host for %s" % (db_service))
            my_logger.info(
                "Calling \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)..."
                % (mysql_target_host))
            try:
                validate_mysql_aws_accounts(dict_target_ttSettings,
                                            mysql_target_host)
            except:
                my_logger.error(
                    "Error encountered: %s. \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_target_host))
                sys.exit(
                    "Error encountered: %s. \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_target_host))
            my_logger.info(
                "\"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...successful!"
                % (mysql_target_host))

        elif "nyc.3top.com" in mysql_target_host:
            my_logger.info("Found \"nyc.3top.com\" in target host")
            my_logger.info("Validating target host for db_service %s" %
                           db_service)
            my_logger.info(
                "Calling \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)..."
                % (mysql_target_host))
            try:
                validate_mysql_nyc_accounts(dict_target_ttSettings,
                                            mysql_target_host)
            except:
                my_logger.error(
                    "Error encountered: %s. \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_target_host))
                sys.exit(
                    "Error encountered: %s. \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_target_host))
            my_logger.info(
                "\"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...successful!"
                % (mysql_target_host))

    elif db_service == 'mongodb':
        my_logger.info("Validating source host for db_service %s" % db_service)
        my_logger.info(
            "Calling \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)..."
            % (mongodb_target_host))
        try:
            validate_mongodb_target_accounts(mongodb_target_host,
                                             dict_target_ttSettings)
        except:
            my_logger.error(
                "Error encountered: %s. \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...failed. Exiting!"
                % (str(sys.exc_info()), mongodb_target_host))
            sys.exit(
                "Error encountered: %s. \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...failed. Exiting!"
                % (str(sys.exc_info()), mongodb_target_host))
        my_logger.info(
            "\"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...successful!"
            % (mongodb_target_host))

    elif db_service == 'neo4j':
        if "nyc.3top.com" in neo4j_target_host:
            my_logger.info("Found \"nyc.3top.com\" in target host")
            my_logger.info(
                "calling \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)\"..."
                % (neo4j_target_host))
            try:
                validate_neo4j_nyc_target(neo4j_target_host,
                                          dict_target_ttSettings)
            except:
                my_logger.error(
                    "Error encountered: %s. \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"
                    % (str(sys.exc_info()), neo4j_target_host))
                sys.exit(
                    "Error encountered: %s. \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"
                    % (str(sys.exc_info()), neo4j_target_host))
            my_logger.info(
                "\"validate_neo4j_nyc_target(%s, dict_target_ttSettings)\"...successful!"
            )

        elif "aws.3top.com" in neo4j_target_host:
            my_logger.info("Found \"aws.3top.com\" in target host")
            my_logger.info(
                "calling \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)\"..."
                % (neo4j_target_host))
            try:
                validate_neo4j_aws_accounts(neo4j_target_host,
                                            dict_target_ttSettings)
            except:
                my_logger.error(
                    "Error encountered: %s. \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"
                    % (str(sys.exc_info()), neo4j_target_host))
                sys.exit(
                    "Error encountered: %s. \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"
                    % (str(sys.exc_info()), neo4j_target_host))
            my_logger.info(
                "\"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)\"...successful!"
            )

    elif db_service == 'all':
        if "aws.3top.com" in mysql_target_host:
            my_logger.info("Found \"aws.3top.com\" in target host")
            my_logger.info("Validating target host for %s" %
                           (mysql_target_host))
            my_logger.info(
                "Calling \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)..."
                % (mysql_target_host))
            try:
                validate_mysql_aws_accounts(dict_target_ttSettings,
                                            mysql_target_host)
            except:
                my_logger.error(
                    "Error encountered: %s. \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_target_host))
                sys.exit(
                    "Error encountered: %s. \"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_target_host))
            my_logger.info(
                "\"validate_mysql_aws_accounts(dict_target_ttSettings, %s)...successful!"
                % (mysql_target_host))

        elif "nyc.3top.com" in mysql_target_host:
            my_logger.info("Found \"nyc.3top.com\" in target host")
            my_logger.info("Validating target host for db_service %s" %
                           db_service)
            my_logger.info(
                "Calling \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)..."
                % (mysql_target_host))
            try:
                validate_mysql_nyc_accounts(dict_target_ttSettings,
                                            mysql_target_host)
            except:
                my_logger.error(
                    "Error encountered: %s. \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_target_host))
                sys.exit(
                    "Error encountered: %s. \"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...failed. Exiting!"
                    % (str(sys.exc_info()), mysql_target_host))
            my_logger.info(
                "\"validate_mysql_nyc_accounts(dict_target_ttSettings, %s)...successful!"
                % (mysql_target_host))

        my_logger.info("Validating source host for db_service %s" % db_service)
        my_logger.info(
            "Calling \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)..."
            % (mongodb_target_host))
        try:
            validate_mongodb_target_accounts(mongodb_target_host,
                                             dict_target_ttSettings)
        except:
            my_logger.error(
                "Error encountered: %s. \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...failed. Exiting!"
                % (str(sys.exc_info()), mongodb_target_host))
            sys.exit(
                "Error encountered: %s. \"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...failed. Exiting!"
                % (str(sys.exc_info()), mongodb_target_host))
        my_logger.info(
            "\"validate_mongodb_target_accounts(%s, dict_target_ttSettings)...successful!"
            % (mongodb_target_host))

        if "nyc.3top.com" in neo4j_target_host:
            my_logger.info("Found \"nyc.3top.com\" in target host")
            my_logger.info(
                "calling \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)\"..."
                % (neo4j_target_host))
            try:
                validate_neo4j_nyc_target(neo4j_target_host,
                                          dict_target_ttSettings)
            except:
                my_logger.error(
                    "Error encountered: %s. \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"
                    % (str(sys.exc_info()), neo4j_target_host))
                sys.exit(
                    "Error encountered: %s. \"validate_neo4j_nyc_target(%s, dict_target_ttSettings)...failed. Exiting!"
                    % (str(sys.exc_info()), neo4j_target_host))
            my_logger.info(
                "\"validate_neo4j_nyc_target(%s, dict_target_ttSettings)\"...successful!"
            )

        elif "aws.3top.com" in neo4j_target_host:
            my_logger.info("Found \"aws.3top.com\" in target host")
            my_logger.info(
                "calling \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)\"..."
                % (neo4j_target_host))
            try:
                validate_neo4j_aws_accounts(neo4j_target_host,
                                            dict_target_ttSettings)
            except:
                my_logger.error(
                    "Error encountered: %s. \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"
                    % (str(sys.exc_info()), neo4j_target_host))
                sys.exit(
                    "Error encountered: %s. \"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)...failed. Exiting!"
                    % (str(sys.exc_info()), neo4j_target_host))
            my_logger.info(
                "\"validate_neo4j_aws_accounts(%s, dict_target_ttSettings)\"...successful!"
            )
    """ Validate Target Accounts... stop"""
    """ Validate DB Accounts... stop"""
    """****************************************************************************************************************"""
    """ Find current working directory path: python_root...start"""

    global python_root
    my_logger.debug("Finding real path (working directory)...")
    python_root = os.path.dirname(os.path.realpath(__file__)) + "/"
    my_logger.debug("python_root:%s" % python_root)
    #print "found."
    """ Find current working directory path: python_root...stop"""
    """********************************************************************************************************************"""
    """ Executing db_operation"""
    #Region = dict_ttSettings["aws"]["REGION_NAME"]
    if db_service == 'mysql':
        print "Executing mysql_operations..."
        my_logger.debug(
            "calling mysql_operations() with source: %s, target: %s..." %
            (mysql_source_host, mysql_target_host))
        mysql_operations(db_operation, db_service, dict_source_ttSettings,
                         dict_target_ttSettings, mysql_source_host,
                         mysql_target_host, my_logger, log_file_abs_path)
        my_logger.info("MySQL operations completed successfully")
    elif db_service == "mongodb":
        print "Executing mongo_operations..."
        my_logger.debug(
            "calling mongo_operations() with source: %s, target: %s..." %
            (mongodb_source_host, mongodb_target_host))
        mongo_operations(db_operation, db_service, dict_source_ttSettings,
                         dict_target_ttSettings, mongodb_source_host,
                         mongodb_target_host, my_logger, log_file_abs_path)
        my_logger.info("MongoDB operations completed successfully")
    elif db_service == 'neo4j':
        print "Executing neo4j_operations..."
        my_logger.debug(
            "calling neo4j_operations() with source: %ss , target: %s..." %
            (neo4j_source_host, neo4j_target_host))
        neo4j_operations(dict_source_ttSettings, dict_target_ttSettings)
        my_logger.info("Neo4j operations completed successfully")
    elif db_service == 'all':
        print "Executing mysql_operations..."
        my_logger.debug(
            "calling mysql_operations() with source: %s, target: %s..." %
            (mysql_source_host, mysql_target_host))
        mysql_operations(db_operation, db_service, dict_source_ttSettings,
                         dict_target_ttSettings, mysql_source_host,
                         mysql_target_host, my_logger, log_file_abs_path)
        my_logger.info("MySQL operations completed successfully")
        print "Executing mongo_operations..."
        my_logger.debug(
            "calling mongo_operations() with source: %s, target: %s..." %
            (mongodb_source_host, mongodb_target_host))
        mongo_operations(db_operation, db_service, dict_source_ttSettings,
                         dict_target_ttSettings, mongodb_source_host,
                         mongodb_target_host, my_logger, log_file_abs_path)
        my_logger.info("MongoDB operations completed successfully")
        print "Executing neo4j_operations..."
        my_logger.debug(
            "calling neo4j_operations() with source: %ss , target: %s..." %
            (neo4j_source_host, neo4j_target_host))
        neo4j_operations(dict_source_ttSettings, dict_target_ttSettings)
        my_logger.info("Neo4j operations completed successfully")
    """main() Module definition... start"""
    """main() Module definition... stop"""

    my_logger.info("Program execution complete. Exiting!")
    print "Program execution complete. Exiting!\nLogfile location: %s" % log_file_abs_path
Example #3
0
def main():
    print("In main()...")
    
    """****************************************************************************************************************"""
    """ Collecting arguments into variables based on the format:
        db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target.suffix (for 'copy' only)]
        start
        """
    #print("Collecting arguments into variables...")
    if length_of_args == 4:
        target_env = sys.argv[3]
    elif length_of_args==3:
        target_env = " "    
    else:
        sys.exit("Arguments format mismatch.  Exiting! \nUse: db_util.py [ swap | copy ] [ ALL | mysql | mongodb | virtuoso | neo4j ] [ target_env (for 'copy' only)].")
        #sys.exit("Arguments mismatch.  Exiting!")
        #sys.exit(-1)
    print("Received target_env: %s"%target_env)
    #print "target_env: ", target_env
    
    db_operation = sys.argv[1]
    print("Received db_operation: %s"%db_operation)
    #print"db_operation: ", db_operation
    
    db_service = sys.argv[2]
    print("Received db_service: %s"%db_service)
    #print"db_service: ",db_service
    
    """Collecting arguments into variables...stop"""
    """****************************************************************************************************************"""
    """ calling validate_args()...start"""
    
    #print("Calling \"validate_args()\"...")
    validate_args(db_operation, db_service, target_env)
    print("Validate args successful. Back in main()...")
    
    """ calling validate_args()...stop"""
    """****************************************************************************************************************"""
    """ calling set_env()...start"""
    
    #print("Calling \"set_env()\"...")
    (source_env, target_env)=set_env(db_operation, target_env)
    print("set_env successful. Back in main()... Received:: source_env: %s, target_env: %s. "%(source_env, target_env))
    
    """ calling set_env()...stop"""
    """****************************************************************************************************************"""
    """Start download of ttSettings based on source env"""
    
    #dict_source_ttSettings = {}
    source_s3_folder = "aws-" + source_env.split(".")[1] + "/" + source_env.split(".")[0]
    print "Downloading ttSettings for %s from %s folder on S3..."%(source_env,source_s3_folder)
    try:
        s3_config_folder = source_s3_folder
        s3_config_filename = "ttSettings.conf"
        global dict_source_ttSettings
        dict_source_ttSettings = get_s3_config(s3_config_folder, s3_config_filename)
        print"complete."  
        #print  "dict_source_ttSettings: %s"%dict_source_ttSettings
    except:
        sys.exit("Download of ttSettings from S3 failed. Exiting! Error Encountered: %s." %str(sys.exc_info()))
        
    """Stop download of ttSettings based on source env""" 
    """****************************************************************************************************************"""    
    """Start download of ttSettings based on target env"""
    
    if "aws.3top.com" in target_env:
        #dict_source_ttSettings = {}
        target_s3_folder = "aws-" + target_env.split(".")[1] + "/" + target_env.split(".")[0]
    elif "nyc.3top.com" in target_env:
        #dict_source_ttSettings = {}
        target_s3_folder = "nyc-sys"
    print "Downloading ttSettings for %s from %s folder on S3..."%(target_env, target_s3_folder)
    try:
        s3_config_folder = target_s3_folder
        s3_config_filename = "ttSettings.conf"
        global dict_target_ttSettings
        dict_target_ttSettings = get_s3_config(s3_config_folder, s3_config_filename)
        print"complete."  
        #print  "dict_target_ttSettings: %s"%dict_target_ttSettings
    except:
        sys.exit("Download of ttSettings from S3 failed. Exiting! Error Encountered: %s." %str(sys.exc_info()))         
       
    """Stop download of ttSettings based on target env""" 
    """****************************************************************************************************************"""
    """ calling validate_cert_loc()...start"""
    
    if ("aws.3top.com" in source_env) or ("aws.3top.com" in target_env):
        #print("Calling \"validate_cert_loc()\"...")
        AWS_MYSQL_CERT = validate_cert_loc(dict_ttSettings)
        print("validate_cert_loc() successful. Back in main()... ")
    
    """ calling validate_cert_loc()...stop"""
    """****************************************************************************************************************"""
    """ calling set_host()...start"""
    
    #print("Calling \"set_host()\"...")
    if db_service == 'mysql':
        (mysql_source_host, mysql_target_host) = set_mysql_host(db_service, source_env,target_env)
        print("set_host successful. Back in main()... Received:: mysql_source_host: %s, mysql_target_host: %s."%(mysql_source_host, mysql_target_host))
    elif db_service == 'mongodb':
        (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service, source_env, target_env)
        print("set_host successful. Back in main()... Received:: mongodb_source_host: %s, mongodb_target_host: %s."%(mongodb_source_host, mongodb_target_host))
    elif db_service == 'neo4j':
        (neo4j_source_host, neo4j_target_host)=set_neo4j_host(db_service, source_env, target_env)
        print("set_host successful. Back in main()... Received:: neo4j_source_host: %s, neo4j_target_host: %s."%(neo4j_source_host, neo4j_target_host))
    elif db_service == 'all':
        (mysql_source_host, mysql_target_host) = set_mysql_host(db_service, source_env,target_env)
        (mongodb_source_host, mongodb_target_host)=set_mongodb_host(db_service, source_env, target_env)
        (neo4j_source_host, neo4j_target_host)=set_neo4j_host(db_service, source_env, target_env)
        print("set_host successful. Back in main()... Received:: mysql_source_host: %s, mysql_target_host: %s."%(mysql_source_host, mysql_target_host))
        print("set_host successful. Back in main()... Received:: mongodb_source_host: %s, mongodb_target_host: %s."%(mongodb_source_host, mongodb_target_host))
        print("set_host successful. Back in main()... Received:: neo4j_source_host: %s, neo4j_target_host: %s."%(neo4j_source_host, neo4j_target_host))
        
    """ calling set_host()...stop"""
    """****************************************************************************************************************"""
    """ Validate DB Accounts... start"""
    
    """ Validate Source Accounts... start"""
    #print("Validating source host..."),
    if db_service == 'mysql':
        validate_mysql_source(AWS_MYSQL_CERT, mysql_source_host)
    elif db_service == 'mongodb':
        validate_mongodb_source_accounts(mongodb_source_host)
    elif db_service == 'neo4j':
        validate_neo4j_aws_accounts(neo4j_source_host)
    elif db_service == 'all':
        validate_mysql_source(AWS_MYSQL_CERT, mysql_source_host)
        validate_mongodb_source_accounts(mongodb_source_host)
        validate_neo4j_aws_accounts(neo4j_source_host)
        
           
    """ Validate Source Accounts... stop"""
    
    """ Validate Target Accounts... start"""
    #print("Validating target host..."),
    if db_service == 'mongodb':
        #print("Calling \"validate_mongodb_target_accounts\"...")
        validate_mongodb_target_accounts(mongodb_target_host)
    elif db_service == 'mysql':
        if "nyc.3top.com" in mysql_target_host:
            validate_mysql_nyc_accounts(mysql_target_host)
        elif "aws.3top.com" in mysql_target_host:
            validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_target_host)
    elif db_service == 'neo4j':
        if "nyc.3top.com" in neo4j_target_host:
            validate_neo4j_nyc_target(neo4j_target_host)
        elif "aws.3top.com" in neo4j_target_host:
            validate_neo4j_aws_accounts(neo4j_target_host)
    elif db_service == 'all':
        validate_mongodb_target_accounts(mongodb_target_host)
        if "nyc.3top.com" in mysql_target_host:
            validate_mysql_nyc_accounts(mysql_target_host)
        elif "aws.3top.com" in mysql_target_host:
            validate_mysql_aws_accounts(AWS_MYSQL_CERT, mysql_target_host)
        if "nyc.3top.com" in neo4j_target_host:
            validate_neo4j_nyc_target(neo4j_target_host)
        elif "aws.3top.com" in neo4j_target_host:
            validate_neo4j_aws_accounts(neo4j_target_host)
            
    """ Validate Target Accounts... stop"""
    
    """ Validate DB Accounts... stop"""    
    """****************************************************************************************************************"""
    """ Find current working directory path: python_root...start"""
    
    global python_root
    #print "Finding real path (working directory)...",
    python_root = os.path.dirname(os.path.realpath(__file__)) + "/"
    #print"python_root:",python_root,
    #print "found."
    
    """ Find current working directory path: python_root...stop"""
    """********************************************************************************************************************"""
    """ Executing db_operation"""
    
    if db_service== "mongodb":
        print "Executing mongo_operations..."
        mongo_operations(db_operation, db_service, mongodb_source_host, mongodb_target_host, my_logger,log_file_abs_path)
        my_logger.info("MongoDB operations completed successfully")
    elif db_service == 'mysql':
        print "Executing mysql_operations..."
        mysql_operations(db_operation, db_service, AWS_MYSQL_CERT, mysql_source_host, mysql_target_host, my_logger,log_file_abs_path)
        my_logger.info("MySQL operations completed successfully")
    elif db_service == 'neo4j':
        print "Executing neo4j_operations..."
        neo4j_operations()
        my_logger.info("Neo4j operations completed successfully")
    elif db_service == 'all':
        print "Executing mongo_operations..."
        mongo_operations(db_operation, db_service, mongodb_source_host, mongodb_target_host, my_logger,log_file_abs_path)
        my_logger.info("MongoDB operations completed successfully")
        print "Executing mysql_operations..."
        mysql_operations(db_operation, db_service, AWS_MYSQL_CERT, mysql_source_host, mysql_target_host, my_logger,log_file_abs_path)
        my_logger.info("MySQL operations completed successfully")
        print "Executing neo4j_operations..."
        neo4j_operations()
        my_logger.info("Neo4j operations completed successfully")
    """main() Module definition... start"""
    """main() Module definition... stop"""
    
    my_logger.info("Program execution complete. Exiting!")
    print "Program execution complete. Exiting!\nLogfile location: %s" %log_file_abs_path