Search in sources :

Example 1 with HostAndPort

use of com.sun.enterprise.util.HostAndPort in project Payara by payara.

the class SunDeploymentManager method addToTargetModuleIDs.

/**
 *Augments a Collection of TargetModuleIDs with new entries for target module IDs of a given module type on the specified target.
 *@param tmids array of TargetModuleIDs
 *@param type the ModuleType of interest
 *@param targetImpl the TargetImpl from which to retrieve modules of the selected type
 *@param resultingTMIDs pre-instantiated List to which TargetModuleIDs will be added
 */
private void addToTargetModuleIDs(TargetModuleID[] tmids, ModuleType type, TargetImpl targetImpl, Collection resultingTMIDs) throws IOException {
    for (int j = 0; j < tmids.length; j++) {
        // Get the host name and port where the application was deployed
        HostAndPort webHost = deploymentFacility.getHostAndPort(targetImpl.getName(), tmids[j].getModuleID(), false);
        if (tmids[j] instanceof TargetModuleIDImpl) {
            ((TargetModuleIDImpl) tmids[j]).setModuleType(type);
        }
        resultingTMIDs.add(tmids[j]);
        /*
             *Set additional information on the target module ID, depending on what type of
             *module this is.  For J2EE apps, this includes constructing sub TargetModuleIDs.
             */
        try {
            if (type.equals(ModuleType.EAR)) {
                setJ2EEApplicationTargetModuleIDInfo(tmids[j], webHost);
            } else if (type.equals(ModuleType.WAR)) {
                setWebApplicationTargetModuleIDInfo(tmids[j], webHost);
            }
        } catch (Exception exp) {
            Logger.getAnonymousLogger().log(Level.WARNING, exp.getLocalizedMessage(), exp);
        }
    }
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) DConfigBeanVersionUnsupportedException(javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException) ConfigurationException(javax.enterprise.deploy.spi.exceptions.ConfigurationException) TargetException(javax.enterprise.deploy.spi.exceptions.TargetException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidModuleException(javax.enterprise.deploy.spi.exceptions.InvalidModuleException)

Example 2 with HostAndPort

use of com.sun.enterprise.util.HostAndPort in project Payara by payara.

the class ChangeNodeMasterPasswordCommand method isRunning.

private boolean isRunning(File nodeDirChild, String serverName) throws CommandException {
    try {
        File serverDir = new File(nodeDirChild, serverName);
        File configDir = new File(serverDir, "config");
        File domainXml = new File(configDir, "domain.xml");
        if (!domainXml.exists())
            return false;
        MiniXmlParser parser = new MiniXmlParser(domainXml, serverName);
        List<HostAndPort> addrSet = parser.getAdminAddresses();
        if (addrSet.size() <= 0)
            throw new CommandException(strings.get("NoAdminPort"));
        HostAndPort addr = addrSet.get(0);
        return isRunning(addr.getHost(), addr.getPort());
    } catch (MiniXmlParserException ex) {
        throw new CommandException(strings.get("NoAdminPortEx", ex), ex);
    }
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException) CommandException(org.glassfish.api.admin.CommandException) File(java.io.File) MiniXmlParser(com.sun.enterprise.universal.xml.MiniXmlParser)

Example 3 with HostAndPort

use of com.sun.enterprise.util.HostAndPort in project Payara by payara.

the class LocalServerCommand method getAdminAddress.

/**
 * Returns the admin address of a particular server. Note that this method
 * should be called only when you own the server that is available on an
 * accessible file system.
 *
 * @param serverName the server name
 * @return HostAndPort object with admin server address
 * @throws CommandException in case of parsing errors
 */
protected final HostAndPort getAdminAddress(String serverName) throws CommandException {
    try {
        MiniXmlParser parser = new MiniXmlParser(getDomainXml(), serverName);
        List<HostAndPort> addrSet = parser.getAdminAddresses();
        if (!addrSet.isEmpty()) {
            return addrSet.get(0);
        } else {
            throw new CommandException(STRINGS.get("NoAdminPort"));
        }
    } catch (MiniXmlParserException ex) {
        throw new CommandException(STRINGS.get("NoAdminPortEx", ex), ex);
    }
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException) CommandException(org.glassfish.api.admin.CommandException) MiniXmlParser(com.sun.enterprise.universal.xml.MiniXmlParser)

Example 4 with HostAndPort

use of com.sun.enterprise.util.HostAndPort in project Payara by payara.

the class StartServerHelper method waitForServer.

public void waitForServer(long timeout, TimeUnit unit) throws CommandException {
    long startWait = System.currentTimeMillis();
    if (!terse) {
        // use stdout because logger always appends a newline
        System.out.print(STRINGS.get("WaitServer", serverOrDomainName) + " ");
    }
    boolean alive = false;
    int count = 0;
    pinged: while (!timedOut(startWait, unit.toMillis(timeout))) {
        if (pidFile != null) {
            logger.log(FINER, "Check for pid file: {0}", pidFile);
            if (pidFile.exists()) {
                alive = true;
                break pinged;
            }
        } else {
            // If it is, the DAS is up
            for (HostAndPort address : addresses) {
                if (isRunning(address.getHost(), address.getPort())) {
                    alive = true;
                    break pinged;
                }
            }
        }
        // If it isn't, startup failed.
        try {
            int exitCode = launcher.getProcess().exitValue();
            // If we reach this location, there's an exit code, so uh oh, DAS died
            // If the DAS is still alive an exception is thrown here
            String sname;
            if (info.isDomain()) {
                sname = "domain " + info.getDomainName();
            } else {
                sname = "instance " + info.getInstanceName();
            }
            String output = launcher.getProcessStreamDrainer().getOutErrString();
            if (ok(output)) {
                throw new CommandException(STRINGS.get("serverDiedOutput", sname, exitCode, output));
            } else {
                throw new CommandException(STRINGS.get("serverDied", sname, exitCode));
            }
        } catch (GFLauncherException ex) {
        // should never happen
        } catch (IllegalThreadStateException ex) {
        // process is still alive
        }
        // Wait before checking again
        try {
            Thread.sleep(100);
            if (!terse && count++ % 10 == 0) {
                System.out.print(".");
            }
        } catch (InterruptedException ex) {
        // don't care
        }
    }
    if (!terse) {
        System.out.println();
    }
    if (!alive) {
        String msg;
        String time = "" + unit.toSeconds(timeout);
        if (info.isDomain()) {
            msg = STRINGS.get("serverNoStart", STRINGS.get("DAS"), info.getDomainName(), time);
        } else {
            // e.g. No response from the Instance Server (instance1) after 600 seconds.
            msg = STRINGS.get("serverNoStart", STRINGS.get("INSTANCE"), info.getInstanceName(), time);
        }
        throw new CommandException(msg);
    }
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) GFLauncherException(com.sun.enterprise.admin.launcher.GFLauncherException) CommandException(org.glassfish.api.admin.CommandException)

Example 5 with HostAndPort

use of com.sun.enterprise.util.HostAndPort in project Payara by payara.

the class GetHostAndPortCommand method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    ActionReport.MessagePart part = report.getTopMessagePart();
    HttpService httpService = null;
    HostAndPort hostAndPort = null;
    try {
        if (config == null) {
            throw new Exception("No such target:" + target);
        }
        httpService = config.getHttpService();
        if (httpService != null) {
            hostAndPort = getHostAndPortForRequest(httpService);
        }
    } catch (Exception e) {
        report.setMessage(e.getMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (hostAndPort != null) {
        part.setMessage(hostAndPort.getHost() + ":" + hostAndPort.getPort());
        // property for REST Access
        part.addProperty("host", hostAndPort.getHost());
        // property for REST Access
        part.addProperty("port", "" + hostAndPort.getPort());
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ActionReport(org.glassfish.api.ActionReport)

Aggregations

HostAndPort (com.sun.enterprise.util.HostAndPort)19 CommandException (org.glassfish.api.admin.CommandException)6 MiniXmlParser (com.sun.enterprise.universal.xml.MiniXmlParser)4 MiniXmlParserException (com.sun.enterprise.universal.xml.MiniXmlParserException)4 File (java.io.File)4 IOException (java.io.IOException)4 Test (org.junit.Test)3 GFLauncherException (com.sun.enterprise.admin.launcher.GFLauncherException)2 Config (com.sun.enterprise.config.serverbeans.Config)2 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)2 MalformedURLException (java.net.MalformedURLException)2 DConfigBeanVersionUnsupportedException (javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException)2 InvalidModuleException (javax.enterprise.deploy.spi.exceptions.InvalidModuleException)2 TargetException (javax.enterprise.deploy.spi.exceptions.TargetException)2 RestEndpoint (org.glassfish.api.admin.RestEndpoint)2 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)2 Protocol (org.glassfish.grizzly.config.dom.Protocol)2 DomainConfig (com.sun.enterprise.admin.servermgmt.DomainConfig)1 PEDomainsManager (com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager)1 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1