Added wrapper application of openstack4j
It is impossible to use openstack4j directly from ONOS apps
due to the Jersey version conflict.
Change-Id: I2df32430de42d627b03e0a2f8d8d2b9067ad3e14
diff --git a/apps/openstack4j/app.xml b/apps/openstack4j/app.xml
new file mode 100644
index 0000000..bcaf7b6
--- /dev/null
+++ b/apps/openstack4j/app.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2016 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<app name="org.onosproject.openstack4j" origin="ON.Lab" version="${project.version}"
+ category="default" url="http://onosproject.org"
+ featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
+ features="${project.artifactId}" apps="">
+ <description>${project.description}</description>
+ <artifact>mvn:${project.groupId}/onos-app-openstack4j/${project.version}</artifact>
+</app>
\ No newline at end of file
diff --git a/apps/openstack4j/features.xml b/apps/openstack4j/features.xml
new file mode 100644
index 0000000..5ea7619
--- /dev/null
+++ b/apps/openstack4j/features.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ ~ Copyright 2016 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+ <feature name="${project.artifactId}" version="${project.version}" description="${project.description}">
+ <bundle>mvn:${project.groupId}/onos-app-openstack4j/${project.version}</bundle>
+ <bundle>wrap:mvn:org.pacesys/openstack4j/2.10/jar/withdeps$Bundle-SymbolicName=openstack4j&Bundle-Version=2.10</bundle>
+ </feature>
+</features>
\ No newline at end of file
diff --git a/apps/openstack4j/pom.xml b/apps/openstack4j/pom.xml
new file mode 100644
index 0000000..65e2d38
--- /dev/null
+++ b/apps/openstack4j/pom.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2016 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-apps</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-app-openstack4j</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>Wrapper application of openstack4j.</description>
+
+ <properties>
+ <onos.app.name>org.onosproject.openstack4j</onos.app.name>
+ <onos.app.category>default</onos.app.category>
+ <onos.app.url>http://onosproject.org</onos.app.url>
+ <onos.app.readme>Wrapper application of openstack4j.</onos.app.readme>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.pacesys</groupId>
+ <artifactId>openstack4j</artifactId>
+ <version>2.10</version>
+ <classifier>withdeps</classifier>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Import-Package>
+ org.slf4j,
+ javax.xml.*,
+ javax.net.*,
+ javax.activation,
+ org.w3c.dom.*,
+ org.xml.sax.*,
+ !com.sun.jdi,
+ !org.openstack4j.*
+ </Import-Package>
+ <Export-Package>
+ org.onosproject.openstack4j,
+ org.openstack4j.api,
+ org.openstack4j.model.network.*
+ </Export-Package>
+ <Embed-Transitive>true</Embed-Transitive>
+ <Embed-Dependency>openstack4j</Embed-Dependency>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/apps/openstack4j/src/main/java/org/onosproject/openstack4j/OpenStack4jManager.java b/apps/openstack4j/src/main/java/org/onosproject/openstack4j/OpenStack4jManager.java
new file mode 100644
index 0000000..6a010b2
--- /dev/null
+++ b/apps/openstack4j/src/main/java/org/onosproject/openstack4j/OpenStack4jManager.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstack4j;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Service;
+import org.openstack4j.api.OSClient;
+import org.openstack4j.api.exceptions.AuthenticationException;
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.Port;
+import org.openstack4j.model.network.Subnet;
+import org.openstack4j.model.network.options.PortListOptions;
+import org.openstack4j.openstack.OSFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Wrapper implementation of openstack4j.
+ */
+@Component(immediate = true)
+@Service
+public class OpenStack4jManager implements OpenStack4jService {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Activate
+ protected void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ log.info("Stopped");
+ }
+
+ @Override
+ public OSClient getClient(String endpoint, String tenant, String user, String password) {
+ try {
+ return OSFactory.builder()
+ .endpoint(endpoint)
+ .credentials(user, password)
+ .tenantName(tenant)
+ .authenticate();
+ } catch (AuthenticationException e) {
+ log.warn("Failed to authenticate");
+ return null;
+ }
+ }
+
+ @Override
+ public List<Network> getNetworks(OSClient client) {
+ checkNotNull(client, "OSClient is null");
+ return client.networking().network().list()
+ .stream()
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Network getNetwork(OSClient client, String networkId) {
+ checkNotNull(client, "OSClient is null");
+ return client.networking().network().get(networkId);
+ }
+
+ @Override
+ public List<Port> getPorts(OSClient client) {
+ checkNotNull(client, "OSClient is null");
+ return client.networking().port().list()
+ .stream()
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public List<Port> getPorts(OSClient client, PortListOptions options) {
+ checkNotNull(client, "OSClient is null");
+ return client.networking().port().list(options)
+ .stream()
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Port getPort(OSClient client, String portId) {
+ checkNotNull(client, "OSClient is null");
+ return client.networking().port().get(portId);
+ }
+
+ @Override
+ public List<Subnet> getSubnets(OSClient client) {
+ checkNotNull(client, "OSClient is null");
+ return client.networking().subnet().list()
+ .stream()
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Subnet getSubnet(OSClient client, String subnetId) {
+ checkNotNull(client, "OSClient is null");
+ return client.networking().subnet().get(subnetId);
+ }
+}
diff --git a/apps/openstack4j/src/main/java/org/onosproject/openstack4j/OpenStack4jService.java b/apps/openstack4j/src/main/java/org/onosproject/openstack4j/OpenStack4jService.java
new file mode 100644
index 0000000..028079e
--- /dev/null
+++ b/apps/openstack4j/src/main/java/org/onosproject/openstack4j/OpenStack4jService.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.openstack4j;
+
+import org.openstack4j.api.OSClient;
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.Port;
+import org.openstack4j.model.network.Subnet;
+import org.openstack4j.model.network.options.PortListOptions;
+
+import java.util.List;
+
+/**
+ * Wrapper service of openstack4j.
+ */
+public interface OpenStack4jService {
+
+ /**
+ * Returns OpenStack REST client.
+ *
+ * @param endpoint endpoint URL
+ * @param tenant tenant name
+ * @param user user name
+ * @param password password
+ * @return openstack rest client or null if auth failed
+ */
+ OSClient getClient(String endpoint, String tenant, String user, String password);
+
+ /**
+ * Returns list of networks with a client information.
+ *
+ * @param client openstack rest client
+ * @return list of networks or empty list if no networks
+ */
+ List<Network> getNetworks(OSClient client);
+
+ /**
+ * Returns network information.
+ *
+ * @param client openstack rest client
+ * @param networkId network id
+ * @return network or null if not found
+ */
+ Network getNetwork(OSClient client, String networkId);
+
+ /**
+ * Returns all ports.
+ *
+ * @param client openstack rest client
+ * @return list of port or empty list if no ports
+ */
+ List<Port> getPorts(OSClient client);
+
+ /**
+ * Returns ports with a given options.
+ *
+ * @param client openstack rest client
+ * @param options port list options
+ * @return port list or empty list if no ports
+ */
+ List<Port> getPorts(OSClient client, PortListOptions options);
+
+ /**
+ * Returns port with a given port ID.
+ *
+ * @param client openstack rest client
+ * @param portId port id
+ * @return port or null if not found
+ */
+ Port getPort(OSClient client, String portId);
+
+ /**
+ * Returns all subnets.
+ *
+ * @param client openstack rest client
+ * @return subnet list or empty list if no subnets
+ */
+ List<Subnet> getSubnets(OSClient client);
+
+ /**
+ * Returns subnet with a given subnet ID.
+ *
+ * @param client openstack rest client
+ * @param subnetId subnet id
+ * @return subnet or null if not found
+ */
+ Subnet getSubnet(OSClient client, String subnetId);
+}
diff --git a/apps/openstack4j/src/main/java/org/onosproject/openstack4j/package-info.java b/apps/openstack4j/src/main/java/org/onosproject/openstack4j/package-info.java
new file mode 100644
index 0000000..a11204b
--- /dev/null
+++ b/apps/openstack4j/src/main/java/org/onosproject/openstack4j/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Wrapper application of openstack4j.
+ */
+package org.onosproject.openstack4j;
\ No newline at end of file
diff --git a/apps/pom.xml b/apps/pom.xml
index 0aa0716..789cc5a 100644
--- a/apps/pom.xml
+++ b/apps/pom.xml
@@ -68,6 +68,7 @@
<module>vpls</module>
<module>openstacknode</module>
<module>openstacknetworking</module>
+ <module>openstack4j</module>
</modules>
<properties>