Permalink
Browse files

misc bugs

git-svn-id: svn://svn.caucho.com/resin/trunk@8509 9c94448d-38f1-0310-a231-d98308ff1ebf
  • Loading branch information...
1 parent b34bf6b commit 0314b5baa9aac37e0823ae3fca56acbef3ef7920 ferg committed Oct 21, 2011
@@ -80,7 +80,7 @@ public int read(byte []buf, int offset, int length) throws IOException
break;
if (ch < 0x80)
- buf[i++] = (byte) ch;
+ buf[i++] = (byte) ch;
else if (ch < 0x800) {
if (i + 1 < end) {
}
@@ -29,6 +29,11 @@
package com.caucho.boot;
+import java.io.IOException;
+import java.net.Socket;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
import com.caucho.bam.NotAuthorizedException;
import com.caucho.config.ConfigException;
import com.caucho.env.repository.CommitBuilder;
@@ -38,6 +43,8 @@
public abstract class AbstractRepositoryCommand extends AbstractBootCommand {
private static final L10N L = new L10N(AbstractRepositoryCommand.class);
+ private static final Logger log
+ = Logger.getLogger(AbstractRepositoryCommand.class.getName());
@Override
public final int doCommand(WatchdogArgs args,
@@ -49,7 +56,7 @@ public final int doCommand(WatchdogArgs args,
try {
deployClient = getDeployClient(args, client);
- return doCommand(args, client, deployClient);
+ return doCommand(args, client, deployClient);
} catch (Exception e) {
if (args.isVerbose())
e.printStackTrace();
@@ -97,9 +104,6 @@ protected WebAppDeployClient getDeployClient(WatchdogArgs args,
{
String address = args.getArg("-address");
- if (address == null || address.isEmpty())
- address = client.getConfig().getAddress();
-
int port = -1;
String portArg = args.getArg("-port");
@@ -113,9 +117,17 @@ protected WebAppDeployClient getDeployClient(WatchdogArgs args,
throw e;
}
+
+ WatchdogClient liveClient = client;
+
+ if (address == null || address.isEmpty()) {
+ liveClient = findLiveClient(client, port);
+
+ address = liveClient.getConfig().getAddress();
+ }
if (port == -1)
- port = findPort(client);
+ port = findPort(liveClient);
if (port == 0) {
throw new ConfigException(L.l("HTTP listener {0}:{1} was not found",
@@ -133,6 +145,43 @@ protected WebAppDeployClient getDeployClient(WatchdogArgs args,
return new WebAppDeployClient(address, port, user, password);
}
+ private WatchdogClient findLiveClient(WatchdogClient client, int port)
+ {
+ for (WatchdogClient triad : client.getConfig().getCluster().getClients()) {
+ int triadPort = port;
+
+ if (triadPort <= 0)
+ triadPort = findPort(triad);
+
+ if (clientCanConnect(triad, triadPort)) {
+ return triad;
+ }
+
+ if (triad.getIndex() > 2)
+ break;
+ }
+
+ return client;
+ }
+
+ private boolean clientCanConnect(WatchdogClient client, int port)
+ {
+ String address = client.getConfig().getAddress();
+ int clusterPort = client.getConfig().getPort();
+
+ try {
+ Socket s = new Socket(address, clusterPort);
+
+ s.close();
+
+ return true;
+ } catch (IOException e) {
+ log.log(Level.FINER, e.toString(), e);
+
+ return false;
+ }
+ }
+
private int findPort(WatchdogClient client)
{
for (TcpSocketLinkListener listener : client.getConfig().getPorts()) {
@@ -29,17 +29,15 @@
package com.caucho.boot;
-import com.caucho.admin.ElasticCloudServiceMarker;
+import java.util.ArrayList;
+
import com.caucho.config.ConfigException;
import com.caucho.config.program.ConfigProgram;
import com.caucho.config.program.ContainerProgram;
import com.caucho.env.service.ResinSystem;
-
import com.caucho.util.L10N;
import com.caucho.xml.QName;
-import java.util.ArrayList;
-
public class BootClusterConfig {
private static final L10N L = new L10N(BootClusterConfig.class);
@@ -53,6 +51,9 @@
private ArrayList<ContainerProgram> _serverDefaultList
= new ArrayList<ContainerProgram>();
+
+ private ArrayList<WatchdogClient> _serverList
+ = new ArrayList<WatchdogClient>();
BootClusterConfig(ResinSystem system,
BootResinConfig resin)
@@ -97,7 +98,9 @@ public void addManagement(BootManagementConfig management)
public WatchdogConfig createServer()
{
WatchdogConfig config
- = new WatchdogConfig(this, _resin.getArgs(), _resin.getRootDirectory());
+ = new WatchdogConfig(this, _resin.getArgs(),
+ _resin.getRootDirectory(),
+ _serverList.size());
for (int i = 0; i < _serverDefaultList.size(); i++)
_serverDefaultList.get(i).configure(config);
@@ -116,7 +119,16 @@ public void addServer(WatchdogConfig config)
config.getId()));
_resin.addServer(config);
- _resin.addClient(new WatchdogClient(_system, _resin, config));
+
+ WatchdogClient client = new WatchdogClient(_system, _resin, config);
+ _resin.addClient(client);
+
+ _serverList.add(client);
+ }
+
+ public ArrayList<WatchdogClient> getClients()
+ {
+ return _serverList;
}
public void addStdoutLog(ContainerProgram config)
@@ -199,14 +199,27 @@ public WatchdogClient findClient(String id)
/**
* Finds a server.
*/
- public WatchdogClient findShutdownClient()
+ public WatchdogClient findShutdownClient(String clusterId)
{
+ WatchdogClient bestClient = null;
+
for (WatchdogClient client : _watchdogMap.values()) {
- if (client != null)
- return client;
+ if (client == null)
+ continue;
+
+ if (clusterId != null && ! clusterId.equals(client.getClusterId()))
+ continue;
+
+ if (bestClient == null || client.getIndex() < bestClient.getIndex())
+ bestClient = client;
}
- return null;
+ return bestClient;
+ }
+
+ public int getNextIndex()
+ {
+ return _watchdogMap.size();
}
/**
@@ -173,11 +173,11 @@ private void initClient(BootResinConfig bootManager)
}
if (_client == null && _args.isShutdown()) {
- _client = bootManager.findShutdownClient();
+ _client = bootManager.findShutdownClient(_args.getClusterId());
}
if (_client == null && ! (_args.isStart() || _args.isConsole())) {
- _client = bootManager.findShutdownClient();
+ _client = bootManager.findShutdownClient(_args.getClusterId());
}
if (_client == null) {
@@ -186,7 +186,8 @@ private void initClient(BootResinConfig bootManager)
}
}
- BootCommand getCommand() {
+ BootCommand getCommand()
+ {
return _commandMap.get(_args.getStartMode());
}
@@ -57,17 +57,23 @@ public int doCommand(WatchdogArgs args, WatchdogClient _client)
validateArgs(args.getArgv());
try {
- _client.restartWatchdog(args.getArgv());
+ String id = args.getServerId();
+
+ if (id == null)
+ id = _client.getId();
+
+ _client.restartWatchdog(id, args.getArgv());
System.out.println(L().l(
"Resin/{0} restarted -server '{1}' for watchdog at {2}:{3}",
VersionFactory.getVersion(),
- _client.getId(),
+ args.getServerId(),
_client.getWatchdogAddress(),
_client.getWatchdogPort()));
} catch (Exception e) {
System.out.println(L().l("Resin/{0} can't restart -server '{1}'.\n{2}",
- VersionFactory.getVersion(), _client.getId(),
+ VersionFactory.getVersion(),
+ args.getServerId(),
e.toString()));
log().log(Level.FINE, e.toString(), e);
@@ -65,6 +65,7 @@
private Path _resinConf;
private Path _logDirectory;
private String _serverId = "";
+ private String _clusterId;
private int _watchdogPort;
private boolean _isVerbose;
private boolean _isHelp;
@@ -147,6 +148,11 @@ String getServerId()
return _serverId;
}
+ String getClusterId()
+ {
+ return _clusterId;
+ }
+
String[] getArgv()
{
return _argv;
@@ -455,6 +461,10 @@ else if ("-server".equals(arg) || "--server".equals(arg)) {
_serverId = argv[i + 1];
i++;
}
+ else if ("-cluster".equals(arg) || "--cluster".equals(arg)) {
+ _clusterId = argv[i + 1];
+ i++;
+ }
else if ("-server-root".equals(arg) || "--server-root".equals(arg)) {
_rootDirectory = Vfs.lookup(argv[i + 1]);
argv[i + 1] = _rootDirectory.getFullPath();
@@ -75,12 +75,13 @@
ResinSystem system,
WatchdogArgs args,
Path rootDirectory,
- BootClusterConfig cluster)
+ BootClusterConfig cluster,
+ int index)
{
_id = id;
_system = system;
- _config = new WatchdogConfig(cluster, args, rootDirectory);
+ _config = new WatchdogConfig(cluster, args, rootDirectory, index);
_admin = new WatchdogAdmin();
}
@@ -89,6 +90,7 @@
WatchdogConfig config)
{
_id = config.getId();
+
_config = config;
_admin = new WatchdogAdmin();
@@ -435,6 +437,16 @@ public void stop()
}
/**
+ * Stops the watchdog instance
+ */
+ public void restart()
+ {
+ stop();
+
+ start();
+ }
+
+ /**
* Kills the watchdog instance
*/
public void kill()
@@ -94,6 +94,16 @@ public String getId()
{
return _id;
}
+
+ public String getClusterId()
+ {
+ return _config.getCluster().getId();
+ }
+
+ public int getIndex()
+ {
+ return _config.getIndex();
+ }
public String getWatchdogAddress()
{
@@ -317,22 +327,26 @@ public void killWatchdog(String serverId)
}
}
- public void restartWatchdog(String []argv)
+ public void restartWatchdog(String id, String []argv)
throws IOException
{
- try {
- stopWatchdog(getId());
- } catch (Exception e) {
- log.log(Level.FINE, e.toString(), e);
- }
+ // cloud/1295
+ ActorSender conn = getConnection();
try {
- Thread.sleep(5000);
+ ResultStatus status = (ResultStatus)
+ conn.query(WATCHDOG_ADDRESS,
+ new WatchdogRestartQuery(id, argv),
+ BAM_TIMEOUT);
+
+ if (! status.isSuccess())
+ throw new RuntimeException(L.l("{0}: watchdog restartfailed because of '{1}'",
+ this, status.getMessage()));
+ } catch (RuntimeException e) {
+ throw e;
} catch (Exception e) {
log.log(Level.FINE, e.toString(), e);
}
-
- startWatchdog(argv);
}
public boolean shutdown()
Oops, something went wrong.

0 comments on commit 0314b5b

Please sign in to comment.