Skip to content
Snippets Groups Projects
Commit 182ec21e authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

Better analyze of why an attribute is not archived in getErrorMessageForAttribute

parent 98cd9b5b
No related branches found
No related tags found
No related merge requests found
......@@ -121,6 +121,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
......@@ -153,6 +154,7 @@ import fr.soleil.archiving.hdbtdb.api.tools.AttributeSupport;
public final class HdbCollectorFactory {
private final Map<SuperMode, HdbCollector> tableCollector = new HashMap<SuperMode, HdbCollector>();
private final Map<SuperMode, String> collectorErrorTable = new ConcurrentHashMap<SuperMode, String>();
private final Logger logger;
public HdbCollectorFactory(final Logger logger) {
......@@ -194,11 +196,12 @@ public final class HdbCollectorFactory {
*/
public void createCollectorAndAddSource(final AttributeLightMode attributeLightMode, final DbProxy dbProxy)
throws ArchivingException {
logger.trace("createCollectorAndAddSource for " + attributeLightMode);
final SuperMode superMode = new SuperMode(attributeLightMode.getDataFormat(), attributeLightMode.getDataType(),
attributeLightMode.getWritable(), attributeLightMode.getMode());
ArchivingException lastException = null;
synchronized (tableCollector) {
try {
HdbCollector collector = tableCollector.get(superMode);
if (collector == null) {
logger.trace("new collector ");
......@@ -206,13 +209,36 @@ public final class HdbCollectorFactory {
collector.setDbProxy(dbProxy);
collector.addSource(attributeLightMode);
tableCollector.put(superMode, collector);
collectorErrorTable.remove(superMode);
} else {
logger.trace("use existing collector " + collector.assessment());
collector.addSource(attributeLightMode);
collectorErrorTable.remove(superMode);
}
} catch (ArchivingException e) {
collectorErrorTable.put(superMode, e.getMessage());
lastException = e;
}
}
if (lastException != null) {
throw lastException;
}
}
public String getLastError(AttributeLightMode attributeLightMode) {
String result;
if (attributeLightMode == null) {
result = null;
} else {
result = collectorErrorTable.get(new SuperMode(attributeLightMode.getDataFormat(), attributeLightMode
.getDataType(), attributeLightMode.getWritable(), attributeLightMode.getMode()));
}
if (result == null) {
result = "";
}
return result;
}
/**
* This method returns the instance of Hdb_Collector associated / associable
* to an attribute. In this method, attributes are not grouped by mode.
......
......@@ -1563,7 +1563,32 @@ public class HdbArchiver extends DeviceImpl implements TangoConst {
final HdbCollector hdbCollector = collectorFactory.get(attributeName);
String result;
if (hdbCollector == null) {
result = null;
StringBuilder builder = new StringBuilder("No HdbCollector found for attribute '");
builder.append(attributeName).append("' - Reason: ");
result = "No HdbCollector found for attribute '" + attributeName + "'";
try {
final Collection<AttributeLightMode> myCurrentTasks = dbProxy.getArchiverCurrentTasks(device_name);
boolean done = false;
for (final AttributeLightMode attributeLightMode : myCurrentTasks) {
final String attrName = attributeLightMode.getAttribute_complete_name();
if (attrName.equalsIgnoreCase(attributeName)) {
done = true;
String message = collectorFactory.getLastError(attributeLightMode);
if ((message == null) || (message.trim().isEmpty())) {
builder.append(" no valid reason found");
} else {
builder.append(message);
}
break;
}
}
if (!done) {
builder.append(" this attribute does not seem to be managed by this archiver");
}
} catch (Exception e) {
builder.append(" Could not recover attribute archiving configuration: ").append(e.getMessage());
}
result = builder.toString();
} else {
result = hdbCollector.getErrorMessage(attributeName);
}
......
......@@ -120,6 +120,7 @@ package TdbArchiver.Collector;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
......@@ -143,6 +144,7 @@ import fr.soleil.archiving.hdbtdb.api.tools.AttributeSupport;
public class TdbCollectorFactory {
private final Map<SuperMode, TdbCollector> tableCollector = new HashMap<SuperMode, TdbCollector>();
private final Map<SuperMode, String> collectorErrorTable = new ConcurrentHashMap<SuperMode, String>();
private final Logger logger;
private String m_currentDbPath = "";
......@@ -193,39 +195,46 @@ public class TdbCollectorFactory {
*/
public void createCollectorAndAddSource(final AttributeLightMode attributeLightMode, final DbProxy dbProxy,
final int attributePerFile) throws ArchivingException {
final SuperMode superMode = new SuperMode(attributeLightMode.getDataFormat(), attributeLightMode.getDataType(),
attributeLightMode.getWritable(), attributeLightMode.getMode());
TdbCollector collector = null;
ArchivingException lastException = null;
synchronized (tableCollector) {
try {
collector = tableCollector.get(superMode);
if (collector == null) {
try {
collector = create(attributeLightMode);
} catch (final ArchivingException e) {
throw e;
}
collector.setDbProxy(dbProxy);
// collector.setDiaryLogger(logger);
try {
collector.addSource(attributeLightMode, attributePerFile);
} catch (final ArchivingException e) {
collector = null;
throw e;
}
tableCollector.put(superMode, collector);
collectorErrorTable.remove(superMode);
} else {
collector.addSource(attributeLightMode, attributePerFile);
collectorErrorTable.remove(superMode);
}
} catch (ArchivingException e) {
collectorErrorTable.put(superMode, e.getMessage());
lastException = e;
}
}
if (lastException != null) {
throw lastException;
}
}
public String getLastError(AttributeLightMode attributeLightMode) {
String result;
if (attributeLightMode == null) {
result = null;
} else {
result = collectorErrorTable.get(new SuperMode(attributeLightMode.getDataFormat(), attributeLightMode
.getDataType(), attributeLightMode.getWritable(), attributeLightMode.getMode()));
}
if (result == null) {
result = "";
}
return result;
}
/**
......
......@@ -922,10 +922,38 @@ public class TdbArchiver extends DeviceImpl implements TangoConst {
final TdbCollector tdbCollector = collectorFactory.get(attributeName);
String result;
if (tdbCollector == null) {
result = null;
StringBuilder builder = new StringBuilder("No TdbCollector found for attribute '");
builder.append(attributeName).append("' - Reason: ");
result = "No TdbCollector found for attribute '" + attributeName + "'";
try {
final Collection<AttributeLightMode> myCurrentTasks = dbProxy.getArchiverCurrentTasks(device_name);
boolean done = false;
for (final AttributeLightMode attributeLightMode : myCurrentTasks) {
final String attrName = attributeLightMode.getAttribute_complete_name();
if (attrName.equalsIgnoreCase(attributeName)) {
done = true;
String message = collectorFactory.getLastError(attributeLightMode);
if ((message == null) || (message.trim().isEmpty())) {
builder.append(" no valid reason found");
} else {
builder.append(message);
}
break;
}
}
if (!done) {
builder.append(" this attribute does not seem to be managed by this archiver");
}
} catch (Exception e) {
builder.append(" Could not recover attribute archiving configuration: ").append(e.getMessage());
}
result = builder.toString();
} else {
result = tdbCollector.getErrorMessage(attributeName);
}
if (result == null) {
result = "";
}
return result;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment