use of org.opennms.netmgt.collection.api.Parameter in project opennms by OpenNMS.
the class PersistRegexSelectorStrategy method shouldPersist.
@Override
public boolean shouldPersist(CollectionResource resource) {
LOG.debug("shouldPersist: checking resource {}", resource);
if (m_parameterCollection == null) {
LOG.warn("shouldPersist: no parameters defined; the resource will be persisted.");
return true;
}
EvaluatorContextVisitor visitor = new EvaluatorContextVisitor();
resource.visit(visitor);
ExpressionParser parser = new SpelExpressionParser();
for (Parameter param : m_parameterCollection) {
if (param.getKey().equals(MATCH_EXPRESSION)) {
Expression exp = parser.parseExpression(param.getValue());
boolean shouldPersist = false;
try {
shouldPersist = (Boolean) exp.getValue(visitor.getEvaluationContext(), Boolean.class);
} catch (Exception e) {
LOG.warn("shouldPersist: can't evaluate expression {} for resource {} because: {}", param.getValue(), resource, e.getMessage());
}
LOG.debug("shouldPersist: checking {} ? {}", param.getValue(), shouldPersist);
if (shouldPersist)
return true;
}
}
return false;
}
use of org.opennms.netmgt.collection.api.Parameter in project opennms by OpenNMS.
the class DataCollectionConfigConverter method visitResourceType.
@Override
public void visitResourceType(final ResourceType resourceType) {
// LOG.debug("visitResourceType({})", resourceType);
final ResourceTypeImpl type = new ResourceTypeImpl(resourceType.getName(), resourceType.getLabel());
if (resourceType.getResourceLabel() != null && !resourceType.getResourceLabel().trim().isEmpty()) {
type.setResourceLabelTemplate(resourceType.getResourceLabel());
}
final String strategy = resourceType.getStorageStrategy().getClazz();
if (strategy.endsWith(".SiblingColumnStorageStrategy")) {
for (final Parameter parameter : resourceType.getStorageStrategy().getParameters()) {
if ("sibling-column-name".equals(parameter.getKey())) {
final String name = parameter.getValue();
if (name != null && !name.trim().isEmpty()) {
type.setResourceNameTemplate("${" + name + "}");
break;
}
}
}
} else if (strategy.endsWith(".IndexStorageStrategy")) {
type.setResourceNameTemplate("${index}");
if (type.getResourceLabelExpression() == null || type.getResourceLabelExpression().getTemplate() == null) {
type.setResourceLabelTemplate("${index}");
}
}
final Set<String> parameters = new TreeSet<>();
parameters.addAll(getParameters(type.getResourceKindExpression()));
parameters.addAll(getParameters(type.getResourceLabelExpression()));
parameters.addAll(getParameters(type.getResourceNameExpression()));
for (final String parameter : parameters) {
if (m_columns.containsKey(parameter)) {
final ColumnImpl column = m_columns.get(parameter);
// LOG.debug("adding column {} to resource type {}", column, type.getTypeName());
type.addColumn(column);
} else if (m_mibs.containsKey(parameter)) {
final MibObjectImpl mib = m_mibs.get(parameter);
// LOG.debug("adding mib {} to resource type {}", mib, type.getTypeName());
type.addColumn(new ColumnImpl(mib));
} else {
if (!"index".equals(parameter)) {
LOG.warn("Unable to locate column/mibObject for parameter: {}", parameter);
}
}
}
m_currentDataCollectionGroup.addResourceType(type);
}
use of org.opennms.netmgt.collection.api.Parameter in project opennms by OpenNMS.
the class SiblingColumnStorageStrategy method setParameters.
/**
* {@inheritDoc}
*/
@Override
public void setParameters(List<Parameter> parameterCollection) throws IllegalArgumentException {
if (parameterCollection == null) {
final String msg = "Got a null parameter list, but need one containing a '" + PARAM_SIBLING_COLUMN_NAME + "' parameter.";
LOG.error(msg);
throw new IllegalArgumentException(msg);
}
for (Parameter param : parameterCollection) {
if (PARAM_SIBLING_COLUMN_NAME.equals(param.getKey())) {
m_siblingColumnName = param.getValue();
} else if (PARAM_REPLACE_FIRST.equals(param.getKey())) {
m_replaceOps.add(new ReplaceFirstOperation(param.getValue()));
} else if (PARAM_REPLACE_ALL.equals(param.getKey())) {
m_replaceOps.add(new ReplaceAllOperation(param.getValue()));
} else {
if (param.getKey().equals("sibling-column-oid")) {
final String msg = "The parameter 'sibling-column-oid' has been deprecated and it is no longer used. You should configure 'sibling-column-name' instead. For this parameter, you should use the name of any MibObj defined as string for the same resource type.";
LOG.error(msg);
throw new IllegalArgumentException(msg);
} else {
LOG.warn("Encountered unsupported parameter key=\"{}\". Can accept: {}, {}, {}", param.getKey(), PARAM_SIBLING_COLUMN_NAME, PARAM_REPLACE_FIRST, PARAM_REPLACE_ALL);
}
}
}
if (m_siblingColumnName == null) {
final String msg = "The provided parameter list must contain a '" + PARAM_SIBLING_COLUMN_NAME + "' parameter.";
LOG.error(msg);
throw new IllegalArgumentException(msg);
}
}
Aggregations