Java Code Examples for org.apache.kylin.common.util.ClassUtil#forName()

The following examples show how to use org.apache.kylin.common.util.ClassUtil#forName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceStore.java    From kylin with Apache License 2.0 6 votes vote down vote up
private static ResourceStore createResourceStore(KylinConfig kylinConfig) {
    StorageURL metadataUrl = kylinConfig.getMetadataUrl();
    logger.info("Using metadata url {} for resource store", metadataUrl);
    String clsName = kylinConfig.getResourceStoreImpls().get(metadataUrl.getScheme());
    try {
        Class<? extends ResourceStore> cls = ClassUtil.forName(clsName, ResourceStore.class);
        ResourceStore store = cls.getConstructor(KylinConfig.class).newInstance(kylinConfig);
        if (!store.exists(METASTORE_UUID_TAG)) {
            store.checkAndPutResource(METASTORE_UUID_TAG, new StringEntity(store.createMetaStoreUUID()), 0,
                    StringEntity.serializer);
        }
        return store;
    } catch (Throwable e) {
        throw new IllegalArgumentException("Failed to find metadata store by url: " + metadataUrl, e);
    }
}
 
Example 2
Source File: ExecutableManager.java    From Kylin with Apache License 2.0 6 votes vote down vote up
private static AbstractExecutable parseTo(ExecutablePO executablePO) {
    if (executablePO == null) {
        return null;
    }
    String type = executablePO.getType();
    try {
        Class<? extends AbstractExecutable> clazz = ClassUtil.forName(type, AbstractExecutable.class);
        Constructor<? extends AbstractExecutable> constructor = clazz.getConstructor();
        AbstractExecutable result = constructor.newInstance();
        result.setId(executablePO.getUuid());
        result.setName(executablePO.getName());
        result.setParams(executablePO.getParams());
        List<ExecutablePO> tasks = executablePO.getTasks();
        if (tasks != null && !tasks.isEmpty()) {
            Preconditions.checkArgument(result instanceof DefaultChainedExecutable);
            for (ExecutablePO subTask: tasks) {
                ((DefaultChainedExecutable) result).addTask(parseTo(subTask));
            }
        }
        return result;
    } catch (ReflectiveOperationException e) {
        throw new IllegalArgumentException("cannot parse this job:" + executablePO.getId(), e);
    }
}
 
Example 3
Source File: RealizationRegistry.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void init() {
    providers = Maps.newConcurrentMap();

    // use reflection to load providers
    String[] providerNames = config.getRealizationProviders();
    for (String clsName : providerNames) {
        try {
            Class<? extends IRealizationProvider> cls = ClassUtil.forName(clsName, IRealizationProvider.class);
            IRealizationProvider p = (IRealizationProvider) cls.getMethod("getInstance", KylinConfig.class).invoke(null, config);
            providers.put(p.getRealizationType(), p);

        } catch (Exception | NoClassDefFoundError e) {
            if (e instanceof ClassNotFoundException || e instanceof NoClassDefFoundError)
                logger.warn("Failed to create realization provider " + e);
            else
                logger.error("Failed to create realization provider", e);
        }
    }

    if (providers.isEmpty())
        throw new IllegalArgumentException("Failed to find realization provider by url: " + config.getMetadataUrl());

    logger.info("RealizationRegistry is " + providers);
}
 
