summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src/main
diff options
context:
space:
mode:
authorMunir Ahmad <munir.ahmad@bell.ca>2019-02-08 16:42:03 -0500
committerMunir Ahmad <munir.ahmad@bell.ca>2019-03-24 17:36:27 -0400
commit563a3579e907daa3952e10e25071b676430fd09d (patch)
tree7252c5d383eadc1e2b693d39fd03db5b7a4db2b6 /adapters/mso-openstack-adapters/src/main
parent7815bcec2a85b023f3004e698712cea7fed2f94e (diff)
heatbridge implementation for openstack-adapter
Converted heatbridge to use AAI Client Removed open feign Removed new aai client implementation Removed aai helper classes Removed unnecessary pom.xml imports converted HeatBridgeImpl to rely on AAI transactions added some example unit tests Replaced MsoLogger with slf4j Resolved merge conflicts Change-Id: I933b49fae82c2f0d7a66d9a85b367b29006c73cc Issue-ID: SO-1484 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com> Change-Id: I547b35ebdf51f4534de5d51d7d50a90bb9de4c72 Signed-off-by: Munir Ahmad <munir.ahmad@bell.ca> Issue-ID: SO-1484
Diffstat (limited to 'adapters/mso-openstack-adapters/src/main')
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java94
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java128
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeException.java29
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java365
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java76
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactory.java41
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImpl.java77
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java275
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackAccess.java120
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClient.java69
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientException.java29
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientImpl.java69
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackV2ClientImpl.java37
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackV3ClientImpl.java37
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactory.java27
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactoryImpl.java74
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java61
17 files changed, 1598 insertions, 10 deletions
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 3913d7f758..949027f7c1 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
@@ -37,10 +37,22 @@ import java.util.concurrent.TimeUnit;
import javax.jws.WebService;
import javax.xml.ws.Holder;
+import org.apache.commons.collections.CollectionUtils;
+import org.onap.so.adapters.valet.GenericValetResponse;
+import org.onap.so.adapters.valet.ValetClient;
+import org.onap.so.adapters.valet.beans.HeatRequest;
+import org.onap.so.adapters.valet.beans.ValetConfirmResponse;
+import org.onap.so.adapters.valet.beans.ValetCreateResponse;
+import org.onap.so.adapters.valet.beans.ValetDeleteResponse;
+import org.onap.so.adapters.valet.beans.ValetRollbackResponse;
+import org.onap.so.adapters.valet.beans.ValetStatus;
+import org.onap.so.adapters.valet.beans.ValetUpdateResponse;
import org.onap.so.adapters.vnf.exceptions.VnfAlreadyExists;
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;
@@ -54,27 +66,26 @@ 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.logger.ErrorCode;
+import org.onap.so.heatbridge.HeatBridgeApi;
+import org.onap.so.heatbridge.HeatBridgeImpl;
+import org.onap.so.heatbridge.openstack.api.OpenstackClient;
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.beans.VnfStatus;
+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.onap.so.adapters.valet.ValetClient;
-import org.onap.so.adapters.valet.beans.HeatRequest;
-import org.onap.so.adapters.valet.beans.ValetConfirmResponse;
-import org.onap.so.adapters.valet.beans.ValetCreateResponse;
-import org.onap.so.adapters.valet.beans.ValetDeleteResponse;
-import org.onap.so.adapters.valet.beans.ValetRollbackResponse;
-import org.onap.so.adapters.valet.beans.ValetStatus;
-import org.onap.so.adapters.valet.beans.ValetUpdateResponse;
-import org.onap.so.adapters.valet.GenericValetResponse;
+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;
@@ -509,6 +520,67 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
}
}
+ private void heatbridge(StackInfo heatStack, 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];
+
+ String cloudOwner = "CloudOwner";//cloud owner needs to come from bpmn-adapter
+ List<String> oobMgtNetNames = new ArrayList<>();
+
+ HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity,
+ cloudOwner, cloudSiteId, tenantId);
+
+ OpenstackClient openstackClient = heatBridgeClient.authenticate();
+ List<Resource> stackResources = heatBridgeClient.queryNestedHeatStackResources(heatStackId);
+
+ List<Server> osServers = heatBridgeClient.getAllOpenstackServers(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);
@@ -1271,7 +1343,9 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
logger.error("Exception encountered while sending Confirm to Valet ", e);
}
}
- logger.debug("VF Module {} successfully created", vfModuleName);
+ logger.debug ("VF Module {} successfully created", vfModuleName);
+ //call heatbridge
+ heatbridge(heatStack, cloudSiteId, tenantId, genericVnfName, vfModuleId);
return;
} catch (Exception e) {
logger.debug("unhandled exception in create VF",e);
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
new file mode 100644
index 0000000000..6b06761474
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeApi.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+package org.onap.so.heatbridge;
+
+import java.util.List;
+import org.onap.so.heatbridge.openstack.api.OpenstackClient;
+import org.openstack4j.model.compute.Flavor;
+import org.openstack4j.model.compute.Image;
+import org.openstack4j.model.compute.Server;
+import org.openstack4j.model.heat.Resource;
+
+/**
+ * Defines the contract to extract Heat Stack Resources from Openstack and inventory it to AAI.
+ * This API is used only to "create" objects in AAI.
+ */
+public interface HeatBridgeApi {
+
+ /**
+ * Authenticate with Openstack Keystone. The auth information is read from SO cloud configuration file.
+ *
+ * @return Openstack client object with keystone token
+ * @throws HeatBridgeException upon failure to authenticate with keystone
+ */
+ OpenstackClient authenticate() throws HeatBridgeException;
+
+ /**
+ * Query all the stack based resources from Openstack Heat service
+ *
+ * @param heatStackId Heat stack UUID
+ * @return A list of stack based resources
+ */
+ List<Resource> queryNestedHeatStackResources(String heatStackId);
+
+ /**
+ * Get a filtered list of resource IDs by resource type
+ *
+ * @param stackResources A list of stack based resources
+ * @param resourceType Resource type to filter by
+ * @return A list of stack resources matching the specified resource-type
+ */
+ List<String> extractStackResourceIdsByResourceType(List<Resource> stackResources, String resourceType);
+
+ /**
+ * Get network IDs for a given list of network names.
+ * It is assumed that there is a one to one mapping between the name and ID.
+ * @param networkNameList List of network names
+ * @return List of matching network IDs
+ */
+ List<String> extractNetworkIds(List<String> networkNameList);
+
+ /**
+ * Query the Openstack server objects from the list of stack resources
+ *
+ * @param stackResources A list of stack based resources
+ * @return A list of Openstack Server objects
+ */
+ List<Server> getAllOpenstackServers(List<Resource> stackResources);
+
+ /**
+ * Extract Openstack Image objects from a a list of Server objects
+ *
+ * @param servers A list of Openstack Server objects
+ * @return A list of Openstack Image objects
+ */
+ List<Image> extractOpenstackImagesFromServers(List<Server> servers);
+
+ /**
+ * Extract Openstack Flavor objects from a a list of Server objects
+ *
+ * @param servers A list of Openstack Server objects
+ * @return A list of Openstack Flavor objects
+ */
+ List<Flavor> extractOpenstackFlavorsFromServers(List<Server> servers);
+
+ /**
+ * Query and build AAI actions for Openstack Image resources to AAI's image objects
+ *
+ * @param images List of Openstack Image objects
+ * @throws HeatBridgeException when failing to add images to AAI
+ */
+ void buildAddImagesToAaiAction(List<Image> images) throws HeatBridgeException;
+
+ /**
+ * Query and build AAI actions for Openstack Flavor resources to AAI's flavor objects
+ *
+ * @param flavors List of Openstack Flavor objects
+ * @throws HeatBridgeException when failing to add flavors to AAI
+ */
+ void buildAddFlavorsToAaiAction(List<Flavor> flavors) throws HeatBridgeException;
+
+ /**
+ * Query and build AAI actions for Openstack Compute resources to AAI's vserver objects
+ *
+ * @param genericVnfId AAI generic-vnf-id
+ * @param vfModuleId AAI vf-module-id
+ * @param servers Openstack Server list
+ */
+ void buildAddVserversToAaiAction(String genericVnfId, String vfModuleId, List<Server> servers);
+
+ /**
+ * Query and build AAI actions for Openstack Neutron resources associated with a Compute resource to AAI's
+ * l-interface objects
+ *
+ * @param stackResources Openstack Heat stack resource list
+ * @param oobMgtNetIds List of OOB network IDs list
+ */
+ void buildAddVserverLInterfacesToAaiAction(List<Resource> stackResources, List<String> oobMgtNetIds);
+
+ /**
+ * Execute AAI restful API to update the Openstack resources
+ *
+ * @throws HeatBridgeException when failing to add openstack resource PoJos to AAI
+ */
+ void submitToAai() throws HeatBridgeException;
+}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeException.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeException.java
new file mode 100644
index 0000000000..f993d71e4c
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeException.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+package org.onap.so.heatbridge;
+
+public class HeatBridgeException extends Exception {
+
+ private static final long serialVersionUID = -1472047930391718894L;
+
+ public HeatBridgeException(final String message) {
+ super(message);
+ }
+
+ public HeatBridgeException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+}
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
new file mode 100644
index 0000000000..90ceeb7d1c
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java
@@ -0,0 +1,365 @@
+/*
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+package org.onap.so.heatbridge;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import javax.annotation.Nonnull;
+import javax.ws.rs.WebApplicationException;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.validator.routines.InetAddressValidator;
+import org.onap.aai.domain.yang.Flavor;
+import org.onap.aai.domain.yang.Image;
+import org.onap.aai.domain.yang.L3InterfaceIpv4AddressList;
+import org.onap.aai.domain.yang.LInterface;
+import org.onap.aai.domain.yang.PInterface;
+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.Vlan;
+import org.onap.aai.domain.yang.Vlans;
+import org.onap.aai.domain.yang.Vserver;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.AAISingleTransactionClient;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+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.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.so.logger.MessageEnum;
+import org.onap.so.logger.ErrorCode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.openstack4j.model.compute.Server;
+import org.openstack4j.model.heat.Resource;
+import org.openstack4j.model.network.IP;
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.NetworkType;
+import org.openstack4j.model.network.Port;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * This class provides an implementation of {@link HeatBridgeApi}
+ */
+public class HeatBridgeImpl implements HeatBridgeApi {
+
+ private static final Logger logger = LoggerFactory.getLogger(HeatBridgeImpl.class);
+ private static final String ERR_MSG_NULL_OS_CLIENT = "Initialization error: Null openstack client. Authenticate with Keystone first.";
+ private static final String OOB_MGT_NETWORK_IDENTIFIER = "Management";
+ private OpenstackClient osClient;
+ private AAIResourcesClient resourcesClient;
+ private AAISingleTransactionClient transaction;
+ private String cloudOwner;
+ private String cloudRegionId;
+ private String tenantId;
+ private AaiHelper aaiHelper = new AaiHelper();
+ private CloudIdentity cloudIdentity;
+
+
+ public HeatBridgeImpl(AAIResourcesClient resourcesClient, final CloudIdentity cloudIdentity,
+ @Nonnull final String cloudOwner, @Nonnull final String cloudRegionId, @Nonnull final String tenantId) {
+ Objects.requireNonNull(cloudOwner, "Null cloud-owner value!");
+ Objects.requireNonNull(cloudRegionId, "Null cloud-region identifier!");
+ Objects.requireNonNull(tenantId, "Null tenant identifier!");
+ Objects.requireNonNull(tenantId, "Null AAI actions list!");
+
+ this.cloudIdentity = cloudIdentity;
+ this.cloudOwner = cloudOwner;
+ this.cloudRegionId = cloudRegionId;
+ this.tenantId = tenantId;
+ this.resourcesClient = resourcesClient;
+ this.transaction = resourcesClient.beginSingleTransaction();
+ }
+
+ @Override
+ public OpenstackClient authenticate() throws HeatBridgeException {
+ this.osClient = new MsoCloudClientFactoryImpl(new OpenstackClientFactoryImpl())
+ .getOpenstackClient(cloudIdentity.getIdentityUrl(), cloudIdentity.getMsoId(), cloudIdentity.getMsoPass(), cloudRegionId, tenantId);
+ logger.debug("Successfully authenticated with keystone for tenant: " + tenantId + " and cloud "
+ + "region: " + cloudRegionId);
+ return osClient;
+ }
+
+ @Override
+ public List<Resource> queryNestedHeatStackResources(final String heatStackId) {
+ Objects.requireNonNull(osClient, ERR_MSG_NULL_OS_CLIENT);
+ Preconditions.checkState(!Strings.isNullOrEmpty(heatStackId), "Invalid heatStackId!");
+ List<Resource> stackBasedResources = osClient
+ .getStackBasedResources(heatStackId, HeatBridgeConstants.OS_DEFAULT_HEAT_NESTING);
+ logger.debug(stackBasedResources.size() + " heat stack resources are extracted for stack: " + heatStackId);
+ return stackBasedResources;
+ }
+
+ @Override
+ public List<String> extractStackResourceIdsByResourceType(final List<Resource> stackResources,
+ final String resourceType) {
+ return stackResources.stream()
+ .filter(stackResource -> stackResource.getType().equals(resourceType))
+ .map(Resource::getPhysicalResourceId)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public List<String> extractNetworkIds(final List<String> networkNameList) {
+ Objects.requireNonNull(osClient, ERR_MSG_NULL_OS_CLIENT);
+ return networkNameList.stream()
+ .map(netName -> osClient.listNetworksByFilter(ImmutableMap.of(HeatBridgeConstants.OS_NAME_KEY, netName)))
+ .filter(nets -> nets != null && nets.size() == 1) //extract network-id only if network-name is unique
+ .map(nets -> nets.get(0).getId())
+ .collect(Collectors.toList());
+ }
+
+ @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);
+ return serverIds.stream().map(serverId -> osClient.getServerById(serverId)).collect(Collectors.toList());
+ }
+
+ @Override
+ public List<org.openstack4j.model.compute.Image> extractOpenstackImagesFromServers(final List<Server> servers) {
+ Objects.requireNonNull(osClient, ERR_MSG_NULL_OS_CLIENT);
+ return servers.stream().map(Server::getImage)
+ .filter(distinctByProperty(org.openstack4j.model.compute.Image::getId)).collect(Collectors.toList());
+ }
+
+ @Override
+ public List<org.openstack4j.model.compute.Flavor> extractOpenstackFlavorsFromServers(final List<Server> servers) {
+ Objects.requireNonNull(osClient, ERR_MSG_NULL_OS_CLIENT);
+ return servers.stream().map(Server::getFlavor)
+ .filter(distinctByProperty(org.openstack4j.model.compute.Flavor::getId)).collect(Collectors.toList());
+ }
+
+ @Override
+ public void buildAddImagesToAaiAction(final List<org.openstack4j.model.compute.Image> images)
+ throws HeatBridgeException {
+ for (org.openstack4j.model.compute.Image image : images) {
+ Image aaiImage = aaiHelper.buildImage(image);
+ try {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.IMAGE, cloudOwner, cloudRegionId, aaiImage.getImageId());
+ if (!resourcesClient.exists(uri)) {
+ transaction.create(uri, aaiImage);
+ logger.debug("Queuing AAI command to add image: " + aaiImage.getImageId());
+ } else {
+ logger.debug("Nothing to add since image: " + aaiImage.getImageId() + "already exists in AAI.");
+ }
+ } catch (WebApplicationException e) {
+ throw new HeatBridgeException("Failed to update image to AAI: " + aaiImage.getImageId() + ". Error"
+ + " cause: " + e, e);
+ }
+ }
+ }
+
+ @Override
+ public void buildAddFlavorsToAaiAction(final List<org.openstack4j.model.compute.Flavor> flavors)
+ throws HeatBridgeException {
+ for (org.openstack4j.model.compute.Flavor flavor : flavors) {
+ Flavor aaiFlavor = aaiHelper.buildFlavor(flavor);
+ 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.");
+ }
+ } catch (WebApplicationException e) {
+ throw new HeatBridgeException("Failed to update flavor to AAI: " + aaiFlavor.getFlavorId() + ". Error"
+ + " cause: " + e, e);
+ }
+ }
+ }
+
+ @Override
+ public void buildAddVserversToAaiAction(final String genericVnfId, final String vfModuleId,
+ final List<Server> servers) {
+ servers.forEach(server -> {
+ Vserver vserver = aaiHelper.buildVserver(server.getId(), server);
+
+ // Build vserver relationships to: image, flavor, pserver, vf-module
+ vserver.setRelationshipList(aaiHelper.getVserverRelationshipList(cloudOwner, cloudRegionId, genericVnfId,
+ vfModuleId, server));
+ transaction.create(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegionId, tenantId, vserver.getVserverId()), vserver);
+ });
+ }
+
+ @Override
+ public void buildAddVserverLInterfacesToAaiAction(final List<Resource> stackResources,
+ final List<String> oobMgtNetIds) {
+ Objects.requireNonNull(osClient, ERR_MSG_NULL_OS_CLIENT);
+ List<String> portIds = extractStackResourceIdsByResourceType(stackResources,
+ HeatBridgeConstants.OS_PORT_RESOURCE_TYPE);
+ for (String portId : portIds) {
+ Port port = osClient.getPortById(portId);
+ LInterface lIf = new LInterface();
+ lIf.setInterfaceId(port.getId());
+ lIf.setInterfaceName(port.getName());
+ lIf.setMacaddr(port.getMacAddress());
+ if (oobMgtNetIds != null && oobMgtNetIds.contains(port.getNetworkId())) {
+ lIf.setInterfaceRole(OOB_MGT_NETWORK_IDENTIFIER);
+ } else {
+ lIf.setInterfaceRole(port.getvNicType());
+ }
+
+ updateLInterfaceIps(port, lIf);
+ updateLInterfaceVlan(port, lIf);
+
+ // Update l-interface to the vserver
+ transaction.create(AAIUriFactory.createResourceUri(
+ AAIObjectType.L_INTERFACE, cloudOwner, cloudRegionId, tenantId, port.getDeviceId(), lIf.getInterfaceName()), lIf);
+ }
+ }
+
+ 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());
+ Vlans vlans = new Vlans();
+ List<Vlan> vlanList = vlans.getVlan();
+ vlanList.add(vlan);
+ lIf.setVlans(vlans);
+ }
+ // Build sriov-vf to the l-interface
+ if (port.getvNicType().equalsIgnoreCase(HeatBridgeConstants.OS_SRIOV_PORT_TYPE)) {
+ SriovVfs sriovVfs = new SriovVfs();
+ // JAXB does not generate setters for list, however getter ensures its creation.
+ // Thus, all list manipulations must be made on live list.
+ List<SriovVf> sriovVfList = sriovVfs.getSriovVf();
+ SriovVf sriovVf = new SriovVf();
+ sriovVf.setPciId(port.getProfile().get(HeatBridgeConstants.OS_PCI_SLOT_KEY).toString());
+ sriovVf.setNeutronNetworkId(port.getNetworkId());
+ if (port.getVifDetails() != null) {
+ sriovVf.setVfVlanFilter((String) port.getVifDetails().get(HeatBridgeConstants.OS_VLAN_NETWORK_KEY));
+ }
+ sriovVfList.add(sriovVf);
+
+ lIf.setSriovVfs(sriovVfs);
+
+ // For the given port create sriov-pf for host pserver/p-interface if absent
+ updateSriovPfToPserver(port, lIf);
+ }
+ }
+
+ /**
+ * Needs to be corrected according to the specification that is in draft
+ * If pserver/p-interface does not have a SRIOV-PF object matching the PCI-ID of the Openstack port object, then
+ * create it in AAI.
+ * Openstack SRIOV Port object has pci-id (to match sriov-pf on pserver/p-interface), physical-network ID (that
+ * matches the p-interface name).
+ *
+ * @param port Openstack port object
+ * @param lIf AAI l-interface object
+ */
+ private void updateSriovPfToPserver(final Port port, final LInterface lIf) {
+ if (port.getProfile() == null || Strings
+ .isNullOrEmpty(port.getProfile().get(HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY).toString())) {
+ logger.debug("The SRIOV port:" + port.getName() + " is missing physical-network-id, cannot update "
+ + "sriov-pf object for host pserver: " + port.getHostId());
+ return;
+ }
+ Optional<String> matchingPifName = HeatBridgeUtils
+ .getMatchingPserverPifName(port.getProfile().get(HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY).toString());
+ if (matchingPifName.isPresent()) {
+ // Update l-interface description
+ String pserverHostName = port.getHostId();
+ lIf.setInterfaceDescription(
+ "Attached to SR-IOV port: " + pserverHostName + "::" + matchingPifName.get());
+ try {
+ Optional<PInterface> matchingPIf = resourcesClient.get(PInterface.class,
+ AAIUriFactory.createResourceUri(AAIObjectType.P_INTERFACE, pserverHostName, matchingPifName.get()).depth(Depth.ONE));
+ if (matchingPIf.isPresent()) {
+ SriovPfs pIfSriovPfs = matchingPIf.get().getSriovPfs();
+ if (pIfSriovPfs == null) {
+ pIfSriovPfs = new SriovPfs();
+ }
+ // Extract PCI-ID from OS port object
+ String pfPciId = port.getProfile().get(HeatBridgeConstants.OS_PCI_SLOT_KEY).toString();
+
+ List<SriovPf> existingSriovPfs = pIfSriovPfs.getSriovPf();
+ if (CollectionUtils.isEmpty(existingSriovPfs) || existingSriovPfs.stream()
+ .noneMatch(existingSriovPf -> existingSriovPf.getPfPciId().equals(pfPciId))) {
+ // Add sriov-pf object with PCI-ID to AAI
+ SriovPf sriovPf = new SriovPf();
+ sriovPf.setPfPciId(pfPciId);
+ logger.debug("Queuing AAI command to update sriov-pf object to pserver: " + pserverHostName + "/" +
+ matchingPifName.get());
+ transaction.create(AAIUriFactory.createResourceUri(
+ AAIObjectType.SRIOV_PF, pserverHostName, matchingPifName.get(), sriovPf.getPfPciId()), sriovPf);
+ }
+ }
+ } catch (WebApplicationException e) {
+ // Silently log that we failed to update the Pserver p-interface with PCI-ID
+ logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.GENERAL_EXCEPTION, pserverHostName, matchingPifName.get(), cloudOwner,
+ tenantId, "OpenStack", "Heatbridge", ErrorCode.DataError.getValue(), "Exception - Failed to add sriov-pf object to pserver", e);
+ }
+ }
+ }
+
+ private void updateLInterfaceIps(final Port port, final LInterface lIf) {
+ List<L3InterfaceIpv4AddressList> lInterfaceIps = lIf.getL3InterfaceIpv4AddressList();
+ for (IP ip : port.getFixedIps()) {
+ String ipAddress = ip.getIpAddress();
+ if (InetAddressValidator.getInstance().isValidInet4Address(ipAddress)) {
+ L3InterfaceIpv4AddressList lInterfaceIp = new L3InterfaceIpv4AddressList();
+ lInterfaceIp.setL3InterfaceIpv4Address(ipAddress);
+ lInterfaceIp.setNeutronNetworkId(port.getNetworkId());
+ lInterfaceIp.setNeutronSubnetId(ip.getSubnetId());
+ lInterfaceIp.setL3InterfaceIpv4PrefixLength(32L);
+ lInterfaceIps.add(lInterfaceIp);
+ }
+ }
+ }
+
+ @Override
+ public void submitToAai() throws HeatBridgeException {
+ try {
+ transaction.execute();
+ } catch (BulkProcessFailed e) {
+ String msg = "Failed to commit transaction";
+ logger.debug(msg + " with error: " + e);
+ throw new HeatBridgeException(msg, e);
+ }
+ }
+
+ private <T> Predicate<T> distinctByProperty(Function<? super T, Object> keyExtractor) {
+ Map<Object, Boolean> map = new ConcurrentHashMap<>();
+ return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
+ }
+}
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
new file mode 100644
index 0000000000..1f302341ad
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+package org.onap.so.heatbridge.constants;
+
+public class HeatBridgeConstants {
+
+ private HeatBridgeConstants() {
+ throw new IllegalStateException("Trying to instantiate a constants class.");
+ }
+
+ /**
+ * Openstack related constants
+ */
+ public static final Integer OS_DEFAULT_HEAT_NESTING = 5;
+ public static final String OS_SERVER_RESOURCE_TYPE = "OS::Nova::Server";
+ public static final String OS_PORT_RESOURCE_TYPE = "OS::Neutron::Port";
+ public static final String OS_SRIOV_PORT_TYPE = "direct";
+ public static final String OS_PCI_SLOT_KEY = "pci_slot";
+ public static final String OS_PHYSICAL_NETWORK_KEY = "physical_network";
+ public static final String OS_VLAN_NETWORK_KEY = "vlan";
+ public static final String OS_UNKNOWN_KEY = "unknown";
+ public static final String OS_RESOURCES_SELF_LINK_KEY = "self";
+ public static final String OS_DEFAULT_DOMAIN_NAME = "default";
+ public static final String OS_KEYSTONE_V2_KEY = "v2.0";
+ public static final String OS_KEYSTONE_V3_KEY = "v3";
+ public static final String OS_NAME_KEY = "name";
+
+ /**
+ * AAI related constants
+ */
+ public static final String AAI_GENERIC_VNF = "generic-vnf";
+ public static final String AAI_GENERIC_VNF_ID = "generic-vnf.vnf-id";
+ public static final String AAI_PSERVER = "pserver";
+ public static final String AAI_VSERVER = "vserver";
+ public static final String AAI_PSERVER_HOSTNAME = "pserver.hostname";
+ public static final String AAI_VF_MODULE = "vf-module";
+ public static final String AAI_VF_MODULE_ID = "vf-module.vf-module-id";
+ public static final String AAI_IMAGE = "image";
+ public static final String AAI_IMAGE_ID = "image.image-id";
+ public static final String AAI_CLOUD_OWNER = "cloud-region.cloud-owner";
+ public static final String AAI_CLOUD_REGION_ID = "cloud-region.cloud-region-id";
+ public static final String AAI_FLAVOR = "flavor";
+ public static final String AAI_FLAVOR_ID = "flavor.flavor-id";
+ public static final String AAI_RESOURCE_DEPTH_ALL = "all";
+ 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";
+
+ /**
+ * Keys for internal usage
+ */
+ public static final String KEY_FLAVORS = "flavors";
+ public static final String KEY_IMAGES = "images";
+ public static final String KEY_VSERVERS = "vservers";
+ public static final String KEY_SRIOV_PFS = "pserverSriovPfs";
+ public static final String KEY_GLOBAL_SUBSCRIBER_ID = "globalSubscriberId";
+ public static final String KEY_SERVICE_TYPE = "subscriptionServiceType";
+ public static final String KEY_SERVICE_INSTANCE_ID = "serviceInstanceId";
+ public static final String KEY_VNF_INSTANCE_ID = "genericVnfId";
+ public static final String KEY_MSO_REQUEST_ID = "msoRequestId";
+ public static final String KEY_SO_WORKFLOW_EXCEPTION = "WorkflowException";
+ public static final String KEY_PROCESS_STATUS_MSG = "processStatusMsg";
+}
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
new file mode 100644
index 0000000000..100b50e502
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactory.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+package org.onap.so.heatbridge.factory;
+
+import org.onap.so.heatbridge.HeatBridgeException;
+import org.onap.so.heatbridge.openstack.api.OpenstackClient;
+
+/**
+ * Defines contract to load the cloud configuration from SO, authenticate with keystone for a given cloud-region and
+ * tenant.
+ */
+public interface MsoCloudClientFactory {
+
+ /**
+ * Get the Openstack Client for keystone version specified in cloud configuration.
+ *
+ * @param url openstack url
+ * @param msoId openstack user for mso
+ * @param msoPass openstack password for mso user
+ * @param cloudRegionId cloud-region identifier
+ * @param tenantId tenant identifier
+ * @return Openstack Client for the keystone version requested
+ * @throws HeatBridgeException if any errors when reading cloud configuration or getting openstack client
+ */
+
+
+ OpenstackClient getOpenstackClient(String url, String msoId, String msoPass, String cloudRegionId, String tenantId) 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
new file mode 100644
index 0000000000..b70b32a4d6
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImpl.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+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;
+import org.onap.so.heatbridge.constants.HeatBridgeConstants;
+import org.onap.so.heatbridge.openstack.api.OpenstackAccess;
+import org.onap.so.heatbridge.openstack.api.OpenstackAccess.OpenstackAccessBuilder;
+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;
+
+/**
+ * This class implements {@link MsoCloudClientFactory}
+ * It loads the cloud configuration from SO and uses it to authenticate with keystone.
+ * As a result of authentication with keystone, it returns the Openstack client with the auth token so that
+ * subsequent API calls to Openstack can be made.
+ */
+public class MsoCloudClientFactoryImpl implements MsoCloudClientFactory {
+
+ private OpenstackClientFactory openstackClientFactory;
+
+ public MsoCloudClientFactoryImpl(@Nonnull OpenstackClientFactory openstackClientFactory) {
+ Objects.requireNonNull(openstackClientFactory, "Null OpenstackClientFactory object");
+ this.openstackClientFactory = openstackClientFactory;
+ }
+ @Override
+ public OpenstackClient getOpenstackClient(@Nonnull String url, @Nonnull String msoId, @Nonnull String msoPass, @Nonnull String cloudRegionId, @Nonnull String tenantId) throws
+ HeatBridgeException {
+ Objects.requireNonNull(url, "Null openstack url!");
+ Objects.requireNonNull(msoId, "Null openstack user id!");
+ Objects.requireNonNull(msoPass, "Null openstack password!");
+ Objects.requireNonNull(cloudRegionId, "Null cloud-region ID!");
+ Objects.requireNonNull(tenantId, "Null tenant ID!");
+ try {
+ final OpenstackAccess osAccess = new OpenstackAccessBuilder()
+ .setBaseUrl(url) // keystone URL
+ .setUser(msoId) // keystone username
+ .setPassword(CryptoUtils.decryptCloudConfigPassword(msoPass)) // keystone decrypted password
+ .setRegion(cloudRegionId) // openstack region
+ .setDomainName(HeatBridgeConstants.OS_DEFAULT_DOMAIN_NAME) // hardcode to "default"
+ .setTenantId(tenantId) // tenantId
+ .build();
+
+ // Identify the Keystone version
+ String version = new URL(url).getPath().replace("/", "");
+ if (version.equals(HeatBridgeConstants.OS_KEYSTONE_V2_KEY)) {
+ return openstackClientFactory.createOpenstackV2Client(osAccess);
+ } else if (version.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);
+ } catch (OpenstackClientException osClientEx) {
+ throw new HeatBridgeException("Client error when authenticating with the Openstack V3.", 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
new file mode 100644
index 0000000000..a0f1f0798f
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java
@@ -0,0 +1,275 @@
+/*
+ * Copyright (C) 2018 Bell Canada.
+ *
+ * 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.
+ */
+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;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
+import org.onap.aai.domain.yang.Flavor;
+import org.onap.aai.domain.yang.Image;
+import org.onap.aai.domain.yang.Relationship;
+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.heatbridge.constants.HeatBridgeConstants;
+import org.openstack4j.model.compute.Server;
+
+/**
+ * This class provides wrapper methods to manage creation of AAI objects and extracting objects from AAI and
+ * transforming into required objects.
+ */
+public class AaiHelper {
+
+ /**
+ * Build vserver relationship object to entities: pserver, vf-module, image, flavor
+ *
+ * @param cloudOwner AAI cloudOwner value
+ * @param cloudRegionId AAI cloud-region identifier
+ * @param genericVnfId AAI generic-vnf identifier
+ * @param vfModuleId AAI vf-module identifier
+ * @param server Openstack Server object
+ */
+ public RelationshipList getVserverRelationshipList(final String cloudOwner, final String cloudRegionId, final String
+ genericVnfId, final String vfModuleId, final Server server) {
+ RelationshipList relationshipList = new RelationshipList();
+ 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());
+ relationships.add(pserverRelationship);
+
+ // 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());
+ relationships.add(vfModuleRelationship);
+
+ // vserver to image relationship
+ 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());
+ 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());
+ relationships.add(flavorRel);
+ return relationshipList;
+ }
+
+ public RelationshipList getLInterfaceRelationshipList(final String pserverName, final String pIfName,
+ final String pfPciId) {
+ RelationshipList relationshipList = new RelationshipList();
+ 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());
+ relationships.add(sriovPfRelationship);
+
+ return relationshipList;
+ }
+
+ /**
+ * Transform Openstack Server object to AAI Vserver object
+ *
+ * @param serverId Openstack server identifier
+ * @param server Openstack server object
+ * @return AAI Vserver object
+ */
+ public Vserver buildVserver(final String serverId, final Server server) {
+ Vserver vserver = new Vserver();
+ vserver.setInMaint(false);
+ vserver.setIsClosedLoopDisabled(false);
+ vserver.setVserverId(serverId);
+ vserver.setVserverName(server.getName());
+ vserver.setVserverName2(server.getName());
+ vserver.setProvStatus(server.getStatus().value());
+ server.getLinks().stream().filter(link -> link.getRel().equals(HeatBridgeConstants.OS_RESOURCES_SELF_LINK_KEY))
+ .findFirst().ifPresent(link -> vserver.setVserverSelflink(link.getHref()));
+ return vserver;
+ }
+
+ /**
+ * Transform Openstack Image object to AAI Image object
+ *
+ * @param image Openstack Image object
+ * @return AAI Image object
+ */
+ public Image buildImage(final org.openstack4j.model.compute.Image image) {
+ Image aaiImage = new Image();
+ aaiImage.setImageId(image.getId());
+ 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()));
+ return aaiImage;
+ }
+
+ /**
+ * Transform Openstack Flavor object to AAI Flavor object
+ *
+ * @param flavor Openstack Flavor object
+ * @return AAI Flavor object
+ */
+ public Flavor buildFlavor(final org.openstack4j.model.compute.Flavor flavor) {
+ Flavor aaiFlavor = new Flavor();
+ aaiFlavor.setFlavorId(flavor.getId());
+ aaiFlavor.setFlavorName(flavor.getName());
+ flavor.getLinks().stream().filter(link -> link.getRel().equals(HeatBridgeConstants.OS_RESOURCES_SELF_LINK_KEY))
+ .findFirst().ifPresent(link -> aaiFlavor.setFlavorSelflink(link.getHref()));
+ return aaiFlavor;
+ }
+
+ /**
+ * Extract a list of flavors URI associated with the list of vservers
+ *
+ * @param vservers List of vserver AAI objects
+ * @return a list of related flavor related-links
+ */
+ public List<String> getFlavorsUriFromVserver(final List<Vserver> vservers) {
+ List<String> flavorUris = new ArrayList<>();
+ vservers.forEach(vserver -> flavorUris.addAll(
+ filterRelatedLinksByRelatedToProperty(vserver.getRelationshipList(), HeatBridgeConstants.AAI_FLAVOR)));
+ return flavorUris;
+ }
+
+ /**
+ * Extract a list of images URI associated with the list of vservers
+ *
+ * @param vservers List of vserver AAI objects
+ * @return a list of related image related-links
+ */
+ public List<String> getImagesUriFromVserver(final List<Vserver> vservers) {
+ List<String> imageUris = new ArrayList<>();
+ vservers.forEach(vserver -> imageUris.addAll(
+ filterRelatedLinksByRelatedToProperty(vserver.getRelationshipList(), HeatBridgeConstants.AAI_IMAGE)));
+ return imageUris;
+ }
+
+ /**
+ * From the list vserver objects build a map of compute hosts's name and the PCI IDs linked to it.
+ *
+ * @param vservers List of vserver AAI objects
+ * @return a map of compute names to the PCI ids associated with the compute
+ */
+ public Map<String, List<String>> getPserverToPciIdMap(final List<Vserver> vservers) {
+ Map<String, List<String>> pserverToPciIdMap = new HashMap<>();
+ for(Vserver vserver : vservers) {
+ if(vserver.getLInterfaces() != null) {
+ List<String> pciIds = vserver.getLInterfaces().getLInterface()
+ .stream()
+ .filter(lInterface -> lInterface.getSriovVfs() != null
+ && CollectionUtils.isNotEmpty(lInterface.getSriovVfs().getSriovVf()))
+ .flatMap(lInterface -> lInterface.getSriovVfs().getSriovVf().stream())
+ .map(SriovVf::getPciId)
+ .collect(Collectors.toList());
+ if (CollectionUtils.isNotEmpty(pciIds)) {
+ List<String> matchingPservers = extractRelationshipDataValue(vserver.getRelationshipList(),
+ HeatBridgeConstants.AAI_PSERVER, HeatBridgeConstants.AAI_PSERVER_HOSTNAME);
+ Preconditions.checkState(matchingPservers != null && matchingPservers.size() == 1,
+ "Invalid pserver relationships for vserver: " + vserver.getVserverName());
+ pserverToPciIdMap.put(matchingPservers.get(0), pciIds);
+ }
+ }
+ }
+ return pserverToPciIdMap;
+ }
+
+ /**
+ * Extract from relationship-list object all the relationship-value that match the related-to and
+ * relationship-key fields.
+ *
+ * @param relationshipListObj AAI relationship-list object
+ * @param relatedToProperty related-to value
+ * @param relationshipKey relationship-key value
+ * @return relationship-value matching the key requested for the relationship object of type related-to property
+ */
+ private List<String> extractRelationshipDataValue(final RelationshipList relationshipListObj,
+ final String relatedToProperty, final String relationshipKey) {
+ if (relationshipListObj != null && relationshipListObj.getRelationship() != null) {
+ return relationshipListObj.getRelationship().stream()
+ .filter(relationship -> relationship.getRelatedTo().equals(relatedToProperty))
+ .map(Relationship::getRelationshipData)
+ .flatMap(Collection::stream)
+ .filter(data -> data.getRelationshipKey() != null && relationshipKey.equals(data.getRelationshipKey()))
+ .map(RelationshipData::getRelationshipValue)
+ .collect(Collectors.toList());
+ }
+ return new ArrayList<>();
+ }
+
+ /**
+ * Extract and filter the related-links to all objects that match the type specified by the filter property
+ *
+ * @param relationshipListObj AAI object representing relationship object
+ * @param relatedToProperty Value identifying the type of AAI object for related-to field
+ * @return a list of related-links filtered by the specified related-to property
+ */
+ private List<String> filterRelatedLinksByRelatedToProperty(final RelationshipList relationshipListObj,
+ final String relatedToProperty) {
+ if (relationshipListObj != null && relationshipListObj.getRelationship() != null) {
+ return relationshipListObj.getRelationship().stream()
+ .filter(relationship -> relationship.getRelatedTo().equals(relatedToProperty))
+ .map(Relationship::getRelatedLink)
+ .collect(Collectors.toList());
+ }
+ return new ArrayList<>();
+ }
+
+ /**
+ * Build the relationship object
+ *
+ * @param relatedTo Related to entity value
+ * @param relationshipKeyValues Key value pairs of relationship data
+ * @return AAI Relationship object
+ */
+ private Relationship buildRelationship(final String relatedTo, final Map<String, String> relationshipKeyValues) {
+ 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);
+ });
+ return relationship;
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackAccess.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackAccess.java
new file mode 100644
index 0000000000..fd5dabc784
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackAccess.java
@@ -0,0 +1,120 @@
+/*-
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+
+package org.onap.so.heatbridge.openstack.api;
+
+import org.openstack4j.model.common.Identifier;
+
+/**
+ * Object handling OpenStack API access information.
+ */
+public class OpenstackAccess {
+ private final String baseUrl;
+ private final String tenantId;
+ private final String user;
+ private final String password;
+ private final String region;
+ private String domainName;
+ private String projectName;
+
+ public OpenstackAccess(OpenstackAccessBuilder builder) {
+ this.baseUrl = builder.baseUrl;
+ this.tenantId = builder.tenantId;
+ this.user = builder.user;
+ this.password = builder.password;
+ this.region = builder.region;
+ this.domainName = builder.domainName;
+ this.projectName = builder.projectName;
+ }
+
+ public String getUrl() {
+ return baseUrl;
+ }
+
+ public String getTenantId() {
+ return tenantId;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getRegion() {
+ return region;
+ }
+
+ public Identifier getDomainNameIdentifier() {
+ return Identifier.byName(domainName);
+ }
+
+ public String getProjectName() {
+ return projectName;
+ }
+
+ public static class OpenstackAccessBuilder {
+
+ private String baseUrl;
+ private String tenantId;
+ private String user;
+ private String password;
+ private String region;
+ private String domainName;
+ private String projectName;
+
+ public OpenstackAccessBuilder setBaseUrl(final String baseUrl) {
+ this.baseUrl = baseUrl;
+ return this;
+ }
+
+ public OpenstackAccessBuilder setTenantId(final String tenantId) {
+ this.tenantId = tenantId;
+ return this;
+ }
+
+ public OpenstackAccessBuilder setUser(final String user) {
+ this.user = user;
+ return this;
+ }
+
+ public OpenstackAccessBuilder setPassword(final String password) {
+ this.password = password;
+ return this;
+ }
+
+ public OpenstackAccessBuilder setRegion(final String region) {
+ this.region = region;
+ return this;
+ }
+
+ public OpenstackAccessBuilder setDomainName(final String domainName) {
+ this.domainName = domainName;
+ return this;
+ }
+
+ public OpenstackAccessBuilder setProjectName(final String projectName) {
+ this.projectName = projectName;
+ return this;
+ }
+
+ public OpenstackAccess build() {
+ return new OpenstackAccess(this);
+ }
+ }
+}
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
new file mode 100644
index 0000000000..143e33581d
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClient.java
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+
+package org.onap.so.heatbridge.openstack.api;
+
+import java.util.List;
+import java.util.Map;
+import org.openstack4j.model.compute.Server;
+import org.openstack4j.model.heat.Resource;
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.Port;
+
+public interface OpenstackClient {
+
+ /**
+ * Get a server object by server ID
+ * @param serverId Unique server-name (simple name) or server-id (UUID)
+ * @return Server object
+ */
+ Server getServerById(String serverId);
+
+ /**
+ * Get a port object by port ID
+ * @param portId Unique UUID of the port.
+ * @return Port object.
+ */
+ Port getPortById(String portId);
+
+ /**
+ * Returns a list of all ports we have the right to see
+ * @return List of all Openstack ports
+ */
+ List<Port> getAllPorts();
+
+ /**
+ * Returns a list of all the resources for the stack
+ * @param stackId Stack name or unique UUID
+ * @param nestingDepth The recursion level for which resources will be listed.
+ * @return List of Openstack Stack resources
+ */
+ List<Resource> getStackBasedResources(String stackId, int nestingDepth);
+
+ /**
+ * Get a network instance by network ID
+ * @param networkId Unique UUID of the network.
+ * @return Network object.
+ */
+ Network getNetworkById(String networkId);
+
+ /**
+ * List networks by filtering parameters
+ * @param filterParams key-value pairs for filtering params
+ * @return List of filtered Network objects
+ */
+ List<Network> listNetworksByFilter(Map<String, String> filterParams);
+}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientException.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientException.java
new file mode 100644
index 0000000000..a062ca826d
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientException.java
@@ -0,0 +1,29 @@
+/*-
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+
+package org.onap.so.heatbridge.openstack.api;
+
+public class OpenstackClientException extends Exception {
+ private static final long serialVersionUID = -5514207977226960180L;
+
+ public OpenstackClientException(final String message) {
+ super(message);
+ }
+
+ public OpenstackClientException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+}
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
new file mode 100644
index 0000000000..ebd4753323
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientImpl.java
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+
+package org.onap.so.heatbridge.openstack.api;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.openstack4j.api.OSClient;
+import org.openstack4j.model.compute.Server;
+import org.openstack4j.model.heat.Resource;
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.Port;
+
+abstract class OpenstackClientImpl implements OpenstackClient {
+ @Override
+ public Server getServerById(String serverId) {
+ return getClient().compute().servers().get(serverId);
+ }
+
+ @Override
+ public Port getPortById(String portId) {
+ return getClient().networking().port().get(portId);
+ }
+
+ @Override
+ public List<Port> getAllPorts() { return (List<Port>)getClient().networking().port().list(); }
+
+ @Override
+ public List<Resource> getStackBasedResources(String stackId, int nestingDepth) {
+ return getClient().heat()
+ .resources()
+ .list(stackId, nestingDepth)
+ .stream()
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Network getNetworkById(String networkId) {
+ return getClient().networking().network().get(networkId);
+ }
+
+ @Override
+ public List<Network> listNetworksByFilter(Map<String, String> filterParams) {
+ return (List<Network>) getClient().networking().network().list(filterParams);
+ }
+
+ /**
+ * Retrieves the specific client to utilize.
+ * @return The specific client to utilize
+ */
+ protected abstract OSClient getClient();
+
+}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackV2ClientImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackV2ClientImpl.java
new file mode 100644
index 0000000000..760be72b3f
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackV2ClientImpl.java
@@ -0,0 +1,37 @@
+/*-
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+
+package org.onap.so.heatbridge.openstack.api;
+
+import org.openstack4j.api.OSClient;
+import org.openstack4j.api.OSClient.OSClientV2;
+
+public class OpenstackV2ClientImpl extends OpenstackClientImpl {
+
+ private OSClientV2 client;
+
+ public OpenstackV2ClientImpl(OSClientV2 client) {
+ this.client = client;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected OSClient getClient() {
+ return client;
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackV3ClientImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackV3ClientImpl.java
new file mode 100644
index 0000000000..dddd82ce6a
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackV3ClientImpl.java
@@ -0,0 +1,37 @@
+/*-
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+
+package org.onap.so.heatbridge.openstack.api;
+
+import org.openstack4j.api.OSClient;
+import org.openstack4j.api.OSClient.OSClientV3;
+
+public class OpenstackV3ClientImpl extends OpenstackClientImpl {
+
+ private OSClientV3 client;
+
+ public OpenstackV3ClientImpl(OSClientV3 client) {
+ this.client = client;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected OSClient getClient() {
+ return client;
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactory.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactory.java
new file mode 100644
index 0000000000..5019eec09b
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactory.java
@@ -0,0 +1,27 @@
+/*-
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+package org.onap.so.heatbridge.openstack.factory;
+
+import org.onap.so.heatbridge.openstack.api.OpenstackAccess;
+import org.onap.so.heatbridge.openstack.api.OpenstackClient;
+import org.onap.so.heatbridge.openstack.api.OpenstackClientException;
+
+public interface OpenstackClientFactory {
+
+ OpenstackClient createOpenstackV3Client(OpenstackAccess osAccess) throws OpenstackClientException;
+
+ OpenstackClient createOpenstackV2Client(OpenstackAccess osAccess) throws OpenstackClientException;
+}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactoryImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactoryImpl.java
new file mode 100644
index 0000000000..72b3795053
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactoryImpl.java
@@ -0,0 +1,74 @@
+/*-
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+package org.onap.so.heatbridge.openstack.factory;
+
+import com.google.common.base.Preconditions;
+import org.onap.so.heatbridge.openstack.api.OpenstackAccess;
+import org.onap.so.heatbridge.openstack.api.OpenstackClient;
+import org.onap.so.heatbridge.openstack.api.OpenstackClientException;
+import org.onap.so.heatbridge.openstack.api.OpenstackV2ClientImpl;
+import org.onap.so.heatbridge.openstack.api.OpenstackV3ClientImpl;
+import org.openstack4j.api.OSClient.OSClientV2;
+import org.openstack4j.api.OSClient.OSClientV3;
+import org.openstack4j.api.exceptions.AuthenticationException;
+import org.openstack4j.openstack.OSFactory;
+
+public class OpenstackClientFactoryImpl implements OpenstackClientFactory {
+
+ @Override
+ public OpenstackClient createOpenstackV3Client(OpenstackAccess osAccess) throws OpenstackClientException {
+ Preconditions.checkNotNull(osAccess.getUrl(), "Keystone-v3 Auth: endpoint not set.");
+ Preconditions.checkNotNull(osAccess.getUser(), "Keystone-v3 Auth: username not set.");
+ Preconditions.checkNotNull(osAccess.getPassword(), "Keystone-v3 Auth: password not set.");
+ Preconditions.checkNotNull(osAccess.getDomainNameIdentifier(), "Keystone-v3 Auth: domain not set.");
+ Preconditions.checkNotNull(osAccess.getRegion(), "Keystone-v3 Auth: region not set.");
+
+ OSClientV3 client;
+ try {
+ client = OSFactory.builderV3()
+ .endpoint(osAccess.getUrl())
+ .credentials(osAccess.getUser(), osAccess.getPassword(), osAccess.getDomainNameIdentifier())
+ .authenticate()
+ .useRegion(osAccess.getRegion());
+ return new OpenstackV3ClientImpl(client);
+ } catch (AuthenticationException exception) {
+ throw new OpenstackClientException("Failed to authenticate with Keystone-v3: " + osAccess.getUrl(), exception);
+ }
+ }
+
+ @Override
+ public OpenstackClient createOpenstackV2Client(OpenstackAccess osAccess) throws OpenstackClientException {
+ Preconditions.checkNotNull(osAccess.getUrl(), "Keystone-v2 Auth: endpoint not set.");
+ Preconditions.checkNotNull(osAccess.getUser(), "Keystone-v2 Auth: username not set.");
+ Preconditions.checkNotNull(osAccess.getPassword(), "Keystone-v2 Auth: password not set.");
+ Preconditions.checkNotNull(osAccess.getTenantId(), "Keystone-v2 Auth: domain not set.");
+ Preconditions.checkNotNull(osAccess.getRegion(), "Keystone-v2 Auth: region not set.");
+
+ OSClientV2 client;
+ try {
+ client = OSFactory.builderV2()
+ .endpoint(osAccess.getUrl())
+ .credentials(osAccess.getUser(), osAccess.getPassword())
+ .tenantId(osAccess.getTenantId())
+ .authenticate()
+ .useRegion(osAccess.getRegion());
+ return new OpenstackV2ClientImpl(client);
+ } catch (AuthenticationException exception) {
+ throw new OpenstackClientException("Failed to authenticate with Keystone-v2.0: " + osAccess.getUrl(),
+ exception);
+ }
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java
new file mode 100644
index 0000000000..7daa8c2c71
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2018 Bell Canada. 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.
+ */
+
+package org.onap.so.heatbridge.utils;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import java.util.Optional;
+import javax.annotation.Nonnull;
+
+public class HeatBridgeUtils {
+
+ private HeatBridgeUtils() {
+ throw new IllegalStateException("Trying to instantiate a utility class.");
+ }
+
+ /**
+ * IaaS naming convention for compute/p-interface to openstack/physical-network name mapping
+ */
+ private static final String OS_SIDE_SHARED_SRIOV_PREFIX = "shared-";
+ private static final String OS_SIDE_DEDICATED_SRIOV_PREFIX = "dedicated-";
+ private static final String COMPUTE_SIDE_SHARED_SRIOV_PREFIX = "sriov-s-";
+ private static final String COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX = "sriov-d-";
+
+ public static Optional<String> getMatchingPserverPifName(@Nonnull final String physicalNetworkName) {
+ Preconditions.checkState(!Strings.isNullOrEmpty(physicalNetworkName), "Physical network name is null or "
+ + "empty!");
+ if (physicalNetworkName.contains(OS_SIDE_DEDICATED_SRIOV_PREFIX)) {
+ return Optional
+ .of(physicalNetworkName.replace(OS_SIDE_DEDICATED_SRIOV_PREFIX, COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX));
+ } else if (physicalNetworkName.contains(OS_SIDE_SHARED_SRIOV_PREFIX)) {
+ return Optional
+ .of(physicalNetworkName.replace(OS_SIDE_SHARED_SRIOV_PREFIX, COMPUTE_SIDE_SHARED_SRIOV_PREFIX));
+ }
+ return Optional.empty();
+ }
+
+ public static Optional<String> getMatchingPhysicalNetworkName(final String pserverPinterfaceName) {
+ if (pserverPinterfaceName.contains(COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX)) {
+ return Optional
+ .of(pserverPinterfaceName.replace(COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX, OS_SIDE_DEDICATED_SRIOV_PREFIX));
+ } else if (pserverPinterfaceName.contains(COMPUTE_SIDE_SHARED_SRIOV_PREFIX)) {
+ return Optional
+ .of(pserverPinterfaceName.replace(COMPUTE_SIDE_SHARED_SRIOV_PREFIX, OS_SIDE_SHARED_SRIOV_PREFIX));
+ }
+ return Optional.empty();
+ }
+}