Thomas Vachuska
Committed by Gerrit Code Review

Adding REST archetype.

Change-Id: Ic129f6d0d419f0d44a371b7758802377a32f9962
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
37 <module>api</module> 37 <module>api</module>
38 <module>bundle</module> 38 <module>bundle</module>
39 <module>cli</module> 39 <module>cli</module>
40 + <module>rest</module>
40 <module>ui</module> 41 <module>ui</module>
41 <module>uitab</module> 42 <module>uitab</module>
42 <module>uitopo</module> 43 <module>uitopo</module>
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014-2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18 + <modelVersion>4.0.0</modelVersion>
19 +
20 + <parent>
21 + <groupId>org.onosproject</groupId>
22 + <artifactId>onos-archetypes</artifactId>
23 + <version>1.4.0-SNAPSHOT</version>
24 + </parent>
25 +
26 + <artifactId>onos-rest-archetype</artifactId>
27 + <packaging>maven-archetype</packaging>
28 +
29 + <name>onos-rest-archetype</name>
30 + <description>ONOS REST API bundle archetype</description>
31 +
32 +</project>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014-2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<archetype-descriptor
18 + xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
19 + name="onos-cli" partial="true"
20 + xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
21 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
22 + <fileSets>
23 + <fileSet filtered="true" packaged="true" encoding="UTF-8">
24 + <directory>src/main/java</directory>
25 + <includes>
26 + <include>**/*.java</include>
27 + </includes>
28 + </fileSet>
29 + <fileSet filtered="true" packaged="false" encoding="UTF-8">
30 + <directory>src/main/webapp</directory>
31 + <includes>
32 + <include>**/*.xml</include>
33 + </includes>
34 + </fileSet>
35 + </fileSets>
36 +</archetype-descriptor>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014-2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18 + <modelVersion>4.0.0</modelVersion>
19 +
20 + <groupId>${groupId}</groupId>
21 + <artifactId>${artifactId}</artifactId>
22 + <version>${version}</version>
23 + <packaging>bundle</packaging>
24 +
25 + <description>ONOS REST API bundle archetype</description>
26 + <url>http://onosproject.org</url>
27 +
28 + <properties>
29 + <onos.version>1.4.0-SNAPSHOT</onos.version>
30 +
31 + <web.context>/onos/${artifactId}</web.context>
32 + <api.version>1.0.0</api.version>
33 + <api.title>Sample app REST API</api.title>
34 + <api.description>
35 + Sample application REST API
36 + </api.description>
37 + <api.package>${package}</api.package>
38 + </properties>
39 +
40 + <dependencies>
41 + <dependency>
42 + <groupId>org.onosproject</groupId>
43 + <artifactId>onos-api</artifactId>
44 + <version>${onos.version}</version>
45 + </dependency>
46 +
47 + <dependency>
48 + <groupId>org.onosproject</groupId>
49 + <artifactId>onlab-osgi</artifactId>
50 + <version>${onos.version}</version>
51 + </dependency>
52 +
53 + <dependency>
54 + <groupId>junit</groupId>
55 + <artifactId>junit</artifactId>
56 + <version>4.11</version>
57 + <scope>test</scope>
58 + </dependency>
59 +
60 + <dependency>
61 + <groupId>org.onosproject</groupId>
62 + <artifactId>onos-cli</artifactId>
63 + <version>${onos.version}</version>
64 + <scope>provided</scope>
65 + </dependency>
66 +
67 + <dependency>
68 + <groupId>org.onosproject</groupId>
69 + <artifactId>onos-api</artifactId>
70 + <version>${onos.version}</version>
71 + <scope>test</scope>
72 + <classifier>tests</classifier>
73 + </dependency>
74 +
75 + <dependency>
76 + <groupId>org.onosproject</groupId>
77 + <artifactId>onos-rest</artifactId>
78 + <version>${onos.version}</version>
79 + <scope>provided</scope>
80 + </dependency>
81 + <dependency>
82 + <groupId>org.onosproject</groupId>
83 + <artifactId>onlab-rest</artifactId>
84 + <version>${onos.version}</version>
85 + <scope>provided</scope>
86 + </dependency>
87 +
88 + <dependency>
89 + <groupId>javax.ws.rs</groupId>
90 + <artifactId>jsr311-api</artifactId>
91 + <version>1.1.1</version>
92 + <scope>provided</scope>
93 + </dependency>
94 + <dependency>
95 + <groupId>com.sun.jersey</groupId>
96 + <artifactId>jersey-servlet</artifactId>
97 + <version>1.19</version>
98 + <scope>provided</scope>
99 + </dependency>
100 +
101 + <dependency>
102 + <groupId>com.fasterxml.jackson.core</groupId>
103 + <artifactId>jackson-databind</artifactId>
104 + <version>2.4.2</version>
105 + <scope>provided</scope>
106 + </dependency>
107 + <dependency>
108 + <groupId>com.fasterxml.jackson.core</groupId>
109 + <artifactId>jackson-annotations</artifactId>
110 + <version>2.4.2</version>
111 + <scope>provided</scope>
112 + </dependency>
113 +
114 + <dependency>
115 + <groupId>org.osgi</groupId>
116 + <artifactId>org.osgi.core</artifactId>
117 + <version>4.3.1</version>
118 + <scope>provided</scope>
119 + </dependency>
120 + <dependency>
121 + <groupId>org.apache.felix</groupId>
122 + <artifactId>org.apache.felix.scr.annotations</artifactId>
123 + <version>1.9.8</version>
124 + <scope>provided</scope>
125 + </dependency>
126 + <dependency>
127 + <groupId>org.apache.karaf.shell</groupId>
128 + <artifactId>org.apache.karaf.shell.console</artifactId>
129 + <version>3.0.3</version>
130 + <scope>provided</scope>
131 + </dependency>
132 + </dependencies>
133 +
134 + <build>
135 + <plugins>
136 + <plugin>
137 + <groupId>org.apache.felix</groupId>
138 + <artifactId>maven-bundle-plugin</artifactId>
139 + <version>2.5.3</version>
140 + <extensions>true</extensions>
141 + <configuration>
142 + <instructions>
143 + <_wab>src/main/webapp/</_wab>
144 + <Include-Resource>
145 + WEB-INF/classes/apidoc/swagger.json=target/swagger.json,
146 + {maven-resources}
147 + </Include-Resource>
148 + <Bundle-SymbolicName>
149 + ${project.groupId}.${project.artifactId}
150 + </Bundle-SymbolicName>
151 + <Import-Package>
152 + org.slf4j,
153 + org.osgi.framework,
154 + javax.ws.rs,
155 + javax.ws.rs.core,
156 + com.sun.jersey.api.core,
157 + com.sun.jersey.spi.container.servlet,
158 + com.sun.jersey.server.impl.container.servlet,
159 + com.fasterxml.jackson.databind,
160 + com.fasterxml.jackson.databind.node,
161 + com.fasterxml.jackson.core,
162 + org.apache.karaf.shell.commands,
163 + org.apache.karaf.shell.console,
164 + com.google.common.*,
165 + org.onlab.packet.*,
166 + org.onlab.rest.*,
167 + org.onosproject.*,
168 + org.onlab.util.*,
169 + org.jboss.netty.util.*
170 + </Import-Package>
171 + <Web-ContextPath>${web.context}</Web-ContextPath>
172 + </instructions>
173 + </configuration>
174 + </plugin>
175 + <plugin>
176 + <groupId>org.apache.maven.plugins</groupId>
177 + <artifactId>maven-compiler-plugin</artifactId>
178 + <version>2.5.1</version>
179 + <configuration>
180 + <source>1.8</source>
181 + <target>1.8</target>
182 + </configuration>
183 + </plugin>
184 + <plugin>
185 + <groupId>org.apache.felix</groupId>
186 + <artifactId>maven-scr-plugin</artifactId>
187 + <version>1.20.0</version>
188 + <executions>
189 + <execution>
190 + <id>generate-scr-srcdescriptor</id>
191 + <goals>
192 + <goal>scr</goal>
193 + </goals>
194 + </execution>
195 + </executions>
196 + <configuration>
197 + <supportedProjectTypes>
198 + <supportedProjectType>bundle</supportedProjectType>
199 + <supportedProjectType>war</supportedProjectType>
200 + </supportedProjectTypes>
201 + </configuration>
202 + </plugin>
203 + </plugins>
204 + </build>
205 +
206 +</project>
1 +#set( $symbol_pound = '#' )
2 +#set( $symbol_dollar = '$' )
3 +#set( $symbol_escape = '\' )
4 +/*
5 + * Copyright 2014-2015 Open Networking Laboratory
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License");
8 + * you may not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS,
15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + */
19 +
20 +package ${package};
21 +
22 +import org.onlab.rest.AbstractWebApplication;
23 +
24 +import java.util.Set;
25 +
26 +/**
27 + * Sample REST API web application.
28 + */
29 +public class AppWebApplication extends AbstractWebApplication {
30 + @Override
31 + public Set<Class<?>> getClasses() {
32 + return getClasses(AppWebResource.class);
33 + }
34 +}
1 +#set( $symbol_pound = '#' )
2 +#set( $symbol_dollar = '$' )
3 +#set( $symbol_escape = '\' )
4 +/*
5 + * Copyright 2014-2015 Open Networking Laboratory
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License");
8 + * you may not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS,
15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + */
19 +package ${package};
20 +
21 +import com.fasterxml.jackson.databind.node.ObjectNode;
22 +import org.onosproject.rest.AbstractWebResource;
23 +
24 +import javax.ws.rs.GET;
25 +import javax.ws.rs.Path;
26 +import javax.ws.rs.core.Response;
27 +
28 +import static org.onlab.util.Tools.nullIsNotFound;
29 +
30 +/**
31 + * Sample web resource.
32 + */
33 +@Path("sample")
34 +public class AppWebResource extends AbstractWebResource {
35 +
36 + /**
37 + * Get hello world greeting.
38 + *
39 + * @return 200 OK
40 + */
41 + @GET
42 + @Path("")
43 + public Response getGreeting() {
44 + ObjectNode node = mapper().createObjectNode().put("hello", "world");
45 + return ok(node).build();
46 + }
47 +
48 +}
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014-2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18 + xmlns="http://java.sun.com/xml/ns/javaee"
19 + xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
20 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
21 + id="ONOS" version="2.5">
22 + <display-name>Sample App REST API v1.0</display-name>
23 +
24 + <security-constraint>
25 + <web-resource-collection>
26 + <web-resource-name>Secured</web-resource-name>
27 + <url-pattern>/*</url-pattern>
28 + </web-resource-collection>
29 + <auth-constraint>
30 + <role-name>admin</role-name>
31 + </auth-constraint>
32 + </security-constraint>
33 +
34 + <security-role>
35 + <role-name>admin</role-name>
36 + </security-role>
37 +
38 + <login-config>
39 + <auth-method>BASIC</auth-method>
40 + <realm-name>karaf</realm-name>
41 + </login-config>
42 +
43 + <servlet>
44 + <servlet-name>JAX-RS Service</servlet-name>
45 + <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
46 + <init-param>
47 + <param-name>javax.ws.rs.Application</param-name>
48 + <param-value>${package}.AppWebApplication</param-value>
49 + </init-param>
50 + <load-on-startup>1</load-on-startup>
51 + </servlet>
52 +
53 + <servlet-mapping>
54 + <servlet-name>JAX-RS Service</servlet-name>
55 + <url-pattern>/*</url-pattern>
56 + </servlet-mapping>
57 +</web-app>
...@@ -51,7 +51,7 @@ complete -F _cell-opts cell vicell ...@@ -51,7 +51,7 @@ complete -F _cell-opts cell vicell
51 function _ocapp-opts () { 51 function _ocapp-opts () {
52 local cur=${COMP_WORDS[COMP_CWORD]} 52 local cur=${COMP_WORDS[COMP_CWORD]}
53 if [ $COMP_CWORD -eq 1 ]; then 53 if [ $COMP_CWORD -eq 1 ]; then
54 - COMPREPLY=( $( compgen -W "app bundle ui uitable uitopo cli" -- $cur ) ) 54 + COMPREPLY=( $( compgen -W "app bundle ui uitab uitopo cli rest" -- $cur ) )
55 fi 55 fi
56 } 56 }
57 57
......
...@@ -62,6 +62,20 @@ ...@@ -62,6 +62,20 @@
62 <step name="Verify-UI-Topo" requires="^" 62 <step name="Verify-UI-Topo" requires="^"
63 exec="onos-check-views ${OCI} id=sample"/> 63 exec="onos-check-views ${OCI} id=sample"/>
64 64
65 + <step name="Clean-Up-For-REST-App" cwd="${WORKSPACE}/tmp" env="~" requires="Reinstall-App-With-UI-Topo"
66 + exec="rm -r test-app"/>
67 +
68 + <step name="Create-REST-App" cwd="${WORKSPACE}/tmp" requires="^"
69 + exec="onos-create-app app org.test.app test-app 1.2.3 org.test.app -DinteractiveMode=false"/>
70 + <step name="Create-REST-Overlay" requires="^"
71 + exec="onos-create-app rest org.test.app test-app 1.2.3 org.test.app -DinteractiveMode=false"/>
72 + <step name="Build-REST-App" requires="^"
73 + exec="mvn clean install"/>
74 + <step name="Install-REST-App" requires="^,~Verify-UI-Topo"
75 + exec="onos-app ${OCI} reinstall! target/test-app-1.2.3.oar"/>
76 + <Xstep name="Verify-REST-App" requires="^" delay="2"
77 + exec="curl --fail -isS --user ${ONOS_WEB_USER}:${ONOS_WEB_PASS} http://${OCI}:8181/onos/test-app/sample"/>
78 +
65 <step name="Uninstall-App" requires="^" 79 <step name="Uninstall-App" requires="^"
66 exec="onos-app ${OCI} uninstall org.foo.app"/> 80 exec="onos-app ${OCI} uninstall org.foo.app"/>
67 </group> 81 </group>
......