summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-02-06 18:11:49 +0100
committerPatrick Brady <pb071s@att.com>2018-02-07 19:30:38 +0000
commit5ffecb09b5fa08ab173290f668f2763be28af924 (patch)
tree4b5e8c6ec8f742d0408707aa9bda56c3301a4eb8
parent2cc9e54313952faad21804b9eceff0c3aef0de67 (diff)
TenantCache sonar fixes
Change-Id: I8c95c1913edb325faac49f416d16f42683d8fa7e Issue-ID: APPC-574 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/TenantCache.java95
1 files changed, 46 insertions, 49 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/TenantCache.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/TenantCache.java
index 3f5950332..ac244b167 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/TenantCache.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/TenantCache.java
@@ -24,6 +24,13 @@
package org.onap.appc.adapter.iaas.impl;
+import com.att.cdp.exceptions.ContextConnectionException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.Context;
+import com.att.cdp.zones.ContextFactory;
+import com.att.cdp.zones.Provider;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -36,14 +43,6 @@ import org.onap.appc.pool.Allocator;
import org.onap.appc.pool.Destructor;
import org.onap.appc.pool.Pool;
import org.onap.appc.pool.PoolSpecificationException;
-import com.att.cdp.exceptions.ContextConnectionException;
-import com.att.cdp.exceptions.ZoneException;
-import com.att.cdp.zones.Context;
-import com.att.cdp.zones.ContextFactory;
-import com.att.cdp.zones.Provider;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-// import com.sun.jersey.api.client.ClientHandlerException;
/**
* This class maintains a cache of tenants within a specific provider.
@@ -58,8 +57,6 @@ public class TenantCache implements Allocator<Context>, Destructor<Context> {
public static final String POOL_PROVIDER_NAME = "pool.provider.name";
public static final String POOL_TENANT_NAME = "pool.tenant.name";
- // public static final String CLIENT_CONNECTOR_CLASS =
- // "com.woorea.openstack.connector.JerseyConnector";
public static final String CLIENT_CONNECTOR_CLASS = "com.woorea.openstack.connector.JaxRs20Connector";
/**
* The domain to use to authenticate
@@ -178,48 +175,18 @@ public class TenantCache implements Allocator<Context>, Destructor<Context> {
catalog.init();
tenantId = catalog.getProjectId();
tenantName = catalog.getProjectName();
-
- for (String region : catalog.getRegions()) {
- try {
- Pool<Context> pool = new Pool<>(min, max);
- pool.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, url);
- pool.setProperty(ContextFactory.PROPERTY_TENANT, tenantName);
- pool.setProperty(ContextFactory.PROPERTY_CLIENT_CONNECTOR_CLASS, CLIENT_CONNECTOR_CLASS);
- pool.setProperty(ContextFactory.PROPERTY_RETRY_DELAY,
- configuration.getProperty(Constants.PROPERTY_RETRY_DELAY));
- pool.setProperty(ContextFactory.PROPERTY_RETRY_LIMIT,
- configuration.getProperty(Constants.PROPERTY_RETRY_LIMIT));
- pool.setProperty(ContextFactory.PROPERTY_REGION, region);
- if (properties.getProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS) != null) {
- pool.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS,
- properties.getProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS));
- }
- pool.setAllocator(this);
- pool.setDestructor(this);
- pools.put(region, pool);
- logger.debug(String.format("Put pool for region %s", region));
- } catch (PoolSpecificationException e) {
- logger.error("Error creating pool", e);
- e.printStackTrace();
- }
- }
+ createPools(min, max, url, properties);
initialized = true;
break;
} catch (ContextConnectionException e) {
- attempt++;
- if (attempt <= limit) {
+ if (++attempt <= limit) {
logger.error(Msg.CONNECTION_FAILED_RETRY, provider.getProviderName(), url, tenantName, tenantId,
e.getMessage(), Integer.toString(delay), Integer.toString(attempt),
Integer.toString(limit));
-
- try {
- Thread.sleep(delay * 1000L);
- } catch (InterruptedException ie) {
- // ignore
- }
+ sleep(delay);
}
} catch (ZoneException e) {
- logger.error(e.getMessage());
+ logger.error("An error occurred when initializing cache", e);
break;
}
}
@@ -229,6 +196,40 @@ public class TenantCache implements Allocator<Context>, Destructor<Context> {
}
}
+ private void createPools(int min, int max, String url, Properties properties) {
+ for (String region : catalog.getRegions()) {
+ try {
+ Pool<Context> pool = new Pool<>(min, max);
+ pool.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, url);
+ pool.setProperty(ContextFactory.PROPERTY_TENANT, tenantName);
+ pool.setProperty(ContextFactory.PROPERTY_CLIENT_CONNECTOR_CLASS, CLIENT_CONNECTOR_CLASS);
+ pool.setProperty(ContextFactory.PROPERTY_RETRY_DELAY,
+ configuration.getProperty(Constants.PROPERTY_RETRY_DELAY));
+ pool.setProperty(ContextFactory.PROPERTY_RETRY_LIMIT,
+ configuration.getProperty(Constants.PROPERTY_RETRY_LIMIT));
+ pool.setProperty(ContextFactory.PROPERTY_REGION, region);
+ if (properties.getProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS) != null) {
+ pool.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS,
+ properties.getProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS));
+ }
+ pool.setAllocator(this);
+ pool.setDestructor(this);
+ pools.put(region, pool);
+ logger.debug(String.format("Put pool for region %s", region));
+ } catch (PoolSpecificationException e) {
+ logger.error("Error creating pool", e);
+ }
+ }
+ }
+
+ private void sleep(int delay) {
+ try {
+ Thread.sleep(delay * 1000L);
+ } catch (InterruptedException ie) {
+ // ignore
+ }
+ }
+
/**
* This method accepts a fully qualified compute node URL and uses that to determine which region of the provider
* hosts that compute node.
@@ -344,15 +345,11 @@ public class TenantCache implements Allocator<Context>, Destructor<Context> {
Class<? extends Provider> providerClass;
try {
providerClass = (Class<? extends Provider>) Class.forName("com.att.cdp.openstack.OpenStackProvider");
- // String providerType = provider.getProviderType();
-
- // Context context = ContextFactory.getContext(providerType, pool.getProperties());
Context context = ContextFactory.getContext(providerClass, pool.getProperties());
context.login(userid, password);
return context;
} catch (IllegalStateException | IllegalArgumentException | ZoneException | ClassNotFoundException e) {
logger.debug("Failed to allocate context for pool", e);
- e.printStackTrace();
}
return null;
}
@@ -365,7 +362,7 @@ public class TenantCache implements Allocator<Context>, Destructor<Context> {
try {
context.close();
} catch (IOException e) {
- e.printStackTrace();
+ logger.error("An error occurred when destroying cache", e);
}
}