Search in sources :

Example 1 with Expression

use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project opennms by OpenNMS.

the class IpInterfaceScan method isIpMatching.

protected static boolean isIpMatching(final InetAddress ip, final String expr) {
    try {
        JexlEngine parser = new JexlEngine();
        Expression e = parser.createExpression(generateExpr(expr));
        final Map<String, Object> context = new HashMap<String, Object>();
        context.put("iplike", IPLike.class);
        context.put("ipaddr", ip.getHostAddress());
        Boolean out = (Boolean) e.evaluate(new MapContext(context));
        return out;
    } catch (Exception e) {
        LOG.error("Can't process rule '{}' while checking IP {}.", expr, ip, e);
        return false;
    }
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) HashMap(java.util.HashMap) MapContext(org.apache.commons.jexl2.MapContext)

Example 2 with Expression

use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project opennms by OpenNMS.

the class JEXL method filter.

@Override
public void filter(RowSortedTable<Long, String, Double> qrAsTable) throws Exception {
    // Prepare the JEXL context
    final Map<String, Object> jexlValues = Maps.newHashMap();
    jexlValues.put("table", qrAsTable);
    final JexlContext context = new MapContext(jexlValues);
    // Compile the expression
    Expression expression = jexl.createExpression(m_expression);
    // Evaluate the expression
    expression.evaluate(context);
}
Also used : Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext)

Example 3 with Expression

use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project opennms by OpenNMS.

the class JMXMonitor method poll.

/**
 * {@inheritDoc}
 */
@Override
public PollStatus poll(MonitoredService svc, Map<String, Object> map) {
    final InetAddress ipv4Addr = svc.getAddress();
    PollStatus serviceStatus = PollStatus.unavailable();
    try {
        final Timer timer = new Timer();
        final JmxConnectionManager connectionManager = new DefaultConnectionManager(ParameterMap.getKeyedInteger(map, "retry", 3));
        final JmxConnectionManager.RetryCallback retryCallback = new JmxConnectionManager.RetryCallback() {

            @Override
            public void onRetry() {
                timer.reset();
            }
        };
        try (JmxServerConnectionWrapper connection = connectionManager.connect(getConnectionName(), ipv4Addr, JmxUtils.convertToStringMap(map), retryCallback)) {
            // Start with simple communication
            connection.getMBeanServerConnection().getMBeanCount();
            // Take time just here to get not influenced by test execution
            // time
            final long nanoResponseTime = System.nanoTime() - timer.getStartTime();
            // Find all variable definitions
            final Map<String, Object> variables = Maps.newHashMap();
            for (final String key : map.keySet()) {
                // Skip fast if it does not start with the prefix
                if (!key.startsWith(PARAM_BEAN_PREFIX)) {
                    continue;
                }
                // Get the variable name
                final String variable = key.substring(PARAM_BEAN_PREFIX.length());
                // Get the variable definition
                final String definition = ParameterMap.getKeyedString(map, key, null);
                // Store wrapper for variable definition
                variables.put(variable, ObjectNameWrapper.create(connection.getMBeanServerConnection(), definition));
            }
            // Find all test definitions
            final Map<String, Expression> tests = Maps.newHashMap();
            for (final String key : map.keySet()) {
                // Skip fast if it does not start with the prefix
                if (!key.startsWith(PARAM_TEST_PREFIX)) {
                    continue;
                }
                // Get the test name
                final String variable = key.substring(PARAM_TEST_PREFIX.length());
                // Get the test definition
                final String definition = ParameterMap.getKeyedString(map, key, null);
                // Build the expression from the definition
                final Expression expression = JEXL_ENGINE.createExpression(definition);
                // Store expressions
                tests.put(variable, expression);
            }
            // Also handle a single test
            if (map.containsKey(PARAM_TEST)) {
                // Get the test definition
                final String definition = ParameterMap.getKeyedString(map, PARAM_TEST, null);
                // Build the expression from the definition
                final Expression expression = JEXL_ENGINE.createExpression(definition);
                // Store expressions
                tests.put(null, expression);
            }
            // Build the context for all tests
            final JexlContext context = new ReadonlyContext(new MapContext(variables));
            serviceStatus = PollStatus.up(nanoResponseTime / 1000000.0);
            // Execute all tests
            for (final Map.Entry<String, Expression> e : tests.entrySet()) {
                if (!(boolean) e.getValue().evaluate(context)) {
                    serviceStatus = PollStatus.down("Test failed: " + e.getKey());
                    break;
                }
            }
        } catch (JmxServerConnectionException mbse) {
            // Number of retries exceeded
            String reason = "IOException while polling address: " + ipv4Addr;
            LOG.debug(reason);
            serviceStatus = PollStatus.unavailable(reason);
        }
    } catch (Throwable e) {
        String reason = "Monitor - failed! " + InetAddressUtils.str(ipv4Addr);
        LOG.debug(reason);
        serviceStatus = PollStatus.unavailable(reason);
    }
    return serviceStatus;
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) DefaultConnectionManager(org.opennms.netmgt.jmx.impl.connection.connectors.DefaultConnectionManager) JmxConnectionManager(org.opennms.netmgt.jmx.connection.JmxConnectionManager) ReadonlyContext(org.apache.commons.jexl2.ReadonlyContext) MapContext(org.apache.commons.jexl2.MapContext) JmxServerConnectionException(org.opennms.netmgt.jmx.connection.JmxServerConnectionException) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) JmxServerConnectionWrapper(org.opennms.netmgt.jmx.connection.JmxServerConnectionWrapper) InetAddress(java.net.InetAddress) HashMap(java.util.HashMap) Map(java.util.Map) ParameterMap(org.opennms.core.utils.ParameterMap)

Example 4 with Expression

use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project xtext-core by eclipse.

the class Expression_Larger_EqualImpl method basicSetLeft.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetLeft(Expression newLeft, NotificationChain msgs) {
    Expression oldLeft = left;
    left = newLeft;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Bug385636Package.EXPRESSION_LARGER_EQUAL__LEFT, oldLeft, newLeft);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : Expression(org.eclipse.xtext.resource.bug385636.Expression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 5 with Expression

use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project xtext-core by eclipse.

the class Expression_Not_EqualImpl method basicSetLeft.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetLeft(Expression newLeft, NotificationChain msgs) {
    Expression oldLeft = left;
    left = newLeft;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Bug385636Package.EXPRESSION_NOT_EQUAL__LEFT, oldLeft, newLeft);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : Expression(org.eclipse.xtext.resource.bug385636.Expression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

Expression (org.kie.workbench.common.dmn.api.definition.v1_1.Expression)19 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)15 Expression (org.apache.commons.jexl2.Expression)14 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)13 JexlContext (org.apache.commons.jexl2.JexlContext)12 Test (org.junit.Test)12 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)12 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)11 HasName (org.kie.workbench.common.dmn.api.definition.HasName)10 JexlEngine (org.apache.commons.jexl2.JexlEngine)9 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)9 BaseGridCellValue (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)9 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)9 MapContext (org.apache.commons.jexl2.MapContext)8 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 Expression (org.eclipse.xtext.resource.bug385636.Expression)7 Optional (java.util.Optional)6 Before (org.junit.Before)6 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)6 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)6