@Override protected void setConverterByName(String converterName) throws Exception { converterName = "org.apache.kylin.dict.Number2BytesConverter"; this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).getDeclaredConstructor().newInstance(); }
public static Object newInstance(String clz) { try { return forName(clz, Object.class).getDeclaredConstructor().newInstance(); } catch (Exception e) { throw new RuntimeException(e); } }
protected void setConverterByName(String converterName) throws Exception { this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).getDeclaredConstructor().newInstance(); }
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); } } }
public static Dictionary<?> deserialize(InputStream inputStream) { try { final DataInputStream dataInputStream = new DataInputStream(inputStream); final String type = dataInputStream.readUTF(); final Dictionary<?> dictionary = ClassUtil.forName(type, Dictionary.class).getDeclaredConstructor().newInstance(); dictionary.readFields(dataInputStream); return dictionary; } catch (Exception e) { throw new RuntimeException(e); } }
@Override protected void setConverterByName(String converterName) throws Exception { converterName = "org.apache.kylin.dict.Number2BytesConverter"; this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).getDeclaredConstructor().newInstance(); ((Number2BytesConverter)this.bytesConvert).setMaxDigitsBeforeDecimalPoint(Number2BytesConverter.MAX_DIGITS_BEFORE_DECIMAL_POINT_LEGACY); }
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; }
public static String getZKConnectStringFromHBase() { Configuration hconf = null; try { Class<? extends Object> hbaseConnClz = ClassUtil.forName("org.apache.kylin.storage.hbase.HBaseConnection", Object.class); hconf = (Configuration) hbaseConnClz.getMethod("getCurrentHBaseConfiguration").invoke(null); } catch (Throwable ex) { logger.warn("Failed to get zookeeper connect string from HBase configuration", ex); return null; } final String serverList = hconf.get("hbase.zookeeper.quorum"); final String port = hconf.get("hbase.zookeeper.property.clientPort"); return StringUtils.join(Iterables.transform(Arrays.asList(serverList.split(",")), new Function<String, String>() { @Nullable @Override public String apply(String input) { return input + ":" + port; } }), ","); } }
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); } }
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); } }
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); } }
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); } }
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); }
private ISource createSource(ISourceAware aware) { String sourceClazz = systemConfig.getSourceEngines().get(aware.getSourceType()); try { return ClassUtil.forName(sourceClazz, ISource.class).getDeclaredConstructor(KylinConfig.class) .newInstance(aware.getConfig()); } catch (Throwable e) { logger.error("Failed to create source: SourceType={}", aware.getSourceType(), e); return null; } }
@Override public DictionaryInfo deserialize(DataInputStream in) throws IOException { String json = in.readUTF(); DictionaryInfo obj = JsonUtil.readValue(json, DictionaryInfo.class); if (infoOnly == false) { Dictionary<String> dict; try { dict = (Dictionary<String>) ClassUtil.forName(obj.getDictionaryClass(), Dictionary.class).getDeclaredConstructor().newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } dict.readFields(in); obj.setDictionaryObject(dict); } return obj; }
BytesConverter<T> bytesConverter = null; if (converterName.isEmpty() == false) bytesConverter = ClassUtil.forName(converterName, BytesConverter.class).getDeclaredConstructor().newInstance();
Preconditions.checkNotNull(params); try { final Constructor<? extends AbstractHadoopJob> constructor = ClassUtil.forName(mapReduceJobClass, AbstractHadoopJob.class).getConstructor(); final AbstractHadoopJob job = constructor.newInstance(); String[] args = params.trim().split("\\s+");
private static ResourceStore createResourceStore(KylinConfig kylinConfig) { StorageURL metadataUrl = kylinConfig.getMetadataUrl(); logger.info("Using metadata url " + metadataUrl + " for resource store"); 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); } }
@Override public GlobalDictMetadata readIndexFile(Path dir) throws IOException { Path indexFile = new Path(dir, V1_INDEX_NAME); try (FSDataInputStream in = fs.open(indexFile)) { int baseId = in.readInt(); int maxId = in.readInt(); int maxValueLength = in.readInt(); int nValues = in.readInt(); String converterName = in.readUTF(); BytesConverter converter; try { converter = ClassUtil.forName(converterName, BytesConverter.class).getDeclaredConstructor().newInstance(); } catch (Exception e) { throw new RuntimeException("Fail to instantiate BytesConverter: " + converterName, e); } int nSlices = in.readInt(); TreeMap<AppendDictSliceKey, String> sliceFileMap = new TreeMap<>(); for (int i = 0; i < nSlices; i++) { AppendDictSliceKey key = new AppendDictSliceKey(); key.readFields(in); sliceFileMap.put(key, sliceFileName(key)); } // make sure first key is always "" String firstFile = sliceFileMap.remove(sliceFileMap.firstKey()); sliceFileMap.put(AppendDictSliceKey.START_KEY, firstFile); return new GlobalDictMetadata(baseId, maxId, maxValueLength, nValues, converter, sliceFileMap); } }
@Override public GlobalDictMetadata readIndexFile(Path dir) throws IOException { Path indexFile = new Path(dir, V2_INDEX_NAME); try (FSDataInputStream in = fs.open(indexFile)) { byte minorVersion = in.readByte(); // include a header to allow minor format changes if (minorVersion != MINOR_VERSION_V1) { throw new RuntimeException("Unsupported minor version " + minorVersion); } int baseId = in.readInt(); int maxId = in.readInt(); int maxValueLength = in.readInt(); int nValues = in.readInt(); String converterName = in.readUTF(); BytesConverter converter; try { converter = ClassUtil.forName(converterName, BytesConverter.class).getDeclaredConstructor().newInstance(); } catch (Exception e) { throw new RuntimeException("Fail to instantiate BytesConverter: " + converterName, e); } int nSlices = in.readInt(); TreeMap<AppendDictSliceKey, String> sliceFileMap = new TreeMap<>(); for (int i = 0; i < nSlices; i++) { AppendDictSliceKey key = new AppendDictSliceKey(); key.readFields(in); String sliceFileName = in.readUTF(); sliceFileMap.put(key, sliceFileName); } return new GlobalDictMetadata(baseId, maxId, maxValueLength, nValues, converter, sliceFileMap); } }