use of co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory in project cdap by caskdata.
the class HBaseStreamConsumerTest method init.
@BeforeClass
public static void init() throws Exception {
zkServer = InMemoryZKServer.builder().setDataDir(TMP_FOLDER.newFolder()).build();
zkServer.startAndWait();
Configuration hConf = TEST_HBASE.getConfiguration();
cConf.setInt(Constants.Stream.CONTAINER_INSTANCES, 1);
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TMP_FOLDER.newFolder().getAbsolutePath());
cConf.set(Constants.Zookeeper.QUORUM, zkServer.getConnectionStr());
Injector injector = Guice.createInjector(new ConfigModule(cConf, hConf), new ZKClientModule(), new NonCustomLocationUnitTestModule().getModule(), new DiscoveryRuntimeModule().getInMemoryModules(), new TransactionMetricsModule(), new DataSetsModules().getInMemoryModules(), new SystemDatasetRuntimeModule().getInMemoryModules(), new ExploreClientModule(), new ViewAdminModules().getInMemoryModules(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), Modules.override(new DataFabricModules().getDistributedModules(), new StreamAdminModules().getDistributedModules()).with(new AbstractModule() {
@Override
protected void configure() {
bind(TransactionStateStorage.class).to(NoOpTransactionStateStorage.class);
bind(TransactionSystemClient.class).to(InMemoryTxSystemClient.class).in(Singleton.class);
bind(StreamMetaStore.class).to(InMemoryStreamMetaStore.class);
bind(NotificationFeedManager.class).to(NoOpNotificationFeedManager.class);
bind(NamespaceQueryAdmin.class).to(SimpleNamespaceQueryAdmin.class);
bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
}
}));
zkClientService = injector.getInstance(ZKClientService.class);
zkClientService.startAndWait();
streamAdmin = injector.getInstance(StreamAdmin.class);
consumerFactory = injector.getInstance(StreamConsumerFactory.class);
txClient = injector.getInstance(TransactionSystemClient.class);
txManager = TxInMemory.getTransactionManager(txClient);
queueClientFactory = injector.getInstance(QueueClientFactory.class);
fileWriterFactory = injector.getInstance(StreamFileWriterFactory.class);
txManager.startAndWait();
tableUtil = injector.getInstance(HBaseTableUtil.class);
ddlExecutor = new HBaseDDLExecutorFactory(cConf, TEST_HBASE.getHBaseAdmin().getConfiguration()).get();
ddlExecutor.createNamespaceIfNotExists(tableUtil.getHBaseNamespace(NamespaceId.SYSTEM));
ddlExecutor.createNamespaceIfNotExists(tableUtil.getHBaseNamespace(TEST_NAMESPACE));
ddlExecutor.createNamespaceIfNotExists(tableUtil.getHBaseNamespace(OTHER_NAMESPACE));
setupNamespaces(injector.getInstance(NamespacedLocationFactory.class));
}
use of co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory in project cdap by caskdata.
the class HBaseMetricsTableTest method setup.
@BeforeClass
public static void setup() throws Exception {
CConfiguration conf = CConfiguration.create();
conf.set(Constants.CFG_HDFS_USER, System.getProperty("user.name"));
Injector injector = Guice.createInjector(new DataFabricModules().getDistributedModules(), new ConfigModule(conf, TEST_HBASE.getConfiguration()), new ZKClientModule(), new DiscoveryRuntimeModule().getDistributedModules(), new TransactionMetricsModule(), new LocationRuntimeModule().getDistributedModules(), new NamespaceClientUnitTestModule().getModule(), new SystemDatasetRuntimeModule().getDistributedModules(), new DataSetsModules().getInMemoryModules(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), new AbstractModule() {
@Override
protected void configure() {
bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
}
});
dsFramework = injector.getInstance(DatasetFramework.class);
tableUtil = injector.getInstance(HBaseTableUtil.class);
ddlExecutor = new HBaseDDLExecutorFactory(conf, TEST_HBASE.getHBaseAdmin().getConfiguration()).get();
ddlExecutor.createNamespaceIfNotExists(tableUtil.getHBaseNamespace(NamespaceId.SYSTEM));
}
use of co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory in project cdap by caskdata.
the class MetricHBaseTableUtilTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
cConf = CConfiguration.create();
hBaseTableUtil = new HBaseTableUtilFactory(cConf, new SimpleNamespaceQueryAdmin()).get();
HBaseDDLExecutor executor = new HBaseDDLExecutorFactory(cConf, TEST_HBASE.getHBaseAdmin().getConfiguration()).get();
executor.createNamespaceIfNotExists(hBaseTableUtil.getHBaseNamespace(NamespaceId.SYSTEM));
}
use of co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory in project cdap by caskdata.
the class DistributedProgramRunner method run.
@Override
public final ProgramController run(final Program program, ProgramOptions oldOptions) {
validateOptions(program, oldOptions);
final CConfiguration cConf = createContainerCConf(this.cConf);
final Configuration hConf = createContainerHConf(this.hConf);
final File tempDir = DirUtils.createTempDir(new File(cConf.get(Constants.CFG_LOCAL_DATA_DIR), cConf.get(Constants.AppFabric.TEMP_DIR)).getAbsoluteFile());
try {
final LaunchConfig launchConfig = new LaunchConfig();
setupLaunchConfig(launchConfig, program, oldOptions, cConf, hConf, tempDir);
// Add extra localize resources needed by the program runner
final Map<String, LocalizeResource> localizeResources = new HashMap<>(launchConfig.getExtraResources());
final ProgramOptions options = addArtifactPluginFiles(oldOptions, localizeResources, DirUtils.createTempDir(tempDir));
final List<String> additionalClassPaths = new ArrayList<>();
addContainerJars(cConf, localizeResources, additionalClassPaths);
// Copy config files to local temp, and ask Twill to localize it to container.
// What Twill does is to save those files in HDFS and keep using them during the lifetime of application.
// Twill will manage the cleanup of those files in HDFS.
localizeResources.put(HADOOP_CONF_FILE_NAME, new LocalizeResource(saveHConf(hConf, File.createTempFile("hConf", ".xml", tempDir))));
localizeResources.put(CDAP_CONF_FILE_NAME, new LocalizeResource(saveCConf(cConf, File.createTempFile("cConf", ".xml", tempDir))));
// Localize the program jar
Location programJarLocation = program.getJarLocation();
final String programJarName = programJarLocation.getName();
localizeResources.put(programJarName, new LocalizeResource(program.getJarLocation().toURI(), false));
// Localize an expanded program jar
final String expandedProgramJarName = "expanded." + programJarName;
localizeResources.put(expandedProgramJarName, new LocalizeResource(program.getJarLocation().toURI(), true));
// Localize the app spec
localizeResources.put(APP_SPEC_FILE_NAME, new LocalizeResource(saveAppSpec(program, File.createTempFile("appSpec", ".json", tempDir))));
final URI logbackURI = getLogBackURI(program, tempDir);
if (logbackURI != null) {
// Localize the logback xml
localizeResources.put(LOGBACK_FILE_NAME, new LocalizeResource(logbackURI, false));
}
Callable<ProgramController> callable = new Callable<ProgramController>() {
@Override
public ProgramController call() throws Exception {
ProgramTwillApplication twillApplication = new ProgramTwillApplication(program.getId(), launchConfig.getRunnables(), launchConfig.getLaunchOrder(), localizeResources, createEventHandler(cConf));
TwillPreparer twillPreparer = twillRunner.prepare(twillApplication);
for (Map.Entry<String, RunnableResource> entry : launchConfig.getRunnables().entrySet()) {
String runnable = entry.getKey();
RunnableResource runnableResource = entry.getValue();
if (runnableResource.getMaxRetries() != null) {
twillPreparer.withMaxRetries(runnable, runnableResource.getMaxRetries());
}
}
if (options.isDebug()) {
twillPreparer.enableDebugging();
}
logProgramStart(program, options);
String serializedOptions = GSON.toJson(options, ProgramOptions.class);
LOG.info("Starting {} with debugging enabled: {}, programOptions: {}, and logback: {}", program.getId(), options.isDebug(), serializedOptions, logbackURI);
// Add scheduler queue name if defined
String schedulerQueueName = options.getArguments().getOption(Constants.AppFabric.APP_SCHEDULER_QUEUE);
if (schedulerQueueName != null && !schedulerQueueName.isEmpty()) {
LOG.info("Setting scheduler queue for app {} as {}", program.getId(), schedulerQueueName);
twillPreparer.setSchedulerQueue(schedulerQueueName);
}
if (logbackURI != null) {
twillPreparer.addJVMOptions("-Dlogback.configurationFile=" + LOGBACK_FILE_NAME);
}
setLogLevels(twillPreparer, program, options);
String logLevelConf = cConf.get(Constants.COLLECT_APP_CONTAINER_LOG_LEVEL).toUpperCase();
if ("OFF".equals(logLevelConf)) {
twillPreparer.withConfiguration(Collections.singletonMap(Configs.Keys.LOG_COLLECTION_ENABLED, "false"));
} else {
LogEntry.Level logLevel = LogEntry.Level.ERROR;
if ("ALL".equals(logLevelConf)) {
logLevel = LogEntry.Level.TRACE;
} else {
try {
logLevel = LogEntry.Level.valueOf(logLevelConf.toUpperCase());
} catch (Exception e) {
LOG.warn("Invalid application container log level {}. Defaulting to ERROR.", logLevelConf);
}
}
twillPreparer.addLogHandler(new LoggerLogHandler(LOG, logLevel));
}
// Add secure tokens
if (User.isHBaseSecurityEnabled(hConf) || UserGroupInformation.isSecurityEnabled()) {
twillPreparer.addSecureStore(YarnSecureStore.create(secureStoreRenewer.createCredentials()));
}
// Setup the environment for the container logback.xml
twillPreparer.withEnv(Collections.singletonMap("CDAP_LOG_DIR", ApplicationConstants.LOG_DIR_EXPANSION_VAR));
// Add dependencies
Set<Class<?>> extraDependencies = new HashSet<>(launchConfig.getExtraDependencies());
extraDependencies.add(HBaseTableUtilFactory.getHBaseTableUtilClass(cConf));
extraDependencies.add(new HBaseDDLExecutorFactory(cConf, hConf).get().getClass());
if (SecureStoreUtils.isKMSBacked(cConf) && SecureStoreUtils.isKMSCapable()) {
extraDependencies.add(SecureStoreUtils.getKMSSecureStore());
}
twillPreparer.withDependencies(extraDependencies);
// Add the additional classes to the classpath that comes from the container jar setting
twillPreparer.withClassPaths(additionalClassPaths);
twillPreparer.withClassPaths(launchConfig.getExtraClasspath());
twillPreparer.withEnv(launchConfig.getExtraEnv());
// The Yarn app classpath goes last
List<String> yarnAppClassPath = Arrays.asList(hConf.getTrimmedStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH, YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH));
twillPreparer.withApplicationClassPaths(yarnAppClassPath).withClassPaths(yarnAppClassPath).withBundlerClassAcceptor(launchConfig.getClassAcceptor()).withApplicationArguments("--" + RunnableOptions.JAR, programJarName, "--" + RunnableOptions.EXPANDED_JAR, expandedProgramJarName, "--" + RunnableOptions.HADOOP_CONF_FILE, HADOOP_CONF_FILE_NAME, "--" + RunnableOptions.CDAP_CONF_FILE, CDAP_CONF_FILE_NAME, "--" + RunnableOptions.APP_SPEC_FILE, APP_SPEC_FILE_NAME, "--" + RunnableOptions.PROGRAM_OPTIONS, serializedOptions, "--" + RunnableOptions.PROGRAM_ID, GSON.toJson(program.getId())).setClassLoader(MainClassLoader.class.getName());
// Invoke the before launch hook
beforeLaunch(program, options);
TwillController twillController;
// Change the context classloader to the combine classloader of this ProgramRunner and
// all the classloaders of the dependencies classes so that Twill can trace classes.
ClassLoader oldClassLoader = ClassLoaders.setContextClassLoader(new CombineClassLoader(DistributedProgramRunner.this.getClass().getClassLoader(), Iterables.transform(extraDependencies, new Function<Class<?>, ClassLoader>() {
@Override
public ClassLoader apply(Class<?> input) {
return input.getClassLoader();
}
})));
try {
twillController = twillPreparer.start(cConf.getLong(Constants.AppFabric.PROGRAM_MAX_START_SECONDS), TimeUnit.SECONDS);
} finally {
ClassLoaders.setContextClassLoader(oldClassLoader);
}
return createProgramController(addCleanupListener(twillController, program, tempDir), new ProgramDescriptor(program.getId(), program.getApplicationSpecification()), ProgramRunners.getRunId(options));
}
};
return impersonator.doAs(program.getId(), callable);
} catch (Exception e) {
deleteDirectory(tempDir);
throw Throwables.propagate(e);
}
}
use of co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory in project cdap by caskdata.
the class HBaseMetadataTableTestRun method setupBeforeClass.
@BeforeClass
public static void setupBeforeClass() throws Exception {
hConf = HBASE_TEST_BASE.getConfiguration();
hConf.set(HBaseTableUtil.CFG_HBASE_TABLE_COMPRESSION, HBaseTableUtil.CompressionType.NONE.name());
tableUtil = new HBaseTableUtilFactory(cConf).get();
ddlExecutor = new HBaseDDLExecutorFactory(cConf, hConf).get();
ddlExecutor.createNamespaceIfNotExists(tableUtil.getHBaseNamespace(NamespaceId.SYSTEM));
LocationFactory locationFactory = getInjector().getInstance(LocationFactory.class);
tableFactory = new HBaseTableFactory(cConf, hConf, tableUtil, locationFactory);
}
Aggregations