Пример #1
0
    def _create_file_spaces(self):
        media_dir_names = ["{0}.journal1.0".format(self.node_name),
                           "{0}.storage1.0".format(self.node_name),
                           "{0}.storage1.1".format(self.node_name),
                           "{0}.storage2.0".format(self.node_name),
                           "{0}.storage2.1".format(self.node_name), ]

        media_paths = \
            [os.path.join(self._media_dir, n) for n in media_dir_names]

        # make media dirs for the node
        for media_path in media_paths:
            os.mkdir(media_path)

        # link to local
        media_link_paths = \
            [os.path.join(self._home_dir, str(n+1)) \
             for n in range(len(media_dir_names))]

        for media_path, media_link_path in zip(media_paths,
                                               media_link_paths):
            self._log.info("linking {0} to {1}".format(media_path,
                                                       media_link_path))
            os.symlink(media_path, media_link_path)

        database_password = self.env['NIMBUSIO_NODE_USER_PASSWORD']
        database_host = self.env["NIMBUSIO_NODE_DATABASE_HOST"]
        database_port = int(self.env["NIMBUSIO_NODE_DATABASE_PORT"])

        connection = get_node_connection(self.node_name, 
                                         database_password, 
                                         database_host, 
                                         database_port)

        connection.begin_transaction()
        command = """
            insert into nimbusio_node.file_space 
            (space_id, purpose, path, volume )
            values ( %s, %s, %s, %s);"""

        connection.execute(command, [1, "journal", media_paths[0], "journal1"])
        connection.execute(command, [2, "storage", media_paths[1], "storage1"])
        connection.execute(command, [3, "storage", media_paths[2], "storage1"])
        connection.execute(command, [4, "storage", media_paths[3], "storage2"])
        connection.execute(command, [5, "storage", media_paths[4], "storage2"])

        connection.commit()
        connection.close()
Пример #2
0
def main():
    """
    main entry point
    """
    [
        work_dir,
        index_str,
    ] = sys.argv[1:]
    index = int(index_str)
    node_name = _node_names[index]
    database_host = _node_database_hosts[index]
    database_port = _node_database_ports[index]
    database_password = _node_database_passwords[index]

    log_path = "{0}/nimbusio_segment_puller_from_{1}_to_{2}.log".format(
        os.environ["NIMBUSIO_LOG_DIR"], node_name, _local_node_name)
    initialize_logging(log_path)
    log = logging.getLogger("main")

    log.info("program starts: work_dir={0}, index={1}, {2}".format(
        work_dir, index, node_name))

    try:
        connection = get_node_connection(node_name, database_password,
                                         database_host, database_port)
    except Exception as instance:
        log.exception("Unable to connect to database {0}".format(instance))
        return -1

    try:
        _pull_segment_data(connection, work_dir, node_name)
        _pull_damaged_segment_data(connection, work_dir, node_name)
    except Exception as instance:
        log.exception("_pull_segment_data failed {0}".format(instance))
        return -2
    finally:
        connection.close()

    log.info("program terminates normally")
    return 0
def main():
    """
    main entry point
    """
    [work_dir, index_str, ] = sys.argv[1:]
    index = int(index_str)
    node_name = _node_names[index]
    database_host = _node_database_hosts[index]
    database_port = _node_database_ports[index]
    database_password = _node_database_passwords[index]

    log_path = "{0}/nimbusio_segment_puller_from_{1}_to_{2}.log".format(
        os.environ["NIMBUSIO_LOG_DIR"], node_name, _local_node_name)
    initialize_logging(log_path)
    log = logging.getLogger("main")

    log.info("program starts: work_dir={0}, index={1}, {2}".format(
        work_dir, index, node_name))

    try:
        connection = get_node_connection(node_name,
                                         database_password,
                                         database_host,
                                         database_port)
    except Exception as instance:
        log.exception("Unable to connect to database {0}".format(instance))
        return -1

    try:
        _pull_segment_data(connection, work_dir, node_name)
        _pull_damaged_segment_data(connection, work_dir, node_name)
    except Exception as instance:
        log.exception("_pull_segment_data failed {0}".format(instance))
        return -2
    finally:
        connection.close()

    log.info("program terminates normally")
    return 0