ODL开发----helloworld实现

root@tian01-virtual-machine:/home/tian01# mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype -DarchetypeRepository=http://nexus.opendaylight.org/content/repositories/opendaylight.release/ -DarchetypeCatalog=remote -DarchetypeVersion=1.5.1
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:3.2.0:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] 
[INFO] <<< maven-archetype-plugin:3.2.0:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] 
[INFO] --- maven-archetype-plugin:3.2.0:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype repository not defined. Using the one from [org.opendaylight.controller:opendaylight-startup-archetype:1.9.3] found in catalog remote
Define value for property 'groupId': org.opendaylight.helloworld
Define value for property 'artifactId': helloworld
[INFO] Using property: version = 0.1.0
Define value for property 'package' org.opendaylight.helloworld: : 
Define value for property 'classPrefix' Helloworld: : 
Define value for property 'copyright':   
[INFO] Using property: copyrightYear = 2017
[WARNING] Archetype is not fully configured
[INFO] Using property: groupId = org.opendaylight.helloworld
[INFO] Using property: artifactId = helloworld
[INFO] Using property: version = 0.1.0
[INFO] Using property: package = org.opendaylight.helloworld
[INFO] Using property: classPrefix = Helloworld
Define value for property 'copyright': Copyright(c) tian
[INFO] Using property: copyrightYear = 2017
Confirm properties configuration:
groupId: org.opendaylight.helloworld
artifactId: helloworld
version: 0.1.0
package: org.opendaylight.helloworld
classPrefix: Helloworld
copyright: Copyright(c) tian
copyrightYear: 2017
 Y: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: opendaylight-startup-archetype:1.5.1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.opendaylight.helloworld
