Search in sources :

Example 1 with FilePath

use of com.alibaba.alink.common.io.filesystem.FilePath in project Alink by alibaba.

the class HiveClassLoaderFactory method doAs.

@Override
public <T> T doAs(PrivilegedExceptionAction<T> action) throws Exception {
    ClassLoader classLoader = create();
    try (TemporaryClassLoaderContext context = TemporaryClassLoaderContext.of(classLoader)) {
        if (actionContext.get(HiveCatalogParams.KERBEROS_PRINCIPAL) == null || actionContext.get(HiveCatalogParams.KERBEROS_KEYTAB) == null) {
            return action.run();
        }
        if (internal == null) {
            String kerberosPrincipal = actionContext.get(HiveCatalogParams.KERBEROS_PRINCIPAL);
            FilePath filePath = FilePath.deserialize(actionContext.get(HiveCatalogParams.KERBEROS_KEYTAB));
            String kerberosKeytab;
            kerberosKeytab = new Path(HiveCatalog.downloadFolder(new FilePath(filePath.getPath().getParent(), filePath.getFileSystem()), filePath.getPath().getName()), filePath.getPath().getName()).toString();
            internal = createDoAs(kerberosPrincipal, kerberosKeytab, create());
        }
        return (T) internal.map((PrivilegedExceptionAction<Object>) action);
    }
}
Also used : FilePath(com.alibaba.alink.common.io.filesystem.FilePath) Path(org.apache.flink.core.fs.Path) FilePath(com.alibaba.alink.common.io.filesystem.FilePath) TemporaryClassLoaderContext(com.alibaba.alink.common.io.plugin.TemporaryClassLoaderContext) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 2 with FilePath

use of com.alibaba.alink.common.io.filesystem.FilePath in project Alink by alibaba.

the class Chap03 method c_2_3_1.

static void c_2_3_1() throws Exception {
    HadoopFileSystem hdfs = new HadoopFileSystem(HADOOP_VERSION, HDFS_URI);
    OssFileSystem oss = new OssFileSystem(OSS_VERSION, OSS_END_POINT, OSS_BUCKET_NAME, OSS_ACCESS_ID, OSS_ACCESS_KEY);
    FilePath[] filePaths = new FilePath[] { new FilePath(LOCAL_DIR + "iris.ak"), new FilePath(HDFS_URI + "user/yangxu/alink/data/temp/iris.ak", hdfs), new FilePath(OSS_PREFIX_URI + "alink/data/temp/iris.ak", oss) };
    for (FilePath filePath : filePaths) {
        new CsvSourceBatchOp().setFilePath(IRIS_HTTP_URL).setSchemaStr(IRIS_SCHEMA_STR).link(new AkSinkBatchOp().setFilePath(filePath).setOverwriteSink(true));
        BatchOperator.execute();
        System.out.println(new AkSourceBatchOp().setFilePath(filePath).count());
    }
    for (FilePath filePath : filePaths) {
        new CsvSourceStreamOp().setFilePath(IRIS_HTTP_URL).setSchemaStr(IRIS_SCHEMA_STR).link(new AkSinkStreamOp().setFilePath(filePath).setOverwriteSink(true));
        StreamOperator.execute();
        new AkSourceStreamOp().setFilePath(filePath).filter("sepal_length < 4.5").print();
        StreamOperator.execute();
    }
}
Also used : FilePath(com.alibaba.alink.common.io.filesystem.FilePath) AkSinkStreamOp(com.alibaba.alink.operator.stream.sink.AkSinkStreamOp) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) AkSourceStreamOp(com.alibaba.alink.operator.stream.source.AkSourceStreamOp) AkSinkBatchOp(com.alibaba.alink.operator.batch.sink.AkSinkBatchOp) HadoopFileSystem(com.alibaba.alink.common.io.filesystem.HadoopFileSystem) CsvSourceStreamOp(com.alibaba.alink.operator.stream.source.CsvSourceStreamOp) OssFileSystem(com.alibaba.alink.common.io.filesystem.OssFileSystem) CsvSourceBatchOp(com.alibaba.alink.operator.batch.source.CsvSourceBatchOp)

Example 3 with FilePath

use of com.alibaba.alink.common.io.filesystem.FilePath in project Alink by alibaba.

the class HiveCatalog method fileExists.

