diff options
Diffstat (limited to 'adapters/mso-adapter-utils')
5 files changed, 51 insertions, 60 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java index b0c2d9430a..71cdcf6078 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java @@ -22,7 +22,6 @@ package org.onap.so.openstack.utils; import org.onap.so.cloud.authentication.KeystoneAuthHolder; -import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; import org.onap.so.openstack.exceptions.MsoException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +41,7 @@ public class CinderClientImpl extends MsoCommonUtils { /** * Gets the Cinder client. * - * @param cloudSite the cloud site + * @param cloudSiteId the cloud site * @param tenantId the tenant id * @return the glance client * @throws MsoException the mso exception @@ -62,15 +61,12 @@ public class CinderClientImpl extends MsoCommonUtils { * @param cloudSiteId the cloud site id * @param tenantId the tenant id * @param limit limits the number of records returned - * @param visibility visibility in the image in openstack * @param marker the last viewed record - * @param name the image names * @return the list of images in openstack - * @throws MsoCloudSiteNotFound the mso cloud site not found * @throws CinderClientException the glance client exception */ public Volumes queryVolumes(String cloudSiteId, String tenantId, int limit, String marker) - throws MsoCloudSiteNotFound, CinderClientException { + throws CinderClientException { try { Cinder cinderClient = getCinderClient(cloudSiteId, tenantId); // list is set to false, otherwise an invalid URL is appended @@ -78,22 +74,23 @@ public class CinderClientImpl extends MsoCommonUtils { cinderClient.volumes().list(false).queryParam("limit", limit).queryParam("marker", marker); return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { - logger.error("Error building Cinder Client", e); - throw new CinderClientException("Error building Cinder Client", e); + String errorMsg = "Error building Cinder Client"; + logger.error(errorMsg, e); + throw new CinderClientException(errorMsg, e); } } - public Volume queryVolume(String cloudSiteId, String tenantId, String volumeId) - throws MsoCloudSiteNotFound, CinderClientException { + public Volume queryVolume(String cloudSiteId, String tenantId, String volumeId) throws CinderClientException { try { Cinder cinderClient = getCinderClient(cloudSiteId, tenantId); // list is set to false, otherwise an invalid URL is appended OpenStackRequest<Volume> request = cinderClient.volumes().show(volumeId); return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { - logger.error("Error building Cinder Client", e); - throw new CinderClientException("Error building Cinder Client", e); + String errorMsg = "Error building Cinder Client"; + logger.error(errorMsg, e); + throw new CinderClientException(errorMsg, e); } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatEnvironmentEntry.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatEnvironmentEntry.java index 8cacf8526a..468b771c07 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatEnvironmentEntry.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatEnvironmentEntry.java @@ -132,14 +132,14 @@ public class MsoHeatEnvironmentEntry { } public boolean hasResources() { - if (this.resources != null && this.resources.size() > 0) { + if (this.resources != null && !this.resources.isEmpty()) { return true; } return false; } public boolean hasParameters() { - if (this.parameters != null && this.parameters.size() > 0) { + if (this.parameters != null && !this.parameters.isEmpty()) { return true; } return false; @@ -147,7 +147,7 @@ public class MsoHeatEnvironmentEntry { public boolean containsParameter(String paramName) { boolean contains = false; - if (this.parameters == null || this.parameters.size() < 1) { + if (this.parameters == null || this.parameters.isEmpty()) { return false; } if (this.parameters.contains(new MsoHeatEnvironmentParameter(paramName))) { diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java index 1d75892138..6565db7ebc 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java @@ -44,7 +44,6 @@ import org.onap.so.adapters.vdu.VduModelInfo; import org.onap.so.adapters.vdu.VduPlugin; import org.onap.so.adapters.vdu.VduStateType; import org.onap.so.adapters.vdu.VduStatus; -import org.onap.so.cloud.CloudConfig; import org.onap.so.cloud.authentication.KeystoneAuthHolder; import org.onap.so.db.catalog.beans.CloudIdentity; import org.onap.so.db.catalog.beans.CloudSite; @@ -108,10 +107,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { "{} Create Stack: Nested exception rolling back stack: {} "; public static final String IN_PROGRESS = "in_progress"; - // Fetch cloud configuration each time (may be cached in CloudConfig class) - @Autowired - protected CloudConfig cloudConfig; - @Autowired private Environment environment; @@ -134,7 +129,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { protected static final String CREATE_POLL_INTERVAL_DEFAULT = "15"; private static final String DELETE_POLL_INTERVAL_DEFAULT = "15"; - private static final String pollingMultiplierDefault = "60"; + private static final String POLLING_MULTIPLIER_DEFAULT = "60"; private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); @@ -200,7 +195,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { * @param cloudOwner the cloud owner of the cloud site in which to create the stack * @param tenantId The Openstack ID of the tenant in which to create the Stack * @param stackName The name of the stack to create - * @param vduModelInfo contains information about the vdu model (added for plugin adapter) + * @param vduModel contains information about the vdu model (added for plugin adapter) * @param heatTemplate The Heat template * @param stackInputs A map of key/value inputs * @param pollForCompletion Indicator that polling should be handled in Java vs. in the client @@ -287,42 +282,41 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { String cloudSiteId, String tenantId, CreateStackParam stackCreate) throws MsoException { if (stack == null) { throw new StackCreationException("Unknown Error in Stack Creation"); - } else { - logger.info("Performing post processing backout: {} cleanUpKeyPair: {}, stack {}", backout, cleanUpKeyPair, - stack); - if (!CREATE_COMPLETE.equals(stack.getStackStatus())) { - if (cleanUpKeyPair && !Strings.isNullOrEmpty(stack.getStackStatusReason()) - && isKeyPairFailure(stack.getStackStatusReason())) { - return handleKeyPairConflict(cloudSiteId, tenantId, stackCreate, timeoutMinutes, backout, stack); - } - if (!backout) { - logger.info("Status is not CREATE_COMPLETE, stack deletion suppressed"); - throw new StackCreationException("Stack rollback suppressed, stack not deleted"); - } else { - logger.info("Status is not CREATE_COMPLETE, stack deletion will be executed"); - String errorMessage = "Stack Creation Failed Openstack Status: " + stack.getStackStatus() - + " Status Reason: " + stack.getStackStatusReason(); - try { - Stack deletedStack = - handleUnknownCreateStackFailure(stack, timeoutMinutes, cloudSiteId, tenantId); - errorMessage = errorMessage + " , Rollback of Stack Creation completed with status: " - + deletedStack.getStackStatus() + " Status Reason: " - + deletedStack.getStackStatusReason(); - } catch (MsoException e) { - logger.error("Sync Error Deleting Stack during rollback", e); - if (e instanceof StackRollbackException) { - errorMessage = errorMessage + e.getMessage(); - } else { - errorMessage = errorMessage + " , Rollback of Stack Creation failed with sync error: " - + e.getMessage(); - } - } - throw new StackCreationException(errorMessage); - } + } + + logger.info("Performing post processing backout: {} cleanUpKeyPair: {}, stack {}", backout, cleanUpKeyPair, + stack); + if (!CREATE_COMPLETE.equals(stack.getStackStatus())) { + if (cleanUpKeyPair && !Strings.isNullOrEmpty(stack.getStackStatusReason()) + && isKeyPairFailure(stack.getStackStatusReason())) { + return handleKeyPairConflict(cloudSiteId, tenantId, stackCreate, timeoutMinutes, backout, stack); + } + if (!backout) { + logger.info("Status is not CREATE_COMPLETE, stack deletion suppressed"); + throw new StackCreationException("Stack rollback suppressed, stack not deleted"); } else { - return stack; + logger.info("Status is not CREATE_COMPLETE, stack deletion will be executed"); + String errorMessage = "Stack Creation Failed Openstack Status: " + stack.getStackStatus() + + " Status Reason: " + stack.getStackStatusReason(); + try { + Stack deletedStack = handleUnknownCreateStackFailure(stack, timeoutMinutes, cloudSiteId, tenantId); + errorMessage = errorMessage + " , Rollback of Stack Creation completed with status: " + + deletedStack.getStackStatus() + " Status Reason: " + deletedStack.getStackStatusReason(); + } catch (StackRollbackException se) { + logger.error("Sync Error Deleting Stack during rollback process", se); + errorMessage = errorMessage + se.getMessage(); + } catch (MsoException e) { + logger.error("Sync Error Deleting Stack during rollback", e); + + errorMessage = + errorMessage + " , Rollback of Stack Creation failed with sync error: " + e.getMessage(); + } + throw new StackCreationException(errorMessage); } + } else { + return stack; } + } protected Stack pollStackForStatus(int timeoutMinutes, Stack stack, String stackStatus, String cloudSiteId, @@ -330,7 +324,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { int pollingFrequency = Integer.parseInt(this.environment.getProperty(createPollIntervalProp, CREATE_POLL_INTERVAL_DEFAULT)); int pollingMultiplier = - Integer.parseInt(this.environment.getProperty(pollingMultiplierProp, pollingMultiplierDefault)); + Integer.parseInt(this.environment.getProperty(pollingMultiplierProp, POLLING_MULTIPLIER_DEFAULT)); int numberOfPollingAttempts = Math.floorDiv((timeoutMinutes * pollingMultiplier), pollingFrequency); Heat heatClient = getHeatClient(cloudSiteId, tenantId); Stack latestStack = null; diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java index 069c6c7c5b..44fc620b07 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java @@ -130,13 +130,13 @@ public class MsoNeutronUtils extends MsoCommonUtils { network.setAdminStateUp(true); if (type == NetworkType.PROVIDER) { - if (provider != null && vlans != null && vlans.size() > 0) { + if (provider != null && vlans != null && !vlans.isEmpty()) { network.setProviderPhysicalNetwork(provider); network.setProviderNetworkType("vlan"); network.setProviderSegmentationId(vlans.get(0)); } } else if (type == NetworkType.MULTI_PROVIDER) { - if (provider != null && vlans != null && vlans.size() > 0) { + if (provider != null && vlans != null && !vlans.isEmpty()) { List<Segment> segments = new ArrayList<>(vlans.size()); for (int vlan : vlans) { Segment segment = new Segment(); diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java index e840d5affd..e68364eab8 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java @@ -322,8 +322,8 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { CreateStackParam createStackParam = new CreateStackParam(); createStackParam.setStackName("stackName"); - doReturn(mockResources).when(heatUtils).queryStackResources(cloudSiteId, tenantId, "stackName", 2); - doNothing().when(novaClient).deleteKeyPair(cloudSiteId, tenantId, "KeypairName"); + // doReturn(mockResources).when(heatUtils).queryStackResources(cloudSiteId, tenantId, "stackName", 2); + // doNothing().when(novaClient).deleteKeyPair(cloudSiteId, tenantId, "KeypairName"); doReturn(null).when(heatUtils).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId); doReturn(createdStack).when(heatUtils).createStack(createStackParam, cloudSiteId, tenantId); doReturn(createdStack).when(heatUtils).processCreateStack(cloudSiteId, tenantId, 120, true, createdStack, |