ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

odl-apps-hello

2021-10-17 20:02:09  阅读:152  来源: 互联网

标签:into apps public project odl true hello opendaylight


odl-apps-hello

replace the maven settings.xml file

url:https://github.com/opendaylight/odlparent/tree/stable/carbon
<!--?xml version="1.0" encoding="UTF-8"?-->
<!-- vi: set et smarttab sw=2 tabstop=2: -->
<!--
 Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.

 This program and the accompanying materials are made available under the
 terms of the Eclipse Public License v1.0 which accompanies this distribution,
 and is available at http://www.eclipse.org/legal/epl-v10.html
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<!--add aliyun mirrors-->
  <mirrors>
    <mirror>
        <id>aliyunmaven</id>
        <mirrorof>*</mirrorof>
        <name>阿里云公共仓库</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>opendaylight-release</id>
      <repositories>
        <repository>
          <id>opendaylight-mirror</id>
          <name>opendaylight-mirror</name>
          <url>https://nexus.opendaylight.org/content/repositories/public/</url>
          <releases>
            <enabled>true</enabled>
            <updatepolicy>never</updatepolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginrepositories>
        <pluginrepository>
          <id>opendaylight-mirror</id>
          <name>opendaylight-mirror</name>
          <url>https://nexus.opendaylight.org/content/repositories/public/</url>
          <releases>
            <enabled>true</enabled>
            <updatepolicy>never</updatepolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginrepository>
      </pluginrepositories>
    </profile>

    <profile>
      <id>opendaylight-snapshots</id>
      <repositories>
        <repository>
          <id>opendaylight-snapshot</id>
          <name>opendaylight-snapshot</name>
          <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginrepositories>
        <pluginrepository>
          <id>opendaylight-snapshot</id>
          <name>opendaylight-snapshot</name>
          <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginrepository>
      </pluginrepositories>
    </profile>
    
    
    <!--carbon needs to add an archetype profile-->
    <profile>
      <id>odlarchtype</id>
      <repositories>
        <repository>
          <id>archetype</id>
          <url>http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
          <releases>
            <enabled>true</enabled>
            <checksumpolicy>fail</checksumpolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <checksumpolicy>warn</checksumpolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <activeprofiles>
    <activeprofile>opendaylight-release</activeprofile>
    <activeprofile>opendaylight-snapshots</activeprofile>
  </activeprofiles>
</settings>

a good maven settings.xml article

https://www.cnblogs.com/jingmoxukong/p/6050172.html

till now, we have achieved the first step.(we assume readers already have maven environments)

generate odl project skeleton

mvn archetype:generate 
-DarchetypeGroupId=org.opendaylight.controller # project organizers exclusive identifier
-DarchetypeArtifactId=opendaylight-startup-archetype 
-DarchetypeRepository=https://nexus.opendaylight.org/content/repositories/public 
-DarchetypeVersion=1.3.2-Carbon 
-DgroupId=org.hut.hello 
-DartifactId=hello 
-DclassPrefix=Hello 
-Dcopyright=cmyhhxx

complie odl project skeleton

get into the project root path

mvn clean install 
-DskipTests 
-Dmaven.javadoc.skip=true 
-Dcheckstyle.skip=true

import the project into idea

get into the project root path

mvn idea:idea

open the .ipr file in idea,you can code in idea

edit the yang code

get into the following path

module hello {
    yang-version 1;
    namespace "urn:opendaylight:params:xml:ns:yang:hello";
    prefix "hello";

    rpc hello-world {
        input {
            leaf name {
                type string;
            }
        }
        output {
            leaf greeting {
                type string;
            }
        }
    }
}

compile the project and edit HelloProvider.java

get into the /api path

mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
public class HelloProvider implements HelloService {

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

    private final DataBroker dataBroker;

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

    /**
     * Method called when the blueprint container is created.
     */
    public void init() {
        LOG.info("HelloProvider Session Initiated");
    }

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

    @Override
    public Future<rpcresult<helloworldoutput>> helloWorld(HelloWorldInput input) {
        HelloWorldOutputBuilder h1 = new HelloWorldOutputBuilder();
        h1.setGreeting("hhhhhh"+input.getName());
        return RpcResultBuilder.success(h1.build()).buildFuture();
    }
}

register odl-rpc-implments into impl-buleprint.xml

<!--?xml version="1.0" encoding="UTF-8"?-->
<!-- vi: set et smarttab sw=4 tabstop=4: -->
<!--
Copyright © 2017 cmyhhxx and others. All rights reserved.

This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
and is available at http://www.eclipse.org/legal/epl-v10.html
-->
<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">

  <bean id="provider" class="org.hut.hello.impl.HelloProvider" init-method="init" destroy-method="close">
    <argument ref="dataBroker">
  </argument></bean>
  <odl:rpc-implementation ref="provider"></odl:rpc-implementation>
</reference></blueprint>

compile the code

get into the /impl path

mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true

get into the project root path

mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true

test the hello project

cd /${your_project_home}/karaf/target/assembly/bin
./karaf
  • test from the apidoc
http://${your_host_ip}:8181/apidoc/explorer/index.html
  • test from a REST client
    • choose postman or insomnia to send restful api
post url:
http://${your_odlserver_ip}:8181/restconf/operations/hello:hello-world

how to solve the problem java.lang.NumberFormatException: For input string: "0x100" if you met

vim /etc/profile

add the follwing into the end of the profile

export TERM=xterm-color

标签:into,apps,public,project,odl,true,hello,opendaylight
来源: https://www.cnblogs.com/cmyadorable/p/15417883.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有