2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.blueprint.ext;
10 import java.util.List;
11 import java.util.function.Predicate;
12 import java.util.stream.Collectors;
13 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
14 import org.opendaylight.mdsal.dom.spi.ContentRoutedRpcContext;
15 import org.opendaylight.yangtools.yang.binding.RpcService;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Utility methods for dealing with various aspects of RPCs and actions.
26 private static final Logger LOG = LoggerFactory.getLogger(RpcUtil.class);
32 static List<QName> decomposeRpcService(final Class<RpcService> service,
33 final EffectiveModelContext schemaContext, final Predicate<ContentRoutedRpcContext> filter) {
34 final var moduleName = BindingReflections.getQNameModule(service);
35 final var module = schemaContext.findModuleStatement(moduleName)
36 .orElseThrow(() -> new IllegalArgumentException("Module not found in SchemaContext: " + moduleName
37 + "; service: " + service));
38 LOG.debug("Resolved service {} to module {}", service, module);
40 return module.streamEffectiveSubstatements(RpcEffectiveStatement.class)
41 .filter(rpc -> filter.test(ContentRoutedRpcContext.forRpc(rpc)))
42 .map(RpcEffectiveStatement::argument)
43 .collect(Collectors.toList());