use of io.cdap.cdap.spi.data.StructuredTableAdmin in project cdap by caskdata.
the class DatasetServiceTestBase method initializeAndStartService.
protected static void initializeAndStartService(CConfiguration cConf) throws Exception {
// TODO: this whole method is a mess. Streamline it!
injector = Guice.createInjector(new ConfigModule(cConf), RemoteAuthenticatorModules.getNoOpModule(), new InMemoryDiscoveryModule(), new NonCustomLocationUnitTestModule(), new NamespaceAdminTestModule(), new SystemDatasetRuntimeModule().getInMemoryModules(), new TransactionInMemoryModule(), new AuthorizationTestModule(), new StorageModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule(), new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Singleton.class);
bind(DatasetDefinitionRegistryFactory.class).to(DefaultDatasetDefinitionRegistryFactory.class).in(Scopes.SINGLETON);
// through the injector, we only need RemoteDatasetFramework in these tests
bind(RemoteDatasetFramework.class);
bind(OwnerStore.class).to(InMemoryOwnerStore.class);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
}
});
AccessEnforcer authEnforcer = injector.getInstance(AccessEnforcer.class);
AuthenticationContext authenticationContext = injector.getInstance(AuthenticationContext.class);
transactionRunner = injector.getInstance(TransactionRunner.class);
DiscoveryService discoveryService = injector.getInstance(DiscoveryService.class);
discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
dsFramework = injector.getInstance(RemoteDatasetFramework.class);
// Tx Manager to support working with datasets
txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
StructuredTableAdmin structuredTableAdmin = injector.getInstance(StructuredTableAdmin.class);
StoreDefinition.createAllTables(structuredTableAdmin);
TransactionSystemClient txSystemClient = injector.getInstance(TransactionSystemClient.class);
TransactionSystemClientService txSystemClientService = new DelegatingTransactionSystemClientService(txSystemClient);
NamespacePathLocator namespacePathLocator = injector.getInstance(NamespacePathLocator.class);
SystemDatasetInstantiatorFactory datasetInstantiatorFactory = new SystemDatasetInstantiatorFactory(locationFactory, dsFramework, cConf);
// ok to pass null, since the impersonator won't actually be called, if kerberos security is not enabled
Impersonator impersonator = new DefaultImpersonator(cConf, null);
DatasetAdminService datasetAdminService = new DatasetAdminService(dsFramework, cConf, locationFactory, datasetInstantiatorFactory, impersonator);
ImmutableSet<HttpHandler> handlers = ImmutableSet.<HttpHandler>of(new DatasetAdminOpHTTPHandler(datasetAdminService));
MetricsCollectionService metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
opExecutorService = new DatasetOpExecutorService(cConf, SConfiguration.create(), discoveryService, metricsCollectionService, handlers);
opExecutorService.startAndWait();
Map<String, DatasetModule> defaultModules = injector.getInstance(Key.get(new TypeLiteral<Map<String, DatasetModule>>() {
}, Constants.Dataset.Manager.DefaultDatasetModules.class));
ImmutableMap<String, DatasetModule> modules = ImmutableMap.<String, DatasetModule>builder().putAll(defaultModules).build();
registryFactory = injector.getInstance(DatasetDefinitionRegistryFactory.class);
inMemoryDatasetFramework = new InMemoryDatasetFramework(registryFactory, modules);
DiscoveryExploreClient exploreClient = new DiscoveryExploreClient(discoveryServiceClient, authenticationContext);
ExploreFacade exploreFacade = new ExploreFacade(exploreClient, cConf);
namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
namespaceAdmin.create(NamespaceMeta.DEFAULT);
ownerAdmin = injector.getInstance(OwnerAdmin.class);
NamespaceQueryAdmin namespaceQueryAdmin = injector.getInstance(NamespaceQueryAdmin.class);
DatasetTypeManager typeManager = new DatasetTypeManager(cConf, locationFactory, impersonator, transactionRunner);
DatasetOpExecutor opExecutor = new InMemoryDatasetOpExecutor(dsFramework);
DatasetInstanceManager instanceManager = new DatasetInstanceManager(transactionRunner);
DatasetTypeService noAuthTypeService = new DefaultDatasetTypeService(typeManager, namespaceAdmin, namespacePathLocator, cConf, impersonator, txSystemClientService, transactionRunner, defaultModules);
DatasetTypeService typeService = new AuthorizationDatasetTypeService(noAuthTypeService, authEnforcer, authenticationContext);
instanceService = new DatasetInstanceService(typeService, noAuthTypeService, instanceManager, opExecutor, exploreFacade, namespaceQueryAdmin, ownerAdmin, authEnforcer, authenticationContext, new NoOpMetadataServiceClient());
service = new DatasetService(cConf, SConfiguration.create(), discoveryService, discoveryServiceClient, metricsCollectionService, new HashSet<>(), typeService, instanceService);
// Start dataset service, wait for it to be discoverable
service.startAndWait();
waitForService(Constants.Service.DATASET_EXECUTOR);
waitForService(Constants.Service.DATASET_MANAGER);
// this usually happens while creating a namespace, however not doing that in data fabric tests
Locations.mkdirsIfNotExists(namespacePathLocator.get(NamespaceId.DEFAULT));
}
use of io.cdap.cdap.spi.data.StructuredTableAdmin in project cdap by caskdata.
the class SqlProfileServiceTest method setup.
@BeforeClass
public static void setup() throws IOException, TableAlreadyExistsException {
cConf = CConfiguration.create();
// any plugin which requires transaction will be excluded
cConf.set(Constants.REQUIREMENTS_DATASET_TYPE_EXCLUDE, Joiner.on(",").join(Table.TYPE, KeyValueTable.TYPE));
pg = PostgresInstantiator.createAndStart(cConf, TEMP_FOLDER.newFolder());
injector = AppFabricTestHelper.getInjector(cConf);
structuredTableAdmin = injector.getInstance(StructuredTableAdmin.class);
TransactionRunner transactionRunner = injector.getInstance(TransactionRunner.class);
StoreDefinition.createAllTables(structuredTableAdmin);
profileService = new ProfileService(cConf, injector.getInstance(MetricsSystemClient.class), transactionRunner);
defaultStore = new DefaultStore(transactionRunner);
}
use of io.cdap.cdap.spi.data.StructuredTableAdmin in project cdap by caskdata.
the class NoSqlFieldLineageTableTest method beforeClass.
@BeforeClass
public static void beforeClass() throws IOException, TableAlreadyExistsException {
CConfiguration cConf = dsFrameworkUtil.getConfiguration();
cConf.set(Constants.Dataset.DATA_STORAGE_IMPLEMENTATION, Constants.Dataset.DATA_STORAGE_NOSQL);
StructuredTableAdmin structuredTableAdmin = dsFrameworkUtil.getInjector().getInstance(StructuredTableAdmin.class);
transactionRunner = dsFrameworkUtil.getInjector().getInstance(TransactionRunner.class);
StoreDefinition.createAllTables(structuredTableAdmin);
}
use of io.cdap.cdap.spi.data.StructuredTableAdmin in project cdap by caskdata.
the class SystemAppTestBaseTest method testTableOperations.
@Test
public void testTableOperations() throws Exception {
StructuredTableAdmin tableAdmin = getStructuredTableAdmin();
StructuredTableId id = new StructuredTableId("t0");
Assert.assertFalse(tableAdmin.exists(id));
String keyCol = "key";
String valCol = "val";
tableAdmin.create(new StructuredTableSpecification.Builder().withId(id).withFields(new FieldType(keyCol, FieldType.Type.STRING), new FieldType(valCol, FieldType.Type.STRING)).withPrimaryKeys(keyCol).build());
try {
TransactionRunner transactionRunner = getTransactionRunner();
String key = "k0";
String val = "v0";
transactionRunner.run(context -> {
StructuredTable table = context.getTable(id);
List<Field<?>> fields = new ArrayList<>();
fields.add(Fields.stringField(keyCol, key));
Optional<StructuredRow> row = table.read(fields);
Assert.assertFalse(row.isPresent());
fields.add(Fields.stringField(valCol, val));
table.upsert(fields);
});
transactionRunner.run(context -> {
StructuredTable table = context.getTable(id);
List<Field<?>> keyField = Collections.singletonList(Fields.stringField(keyCol, key));
Optional<StructuredRow> row = table.read(keyField);
Assert.assertTrue(row.isPresent());
Assert.assertEquals(val, row.get().getString(valCol));
});
} finally {
tableAdmin.drop(id);
}
}
use of io.cdap.cdap.spi.data.StructuredTableAdmin in project cdap by caskdata.
the class NoSqlLineageTableTest method beforeClass.
@BeforeClass
public static void beforeClass() throws IOException, TableAlreadyExistsException {
CConfiguration cConf = dsFrameworkUtil.getConfiguration();
cConf.set(Constants.Dataset.DATA_STORAGE_IMPLEMENTATION, Constants.Dataset.DATA_STORAGE_NOSQL);
StructuredTableAdmin structuredTableAdmin = dsFrameworkUtil.getInjector().getInstance(StructuredTableAdmin.class);
transactionRunner = dsFrameworkUtil.getInjector().getInstance(TransactionRunner.class);
StoreDefinition.createAllTables(structuredTableAdmin);
}
Aggregations