use of org.glassfish.api.admin.CommandException in project Payara by payara.
the class CreateLocalInstanceCommand method getInstanceHostName.
private String getInstanceHostName(boolean isCanonical) throws CommandException {
String instanceHostName = null;
InetAddress localHost = null;
try {
localHost = InetAddress.getLocalHost();
} catch (UnknownHostException ex) {
throw new CommandException(Strings.get("cantGetHostName", ex));
}
if (localHost != null) {
if (isCanonical) {
instanceHostName = localHost.getCanonicalHostName();
} else {
instanceHostName = localHost.getHostName();
}
}
return instanceHostName;
}
use of org.glassfish.api.admin.CommandException in project Payara by payara.
the class InstallNodeDcomCommand method unpackOnHosts.
private void unpackOnHosts(String host, String remotePassword, String unpackScript) throws WindowsException, CommandException {
String domain = windowsDomain;
if (!ok(domain))
domain = host;
WindowsCredentials bonafides = new WindowsCredentials(host, domain, getRemoteUser(), remotePassword);
WindowsRemoteScripter scripter = new WindowsRemoteScripter(bonafides);
String out = scripter.run(unpackScript);
if (out == null || out.length() < 50)
throw new CommandException(Strings.get("dcom.error.unpacking", unpackScript, out));
if (logger.isLoggable(Level.FINE))
logger.fine("Output from Windows Unpacker:\n" + out);
}
use of org.glassfish.api.admin.CommandException in project Payara by payara.
the class InstallNodeSshCommand method copyToHostsInternal.
private void copyToHostsInternal(File zipFile, ArrayList<String> binDirFiles) throws IOException, InterruptedException, CommandException {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
boolean prompt = promptPass;
for (String host : hosts) {
sshLauncher.init(getRemoteUser(), host, getRemotePort(), sshpassword, getSshKeyFile(), sshkeypassphrase, logger);
if (getSshKeyFile() != null && !sshLauncher.checkConnection()) {
// key auth failed, so use password auth
prompt = true;
}
if (prompt) {
String sshpass = null;
if (sshPasswords.containsKey(host))
sshpass = String.valueOf(sshPasswords.get(host));
else
sshpass = getSSHPassword(host);
// re-initialize
sshLauncher.init(getRemoteUser(), host, getRemotePort(), sshpass, getSshKeyFile(), sshkeypassphrase, logger);
prompt = false;
}
String sshInstallDir = getInstallDir().replace('\\', '/');
SFTPClient sftpClient = sshLauncher.getSFTPClient();
SCPClient scpClient = sshLauncher.getSCPClient();
try {
if (!sftpClient.exists(sshInstallDir)) {
sftpClient.mkdirs(sshInstallDir, 0755);
}
} catch (IOException ioe) {
logger.info(Strings.get("mkdir.failed", sshInstallDir, host));
throw new IOException(ioe);
}
// delete the sshInstallDir contents if non-empty
try {
// get list of file in DAS sshInstallDir
List<String> files = getListOfInstallFiles(sshInstallDir);
deleteRemoteFiles(sftpClient, files, sshInstallDir, getForce());
} catch (IOException ex) {
logger.finer("Failed to remove sshInstallDir contents");
throw new IOException(ex);
}
String zip = zipFile.getCanonicalPath();
try {
logger.info("Copying " + zip + " (" + zipFile.length() + " bytes)" + " to " + host + ":" + sshInstallDir);
// Looks like we need to quote the paths to scp in case they
// contain spaces.
scpClient.put(zipFile.getAbsolutePath(), FileUtils.quoteString(sshInstallDir));
if (logger.isLoggable(Level.FINER))
logger.finer("Copied " + zip + " to " + host + ":" + sshInstallDir);
} catch (IOException ex) {
logger.info(Strings.get("cannot.copy.zip.file", zip, host));
throw new IOException(ex);
}
try {
logger.info("Installing " + getArchiveName() + " into " + host + ":" + sshInstallDir);
String unzipCommand = "cd '" + sshInstallDir + "'; jar -xvf " + getArchiveName();
int status = sshLauncher.runCommand(unzipCommand, outStream);
if (status != 0) {
logger.info(Strings.get("jar.failed", host, outStream.toString()));
throw new CommandException("Remote command output: " + outStream.toString());
}
if (logger.isLoggable(Level.FINER))
logger.finer("Installed " + getArchiveName() + " into " + host + ":" + sshInstallDir);
} catch (IOException ioe) {
logger.info(Strings.get("jar.failed", host, outStream.toString()));
throw new IOException(ioe);
}
try {
logger.info("Removing " + host + ":" + sshInstallDir + "/" + getArchiveName());
sftpClient.rm(sshInstallDir + "/" + getArchiveName());
if (logger.isLoggable(Level.FINER))
logger.finer("Removed " + host + ":" + sshInstallDir + "/" + getArchiveName());
} catch (IOException ioe) {
logger.info(Strings.get("remove.glassfish.failed", host, sshInstallDir));
throw new IOException(ioe);
}
// unjarring doesn't retain file permissions, hence executables need
// to be fixed with proper permissions
logger.info("Fixing file permissions of all bin files under " + host + ":" + sshInstallDir);
try {
if (binDirFiles.isEmpty()) {
// binDirFiles can be empty if the archive isn't a fresh one
searchAndFixBinDirectoryFiles(sshInstallDir, sftpClient);
} else {
for (String binDirFile : binDirFiles) {
sftpClient.chmod((sshInstallDir + "/" + binDirFile), 0755);
}
}
if (logger.isLoggable(Level.FINER))
logger.finer("Fixed file permissions of all bin files " + "under " + host + ":" + sshInstallDir);
} catch (IOException ioe) {
logger.info(Strings.get("fix.permissions.failed", host, sshInstallDir));
throw new IOException(ioe);
}
if (Constants.v4) {
logger.info("Fixing file permissions for nadmin file under " + host + ":" + sshInstallDir + "/" + SystemPropertyConstants.getComponentName() + "/lib");
try {
sftpClient.chmod((sshInstallDir + "/" + SystemPropertyConstants.getComponentName() + "/lib/nadmin"), 0755);
if (logger.isLoggable(Level.FINER))
logger.finer("Fixed file permission for nadmin under " + host + ":" + sshInstallDir + "/" + SystemPropertyConstants.getComponentName() + "/lib/nadmin");
} catch (IOException ioe) {
logger.info(Strings.get("fix.permissions.failed", host, sshInstallDir));
throw new IOException(ioe);
}
}
sftpClient.close();
}
}
use of org.glassfish.api.admin.CommandException in project Payara by payara.
the class InstallNodeSshCommand method precopy.
@Override
final void precopy() throws CommandException {
if (getForce())
return;
boolean prompt = promptPass;
for (String host : hosts) {
sshLauncher.init(getRemoteUser(), host, getRemotePort(), sshpassword, getSshKeyFile(), sshkeypassphrase, logger);
if (getSshKeyFile() != null && !sshLauncher.checkConnection()) {
// key auth failed, so use password auth
prompt = true;
}
if (prompt) {
String sshpass = getSSHPassword(host);
sshPasswords.put(host, sshpass.toCharArray());
// re-initialize
sshLauncher.init(getRemoteUser(), host, getRemotePort(), sshpass, getSshKeyFile(), sshkeypassphrase, logger);
prompt = false;
}
String sshInstallDir = getInstallDir().replaceAll("\\\\", "/");
try {
SFTPClient sftpClient = sshLauncher.getSFTPClient();
if (sftpClient.exists(sshInstallDir)) {
checkIfAlreadyInstalled(host, sshInstallDir);
}
sftpClient.close();
} catch (IOException ex) {
throw new CommandException(ex);
} catch (InterruptedException ex) {
throw new CommandException(ex);
}
}
}
use of org.glassfish.api.admin.CommandException in project Payara by payara.
the class UninstallNodeSshCommand method deleteFromHosts.
@Override
void deleteFromHosts() throws CommandException {
SFTPClient sftpClient = null;
try {
List<String> files = getListOfInstallFiles(getInstallDir());
for (String host : hosts) {
sshLauncher.init(getRemoteUser(), host, getRemotePort(), sshpassword, sshkeyfile, sshkeypassphrase, logger);
if (sshkeyfile != null && !sshLauncher.checkConnection()) {
// key auth failed, so use password auth
promptPass = true;
}
if (promptPass) {
sshpassword = getSSHPassword(host);
// re-initialize
sshLauncher.init(getRemoteUser(), host, getRemotePort(), sshpassword, sshkeyfile, sshkeypassphrase, logger);
}
sftpClient = sshLauncher.getSFTPClient();
if (!sftpClient.exists(getInstallDir())) {
throw new IOException(getInstallDir() + " Directory does not exist");
}
deleteRemoteFiles(sftpClient, files, getInstallDir(), getForce());
if (isRemoteDirectoryEmpty(sftpClient, getInstallDir())) {
sftpClient.rmdir(getInstallDir());
}
sftpClient.close();
}
} catch (CommandException ce) {
throw ce;
} catch (Exception ex) {
throw new CommandException(ex);
} finally {
if (sftpClient != null) {
sftpClient.close();
}
}
}
Aggregations