Search in sources :

Example 1 with PreviewRequestPollerInfo

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);
}
Also used : ExtendedTwillContext(io.cdap.cdap.master.spi.twill.ExtendedTwillContext) LogAppenderInitializer(io.cdap.cdap.logging.appender.LogAppenderInitializer) Configuration(org.apache.hadoop.conf.Configuration) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LoggingContext(io.cdap.cdap.common.logging.LoggingContext) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) Injector(com.google.inject.Injector) PreviewRunnerManager(io.cdap.cdap.app.preview.PreviewRunnerManager) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) StorageProvider(io.cdap.cdap.spi.data.StorageProvider) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) File(java.io.File) PreviewRequestPollerInfo(io.cdap.cdap.internal.app.runtime.k8s.PreviewRequestPollerInfo)

Example 2 with PreviewRequestPollerInfo

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);
}
Also used : TwillController(org.apache.twill.api.TwillController) ExtendedTwillController(io.cdap.cdap.master.spi.twill.ExtendedTwillController) ExtendedTwillController(io.cdap.cdap.master.spi.twill.ExtendedTwillController) PreviewRequestPollerInfo(io.cdap.cdap.internal.app.runtime.k8s.PreviewRequestPollerInfo)

Example 3 with PreviewRequestPollerInfo

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);
}
Also used : CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Injector(com.google.inject.Injector) PreviewRequestPollerInfo(io.cdap.cdap.internal.app.runtime.k8s.PreviewRequestPollerInfo) Test(org.junit.Test)

Aggregations

PreviewRequestPollerInfo (io.cdap.cdap.internal.app.runtime.k8s.PreviewRequestPollerInfo)3 Injector (com.google.inject.Injector)2 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)2 Configuration (org.apache.hadoop.conf.Configuration)2 PreviewRunnerManager (io.cdap.cdap.app.preview.PreviewRunnerManager)1 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)1 LoggingContext (io.cdap.cdap.common.logging.LoggingContext)1 ServiceLoggingContext (io.cdap.cdap.common.logging.ServiceLoggingContext)1 LogAppenderInitializer (io.cdap.cdap.logging.appender.LogAppenderInitializer)1 ExtendedTwillContext (io.cdap.cdap.master.spi.twill.ExtendedTwillContext)1 ExtendedTwillController (io.cdap.cdap.master.spi.twill.ExtendedTwillController)1 StorageProvider (io.cdap.cdap.spi.data.StorageProvider)1 File (java.io.File)1 TwillController (org.apache.twill.api.TwillController)1 Test (org.junit.Test)1