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.ArrayList;
11 import java.util.Collection;
12 import java.util.function.Predicate;
13 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
14 import org.opendaylight.mdsal.dom.spi.RpcRoutingStrategy;
15 import org.opendaylight.yangtools.yang.binding.RpcService;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Utility methods for dealing with various aspects of RPCs and actions.
27 * @author Robert Varga
30 private static final Logger LOG = LoggerFactory.getLogger(RpcUtil.class);
33 throw new UnsupportedOperationException();
36 static Collection<SchemaPath> decomposeRpcService(final Class<RpcService> service,
37 final SchemaContext schemaContext, final Predicate<RpcRoutingStrategy> filter) {
38 final QNameModule moduleName = BindingReflections.getQNameModule(service);
39 final Module module = schemaContext.findModule(moduleName).orElseThrow(() -> new IllegalArgumentException(
40 "Module not found in SchemaContext: " + moduleName + "; service: " + service));
41 LOG.debug("Resolved service {} to module {}", service, module);
43 final Collection<RpcDefinition> rpcs = module.getRpcs();
44 final Collection<SchemaPath> ret = new ArrayList<>(rpcs.size());
45 for (RpcDefinition rpc : rpcs) {
46 final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(rpc);
47 if (filter.test(strategy)) {
48 ret.add(rpc.getPath());