Search in sources :

Example 41 with Context

use of org.glassfish.hk2.api.Context in project Payara by payara.

the class ApplicationLifecycle method startContainers.

protected boolean startContainers(Collection<EngineInfo> containersInfo, Logger logger, DeploymentContext context) {
    ActionReport report = context.getActionReport();
    for (EngineInfo engineInfo : containersInfo) {
        Container container;
        try {
            container = engineInfo.getContainer();
        } catch (Exception e) {
            logger.log(Level.SEVERE, KernelLoggerInfo.cantStartContainer, new Object[] { engineInfo.getSniffer().getModuleType(), e });
            return false;
        }
        Class<? extends Deployer> deployerClass = container.getDeployer();
        Deployer deployer;
        try {
            deployer = habitat.getService(deployerClass);
            engineInfo.setDeployer(deployer);
        } catch (MultiException e) {
            report.failure(logger, "Cannot instantiate or inject " + deployerClass, e);
            engineInfo.stop(logger);
            return false;
        } catch (ClassCastException e) {
            engineInfo.stop(logger);
            report.failure(logger, deployerClass + " does not implement " + " the org.jvnet.glassfish.api.deployment.Deployer interface", e);
            return false;
        }
    }
    return true;
}
Also used : Container(org.glassfish.api.container.Container) MultiException(org.glassfish.hk2.api.MultiException) PropertyVetoException(java.beans.PropertyVetoException) RetryableException(org.jvnet.hk2.config.RetryableException) MultiException(org.glassfish.hk2.api.MultiException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException) IOException(java.io.IOException)

Example 42 with Context

use of org.glassfish.hk2.api.Context in project storm by apache.

the class UIServer method main.

/**
 * main.
 * @param args args
 */
