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);
}
}
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);
}
}
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);
}
}
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;
}
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));
}
}
}
}
Aggregations