/** * Create a {@link SystemDatasetInstantiator} using the system classloader as the parent classloader. * * @return a {@link SystemDatasetInstantiator} using the system classloader as the parent classloader */ public SystemDatasetInstantiator create() { return create(null); }
new SystemDatasetInstantiatorFactory(locationFactory, dsFramework, cConf);
new SystemDatasetInstantiatorFactory(locationFactory, framework, cConf);
/** * Create a {@link SystemDatasetInstantiator} using the system classloader as the parent classloader. * * @return a {@link SystemDatasetInstantiator} using the system classloader as the parent classloader */ public SystemDatasetInstantiator create() { return create(null); }
/** * Get a {@link SystemDatasetInstantiator} that can instantiate datasets using the given classloader as the * parent classloader for datasets. Must be closed after it is no longer needed, as dataset jars may be unpacked * in order to create classloaders for custom datasets. * * The given parent classloader will be wrapped in a {@link FilterClassLoader} * to prevent CDAP dependencies from leaking through. For example, if a custom dataset has an avro dependency, * the classloader should use the avro from the custom dataset and not from cdap. * * @param parentClassLoader the parent classloader to use when instantiating datasets. If null, the system * classloader will be used * @return a dataset instantiator that can be used to instantiate datasets */ public SystemDatasetInstantiator createDatasetInstantiator(@Nullable ClassLoader parentClassLoader) { parentClassLoader = parentClassLoader == null ? Objects.firstNonNull(Thread.currentThread().getContextClassLoader(), getClass().getClassLoader()) : parentClassLoader; return datasetInstantiatorFactory.create(FilterClassLoader.create(parentClassLoader)); }
/** * Get a {@link SystemDatasetInstantiator} that can instantiate datasets using the given classloader as the * parent classloader for datasets. Must be closed after it is no longer needed, as dataset jars may be unpacked * in order to create classloaders for custom datasets. * * The given parent classloader will be wrapped in a {@link FilterClassLoader} * to prevent CDAP dependencies from leaking through. For example, if a custom dataset has an avro dependency, * the classloader should use the avro from the custom dataset and not from cdap. * * @param parentClassLoader the parent classloader to use when instantiating datasets. If null, the system * classloader will be used * @return a dataset instantiator that can be used to instantiate datasets */ public SystemDatasetInstantiator createDatasetInstantiator(@Nullable ClassLoader parentClassLoader) { parentClassLoader = parentClassLoader == null ? Objects.firstNonNull(Thread.currentThread().getContextClassLoader(), getClass().getClassLoader()) : parentClassLoader; return datasetInstantiatorFactory.create(FilterClassLoader.create(parentClassLoader)); }
private String generateEnableStatement(DatasetId datasetId, DatasetSpecification spec, boolean truncating) throws UnsupportedTypeException, ExploreException { try (SystemDatasetInstantiator datasetInstantiator = datasetInstantiatorFactory.create()) { Dataset dataset = datasetInstantiator.getDataset(datasetId); try { return generateEnableStatement(dataset, spec, datasetId, tableNaming.getTableName(datasetId, spec.getProperties()), truncating); } finally { Closeables.closeQuietly(dataset); } } catch (IOException e) { throw new ExploreException("Exception while trying to instantiate dataset " + datasetId, e); } }
private String generateEnableStatement(DatasetId datasetId, DatasetSpecification spec, boolean truncating) throws UnsupportedTypeException, ExploreException { try (SystemDatasetInstantiator datasetInstantiator = datasetInstantiatorFactory.create()) { Dataset dataset = datasetInstantiator.getDataset(datasetId); try { return generateEnableStatement(dataset, spec, datasetId, tableNaming.getTableName(datasetId, spec.getProperties()), truncating); } finally { Closeables.closeQuietly(dataset); } } catch (IOException e) { throw new ExploreException("Exception while trying to instantiate dataset " + datasetId, e); } }
private <T> T performDatasetAdmin(final DatasetId datasetInstanceId, Operation<T> operation) throws Exception { try (SystemDatasetInstantiator datasetInstantiator = datasetInstantiatorFactory.create()) { DatasetAdmin admin = impersonator.doAs(datasetInstanceId, (Callable<DatasetAdmin>) () -> { DatasetAdmin admin1 = datasetInstantiator.getDatasetAdmin(datasetInstanceId); if (admin1 == null) { throw new NotFoundException("Couldn't obtain DatasetAdmin for dataset instance " + datasetInstanceId); } // returns a DatasetAdmin that executes operations as a particular user, for a particular namespace return new ImpersonatingDatasetAdmin(admin1, impersonator, datasetInstanceId); }); try { return operation.perform(admin); } finally { Closeables.closeQuietly(admin); } } }
private <T> T performDatasetAdmin(final DatasetId datasetInstanceId, Operation<T> operation) throws Exception { try (SystemDatasetInstantiator datasetInstantiator = datasetInstantiatorFactory.create()) { DatasetAdmin admin = impersonator.doAs(datasetInstanceId, (Callable<DatasetAdmin>) () -> { DatasetAdmin admin1 = datasetInstantiator.getDatasetAdmin(datasetInstanceId); if (admin1 == null) { throw new NotFoundException("Couldn't obtain DatasetAdmin for dataset instance " + datasetInstanceId); } // returns a DatasetAdmin that executes operations as a particular user, for a particular namespace return new ImpersonatingDatasetAdmin(admin1, impersonator, datasetInstanceId); }); try { return operation.perform(admin); } finally { Closeables.closeQuietly(admin); } } }
private void doPartitionOperation(FullHttpRequest request, HttpResponder responder, DatasetId datasetId, PartitionOperation partitionOperation) { try (SystemDatasetInstantiator datasetInstantiator = datasetInstantiatorFactory.create()) { Dataset dataset; try {
private void doPartitionOperation(FullHttpRequest request, HttpResponder responder, DatasetId datasetId, PartitionOperation partitionOperation) { try (SystemDatasetInstantiator datasetInstantiator = datasetInstantiatorFactory.create()) { Dataset dataset; try {
try (SystemDatasetInstantiator datasetInstantiator = datasetInstantiatorFactory.create()) { Dataset dataset = datasetInstantiator.getDataset(datasetId); try {
try (SystemDatasetInstantiator datasetInstantiator = datasetInstantiatorFactory.create()) { Dataset dataset = datasetInstantiator.getDataset(datasetId); try {
private String generateDisableStatement(DatasetId datasetId, DatasetSpecification spec) throws ExploreException { String tableName = tableNaming.getTableName(datasetId, spec.getProperties()); String databaseName = ExploreProperties.getExploreDatabaseName(spec.getProperties()); // If table does not exist, nothing to be done try { exploreService.getTableInfo(datasetId.getNamespace(), databaseName, tableName); } catch (TableNotFoundException e) { // Ignore exception, since this means table was not found. return null; } try (SystemDatasetInstantiator datasetInstantiator = datasetInstantiatorFactory.create()) { Dataset dataset = datasetInstantiator.getDataset(datasetId); try { if (dataset instanceof FileSet || dataset instanceof PartitionedFileSet) { // do not drop the explore table that dataset is reusing an existing table if (FileSetProperties.isUseExisting(spec.getProperties())) { return null; } } return generateDeleteStatement(dataset, databaseName, tableName); } finally { Closeables.closeQuietly(dataset); } } catch (IOException e) { LOG.error("Exception creating dataset classLoaderProvider for dataset {}.", datasetId, e); throw new ExploreException("Exception instantiating dataset " + datasetId); } }
private String generateDisableStatement(DatasetId datasetId, DatasetSpecification spec) throws ExploreException { String tableName = tableNaming.getTableName(datasetId, spec.getProperties()); String databaseName = ExploreProperties.getExploreDatabaseName(spec.getProperties()); // If table does not exist, nothing to be done try { exploreService.getTableInfo(datasetId.getNamespace(), databaseName, tableName); } catch (TableNotFoundException e) { // Ignore exception, since this means table was not found. return null; } try (SystemDatasetInstantiator datasetInstantiator = datasetInstantiatorFactory.create()) { Dataset dataset = datasetInstantiator.getDataset(datasetId); try { if (dataset instanceof FileSet || dataset instanceof PartitionedFileSet) { // do not drop the explore table that dataset is reusing an existing table if (FileSetProperties.isUseExisting(spec.getProperties())) { return null; } } return generateDeleteStatement(dataset, databaseName, tableName); } finally { Closeables.closeQuietly(dataset); } } catch (IOException e) { LOG.error("Exception creating dataset classLoaderProvider for dataset {}.", datasetId, e); throw new ExploreException("Exception instantiating dataset " + datasetId); } }