use of io.cdap.cdap.internal.app.runtime.k8s.PreviewRequestPollerInfo in project cdap by caskdata.
the class PreviewRunnerTwillRunnable method doInitialize.
private void doInitialize(TwillContext context) throws Exception {
CConfiguration cConf = CConfiguration.create(new File(getArgument("cConf")).toURI().toURL());
Configuration hConf = new Configuration();
hConf.clear();
hConf.addResource(new File(getArgument("hConf")).toURI().toURL());
PreviewRequestPollerInfo pollerInfo;
if (context instanceof ExtendedTwillContext) {
pollerInfo = new PreviewRequestPollerInfo(context.getInstanceId(), ((ExtendedTwillContext) context).getUID());
} else {
pollerInfo = new PreviewRequestPollerInfo(context.getInstanceId(), null);
}
LOG.debug("Initializing preview runner with poller info {} in total {} runners", pollerInfo, context.getInstanceCount());
Injector injector = createInjector(cConf, hConf, pollerInfo);
// Initialize logging context
logAppenderInitializer = injector.getInstance(LogAppenderInitializer.class);
logAppenderInitializer.initialize();
LoggingContext loggingContext = new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, PreviewRunnerTwillApplication.NAME);
LoggingContextAccessor.setLoggingContext(loggingContext);
// Optionally get the storage provider. It is for destroy() method to close it on shutdown.
Binding<StorageProvider> storageBinding = injector.getExistingBinding(Key.get(StorageProvider.class));
if (storageBinding != null) {
storageProvider = storageBinding.getProvider().get();
}
previewRunnerManager = injector.getInstance(PreviewRunnerManager.class);
}
use of io.cdap.cdap.internal.app.runtime.k8s.PreviewRequestPollerInfo in project cdap by caskdata.
the class DistributedPreviewRunStopper method stop.
@Override
public void stop(ApplicationId previewApp) throws Exception {
byte[] info = previewStore.getPreviewRequestPollerInfo(previewApp);
if (info == null) {
// should not happen
throw new IllegalStateException("Preview cannot be stopped. Please try stopping again or run the new preview.");
}
PreviewRequestPollerInfo pollerInfo = GSON.fromJson(new String(info, StandardCharsets.UTF_8), PreviewRequestPollerInfo.class);
Iterator<TwillController> controllers = twillRunner.lookup(PreviewRunnerTwillApplication.NAME).iterator();
if (!controllers.hasNext()) {
throw new IllegalStateException("Preview runners cannot be stopped. Please try again.");
}
LOG.debug("Stopping preview run {} with poller info {}", previewApp, pollerInfo);
TwillController controller = controllers.next();
Future<String> future;
if (controller instanceof ExtendedTwillController) {
future = ((ExtendedTwillController) controller).restartInstance(PreviewRunnerTwillRunnable.class.getSimpleName(), pollerInfo.getInstanceId(), pollerInfo.getInstanceUid());
} else {
future = controller.restartInstances(PreviewRunnerTwillRunnable.class.getSimpleName(), pollerInfo.getInstanceId());
}
future.get();
LOG.info("Force stopped preview run {}", previewApp);
}
use of io.cdap.cdap.internal.app.runtime.k8s.PreviewRequestPollerInfo in project cdap by caskdata.
the class PreviewRunnerTwillRunnableTest method testInjector.
@Test
public void testInjector() {
Injector injector = PreviewRunnerTwillRunnable.createInjector(CConfiguration.create(), new Configuration(), new PreviewRequestPollerInfo(0, "testuid"));
injector.getInstance(PreviewRunnerManager.class);
}
Aggregations