diff options
Diffstat (limited to 'adapters/mso-adapter-utils/src/main')
7 files changed, 67 insertions, 53 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 567f849b36..b0c2d9430a 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 @@ -76,7 +76,7 @@ public class CinderClientImpl extends MsoCommonUtils { // list is set to false, otherwise an invalid URL is appended OpenStackRequest<Volumes> request = cinderClient.volumes().list(false).queryParam("limit", limit).queryParam("marker", marker); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Cinder Client", e); throw new CinderClientException("Error building Cinder Client", e); @@ -90,7 +90,7 @@ public class CinderClientImpl extends MsoCommonUtils { 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); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Cinder Client", e); throw new CinderClientException("Error building Cinder Client", e); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java index 57faaac717..698b605be3 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java @@ -74,7 +74,7 @@ public class GlanceClientImpl extends MsoCommonUtils { // list is set to false, otherwise an invalid URL is appended OpenStackRequest<Images> request = glanceClient.images().list(false).queryParam("visibility", visibility) .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", name); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Glance Client", e); throw new GlanceClientException("Error building Glance Client", e); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java index 4ea205a8e1..576784ae3e 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java @@ -98,19 +98,23 @@ public class MsoCommonUtils { */ protected <T> T executeAndRecordOpenstackRequest(OpenStackRequest<T> request) { + return executeAndRecordOpenstackRequest(request, true); + } - String requestType; - if (request.getClass().getEnclosingClass() != null) { - requestType = - request.getClass().getEnclosingClass().getSimpleName() + "." + request.getClass().getSimpleName(); - } else { - requestType = request.getClass().getSimpleName(); - } + /* + * Method to execute an Openstack command and track its execution time. For the metrics log, a category of + * "Openstack" is used along with a sub-category that identifies the specific call (using the real + * openstack-java-sdk classname of the OpenStackRequest<T> parameter). boolean isNoRetry - true if No retry; and + * false if Retry. + */ + protected <T> T executeAndRecordOpenstackRequest(OpenStackRequest<T> request, boolean shouldRetry) { int retryDelay = poConfig.getRetryDelay(); int retryCount = poConfig.getRetryCount(); String retryCodes = poConfig.getRetryCodes(); - + if (!shouldRetry) { + retryCodes = null; + } // Run the actual command. All exceptions will be propagated while (true) { try { 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 c323bb699d..7174bc0e31 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 @@ -220,7 +220,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { boolean backout) throws MsoException { stripMultiCloudInputs(stackInputs); - CreateStackParam createStack = createStackParam(stackName, heatTemplate, stackInputs, timeoutMinutes, environment, files, heatFiles); Stack currentStack = createStack(createStack, cloudSiteId, tenantId); @@ -271,20 +270,14 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } } + protected Stack processCreateStack(String cloudSiteId, String tenantId, int timeoutMinutes, boolean backout, Stack heatStack, CreateStackParam stackCreate, boolean keyPairCleanUp) throws MsoException { - Stack latestStack; + Stack latestStack = null; try { latestStack = pollStackForStatus(timeoutMinutes, heatStack, CREATE_IN_PROGRESS, cloudSiteId, tenantId); } catch (MsoException me) { - if (!backout) { - logger.info("Exception in Create Stack, stack deletion suppressed", me); - } else { - logger.info("Exception in Create Stack, stack deletion will be executed", me); - handleUnknownCreateStackFailure(heatStack, timeoutMinutes, cloudSiteId, tenantId); - } - me.addContext(CREATE_STACK); - throw me; + logger.error("Exception in Create Stack", me); } return postProcessStackCreate(latestStack, backout, timeoutMinutes, keyPairCleanUp, cloudSiteId, tenantId, stackCreate); @@ -292,26 +285,43 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { protected Stack postProcessStackCreate(Stack stack, boolean backout, int timeoutMinutes, boolean cleanUpKeyPair, String cloudSiteId, String tenantId, CreateStackParam stackCreate) throws MsoException { - 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"); + 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); + } } else { - logger.info("Status is not CREATE_COMPLETE, stack deletion will be executed"); - Stack deletedStack = handleUnknownCreateStackFailure(stack, timeoutMinutes, cloudSiteId, tenantId); - throw new StackCreationException("Stack Creation Failed Openstack Status: " + stack.getStackStatus() - + " Status Reason: " + stack.getStackStatusReason() - + " , Rollback of Stack Creation completed with status: " + deletedStack.getStackStatus() - + " Status Reason: " + deletedStack.getStackStatusReason()); + return stack; } - } else { - return stack; } } @@ -1239,7 +1249,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { Heat heatClient = getHeatClient(cloudSiteId, tenantId); OpenStackRequest<Resources> request = heatClient.getResources().listResources(stackName).queryParam("nested_depth", nestedDepth); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } public Events queryStackEvents(String cloudSiteId, String tenantId, String stackName, String stackId, @@ -1247,7 +1257,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { Heat heatClient = getHeatClient(cloudSiteId, tenantId); OpenStackRequest<Events> request = heatClient.getEvents().listEvents(stackName, stackId).queryParam("nested_depth", nestedDepth); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } public Stacks queryStacks(String cloudSiteId, String tenantId, int limit, String marker) @@ -1261,14 +1271,14 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } OpenStackRequest<Stacks> request = heatClient.getStacks().list().queryParam("limit", limit).queryParam("marker", marker); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } public <R> R executeHeatClientRequest(String url, String cloudSiteId, String tenantId, Class<R> returnType) throws MsoException { Heat heatClient = getHeatClient(cloudSiteId, tenantId); OpenStackRequest<R> request = heatClient.get(url, returnType); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } protected void sleep(long time) { 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 6f08afc55f..069c6c7c5b 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 @@ -382,7 +382,7 @@ public class MsoNeutronUtils extends MsoCommonUtils { Authentication credentials = authenticationMethodFactory.getAuthenticationFor(cloudIdentity); OpenStackRequest<Access> request = keystoneTenantClient.tokens().authenticate(credentials).withTenantId(tenantId); - access = executeAndRecordOpenstackRequest(request); + access = executeAndRecordOpenstackRequest(request, true); try { @@ -499,7 +499,7 @@ public class MsoNeutronUtils extends MsoCommonUtils { try { OpenStackRequest<Port> request = neutronClient.ports().show(neutronPortId); - Port port = executeAndRecordOpenstackRequest(request); + Port port = executeAndRecordOpenstackRequest(request, false); return port; } catch (OpenStackResponseException e) { if (e.getStatus() == 404) { diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java index 93745de54a..938a888bbd 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java @@ -75,7 +75,7 @@ public class NeutronClientImpl extends MsoCommonUtils { Quantum neutronClient = getNeutronClient(cloudSiteId, tenantId); OpenStackRequest<Networks> request = neutronClient.networks().list().queryParam("id", id) .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", name); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Neutron Client", e); throw new NeutronClientException("Error building Neutron Client", e); @@ -103,7 +103,7 @@ public class NeutronClientImpl extends MsoCommonUtils { Quantum neutronClient = getNeutronClient(cloudSiteId, tenantId); OpenStackRequest<Subnets> request = neutronClient.subnets().list().queryParam("id", id) .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", name); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Neutron Client", e); throw new NeutronClientException("Error building Neutron Client", e); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java index 6cd79de476..99e8b589b1 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java @@ -78,7 +78,7 @@ public class NovaClientImpl extends MsoCommonUtils { Nova novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Flavors> request = novaClient.flavors().list(false).queryParam("limit", limit).queryParam("marker", marker); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); @@ -103,7 +103,7 @@ public class NovaClientImpl extends MsoCommonUtils { Nova novaClient = getNovaClient(cloudSiteId, tenantId); novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Flavor> request = novaClient.flavors().show(id); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); @@ -128,7 +128,7 @@ public class NovaClientImpl extends MsoCommonUtils { Nova novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<HostAggregates> request = novaClient.aggregates().list().queryParam("limit", limit).queryParam("marker", marker); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); @@ -152,7 +152,7 @@ public class NovaClientImpl extends MsoCommonUtils { try { Nova novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<HostAggregate> request = novaClient.aggregates().showAggregate(id); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); @@ -176,7 +176,7 @@ public class NovaClientImpl extends MsoCommonUtils { try { Nova novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<QuotaSet> request = novaClient.quotaSets().showQuota(tenantId); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); @@ -198,7 +198,7 @@ public class NovaClientImpl extends MsoCommonUtils { try { Nova novaClient = getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Void> request = novaClient.keyPairs().delete(keyPairName); - executeAndRecordOpenstackRequest(request); + executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Nova Client", e); throw new NovaClientException("Error building Nova Client", e); |