Search in sources :

Example 1 with Operation

use of org.opennms.features.topology.api.Operation in project opennms by OpenNMS.

the class OperationListShellCommand method doExecute.

@Override
protected Object doExecute() throws Exception {
    final List<Operation> operations = Lists.newArrayList();
    final Map<Operation, Map<String, Object>> properties = new HashMap<>();
    final Collection<ServiceReference<Operation>> services = this.bundleContext.getServiceReferences(Operation.class, null);
    if (services == null)
        return null;
    for (final ServiceReference<Operation> sr : services) {
        final Operation operation = this.bundleContext.getService(sr);
        if (operation == null)
            continue;
        operations.add(operation);
        final Map<String, Object> props = new TreeMap<>();
        for (final String key : sr.getPropertyKeys()) {
            props.put(key, sr.getProperty(key));
        }
        properties.put(operation, props);
    }
    // Output
    for (final Operation operation : operations) {
        final String operationClass = operation.getClass().getName();
        System.out.println("    " + makeLine(operationClass));
        System.out.println("    Class: " + operationClass);
        System.out.println("    ID:    " + operation.getId());
        final Map<String, Object> props = properties.get(operation);
        if (!props.isEmpty()) {
            System.out.println("    Service Properties:");
            for (final String key : props.keySet()) {
                final Object object = props.get(key);
                final String value = (object instanceof Object[]) ? Arrays.toString((Object[]) object) : object.toString();
                System.out.println("        " + key + "=" + value);
            }
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) Operation(org.opennms.features.topology.api.Operation) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with Operation

use of org.opennms.features.topology.api.Operation in project opennms by OpenNMS.

the class OperationListShellCommand method execute.

@Override
public Object execute() throws Exception {
    final List<Operation> operations = Lists.newArrayList();
    final Map<Operation, Map<String, Object>> properties = new HashMap<>();
    final Collection<ServiceReference<Operation>> services = this.bundleContext.getServiceReferences(Operation.class, null);
    if (services == null)
        return null;
    for (final ServiceReference<Operation> sr : services) {
        final Operation operation = this.bundleContext.getService(sr);
        if (operation == null)
            continue;
        operations.add(operation);
        final Map<String, Object> props = new TreeMap<>();
        for (final String key : sr.getPropertyKeys()) {
            props.put(key, sr.getProperty(key));
        }
        properties.put(operation, props);
    }
    // Output
    for (final Operation operation : operations) {
        final String operationClass = operation.getClass().getName();
        System.out.println("    " + makeLine(operationClass));
        System.out.println("    Class: " + operationClass);
        System.out.println("    ID:    " + operation.getId());
        final Map<String, Object> props = properties.get(operation);
        if (!props.isEmpty()) {
            System.out.println("    Service Properties:");
            for (final String key : props.keySet()) {
                final Object object = props.get(key);
                final String value = (object instanceof Object[]) ? Arrays.toString((Object[]) object) : object.toString();
                System.out.println("        " + key + "=" + value);
            }
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) Operation(org.opennms.features.topology.api.Operation) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Operation (org.opennms.features.topology.api.Operation)2 ServiceReference (org.osgi.framework.ServiceReference)2