Search in sources :

Example 6 with TemporaryClassLoaderContext

use of org.apache.flink.util.TemporaryClassLoaderContext in project flink by apache.

the class SourceCoordinator method resetToCheckpoint.

@Override
public void resetToCheckpoint(final long checkpointId, @Nullable final byte[] checkpointData) throws Exception {
    checkState(!started, "The coordinator can only be reset if it was not yet started");
    assert enumerator == null;
    // when "start()" is called.
    if (checkpointData == null) {
        return;
    }
    LOG.info("Restoring SplitEnumerator of source {} from checkpoint.", operatorName);
    final ClassLoader userCodeClassLoader = context.getCoordinatorContext().getUserCodeClassloader();
    try (TemporaryClassLoaderContext ignored = TemporaryClassLoaderContext.of(userCodeClassLoader)) {
        final EnumChkT enumeratorCheckpoint = deserializeCheckpoint(checkpointData);
        enumerator = source.restoreEnumerator(context, enumeratorCheckpoint);
    }
}
Also used : TemporaryClassLoaderContext(org.apache.flink.util.TemporaryClassLoaderContext)

Example 7 with TemporaryClassLoaderContext

use of org.apache.flink.util.TemporaryClassLoaderContext in project flink by apache.

the class CatalogITCase method testCreateLegacyCatalogFromUserClassLoader.

@Test
public void testCreateLegacyCatalogFromUserClassLoader() throws Exception {
    final String className = "UserCatalogFactory";
    URLClassLoader classLoader = ClassLoaderUtils.withRoot(temporaryFolder.newFolder()).addResource("META-INF/services/org.apache.flink.table.factories.TableFactory", "UserCatalogFactory").addClass(className, "import org.apache.flink.table.catalog.GenericInMemoryCatalog;\n" + "import org.apache.flink.table.factories.CatalogFactory;\n" + "import java.util.Collections;\n" + "import org.apache.flink.table.catalog.Catalog;\n" + "import java.util.HashMap;\n" + "import java.util.List;\n" + "import java.util.Map;\n" + "\tpublic class UserCatalogFactory implements CatalogFactory {\n" + "\t\t@Override\n" + "\t\tpublic Catalog createCatalog(\n" + "\t\t\t\tString name,\n" + "\t\t\t\tMap<String, String> properties) {\n" + "\t\t\treturn new GenericInMemoryCatalog(name);\n" + "\t\t}\n" + "\n" + "\t\t@Override\n" + "\t\tpublic Map<String, String> requiredContext() {\n" + "\t\t\tHashMap<String, String> hashMap = new HashMap<>();\n" + "\t\t\thashMap.put(\"type\", \"userCatalog\");\n" + "\t\t\treturn hashMap;\n" + "\t\t}\n" + "\n" + "\t\t@Override\n" + "\t\tpublic List<String> supportedProperties() {\n" + "\t\t\treturn Collections.emptyList();\n" + "\t\t}\n" + "\t}").build();
    try (TemporaryClassLoaderContext context = TemporaryClassLoaderContext.of(classLoader)) {
        TableEnvironment tableEnvironment = getTableEnvironment();
        tableEnvironment.executeSql("CREATE CATALOG cat WITH ('type'='userCatalog')");
        assertTrue(tableEnvironment.getCatalog("cat").isPresent());
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) TemporaryClassLoaderContext(org.apache.flink.util.TemporaryClassLoaderContext) TableEnvironment(org.apache.flink.table.api.TableEnvironment) StreamTableEnvironment(org.apache.flink.table.api.bridge.java.StreamTableEnvironment) Test(org.junit.Test)

Aggregations

TemporaryClassLoaderContext (org.apache.flink.util.TemporaryClassLoaderContext)7 URLClassLoader (java.net.URLClassLoader)2 TableEnvironment (org.apache.flink.table.api.TableEnvironment)2 StreamTableEnvironment (org.apache.flink.table.api.bridge.java.StreamTableEnvironment)2 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Collection (java.util.Collection)1 Properties (java.util.Properties)1 Internal (org.apache.flink.annotation.Internal)1 Configuration (org.apache.flink.configuration.Configuration)1 LocalFileSystem (org.apache.flink.core.fs.local.LocalFileSystem)1 LocalFileSystemFactory (org.apache.flink.core.fs.local.LocalFileSystemFactory)1 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)1