Example 4
Source File: RemoveBlackoutRealizationsRule.java    From kylin with Apache License 2.0 6 votes vote down vote up
private static IRealizationFilter getFilterImpl(KylinConfig conf) {
    IRealizationFilter filter = filters.get(conf);
    if (filter == null) {
        synchronized (RemoveBlackoutRealizationsRule.class) {
            try {
                Class<? extends IRealizationFilter> clz = ClassUtil.forName(conf.getQueryRealizationFilter(),
                        IRealizationFilter.class);
                filter = clz.getConstructor(KylinConfig.class).newInstance(conf);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            filters.put(conf, filter);
        }
    }
    return filter;
}
 
Example 5
Source File: ResourceStore.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private static ResourceStore createResourceStore(KylinConfig kylinConfig) {
    StorageURL metadataUrl = kylinConfig.getMetadataUrl();
    logger.info("Using metadata url {} for resource store", metadataUrl);
    String clsName = kylinConfig.getResourceStoreImpls().get(metadataUrl.getScheme());
    try {
        Class<? extends ResourceStore> cls = ClassUtil.forName(clsName, ResourceStore.class);
        ResourceStore store = cls.getConstructor(KylinConfig.class).newInstance(kylinConfig);
        if (!store.exists(METASTORE_UUID_TAG)) {
            store.checkAndPutResource(METASTORE_UUID_TAG, new StringEntity(store.createMetaStoreUUID()), 0,
                    StringEntity.serializer);
        }
        return store;
    } catch (Throwable e) {
        throw new IllegalArgumentException("Failed to find metadata store by url: " + metadataUrl, e);
    }
}
 
Example 6
Source File: RealizationRegistry.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void init() {
    providers = Maps.newConcurrentMap();

    // use reflection to load providers
    String[] providerNames = config.getRealizationProviders();
    for (String clsName : providerNames) {
        try {
            Class<? extends IRealizationProvider> cls = ClassUtil.forName(clsName, IRealizationProvider.class);
            IRealizationProvider p = (IRealizationProvider) cls.getMethod("getInstance", KylinConfig.class).invoke(null, config);
            providers.put(p.getRealizationType(), p);

        } catch (Exception | NoClassDefFoundError e) {
            if (e instanceof ClassNotFoundException || e instanceof NoClassDefFoundError)
                logger.warn("Failed to create realization provider " + e);
            else
                logger.error("Failed to create realization provider", e);
        }
    }

    if (providers.isEmpty())
        throw new IllegalArgumentException("Failed to find realization provider by url: " + config.getMetadataUrl());

    logger.info("RealizationRegistry is " + providers);
}
 
Example 7
Source File: RemoveBlackoutRealizationsRule.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private static IRealizationFilter getFilterImpl(KylinConfig conf) {
    IRealizationFilter filter = filters.get(conf);
    if (filter == null) {
        synchronized (RemoveBlackoutRealizationsRule.class) {
            try {
                Class<? extends IRealizationFilter> clz = ClassUtil.forName(conf.getQueryRealizationFilter(),
                        IRealizationFilter.class);
                filter = clz.getConstructor(KylinConfig.class).newInstance(conf);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            filters.put(conf, filter);
        }
    }
    return filter;
}
 
Example 8
Source File: DataModelManager.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private Class<DataModelDesc> getDataModelImplClass() {
    try {
        String cls = StringUtil.noBlank(config.getDataModelImpl(), DataModelDesc.class.getName());
        Class<? extends DataModelDesc> clz = ClassUtil.forName(cls, DataModelDesc.class);
        return (Class<DataModelDesc>) clz;
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
Example 9
Source File: ExecutableManager.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private AbstractExecutable newExecutable(String type) {
    Class<? extends AbstractExecutable> clazz;
    try {
        clazz = ClassUtil.forName(type, AbstractExecutable.class);
    } catch (ClassNotFoundException ex) {
        clazz = BrokenExecutable.class;
        logger.error("Unknown executable type '" + type + "', using BrokenExecutable");
    }
    try {
        return clazz.getConstructor().newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Failed to instantiate " + clazz, e);
    }
}
 
Example 10
Source File: CuboidScheduler.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static CuboidScheduler getInstance(CubeDesc cubeDesc) {
    String clzName = cubeDesc.getConfig().getCuboidScheduler();
    try {
        Class<? extends CuboidScheduler> clz = ClassUtil.forName(clzName, CuboidScheduler.class);
        return clz.getConstructor(CubeDesc.class).newInstance(cubeDesc);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 11
Source File: NSparkExecutable.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private ExecuteResult runLocalMode(String appArgs, KylinConfig config) {
    try {
        Class<? extends Object> appClz = ClassUtil.forName(getSparkSubmitClassName(), Object.class);
        appClz.getMethod("main", String[].class).invoke(null, (Object) new String[] { appArgs });
        updateMetaAfterBuilding(config);
        return ExecuteResult.createSucceed();
    } catch (Exception e) {
        return ExecuteResult.createError(e);
    }
}
 
Example 12
Source File: DataModelManager.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
static DataModelManager newInstance(KylinConfig conf) {
    try {
        String cls = StringUtil.noBlank(conf.getDataModelManagerImpl(), DataModelManager.class.getName());
        Class<? extends DataModelManager> clz = ClassUtil.forName(cls, DataModelManager.class);
        return clz.getConstructor(KylinConfig.class).newInstance(conf);
    } catch (Exception e) {
        throw new RuntimeException("Failed to init DataModelManager from " + conf, e);
    }
}
 
Example 13
Source File: Segments.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static ISegmentAdvisor newSegmentAdvisor(ISegment seg) {
    try {
        Class<? extends ISegmentAdvisor> clz = ClassUtil.forName(seg.getConfig().getSegmentAdvisor(),
                ISegmentAdvisor.class);
        return clz.getConstructor(ISegment.class).newInstance(seg);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 14
Source File: Segments.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static ISegmentAdvisor newSegmentAdvisor(ISegment seg) {
    try {
        Class<? extends ISegmentAdvisor> clz = ClassUtil.forName(seg.getConfig().getSegmentAdvisor(),
                ISegmentAdvisor.class);
        return clz.getConstructor(ISegment.class).newInstance(seg);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 15
Source File: DataModelManager.java    From kylin with Apache License 2.0 5 votes vote down vote up
static DataModelManager newInstance(KylinConfig conf) {
    try {
        String cls = StringUtil.noBlank(conf.getDataModelManagerImpl(), DataModelManager.class.getName());
        Class<? extends DataModelManager> clz = ClassUtil.forName(cls, DataModelManager.class);
        return clz.getConstructor(KylinConfig.class).newInstance(conf);
    } catch (Exception e) {
        throw new RuntimeException("Failed to init DataModelManager from " + conf, e);
    }
}
 
Example 16
Source File: DataModelManager.java    From kylin with Apache License 2.0 5 votes vote down vote up
private Class<DataModelDesc> getDataModelImplClass() {
    try {
        String cls = StringUtil.noBlank(config.getDataModelImpl(), DataModelDesc.class.getName());
        Class<? extends DataModelDesc> clz = ClassUtil.forName(cls, DataModelDesc.class);
        return (Class<DataModelDesc>) clz;
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
Example 17
Source File: ExecutableManager.java    From kylin with Apache License 2.0 5 votes vote down vote up
private AbstractExecutable newExecutable(String type) {
    Class<? extends AbstractExecutable> clazz;
    try {
        clazz = ClassUtil.forName(type, AbstractExecutable.class);
    } catch (ClassNotFoundException ex) {
        clazz = BrokenExecutable.class;
        logger.error("Unknown executable type '" + type + "', using BrokenExecutable");
    }
    try {
        return clazz.getConstructor().newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Failed to instantiate " + clazz, e);
    }
}
 
Example 18
Source File: CuboidScheduler.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static CuboidScheduler getInstance(CubeDesc cubeDesc) {
    String clzName = cubeDesc.getConfig().getCuboidScheduler();
    try {
        Class<? extends CuboidScheduler> clz = ClassUtil.forName(clzName, CuboidScheduler.class);
        return clz.getConstructor(CubeDesc.class).newInstance(cubeDesc);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}