Search in sources :

Example 6 with CommandException

use of org.glassfish.api.admin.CommandException 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 7 with CommandException

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

the class ChangeNodeMasterPasswordCommand method executeCommand.

@Override
protected int executeCommand() throws CommandException {
    try {
        nodeDir = nodeDir0;
        node = node0;
        File serverDir = new File(nodeDir, node);
        if (!serverDir.isDirectory()) {
            throw new CommandException(strings.get("bad.node.dir", serverDir));
        }
        ArrayList<String> serverNames = getInstanceDirs(serverDir);
        for (String serverName : serverNames) if (isRunning(serverDir, serverName))
            throw new CommandException(strings.get("instance.is.running", serverName));
        oldPassword = passwords.get("AS_ADMIN_MASTERPASSWORD");
        if (oldPassword == null) {
            char[] opArr = super.readPassword(strings.get("old.mp"));
            oldPassword = opArr != null ? new String(opArr) : null;
        }
        if (oldPassword == null)
            throw new CommandException(strings.get("no.console"));
        // for each instance iterate through the instances first,
        // read each keystore with the old password,
        // only then should it save the new master password.
        boolean valid = true;
        for (String instanceDir0 : getInstanceDirs(nodeDirChild)) {
            valid &= verifyInstancePassword(new File(nodeDirChild, instanceDir0));
        }
        if (!valid) {
            throw new CommandException(strings.get("incorrect.old.mp"));
        }
        ParamModelData nmpo = new ParamModelData("AS_ADMIN_NEWMASTERPASSWORD", String.class, false, null);
        nmpo.prompt = strings.get("new.mp");
        nmpo.promptAgain = strings.get("new.mp.again");
        nmpo.param._password = true;
        char[] npArr = super.getPassword(nmpo, null, true);
        newPassword = npArr != null ? new String(npArr) : null;
        // for each instance encrypt the keystore
        for (String instanceDir2 : getInstanceDirs(nodeDirChild)) {
            encryptKeystore(instanceDir2);
        }
        if (savemp) {
            createMasterPasswordFile();
        }
        return 0;
    } catch (Exception e) {
        throw new CommandException(e.getMessage(), e);
    }
}
Also used : ParamModelData(com.sun.enterprise.admin.util.CommandModelData.ParamModelData) CommandException(org.glassfish.api.admin.CommandException) File(java.io.File) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException) CommandException(org.glassfish.api.admin.CommandException)

Example 8 with CommandException

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

the class ChangeNodeMasterPasswordCommand method encryptKeystore.

/*
     * This will encrypt the keystore
     */
public void encryptKeystore(String f) throws CommandException {
    RepositoryConfig nodeConfig = new RepositoryConfig(f, new File(nodeDir, node).toString(), f);
    NodeKeystoreManager km = new NodeKeystoreManager();
    try {
        km.encryptKeystore(nodeConfig, oldPassword, newPassword);
    } catch (Exception e) {
        throw new CommandException(strings.get("Keystore.not.encrypted"), e);
    }
}
Also used : RepositoryConfig(com.sun.enterprise.admin.servermgmt.RepositoryConfig) NodeKeystoreManager(com.sun.enterprise.admin.servermgmt.NodeKeystoreManager) CommandException(org.glassfish.api.admin.CommandException) File(java.io.File) MiniXmlParserException(com.sun.enterprise.universal.xml.MiniXmlParserException) CommandException(org.glassfish.api.admin.CommandException)

Example 9 with CommandException

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

the class CreateLocalInstanceCommand method executeCommand.

/**
 */
@Override
protected int executeCommand() throws CommandException, CommandValidationException {
    int exitCode = -1;
    if (node == null) {
        if (nodeDirChild == null)
            throw new CommandException(Strings.get("internal.error", "nodeDirChild was null.  The Base Class is supposed to " + "guarantee that this won't happen"));
        _node = nodeDirChild.getName();
        String nodeHost = getInstanceHostName(true);
        createNodeImplicit(_node, getProductRootPath(), nodeHost);
    } else {
        _node = node;
    }
    if (isRegisteredToDAS()) {
        if (!_rendezvousOccurred) {
            setRendezvousOccurred("true");
            _rendezvousOccurred = true;
        }
    } else {
        validateInstanceDirUnique();
        try {
            registerToDAS();
            _rendezvousOccurred = true;
        } catch (CommandException ce) {
            FileUtils.deleteFileNowOrLater(instanceDir);
            throw ce;
        }
    }
    bootstrapSecureAdminFiles();
    try {
        exitCode = super.executeCommand();
        if (exitCode == SUCCESS) {
            saveMasterPassword();
        }
    } catch (CommandException ce) {
        String msg = "Something went wrong in creating the local filesystem for instance " + instanceName;
        if (ce.getLocalizedMessage() != null) {
            msg = msg + ": " + ce.getLocalizedMessage();
        }
        logger.severe(msg);
        setRendezvousOccurred("false");
        _rendezvousOccurred = false;
        throw new CommandException(msg, ce);
    }
    return exitCode;
}
Also used : CommandException(org.glassfish.api.admin.CommandException)

Example 10 with CommandException

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

the class CreateLocalInstanceCommand method validateInstanceDirUnique.

private void validateInstanceDirUnique() throws CommandException {
    RemoteCLICommand rc = new RemoteCLICommand("list-instances", this.programOpts, this.env);
    String returnOutput = rc.executeAndReturnOutput("list-instances", "--nostatus", _node);
    if (returnOutput == null)
        return;
    String[] registeredInstanceNamesOnThisNode = returnOutput.split("\r?\n");
    for (String registeredInstanceName : registeredInstanceNamesOnThisNode) {
        File instanceListDir = new File(nodeDirChild, registeredInstanceName);
        if (instanceName != null && registeredInstanceName.equalsIgnoreCase(instanceName)) {
            if (instanceDir != null && instanceListDir.equals(instanceDir)) {
                throw new CommandException(Strings.get("Instance.duplicateInstanceDir", instanceName, registeredInstanceName));
            }
        }
    }
}
Also used : CommandException(org.glassfish.api.admin.CommandException) File(java.io.File) RemoteCLICommand(com.sun.enterprise.admin.cli.remote.RemoteCLICommand)

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