<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.ignite.hadoop.fs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.ParentNotDirectoryException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathExistsException;
import org.apache.hadoop.fs.PathIsNotEmptyDirectoryException;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteFileSystem;
import org.apache.ignite.igfs.IgfsDirectoryNotEmptyException;
import org.apache.ignite.igfs.IgfsException;
import org.apache.ignite.igfs.IgfsFile;
import org.apache.ignite.igfs.IgfsParentNotDirectoryException;
import org.apache.ignite.igfs.IgfsPath;
import org.apache.ignite.igfs.IgfsPathAlreadyExistsException;
import org.apache.ignite.igfs.IgfsPathNotFoundException;
import org.apache.ignite.igfs.IgfsUserContext;
import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystem;
import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystemPositionedReadable;
import org.apache.ignite.internal.processors.hadoop.HadoopPayloadAware;
import org.apache.ignite.internal.processors.hadoop.igfs.HadoopIgfsProperties;
import org.apache.ignite.internal.processors.hadoop.igfs.HadoopIgfsSecondaryFileSystemPositionedReadable;
import org.apache.ignite.internal.processors.igfs.IgfsFileImpl;
import org.apache.ignite.internal.processors.igfs.IgfsFileInfo;
import org.apache.ignite.internal.processors.igfs.IgfsUtils;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgniteOutClosure;
import org.apache.ignite.lifecycle.LifecycleAware;
import org.jetbrains.annotations.Nullable;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.Callable;

import static org.apache.ignite.internal.processors.igfs.IgfsEx.PROP_GROUP_NAME;
import static org.apache.ignite.internal.processors.igfs.IgfsEx.PROP_PERMISSION;
import static org.apache.ignite.internal.processors.igfs.IgfsEx.PROP_USER_NAME;

/**
 * Secondary file system which delegates calls to an instance of Hadoop {@link FileSystem}.
 * <p>
 * Target {@code FileSystem}'s are created on per-user basis using passed {@link HadoopFileSystemFactory}.
 */
