Skip to content

Commit

Permalink
Improved connection creation debug and failure
Browse files Browse the repository at this point in the history
some general logs cleaning
catch failed connection creation
  • Loading branch information
fbacchella committed May 31, 2013
1 parent 19ace14 commit 71ba5ee
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 44 deletions.
5 changes: 0 additions & 5 deletions src/jrds/ProbeConnected.java
Expand Up @@ -17,11 +17,6 @@ public ProbeConnected(String connectionName) {
}

public Boolean configure() {
ConnectionClass cnx = getConnection();
if(cnx == null) {
log(Level.ERROR, "No connection configured with name %s", getConnectionName());
return false;
}
return true;
}

Expand Down
85 changes: 51 additions & 34 deletions src/jrds/configuration/HostBuilder.java
Expand Up @@ -93,6 +93,8 @@ public HostInfo makeHost(JrdsDocument n) throws SecurityException, IllegalArgume

private void parseFragment(JrdsElement fragment, HostInfo host, Map<String, Set<String>> collections, Map<String, String> properties) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {

// Find the connection for this host
// Will the registered latter, in the starter node, one for each timer
for(ConnectionInfo cnx: makeConnexion(fragment, host)) {
host.addConnection(cnx);
}
Expand Down Expand Up @@ -176,6 +178,7 @@ else if(forattr.containsKey("min") && forattr.containsKey("max") && forattr.cont
logger.error("Invalid host configuration, collection " + name + " not found");
}
}

