def restore_collection(env): """ Restore collections using replication API (as Solr Cloud Backup API is not available in Solr 5) """ import params, command_commons env.set_params(command_commons) collection_available = command_commons.is_collection_available_on_host() if command_commons.check_hosts and not collection_available: Logger.info(format("No any '{collection}' replica is used on {params.hostname} host")) return Logger.info(format("Remove write.lock files from folder '{index_location}'")) for write_lock_file in command_commons.get_files_by_pattern(format("{index_location}"), 'write.lock'): File(write_lock_file, action="delete") Logger.info(format("Restore Solr Collection {collection} from {index_location}")) solr_request_path = format("{collection}/replication?command=RESTORE&location={index_location}&name={backup_name}&wt=json") restore_api_cmd = command_commons.create_solr_api_request_command(solr_request_path) Execute(restore_api_cmd, user=params.infra_solr_user, logoutput=True) if command_commons.request_async is False: Logger.info("Sleep 5 seconds to wait until the restore request is executed.") time.sleep(5) Logger.info("Check restore status ...") solr_status_request_path = format("{collection}/replication?command=restorestatus&wt=json") status_check_json_output = format("{index_location}/restore_status.json") status_check_cmd = command_commons.create_solr_api_request_command(solr_status_request_path, status_check_json_output) command_commons.snapshot_status_check(status_check_cmd, status_check_json_output, command_commons.backup_name, False, log_output=command_commons.log_output, tries=command_commons.request_tries, time_interval=command_commons.request_time_interval)
def backup_collection(env): """ Backup collections using replication API (as Solr Cloud Backup API is not available in Solr 5) """ import params, command_commons env.set_params(command_commons) Directory(command_commons.index_location, mode=0755, cd_access='a', owner=params.infra_solr_user, group=params.user_group ) collection_available = command_commons.is_collection_available_on_host() if not collection_available: Logger.info(format("No any '{collection}' replica is used on {params.hostname} host")) return Logger.info(format("Backup Solr Collection {collection} to {index_location}")) solr_request_path = format("{collection}/replication?command=BACKUP&location={index_location}&name={backup_name}&wt=json") backup_api_cmd = command_commons.create_solr_api_request_command(solr_request_path) Execute(backup_api_cmd, user=params.infra_solr_user, logoutput=True) if command_commons.request_async is False: Logger.info("Sleep 5 seconds to wait until the backup request is executed.") time.sleep(5) Logger.info("Check backup status ...") solr_status_request_path = format("{collection}/replication?command=details&wt=json") status_check_json_output = format("{index_location}/backup_status.json") status_check_cmd = command_commons.create_solr_api_request_command(solr_status_request_path, status_check_json_output) command_commons.snapshot_status_check(status_check_cmd, status_check_json_output, command_commons.backup_name, True, log_output=command_commons.log_output, tries=command_commons.request_tries, time_interval=command_commons.request_time_interval)
def backup_collection(env): """ Backup collections using replication API (as Solr Cloud Backup API is not available in Solr 5) If the cluster is not kerberized, it will be needed to resolve ip addresses to hostnames (as SOLR_HOST=`hostname -f` is not used by default in infra-solr-env) """ import params, command_commons env.set_params(command_commons) Directory(command_commons.index_location, mode=0755, cd_access='a', create_parents=True, owner=params.infra_solr_user, group=params.user_group ) host_cores_data_map = command_commons.get_host_cores_for_collection() Logger.info(format("Backup Solr Collection {collection} to {index_location}")) host_core_map = host_cores_data_map[command_commons.HOST_CORES] host_or_ip = params.hostname # IP resolve - for unsecure cluster host_ip_pairs = {} if not params.security_enabled: keys = host_core_map.keys() for key in keys: if command_commons.is_ip(key): resolved_hostname = command_commons.resolve_ip_to_hostname(key) host_ip_pairs[resolved_hostname] = key if params.hostname in host_ip_pairs: host_or_ip = host_ip_pairs[params.hostname] cores = host_core_map[host_or_ip] if host_or_ip in host_core_map else [] for core in cores: if core in command_commons.skip_cores: Logger.info(format("Core '{core}' is filtered out.")) continue solr_request_path = format("{core}/replication?command=BACKUP&location={index_location}&name={core}&wt=json") backup_api_cmd = command_commons.create_solr_api_request_command(solr_request_path) Execute(backup_api_cmd, user=params.infra_solr_user, logoutput=True) if command_commons.request_async is False: Logger.info("Sleep 5 seconds to wait until the backup request is executed.") time.sleep(5) Logger.info("Check backup status ...") solr_status_request_path = format("{core}/replication?command=details&wt=json") status_check_json_output = format("{index_location}/backup_status.json") status_check_cmd = command_commons.create_solr_api_request_command(solr_status_request_path, status_check_json_output) command_commons.snapshot_status_check(status_check_cmd, status_check_json_output, core, True, log_output=command_commons.log_output, tries=command_commons.request_tries, time_interval=command_commons.request_time_interval)
def delete_collection(env): """ Delete specific Solr collection - used on ranger_audits by default """ import params, command_commons env.set_params(command_commons) Logger.info(format("Delete Solr Collection: {collection}")) solr_request_path = format( "admin/collections?action=DELETE&name={collection}&wt=json") delete_api_cmd = command_commons.create_solr_api_request_command( solr_request_path) Execute(delete_api_cmd, user=params.infra_solr_user, logoutput=True)
def restore_collection(env): """ Restore collections using replication API (as Solr Cloud Backup API is not available in Solr 5) """ import params, command_commons env.set_params(command_commons) Logger.info( format("Remove write.lock files from folder '{index_location}'")) for write_lock_file in command_commons.get_files_by_pattern( format("{index_location}"), 'write.lock'): File(write_lock_file, action="delete") Logger.info( format("Restore Solr Collection {collection} from {index_location}")) solr_request_path = format( "{collection}/replication?command=RESTORE&location={index_location}&name={backup_name}&wt=json" ) restore_api_cmd = command_commons.create_solr_api_request_command( solr_request_path) Execute(restore_api_cmd, user=params.infra_solr_user, logoutput=True)
def backup_collection(env): """ Backup collections using replication API (as Solr Cloud Backup API is not available in Solr 5) """ import params, command_commons env.set_params(command_commons) Logger.info( format("Backup Solr Collection {collection} to {index_location}")) solr_request_path = format( "{collection}/replication?command=BACKUP&location={index_location}&name={backup_name}&wt=json" ) backup_api_cmd = command_commons.create_solr_api_request_command( solr_request_path) Directory(command_commons.index_location, mode=0755, cd_access='a', owner=params.infra_solr_user, group=params.user_group) Execute(backup_api_cmd, user=params.infra_solr_user, logoutput=True)