Search in sources :

Example 1 with StringFilter

use of org.onlab.util.StringFilter in project onos by opennetworkinglab.

the class VirtualFlowsListCommand method doExecute.

@Override
protected void doExecute() {
    CoreService coreService = get(CoreService.class);
    VirtualNetworkService vnetservice = get(VirtualNetworkService.class);
    DeviceService deviceService = vnetservice.get(NetworkId.networkId(networkId), DeviceService.class);
    FlowRuleService service = vnetservice.get(NetworkId.networkId(networkId), FlowRuleService.class);
    contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
    compilePredicate();
    SortedMap<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service);
    if (outputJson()) {
        print("%s", json(flows.keySet(), flows));
    } else {
        flows.forEach((device, flow) -> printFlows(device, flow, coreService));
    }
}
Also used : VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) StringFilter(org.onlab.util.StringFilter) ArrayList(java.util.ArrayList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService)

Example 2 with StringFilter

use of org.onlab.util.StringFilter in project onos by opennetworkinglab.

the class FlowsListCommand method doExecute.

@Override
protected void doExecute() {
    CoreService coreService = get(CoreService.class);
    DeviceService deviceService = get(DeviceService.class);
    FlowRuleService service = get(FlowRuleService.class);
    contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
    compilePredicate();
    if (countOnly && !suppressCoreOutput && filter.isEmpty() && remove == null) {
        if (state == null && uri == null) {
            deviceService.getDevices().forEach(device -> printCount(device, service));
        } else if (uri == null) {
            deviceService.getDevices().forEach(device -> printCount(device, FlowEntryState.valueOf(state.toUpperCase()), service));
        } else {
            Device device = deviceService.getDevice(DeviceId.deviceId(uri));
            if (device != null) {
                printCount(device, FlowEntryState.valueOf(state.toUpperCase()), service);
            }
        }
        return;
    }
    SortedMap<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service, coreService);
    // Remove flows
    if (remove != null) {
        flows.values().forEach(flowList -> {
            if (!remove.isEmpty()) {
                filter.add(remove);
                contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
            }
            if (!filter.isEmpty() || (remove != null && !remove.isEmpty())) {
                flowList = filterFlows(flowList);
                this.removeFlowsInteractive(flowList, service, coreService);
            }
        });
        return;
    }
    // Show flows
    if (outputJson()) {
        print("%s", json(flows.keySet(), flows));
    } else {
        flows.forEach((device, flow) -> printFlows(device, flow, coreService));
    }
}
Also used : StringFilter(org.onlab.util.StringFilter) Comparators(org.onosproject.utils.Comparators) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ArrayList(java.util.ArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) JsonNode(com.fasterxml.jackson.databind.JsonNode) PlaceholderCompleter(org.onosproject.cli.PlaceholderCompleter) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Device(org.onosproject.net.Device) Predicate(java.util.function.Predicate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Argument(org.apache.karaf.shell.api.action.Argument) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) TreeMap(java.util.TreeMap) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) BufferedReader(java.io.BufferedReader) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) SortedMap(java.util.SortedMap) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) StringFilter(org.onlab.util.StringFilter) ArrayList(java.util.ArrayList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService)

Example 3 with StringFilter

use of org.onlab.util.StringFilter in project onos by opennetworkinglab.

the class IntentsListCommand method doExecute.

@Override
protected void doExecute() {
    service = get(IntentService.class);
    workPartitionService = get(WorkPartitionService.class);
    if (workPartitionService == null) {
        return;
    }
    contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
    Iterable<Intent> intents;
    if (pending) {
        intents = service.getPending();
    } else {
        intents = service.getIntents();
    }
    // Remove intents
    if (remove != null && !remove.isEmpty()) {
        filter.add(remove);
        contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
        IntentRemoveCommand intentRemoveCmd = new IntentRemoveCommand();
        if (!remove.isEmpty()) {
            intentRemoveCmd.purgeIntentsInteractive(filterIntents(service));
        }
        return;
    }
    // Show detailed intents
    if (!intentIds.isEmpty()) {
        IntentDetailsCommand intentDetailsCmd = new IntentDetailsCommand();
        intentDetailsCmd.detailIntents(intentIds);
        return;
    }
    // Show brief intents
    if (intentsSummary || miniSummary) {
        Map<String, IntentSummary> summarized = summarize(intents);
        if (outputJson()) {
            ObjectNode summaries = mapper().createObjectNode();
            summarized.forEach((n, s) -> summaries.set(uncapitalize(n), s.json(mapper())));
            print("%s", summaries);
        } else if (miniSummary) {
            StringBuilder builder = new StringBuilder();
            builder.append(summarized.remove("All").miniSummary());
            summarized.values().forEach(s -> builder.append(s.miniSummary()));
            print("%s", builder.toString());
        } else {
            StringBuilder builder = new StringBuilder();
            builder.append(SUMMARY_TITLES);
            builder.append('\n').append(SEPARATOR);
            builder.append(summarized.remove("All").summary());
            summarized.values().forEach(s -> builder.append(s.summary()));
            print("%s", builder.toString());
        }
        return;
    }
    // JSON or default output
    if (outputJson()) {
        print("%s", json(intents));
    } else {
        for (Intent intent : intents) {
            IntentState state = service.getIntentState(intent.key());
            StringBuilder intentFormat = fullFormat(intent, state);
            StringBuilder detailsIntentFormat = detailsFormat(intent, state);
            String formatted = intentFormat.append(detailsIntentFormat).toString();
            if (contentFilter.filter(formatted)) {
                print("%s\n", formatted);
            }
        }
    }
}
Also used : StringFilter(org.onlab.util.StringFilter) StringUtils(org.apache.commons.lang.StringUtils) Tools(org.onlab.util.Tools) IntentState(org.onosproject.net.intent.IntentState) HashMap(java.util.HashMap) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) IntentService(org.onosproject.net.intent.IntentService) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) JsonNode(com.fasterxml.jackson.databind.JsonNode) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) Criterion(org.onosproject.net.flow.criteria.Criterion) NodeId(org.onosproject.cluster.NodeId) PathIntent(org.onosproject.net.intent.PathIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) WordUtils.uncapitalize(org.apache.commons.lang3.text.WordUtils.uncapitalize) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Key(org.onosproject.net.intent.Key) List(java.util.List) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Service(org.apache.karaf.shell.api.action.lifecycle.Service) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) Option(org.apache.karaf.shell.api.action.Option) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) IntentService(org.onosproject.net.intent.IntentService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) IntentState(org.onosproject.net.intent.IntentState) StringFilter(org.onlab.util.StringFilter)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 StringFilter (org.onlab.util.StringFilter)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Command (org.apache.karaf.shell.api.action.Command)2 Option (org.apache.karaf.shell.api.action.Option)2 Service (org.apache.karaf.shell.api.action.lifecycle.Service)2 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)2 CoreService (org.onosproject.core.CoreService)2 Device (org.onosproject.net.Device)2 DeviceService (org.onosproject.net.device.DeviceService)2 FlowRuleService (org.onosproject.net.flow.FlowRuleService)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Strings (com.google.common.base.Strings)1