From 4974a05441d412a6e812e5716a0518e9e12a9acf Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Wed, 13 Feb 2019 10:18:48 -0500 Subject: Strip off TenantId from self link url Strip off TenantId from self link url Change-Id: I58ac9fe693059eb8cb93d85fb88604cb9c0a0db2 Issue-ID: SO-1502 Signed-off-by: Benjamin, Max (mb388a) --- .../org/onap/so/adapters/audit/HeatStackAudit.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'adapters/mso-openstack-adapters/src/main/java/org') diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java index 974315374a..dfe5912fbf 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java @@ -25,6 +25,8 @@ import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -174,11 +176,13 @@ public class HeatStackAudit { return vserversToAudit; } - protected Optional extractResourcePathFromHref(String href) { - URI uri; + protected Optional extractResourcePathFromHref(String href) { try { - uri = new URI(href); - return Optional.of(uri.getPath().replaceFirst("/v\\d+", "")+RESOURCES); + Optional stackPath = extractStackPathFromHref(href); + if (stackPath.isPresent()){ + return Optional.of(stackPath.get()+RESOURCES); + }else + return Optional.empty(); } catch (Exception e) { logger.error("Error parsing URI", e); } @@ -186,10 +190,14 @@ public class HeatStackAudit { } protected Optional extractStackPathFromHref(String href) { - URI uri; try { - uri = new URI(href); - return Optional.of(uri.getPath().replaceFirst("/v\\d+", "")); + URI uri = new URI(href); + Pattern p = Pattern.compile("/stacks.*"); + Matcher m = p.matcher(uri.getPath()); + if (m.find()){ + return Optional.of(m.group()); + }else + return Optional.empty(); } catch (Exception e) { logger.error("Error parsing URI", e); } -- cgit 1.2.3-korg