Search in sources :

Example 1 with PythonDependencyInfo

use of org.apache.flink.python.env.PythonDependencyInfo in project flink by apache.

the class ProcessPythonEnvironmentManagerTest method testRequirements.

@Test
public void testRequirements() throws Exception {
    PythonDependencyInfo dependencyInfo = new PythonDependencyInfo(new HashMap<>(), String.join(File.separator, tmpDir, "file0"), String.join(File.separator, tmpDir, "dir0"), new HashMap<>(), "python");
    try (ProcessPythonEnvironmentManager environmentManager = createBasicPythonEnvironmentManager(dependencyInfo)) {
        File baseDirectory = new File(tmpDir, "python-dist-" + UUID.randomUUID().toString());
        if (!baseDirectory.mkdirs()) {
            throw new IOException("Could not find a unique directory name in '" + tmpDir + "' for storing the generated files of python dependency.");
        }
        String tmpBase = baseDirectory.getAbsolutePath();
        Map<String, String> environmentVariable = environmentManager.constructEnvironmentVariables(tmpBase);
        Map<String, String> expected = new HashMap<>();
        expected.put("python", "python");
        expected.put("BOOT_LOG_DIR", tmpBase);
        expected.put(PYFLINK_GATEWAY_DISABLED, "true");
        expected.put(PYTHON_REQUIREMENTS_FILE, String.join(File.separator, tmpDir, "file0"));
        expected.put(PYTHON_REQUIREMENTS_CACHE, String.join(File.separator, tmpDir, "dir0"));
        expected.put(PYTHON_REQUIREMENTS_INSTALL_DIR, String.join(File.separator, tmpBase, PYTHON_REQUIREMENTS_DIR));
        assertEquals(expected, environmentVariable);
    }
}
Also used : PythonDependencyInfo(org.apache.flink.python.env.PythonDependencyInfo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 2 with PythonDependencyInfo

use of org.apache.flink.python.env.PythonDependencyInfo in project flink by apache.

the class ProcessPythonEnvironmentManagerTest method testSetLogDirectory.

@Test
public void testSetLogDirectory() throws Exception {
    PythonDependencyInfo dependencyInfo = new PythonDependencyInfo(new HashMap<>(), null, null, new HashMap<>(), "python");
    try (ProcessPythonEnvironmentManager environmentManager = new ProcessPythonEnvironmentManager(dependencyInfo, new String[] { tmpDir }, new HashMap<>(), new JobID())) {
        environmentManager.open();
        Map<String, String> env = environmentManager.constructEnvironmentVariables(environmentManager.getBaseDirectory());
        Map<String, String> expected = getBasicExpectedEnv(environmentManager);
        expected.put("BOOT_LOG_DIR", environmentManager.getBaseDirectory());
        assertEquals(expected, env);
    }
}
Also used : PythonDependencyInfo(org.apache.flink.python.env.PythonDependencyInfo) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 3 with PythonDependencyInfo

use of org.apache.flink.python.env.PythonDependencyInfo in project flink by apache.

the class ProcessPythonEnvironmentManagerTest method testPythonExecutable.

@Test
public void testPythonExecutable() throws Exception {
    PythonDependencyInfo dependencyInfo = new PythonDependencyInfo(new HashMap<>(), null, null, new HashMap<>(), "/usr/local/bin/python");
    try (ProcessPythonEnvironmentManager environmentManager = createBasicPythonEnvironmentManager(dependencyInfo)) {
        environmentManager.open();
        Map<String, String> environmentVariable = environmentManager.getPythonEnv();
        Map<String, String> expected = getBasicExpectedEnv(environmentManager);
        expected.put("python", "/usr/local/bin/python");
        assertEquals(expected, environmentVariable);
    }
}
Also used : PythonDependencyInfo(org.apache.flink.python.env.PythonDependencyInfo) Test(org.junit.Test)

Example 4 with PythonDependencyInfo

use of org.apache.flink.python.env.PythonDependencyInfo in project flink by apache.

the class PythonTestUtils method createTestProcessEnvironmentManager.

public static ProcessPythonEnvironmentManager createTestProcessEnvironmentManager() {
    Map<String, String> env = new HashMap<>();
    env.put(PythonEnvironmentManagerUtils.PYFLINK_UDF_RUNNER_DIR, "");
    return new ProcessPythonEnvironmentManager(new PythonDependencyInfo(new HashMap<>(), null, null, new HashMap<>(), "python"), new String[] { System.getProperty("java.io.tmpdir") }, env, new JobID());
}
Also used : ProcessPythonEnvironmentManager(org.apache.flink.python.env.process.ProcessPythonEnvironmentManager) PythonDependencyInfo(org.apache.flink.python.env.PythonDependencyInfo) HashMap(java.util.HashMap) JobID(org.apache.flink.api.common.JobID)

Example 5 with PythonDependencyInfo

use of org.apache.flink.python.env.PythonDependencyInfo in project flink by apache.

the class ProcessPythonEnvironmentManagerTest method testArchives.

@Test
public void testArchives() throws Exception {
    // use LinkedHashMap to preserve the file order in python working directory
    Map<String, String> archives = new LinkedHashMap<>();
    archives.put(String.join(File.separator, tmpDir, "zip0"), "py27.zip");
    archives.put(String.join(File.separator, tmpDir, "zip1"), "py37");
    PythonDependencyInfo dependencyInfo = new PythonDependencyInfo(new HashMap<>(), null, null, archives, "python");
    try (ProcessPythonEnvironmentManager environmentManager = createBasicPythonEnvironmentManager(dependencyInfo)) {
        environmentManager.open();
        String tmpBase = environmentManager.getBaseDirectory();
        Map<String, String> environmentVariable = environmentManager.getPythonEnv();
        Map<String, String> expected = getBasicExpectedEnv(environmentManager);
        expected.put(PYTHON_WORKING_DIR, String.join(File.separator, tmpBase, PYTHON_ARCHIVES_DIR));
        assertEquals(expected, environmentVariable);
        assertFileEquals(new File(String.join(File.separator, tmpDir, "zipExpected0")), new File(String.join(File.separator, tmpBase, PYTHON_ARCHIVES_DIR, "py27.zip")), true);
        assertFileEquals(new File(String.join(File.separator, tmpDir, "zipExpected1")), new File(String.join(File.separator, tmpBase, PYTHON_ARCHIVES_DIR, "py37")), true);
    }
}
Also used : PythonDependencyInfo(org.apache.flink.python.env.PythonDependencyInfo) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

PythonDependencyInfo (org.apache.flink.python.env.PythonDependencyInfo)9 Test (org.junit.Test)7 File (java.io.File)5 LinkedHashMap (java.util.LinkedHashMap)4 HashMap (java.util.HashMap)3 JobID (org.apache.flink.api.common.JobID)3 ProcessPythonEnvironmentManager (org.apache.flink.python.env.process.ProcessPythonEnvironmentManager)2 DataInputStream (java.io.DataInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 PythonEnv (org.apache.flink.table.functions.python.PythonEnv)1