Search code examples
networkingsdnopendaylight

Opendaylight Hello World RPC throw "Unable to find a matching constructor" error


I am new at Opendaylight so I try to build Hello api on Magnesium via this tutorial.

https://docs.opendaylight.org/en/stable-magnesium/developer-guide/developing-apps-on-the-opendaylight-controller.html

I am going step by step what tutorial said but encountered an error when building app

Unable to find a matching constructor on class org.opendaylight.hello.impl.HelloProvider for
arguments [org.apache.aries.blueprint.container.ReferenceRecipe$ServiceProxyWrapper@3dc7838f 
(class org.apache.aries.blueprint.container.ReferenceRecipe$ServiceProxyWrapper), 
org.apache.aries.blueprint.container.ReferenceRecipe$ServiceProxyWrapper@665cb91b (class             
org.apache.aries.blueprint.container.ReferenceRecipe$ServiceProxyWrapper)] when instanciating 
bean provider

I have been googled for a time and try this solution but unfortunately this was not solve my problem.

Missing Dependency for OpenDaylight controller app (Sodium SR1)

Final impl/src/main/resources/OSGI-INF/blueprint/impl-blueprint.xml file as follows;

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
  odl:use-default-for-reference-types="true">

  <reference id="dataBroker"
    interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
    odl:type="default" />
  <reference id="rpcProviderService"
    interface="org.opendaylight.mdsal.binding.api.RpcProviderService"
    odl:type="default" />


  <bean id="provider"
    class="org.opendaylight.hello.impl.HelloProvider"
    init-method="init" destroy-method="close">
    <argument ref="dataBroker" />
    <argument ref="rpcProviderService" />
  </bean>

</blueprint>

YANG file:

module hello {
    yang-version 1;
    namespace "urn:opendaylight:params:xml:ns:yang:hello";
    prefix "hello";
    revision "2019-11-27" {
        description "Initial revision of hello model";
    }
    rpc hello-world {
        input {
            leaf name {
                type string;
            }
        }
        output {
            leaf greeting {
                type string;
            }
        }
    }
}

HelloProvider.java:

package org.opendaylight.hello.impl;

import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev191127.HelloService;
import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HelloProvider {

    private static final Logger LOG = LoggerFactory.getLogger(HelloProvider.class);

    private final DataBroker dataBroker;
    private ObjectRegistration<HelloService> helloService;
    private RpcProviderService rpcProviderService;

    public HelloProvider(final DataBroker dataBroker, final RpcProviderService rpcProviderService) {
        this.dataBroker = dataBroker;
        this.rpcProviderService = rpcProviderService;
    }

    /**
    * Method called when the blueprint container is created.
    */
    public void init() {
        LOG.info("HelloProvider Session Initiated");
        helloService = rpcProviderService.registerRpcImplementation(HelloService.class, new HelloWorldImpl());
    }

    /**
    * Method called when the blueprint container is destroyed.
    */
    public void close() {
        LOG.info("HelloProvider Closed");
        if (helloService != null) {
            helloService.close();
        }
    }
}

So what is the problem?


Solution

  • The type of the DataBroker constructor parameter for HelloProvider in the blueprint XML (org.opendaylight.controller.md.sal.binding.api.DataBroker) doesn't match the code (org.opendaylight.mdsal.binding.api.DataBroker).