Search in sources :

Example 1 with MiniXmlParserException

use of com.sun.enterprise.universal.xml.MiniXmlParserException 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 2 with MiniXmlParserException

use of com.sun.enterprise.universal.xml.MiniXmlParserException in project Payara by payara.

the class GFEmbeddedLauncher method setup.

@Override
public void setup() throws GFLauncherException, MiniXmlParserException {
    if (setup)
        return;
    else
        setup = true;
    try {
        setupFromEnv();
    } catch (GFLauncherException gfle) {
        String msg = "";
        throw new GFLauncherException(GENERAL_MESSAGE + gfle.getMessage());
    }
    setCommandLine();
    /* it is NOT an error for there to be no domain.xml (yet).
         * so eat exceptions.  Also just set the default to 4848 if we don't find
         * the port...
         */
    GFLauncherInfo info = getInfo();
    try {
        File parent = info.getDomainParentDir();
        String domainName = info.getDomainName();
        String instanceName = info.getInstanceName();
        if (instanceName == null)
            instanceName = "server";
        File dom = new File(parent, domainName);
        File theConfigDir = new File(dom, "config");
        File dx = new File(theConfigDir, "domain.xml");
        info.setConfigDir(theConfigDir);
        info.setDomainRootDir(new File(System.getenv(INSTALL_HOME)));
        MiniXmlParser parser = new MiniXmlParser(dx, instanceName);
        info.setAdminAddresses(parser.getAdminAddresses());
        File logFile = new File(dom, "logs");
        logFile = new File(logFile, "server.log");
        logFilename = logFile.getAbsolutePath();
    } catch (Exception e) {
        // temp todo
        e.printStackTrace();
    }
    List<HostAndPort> adminAddresses = info.getAdminAddresses();
    if (adminAddresses == null || adminAddresses.isEmpty()) {
        adminAddresses = new ArrayList<HostAndPort>();
        adminAddresses.add(new HostAndPort("localhost", 4848, false));
        info.setAdminAddresses(adminAddresses);
    }
    GFLauncherLogger.addLogFileHandler(getLogFilename(), info);
// super.fixLogFilename();
/*
    String domainName = parser.getDomainName();
    if(GFLauncherUtils.ok(domainName)) {
    info.setDomainName(domainName);
    }
     */
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) SmartFile(com.sun.enterprise.universal.io.SmartFile) File(java.io.File) MiniXmlParser(com.sun.enterprise.universal.xml.MiniXmlParser) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException)

Example 3 with MiniXmlParserException

use of com.sun.enterprise.universal.xml.MiniXmlParserException 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.
 *
 * @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.size() > 0)
            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 MiniXmlParserException

use of com.sun.enterprise.universal.xml.MiniXmlParserException in project Payara by payara.

the class ChangeAdminPasswordCommand method changeAdminPasswordLocally.

private int changeAdminPasswordLocally(String domainDir, String domainName) throws CommandException {
    if (!isLocalHost(programOpts.getHost())) {
        throw new CommandException(strings.get("CannotExecuteLocally"));
    }
    GFLauncher launcher = null;
    try {
        launcher = GFLauncherFactory.getInstance(RuntimeType.DAS);
        GFLauncherInfo info = launcher.getInfo();
        info.setDomainName(domainName);
        info.setDomainParentDir(domainDir);
        launcher.setup();
        // throw new exception
        if (launcher.isSecureAdminEnabled()) {
            if ((newpassword == null) || (newpassword.isEmpty())) {
                throw new CommandException(strings.get("NullNewPassword"));
            }
        }
        String adminKeyFile = launcher.getAdminRealmKeyFile();
        if (adminKeyFile != null) {
            // This is a FileRealm, instantiate it.
            FileRealmHelper helper = new FileRealmHelper(adminKeyFile);
            // Authenticate the old password
            String[] groups = helper.authenticate(programOpts.getUser(), password.toCharArray());
            if (groups == null) {
                throw new CommandException(strings.get("InvalidCredentials", programOpts.getUser()));
            }
            helper.updateUser(programOpts.getUser(), programOpts.getUser(), newpassword.toCharArray(), null);
            helper.persist();
            return SUCCESS;
        } else {
            // Cannot change password locally for non file realms
            throw new CommandException(strings.get("NotFileRealmCannotChangeLocally"));
        }
    } catch (MiniXmlParserException ex) {
        throw new CommandException(ex);
    } catch (GFLauncherException ex) {
        throw new CommandException(ex);
    } catch (IOException ex) {
        throw new CommandException(ex);
    }
}
Also used : FileRealmHelper(org.glassfish.security.common.FileRealmHelper) GFLauncher(com.sun.enterprise.admin.launcher.GFLauncher) GFLauncherException(com.sun.enterprise.admin.launcher.GFLauncherException) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException) IOException(java.io.IOException) GFLauncherInfo(com.sun.enterprise.admin.launcher.GFLauncherInfo)