[INFO] Parameter: artifactId, Value: helloworld
[INFO] Parameter: version, Value: 0.1.0
[INFO] Parameter: package, Value: org.opendaylight.helloworld
[INFO] Parameter: packageInPathFormat, Value: org/opendaylight/helloworld
[INFO] Parameter: classPrefix, Value: Helloworld
[INFO] Parameter: package, Value: org.opendaylight.helloworld
[INFO] Parameter: version, Value: 0.1.0
[INFO] Parameter: copyright, Value: Copyright(c) tian
[INFO] Parameter: groupId, Value: org.opendaylight.helloworld
[INFO] Parameter: artifactId, Value: helloworld
[INFO] Parameter: copyrightYear, Value: 2017
[WARNING] Don't override file /home/tian01/helloworld/pom.xml
[INFO] Project created from Archetype in dir: /home/tian01/helloworld
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:23 min
[INFO] Finished at: 2021-04-06T11:10:09+08:00
[INFO] Final Memory: 20M/60M
[INFO] ------------------------------------------------------------------------
root@tian01-virtual-machine:/home/tian01# ls
examples.desktop  helloworld  idea-IC-182.5262.2  karaf-0.8.1  log  mininet  openvswitch  ryu  vmware-tools-distrib  公共的  模板  视频  图片  文档  下载  音乐  桌面
root@tian01-virtual-machine:/home/tian01# cd helloworld/
root@tian01-virtual-machine:/home/tian01/helloworld# mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] ODL :: org.opendaylight.helloworld :: helloworld-api
[INFO] ODL :: org.opendaylight.helloworld :: helloworld-impl
[INFO] OpenDaylight :: helloworld :: API [Karaf Feature]
[INFO] OpenDaylight :: helloworld :: Impl [Karaf Feature]
[INFO] ODL :: org.opendaylight.helloworld :: helloworld-cli
[INFO] OpenDaylight :: helloworld :: CLI [Karaf Feature]
[INFO] OpenDaylight :: helloworld :: REST [Karaf Feature]
[INFO] ODL :: org.opendaylight.helloworld :: features-helloworld
[INFO] ODL :: org.opendaylight.helloworld :: helloworld-karaf
[INFO] ODL :: org.opendaylight.helloworld :: helloworld-features-aggregator
[INFO] ODL :: org.opendaylight.helloworld :: helloworld-artifacts
[INFO] ODL :: org.opendaylight.helloworld :: helloworld-it
[INFO] helloworld
......
......
[INFO] ODL :: org.opendaylight.helloworld :: helloworld-artifacts SUCCESS [  0.041 s]
[INFO] ODL :: org.opendaylight.helloworld :: helloworld-it  SUCCESS [  4.899 s]
[INFO] helloworld ......................................... SUCCESS [  0.369 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:54 min
[INFO] Finished at: 2021-04-06T11:29:08+08:00
[INFO] Final Memory: 178M/426M
[INFO] ------------------------------------------------------------------------
root@tian01-virtual-machine:/home/tian01/helloworld# ls
api  artifacts  cli  features  impl  it  karaf  pom.xml  src  target
root@tian01-virtual-machine:/home/tian01/helloworld# cd karaf/
root@tian01-virtual-machine:/home/tian01/helloworld/karaf# ls
pom.xml  target
root@tian01-virtual-machine:/home/tian01/helloworld/karaf# cd target/
root@tian01-virtual-machine:/home/tian01/helloworld/karaf/target# ls
antrun  assembly  classes  cpd.xml  dependency-maven-plugin-markers  helloworld-karaf-0.1.0.jar  helloworld-karaf-0.1.0.tar.gz  helloworld-karaf-0.1.0.zip  maven-archiver
root@tian01-virtual-machine:/home/tian01/helloworld/karaf/target# cd a
antrun/   assembly/ 
root@tian01-virtual-machine:/home/tian01/helloworld/karaf/target# cd assembly/
root@tian01-virtual-machine:/home/tian01/helloworld/karaf/target/assembly# ls
bin  configuration  CONTRIBUTING.markdown  data  deploy  etc  lib  LICENSE  README.markdown  system
root@tian01-virtual-machine:/home/tian01/helloworld/karaf/target/assembly# cd bin/
root@tian01-virtual-machine:/home/tian01/helloworld/karaf/target/assembly/bin# ls
client  client.bat  contrib  inc  instance  instance.bat  karaf  karaf.bat  setenv  setenv.bat  shell  shell.bat  start  start.bat  status  status.bat  stop  stop.bat
root@tian01-virtual-machine:/home/tian01/helloworld/karaf/target/assembly/bin# ./karaf 
karaf: JAVA_HOME not set; results may vary
Apache Karaf starting up. Press Enter to open the shell now...
100% [========================================================================]

Karaf started in 1s. Bundle stats: 13 active, 13 total
                                                                                           
    ________                       ________                .__  .__       .__     __       
    \_____  \ ______   ____   ____ \______ \ _____  ___.__.|  | |__| ____ |  |___/  |_     
     /   |   \\____ \_/ __ \ /    \ |    |  \\__  \<   |  ||  | |  |/ ___\|  |  \   __\    
    /    |    \  |_> >  ___/|   |  \|    `   \/ __ \\___  ||  |_|  / /_/  >   Y  \  |      
    \_______  /   __/ \___  >___|  /_______  (____  / ____||____/__\___  /|___|  /__|      
            \/|__|        \/     \/        \/     \/\/            /_____/      \/          
                                                                                           

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown OpenDaylight.

karaf@root()>       

在这里插入图片描述

module helloworld {
    yang-version 1.1;
    namespace "urn:opendaylight:params:xml:ns:yang:helloworld";
    prefix "helloworld";

    revision "2017-08-30" { // TODO change revision to date of model creation
        description "Initial revision of helloworld model";
    }
    rpc hello-world {
            input {
                leaf name {
                    type string;
                }
            }
            output {
                leaf greeting {
                    type string;
                }
            }
        }
}

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<!-- vi: set et smarttab sw=4 tabstop=4: -->
<!--
Copyright © 2017 Copyright(c) tian 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" />
  <reference id="rpcRegistry"
             interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"/>

  <bean id="provider"
    class="org.opendaylight.helloworld.impl.HelloworldProvider"
    init-method="init" destroy-method="close">
    <argument ref="dataBroker" />
    <argument ref="rpcRegistry" />
  </bean>

</blueprint>

在这里插入图片描述

package org.opendaylight.helloworld.impl;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.helloworld.rev170830.HelloworldService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HelloworldProvider {

    private static final Logger LOG = LoggerFactory.getLogger(HelloworldProvider.class);
    private final DataBroker dataBroker;
    private final RpcProviderRegistry rpcProviderRegistry;
    private BindingAwareBroker.RpcRegistration<HelloworldService> serviceRpcRegistration;

    public HelloworldProvider(final DataBroker dataBroker, final RpcProviderRegistry rpcProviderRegistry) {
        this.dataBroker = dataBroker;
        this.rpcProviderRegistry  = rpcProviderRegistry;
    }
    /**
     * Method called when the blueprint container is created.
     */
    public void init() {
        serviceRpcRegistration = rpcProviderRegistry.addRpcImplementation(HelloworldService.class,new HelloWorldImpl());
        LOG.info("HelloworldProvider Session Initiated");
    }
    /**
     * Method called when the blueprint container is destroyed.
     */
    public void close() {
        serviceRpcRegistration.close();
        LOG.info("HelloworldProvider Closed");
    }
}

在这里插入图片描述

package org.opendaylight.helloworld.impl;

import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.helloworld.rev170830.HelloWorldInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.helloworld.rev170830.HelloWorldOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.helloworld.rev170830.HelloWorldOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.helloworld.rev170830.HelloworldService;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;


public class HelloWorldImpl implements HelloworldService {
    @Override
    public ListenableFuture<RpcResult<HelloWorldOutput>> helloWorld(HelloWorldInput input) {
        HelloWorldOutputBuilder helloBuilder = new HelloWorldOutputBuilder();
        helloBuilder.setGreeting("Hello,"+input.getName());
        return RpcResultBuilder.success(helloBuilder.build()).buildFuture();
    }
}

在这里插入图片描述
在这里插入图片描述
windows
在这里插入图片描述
在这里插入图片描述

mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值