From 94cd1ffc720bc206f6b75a8781acbcdb147f7778 Mon Sep 17 00:00:00 2001 From: RY303T Date: Wed, 30 Aug 2017 16:12:42 -0400 Subject: 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 --- .../appc/adapter/iaas/impl/IdentityURL.java | 30 +++++++++++++++++++--- .../openecomp/appc/adapter/iaas/impl/VMURL.java | 30 +++++++++++++++++++--- .../org/openecomp/appc/default.properties | 7 +++++ 3 files changed, 60 insertions(+), 7 deletions(-) (limited to 'appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main') 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 @@ -47,6 +47,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 */ @@ -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); } } @@ -104,6 +110,13 @@ public class IdentityURL { return host; } + /** + * @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 */ @@ -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 @@ -49,6 +49,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 */ @@ -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); } } @@ -112,6 +118,13 @@ public class VMURL { return host; } + /** + * @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 */ @@ -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 -- cgit 1.2.3-korg