public static void main(String[] args) {
    Map<String, Object> conf = ConfigUtils.readStormConfig();
    int headerBufferSize = (int) conf.get(DaemonConfig.UI_HEADER_BUFFER_BYTES);
    final Integer httpsPort = ObjectReader.getInt(conf.get(DaemonConfig.UI_HTTPS_PORT), 0);
    final String httpsKsPath = (String) (conf.get(DaemonConfig.UI_HTTPS_KEYSTORE_PATH));
    final String httpsKsPassword = (String) (conf.get(DaemonConfig.UI_HTTPS_KEYSTORE_PASSWORD));
    final String httpsKsType = (String) (conf.get(DaemonConfig.UI_HTTPS_KEYSTORE_TYPE));
    final String httpsKeyPassword = (String) (conf.get(DaemonConfig.UI_HTTPS_KEY_PASSWORD));
    final String httpsTsPath = (String) (conf.get(DaemonConfig.UI_HTTPS_TRUSTSTORE_PATH));
    final String httpsTsPassword = (String) (conf.get(DaemonConfig.UI_HTTPS_TRUSTSTORE_PASSWORD));
    final String httpsTsType = (String) (conf.get(DaemonConfig.UI_HTTPS_TRUSTSTORE_TYPE));
    final Boolean httpsWantClientAuth = (Boolean) (conf.get(DaemonConfig.UI_HTTPS_WANT_CLIENT_AUTH));
    final Boolean httpsNeedClientAuth = (Boolean) (conf.get(DaemonConfig.UI_HTTPS_NEED_CLIENT_AUTH));
    final Boolean disableHttpBinding = (Boolean) (conf.get(DaemonConfig.UI_DISABLE_HTTP_BINDING));
    final boolean enableSslReload = ObjectReader.getBoolean(conf.get(DaemonConfig.UI_HTTPS_ENABLE_SSL_RELOAD), false);
    Server jettyServer = UIHelpers.jettyCreateServer((int) conf.get(DaemonConfig.UI_PORT), null, httpsPort, headerBufferSize, disableHttpBinding);
    UIHelpers.configSsl(jettyServer, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType, httpsNeedClientAuth, httpsWantClientAuth, enableSslReload);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    jettyServer.setHandler(context);
    FilterConfiguration filterConfiguration = new FilterConfiguration((String) conf.get(DaemonConfig.UI_FILTER), (Map<String, String>) conf.get(DaemonConfig.UI_FILTER_PARAMS));
    final List<FilterConfiguration> filterConfigurationList = Arrays.asList(filterConfiguration);
    UIHelpers.configFilters(context, filterConfigurationList);
    StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
    ResourceConfig resourceConfig = new ResourceConfig().packages("org.apache.storm.daemon.ui.resources").registerInstances(new AbstractBinder() {

        @Override
        protected void configure() {
            super.bind(metricsRegistry).to(StormMetricsRegistry.class);
        }
    }).register(AuthorizedUserFilter.class).register(HeaderResponseFilter.class).register(AuthorizationExceptionMapper.class).register(NotAliveExceptionMapper.class).register(DefaultExceptionMapper.class);
    ServletHolder jerseyServlet = new ServletHolder(new ServletContainer(resourceConfig));
    jerseyServlet.setInitOrder(0);
    context.addServlet(jerseyServlet, STORM_API_URL_PREFIX + "*");
    addRequestContextFilter(context, DaemonConfig.UI_HTTP_CREDS_PLUGIN, conf);
    // add special pathspec of static content mapped to the homePath
    ServletHolder holderHome = new ServletHolder("static-home", DefaultServlet.class);
    String packagedStaticFileLocation = System.getProperty(STORM_HOME) + FILE_SEPARATOR + "public/";
    if (Files.exists(Paths.get(packagedStaticFileLocation))) {
        holderHome.setInitParameter("resourceBase", packagedStaticFileLocation);
    } else {
        LOG.warn("Cannot find static file directory in " + packagedStaticFileLocation + " - assuming that UIServer is being launched" + "in a development environment and not from a packaged release");
        String developmentStaticFileLocation = UIServer.class.getProtectionDomain().getCodeSource().getLocation().getPath() + "WEB-INF";
        if (Files.exists(Paths.get(developmentStaticFileLocation))) {
            holderHome.setInitParameter("resourceBase", developmentStaticFileLocation);
        } else {
            throw new RuntimeException("Cannot find static file directory in development " + "location " + developmentStaticFileLocation);
        }
    }
    holderHome.setInitParameter("dirAllowed", "true");
    holderHome.setInitParameter("pathInfoOnly", "true");
    context.addFilter(new FilterHolder(new HeaderResponseServletFilter(metricsRegistry)), "/*", EnumSet.allOf(DispatcherType.class));
    context.addServlet(holderHome, "/*");
    // Lastly, the default servlet for root content (always needed, to satisfy servlet spec)
    ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
    holderPwd.setInitParameter("dirAllowed", "true");
    context.addServlet(holderPwd, "/");
    metricsRegistry.startMetricsReporters(conf);
    Utils.addShutdownHookWithForceKillIn1Sec(metricsRegistry::stopMetricsReporters);
    try {
        jettyServer.start();
        jettyServer.join();
    } catch (Throwable t) {
        LOG.error("Exception in UIServer: ", t);
        throw new RuntimeException(t);
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) NotAliveExceptionMapper(org.apache.storm.daemon.ui.exceptionmappers.NotAliveExceptionMapper) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) HeaderResponseFilter(org.apache.storm.daemon.ui.filters.HeaderResponseFilter) HeaderResponseServletFilter(org.apache.storm.daemon.ui.filters.HeaderResponseServletFilter) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DispatcherType(javax.servlet.DispatcherType)

Example 43 with Context

use of org.glassfish.hk2.api.Context in project zeppelin by apache.

the class NotebookServer method angularObjectUpdated.

/**
 * 1. When angular object updated from client.
 * 2. Save AngularObject to note.
 *
 * @param conn        the web socket.
 * @param fromMessage the message.
 */
