From 89cedfabe33390fd4e31bdb918fb2dc98f160b3f Mon Sep 17 00:00:00 2001 From: "Sangalang, Felix" Date: Fri, 14 Jun 2019 09:40:04 -0400 Subject: adapter client will not retry on openstack failure Utilized the original util method with boolean argument. inventory audit: adapter client should not retry on openstack failures. Change-Id: Ibdcec58c662f54ccef887e74f17634baa9df2457 Issue-ID: SO-2016 Signed-off-by: Benjamin, Max (mb388a) --- .../onap/so/openstack/utils/CinderClientImpl.java | 4 ++-- .../onap/so/openstack/utils/GlanceClientImpl.java | 2 +- .../org/onap/so/openstack/utils/MsoCommonUtils.java | 20 ++++++++++++-------- .../org/onap/so/openstack/utils/MsoHeatUtils.java | 8 ++++---- .../org/onap/so/openstack/utils/MsoNeutronUtils.java | 4 ++-- .../onap/so/openstack/utils/NeutronClientImpl.java | 4 ++-- .../org/onap/so/openstack/utils/NovaClientImpl.java | 12 ++++++------ .../onap/so/openstack/utils/MsoCommonUtilsTest.java | 4 +++- 8 files changed, 32 insertions(+), 26 deletions(-) (limited to 'adapters') 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 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 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 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 executeAndRecordOpenstackRequest(OpenStackRequest 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 parameter). boolean isNoRetry - true if No retry; and + * false if Retry. + */ + protected T executeAndRecordOpenstackRequest(OpenStackRequest 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..711fae94ae 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 @@ -1239,7 +1239,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { Heat heatClient = getHeatClient(cloudSiteId, tenantId); OpenStackRequest 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 +1247,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { Heat heatClient = getHeatClient(cloudSiteId, tenantId); OpenStackRequest 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 +1261,14 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } OpenStackRequest request = heatClient.getStacks().list().queryParam("limit", limit).queryParam("marker", marker); - return executeAndRecordOpenstackRequest(request); + return executeAndRecordOpenstackRequest(request, false); } public R executeHeatClientRequest(String url, String cloudSiteId, String tenantId, Class returnType) throws MsoException { Heat heatClient = getHeatClient(cloudSiteId, tenantId); OpenStackRequest 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 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 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 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 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 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 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 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 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 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 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); diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoCommonUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoCommonUtilsTest.java index 5cf7c86522..622ad4f94f 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoCommonUtilsTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoCommonUtilsTest.java @@ -69,6 +69,7 @@ public class MsoCommonUtilsTest extends BaseTest { Mockito.when(openstackRequest.path()).thenReturn("/test"); // TODO:Must try a real connection assertNull(commonUtils.executeAndRecordOpenstackRequest(openstackRequest)); + assertNull(commonUtils.executeAndRecordOpenstackRequest(openstackRequest, true)); } @Test @@ -78,6 +79,7 @@ public class MsoCommonUtilsTest extends BaseTest { doThrow(OpenStackResponseException.class).when(openstackRequest).execute(); commonUtils.executeAndRecordOpenstackRequest(openstackRequest); + commonUtils.executeAndRecordOpenstackRequest(openstackRequest, true); } @Test @@ -86,7 +88,7 @@ public class MsoCommonUtilsTest extends BaseTest { doThrow(OpenStackConnectException.class).when(openstackRequest).execute(); - commonUtils.executeAndRecordOpenstackRequest(openstackRequest); + commonUtils.executeAndRecordOpenstackRequest(openstackRequest, true); } @Test -- cgit 1.2.3-korg