summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src
diff options
context:
space:
mode:
authorSmokowski, Steven <steve.smokowski@att.com>2020-04-01 10:41:17 -0400
committerBenjamin, Max (mb388a) <mb388a@att.com>2020-04-17 12:05:16 -0400
commitfbb984e6a8823ca26eae20a65c6d261feac02b7b (patch)
tree00e6f3c385587a351ab644112ffca733f77465e7 /adapters/mso-openstack-adapters/src
parenteceef88af7a5e13a7840059004116e8b6cbf35ac (diff)
openstack inventory capture
Begin heatbridge refactor initial check in of heatbridge Additional commits of heatbridge Update Heat bridge to write more AAI data Update to utlize HeatBrdige to populate AAI Adjust simulator endpoints to work again Remove not needed BB Test case, fix tc Refactor how AAI relationships are being built Issue-ID: SO-2777 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: Iffccc24e18b278188c3fe98bcb1ad9685229d0a2
Diffstat (limited to 'adapters/mso-openstack-adapters/src')
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteAAIInventory.java79
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryService.java52
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryTask.java106
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java114
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTask.java41
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java84
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java5
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java53
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java2
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactory.java4
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImpl.java23
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java71
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventoryTest.java47
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTaskTest.java1
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java8
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImplTest.java7
16 files changed, 438 insertions, 259 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteAAIInventory.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteAAIInventory.java
new file mode 100644
index 0000000000..77a7435295
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteAAIInventory.java
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.inventory.delete;
+
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.cloud.CloudConfig;
+import org.onap.so.cloud.resource.beans.CloudInformation;
+import org.onap.so.db.catalog.beans.CloudIdentity;
+import org.onap.so.db.catalog.beans.CloudSite;
+import org.onap.so.heatbridge.HeatBridgeApi;
+import org.onap.so.heatbridge.HeatBridgeImpl;
+import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+@Component
+public class DeleteAAIInventory {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeleteAAIInventory.class);
+
+ private AAIResourcesClient aaiClient;
+
+ @Autowired
+ protected CloudConfig cloudConfig;
+
+ @Autowired
+ protected Environment env;
+
+ public void heatbridge(CloudInformation cloudInformation, boolean dryrun) {
+ try {
+ if (!dryrun) {
+ logger.debug("Heatbridge delete executing");
+
+ CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId())
+ .orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
+ CloudIdentity cloudIdentity = cloudSite.getIdentityService();
+ HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity,
+ cloudInformation.getOwner(), cloudInformation.getRegionId(), cloudSite.getRegionId(),
+ cloudInformation.getTenantId());
+ heatBridgeClient.authenticate();
+ heatBridgeClient.deleteVfModuleData(cloudInformation.getVnfId(), cloudInformation.getVfModuleId());
+ }
+ } catch (Exception ex) {
+ logger.debug("Heatbrige failed for stackId: " + cloudInformation.getTemplateInstanceId(), ex);
+ }
+ }
+
+ protected AAIResourcesClient getAaiClient() {
+ if (aaiClient == null)
+ return new AAIResourcesClient();
+ else
+ return aaiClient;
+ }
+
+ protected void setAaiClient(AAIResourcesClient aaiResource) {
+ aaiClient = aaiResource;
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryService.java
new file mode 100644
index 0000000000..b104c3310c
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryService.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.inventory.delete;
+
+import javax.annotation.PostConstruct;
+import org.camunda.bpm.client.ExternalTaskClient;
+import org.onap.so.utils.ExternalTaskServiceUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Profile;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+@Component
+@Profile("!test")
+public class DeleteInventoryService {
+
+ @Autowired
+ public Environment env;
+
+ @Autowired
+ private DeleteInventoryTask deleteInventory;
+
+ @Autowired
+ private ExternalTaskServiceUtils externalTaskServiceUtils;
+
+ @PostConstruct
+ public void auditAAIInventory() throws Exception {
+ ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
+ client.subscribe("InventoryDelete")
+ .lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", "60000")))
+ .handler(deleteInventory::executeExternalTask).open();
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryTask.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryTask.java
new file mode 100644
index 0000000000..c5feee2089
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/delete/DeleteInventoryTask.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ *
+ * Copyright (C) 2019 IBM
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.inventory.delete;
+
+import org.camunda.bpm.client.task.ExternalTask;
+import org.camunda.bpm.client.task.ExternalTaskService;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.so.cloud.resource.beans.CloudInformation;
+import org.onap.so.logging.tasks.AuditMDCSetup;
+import org.onap.so.utils.ExternalTaskUtils;
+import org.onap.so.utils.RetrySequenceLevel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+
+@Component
+public class DeleteInventoryTask extends ExternalTaskUtils {
+
+ private static final String UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI = "Unable to write all inventory to A&AI";
+
+ private static final Logger logger = LoggerFactory.getLogger(DeleteInventoryTask.class);
+
+ private static final String AAI_INVENTORY_FAILURE = "AAIInventoryFailure";
+
+ @Autowired
+ private DeleteAAIInventory deleteInventory;
+
+ @Autowired
+ private Environment env;
+
+ @Autowired
+ private AuditMDCSetup mdcSetup;
+
+ public DeleteInventoryTask() {
+ super(RetrySequenceLevel.SHORT);
+ }
+
+ protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
+ mdcSetup.setupMDC(externalTask);
+ boolean inventoryException = false;
+ String externalTaskId = externalTask.getId();
+ CloudInformation cloudInformation = externalTask.getVariable("cloudInformation");
+ boolean success = true;
+ if (cloudInformation != null) {
+ Integer retryCount = externalTask.getRetries();
+ try {
+ deleteInventory.heatbridge(cloudInformation, env.getProperty("heatBridgeDryrun", Boolean.class, true));
+ } catch (Exception e) {
+ logger.error("Error during inventory of stack", e);
+ success = false;
+ }
+ mdcSetup.setElapsedTime();
+ if (success) {
+ externalTaskService.complete(externalTask);
+ mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.COMPLETE.toString());
+ logger.debug("The External Task Id: {} Successful", externalTaskId);
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
+ mdcSetup.clearClientMDCs();
+ } else {
+ if (retryCount == null) {
+ logger.error("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
+ externalTaskId, getRetrySequence().length);
+ externalTaskService.handleFailure(externalTask, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI,
+ UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, getRetrySequence().length, 10000);
+ } else if (retryCount != null && retryCount - 1 == 0) {
+ externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);
+ mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.ERROR.toString());
+ logger.error("The External Task Id: {} Failed, All Retries Exhausted", externalTaskId);
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
+ } else {
+ logger.error("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
+ externalTaskId, retryCount - 1, calculateRetryDelay(retryCount));
+ externalTaskService.handleFailure(externalTask, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI,
+ UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, retryCount - 1, calculateRetryDelay(retryCount));
+ }
+ logger.error("The External Task Id: {} Failed", externalTaskId);
+ }
+ } else {
+ logger.error("The External Task Id: {} Failed, No Cloud Information Provided", externalTaskId);
+ externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);
+ }
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java
index a3cb99e3af..e7c0fe21e0 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java
@@ -20,44 +20,104 @@
package org.onap.so.adapters.tasks.inventory;
-import java.util.Optional;
-import java.util.stream.Stream;
-import org.onap.so.client.aai.AAIObjectType;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.collections.CollectionUtils;
import org.onap.so.client.aai.AAIResourcesClient;
-import org.onap.so.client.aai.entities.uri.AAIUriFactory;
-import org.onap.so.objects.audit.AAIObjectAudit;
-import org.onap.so.objects.audit.AAIObjectAuditList;
+import org.onap.so.cloud.CloudConfig;
+import org.onap.so.cloud.resource.beans.CloudInformation;
+import org.onap.so.db.catalog.beans.CloudIdentity;
+import org.onap.so.db.catalog.beans.CloudSite;
+import org.onap.so.heatbridge.HeatBridgeApi;
+import org.onap.so.heatbridge.HeatBridgeImpl;
+import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
+import org.openstack4j.model.compute.Flavor;
+import org.openstack4j.model.compute.Image;
+import org.openstack4j.model.compute.Server;
+import org.openstack4j.model.heat.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
public class CreateAAIInventory {
+ private static final Logger logger = LoggerFactory.getLogger(CreateAAIInventory.class);
+
private AAIResourcesClient aaiClient;
- public void createInventory(AAIObjectAuditList auditList) throws InventoryException {
- if (didAuditFailVserverLInterfaces(auditList)) {
- throw new InventoryException("Audit failed for VServer or LInterface cannot write Sub-Interfaces");
- }
- auditList.getAuditList().parallelStream()
- .filter(auditObject -> !auditObject.isDoesObjectExist()
- && AAIObjectType.SUB_L_INTERFACE.typeName().equals(auditObject.getAaiObjectType()))
- .forEach(auditObject -> getAaiClient().createIfNotExists(AAIUriFactory.createResourceFromExistingURI(
- AAIObjectType.fromTypeName(auditObject.getAaiObjectType()), auditObject.getResourceURI()),
- Optional.of(auditObject.getAaiObject())));
- }
+ @Autowired
+ protected CloudConfig cloudConfig;
+
+ @Autowired
+ protected Environment env;
+
+ public void heatbridge(CloudInformation cloudInformation) {
+ try {
+ CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId())
+ .orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
+ CloudIdentity cloudIdentity = cloudSite.getIdentityService();
+ String heatStackId = cloudInformation.getTemplateInstanceId().split("/")[1];
+
+ List<String> oobMgtNetNames = new ArrayList<>();
+
+ HeatBridgeApi heatBridgeClient =
+ new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity, cloudInformation.getOwner(),
+ cloudInformation.getRegionId(), cloudSite.getRegionId(), cloudInformation.getTenantId());
+
+ heatBridgeClient.authenticate();
+ List<Resource> stackResources =
+ heatBridgeClient.queryNestedHeatStackResources(cloudInformation.getTemplateInstanceId());
- /**
- * @param auditHeatStackFailed
- * @param auditList
- * @return
- */
- protected boolean didAuditFailVserverLInterfaces(AAIObjectAuditList auditList) {
- Stream<AAIObjectAudit> issue = auditList.getAuditList().stream()
- .filter(auditObject -> auditObject.getAaiObjectType().equals(AAIObjectType.VSERVER.typeName())
- || auditObject.getAaiObjectType().equals(AAIObjectType.L_INTERFACE.typeName()));
+ List<Server> osServers = heatBridgeClient.getAllOpenstackServers(stackResources);
- return issue.filter(auditObject -> !auditObject.isDoesObjectExist()).findFirst().map(v -> true).orElse(false);
+ heatBridgeClient.createPserversAndPinterfacesIfNotPresentInAai(stackResources);
+
+ List<Image> osImages = heatBridgeClient.extractOpenstackImagesFromServers(osServers);
+
+ List<Flavor> osFlavors = heatBridgeClient.extractOpenstackFlavorsFromServers(osServers);
+
+ logger.debug("Successfully queried heat stack{} for resources.", heatStackId);
+ // os images
+ if (osImages != null && !osImages.isEmpty()) {
+ heatBridgeClient.buildAddImagesToAaiAction(osImages);
+ logger.debug("Successfully built AAI actions to add images.");
+ } else {
+ logger.debug("No images to update to AAI.");
+ }
+ // flavors
+ if (osFlavors != null && !osFlavors.isEmpty()) {
+ heatBridgeClient.buildAddFlavorsToAaiAction(osFlavors);
+ logger.debug("Successfully built AAI actions to add flavors.");
+ } else {
+ logger.debug("No flavors to update to AAI.");
+ }
+
+ // compute resources
+ heatBridgeClient.buildAddVserversToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(),
+ osServers);
+ logger.debug("Successfully queried compute resources and built AAI vserver actions.");
+
+ // neutron resources
+ List<String> oobMgtNetIds = new ArrayList<>();
+
+ // if no network-id list is provided, however network-name list is
+ if (!CollectionUtils.isEmpty(oobMgtNetNames)) {
+ oobMgtNetIds = heatBridgeClient.extractNetworkIds(oobMgtNetNames);
+ }
+ heatBridgeClient.buildAddVserverLInterfacesToAaiAction(stackResources, oobMgtNetIds);
+ logger.debug(
+ "Successfully queried neutron resources and built AAI actions to add l-interfaces to vservers.");
+
+ // Update AAI
+ logger.debug("Current Dry Run Value: {}", env.getProperty("heatBridgeDryrun", Boolean.class, true));
+ heatBridgeClient.submitToAai(env.getProperty("heatBridgeDryrun", Boolean.class, true));
+ } catch (Exception ex) {
+ logger.debug("Heatbrige failed for stackId: " + cloudInformation.getTemplateInstanceId(), ex);
+ }
}
protected AAIResourcesClient getAaiClient() {
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTask.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTask.java
index 04dcd9ff61..317dae61b9 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTask.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTask.java
@@ -25,9 +25,8 @@ package org.onap.so.adapters.tasks.inventory;
import org.camunda.bpm.client.task.ExternalTask;
import org.camunda.bpm.client.task.ExternalTaskService;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
-import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
+import org.onap.so.cloud.resource.beans.CloudInformation;
import org.onap.so.logging.tasks.AuditMDCSetup;
-import org.onap.so.objects.audit.AAIObjectAuditList;
import org.onap.so.utils.ExternalTaskUtils;
import org.onap.so.utils.RetrySequenceLevel;
import org.slf4j.Logger;
@@ -35,6 +34,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+
@Component
public class CreateInventoryTask extends ExternalTaskUtils {
@@ -57,29 +57,16 @@ public class CreateInventoryTask extends ExternalTaskUtils {
public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
mdcSetup.setupMDC(externalTask);
- boolean success = true;
boolean inventoryException = false;
- String auditInventoryString = externalTask.getVariable("auditInventoryResult");
- AAIObjectAuditList auditInventory = null;
String externalTaskId = externalTask.getId();
- try {
- GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
- auditInventory = objectMapper.getMapper().readValue(auditInventoryString, AAIObjectAuditList.class);
- } catch (Exception e) {
- mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.ERROR.toString());
- logger.error("Error Parsing Audit Results", e);
- }
- mdcSetup.setElapsedTime();
- if (auditInventory != null) {
+ CloudInformation cloudInformation = externalTask.getVariable("cloudInformation");
+ boolean success = true;
+ if (cloudInformation != null) {
Integer retryCount = externalTask.getRetries();
try {
- logger.info("Executing External Task Create Inventory, Retry Number: {} \n {}", auditInventory,
+ logger.info("Executing External Task Create Inventory, Retry Number: {} \n {}", cloudInformation,
retryCount);
- createInventory.createInventory(auditInventory);
- } catch (InventoryException e) {
- logger.error("Error during inventory of stack", e);
- success = false;
- inventoryException = true;
+ createInventory.heatbridge(cloudInformation);
} catch (Exception e) {
logger.error("Error during inventory of stack", e);
success = false;
@@ -91,31 +78,27 @@ public class CreateInventoryTask extends ExternalTaskUtils {
logger.debug("The External Task Id: {} Successful", externalTaskId);
logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
mdcSetup.clearClientMDCs();
- } else if (inventoryException) {
- mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.ERROR.toString());
- logger.debug("The External Task Id: {} Failed, Retry not needed", externalTaskId);
- externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);
} else {
if (retryCount == null) {
- logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
+ logger.error("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
externalTaskId, getRetrySequence().length);
externalTaskService.handleFailure(externalTask, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI,
UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, getRetrySequence().length, 10000);
} else if (retryCount != null && retryCount - 1 == 0) {
externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);
mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.ERROR.toString());
- logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTaskId);
+ logger.error("The External Task Id: {} Failed, All Retries Exhausted", externalTaskId);
logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
} else {
- logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
+ logger.error("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
externalTaskId, retryCount - 1, calculateRetryDelay(retryCount));
externalTaskService.handleFailure(externalTask, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI,
UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, retryCount - 1, calculateRetryDelay(retryCount));
}
- logger.debug("The External Task Id: {} Failed", externalTaskId);
+ logger.error("The External Task Id: {} Failed", externalTaskId);
}
} else {
- logger.debug("The External Task Id: {} Failed, No Audit Results Written", externalTaskId);
+ logger.error("The External Task Id: {} Failed, No Cloud Information Provided", externalTaskId);
externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);
}
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java
index a58c0c10c5..26bce5f362 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java
@@ -31,13 +31,10 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.xml.ws.Holder;
-import org.apache.commons.collections.CollectionUtils;
import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.adapters.vnf.exceptions.VnfException;
import org.onap.so.adapters.vnf.exceptions.VnfNotFound;
-import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.cloud.CloudConfig;
-import org.onap.so.db.catalog.beans.CloudIdentity;
import org.onap.so.db.catalog.beans.CloudSite;
import org.onap.so.db.catalog.beans.HeatEnvironment;
import org.onap.so.db.catalog.beans.HeatFiles;
@@ -50,25 +47,17 @@ import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
import org.onap.so.db.catalog.utils.MavenLikeVersioning;
import org.onap.so.entity.MsoRequest;
-import org.onap.so.heatbridge.HeatBridgeApi;
-import org.onap.so.heatbridge.HeatBridgeException;
-import org.onap.so.heatbridge.HeatBridgeImpl;
import org.onap.so.logger.LoggingAnchor;
import org.onap.so.logger.MessageEnum;
import org.onap.so.openstack.beans.HeatStatus;
import org.onap.so.openstack.beans.StackInfo;
import org.onap.so.openstack.beans.VnfRollback;
-import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
import org.onap.so.openstack.exceptions.MsoException;
import org.onap.so.openstack.exceptions.MsoExceptionCategory;
import org.onap.so.openstack.exceptions.MsoHeatNotFoundException;
import org.onap.so.openstack.utils.MsoHeatEnvironmentEntry;
import org.onap.so.openstack.utils.MsoHeatUtils;
import org.onap.so.openstack.utils.MsoHeatUtilsWithUpdate;
-import org.openstack4j.model.compute.Flavor;
-import org.openstack4j.model.compute.Image;
-import org.openstack4j.model.compute.Server;
-import org.openstack4j.model.heat.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -353,69 +342,6 @@ public class MsoVnfAdapterImpl {
return new HashMap<>(stringInputs);
}
- private void heatbridge(StackInfo heatStack, String cloudOwner, String cloudSiteId, String tenantId,
- String genericVnfName, String vfModuleId) {
- try {
- CloudSite cloudSite =
- cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
- CloudIdentity cloudIdentity = cloudSite.getIdentityService();
- String heatStackId = heatStack.getCanonicalName().split("/")[1];
-
- List<String> oobMgtNetNames = new ArrayList<>();
-
- HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity, cloudOwner,
- cloudSiteId, cloudSite.getRegionId(), tenantId);
-
- heatBridgeClient.authenticate();
-
- List<Resource> stackResources = heatBridgeClient.queryNestedHeatStackResources(heatStackId);
-
- List<Server> osServers = heatBridgeClient.getAllOpenstackServers(stackResources);
-
- heatBridgeClient.createPserversAndPinterfacesIfNotPresentInAai(stackResources);
-
- List<Image> osImages = heatBridgeClient.extractOpenstackImagesFromServers(osServers);
-
- List<Flavor> osFlavors = heatBridgeClient.extractOpenstackFlavorsFromServers(osServers);
-
- logger.debug("Successfully queried heat stack{} for resources.", heatStackId);
- // os images
- if (osImages != null && !osImages.isEmpty()) {
- heatBridgeClient.buildAddImagesToAaiAction(osImages);
- logger.debug("Successfully built AAI actions to add images.");
- } else {
- logger.debug("No images to update to AAI.");
- }
- // flavors
- if (osFlavors != null && !osFlavors.isEmpty()) {
- heatBridgeClient.buildAddFlavorsToAaiAction(osFlavors);
- logger.debug("Successfully built AAI actions to add flavors.");
- } else {
- logger.debug("No flavors to update to AAI.");
- }
-
- // compute resources
- heatBridgeClient.buildAddVserversToAaiAction(genericVnfName, vfModuleId, osServers);
- logger.debug("Successfully queried compute resources and built AAI vserver actions.");
-
- // neutron resources
- List<String> oobMgtNetIds = new ArrayList<>();
-
- // if no network-id list is provided, however network-name list is
- if (!CollectionUtils.isEmpty(oobMgtNetNames)) {
- oobMgtNetIds = heatBridgeClient.extractNetworkIds(oobMgtNetNames);
- }
- heatBridgeClient.buildAddVserverLInterfacesToAaiAction(stackResources, oobMgtNetIds);
- logger.debug(
- "Successfully queried neutron resources and built AAI actions to add l-interfaces to vservers.");
-
- // Update AAI
- heatBridgeClient.submitToAai();
- } catch (Exception ex) {
- logger.debug("Heatbrige failed for stackId: " + heatStack.getCanonicalName(), ex);
- }
- }
-
private String convertNode(final JsonNode node) {
try {
final Object obj = JSON_MAPPER.treeToValue(node, Object.class);
@@ -1036,10 +962,6 @@ public class MsoVnfAdapterImpl {
outputs.value = copyStringOutputs(heatStack.getOutputs());
rollback.value = vfRollback;
logger.debug("VF Module {} successfully created", vfModuleName);
- if (enableBridge != null && enableBridge) {
- // call heatbridge
- heatbridge(heatStack, cloudOwner, cloudSiteId, tenantId, genericVnfName, vfModuleId);
- }
} catch (Exception e) {
logger.debug("unhandled exception in create VF", e);
throw new VnfException("Exception during create VF " + e.getMessage());
@@ -1111,12 +1033,6 @@ public class MsoVnfAdapterImpl {
logger.error(error);
throw new VnfException(me);
}
- // call heatbridge delete
- try {
- new HeatBridgeImpl().deleteVfModuleData(vnfId, vfModuleId);
- } catch (HeatBridgeException e) {
- logger.error("Heatbridge failed to delete AAI data for vf-module: " + vfModuleId, e);
- }
}
public void updateVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vnfType,
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java
index 7eff09b692..d0ca87df95 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java
@@ -146,10 +146,11 @@ public interface HeatBridgeApi {
/**
* Execute AAI restful API to update the Openstack resources
- *
+ *
+ * @param dryrun - this will simply log the aai transaction to log if enabled and not write any data
* @throws HeatBridgeException when failing to add openstack resource PoJos to AAI
*/
- void submitToAai() throws HeatBridgeException;
+ void submitToAai(boolean dryrun) throws HeatBridgeException;
/**
* Delete heatbridge data for a given vf-module
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java
index 390ed38764..6b980cb590 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java
@@ -55,10 +55,11 @@ import org.onap.aai.domain.yang.SriovPf;
import org.onap.aai.domain.yang.SriovPfs;
import org.onap.aai.domain.yang.SriovVf;
import org.onap.aai.domain.yang.SriovVfs;
+import org.onap.aai.domain.yang.VfModule;
import org.onap.aai.domain.yang.Vlan;
import org.onap.aai.domain.yang.Vlans;
import org.onap.aai.domain.yang.Vserver;
-import org.onap.aai.domain.yang.VfModule;
+import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.AAISingleTransactionClient;
@@ -69,13 +70,13 @@ import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.client.graphinventory.entities.uri.Depth;
import org.onap.so.client.graphinventory.exceptions.BulkProcessFailed;
import org.onap.so.db.catalog.beans.CloudIdentity;
+import org.onap.so.db.catalog.beans.ServerType;
import org.onap.so.heatbridge.constants.HeatBridgeConstants;
import org.onap.so.heatbridge.factory.MsoCloudClientFactoryImpl;
import org.onap.so.heatbridge.helpers.AaiHelper;
import org.onap.so.heatbridge.openstack.api.OpenstackClient;
import org.onap.so.heatbridge.openstack.factory.OpenstackClientFactoryImpl;
import org.onap.so.heatbridge.utils.HeatBridgeUtils;
-import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.logger.LoggingAnchor;
import org.onap.so.logger.MessageEnum;
import org.openstack4j.model.compute.Server;
@@ -133,10 +134,19 @@ public class HeatBridgeImpl implements HeatBridgeApi {
@Override
public OpenstackClient authenticate() throws HeatBridgeException {
+ String keystoneVersion = "";
+ if (ServerType.KEYSTONE.equals(cloudIdentity.getIdentityServerType()))
+ keystoneVersion = "v2.0";
+ else if (ServerType.KEYSTONE_V3.equals(cloudIdentity.getIdentityServerType())) {
+ keystoneVersion = "v3";
+ } else {
+ keystoneVersion = "UNKNOWN";
+ }
+ logger.trace("Keystone Version: {} ", keystoneVersion);
this.osClient = new MsoCloudClientFactoryImpl(new OpenstackClientFactoryImpl()).getOpenstackClient(
cloudIdentity.getIdentityUrl(), cloudIdentity.getMsoId(), cloudIdentity.getMsoPass(), regionId,
- tenantId);
- logger.debug("Successfully authenticated with keystone for tenant: " + tenantId + " and region: " + regionId);
+ tenantId, keystoneVersion);
+ logger.trace("Successfully authenticated with keystone for tenant: {} and region: {}", tenantId, regionId);
return osClient;
}
@@ -170,7 +180,6 @@ public class HeatBridgeImpl implements HeatBridgeApi {
@Override
public List<Server> getAllOpenstackServers(final List<Resource> stackResources) {
Objects.requireNonNull(osClient, ERR_MSG_NULL_OS_CLIENT);
-
// Filter Openstack Compute resources
List<String> serverIds =
extractStackResourceIdsByResourceType(stackResources, HeatBridgeConstants.OS_SERVER_RESOURCE_TYPE);
@@ -220,12 +229,7 @@ public class HeatBridgeImpl implements HeatBridgeApi {
try {
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.FLAVOR, cloudOwner, cloudRegionId,
aaiFlavor.getFlavorId());
- if (!resourcesClient.exists(uri)) {
- transaction.create(uri, aaiFlavor);
- logger.debug("Queuing AAI command to add flavor: " + aaiFlavor.getFlavorId());
- } else {
- logger.debug("Nothing to add since flavor: " + aaiFlavor.getFlavorId() + "already exists in AAI.");
- }
+ transaction.createIfNotExists(uri, Optional.of(aaiFlavor));
} catch (WebApplicationException e) {
throw new HeatBridgeException(
"Failed to update flavor to AAI: " + aaiFlavor.getFlavorId() + ". Error" + " cause: " + e, e);
@@ -259,12 +263,15 @@ public class HeatBridgeImpl implements HeatBridgeApi {
lIf.setInterfaceId(port.getId());
lIf.setInterfaceName(port.getName());
lIf.setMacaddr(port.getMacAddress());
+ lIf.setNetworkName((String) port.getProfile().get("physical_network"));
+ lIf.setIsPortMirrored(false);
+ lIf.setIsIpUnnumbered(false);
+ lIf.setInMaint(false);
if (oobMgtNetIds != null && oobMgtNetIds.contains(port.getNetworkId())) {
lIf.setInterfaceRole(OOB_MGT_NETWORK_IDENTIFIER);
} else {
lIf.setInterfaceRole(port.getvNicType());
}
-
updateLInterfaceIps(port, lIf);
updateLInterfaceVlan(port, lIf);
@@ -323,9 +330,14 @@ public class HeatBridgeImpl implements HeatBridgeApi {
private void updateLInterfaceVlan(final Port port, final LInterface lIf) {
Vlan vlan = new Vlan();
Network network = osClient.getNetworkById(port.getNetworkId());
- lIf.setNetworkName(network.getName());
if (network.getNetworkType().equals(NetworkType.VLAN)) {
- vlan.setVlanInterface(network.getProviderSegID());
+ vlan.setVlanInterface(network.getName() + network.getProviderSegID());
+
+ vlan.setVlanIdOuter(Long.parseLong(network.getProviderSegID()));
+ vlan.setVlanIdInner(0L);
+ vlan.setInMaint(false);
+ vlan.setIsIpUnnumbered(false);
+ vlan.setIsPrivate(false);
Vlans vlans = new Vlans();
List<Vlan> vlanList = vlans.getVlan();
vlanList.add(vlan);
@@ -343,6 +355,8 @@ public class HeatBridgeImpl implements HeatBridgeApi {
if (port.getVifDetails() != null) {
sriovVf.setVfVlanFilter((String) port.getVifDetails().get(HeatBridgeConstants.OS_VLAN_NETWORK_KEY));
}
+ sriovVf.setVfVlanAntiSpoofCheck(false);
+ sriovVf.setVfMacAntiSpoofCheck(false);
sriovVfList.add(sriovVf);
lIf.setSriovVfs(sriovVfs);
@@ -424,9 +438,9 @@ public class HeatBridgeImpl implements HeatBridgeApi {
}
@Override
- public void submitToAai() throws HeatBridgeException {
+ public void submitToAai(boolean dryrun) throws HeatBridgeException {
try {
- transaction.execute();
+ transaction.execute(dryrun);
} catch (BulkProcessFailed e) {
String msg = "Failed to commit transaction";
logger.debug(msg + " with error: " + e);
@@ -442,15 +456,20 @@ public class HeatBridgeImpl implements HeatBridgeApi {
try {
Optional<VfModule> vfModule = resourcesClient.get(VfModule.class,
AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId).depth(Depth.ONE));
+ logger.debug("vfModule is present: {}", vfModule.isPresent());
if (vfModule.isPresent()) {
- AAIResultWrapper resultWrapper = new AAIResultWrapper(vfModule);
+ AAIResultWrapper resultWrapper = new AAIResultWrapper(vfModule.get());
Optional<Relationships> relationships = resultWrapper.getRelationships();
+ logger.debug("relationships is present: {}", relationships.isPresent());
if (relationships.isPresent()) {
List<AAIResourceUri> vserverUris = relationships.get().getRelatedUris(AAIObjectType.VSERVER);
+ logger.debug("vserverList isEmpty: {}", vserverUris.isEmpty());
createTransactionToDeleteSriovPfFromPserver(vserverUris);
+
if (!vserverUris.isEmpty()) {
for (AAIResourceUri vserverUri : vserverUris) {
+ logger.debug("Deleting Vservers: {}", vserverUri.toString());
resourcesClient.delete(vserverUri);
}
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java
index 0e87e1fb31..fdf7ce38f1 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java
@@ -72,6 +72,8 @@ public class HeatBridgeConstants {
public static final String AAI_SRIOV_PF = "sriov-pf";
public static final String AAI_P_INTERFACE_NAME = "p-interface.interface-name";
public static final String AAI_SRIOV_PF_PCI_ID = "sriov-pf.pf-pci-id";
+ public static final String AAI_VNFC = "vnfc";
+ public static final String AAI_VNFC_ID = "vnfc.vnfc-name";
/**
* Keys for internal usage
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactory.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactory.java
index e1f363ca05..a9a63b312d 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactory.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactory.java
@@ -54,6 +54,6 @@ public interface MsoCloudClientFactory {
*/
- OpenstackClient getOpenstackClient(String url, String msoId, String msoPass, String regionId, String tenantId)
- throws HeatBridgeException;
+ OpenstackClient getOpenstackClient(String url, String msoId, String msoPass, String regionId, String tenantId,
+ String keystoneVersion) throws HeatBridgeException;
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImpl.java
index 04245899aa..88a7d3dbbc 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImpl.java
@@ -32,8 +32,6 @@
*/
package org.onap.so.heatbridge.factory;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.util.Objects;
import javax.annotation.Nonnull;
import org.onap.so.heatbridge.HeatBridgeException;
@@ -44,6 +42,9 @@ import org.onap.so.heatbridge.openstack.api.OpenstackClient;
import org.onap.so.heatbridge.openstack.api.OpenstackClientException;
import org.onap.so.heatbridge.openstack.factory.OpenstackClientFactory;
import org.onap.so.utils.CryptoUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* This class implements {@link MsoCloudClientFactory} It loads the cloud configuration from SO and uses it to
@@ -52,6 +53,8 @@ import org.onap.so.utils.CryptoUtils;
*/
public class MsoCloudClientFactoryImpl implements MsoCloudClientFactory {
+ private static final Logger logger = LoggerFactory.getLogger(MsoCloudClientFactoryImpl.class);
+
private OpenstackClientFactory openstackClientFactory;
public MsoCloudClientFactoryImpl(@Nonnull OpenstackClientFactory openstackClientFactory) {
@@ -61,12 +64,14 @@ public class MsoCloudClientFactoryImpl implements MsoCloudClientFactory {
@Override
public OpenstackClient getOpenstackClient(@Nonnull String url, @Nonnull String msoId, @Nonnull String msoPass,
- @Nonnull String regionId, @Nonnull String tenantId) throws HeatBridgeException {
+ @Nonnull String regionId, @Nonnull String tenantId, @Nonnull String keystoneVersion)
+ throws HeatBridgeException {
Objects.requireNonNull(url, "Null openstack url!");
Objects.requireNonNull(msoId, "Null openstack user id!");
Objects.requireNonNull(msoPass, "Null openstack password!");
Objects.requireNonNull(regionId, "Null regionId ID!");
Objects.requireNonNull(tenantId, "Null tenant ID!");
+ Objects.requireNonNull(tenantId, "Null keystone version");
try {
final OpenstackAccess osAccess = new OpenstackAccessBuilder().setBaseUrl(url) // keystone URL
.setUser(msoId) // keystone username
@@ -77,17 +82,15 @@ public class MsoCloudClientFactoryImpl implements MsoCloudClientFactory {
.build();
// Identify the Keystone version
- String version = new URL(url).getPath().replace("/", "");
- if (version.equals(HeatBridgeConstants.OS_KEYSTONE_V2_KEY)) {
+ if (keystoneVersion.equals(HeatBridgeConstants.OS_KEYSTONE_V2_KEY)) {
return openstackClientFactory.createOpenstackV2Client(osAccess);
- } else if (version.equals(HeatBridgeConstants.OS_KEYSTONE_V3_KEY)) {
+ } else if (keystoneVersion.equals(HeatBridgeConstants.OS_KEYSTONE_V3_KEY)) {
return openstackClientFactory.createOpenstackV3Client(osAccess);
}
- throw new OpenstackClientException("Unsupported keystone version!");
- } catch (MalformedURLException e) {
- throw new HeatBridgeException("Malformed Keystone Endpoint in SO configuration.", e);
+ throw new OpenstackClientException("Unsupported keystone version! " + keystoneVersion);
} catch (OpenstackClientException osClientEx) {
- throw new HeatBridgeException("Client error when authenticating with the Openstack V3.", osClientEx);
+ logger.error("Error creating OS Client", osClientEx);
+ throw new HeatBridgeException("Client error when authenticating with the Openstack", osClientEx);
}
}
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java
index 727cdccff5..5271528e91 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java
@@ -32,8 +32,6 @@
*/
package org.onap.so.heatbridge.helpers;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -50,9 +48,13 @@ import org.onap.aai.domain.yang.RelationshipData;
import org.onap.aai.domain.yang.RelationshipList;
import org.onap.aai.domain.yang.SriovVf;
import org.onap.aai.domain.yang.Vserver;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.heatbridge.constants.HeatBridgeConstants;
import org.openstack4j.model.compute.Server;
import org.openstack4j.model.network.Port;
+import com.google.common.base.Preconditions;
/**
* This class provides wrapper methods to manage creation of AAI objects and extracting objects from AAI and
@@ -75,31 +77,36 @@ public class AaiHelper {
List<Relationship> relationships = relationshipList.getRelationship();
// vserver to pserver relationship
- Relationship pserverRelationship =
- buildRelationship(HeatBridgeConstants.AAI_PSERVER, ImmutableMap.<String, String>builder()
- .put(HeatBridgeConstants.AAI_PSERVER_HOSTNAME, server.getHypervisorHostname()).build());
+ Relationship pserverRelationship = buildRelationship(
+ AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, server.getHypervisorHostname()));
relationships.add(pserverRelationship);
+ // vserver to generic-vnf relationship
+ Relationship genericVnfRelationship =
+ buildRelationship(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericVnfId));
+ relationships.add(genericVnfRelationship);
+
+ // vserver to vnfc relationship
+ Relationship vnfcRelationship =
+ buildRelationship(AAIUriFactory.createResourceUri(AAIObjectType.VNFC, server.getName()));
+ relationships.add(vnfcRelationship);
+
+
// vserver to vf-module relationship
- Relationship vfModuleRelationship = buildRelationship(HeatBridgeConstants.AAI_VF_MODULE,
- ImmutableMap.<String, String>builder().put(HeatBridgeConstants.AAI_GENERIC_VNF_ID, genericVnfId)
- .put(HeatBridgeConstants.AAI_VF_MODULE_ID, vfModuleId).build());
+ Relationship vfModuleRelationship =
+ buildRelationship(AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, genericVnfId, vfModuleId));
relationships.add(vfModuleRelationship);
// vserver to image relationship
if (server.getImage() != null) {
- Relationship imageRel = buildRelationship(HeatBridgeConstants.AAI_IMAGE,
- ImmutableMap.<String, String>builder().put(HeatBridgeConstants.AAI_CLOUD_OWNER, cloudOwner)
- .put(HeatBridgeConstants.AAI_CLOUD_REGION_ID, cloudRegionId)
- .put(HeatBridgeConstants.AAI_IMAGE_ID, server.getImage().getId()).build());
+ Relationship imageRel = buildRelationship(AAIUriFactory.createResourceUri(AAIObjectType.IMAGE, cloudOwner,
+ cloudRegionId, server.getImage().getId()));
relationships.add(imageRel);
}
// vserver to flavor relationship
- Relationship flavorRel = buildRelationship(HeatBridgeConstants.AAI_FLAVOR,
- ImmutableMap.<String, String>builder().put(HeatBridgeConstants.AAI_CLOUD_OWNER, cloudOwner)
- .put(HeatBridgeConstants.AAI_CLOUD_REGION_ID, cloudRegionId)
- .put(HeatBridgeConstants.AAI_FLAVOR_ID, server.getFlavor().getId()).build());
+ Relationship flavorRel = buildRelationship(AAIUriFactory.createResourceUri(AAIObjectType.FLAVOR, cloudOwner,
+ cloudRegionId, server.getFlavor().getId()));
relationships.add(flavorRel);
return relationshipList;
}
@@ -110,10 +117,8 @@ public class AaiHelper {
List<Relationship> relationships = relationshipList.getRelationship();
// sriov-vf to sriov-pf relationship
- Relationship sriovPfRelationship = buildRelationship(HeatBridgeConstants.AAI_SRIOV_PF,
- ImmutableMap.<String, String>builder().put(HeatBridgeConstants.AAI_PSERVER_HOSTNAME, pserverName)
- .put(HeatBridgeConstants.AAI_P_INTERFACE_NAME, pIfName)
- .put(HeatBridgeConstants.AAI_SRIOV_PF_PCI_ID, pfPciId).build());
+ Relationship sriovPfRelationship = buildRelationship(
+ AAIUriFactory.createResourceUri(AAIObjectType.SRIOV_PF, pserverName, pIfName, pfPciId));
relationships.add(sriovPfRelationship);
return relationshipList;
@@ -191,8 +196,13 @@ public class AaiHelper {
aaiImage.setImageName(image.getName());
aaiImage.setImageOsDistro(HeatBridgeConstants.OS_UNKNOWN_KEY);
aaiImage.setImageOsVersion(HeatBridgeConstants.OS_UNKNOWN_KEY);
- image.getLinks().stream().filter(link -> link.getRel().equals(HeatBridgeConstants.OS_RESOURCES_SELF_LINK_KEY))
- .findFirst().ifPresent(link -> aaiImage.setImageSelflink(link.getHref()));
+
+ // application name/vendor/version needs to be set
+ if (image.getLinks() != null) {
+ image.getLinks().stream()
+ .filter(link -> link.getRel().equals(HeatBridgeConstants.OS_RESOURCES_SELF_LINK_KEY)).findFirst()
+ .ifPresent(link -> aaiImage.setImageSelflink(link.getHref()));
+ }
return aaiImage;
}
@@ -206,6 +216,13 @@ public class AaiHelper {
Flavor aaiFlavor = new Flavor();
aaiFlavor.setFlavorId(flavor.getId());
aaiFlavor.setFlavorName(flavor.getName());
+ aaiFlavor.setFlavorVcpus(flavor.getVcpus());
+ aaiFlavor.setFlavorRam(flavor.getRam());
+ aaiFlavor.setFlavorDisk(flavor.getDisk());
+ aaiFlavor.setFlavorEphemeral(flavor.getEphemeral());
+ aaiFlavor.setFlavorDisabled(flavor.isDisabled());
+ aaiFlavor.setFlavorIsPublic(flavor.isPublic());
+ aaiFlavor.setFlavorSwap(Integer.toString(flavor.getSwap()));
flavor.getLinks().stream().filter(link -> link.getRel().equals(HeatBridgeConstants.OS_RESOURCES_SELF_LINK_KEY))
.findFirst().ifPresent(link -> aaiFlavor.setFlavorSelflink(link.getHref()));
return aaiFlavor;
@@ -310,15 +327,9 @@ public class AaiHelper {
* @param relationshipKeyValues Key value pairs of relationship data
* @return AAI Relationship object
*/
- private Relationship buildRelationship(final String relatedTo, final Map<String, String> relationshipKeyValues) {
+ private Relationship buildRelationship(final AAIResourceUri relatedLink) {
Relationship relationship = new Relationship();
- relationship.setRelatedTo(relatedTo);
- relationshipKeyValues.keySet().forEach(k -> {
- RelationshipData relationshipData = new RelationshipData();
- relationshipData.setRelationshipKey(k);
- relationshipData.setRelationshipValue(relationshipKeyValues.get(k));
- relationship.getRelationshipData().add(relationshipData);
- });
+ relationship.setRelatedLink(relatedLink.build().toString());
return relationship;
}
}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventoryTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventoryTest.java
index e822f65072..583bfbadb2 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventoryTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventoryTest.java
@@ -20,30 +20,17 @@
package org.onap.so.adapters.tasks.inventory;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.times;
import java.io.File;
import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
import org.camunda.bpm.client.task.ExternalTask;
-import org.hamcrest.Matchers;
import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.so.adapters.tasks.inventory.CreateAAIInventory;
import org.onap.so.audit.beans.AuditInventory;
-import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIResourcesClient;
-import org.onap.so.client.aai.entities.uri.AAIResourceUri;
-import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.objects.audit.AAIObjectAuditList;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
@@ -86,38 +73,4 @@ public class CreateAAIInventoryTest extends CreateAAIInventory {
doReturn(auditInventory).when(mockExternalTask).getVariable("auditInventory");
}
- @Test
- public void determineAuditResult_Test() throws Exception {
- boolean actual = createAAIInventory.didAuditFailVserverLInterfaces(auditListSuccess);
- assertEquals(false, actual);
- }
-
- @Test
- public void determineAuditResult_Failure_Test() throws Exception {
- boolean actual = createAAIInventory.didAuditFailVserverLInterfaces(auditListFailure);
- assertEquals(true, actual);
- }
-
- @Test
- public void missing_Sub_Interfaces_Test() throws Exception {
- AAIResourceUri aaiURI2 = AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, "cloudOwner",
- "regionOne", "0422ffb57ba042c0800a29dc85ca70f8", "92272b67-d23f-42ca-87fa-7b06a9ec81f3",
- "tsbc0005v_tsbc0005vm002_svc1_port_0", "tsbc0005v_tsbc0005vm002_subint_untrusted_svc1_81");
- AAIResourceUri aaiURI1 = AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, "cloudOwner",
- "regionOne", "0422ffb57ba042c0800a29dc85ca70f8", "92272b67-d23f-42ca-87fa-7b06a9ec81f3",
- "tsbc0005v_tsbc0005vm002_svc2_port_0", "tsbc0005v_tsbc0005vm002_subint_untrusted_svc2_103");
- ArgumentCaptor<Optional> captor = ArgumentCaptor.forClass(Optional.class);
- ArgumentCaptor<AAIResourceUri> uriCaptor = ArgumentCaptor.forClass(AAIResourceUri.class);
-
- createAAIInventory.setAaiClient(mockClient);
- createAAIInventory.createInventory(missingSubInterfaces);
- Mockito.verify(mockClient, times(2)).createIfNotExists(uriCaptor.capture(), captor.capture());
-
- List<AAIResourceUri> capturedURI = uriCaptor.getAllValues();
- assertTrue(capturedURI.stream().anyMatch(item -> aaiURI1.build().toString().equals(item.build().toString())));
- assertTrue(capturedURI.stream().anyMatch(item -> aaiURI2.build().toString().equals(item.build().toString())));
-
-
-
- }
}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTaskTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTaskTest.java
index fc2baefcd5..653099a0ea 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTaskTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTaskTest.java
@@ -76,7 +76,6 @@ public class CreateInventoryTaskTest {
object.getAuditList().add(e);
GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
doReturn(objectMapper.getMapper().writeValueAsString(e)).when(externalTask).getVariable("auditInventoryResult");
- Mockito.doThrow(InventoryException.class).when(createAAIInventory).createInventory(Mockito.any());
inventoryTask.executeExternalTask(externalTask, externalTaskService);
Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure");
}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java
index e2f5531280..6ecdcf9f28 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java
@@ -308,13 +308,7 @@ public class HeatBridgeImplTest {
heatbridge.buildAddFlavorsToAaiAction(flavors);
// Assert #1
- verify(transaction, times(2)).create(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.Flavor.class));
-
- // Act #2
- heatbridge.buildAddFlavorsToAaiAction(flavors);
-
- // Assert #2
- verify(transaction, times(4)).create(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.Flavor.class));
+ verify(transaction, times(2)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
}
@Ignore
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImplTest.java
index 4eeb1c03a3..86400c2190 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImplTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImplTest.java
@@ -52,19 +52,20 @@ public class MsoCloudClientFactoryImplTest {
@Test
public void getOpenstackClientWithVersion2() throws Exception {
- testedObject.getOpenstackClient(URL_V2, MSO_ID, ENCRYPTED_PASSWORD, REGION_ID, TENANT_ID);
+ testedObject.getOpenstackClient(URL_V2, MSO_ID, ENCRYPTED_PASSWORD, REGION_ID, TENANT_ID, "v2.0");
verify(openstackClientFactoryMock).createOpenstackV2Client(any(OpenstackAccess.class));
}
@Test
public void getOpenstackClientWithVersion3() throws Exception {
- testedObject.getOpenstackClient(URL_V3, MSO_ID, ENCRYPTED_PASSWORD, REGION_ID, TENANT_ID);
+ testedObject.getOpenstackClient(URL_V3, MSO_ID, ENCRYPTED_PASSWORD, REGION_ID, TENANT_ID, "v3");
verify(openstackClientFactoryMock).createOpenstackV3Client(any(OpenstackAccess.class));
}
@Test(expected = HeatBridgeException.class)
public void getOpenstackClient_unsupportedVersion() throws Exception {
- testedObject.getOpenstackClient(URL_WITH_UNSUPPORTED_VERSION, MSO_ID, ENCRYPTED_PASSWORD, REGION_ID, TENANT_ID);
+ testedObject.getOpenstackClient(URL_WITH_UNSUPPORTED_VERSION, MSO_ID, ENCRYPTED_PASSWORD, REGION_ID, TENANT_ID,
+ "UNKNOWN");
}
}