summaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-13 10:01:47 -0500
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-13 10:02:04 -0500
commit887766a34dd989d3fe0a97a8b32d51903813e21a (patch)
treede5847c903cbba9b0ed8f2e8cbbc6d5a055a6ff0 /adapters/mso-adapter-utils
parent641d9e6b68a964dc69dbec7c63f82e73b61433e2 (diff)
Remove un-needed cacheing layer for OS Clients
Remove un-needed cacheing layer for OS Clients Change-Id: I7fbb6e23a3c34f65286202ec4dad1fb051991cf0 Issue-ID: SO-1500 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'adapters/mso-adapter-utils')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java47
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoKeystoneUtils.java54
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java48
3 files changed, 2 insertions, 147 deletions
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 14aee2f4f2..20498cb694 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
@@ -103,13 +103,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
protected static final String CREATE_STACK = "CreateStack";
- // Cache Heat Clients statically. Since there is just one MSO user, there is no
- // benefit to re-authentication on every request (or across different flows). The
- // token will be used until it expires.
- //
- // The cache key is "tenantId:cloudId"
- private static Map <String, HeatCacheEntry> heatClientCache = new HashMap <> ();
-
// Fetch cloud configuration each time (may be cached in CloudConfig class)
@Autowired
protected CloudConfig cloudConfig;
@@ -859,19 +852,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
String cloudId = cloudSite.getId();
// For DCP/LCP, the region should be the cloudId.
String region = cloudSite.getRegionId ();
-
- // Check first in the cache of previously authorized clients
- String cacheKey = cloudId + ":" + tenantId;
- if (heatClientCache.containsKey (cacheKey)) {
- if (!heatClientCache.get (cacheKey).isExpired ()) {
- LOGGER.debug ("Using Cached HEAT Client for " + cacheKey);
- return heatClientCache.get (cacheKey).getHeatClient ();
- } else {
- // Token is expired. Remove it from cache.
- heatClientCache.remove (cacheKey);
- LOGGER.debug ("Expired Cached HEAT Client for " + cacheKey);
- }
- }
// Obtain an MSO token for the tenant
CloudIdentity cloudIdentity = cloudSite.getIdentityService();
@@ -946,38 +926,11 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
// Catch-all
throw runtimeExceptionToMsoException (e, TOKEN_AUTH);
}
-
Heat heatClient = new Heat (heatUrl);
heatClient.token (tokenId);
-
- heatClientCache.put (cacheKey,
- new HeatCacheEntry (heatUrl,
- tokenId,
- expiration));
- LOGGER.debug ("Caching HEAT Client for " + cacheKey);
-
return heatClient;
}
- /**
- * Forcibly expire a HEAT client from the cache. This call is for use by
- * the KeystoneClient in case where a tenant is deleted. In that case,
- * all cached credentials must be purged so that fresh authentication is
- * done if a similarly named tenant is re-created.
- * <p>
- * Note: This is probably only applicable to dev/test environments where
- * the same Tenant Name is repeatedly used for creation/deletion.
- * <p>
- *
- */
- public void expireHeatClient (String tenantId, String cloudId) {
- String cacheKey = cloudId + ":" + tenantId;
- if (heatClientCache.containsKey (cacheKey)) {
- heatClientCache.remove (cacheKey);
- LOGGER.debug ("Deleted Cached HEAT Client for " + cacheKey);
- }
- }
-
/*
* Query for a Heat Stack. This function is needed in several places, so
* a common method is useful. This method takes an authenticated Heat Client
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoKeystoneUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoKeystoneUtils.java
index 3936ae6496..0bd2a3931f 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoKeystoneUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoKeystoneUtils.java
@@ -59,12 +59,6 @@ import com.woorea.openstack.keystone.utils.KeystoneUtils;
@Component
public class MsoKeystoneUtils extends MsoTenantUtils {
- // Cache the Keystone Clients statically. Since there is just one MSO user, there is no
- // benefit to re-authentication on every request (or across different flows). The
- // token will be used until it expires.
- //
- // The cache key is "cloudId"
- private static Map <String, KeystoneCacheEntry> adminClientCache = new HashMap<>();
private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, MsoKeystoneUtils.class);
@@ -316,10 +310,6 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
OpenStackRequest <Void> request = keystoneAdminClient.tenants ().delete (tenant.getId ());
executeAndRecordOpenstackRequest (request);
LOGGER.debug ("Deleted Tenant " + tenant.getId () + " (" + tenant.getName () + ")");
-
- // Clear any cached clients. Not really needed, ID will not be reused.
- msoHeatUtils.expireHeatClient (tenant.getId (), cloudSiteId);
- msoNeutronUtils.expireNeutronClient (tenant.getId (), cloudSiteId);
} catch (OpenStackBaseException e) {
// Convert Keystone OpenStackResponseException to MsoOpenstackException
throw keystoneErrorToMsoException (e, "Delete Tenant");
@@ -369,9 +359,6 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
LOGGER.debug ("Deleted Tenant " + tenant.getId () + " (" + tenant.getName () + ")");
- // Clear any cached clients. Not really needed, ID will not be reused.
- msoHeatUtils.expireHeatClient (tenant.getId (), cloudSiteId);
- msoNeutronUtils.expireNeutronClient (tenant.getId (), cloudSiteId);
} catch (OpenStackBaseException e) {
// Note: It doesn't seem to matter if tenant doesn't exist, no exception is thrown.
// Convert Keystone OpenStackResponseException to MsoOpenstackException
@@ -407,16 +394,6 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
String adminTenantName = cloudIdentity.getAdminTenant ();
String region = cloudSite.getRegionId ();
- // Check first in the cache of previously authorized clients
- KeystoneCacheEntry entry = adminClientCache.get (cloudId);
- if (entry != null) {
- if (!entry.isExpired ()) {
- return entry.getKeystoneClient ();
- } else {
- // Token is expired. Remove it from cache.
- adminClientCache.remove (cloudId);
- }
- }
MsoTenantUtils tenantUtils = tenantUtilsFactory.getTenantUtilsByServerType(cloudIdentity.getIdentityServerType());
final String keystoneUrl = tenantUtils.getKeystoneUrl(region, cloudIdentity);
Keystone keystone = new Keystone(keystoneUrl);
@@ -462,11 +439,6 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
// Note: this doesn't go back to Openstack, it's just a local object.
keystone = new Keystone (adminUrl);
keystone.token (token);
-
- // Cache to avoid re-authentication for every call.
- KeystoneCacheEntry cacheEntry = new KeystoneCacheEntry (adminUrl, token, access.getToken ().getExpires ());
- adminClientCache.put (cloudId, cacheEntry);
-
return keystone;
}
@@ -636,32 +608,6 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
return null;
}
- private static class KeystoneCacheEntry implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private String keystoneUrl;
- private String token;
- private Calendar expires;
-
- public KeystoneCacheEntry (String url, String token, Calendar expires) {
- this.keystoneUrl = url;
- this.token = token;
- this.expires = expires;
- }
-
- public Keystone getKeystoneClient () {
- Keystone keystone = new Keystone (keystoneUrl);
- keystone.token (token);
- return keystone;
- }
-
- public boolean isExpired () {
- // adding arbitrary guard timer of 5 minutes
- return expires == null || System.currentTimeMillis() > (expires.getTimeInMillis() - 1800000);
- }
- }
-
@Override
public String getKeystoneUrl(String regionId, CloudIdentity cloudIdentity) throws MsoException {
return cloudIdentity.getIdentityUrl();
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 7b82ad62ff..785e8606d3 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
@@ -67,12 +67,6 @@ import com.woorea.openstack.quantum.model.Segment;
@Component
public class MsoNeutronUtils extends MsoCommonUtils
{
- // Cache Neutron Clients statically. Since there is just one MSO user, there is no
- // benefit to re-authentication on every request (or across different flows). The
- // token will be used until it expires.
- //
- // The cache key is "tenantId:cloudId"
- private static Map<String,NeutronCacheEntry> neutronClientCache = new HashMap<>();
// Fetch cloud configuration each time (may be cached in CloudConfig class)
@Autowired
@@ -364,24 +358,8 @@ public class MsoNeutronUtils extends MsoCommonUtils
private Quantum getNeutronClient(CloudSite cloudSite, String tenantId) throws MsoException
{
String cloudId = cloudSite.getId();
- String region = cloudSite.getRegionId();
-
- // Check first in the cache of previously authorized clients
- String cacheKey = cloudId + ":" + tenantId;
- if (neutronClientCache.containsKey(cacheKey)) {
- if (! neutronClientCache.get(cacheKey).isExpired()) {
- LOGGER.debug ("Using Cached HEAT Client for " + cacheKey);
- NeutronCacheEntry cacheEntry = neutronClientCache.get(cacheKey);
- Quantum neutronClient = new Quantum(cacheEntry.getNeutronUrl());
- neutronClient.token(cacheEntry.getToken());
- return neutronClient;
- }
- else {
- // Token is expired. Remove it from cache.
- neutronClientCache.remove(cacheKey);
- LOGGER.debug ("Expired Cached Neutron Client for " + cacheKey);
- }
- }
+ String region = cloudSite.getRegionId();
+
// Obtain an MSO token for the tenant from the identity service
CloudIdentity cloudIdentity = cloudSite.getIdentityService();
@@ -454,31 +432,9 @@ public class MsoNeutronUtils extends MsoCommonUtils
Quantum neutronClient = new Quantum(neutronUrl);
neutronClient.token(tokenId);
-
- neutronClientCache.put(cacheKey, new NeutronCacheEntry(neutronUrl, tokenId, expiration));
- LOGGER.debug ("Caching Neutron Client for " + cacheKey);
-
return neutronClient;
}
- /**
- * Forcibly expire a Neutron client from the cache. This call is for use by
- * the KeystoneClient in case where a tenant is deleted. In that case,
- * all cached credentials must be purged so that fresh authentication is
- * done on subsequent calls.
- * <p>
- * @param tenantName
- * @param cloudId
- */
- public void expireNeutronClient (String tenantId, String cloudId) {
- String cacheKey = cloudId + ":" + tenantId;
- if (neutronClientCache.containsKey(cacheKey)) {
- neutronClientCache.remove(cacheKey);
- LOGGER.debug ("Deleted Cached Neutron Client for " + cacheKey);
- }
- }
-
-
/*
* Find a tenant (or query its existence) by its Name or Id. Check first against the
* ID. If that fails, then try by name.