Slim MfApi stack to restart-only path.
Drop ping/list discovery, WinRM scripts, and heavy Java probing so only KnownContainers + MBean restart remain. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,27 +1,15 @@
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.management.MBeanOperationInfo;
|
||||
import javax.management.MBeanInfo;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
/**
|
||||
* Sonic Management Application API helper (same restart intent as SMC).
|
||||
*
|
||||
* TOOL_VERSION is printed first so we can verify the deployed build.
|
||||
*
|
||||
* Remote JMSConnectorClient is "unbounded". IAgentProxy.restart() often throws
|
||||
* "Operation unsupported for unbounded client connector". SMC Restart typically
|
||||
* stops the agent via JMX; Launch Daemon brings it back.
|
||||
*
|
||||
* Minimaler Sonic-Restart (wie SMC): JMSConnectorClient + MBean stop/restart.
|
||||
* Compile: javac --release 8 SonicMfContainerTool.java
|
||||
*/
|
||||
public final class SonicMfContainerTool
|
||||
{
|
||||
/** Bump when restart logic changes – must appear in app output. */
|
||||
public static final String TOOL_VERSION = "2026-07-24c-mbean-stop";
|
||||
public static final String TOOL_VERSION = "2026-07-24d-restart-only";
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
@@ -29,21 +17,14 @@ public final class SonicMfContainerTool
|
||||
try
|
||||
{
|
||||
Args a = Args.parse(args);
|
||||
if (a.command == null)
|
||||
if (!"restart".equals(a.command))
|
||||
{
|
||||
fail("Usage: SonicMfContainerTool ping|list|restart --domain D --url U --user U [--password P] [--container C] [--timeout SEC]");
|
||||
fail("Usage: SonicMfContainerTool restart --domain D --url U --user U --container C [--timeout SEC]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isBlank(a.domain) || isBlank(a.url) || isBlank(a.user))
|
||||
if (isBlank(a.domain) || isBlank(a.url) || isBlank(a.user) || isBlank(a.container))
|
||||
{
|
||||
fail("domain, url und user sind Pflicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ("restart".equals(a.command) && isBlank(a.container))
|
||||
{
|
||||
fail("restart erfordert --container.");
|
||||
fail("domain, url, user und container sind Pflicht.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,22 +32,7 @@ public final class SonicMfContainerTool
|
||||
Object connector = connect(a.url, a.user, a.password, timeoutMs);
|
||||
try
|
||||
{
|
||||
if ("ping".equals(a.command))
|
||||
{
|
||||
ping(connector, a.domain);
|
||||
}
|
||||
else if ("list".equals(a.command))
|
||||
{
|
||||
list(connector, a.domain);
|
||||
}
|
||||
else if ("restart".equals(a.command))
|
||||
{
|
||||
restart(connector, a.domain, a.container);
|
||||
}
|
||||
else
|
||||
{
|
||||
fail("Unbekannter Befehl: " + a.command);
|
||||
}
|
||||
restart(connector, a.domain, a.container);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -86,8 +52,7 @@ public final class SonicMfContainerTool
|
||||
}
|
||||
}
|
||||
|
||||
private static Object connect(String url, String user, String password, long timeoutMs)
|
||||
throws Exception
|
||||
private static Object connect(String url, String user, String password, long timeoutMs) throws Exception
|
||||
{
|
||||
Hashtable env = new Hashtable();
|
||||
env.put("ConnectionURLs", url);
|
||||
@@ -99,8 +64,6 @@ public final class SonicMfContainerTool
|
||||
|
||||
Class clientCl = Class.forName("com.sonicsw.mf.jmx.client.JMSConnectorClient");
|
||||
Object connector = clientCl.getConstructor(new Class[] {}).newInstance(new Object[] {});
|
||||
|
||||
// Optional: Request-Timeout setzen (falls vorhanden)
|
||||
trySetTimeout(connector, timeoutMs);
|
||||
|
||||
Method connect = findConnect(clientCl);
|
||||
@@ -111,199 +74,34 @@ public final class SonicMfContainerTool
|
||||
}
|
||||
|
||||
Class[] pts = connect.getParameterTypes();
|
||||
Object[] callArgs;
|
||||
if (pts.length == 2)
|
||||
{
|
||||
callArgs = new Object[] { address, boxTimeout(pts[1], timeoutMs) };
|
||||
}
|
||||
else if (pts.length == 1)
|
||||
{
|
||||
callArgs = new Object[] { address };
|
||||
connect.invoke(connector, new Object[] { address, boxTimeout(pts[1], timeoutMs) });
|
||||
}
|
||||
else
|
||||
{
|
||||
callArgs = new Object[] { address, boxTimeout(pts[1], timeoutMs) };
|
||||
connect.invoke(connector, new Object[] { address });
|
||||
}
|
||||
|
||||
connect.invoke(connector, callArgs);
|
||||
info("Connected url=" + url + " user=" + user);
|
||||
return connector;
|
||||
}
|
||||
|
||||
private static Method findConnect(Class clientCl)
|
||||
{
|
||||
Method best = null;
|
||||
Method[] methods = clientCl.getMethods();
|
||||
for (int i = 0; i < methods.length; i++)
|
||||
{
|
||||
Method m = methods[i];
|
||||
if (!"connect".equals(m.getName()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (m.getParameterTypes().length == 2)
|
||||
{
|
||||
return m;
|
||||
}
|
||||
if (m.getParameterTypes().length == 1)
|
||||
{
|
||||
best = m;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
private static void trySetTimeout(Object connector, long timeoutMs)
|
||||
{
|
||||
String[] names = new String[] { "setTimeout", "setRequestTimeout", "setDefaultTimeout" };
|
||||
for (int i = 0; i < names.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
Method m = connector.getClass().getMethod(names[i], new Class[] { Long.TYPE });
|
||||
m.invoke(connector, new Object[] { Long.valueOf(timeoutMs) });
|
||||
info("Set " + names[i] + "=" + timeoutMs);
|
||||
return;
|
||||
}
|
||||
catch (NoSuchMethodException ignore)
|
||||
{
|
||||
try
|
||||
{
|
||||
Method m = connector.getClass().getMethod(names[i], new Class[] { Integer.TYPE });
|
||||
m.invoke(connector, new Object[] { Integer.valueOf((int) Math.min(Integer.MAX_VALUE, timeoutMs)) });
|
||||
info("Set " + names[i] + "=" + timeoutMs);
|
||||
return;
|
||||
}
|
||||
catch (Exception ignore2)
|
||||
{
|
||||
/* next */
|
||||
}
|
||||
}
|
||||
catch (Exception ignore)
|
||||
{
|
||||
/* next */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Object boxTimeout(Class type, long timeoutMs)
|
||||
{
|
||||
if (type == Long.TYPE || type == Long.class)
|
||||
{
|
||||
return Long.valueOf(timeoutMs);
|
||||
}
|
||||
if (type == Integer.TYPE || type == Integer.class)
|
||||
{
|
||||
return Integer.valueOf((int) Math.min(Integer.MAX_VALUE, timeoutMs));
|
||||
}
|
||||
return Long.valueOf(timeoutMs);
|
||||
}
|
||||
|
||||
private static void ping(Object connector, String domain) throws Exception
|
||||
{
|
||||
Set names = queryAgents(connector);
|
||||
int matched = 0;
|
||||
if (names != null)
|
||||
{
|
||||
for (Iterator it = names.iterator(); it.hasNext(); )
|
||||
{
|
||||
ObjectName on = (ObjectName) it.next();
|
||||
if (extractContainer(on, domain) != null)
|
||||
{
|
||||
matched++;
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("OK:MfApiPing domain=" + domain + " agents=" + matched);
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
private static void list(Object connector, String domain) throws Exception
|
||||
{
|
||||
Set names = queryAgents(connector);
|
||||
int count = 0;
|
||||
if (names != null)
|
||||
{
|
||||
for (Iterator it = names.iterator(); it.hasNext(); )
|
||||
{
|
||||
ObjectName on = (ObjectName) it.next();
|
||||
String container = extractContainer(on, domain);
|
||||
if (container != null)
|
||||
{
|
||||
System.out.println(container);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
info("KeineAgentContainer Domain=" + domain);
|
||||
}
|
||||
System.out.println("OK:List count=" + count);
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
private static void restart(Object connector, String domain, String container) throws Exception
|
||||
{
|
||||
String shortName = shortContainer(container);
|
||||
// Zuerst Preferred-ObjectName OHNE queryNames – query kann schon scheitern/irreführen
|
||||
ObjectName preferred = new ObjectName(domain + "." + shortName + ":ID=AGENT");
|
||||
info("PreferredObjectName=" + preferred);
|
||||
|
||||
ObjectName on = preferred;
|
||||
try
|
||||
{
|
||||
ObjectName resolved = resolveAgentObjectName(connector, domain, shortName);
|
||||
if (resolved != null)
|
||||
{
|
||||
on = resolved;
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
warn("resolveAgentObjectName: " + rootOf(t).getClass().getName() + ": " + rootOf(t).getMessage()
|
||||
+ " – nutze PreferredObjectName");
|
||||
}
|
||||
ObjectName on = new ObjectName(domain + "." + shortName + ":ID=AGENT");
|
||||
info("ObjectName=" + on);
|
||||
|
||||
dumpOpsSafe(connector, on);
|
||||
|
||||
StringBuffer attempts = new StringBuffer();
|
||||
|
||||
// 1) JMX invoke stop/restart/shutdown (remote / wie SMC)
|
||||
if (tryMBeanLifecycle(connector, on, shortName, domain, attempts))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 2) IAgentProxy stop/restart
|
||||
if (tryAgentProxyLifecycle(connector, on, shortName, domain, attempts))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 3) Manager-MBeans mit Container-Namen
|
||||
if (tryManagerContainerOps(connector, domain, shortName, attempts))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fail("Kein Neustart-Weg erfolgreich. ToolVersion=" + TOOL_VERSION + "\nAttempts:\n" + attempts.toString());
|
||||
}
|
||||
|
||||
private static boolean tryMBeanLifecycle(
|
||||
Object connector, ObjectName on, String shortName, String domain, StringBuffer attempts)
|
||||
{
|
||||
String[] ops = new String[] { "stop", "restart", "shutdown" };
|
||||
String[] ops = new String[] { "stop", "restart" };
|
||||
for (int i = 0; i < ops.length; i++)
|
||||
{
|
||||
String op = ops[i];
|
||||
try
|
||||
{
|
||||
info("Trying MBean.invoke(" + op + ") on " + on);
|
||||
info("Trying MBean.invoke(" + op + ")");
|
||||
invokeNoArgs(connector, on, op);
|
||||
okRestart("MBean." + op, shortName, domain);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
@@ -311,162 +109,23 @@ public final class SonicMfContainerTool
|
||||
String line = "MBean." + op + " => " + root.getClass().getName() + ": " + root.getMessage();
|
||||
warn(line);
|
||||
attempts.append(line).append('\n');
|
||||
|
||||
// stop kann die Verbindung reissen – wenn Message darauf hindeutet, als Erfolg werten
|
||||
if ("stop".equals(op) && looksLikeStopSideEffect(root))
|
||||
{
|
||||
warn("Treat stop side-effect as success (agent going down)");
|
||||
okRestart("MBean.stop(side-effect)", shortName, domain);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
fail("Neustart fehlgeschlagen. ToolVersion=" + TOOL_VERSION + "\nAttempts:\n" + attempts.toString());
|
||||
}
|
||||
|
||||
private static boolean tryAgentProxyLifecycle(
|
||||
Object connector, ObjectName on, String shortName, String domain, StringBuffer attempts)
|
||||
private static void invokeNoArgs(Object connector, ObjectName on, String op) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
Class factoryCl = Class.forName("com.sonicsw.mf.mgmtapi.runtime.MFProxyFactory");
|
||||
Method create = factoryCl.getMethod("createAgentProxy", new Class[] {
|
||||
Class.forName("com.sonicsw.mf.jmx.client.JMSConnectorClient"),
|
||||
ObjectName.class
|
||||
});
|
||||
Object agent = create.invoke(null, new Object[] { connector, on });
|
||||
info("StateBefore=" + safeState(agent));
|
||||
|
||||
String[] methods = new String[] { "stop", "restart", "shutdown" };
|
||||
for (int i = 0; i < methods.length; i++)
|
||||
{
|
||||
String mName = methods[i];
|
||||
try
|
||||
{
|
||||
info("Trying IAgentProxy." + mName);
|
||||
agent.getClass().getMethod(mName).invoke(agent);
|
||||
okRestart("IAgentProxy." + mName, shortName, domain);
|
||||
return true;
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
Throwable root = rootOf(t);
|
||||
String line = "IAgentProxy." + mName + " => " + root.getClass().getName() + ": " + root.getMessage();
|
||||
warn(line);
|
||||
attempts.append(line).append('\n');
|
||||
if ("stop".equals(mName) && looksLikeStopSideEffect(root))
|
||||
{
|
||||
okRestart("IAgentProxy.stop(side-effect)", shortName, domain);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
Throwable root = rootOf(t);
|
||||
String line = "IAgentProxy path => " + root.getClass().getName() + ": " + root.getMessage();
|
||||
warn(line);
|
||||
attempts.append(line).append('\n');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean tryManagerContainerOps(
|
||||
Object connector, String domain, String shortName, StringBuffer attempts)
|
||||
{
|
||||
String[] candidates = new String[] {
|
||||
domain + ".DomainManager:ID=DomainManager",
|
||||
domain + ".DomainManager:ID=AGENT",
|
||||
domain + ".dm:ID=AGENT"
|
||||
};
|
||||
|
||||
for (int i = 0; i < candidates.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
ObjectName pattern = new ObjectName(candidates[i]);
|
||||
Set found = queryNames(connector, pattern);
|
||||
if (found == null || found.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ObjectName real = (ObjectName) found.iterator().next();
|
||||
info("Manager=" + real);
|
||||
dumpOpsSafe(connector, real);
|
||||
|
||||
String[] ops = new String[] { "restartContainer", "stopContainer", "startContainer" };
|
||||
for (int o = 0; o < ops.length; o++)
|
||||
{
|
||||
try
|
||||
{
|
||||
info("Trying " + ops[o] + "(\"" + shortName + "\") on " + real);
|
||||
invokeStringArg(connector, real, ops[o], shortName);
|
||||
okRestart("Manager." + ops[o], shortName, domain);
|
||||
return true;
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
Throwable root = rootOf(t);
|
||||
String line = ops[o] + " => " + root.getClass().getName() + ": " + root.getMessage();
|
||||
warn(line);
|
||||
attempts.append(line).append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
warn("Manager candidate " + candidates[i] + ": " + rootOf(t).getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Scan AGENT-MBeans nach Container-Ops
|
||||
try
|
||||
{
|
||||
Set agents = queryAgents(connector);
|
||||
if (agents == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (Iterator it = agents.iterator(); it.hasNext(); )
|
||||
{
|
||||
ObjectName on = (ObjectName) it.next();
|
||||
String jmxDomain = on.getDomain();
|
||||
if (jmxDomain == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String lower = jmxDomain.toLowerCase();
|
||||
if (!(lower.contains("domainmanager") || lower.contains(".dm")
|
||||
|| lower.contains("collector") || lower.contains("host")
|
||||
|| lower.contains("launch")))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
info("Scan manager agent " + on);
|
||||
dumpOpsSafe(connector, on);
|
||||
String[] ops = new String[] { "restartContainer", "stopContainer" };
|
||||
for (int i = 0; i < ops.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
invokeStringArg(connector, on, ops[i], shortName);
|
||||
okRestart(ops[i] + "@" + on, shortName, domain);
|
||||
return true;
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
attempts.append(ops[i]).append('@').append(on).append(" => ")
|
||||
.append(rootOf(t).getMessage()).append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
warn("Manager scan: " + rootOf(t).getMessage());
|
||||
}
|
||||
return false;
|
||||
Method invoke = connector.getClass().getMethod("invoke", new Class[] {
|
||||
ObjectName.class, String.class, Object[].class, String[].class
|
||||
});
|
||||
invoke.invoke(connector, new Object[] { on, op, new Object[0], new String[0] });
|
||||
}
|
||||
|
||||
private static boolean looksLikeStopSideEffect(Throwable root)
|
||||
@@ -479,8 +138,7 @@ public final class SonicMfContainerTool
|
||||
return m.indexOf("disconnect") >= 0
|
||||
|| m.indexOf("closed") >= 0
|
||||
|| m.indexOf("not connected") >= 0
|
||||
|| m.indexOf("connection lost") >= 0
|
||||
|| m.indexOf("broker") >= 0 && m.indexOf("down") >= 0;
|
||||
|| m.indexOf("connection lost") >= 0;
|
||||
}
|
||||
|
||||
private static void okRestart(String method, String shortName, String domain)
|
||||
@@ -491,172 +149,75 @@ public final class SonicMfContainerTool
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
private static void invokeNoArgs(Object connector, ObjectName on, String op) throws Exception
|
||||
private static Method findConnect(Class clientCl)
|
||||
{
|
||||
Method invoke = connector.getClass().getMethod("invoke", new Class[] {
|
||||
ObjectName.class, String.class, Object[].class, String[].class
|
||||
});
|
||||
invoke.invoke(connector, new Object[] { on, op, new Object[0], new String[0] });
|
||||
Method[] methods = clientCl.getMethods();
|
||||
Method best = null;
|
||||
for (int i = 0; i < methods.length; i++)
|
||||
{
|
||||
Method m = methods[i];
|
||||
if (!"connect".equals(m.getName()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Class[] pts = m.getParameterTypes();
|
||||
if (pts.length == 1 || pts.length == 2)
|
||||
{
|
||||
best = m;
|
||||
if (pts.length == 2)
|
||||
{
|
||||
return m;
|
||||
}
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
private static void invokeStringArg(Object connector, ObjectName on, String op, String arg) throws Exception
|
||||
{
|
||||
Method invoke = connector.getClass().getMethod("invoke", new Class[] {
|
||||
ObjectName.class, String.class, Object[].class, String[].class
|
||||
});
|
||||
invoke.invoke(connector, new Object[] {
|
||||
on, op, new Object[] { arg }, new String[] { "java.lang.String" }
|
||||
});
|
||||
}
|
||||
|
||||
private static void dumpOpsSafe(Object connector, ObjectName on)
|
||||
private static void trySetTimeout(Object connector, long timeoutMs)
|
||||
{
|
||||
try
|
||||
{
|
||||
Method getInfo = connector.getClass().getMethod("getMBeanInfo", new Class[] { ObjectName.class });
|
||||
MBeanInfo infoBean = (MBeanInfo) getInfo.invoke(connector, new Object[] { on });
|
||||
if (infoBean == null || infoBean.getOperations() == null)
|
||||
connector.getClass().getMethod("setTimeout", new Class[] { Long.TYPE })
|
||||
.invoke(connector, new Object[] { Long.valueOf(timeoutMs) });
|
||||
}
|
||||
catch (Exception ignore)
|
||||
{
|
||||
try
|
||||
{
|
||||
info("Ops(" + on + ")=(null)");
|
||||
return;
|
||||
connector.getClass().getMethod("setRequestTimeout", new Class[] { Long.TYPE })
|
||||
.invoke(connector, new Object[] { Long.valueOf(timeoutMs) });
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
MBeanOperationInfo[] ops = infoBean.getOperations();
|
||||
for (int i = 0; i < ops.length; i++)
|
||||
catch (Exception ignore2)
|
||||
{
|
||||
String name = ops[i].getName();
|
||||
String lower = name.toLowerCase();
|
||||
if (lower.indexOf("restart") >= 0 || lower.indexOf("stop") >= 0
|
||||
|| lower.indexOf("start") >= 0 || lower.indexOf("shutdown") >= 0
|
||||
|| lower.indexOf("container") >= 0)
|
||||
{
|
||||
if (sb.length() > 0)
|
||||
{
|
||||
sb.append(',');
|
||||
}
|
||||
sb.append(name);
|
||||
}
|
||||
}
|
||||
info("Ops(" + on + ")=" + (sb.length() == 0 ? "(keine lifecycle)" : sb.toString()));
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
warn("getMBeanInfo(" + on + "): " + rootOf(t).getClass().getName() + ": " + rootOf(t).getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static Set queryAgents(Object connector) throws Exception
|
||||
{
|
||||
return queryNames(connector, new ObjectName("*:ID=AGENT"));
|
||||
}
|
||||
|
||||
private static Set queryNames(Object connector, ObjectName pattern) throws Exception
|
||||
{
|
||||
Method query = connector.getClass().getMethod("queryNames", new Class[] {
|
||||
ObjectName.class, javax.management.QueryExp.class
|
||||
});
|
||||
return (Set) query.invoke(connector, new Object[] { pattern, null });
|
||||
}
|
||||
|
||||
private static ObjectName resolveAgentObjectName(Object connector, String domain, String container)
|
||||
throws Exception
|
||||
{
|
||||
ObjectName preferred = new ObjectName(domain + "." + container + ":ID=AGENT");
|
||||
Set exact = queryNames(connector, preferred);
|
||||
if (exact != null && !exact.isEmpty())
|
||||
{
|
||||
return (ObjectName) exact.iterator().next();
|
||||
}
|
||||
|
||||
Set names = queryAgents(connector);
|
||||
if (names != null)
|
||||
{
|
||||
for (Iterator it = names.iterator(); it.hasNext(); )
|
||||
{
|
||||
ObjectName on = (ObjectName) it.next();
|
||||
String c = extractContainer(on, domain);
|
||||
if (c != null && c.equalsIgnoreCase(container))
|
||||
{
|
||||
return on;
|
||||
}
|
||||
/* optional */
|
||||
}
|
||||
}
|
||||
return preferred;
|
||||
}
|
||||
|
||||
private static String extractContainer(ObjectName on, String domain)
|
||||
private static Object boxTimeout(Class type, long timeoutMs)
|
||||
{
|
||||
if (on == null || isBlank(domain))
|
||||
if (type == Integer.TYPE || type == Integer.class)
|
||||
{
|
||||
return null;
|
||||
return Integer.valueOf((int) Math.min(Integer.MAX_VALUE, timeoutMs));
|
||||
}
|
||||
String jmxDomain = on.getDomain();
|
||||
if (jmxDomain == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String prefix = domain + ".";
|
||||
if (jmxDomain.regionMatches(true, 0, prefix, 0, prefix.length()))
|
||||
{
|
||||
return jmxDomain.substring(prefix.length());
|
||||
}
|
||||
return null;
|
||||
return Long.valueOf(timeoutMs);
|
||||
}
|
||||
|
||||
private static String shortContainer(String container)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
int dot = container.indexOf('.');
|
||||
if (dot >= 0 && dot < container.length() - 1)
|
||||
{
|
||||
return container.substring(dot + 1);
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
private static String safeState(Object agent)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object s = agent.getClass().getMethod("getStateString").invoke(agent);
|
||||
return s == null ? "?" : String.valueOf(s);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
return "?";
|
||||
}
|
||||
String c = container.trim();
|
||||
int dot = c.lastIndexOf('.');
|
||||
return dot >= 0 ? c.substring(dot + 1) : c;
|
||||
}
|
||||
|
||||
private static Throwable rootOf(Throwable t)
|
||||
{
|
||||
Throwable root = t;
|
||||
while (root != null && root.getCause() != null && root.getCause() != root)
|
||||
Throwable cur = t;
|
||||
while (cur.getCause() != null && cur.getCause() != cur)
|
||||
{
|
||||
root = root.getCause();
|
||||
cur = cur.getCause();
|
||||
}
|
||||
return root == null ? t : root;
|
||||
}
|
||||
|
||||
private static void info(String message)
|
||||
{
|
||||
System.out.println("INFO:" + message);
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
private static void warn(String message)
|
||||
{
|
||||
System.out.println("WARN:" + message);
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
private static void fail(String message)
|
||||
{
|
||||
System.err.println("ERROR:" + message);
|
||||
System.err.flush();
|
||||
System.exit(2);
|
||||
return cur;
|
||||
}
|
||||
|
||||
private static boolean isBlank(String s)
|
||||
@@ -664,6 +225,25 @@ public final class SonicMfContainerTool
|
||||
return s == null || s.trim().length() == 0;
|
||||
}
|
||||
|
||||
private static void info(String msg)
|
||||
{
|
||||
System.out.println("INFO:" + msg);
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
private static void warn(String msg)
|
||||
{
|
||||
System.out.println("WARN:" + msg);
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
private static void fail(String msg)
|
||||
{
|
||||
System.err.println("ERROR:" + msg);
|
||||
System.err.flush();
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
private static final class Args
|
||||
{
|
||||
String command;
|
||||
@@ -681,27 +261,22 @@ public final class SonicMfContainerTool
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
a.command = args[0].toLowerCase();
|
||||
a.command = args[0];
|
||||
for (int i = 1; i < args.length; i++)
|
||||
{
|
||||
String key = args[i];
|
||||
if (!key.startsWith("--") || i + 1 >= args.length)
|
||||
String k = args[i];
|
||||
String v = (i + 1 < args.length) ? args[i + 1] : null;
|
||||
if ("--domain".equals(k) && v != null) { a.domain = v; i++; }
|
||||
else if ("--url".equals(k) && v != null) { a.url = v; i++; }
|
||||
else if ("--user".equals(k) && v != null) { a.user = v; i++; }
|
||||
else if ("--password".equals(k) && v != null) { a.password = v; i++; }
|
||||
else if ("--container".equals(k) && v != null) { a.container = v; i++; }
|
||||
else if ("--timeout".equals(k) && v != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String val = args[++i];
|
||||
if ("--domain".equals(key)) a.domain = val;
|
||||
else if ("--url".equals(key)) a.url = val;
|
||||
else if ("--user".equals(key)) a.user = val;
|
||||
else if ("--password".equals(key)) a.password = val;
|
||||
else if ("--container".equals(key)) a.container = val;
|
||||
else if ("--timeout".equals(key))
|
||||
{
|
||||
try { a.timeoutSec = Integer.parseInt(val); } catch (Exception ignore) { /* keep */ }
|
||||
try { a.timeoutSec = Integer.parseInt(v); } catch (Exception ignore) { /* keep default */ }
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlank(a.password))
|
||||
{
|
||||
String env = System.getenv("ESB_SONIC_PASSWORD");
|
||||
@@ -713,4 +288,8 @@ public final class SonicMfContainerTool
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
private SonicMfContainerTool()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user