use of com.sun.enterprise.util.HostAndPort in project Payara by payara.
the class GetHostAndPortTest method testGetHostAndPortTest.
@Ignore
@Test
public void testGetHostAndPortTest() {
System.out.println("testGetHostAndPortTest");
DeploymentFacility df = DeploymentFacilityFactory.getDeploymentFacility();
ServerConnectionIdentifier sci = new ServerConnectionIdentifier();
sci.setHostName("localhost");
// 8080 for the REST client
sci.setHostPort(4848);
sci.setUserName("admin");
sci.setPassword("");
df.connect(sci);
try {
HostAndPort hap1 = df.getHostAndPort("server", "webapps-simple", false);
System.out.println("Host1 returned:" + hap1.getHost());
System.out.println("Port1 returned:" + hap1.getPort());
HostAndPort hap2 = df.getVirtualServerHostAndPort("server", "__asadmin", false);
System.out.println("Host2 returned:" + hap2.getHost());
System.out.println("Port2 returned:" + hap2.getPort());
HostAndPort hap3 = df.getHostAndPort("server", false);
System.out.println("Host3 returned:" + hap3.getHost());
System.out.println("Port3 returned:" + hap3.getPort());
HostAndPort hap4 = df.getHostAndPort("foo", false);
System.out.println("hap4:" + hap4);
} catch (Exception e) {
fail("Failed due to exception " + e.getMessage());
}
}
use of com.sun.enterprise.util.HostAndPort 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);
}
}
use of com.sun.enterprise.util.HostAndPort 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);
}
}
use of com.sun.enterprise.util.HostAndPort in project Payara by payara.
the class RestartLocalInstanceCommand method executeCommand.
@Override
protected int executeCommand() throws CommandException {
if (logger.isLoggable(Level.FINER)) {
logger.finer(toString());
}
File serverDir = getServerDirs().getServerDir();
if (serverDir == null || !serverDir.isDirectory()) {
return noSuchInstance();
}
String serverName = getServerDirs().getServerName();
HostAndPort addr = getAdminAddress(serverName);
if (!isRunning() && !isRunning(addr.getHost(), addr.getPort())) {
return instanceNotRunning();
}
if (sync.equals("none")) {
logger.info(Strings.get("Instance.nosync"));
} else if (!synchronizeInstance()) {
File domainXml = new File(new File(instanceDir, "config"), "domain.xml");
if (!domainXml.exists()) {
logger.info(Strings.get("Instance.nodomainxml"));
return ERROR;
}
logger.info(Strings.get("Instance.syncFailed"));
}
programOpts.setHostAndPort(addr);
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, "Stopping server at {0}", addr.toString());
}
logger.finer("It's the correct Instance");
return doRemoteCommand();
}
use of com.sun.enterprise.util.HostAndPort in project Payara by payara.
the class MiniXmlParserTest method testOldSchema.
@Test
public void testOldSchema() throws MiniXmlParserException {
final MiniXmlParser parser = new MiniXmlParser(new File(getClass().getClassLoader().getResource("olddomain.xml").getPath()), "server");
List<HostAndPort> addrs = parser.getAdminAddresses();
assertEquals(1, addrs.size());
}
Aggregations