Search in sources :

Example 1 with EngineInfo

use of org.glassfish.internal.data.EngineInfo in project Payara by payara.

the class ApplicationLoaderService method preDestroy.

/**
 * Stopped all loaded applications
 */
public void preDestroy() {
    // stop all running applications including user and system applications
    // which are registered in the domain.xml
    List<Application> allApplications = new ArrayList<Application>();
    List<Application> standaloneAdapters = applications.getApplicationsWithSnifferType(ServerTags.CONNECTOR, true);
    allApplications.addAll(applications.getApplications());
    allApplications.addAll(systemApplications.getApplications());
    // stop applications that are not of type "standalone" connectors
    for (Application app : allApplications) {
        if (app.isStandaloneModule() && app.containsSnifferType(ServerTags.CONNECTOR)) {
            continue;
        }
        ApplicationInfo appInfo = deployment.get(app.getName());
        stopApplication(app, appInfo);
    }
    // stop applications that are "standalone" connectors
    for (Application app : standaloneAdapters) {
        ApplicationInfo appInfo = deployment.get(app.getName());
        stopApplication(app, appInfo);
    }
    // now stop the applications which are not registered in the
    // domain.xml like timer service application
    Set<String> allAppNames = new HashSet<String>();
    allAppNames.addAll(appRegistry.getAllApplicationNames());
    for (String appName : allAppNames) {
        ApplicationInfo appInfo = appRegistry.get(appName);
        stopApplication(null, appInfo);
    }
    // stop all the containers
    for (EngineInfo engineInfo : containerRegistry.getContainers()) {
        engineInfo.stop(logger);
    }
    events.send(new Event<>(Deployment.ALL_APPLICATIONS_STOPPED, null), false);
}
Also used : EngineInfo(org.glassfish.internal.data.EngineInfo) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo)

Example 2 with EngineInfo

use of org.glassfish.internal.data.EngineInfo in project Payara by payara.

the class ContainerStarter method startContainer.

public Collection<EngineInfo> startContainer(Sniffer sniffer) {
    assert sniffer != null;
    String containerName = sniffer.getModuleType();
    assert containerName != null;
    // repositories which would allow access to the container module.
    try {
        Module[] modules = sniffer.setup(null, logger);
        logger.logp(Level.FINE, "ContainerStarter", "startContainer", "Sniffer {0} set up following modules: {1}", new Object[] { sniffer, modules != null ? Arrays.toString(modules) : "" });
    } catch (FileNotFoundException fnf) {
        logger.log(Level.SEVERE, fnf.getMessage());
        return null;
    } catch (IOException ioe) {
        logger.log(Level.SEVERE, ioe.getMessage(), ioe);
        return null;
    }
    // first the right container from that module.
    Map<String, EngineInfo> containers = new HashMap<String, EngineInfo>();
    for (String name : sniffer.getContainersNames()) {
        ServiceHandle<Container> provider = serviceLocator.getServiceHandle(Container.class, name);
        if (provider == null) {
            logger.severe("Cannot find Container named " + name + ", so unable to start " + sniffer.getModuleType() + " container");
            return null;
        }
        EngineInfo info = new EngineInfo(provider, sniffer, null);
        containers.put(name, info);
    }
    // Now that we have successfully created all containers, let's register them as well.
    for (Map.Entry<String, EngineInfo> entry : containers.entrySet()) {
        registry.addContainer(entry.getKey(), entry.getValue());
    }
    return containers.values();
}
Also used : EngineInfo(org.glassfish.internal.data.EngineInfo) Container(org.glassfish.api.container.Container) HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Module(com.sun.enterprise.module.Module) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with EngineInfo

use of org.glassfish.internal.data.EngineInfo in project Payara by payara.

the class ListContainersCommand method execute.

