Fix cloudSite creation in homing 89/74089/1
authorMarcus G K Williams <marcus.williams@intel.com>
Fri, 30 Nov 2018 21:38:15 +0000 (13:38 -0800)
committerMarcus G K Williams <marcus.williams@intel.com>
Fri, 30 Nov 2018 21:38:26 +0000 (13:38 -0800)
This change fixes the use of optional
in OofInfraUtils.java, so that cloudSites
can be created if one is not found in
catalogDB.

Issue-ID: SO-1262
Change-Id: Ifec9083950758c650a369e9c5ebd386715ed9df8
Signed-off-by: Marcus G K Williams <marcus.williams@intel.com>
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/util/OofInfraUtils.java

index df3399f..b03256b 100644 (file)
@@ -268,7 +268,7 @@ class OofHoming extends AbstractServiceTaskProcessor {
                             cloudIdentity.setAdminTenant("service")
                             cloudIdentity.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD)
                             String msoMulticloudUserName = UrnPropertiesReader
-                                    .getVariable("mso.multicloud.api.password", execution,
+                                    .getVariable("mso.multicloud.api.username", execution,
                                     "apih")
                             String msoMulticloudPassword = UrnPropertiesReader
                                     .getVariable("mso.multicloud.api.password", execution,
index b62d8be..df7b57f 100644 (file)
@@ -45,18 +45,27 @@ public class OofInfraUtils {
     public void createCloudSite(CloudSite cloudSite, DelegateExecution execution) {
         String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
         String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
-        Optional <CloudSite> optCloudsite = Optional.empty();
-
-        CatalogDbClient client = new CatalogDbClient(endpoint, auth);
         try {
-            optCloudsite = Optional.ofNullable(client.getCloudSite(cloudSite.getId(), endpoint + "/cloudSite/"));
+            CloudSite getCloudsite;
+
+            CatalogDbClient client = new CatalogDbClient(endpoint, auth);
+
+            getCloudsite = Optional.ofNullable(client.getCloudSite(cloudSite.getId(), endpoint + "/cloudSite/")).orElse(new CloudSite());
+            if (!cloudSite.getId().equals(getCloudsite.getId())) {
+                client.postCloudSite(cloudSite);
+                LOGGER.debug("Did not findd cloudsite : " + cloudSite.getId());
+                LOGGER.debug("Will create cloudSite: " + cloudSite.toString());
+            }
+            else {
+                LOGGER.debug("Found cloudsite : " + cloudSite.getId());
+                LOGGER.debug("Will not create cloudSite: " + cloudSite.toString());
+            }
         } catch (Exception e) {
-            LOGGER.debug("Could not find cloudsite : " + cloudSite.getId());
-            LOGGER.debug("Creating cloudSite: " + cloudSite.toString());
-        }
-        if (optCloudsite.isPresent() && (cloudSite.getId()) != optCloudsite.get().getId()) {
-            client.postCloudSite(cloudSite);
+            LOGGER.debug("Error looking up or creating cloudsite : " + cloudSite.getId());
+            LOGGER.debug("CloudSite Lookup/Creation Error: " + e);
         }
+
+
     }
 
     /**