Add tenantId to multicloud request header 09/84409/1
authorEric Multanen <eric.w.multanen@intel.com>
Sat, 6 Apr 2019 07:15:37 +0000 (00:15 -0700)
committerEric Multanen <eric.w.multanen@intel.com>
Sat, 6 Apr 2019 07:43:01 +0000 (00:43 -0700)
The multicloud API can take the tenantId as an item in the
header.  Add the tenantId to the request headers of the
multicloud plugin.

Change-Id: I7ff11cd52eea429e0c694092b006887f13de2fda
Issue-ID: SO-1446
Signed-off-by: Eric Multanen <eric.w.multanen@intel.com>
adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java

index 1fabcb2..6d4deeb 100644 (file)
@@ -45,6 +45,7 @@ import org.onap.so.adapters.vdu.VduModelInfo;
 import org.onap.so.adapters.vdu.VduPlugin;
 import org.onap.so.adapters.vdu.VduStateType;
 import org.onap.so.adapters.vdu.VduStatus;
+import org.onap.so.client.HttpClient;
 import org.onap.so.client.HttpClientFactory;
 import org.onap.so.client.RestClient;
 import org.onap.so.logger.ErrorCode;
@@ -207,7 +208,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
         }
 
         String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, null);
-        RestClient multicloudClient = getMulticloudClient(multicloudEndpoint);
+        RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId);
 
         if (multicloudClient == null) {
             MsoOpenstackException me = new MsoOpenstackException(0, "", "Multicloud client could not be initialized");
@@ -289,7 +290,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
         returnInfo.setName(stackName);
 
         String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, stackId);
-        RestClient multicloudClient = getMulticloudClient(multicloudEndpoint);
+        RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId);
 
         if (multicloudClient != null) {
             Response response = multicloudClient.get();
@@ -343,7 +344,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
         Response response = null;
 
         String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, stackId);
-        RestClient multicloudClient = getMulticloudClient(multicloudEndpoint);
+        RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId);
 
         if (multicloudClient != null) {
             response = multicloudClient.delete();
@@ -392,7 +393,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
         multicloudRequest.setVfModuleId(vfModuleId);
 
         String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, workloadId);
-        RestClient multicloudClient = getMulticloudClient(multicloudEndpoint);
+        RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId);
 
         if (multicloudClient == null) {
             if (logger.isDebugEnabled())
@@ -708,12 +709,15 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{
         }
     }
 
-    private RestClient getMulticloudClient(String endpoint) {
-        RestClient client = null;
+    private RestClient getMulticloudClient(String endpoint, String tenantId) {
+        HttpClient client = null;
         try {
             client = httpClientFactory.newJsonClient(
                 new URL(endpoint),
                 TargetEntity.MULTICLOUD);
+            if (tenantId != null && !tenantId.isEmpty()) {
+                client.addAdditionalHeader("Project", tenantId);
+            }
         } catch (MalformedURLException e) {
             logger.debug(String.format("Encountered malformed URL error getting multicloud rest client %s", e.getMessage()));
         } catch (IllegalArgumentException e) {