aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-iaas-adapter
diff options
context:
space:
mode:
authorRY303T <RY303T@att.com>2017-08-30 16:12:42 -0400
committerRanda Maher <rx196w@att.com>2017-09-01 00:18:57 +0000
commit94cd1ffc720bc206f6b75a8781acbcdb147f7778 (patch)
tree09a40eab18f13eba2c4b1b85baee705302230892 /appc-adapters/appc-iaas-adapter
parent3df3182a7badeef662f743bfc8d67cea805b1ef4 (diff)
Modify IaaS adapter URL parsing to include path
Modified the pattern in IdentityURL and VMURL to include optional path Modified the toString in IdentityURL and VMURL to properly print the full url string Updated tests to include new URL format Issue-ID: APPC-133 Change-Id: Ic7c272b70d4fe18c815d5dd5311f760d8b8953c1 Signed-off-by: RY303T <RY303T@att.com>
Diffstat (limited to 'appc-adapters/appc-iaas-adapter')
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/impl/IdentityURL.java30
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/impl/VMURL.java30
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties7
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestIdentityUrl.java51
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestVMURL.java37
5 files changed, 139 insertions, 16 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/impl/IdentityURL.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/impl/IdentityURL.java
index 482e54a9d..327191af2 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/impl/IdentityURL.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/impl/IdentityURL.java
@@ -35,7 +35,7 @@ public class IdentityURL {
* The regular expression pattern used to parse the URL. Capturing groups are used to identify and extract the
* various component parts of the URL.
*/
- private static Pattern pattern = Pattern.compile("(\\p{Alnum}+)://([^/:]+)(?::([0-9]+))?/(v[0-9\\.]+)/?");
+ private static Pattern pattern = Pattern.compile("(\\p{Alnum}+)://([^/:]+)(?::([0-9]+))?(/.*)?/(v[0-9\\.]+)/?");
/**
* The URL scheme or protocol, such as HTTP or HTTPS
@@ -48,6 +48,11 @@ public class IdentityURL {
private String host;
/**
+ * The path of the service, or null if no path is defined
+ */
+ private String path;
+
+ /**
* The port number, or null if no port is defined
*/
private String port;
@@ -83,7 +88,8 @@ public class IdentityURL {
obj.scheme = matcher.group(1);
obj.host = matcher.group(2);
obj.port = matcher.group(3);
- obj.version = matcher.group(4);
+ obj.path = matcher.group(4);
+ obj.version = matcher.group(5);
}
}
@@ -105,6 +111,13 @@ public class IdentityURL {
}
/**
+ * @return The URL path, or null if no path was defined
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
* @return The URL port, or null if no port was defined
*/
public String getPort() {
@@ -117,7 +130,18 @@ public class IdentityURL {
@Override
public String toString() {
- return String.format("%s://%s:%s/%s", scheme, host, port, version);
+ StringBuilder str = new StringBuilder();
+
+ str.append(scheme + "://" + host);
+ if (port != null) {
+ str.append(":" + port);
+ }
+ if (path != null) {
+ str.append(path);
+ }
+ str.append("/" + version);
+
+ return str.toString();
}
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/impl/VMURL.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/impl/VMURL.java
index e591a5616..20b15bb1e 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/impl/VMURL.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/impl/VMURL.java
@@ -37,7 +37,7 @@ public class VMURL {
* various component parts of the URL.
*/
private static Pattern pattern = Pattern
- .compile("(\\p{Alnum}+)://([^/:]+)(?::([0-9]+))?/v2/([^/]+)/servers/([^/]+)");
+ .compile("(\\p{Alnum}+)://([^/:]+)(?::([0-9]+))?(/.*)?/v2/([^/]+)/servers/([^/]+)");
/**
* The URL scheme or protocol, such as HTTP or HTTPS
@@ -50,6 +50,11 @@ public class VMURL {
private String host;
/**
+ * The path, or null if no path is defined
+ */
+ private String path;
+
+ /**
* The port number, or null if no port is defined
*/
private String port;
@@ -90,8 +95,9 @@ public class VMURL {
obj.scheme = matcher.group(1);
obj.host = matcher.group(2);
obj.port = matcher.group(3);
- obj.tenantId = matcher.group(4);
- obj.serverId = matcher.group(5);
+ obj.path = matcher.group(4);
+ obj.tenantId = matcher.group(5);
+ obj.serverId = matcher.group(6);
}
}
@@ -113,6 +119,13 @@ public class VMURL {
}
/**
+ * @return THe URL path, or null if no path was defined
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
* @return The URL port, or null if no port was defined
*/
public String getPort() {
@@ -135,7 +148,16 @@ public class VMURL {
@Override
public String toString() {
- return String.format("%s://%s:%s/%s/servers/%s", scheme, host, port, tenantId, serverId);
+ StringBuilder str = new StringBuilder();
+ str.append(scheme + "://" + host);
+ if (port != null) {
+ str.append(":" + port);
+ }
+ if (path != null) {
+ str.append(path);
+ }
+ str.append("/v2/" + tenantId + "/servers/" + serverId);
+ return str.toString();
}
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties
index 75fc1edf8..21f96d9ee 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties
@@ -103,3 +103,10 @@ provider1.identity=appc
provider1.tenant1.name=appc
provider1.tenant1.userid=appc
provider1.tenant1.password=appc
+
+#Your OpenStack IP
+test.ip=192.168.1.2
+# Your OpenStack Platform's Keystone Port (default is 5000)
+test.port=5000
+test.tenantid=abcde12345fghijk6789lmnopq123rst
+test.vmid=abc12345-1234-5678-890a-abcdefg12345
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestIdentityUrl.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestIdentityUrl.java
index be0535f64..1694529f4 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestIdentityUrl.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestIdentityUrl.java
@@ -26,6 +26,8 @@
package org.openecomp.appc.adapter.iaas.impl;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.util.Properties;
@@ -48,10 +50,55 @@ public class TestIdentityUrl {
* Test that we can parse and interpret valid URLs
*/
@Test
- public void testValidURLs() {
+ public void testValidURL1() {
URL = "http://192.168.1.1:5000/v2.0/";
IdentityURL idurl = IdentityURL.parseURL(URL);
assertNotNull(idurl);
- System.out.println(idurl.getVersion());
+ assertTrue(idurl.getScheme().equals("http"));
+ assertTrue(idurl.getHost().equals("192.168.1.1"));
+ assertTrue(idurl.getPort().equals("5000"));
+ assertNull(idurl.getPath());
+ assertTrue(idurl.getVersion().equals("v2.0"));
+ assertTrue(idurl.toString().equals("http://192.168.1.1:5000/v2.0"));
+ }
+
+ @Test
+ public void testValidURL2() {
+ URL = "https://192.168.1.1:5000/v3/";
+ IdentityURL idurl = IdentityURL.parseURL(URL);
+ assertNotNull(idurl);
+ assertTrue(idurl.getScheme().equals("https"));
+ assertTrue(idurl.getHost().equals("192.168.1.1"));
+ assertTrue(idurl.getPort().equals("5000"));
+ assertNull(idurl.getPath());
+ assertTrue(idurl.getVersion().equals("v3"));
+ assertTrue(idurl.toString().equals("https://192.168.1.1:5000/v3"));
+ }
+
+ @Test
+ public void testValidURL3() {
+ URL = "http://192.168.1.1/v2.0/";
+ IdentityURL idurl = IdentityURL.parseURL(URL);
+ assertNotNull(idurl);
+ assertTrue(idurl.getScheme().equals("http"));
+ assertTrue(idurl.getHost().equals("192.168.1.1"));
+ assertNull(idurl.getPort());
+ assertNull(idurl.getPath());
+ assertTrue(idurl.getVersion().equals("v2.0"));
+ System.out.println(idurl.toString());
+ assertTrue(idurl.toString().equals("http://192.168.1.1/v2.0"));
+ }
+
+ @Test
+ public void testValidURL4() {
+ URL = "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3";
+ IdentityURL idurl = IdentityURL.parseURL(URL);
+ assertNotNull(idurl);
+ assertTrue(idurl.getScheme().equals("http"));
+ assertTrue(idurl.getHost().equals("msb.onap.org"));
+ assertTrue(idurl.getPort().equals("80"));
+ assertTrue(idurl.getPath().equals("/api/multicloud/v0/cloudowner_region/identity"));
+ assertTrue(idurl.getVersion().equals("v3"));
+ assertTrue(idurl.toString().equals("http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3"));
}
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestVMURL.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestVMURL.java
index 2173d5c74..c1434273d 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestVMURL.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestVMURL.java
@@ -27,6 +27,7 @@
package org.openecomp.appc.adapter.iaas.impl;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.Properties;
@@ -46,18 +47,19 @@ public class TestVMURL {
@BeforeClass
public static void before() {
- IP = "192.168.1.2";
- PORT = "5000";
- TENANTID = "abcde12345fghijk6789lmnopq123rst";
- VMID = "abc12345-1234-5678-890a-abcdefg12345";
- URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID);
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ IP = props.getProperty("test.ip");
+ PORT = props.getProperty("test.port");
+ TENANTID = props.getProperty("test.tenantid");
+ VMID = props.getProperty("test.vmid");
}
/**
* Test that we can parse and interpret valid URLs
*/
@Test
- public void testValidURLs() {
+ public void testValidURL1() {
+ URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID);
VMURL url = VMURL.parseURL(URL);
assertEquals("http", url.getScheme());
@@ -65,13 +67,34 @@ public class TestVMURL {
assertEquals(PORT, url.getPort());
assertEquals(TENANTID, url.getTenantId());
assertEquals(VMID, url.getServerId());
+ assertEquals(url.toString(), URL);
+ }
- url = VMURL.parseURL(String.format("http://%s/v2/%s/servers/%s", IP, TENANTID, VMID));
+ @Test
+ public void testValidURL2() {
+ URL = String.format("http://%s/v2/%s/servers/%s", IP, TENANTID, VMID);
+ VMURL url = VMURL.parseURL(URL);
assertEquals("http", url.getScheme());
assertEquals(IP, url.getHost());
assertNull(url.getPort());
+ assertNull(url.getPath());
+ assertEquals(TENANTID, url.getTenantId());
+ assertEquals(VMID, url.getServerId());
+ assertEquals(url.toString(), URL);
+ }
+
+ @Test
+ public void testValidURL3() {
+ URL = "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345";
+ VMURL url = VMURL.parseURL(URL);
+ assertNotNull(url);
+ assertEquals("http", url.getScheme());
+ assertEquals("msb.onap.org", url.getHost());
+ assertEquals("80", url.getPort());
+ assertEquals("/api/multicloud/v0/cloudowner_region", url.getPath());
assertEquals(TENANTID, url.getTenantId());
assertEquals(VMID, url.getServerId());
+ assertEquals(url.toString(), URL);
}
/**