def start_staging(repository, source_config, staged_source): common.add_debug_heading_block("Start Staged - Start Staging") helpers._record_hook("staging start", staged_source.staged_connection) helpers._set_running(staged_source.staged_connection, staged_source.guid) staged_source.mongo_install_path = repository.mongo_install_path staged_source.mongo_shell_path = repository.mongo_shell_path if staged_source.parameters.d_source_type == "extendedcluster": staged_source.parameters.mongos_port = staged_source.parameters.start_portpool staged_source.parameters.mongo_db_user = staged_source.parameters.src_db_user staged_source.parameters.mongo_db_password = staged_source.parameters.src_db_password linked.add_staging_to_primary(staged_source, 'Staging', "extendedcluster") elif staged_source.parameters.d_source_type == "stagingpush": logger.info("No action needed for stagingpsuh") else: if staged_source.parameters.d_source_type == "nonshardedsource": staged_source.parameters.mongos_port = staged_source.parameters.start_portpool common.start_sharded_mongo('Staging', staged_source) logger.debug("End of start staging") common.add_debug_heading_block("End Staged - Start Staging") logger.debug(" ")
def configure(virtual_source, repository, snapshot): helpers._record_hook("virtual configure", virtual_source.connection) helpers._set_running(virtual_source.connection, virtual_source.guid) virtual_source.mongo_install_path = repository.mongo_install_path virtual_source.mongo_shell_path = repository.mongo_shell_path logger.info("snapshot:{}".format(snapshot)) logger.info("d_source_type:{}".format(snapshot.d_source_type)) d_source_type = snapshot.d_source_type if d_source_type in [ "nonshardedsource", "offlinemongodump", "onlinemongodump", "seed", "stagingpush", "extendedcluster" ]: virtual_source.parameters.mongos_port = virtual_source.parameters.start_portpool common.setup_dataset(virtual_source, 'Virtual', snapshot, d_source_type) logger.debug("End of virtual configure") logger.debug(" ") discovery_type = "Auto" pretty_name = "{}-{}-{}".format(d_source_type, virtual_source.parameters.mount_path, virtual_source.parameters.start_portpool) return SourceConfigDefinition(discovery_type=discovery_type, pretty_name=pretty_name)
def reconfigure(snapshot, repository, source_config, virtual_source): helpers._record_hook("virtual reconfigure", virtual_source.connection) helpers._set_running(virtual_source.connection, virtual_source.guid) virtual_source.mongo_install_path = repository.mongo_install_path virtual_source.mongo_shell_path = repository.mongo_shell_path common.start_sharded_mongo('Virtual', virtual_source) return source_config
def start(repository, source_config, virtual_source): helpers._record_hook("virtual start", virtual_source.connection) helpers._set_running(virtual_source.connection, virtual_source.guid) virtual_source.mongo_install_path = repository.mongo_install_path virtual_source.mongo_shell_path = repository.mongo_shell_path common.start_sharded_mongo('Virtual', virtual_source) logger.debug("End of start virtual") logger.debug(" ")
def staged_post_snapshot(repository, source_config, staged_source, optional_snapshot_parameters): common.add_debug_heading_block("Start Staged Post Snapshot") helpers._record_hook("staging post snapshot", staged_source.staged_connection) helpers._set_running(staged_source.staged_connection, staged_source.guid) staged_source.mongo_install_path = repository.mongo_install_path staged_source.mongo_shell_path = repository.mongo_shell_path if staged_source.parameters.d_source_type == "extendedcluster": staged_source.parameters.mongo_db_user = staged_source.parameters.src_db_user staged_source.parameters.mongo_db_password = staged_source.parameters.src_db_password snapshot_possible_file_path = "{}/{}".format( staged_source.parameters.mount_path, ".delphix/snapshot_not_possible.txt") cmd = "test -f {} && cat {} || echo 'file does not exist.'".format( snapshot_possible_file_path, snapshot_possible_file_path) res = common.execute_bash_cmd(staged_source.staged_connection, cmd, {}) if res != "file does not exist.": cmd = "rm {}".format(snapshot_possible_file_path) res_rm = common.execute_bash_cmd(staged_source.staged_connection, cmd, {}) errorMsg = "Cannot perform Snapshot as the host {} is in state {}".format( res.split(" ")[1].split(" : ")[1], res.split(" ")[2].split(" : ")[1]) logger.info(errorMsg) raise UserError(errorMsg) elif staged_source.parameters.d_source_type == "stagingpush": staged_source.parameters.mongo_db_user = staged_source.parameters.src_db_user staged_source.parameters.mongo_db_password = staged_source.parameters.src_db_password if staged_source.parameters.d_source_type == "nonshardedsource": staged_source.parameters.mongos_port = staged_source.parameters.start_portpool logger.info("In Post snapshot...") logger.debug("len shard_backupfiles: {}".format( len(staged_source.parameters.shard_backupfiles))) script_content = 'echo "$(uname):$(uname -p):$(cat /etc/*-release)"' res = common.execute_bash_cmd(staged_source.staged_connection, script_content, {}) output = res.strip().split(":") logger.debug("output = {}".format(output)) if staged_source.parameters.d_source_type in [ "shardedsource", "offlinemongodump", "nonshardedsource" ]: cmd = "cat {}".format(staged_source.parameters.backup_metadata_file) lastbackup_datetime = common.execute_bash_cmd( staged_source.staged_connection, cmd, {}) dateTimeObj = datetime.strptime(lastbackup_datetime, "%m%d%Y_%H%M%S") else: dateTimeObj = datetime.now() timestampStr = dateTimeObj.strftime("%m%d%Y-%H%M%S.%f") snapshot = SnapshotDefinition(validate=False) snapshot.toolkit_version = _version.Version snapshot.timestamp = timestampStr snapshot.architecture = output[1] snapshot.os_type = output[0] snapshot.os_version = re.search('.*"VERSION="([\d\.]+).*', output[2]).group(1) snapshot.mongo_version = repository.version snapshot.delphix_mount = staged_source.parameters.mount_path snapshot.storage_engine = staged_source.parameters.storage_engine snapshot.user_auth_mode = staged_source.parameters.user_auth_mode snapshot.keyfile_path = staged_source.parameters.keyfile_path snapshot.replica_set = "N/A" snapshot.journal_interval = staged_source.parameters.journal_interval snapshot.oplog_size = staged_source.parameters.oplog_size snapshot.d_source_type = staged_source.parameters.d_source_type snapshot.append_db_path = "N/A" snapshot.mongo_db_user = staged_source.parameters.mongo_db_user snapshot.mongo_db_password = staged_source.parameters.mongo_db_password snapshot.source_sharded = staged_source.parameters.source_sharded snapshot.shard_count = (len(staged_source.parameters.shard_backupfiles)) snapshot.source_encrypted = staged_source.parameters.source_encrypted snapshot.cluster_auth_mode = staged_source.parameters.cluster_auth_mode snapshot.encryption_method = staged_source.parameters.encryption_method snapshot.encryption_keyfile = ".delphix/.dlpx_enckeyfile" snapshot.kmip_params = staged_source.parameters.kmip_params #logger.debug("Staging Post Snapshot - Unfreeze IO") #common.fsync_unlock_sharded_mongo(staged_source, 'Staging') #logger.debug("Staging Post Snapshot - Unfreeze IO - done") mask_snap = copy.deepcopy(snapshot) mask_snap.mongo_db_password = '******' logger.debug("snapshot schema: {}".format(mask_snap)) common.add_debug_heading_block("End Staged Post Snapshot") # ADD start Balancer return snapshot