public class IgniteHadoopIgfsSecondaryFileSystem implements IgfsSecondaryFileSystem, LifecycleAware,
    HadoopPayloadAware {
    /** The default user name. It is used if no user context is set. */
    private String dfltUsrName;

    /** Factory. */
    private HadoopFileSystemFactory fsFactory;

    /**
     * Default constructor for Spring.
     */
    public IgniteHadoopIgfsSecondaryFileSystem() {
        // No-op.
    }

    /**
     * Simple constructor that is to be used by default.
     *
     * @param uri URI of file system.
     * @throws IgniteCheckedException In case of error.
     * @deprecated Use {@link #getFileSystemFactory()} instead.
     */
    @Deprecated
    public IgniteHadoopIgfsSecondaryFileSystem(String uri) throws IgniteCheckedException {
        this(uri, null, null);
    }

    /**
     * Constructor.
     *
     * @param uri URI of file system.
     * @param cfgPath Additional path to Hadoop configuration.
     * @throws IgniteCheckedException In case of error.
     * @deprecated Use {@link #getFileSystemFactory()} instead.
     */
    @Deprecated
    public IgniteHadoopIgfsSecondaryFileSystem(@Nullable String uri, @Nullable String cfgPath)
        throws IgniteCheckedException {
        this(uri, cfgPath, null);
    }

    /**
     * Constructor.
     *
     * @param uri URI of file system.
     * @param cfgPath Additional path to Hadoop configuration.
     * @param usrName User name.
     * @throws IgniteCheckedException In case of error.
     * @deprecated Use {@link #getFileSystemFactory()} instead.
     */
    @Deprecated
    public IgniteHadoopIgfsSecondaryFileSystem(@Nullable String uri, @Nullable String cfgPath,
        @Nullable String usrName) throws IgniteCheckedException {
        setDefaultUserName(usrName);

        CachingHadoopFileSystemFactory fac = new CachingHadoopFileSystemFactory();

        fac.setUri(uri);

        if (cfgPath != null)
            fac.setConfigPaths(cfgPath);

        setFileSystemFactory(fac);
    }

    /**
     * Gets default user name.
     * <p>
     * Defines user name which will be used during file system invocation in case no user name is defined explicitly
     * through {@link FileSystem#get(URI, Configuration, String)}.
     * <p>
     * Also this name will be used if you manipulate {@link IgniteFileSystem} directly and do not set user name
     * explicitly using {@link IgfsUserContext#doAs(String, IgniteOutClosure)} or
     * {@link IgfsUserContext#doAs(String, Callable)} methods.
     * <p>
     * If not set value of system property {@code "user.name"} will be used. If this property is not set either,
     * {@code "anonymous"} will be used.
     *
     * @return Default user name.
     */
    @Nullable public String getDefaultUserName() {<commit_msg>IgniteHadoopIgfsSecondaryFileSystem.usrName field is renamed to "userName" to preserve backward compatibility.<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.ignite.hadoop.fs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.ParentNotDirectoryException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathExistsException;
import org.apache.hadoop.fs.PathIsNotEmptyDirectoryException;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteFileSystem;
import org.apache.ignite.igfs.IgfsDirectoryNotEmptyException;
import org.apache.ignite.igfs.IgfsException;
import org.apache.ignite.igfs.IgfsFile;
import org.apache.ignite.igfs.IgfsParentNotDirectoryException;
import org.apache.ignite.igfs.IgfsPath;
import org.apache.ignite.igfs.IgfsPathAlreadyExistsException;
import org.apache.ignite.igfs.IgfsPathNotFoundException;
import org.apache.ignite.igfs.IgfsUserContext;
import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystem;
import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystemPositionedReadable;
import org.apache.ignite.internal.processors.hadoop.HadoopPayloadAware;
import org.apache.ignite.internal.processors.hadoop.igfs.HadoopIgfsProperties;
import org.apache.ignite.internal.processors.hadoop.igfs.HadoopIgfsSecondaryFileSystemPositionedReadable;
import org.apache.ignite.internal.processors.igfs.IgfsFileImpl;
import org.apache.ignite.internal.processors.igfs.IgfsFileInfo;
import org.apache.ignite.internal.processors.igfs.IgfsUtils;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgniteOutClosure;
import org.apache.ignite.lifecycle.LifecycleAware;
import org.jetbrains.annotations.Nullable;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.Callable;

import static org.apache.ignite.internal.processors.igfs.IgfsEx.PROP_GROUP_NAME;
import static org.apache.ignite.internal.processors.igfs.IgfsEx.PROP_PERMISSION;
import static org.apache.ignite.internal.processors.igfs.IgfsEx.PROP_USER_NAME;

/**
 * Secondary file system which delegates calls to an instance of Hadoop {@link FileSystem}.
 * <p>
 * Target {@code FileSystem}'s are created on per-user basis using passed {@link HadoopFileSystemFactory}.
 */
public class IgniteHadoopIgfsSecondaryFileSystem implements IgfsSecondaryFileSystem, LifecycleAware,
    HadoopPayloadAware {
    /** The default user name. It is used if no user context is set. */
    private String dfltUsrName;

    /** Factory. */
    private HadoopFileSystemFactory fsFactory;

    /**
     * Default constructor for Spring.
     */
    public IgniteHadoopIgfsSecondaryFileSystem() {
        // No-op.
    }

    /**
     * Simple constructor that is to be used by default.
     *
     * @param uri URI of file system.
     * @throws IgniteCheckedException In case of error.
     * @deprecated Use {@link #getFileSystemFactory()} instead.
     */
    @Deprecated
    public IgniteHadoopIgfsSecondaryFileSystem(String uri) throws IgniteCheckedException {
        this(uri, null, null);
    }

    /**
     * Constructor.
     *
     * @param uri URI of file system.
     * @param cfgPath Additional path to Hadoop configuration.
     * @throws IgniteCheckedException In case of error.
     * @deprecated Use {@link #getFileSystemFactory()} instead.
     */
    @Deprecated
    public IgniteHadoopIgfsSecondaryFileSystem(@Nullable String uri, @Nullable String cfgPath)
        throws IgniteCheckedException {
        this(uri, cfgPath, null);
    }

    /**
     * Constructor.
     *
     * @param uri URI of file system.
     * @param cfgPath Additional path to Hadoop configuration.
     * @param userName User name.
     * @throws IgniteCheckedException In case of error.
     * @deprecated Use {@link #getFileSystemFactory()} instead.
     */
    @Deprecated
    public IgniteHadoopIgfsSecondaryFileSystem(@Nullable String uri, @Nullable String cfgPath,
        @Nullable String userName) throws IgniteCheckedException {
        setDefaultUserName(userName);

        CachingHadoopFileSystemFactory fac = new CachingHadoopFileSystemFactory();

        fac.setUri(uri);

        if (cfgPath != null)
            fac.setConfigPaths(cfgPath);

        setFileSystemFactory(fac);
    }

    /**
     * Gets default user name.
     * <p>
     * Defines user name which will be used during file system invocation in case no user name is defined explicitly
     * through {@link FileSystem#get(URI, Configuration, String)}.
     * <p>
     * Also this name will be used if you manipulate {@link IgniteFileSystem} directly and do not set user name
     * explicitly using {@link IgfsUserContext#doAs(String, IgniteOutClosure)} or
     * {@link IgfsUserContext#doAs(String, Callable)} methods.
     * <p>
     * If not set value of system property {@code "user.name"} will be used. If this property is not set either,
     * {@code "anonymous"} will be used.
     *
     * @return Default user name.
     */
    @Nullable public String getDefaultUserName() {
{'fraction_non_alphanumeric': 0.08797127468581688, 'fraction_numerical': 0.0006528480496164518, 'mean_word_length': 4.018427518427519, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4269334', 'n_tokens_mistral': 3585, 'n_tokens_neox': 3439, 'n_words': 971}