for(JrdsElement probeNode: fragment.getChildElements()) {
if(! "probe".equals(probeNode.getNodeName()) && ! "rrd".equals(probeNode.getNodeName()) )
continue;
Expand Down Expand Up @@ -210,7 +213,7 @@ public Probe<?,?> makeProbe(JrdsElement probeNode, HostInfo host, Map<String, St
}
if(p == null)
return null;

p.readProperties(pm);

String timerName = probeNode.getAttribute("timer");
Expand All @@ -222,7 +225,7 @@ public Probe<?,?> makeProbe(JrdsElement probeNode, HostInfo host, Map<String, St
return null;
}
else {
logger.trace(Util.delayedFormatString("probe %s/%s added to timer %s", host, type, timer));
logger.trace(Util.delayedFormatString("probe %s/%s will use timer %s", host, type, timer));
}
p.setStep(timer.getStep());
p.setTimeout(timer.getTimeout());
Expand All @@ -238,28 +241,6 @@ public Probe<?,?> makeProbe(JrdsElement probeNode, HostInfo host, Map<String, St
HostStarter shost = timer.getHost(host);
p.setHost(shost);

//A connected probe, register the needed connection
//It can be defined within the node, referenced by it's name, or it's implied name
if(p instanceof ConnectedProbe) {
String connectionName = null;
ConnectedProbe cp = (ConnectedProbe) p;
for(ConnectionInfo ci: makeConnexion(probeNode, host)) {
ci.register(p);
}
String connexionName = probeNode.getAttribute("connection");
if(connexionName != null && ! "".equals(connexionName)) {
logger.trace(Util.delayedFormatString("Adding connection %s to %s", connexionName, p));
connectionName = jrds.Util.parseTemplate(connexionName, host);
cp.setConnectionName(connectionName);
}
else {
connectionName = cp.getConnectionName();
}
ConnectionInfo ci = host.getConnection(connectionName);
if(ci != null && p.find(connectionName) == null)
ci.register(shost);
}

ProbeDesc pd = p.getPd();
List<Object> args = ArgFactory.makeArgs(probeNode, host, properties);
//Prepare the probe with the default beans values
Expand Down Expand Up @@ -299,16 +280,47 @@ public Probe<?,?> makeProbe(JrdsElement probeNode, HostInfo host, Map<String, St
logger.error(p + " configuration failed");
return null;
}
if(p != null && p.checkStore()) {

//A connected probe, register the needed connection
//It can be defined within the node, referenced by it's name, or it's implied name
if(p instanceof ConnectedProbe) {
String connectionName = null;
ConnectedProbe cp = (ConnectedProbe) p;
//Register the connections defined within the probe
for(ConnectionInfo ci: makeConnexion(probeNode, p)) {
ci.register(p);
}
String connexionName = probeNode.getAttribute("connection");
if(connexionName != null && ! "".equals(connexionName)) {
logger.trace(Util.delayedFormatString("Adding connection %s to %s", connexionName, p));
connectionName = jrds.Util.parseTemplate(connexionName, host);
cp.setConnectionName(connectionName);
}
else {
connectionName = cp.getConnectionName();
}
//If the connection is not already registred, try looking for it
//And register it with the host
if(p.find(connectionName) == null) {
if(logger.isTraceEnabled())
logger.trace(Util.delayedFormatString("Looking for connection %s in %s", connectionName, host.getConnections()));
ConnectionInfo ci = host.getConnection(connectionName);
if(ci != null)
ci.register(shost);
else {
logger.error(Util.delayedFormatString("Failed to find a connection %s for a probe %s", connectionName, cp));
return null;
}
}
}

if(p.checkStore()) {
shost.addProbe(p);
}
else {
return null;
}

for(ConnectionInfo cnx: makeConnexion(probeNode, host))
cnx.register(p);

return p;
}

Expand All @@ -323,7 +335,7 @@ private ConnectionInfo parseSnmp(JrdsElement node) {
try {
JrdsElement snmpNode = node.getElementbyName("snmp");
if(snmpNode != null) {
logger.trace("found a snmp starter");
logger.info("found an old snmp starter, please update to a connection");
String connectionClassName = "jrds.snmp.SnmpConnection";
Class<? extends Connection<?>> connectionClass = (Class<? extends Connection<?>>) pm.extensionClassLoader.loadClass(connectionClassName);

Expand All @@ -339,10 +351,16 @@ private ConnectionInfo parseSnmp(JrdsElement node) {
return null;
}

Set<ConnectionInfo> makeConnexion(JrdsElement domNode, HostInfo host) {
/**
* Enumerate the connections found in an XML node
* @param domNode a node to parse
* @param host
* @return
*/
Set<ConnectionInfo> makeConnexion(JrdsElement domNode, Object parent) {
Set<ConnectionInfo> connectionSet = new HashSet<ConnectionInfo>();

//For a connect probe, the connection can be defined within the probe
//Check for the old SNMP connection node
ConnectionInfo cnxSnmp = parseSnmp(domNode);
if(cnxSnmp != null)
connectionSet.add(cnxSnmp);
Expand All @@ -354,8 +372,6 @@ Set<ConnectionInfo> makeConnexion(JrdsElement domNode, HostInfo host) {
continue;
}
String name = cnxNode.getAttribute("name");
if(name == null)
name = type;

try {
//Load the class for the connection
Expand All @@ -369,11 +385,12 @@ Set<ConnectionInfo> makeConnexion(JrdsElement domNode, HostInfo host) {
Map<String, String> attrs = new HashMap<String, String>();
for(JrdsElement attrNode: cnxNode.getChildElementsByName("attr")) {
String attrName = attrNode.getAttribute("name");
String textValue = Util.parseTemplate(attrNode.getTextContent(), host);
String textValue = Util.parseTemplate(attrNode.getTextContent(), parent);
attrs.put(attrName, textValue);
}
ConnectionInfo cnx = new ConnectionInfo(connectionClass, name, args, attrs);
connectionSet.add(cnx);
logger.debug(Util.delayedFormatString("Added connection %s to node %s", cnx, parent));
}
catch (NoClassDefFoundError ex) {
logger.warn("Connection class not found: " + type+ ": " + ex);
Expand Down
2 changes: 1 addition & 1 deletion src/jrds/factories/ArgFactory.java
Expand Up @@ -190,7 +190,7 @@ static public void beanSetter(Object o, String beanName, String beanValue) throw
Object argInstance = ArgFactory.ConstructFromString(setArgType, beanValue);
setMethod.invoke(o, argInstance);
} catch (Exception e) {
throw new InvocationTargetException(e, "invalid bean name '" + beanName + "' for " + o);
throw new InvocationTargetException(e, "invalid bean '" + beanName + "' for " + o);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/jrds/factories/ProbeFactory.java
Expand Up @@ -123,7 +123,7 @@ public boolean configure(Probe<?, ?> p, List<?> constArgs) {
return true;
} catch (SecurityException e) {
} catch (NoSuchMethodException e) {
logger.warn("Probe arguments not matching configurators for" + p.getPd().getName() + ": " + e.getMessage());
logger.warn("Probe arguments not matching configurators for " + p.getPd().getName() + ": " + e.getMessage());
return false;
} catch (Exception ex) {
Throwable showException = ex;
Expand Down
9 changes: 9 additions & 0 deletions src/jrds/starter/ConnectionInfo.java
Expand Up @@ -59,4 +59,13 @@ public String getName() {
return name;
}

/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return type.getCanonicalName() + (name == null ? "" : ("/" + name));
}


}
2 changes: 1 addition & 1 deletion src/jrds/starter/Resolver.java
Expand Up @@ -13,8 +13,8 @@ public class Resolver extends Starter {
InetAddress address = null;

public Resolver(String hostname) {
log(Level.DEBUG, "New dns resolver");
this.hostname = hostname;
log(Level.DEBUG, "New dns resolver");
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/jrds/starter/StarterNode.java
Expand Up @@ -96,7 +96,7 @@ public Starter registerStarter(Starter s) {
if(! allStarters.containsKey(key)) {
s.initialize(this);
allStarters.put(key, s);
log(Level.DEBUG, "registering %s with key %s", s, key);
log(Level.DEBUG, "registering %s with key %s", s.getClass().getName(), key);
return s;
}
else {
Expand Down Expand Up @@ -160,7 +160,8 @@ public Starter find(Object key) {
@SuppressWarnings("unchecked")
public <StarterClass extends Starter> StarterClass find(Class<StarterClass> sc, Object key) {
StarterClass s = null;
log(Level.TRACE, "Looking for starter %s with key %s in %s", sc, key, allStarters);
if(allStarters != null)
log(Level.TRACE, "Looking for starter %s with key %s in %s", sc, key, allStarters);
if(allStarters != null && allStarters.containsKey(key)) {
Starter stemp = allStarters.get(key);
if(sc.isInstance(stemp)) {
Expand Down

0 comments on commit 71ba5ee

Please sign in to comment.