Search in sources :

Example 41 with CommandException

use of org.glassfish.api.admin.CommandException in project Payara by payara.

the class RemoteAdminCommand method handleResponse.

private void handleResponse(ParameterMap params, InputStream in, int code) throws IOException, CommandException {
    RemoteResponseManager rrm = null;
    try {
        rrm = new RemoteResponseManager(in, code, logger);
        rrm.process();
    } catch (RemoteSuccessException rse) {
        // save results
        output = rse.getMessage();
        assert rrm != null;
        attrs = rrm.getMainAtts();
    } catch (RemoteException rfe) {
        // XXX - gross
        if (rfe.getRemoteCause().indexOf("CommandNotFoundException") >= 0) {
            // the closest matching commands
            throw new InvalidCommandException(rfe.getMessage());
        }
        throw new CommandException("remote failure: " + rfe.getMessage(), rfe);
    }
}
Also used : InvalidCommandException(org.glassfish.api.admin.InvalidCommandException) InvalidCommandException(org.glassfish.api.admin.InvalidCommandException) CommandException(org.glassfish.api.admin.CommandException)

Example 42 with CommandException

use of org.glassfish.api.admin.CommandException in project Payara by payara.

the class RemoteAdminCommand method addFileOption.

/**
 * Adds an option for a file argument, passing the name (for uploads) or the
 * path (for no-upload) operations.
 *
 * @param uriString the URI string so far
 * @param optionName the option which takes a path or name
 * @param filename the name of the file
 * @return the URI string
 * @throws java.io.IOException
 */
private StringBuilder addFileOption(StringBuilder uriString, String optionName, String filename) throws IOException, CommandException {
    File f = SmartFile.sanitize(new File(filename));
    logger.finer("FILE PARAM: " + optionName + " = " + f);
    final boolean uploadThisFile = doUpload && !f.isDirectory();
    // in different directories
    if (uploadThisFile) {
        logger.finer("Uploading file");
        try {
            outboundPayload.attachFile(FILE_PAYLOAD_MIME_TYPE, URI.create(optionName + "/" + f.getName() + (f.isDirectory() ? "/" : "")), optionName, null, f, true);
        } catch (FileNotFoundException fnfe) {
            /*
                 * Probably due to an attempt to upload a non-existent file.
                 * Convert this to a CommandException so it's better handled
                 * by the rest of the command running infrastructure.
                 */
            throw new CommandException(strings.get("UploadedFileNotFound", f.getAbsolutePath()));
        }
    }
    if (f != null) {
        // if we are about to upload it -- give just the name
        // o/w give the full path
        String pathToPass = (uploadThisFile ? f.getName() : f.getPath());
        addStringOption(uriString, optionName, pathToPass);
    }
    return uriString;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) InvalidCommandException(org.glassfish.api.admin.InvalidCommandException) CommandException(org.glassfish.api.admin.CommandException) SmartFile(com.sun.enterprise.universal.io.SmartFile) File(java.io.File)

Example 43 with CommandException

use of org.glassfish.api.admin.CommandException in project Payara by payara.

the class ChangeMasterPasswordCommandDAS method executeCommand.

@Override
protected int executeCommand() throws CommandException {
    try {
        HostAndPort adminAddress = getAdminAddress();
        if (isRunning(adminAddress.getHost(), adminAddress.getPort()))
            throw new CommandException(strings.get("domain.is.running", getDomainName(), getDomainRootDir()));
        DomainConfig domainConfig = new DomainConfig(getDomainName(), getDomainsDir().getAbsolutePath());
        PEDomainsManager manager = new PEDomainsManager();
        String mp = super.readFromMasterPasswordFile();
        if (mp == null) {
            mp = passwords.get("AS_ADMIN_MASTERPASSWORD");
            if (mp == null) {
                char[] mpCharArr = super.readPassword(strings.get("current.mp"));
                mp = mpCharArr != null ? new String(mpCharArr) : null;
            }
        }
        if (mp == null)
            throw new CommandException(strings.get("no.console"));
        if (!super.verifyMasterPassword(mp))
            throw new CommandException(strings.get("incorrect.mp"));
        char[] nmpCharArr = getPassword("newmasterpassword", strings.get("new.mp"), strings.get("new.mp.again"), true);
        String nmp = nmpCharArr != null ? new String(nmpCharArr) : null;
        if (nmp == null)
            throw new CommandException(strings.get("no.console"));
        // FIXES GLASSFISH-21017
        if (nmp.length() < 6) {
            throw new CommandException(strings.get("password.too.short"));
        }
        domainConfig.put(DomainConfig.K_MASTER_PASSWORD, mp);
        domainConfig.put(DomainConfig.K_NEW_MASTER_PASSWORD, nmp);
        domainConfig.put(DomainConfig.K_SAVE_MASTER_PASSWORD, savemp);
        manager.changeMasterPassword(domainConfig);
        return 0;
    } catch (Exception e) {
        throw new CommandException(e.getMessage(), e);
    }
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) CommandException(org.glassfish.api.admin.CommandException) PEDomainsManager(com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager) CommandException(org.glassfish.api.admin.CommandException) DomainConfig(com.sun.enterprise.admin.servermgmt.DomainConfig)