private void angularObjectUpdated(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException {
    String noteId = (String) fromMessage.get("noteId");
    String paragraphId = (String) fromMessage.get("paragraphId");
    String interpreterGroupId = (String) fromMessage.get("interpreterGroupId");
    String varName = (String) fromMessage.get("name");
    Object varValue = fromMessage.get("value");
    String user = fromMessage.principal;
    getNotebookService().updateAngularObject(noteId, paragraphId, interpreterGroupId, varName, varValue, context, new WebSocketServiceCallback<AngularObject>(conn) {

        @Override
        public void onSuccess(AngularObject ao, ServiceContext context) throws IOException {
            super.onSuccess(ao, context);
            connectionManager.broadcastExcept(noteId, new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao).put("interpreterGroupId", interpreterGroupId).put("noteId", noteId).put("paragraphId", ao.getParagraphId()), conn);
            getNotebook().processNote(noteId, note -> {
                note.addOrUpdateAngularObject(interpreterGroupId, ao);
                return null;
            });
        }
    });
}
Also used : ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) TestUtils(org.apache.zeppelin.utils.TestUtils) Arrays(java.util.Arrays) TypeToken(com.google.gson.reflect.TypeToken) Provider(javax.inject.Provider) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) OnMessage(javax.websocket.OnMessage) GUI(org.apache.zeppelin.display.GUI) LoggerFactory(org.slf4j.LoggerFactory) ManagedOperation(org.eclipse.jetty.util.annotation.ManagedOperation) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) StringUtils(org.apache.commons.lang3.StringUtils) TicketContainer(org.apache.zeppelin.ticket.TicketContainer) GsonBuilder(com.google.gson.GsonBuilder) ManagedAttribute(org.eclipse.jetty.util.annotation.ManagedAttribute) ServiceContext(org.apache.zeppelin.service.ServiceContext) HeliumPackage(org.apache.zeppelin.helium.HeliumPackage) ParagraphInfo(org.apache.zeppelin.interpreter.thrift.ParagraphInfo) Gson(com.google.gson.Gson) Map(java.util.Map) ClusterEvent(org.apache.zeppelin.cluster.event.ClusterEvent) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) AuthorizationService(org.apache.zeppelin.notebook.AuthorizationService) ParagraphJobListener(org.apache.zeppelin.notebook.ParagraphJobListener) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) AngularObject(org.apache.zeppelin.display.AngularObject) Revision(org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision) Session(javax.websocket.Session) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) NoteInfo(org.apache.zeppelin.notebook.NoteInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) JupyterUtil(org.apache.zeppelin.jupyter.JupyterUtil) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) ServerEndpoint(javax.websocket.server.ServerEndpoint) Executors(java.util.concurrent.Executors) ClusterManagerServer(org.apache.zeppelin.cluster.ClusterManagerServer) JobManagerService(org.apache.zeppelin.service.JobManagerService) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) List(java.util.List) Type(java.lang.reflect.Type) Status(org.apache.zeppelin.scheduler.Job.Status) NotebookImportDeserializer(org.apache.zeppelin.notebook.NotebookImportDeserializer) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) MSG_ID_NOT_DEFINED(org.apache.zeppelin.common.Message.MSG_ID_NOT_DEFINED) RemoteInterpreterProcessListener(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener) CloseReason(javax.websocket.CloseReason) ClusterEventListener(org.apache.zeppelin.cluster.event.ClusterEventListener) Input(org.apache.zeppelin.display.Input) InterpreterSettingsList(org.apache.zeppelin.types.InterpreterSettingsList) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) OnOpen(javax.websocket.OnOpen) AngularObjectRegistryListener(org.apache.zeppelin.display.AngularObjectRegistryListener) IdHashes(org.apache.zeppelin.util.IdHashes) OnClose(javax.websocket.OnClose) Message(org.apache.zeppelin.common.Message) ExecutorService(java.util.concurrent.ExecutorService) OP(org.apache.zeppelin.common.Message.OP) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) NoteEventListener(org.apache.zeppelin.notebook.NoteEventListener) Paragraph(org.apache.zeppelin.notebook.Paragraph) CorsUtils(org.apache.zeppelin.utils.CorsUtils) NotebookService(org.apache.zeppelin.service.NotebookService) Logger(org.slf4j.Logger) ApplicationEventListener(org.apache.zeppelin.helium.ApplicationEventListener) SimpleServiceCallback(org.apache.zeppelin.service.SimpleServiceCallback) EndpointConfig(javax.websocket.EndpointConfig) Note(org.apache.zeppelin.notebook.Note) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Notebook(org.apache.zeppelin.notebook.Notebook) ServiceException(org.apache.zeppelin.interpreter.thrift.ServiceException) InterpreterCompletion(org.apache.zeppelin.interpreter.thrift.InterpreterCompletion) ZEPPELIN_ALLOWED_ORIGINS(org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars.ZEPPELIN_ALLOWED_ORIGINS) ConfigurationService(org.apache.zeppelin.service.ConfigurationService) OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) ServiceContext(org.apache.zeppelin.service.ServiceContext) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) AngularObject(org.apache.zeppelin.display.AngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) IOException(java.io.IOException)

Aggregations

ActionReport (org.glassfish.api.ActionReport)12 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)12 IOException (java.io.IOException)11 Properties (java.util.Properties)8 ArrayList (java.util.ArrayList)7 MultiException (org.glassfish.hk2.api.MultiException)7 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)7 Config (com.sun.enterprise.config.serverbeans.Config)6 PropertyVetoException (java.beans.PropertyVetoException)6 VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)6 Types (org.glassfish.hk2.classmodel.reflect.Types)6 RetryableException (org.jvnet.hk2.config.RetryableException)6 Logger (java.util.logging.Logger)5 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)5 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)4 ServletContext (javax.servlet.ServletContext)4 TargetType (org.glassfish.config.support.TargetType)4 Notifier (fish.payara.nucleus.notification.configuration.Notifier)3 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)3 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)3