Esempio n. 1
0
print "Importing python libraries successful!"

"""Import sys, re...stop"""

"""********************************************************************************************************************"""

"""Download ttSettings.conf from S3...start"""

from ttLib.ttSys import get_s3_config 
#print "Downloading ttSettings from S3...",
try:
    s3_config_foldername="aws-prod"
    s3_config_filename = "ttSettings.conf"
    global dict_ttSettings
    dict_ttSettings = get_s3_config(s3_config_foldername, s3_config_filename)
    #global dict_ttSettings
    #dict_ttSettings = get_s3_config(s3_config_filename)
    #print"complete."  
    #print  dict_ttSettings
except:
    sys.exit("Error Encountered: %s. Download of ttSettings from S3 failed. Exiting!" %str(sys.exc_info()))

print "Downloading ttSettings from S3 successful!"
PATH_ROOT = dict_ttSettings["PATH_ROOT"]


"""Download ttSettings.conf from S3...stop"""

"""********************************************************************************************************************"""
Esempio n. 2
0
print "Importing python libraries successful!"
"""Import sys, re...stop"""
"""********************************************************************************************************************"""
"""Download ttSettings.conf from S3...start"""

python_root = os.path.dirname(os.path.realpath(__file__)) + "/"
sys.path.append(python_root + "ttLib")

from ttLib.ttSys import get_s3_config
#print "Downloading ttSettings from S3...",
try:
    s3_config_foldername = "nyc-sys"
    s3_config_filename = "ttSettings.conf"
    global dict_ttSettings
    dict_ttSettings = get_s3_config(s3_config_foldername, s3_config_filename)
except:
    sys.exit(
        "Error Encountered: %s. Download of ttSettings from S3 failed. Exiting!"
        % str(sys.exc_info()))

print "Downloading ttSettings from S3 successful!"
PATH_ROOT = dict_ttSettings["PATH_ROOT"]
"""Download ttSettings.conf from S3...stop"""
"""********************************************************************************************************************"""
""" Create a timestamp directory to store log files...start"""

#print "Creating timestamp directory..."
try:
    from ttLib.ttSys import dirCreateTimestamp
except:
Esempio n. 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
Esempio n. 4
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"""
    """****************************************************************************************************************"""
    """ Validate certificate location...start"""
    
    #print("Calling \"validate_cert_loc()\"...")
    #AWS_MYSQL_CERT = validate_cert_loc()
    
    """ Validate certificate location...start"""
    """****************************************************************************************************************"""
    """ 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""" 
    """****************************************************************************************************************"""
Esempio n. 5
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"""
    """****************************************************************************************************************"""
    """ Validate certificate location...start"""

    #print("Calling \"validate_cert_loc()\"...")
    #AWS_MYSQL_CERT = validate_cert_loc()
    """ Validate certificate location...start"""
    """****************************************************************************************************************"""
    """ 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"""
    """****************************************************************************************************************"""