Example 5 with MiniXmlParserException

use of com.sun.enterprise.universal.xml.MiniXmlParserException in project Payara by payara.

the class StartLocalInstanceCommand method executeCommand.

/**
 */
@Override
protected int executeCommand() throws CommandException {
    if (logger.isLoggable(Level.FINER))
        logger.finer(toString());
    if (sync.equals("none")) {
        logger.info(Strings.get("Instance.nosync"));
    } else {
        if (!synchronizeInstance()) {
            File domainXml = new File(new File(instanceDir, "config"), "domain.xml");
            if (!domainXml.exists()) {
                logger.info(Strings.get("Instance.nodomainxml"));
                return ERROR;
            }
            logger.info(Strings.get("Instance.syncFailed"));
        }
    }
    try {
        // createLauncher needs to go before the helper is created!!
        createLauncher();
        final String mpv = getMasterPassword();
        helper = new StartServerHelper(logger, programOpts.isTerse(), getServerDirs(), launcher, mpv, debug);
        if (!helper.prepareForLaunch()) {
            return ERROR;
        }
        if (dry_run) {
            if (logger.isLoggable(Level.FINE))
                logger.fine(Strings.get("dry_run_msg"));
            List<String> cmd = getLauncher().getCommandLine();
            StringBuilder sb = new StringBuilder();
            for (String s : cmd) {
                sb.append(s);
                sb.append('\n');
            }
            logger.info(sb.toString());
            return SUCCESS;
        }
        getLauncher().launch();
        if (verbose || watchdog) {
            // we can potentially loop forever here...
            while (true) {
                int returnValue = getLauncher().getExitValue();
                switch(returnValue) {
                    case RESTART_NORMAL:
                        logger.info(Strings.get("restart"));
                        break;
                    case RESTART_DEBUG_ON:
                        logger.info(Strings.get("restartChangeDebug", "on"));
                        getInfo().setDebug(true);
                        break;
                    case RESTART_DEBUG_OFF:
                        logger.info(Strings.get("restartChangeDebug", "off"));
                        getInfo().setDebug(false);
                        break;
                    default:
                        return returnValue;
                }
                if (env.debug())
                    System.setProperty(CLIConstants.WALL_CLOCK_START_PROP, "" + System.currentTimeMillis());
                getLauncher().relaunch();
            }
        } else {
            helper.waitForServer();
            helper.report();
            return SUCCESS;
        }
    } catch (GFLauncherException gfle) {
        throw new CommandException(gfle.getMessage());
    } catch (MiniXmlParserException me) {
        throw new CommandException(me);
    }
}
Also used : StartServerHelper(com.sun.enterprise.admin.servermgmt.cli.StartServerHelper) GFLauncherException(com.sun.enterprise.admin.launcher.GFLauncherException) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException)

Aggregations

MiniXmlParserException (com.sun.enterprise.universal.xml.MiniXmlParserException)6 MiniXmlParser (com.sun.enterprise.universal.xml.MiniXmlParser)3 HostAndPort (com.sun.enterprise.util.HostAndPort)3 GFLauncherException (com.sun.enterprise.admin.launcher.GFLauncherException)2 SmartFile (com.sun.enterprise.universal.io.SmartFile)2 File (java.io.File)2 CommandException (org.glassfish.api.admin.CommandException)2 GFLauncher (com.sun.enterprise.admin.launcher.GFLauncher)1 GFLauncherInfo (com.sun.enterprise.admin.launcher.GFLauncherInfo)1 StartServerHelper (com.sun.enterprise.admin.servermgmt.cli.StartServerHelper)1 IOException (java.io.IOException)1 FileRealmHelper (org.glassfish.security.common.FileRealmHelper)1