use of com.sun.enterprise.util.HostAndPort in project Payara by payara.
the class SunDeploymentManager method addToTargetModuleIDs.
/**
*Augments a Collection of TargetModuleIDs with new entries for target module IDs of a given module type on the specified target.
*@param tmids array of TargetModuleIDs
*@param type the ModuleType of interest
*@param targetImpl the TargetImpl from which to retrieve modules of the selected type
*@param resultingTMIDs pre-instantiated List to which TargetModuleIDs will be added
*/
private void addToTargetModuleIDs(TargetModuleID[] tmids, ModuleType type, TargetImpl targetImpl, Collection resultingTMIDs) throws IOException {
for (int j = 0; j < tmids.length; j++) {
// Get the host name and port where the application was deployed
HostAndPort webHost = deploymentFacility.getHostAndPort(targetImpl.getName(), tmids[j].getModuleID(), false);
if (tmids[j] instanceof TargetModuleIDImpl) {
((TargetModuleIDImpl) tmids[j]).setModuleType(type);
}
resultingTMIDs.add(tmids[j]);
/*
*Set additional information on the target module ID, depending on what type of
*module this is. For J2EE apps, this includes constructing sub TargetModuleIDs.
*/
try {
if (type.equals(ModuleType.EAR)) {
setJ2EEApplicationTargetModuleIDInfo(tmids[j], webHost);
} else if (type.equals(ModuleType.WAR)) {
setWebApplicationTargetModuleIDInfo(tmids[j], webHost);
}
} catch (Exception exp) {
Logger.getAnonymousLogger().log(Level.WARNING, exp.getLocalizedMessage(), exp);
}
}
}
use of com.sun.enterprise.util.HostAndPort 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 com.sun.enterprise.util.HostAndPort 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.
*
* @param serverName the server name
* @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.isEmpty()) {
return addrSet.get(0);
} else {
throw new CommandException(STRINGS.get("NoAdminPort"));
}
} catch (MiniXmlParserException ex) {
throw new CommandException(STRINGS.get("NoAdminPortEx", ex), ex);
}
}
use of com.sun.enterprise.util.HostAndPort in project Payara by payara.
the class StartServerHelper method waitForServer.
public void waitForServer(long timeout, TimeUnit unit) 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, unit.toMillis(timeout))) {
if (pidFile != null) {
logger.log(FINER, "Check for pid file: {0}", pidFile);
if (pidFile.exists()) {
alive = true;
break pinged;
}
} else {
// If it is, the DAS is up
for (HostAndPort address : addresses) {
if (isRunning(address.getHost(), address.getPort())) {
alive = true;
break pinged;
}
}
}
// If it isn't, startup failed.
try {
int exitCode = launcher.getProcess().exitValue();
// If we reach this location, there's an exit code, so uh oh, DAS died
// If the DAS is still alive an exception is thrown here
String sname;
if (info.isDomain()) {
sname = "domain " + info.getDomainName();
} else {
sname = "instance " + info.getInstanceName();
}
String output = launcher.getProcessStreamDrainer().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 = "" + unit.toSeconds(timeout);
if (info.isDomain()) {
msg = STRINGS.get("serverNoStart", STRINGS.get("DAS"), info.getDomainName(), time);
} else {
// e.g. No response from the Instance Server (instance1) after 600 seconds.
msg = STRINGS.get("serverNoStart", STRINGS.get("INSTANCE"), info.getInstanceName(), time);
}
throw new CommandException(msg);
}
}
use of com.sun.enterprise.util.HostAndPort in project Payara by payara.
the class GetHostAndPortCommand method execute.
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
ActionReport.MessagePart part = report.getTopMessagePart();
HttpService httpService = null;
HostAndPort hostAndPort = null;
try {
if (config == null) {
throw new Exception("No such target:" + target);
}
httpService = config.getHttpService();
if (httpService != null) {
hostAndPort = getHostAndPortForRequest(httpService);
}
} catch (Exception e) {
report.setMessage(e.getMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (hostAndPort != null) {
part.setMessage(hostAndPort.getHost() + ":" + hostAndPort.getPort());
// property for REST Access
part.addProperty("host", hostAndPort.getHost());
// property for REST Access
part.addProperty("port", "" + hostAndPort.getPort());
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations