summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src/main
diff options
context:
space:
mode:
authorBOSLET, CORY <cory.boslet@att.com>2021-03-08 15:08:06 -0500
committerAT&T Open Source <g22940@att.com>2021-03-08 15:08:06 -0500
commit9f6c9c74c5f10794cdbe6de2ed6d0539ce7d0d84 (patch)
tree7f00ff20e931ef5d7659fa4b50664a0884b20ffd /adapters/mso-openstack-adapters/src/main
parent3c0b8888188d9d1a263472fa7450c060d5dd5767 (diff)
Added volume creation to heatbridge
Added volume creation to heatbridge Issue-ID: SO-3577 Signed-off-by: AT&T Open Source <g22940@att.com> Change-Id: I0f0844187efe880cccf4b663c8c4fadc346680c3
Diffstat (limited to 'adapters/mso-openstack-adapters/src/main')
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java2
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java9
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java42
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClient.java8
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientImpl.java7
5 files changed, 68 insertions, 0 deletions
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 0dd7635506..15cf4af62a 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
@@ -121,6 +121,8 @@ public class CreateAAIInventory {
cloudInformation.getOwner());
logger.debug("Successfully queried neutron resources and built AAI actions to add l-interfaces to vservers.");
+ heatBridgeClient.buildAddVolumes(stackResources);
+
// Update AAI
logger.debug("Current Dry Run Value: {}", env.getProperty("heatBridgeDryrun", Boolean.class, false));
heatBridgeClient.submitToAai(env.getProperty("heatBridgeDryrun", Boolean.class, false));
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 1b2fdfedfa..1de7273909 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
@@ -160,6 +160,13 @@ public interface HeatBridgeApi {
String cloudOwner) throws HeatBridgeException;
/**
+ * Query and build AAI actions for Openstack volumes
+ *
+ * @throws HeatBridgeException when failing to remove heatbridge data from AAI for a given vf-module
+ */
+ void buildAddVolumes(List<Resource> stackResources) throws HeatBridgeException;
+
+ /**
* Query and build AAI actions for Openstack Compute resources to AAI's pserver and pinterface objects
*
* @param stackResources Openstack StackResources list
@@ -180,4 +187,6 @@ public interface HeatBridgeApi {
* @throws HeatBridgeException when failing to remove heatbridge data from AAI for a given vf-module
*/
void deleteVfModuleData(String vnfId, String vfModuleId) throws HeatBridgeException;
+
+
}
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 04c6ea4ff7..1bf4aff8f6 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
@@ -64,6 +64,7 @@ import org.onap.aai.domain.yang.SriovPf;
import org.onap.aai.domain.yang.SriovVf;
import org.onap.aai.domain.yang.Subnets;
import org.onap.aai.domain.yang.Vlan;
+import org.onap.aai.domain.yang.Volume;
import org.onap.aai.domain.yang.Vserver;
import org.onap.aaiclient.client.aai.AAIDSLQueryClient;
import org.onap.aaiclient.client.aai.AAIResourcesClient;
@@ -103,6 +104,7 @@ import org.openstack4j.model.network.Network;
import org.openstack4j.model.network.NetworkType;
import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.Subnet;
+import org.openstack4j.model.storage.block.VolumeAttachment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
@@ -421,6 +423,46 @@ public class HeatBridgeImpl implements HeatBridgeApi {
}
}
+ @Override
+ public void buildAddVolumes(List<Resource> stackResources) throws HeatBridgeException {
+ try {
+ if (stackResources.stream().anyMatch(r -> r.getType().equals("OS::Cinder::Volume"))) {
+ stackResources.stream().filter(r -> r.getType().equalsIgnoreCase("OS::Cinder::Volume"))
+ .forEach(r -> createVolume(r));
+ } else {
+ logger.debug("Heat stack contains no volumes");
+ }
+ } catch (Exception e) {
+ logger.error("Failed to add volumes to AAI", e);
+ throw new HeatBridgeException("Failed to add volumes to AAI", e);
+ }
+
+ }
+
+ protected void createVolume(Resource r) {
+ org.openstack4j.model.storage.block.Volume osVolume = osClient.getVolumeById(r.getPhysicalResourceId());
+ List<? extends VolumeAttachment> attachments = osVolume.getAttachments();
+ if (attachments != null) {
+ Optional<? extends VolumeAttachment> vserver = attachments.stream().findFirst();
+ if (vserver.isPresent()) {
+ Volume volume = new Volume();
+ volume.setVolumeId(r.getPhysicalResourceId());
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
+ .cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(vserver.get().getServerId())
+ .volume(r.getPhysicalResourceId()));
+ transaction.createIfNotExists(uri, Optional.of(volume));
+ } else {
+ logger.warn(
+ "Volume {} contains no attachments in openstack. Unable to determine which vserver volume belongs too.",
+ r.getPhysicalResourceId());
+ }
+ } else {
+ logger.warn(
+ "Volume {} contains no attachments in openstack. Unable to determine which vserver volume belongs too.",
+ r.getPhysicalResourceId());
+ }
+ }
+
protected String getInterfaceType(NodeType nodeType, String nicType) {
logger.debug("nicType: " + nicType + "nodeType: " + nodeType);
if (DIRECT.equalsIgnoreCase(nicType)) {
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClient.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClient.java
index 8d47ff4ceb..a4aacfe0e2 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClient.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClient.java
@@ -43,6 +43,7 @@ import org.openstack4j.model.heat.Resource;
import org.openstack4j.model.network.Network;
import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.Subnet;
+import org.openstack4j.model.storage.block.Volume;
public interface OpenstackClient {
@@ -101,4 +102,11 @@ public interface OpenstackClient {
* @return Subnet object.
*/
Subnet getSubnetById(String subnetId);
+
+ /**
+ * Get a volume object by volume ID
+ *
+ * @return Volume object.
+ */
+ Volume getVolumeById(String volumeId);
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientImpl.java
index 1505203d7c..81f09b8a3e 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientImpl.java
@@ -46,6 +46,8 @@ import org.openstack4j.model.heat.Resource;
import org.openstack4j.model.network.Network;
import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.Subnet;
+import org.openstack4j.model.storage.block.Volume;
+import org.openstack4j.model.storage.block.VolumeBackup;
abstract class OpenstackClientImpl implements OpenstackClient {
@Override
@@ -84,6 +86,11 @@ abstract class OpenstackClientImpl implements OpenstackClient {
return getClient().networking().subnet().get(subnetId);
}
+ @Override
+ public Volume getVolumeById(String id) {
+ return getClient().blockStorage().volumes().get(id);
+ }
+
/**
* Retrieves the specific client to utilize.
*