public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    report.setActionDescription(localStrings.getLocalString("list.containers.command", "List of Containers"));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    ActionReport.MessagePart top = report.getTopMessagePart();
    top.setMessage(localStrings.getLocalString("list.containers.command", "List of Containers"));
    top.setChildrenType(localStrings.getLocalString("container", "Container"));
    Iterable<? extends Sniffer> sniffers = habitat.getAllServices(Sniffer.class);
    if (sniffers == null) {
        top.setMessage(localStrings.getLocalString("list.containers.nocontainer", "No container currently configured"));
    } else {
        for (Sniffer sniffer : sniffers) {
            ActionReport.MessagePart container = top.addChild();
            container.setMessage(sniffer.getModuleType());
            container.addProperty(localStrings.getLocalString("contractprovider", "ContractProvider"), sniffer.getModuleType());
            EngineInfo engineInfo = containerRegistry.getContainer(sniffer.getModuleType());
            if (engineInfo != null) {
                container.addProperty(localStrings.getLocalString("status", "Status"), localStrings.getLocalString("started", "Started"));
                Module connectorModule = modulesRegistry.find(engineInfo.getSniffer().getClass());
                container.addProperty(localStrings.getLocalString("connector", "Connector"), connectorModule.getModuleDefinition().getName() + ":" + connectorModule.getModuleDefinition().getVersion());
                container.addProperty(localStrings.getLocalString("implementation", "Implementation"), engineInfo.getContainer().getClass().toString());
                boolean atLeastOne = false;
                for (Application app : applications.getApplications()) {
                    for (com.sun.enterprise.config.serverbeans.Module module : app.getModule()) {
                        Engine engine = module.getEngine(engineInfo.getSniffer().getModuleType());
                        if (engine != null) {
                            if (!atLeastOne) {
                                atLeastOne = true;
                                container.setChildrenType(localStrings.getLocalString("list.containers.listapps", "Applications deployed"));
                            }
                            container.addChild().setMessage(app.getName());
                        }
                    }
                }
                if (!atLeastOne) {
                    container.addProperty("Status", "Not Started");
                }
            }
        }
    }
}
Also used : Sniffer(org.glassfish.api.container.Sniffer) ActionReport(org.glassfish.api.ActionReport) EngineInfo(org.glassfish.internal.data.EngineInfo) Module(com.sun.enterprise.module.Module) Application(com.sun.enterprise.config.serverbeans.Application) Engine(com.sun.enterprise.config.serverbeans.Engine)

Example 4 with EngineInfo

use of org.glassfish.internal.data.EngineInfo in project Payara by payara.

the class SnifferAdapter method service.

// I could synchronize this method since I only start one container and do it
// synchronously but that seems like an overkill and I would still need to handle
// pending requests.
@Override
public void service(Request req, Response resp) throws Exception {
    if (adapter != null) {
        // this is not supposed to happen, however due to multiple requests coming in, I would
        // not be surprised...
        adapter.service(req, resp);
        return;
    }
    // different threads.
    synchronized (containerRegistry) {
        if (adapter != null) {
            // I got started in the meantime
            adapter.service(req, resp);
            return;
        }
        if (containerRegistry.getContainer(sniffer.getContainersNames()[0]) != null) {
            LOGGER.fine("Container is claimed to be started...");
            containerRegistry.getContainer(sniffer.getContainersNames()[0]).getContainer();
        } else {
            final long startTime = System.currentTimeMillis();
            LOGGER.log(Level.INFO, KernelLoggerInfo.snifferAdapterStartingContainer, sniffer.getModuleType());
            try {
                Collection<EngineInfo> containersInfo = containerStarter.startContainer(sniffer);
                if (containersInfo != null && !containersInfo.isEmpty()) {
                    // force the start on each container
                    for (EngineInfo info : containersInfo) {
                        if (LOGGER.isLoggable(Level.FINE)) {
                            LOGGER.log(Level.FINE, "Got container, deployer is {0}", info.getDeployer());
                        }
                        info.getContainer();
                        LOGGER.log(Level.INFO, KernelLoggerInfo.snifferAdapterContainerStarted, new Object[] { sniffer.getModuleType(), System.currentTimeMillis() - startTime });
                    }
                } else {
                    LOGGER.severe(KernelLoggerInfo.snifferAdapterNoContainer);
                }
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, KernelLoggerInfo.snifferAdapterExceptionStarting, new Object[] { sniffer.getContainersNames()[0], e });
            }
        }
        // at this point the post construct should have been called.
        // seems like there is some possibility that the container is not synchronously started
        // preventing the calls below to succeed...
        DataChunk decodedURI = req.getRequest().getRequestURIRef().getDecodedRequestURIBC();
        try {
            // Clear the previous mapped information.
            MappingData mappingData = (MappingData) req.getNote(ContainerMapper.MAPPING_DATA);
            mappingData.recycle();
            adapter = mapper.mapUriWithSemicolon(req, decodedURI, 0, null);
            // and throw a Runtime exception.
            if (adapter.equals(this)) {
                adapter = null;
                throw new RuntimeException("SnifferAdapter cannot map themself.");
            }
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, KernelLoggerInfo.snifferAdapterExceptionMapping, e);
            throw e;
        }
        // pass on,,,
        if (adapter != null) {
            adapter.service(req, resp);
        } else {
            throw new RuntimeException("No Adapter found.");
        }
    }
}
Also used : EngineInfo(org.glassfish.internal.data.EngineInfo) MappingData(org.glassfish.grizzly.http.server.util.MappingData) DataChunk(org.glassfish.grizzly.http.util.DataChunk)

Aggregations

EngineInfo (org.glassfish.internal.data.EngineInfo)4 Module (com.sun.enterprise.module.Module)2 Application (com.sun.enterprise.config.serverbeans.Application)1 Engine (com.sun.enterprise.config.serverbeans.Engine)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ActionReport (org.glassfish.api.ActionReport)1 Container (org.glassfish.api.container.Container)1 Sniffer (org.glassfish.api.container.Sniffer)1 MappingData (org.glassfish.grizzly.http.server.util.MappingData)1 DataChunk (org.glassfish.grizzly.http.util.DataChunk)1 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)1