odl-apps-hello
作者:互联网
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