public static boolean fileExists(FilePath folder, String file) throws IOException {
    // local
    if (folder.getFileSystem() instanceof LocalFileSystem) {
        return folder.getFileSystem().exists(new Path(folder.getPath(), file));
    }
    String scheme = folder.getPath().toUri().getScheme();
    if (scheme != null && (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"))) {
        try (HttpFileSplitReader reader = new HttpFileSplitReader(folder.getPathStr() + "/" + file)) {
            long fileLen = reader.getFileLength();
            reader.open(null, 0, fileLen);
        } catch (FileNotFoundException exception) {
            return false;
        }
        return true;
    } else {
        return folder.getFileSystem().exists(new Path(folder.getPath(), file));
    }
}
Also used : Path(org.apache.flink.core.fs.Path) ObjectPath(org.apache.flink.table.catalog.ObjectPath) FilePath(com.alibaba.alink.common.io.filesystem.FilePath) LocalFileSystem(com.alibaba.alink.common.io.filesystem.LocalFileSystem) FileNotFoundException(java.io.FileNotFoundException) HttpFileSplitReader(com.alibaba.alink.operator.common.io.reader.HttpFileSplitReader)

Example 4 with FilePath

use of com.alibaba.alink.common.io.filesystem.FilePath in project Alink by alibaba.

the class PluginDownloader method downloadPlugin.

public void downloadPlugin(String pluginName, String pluginVersion) throws IOException {
    loadPluginConfig();
    String pluginFolder = pluginName + "-" + pluginVersion;
    if (jarsPluginConfigs.containsKey(pluginName)) {
        List<String> jars = getListOfJars(pluginName, pluginVersion);
        FilePath remotePath = new FilePath(new Path(getRemoteFlinkRoot().getPath(), pluginFolder), getRemoteFlinkRoot().getFileSystem());
        Path localPath = new Path(getLocalFlinkRoot(), pluginFolder);
        for (String jar : jars) {
            download(new FilePath(new Path(remotePath.getPath(), jar), remotePath.getFileSystem()), new Path(localPath, jar).getPath());
        }
    } else if (resourcePluginConfigs.containsKey(pluginName)) {
        List<String> resources = getListOfResource(pluginName, pluginVersion);
        FilePath remotePath = new FilePath(new Path(getRemoteResourceRoot().getPath(), pluginFolder), getRemoteResourceRoot().getFileSystem());
        Path localPath = new Path(getLocalResourceRoot(), pluginFolder);
        for (String resource : resources) {
            download(new FilePath(new Path(remotePath.getPath(), resource), remotePath.getFileSystem()), new Path(localPath, resource).getPath());
        }
    } else {
        throw new IllegalArgumentException("plugin [" + pluginName + "] not found!");
    }
}
Also used : FilePath(com.alibaba.alink.common.io.filesystem.FilePath) Path(org.apache.flink.core.fs.Path) FilePath(com.alibaba.alink.common.io.filesystem.FilePath) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with FilePath

use of com.alibaba.alink.common.io.filesystem.FilePath in project Alink by alibaba.

the class PluginDownloader method loadPluginConfig.

private static String loadPluginConfig(String configFileName, FilePath remotePath, String localPath, boolean force) throws IOException {
    final FilePath remoteFilePath = new FilePath(new Path(remotePath.getPath(), configFileName), remotePath.getFileSystem());
    downloadFileLocked(localPath, configFileName, (rawPath, path) -> {
        File rawFile = new File(rawPath.getPath());
        if (force || !rawFile.exists()) {
            download(remoteFilePath, path.getPath());
            if (force) {
                rawFile.delete();
            }
            if (!new File(path.getPath()).renameTo(new File(rawPath.getPath()))) {
                throw new DistributePluginException(String.format("Commit file: %s fail.", path.getPath()));
            }
        }
    });
    return Files.toString(new File(new Path(localPath, configFileName).getPath()), StandardCharsets.UTF_8);
}
Also used : FilePath(com.alibaba.alink.common.io.filesystem.FilePath) Path(org.apache.flink.core.fs.Path) FilePath(com.alibaba.alink.common.io.filesystem.FilePath) DistributePluginException(com.alibaba.alink.common.exceptions.DistributePluginException) File(java.io.File)

Aggregations

FilePath (com.alibaba.alink.common.io.filesystem.FilePath)36 Path (org.apache.flink.core.fs.Path)22 IOException (java.io.IOException)9 Test (org.junit.Test)9 Row (org.apache.flink.types.Row)8 File (java.io.File)7 TableSchema (org.apache.flink.table.api.TableSchema)6 AkSinkStreamOp (com.alibaba.alink.operator.stream.sink.AkSinkStreamOp)5 AppendIdBatchOp (com.alibaba.alink.operator.batch.dataproc.AppendIdBatchOp)4 CsvSourceBatchOp (com.alibaba.alink.operator.batch.source.CsvSourceBatchOp)4 RandomTableSourceBatchOp (com.alibaba.alink.operator.batch.source.RandomTableSourceBatchOp)4 SelectBatchOp (com.alibaba.alink.operator.batch.sql.SelectBatchOp)4 HttpFileSplitReader (com.alibaba.alink.operator.common.io.reader.HttpFileSplitReader)4 AppendIdStreamOp (com.alibaba.alink.operator.stream.dataproc.AppendIdStreamOp)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 HadoopFileSystem (com.alibaba.alink.common.io.filesystem.HadoopFileSystem)3 OssFileSystem (com.alibaba.alink.common.io.filesystem.OssFileSystem)3 RandomTableSourceStreamOp (com.alibaba.alink.operator.stream.source.RandomTableSourceStreamOp)3 SelectStreamOp (com.alibaba.alink.operator.stream.sql.SelectStreamOp)3