Example 44 with CommandException

use of org.glassfish.api.admin.CommandException in project Payara by payara.

the class StartServerHelper method waitForServer.

// TODO check the i18n messages
public void waitForServer() 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)) {
        if (pidFile != null) {
            if (logger.isLoggable(Level.FINER)) {
                logger.finer("Check for pid file: " + pidFile);
            }
            if (pidFile.exists()) {
                alive = true;
                break pinged;
            }
        } else {
            // if it is, the DAS is up
            for (HostAndPort addr : addresses) {
                if (NetUtils.isRunning(addr.getHost(), addr.getPort())) {
                    alive = true;
                    break pinged;
                }
            }
        }
        // if it isn't, startup failed
        try {
            Process p = launcher.getProcess();
            int exitCode = p.exitValue();
            // uh oh, DAS died
            String sname;
            if (info.isDomain()) {
                sname = "domain " + info.getDomainName();
            } else {
                sname = "instance " + info.getInstanceName();
            }
            ProcessStreamDrainer psd = launcher.getProcessStreamDrainer();
            String output = psd.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 = "" + (WAIT_FOR_DAS_TIME_MS / 1000);
        if (info.isDomain()) {
            msg = strings.get("serverNoStart", strings.get("DAS"), info.getDomainName(), time);
        } else {
            msg = strings.get("serverNoStart", strings.get("INSTANCE"), info.getInstanceName(), time);
        }
        throw new CommandException(msg);
    }
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) ProcessStreamDrainer(com.sun.enterprise.universal.process.ProcessStreamDrainer) GFLauncherException(com.sun.enterprise.admin.launcher.GFLauncherException) CommandException(org.glassfish.api.admin.CommandException)

Example 45 with CommandException

use of org.glassfish.api.admin.CommandException in project Payara by payara.

the class RestartDeploymentGroupCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Logger logger = context.getLogger();
    logger.info(Strings.get("restart.dg", deploymentGroup));
    // Require that we be a DAS
    if (!env.isDas()) {
        String msg = Strings.get("cluster.command.notDas");
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    if (rolling) {
        doRolling(context);
    } else {
        ClusterCommandHelper clusterHelper = new ClusterCommandHelper(domain, runner);
        ParameterMap pm = new ParameterMap();
        pm.add("delay", delay);
        try {
            // Run restart-instance against each instance in the cluster
            String commandName = "restart-instance";
            clusterHelper.runCommand(commandName, pm, deploymentGroup, context, verbose, rolling);
        } catch (CommandException e) {
            String msg = e.getLocalizedMessage();
            logger.warning(msg);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
        }
    }
}
Also used : ClusterCommandHelper(com.sun.enterprise.v3.admin.cluster.ClusterCommandHelper) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandException(org.glassfish.api.admin.CommandException) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger)

Aggregations

CommandException (org.glassfish.api.admin.CommandException)61 File (java.io.File)20 CommandValidationException (org.glassfish.api.admin.CommandValidationException)16 IOException (java.io.IOException)13 ParameterMap (org.glassfish.api.admin.ParameterMap)11 InvalidCommandException (org.glassfish.api.admin.InvalidCommandException)10 ActionReport (org.glassfish.api.ActionReport)9 ArrayList (java.util.ArrayList)6 RemoteCLICommand (com.sun.enterprise.admin.cli.remote.RemoteCLICommand)5 MiniXmlParserException (com.sun.enterprise.universal.xml.MiniXmlParserException)5 HostAndPort (com.sun.enterprise.util.HostAndPort)4 BackupException (com.sun.enterprise.backup.BackupException)3 BackupWarningException (com.sun.enterprise.backup.BackupWarningException)3 SmartFile (com.sun.enterprise.universal.io.SmartFile)3 FileNotFoundException (java.io.FileNotFoundException)3 UnknownHostException (java.net.UnknownHostException)3 Logger (java.util.logging.Logger)3 SFTPClient (org.glassfish.cluster.ssh.sftp.SFTPClient)3 CLIProcessExecutor (com.sun.enterprise.admin.cli.CLIProcessExecutor)2 PEDomainsManager (com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager)2