From dda9213466af575725b3e0b734c1fe70b1e2944f Mon Sep 17 00:00:00 2001 From: Lathishbabu Ganesan Date: Mon, 28 May 2018 11:07:44 +0100 Subject: Unit test cases for iaas impl package Change-Id: Iac6167dca83413b7533cb65a73775a616866589c Issue-ID: APPC-436 Signed-off-by: Lathishbabu Ganesan --- .../adapter/iaas/impl/ProviderAdapterImpl.java | 3 +- .../adapter/iaas/impl/ServiceCatalogFactory.java | 16 +++----- .../appc/adapter/iaas/impl/ServiceCatalogV3.java | 45 ++++++++++++---------- .../onap/appc/adapter/iaas/impl/TenantCache.java | 25 ++++++------ 4 files changed, 44 insertions(+), 45 deletions(-) (limited to 'appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main') diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ProviderAdapterImpl.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ProviderAdapterImpl.java index 79d7aa569..36191dd5a 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ProviderAdapterImpl.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ProviderAdapterImpl.java @@ -68,7 +68,7 @@ public class ProviderAdapterImpl implements ProviderAdapter { /** * reference to operation factory */ - ProviderOperationFactory factory = ProviderOperationFactory.getInstance(); + private ProviderOperationFactory factory; /** * A cache of providers that are predefined. */ @@ -257,6 +257,7 @@ public class ProviderAdapterImpl implements ProviderAdapter { * provider2.identity=http://provider2:5000/v2.0 provider2.tenant1.name=someName * provider2.tenant1.userid=someUser provider2.tenant1.password=somePassword

*/ + factory = ProviderOperationFactory.getInstance(); providerCache = new HashMap<>(); Properties properties = configuration.getProperties(); List providers = StructuredPropertyHelper.getStructuredProperties(properties, Property.PROVIDER); diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogFactory.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogFactory.java index a4be23349..74d87571b 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogFactory.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogFactory.java @@ -51,18 +51,12 @@ public class ServiceCatalogFactory { return null; } String version = idUrl.getVersion(); - if(version == null){ - logger.error("Invalid Identity URL check configuration"); - return null; - } String prefix = version.split("\\.")[0]; - if (prefix != null) { - switch (prefix) { - case "v2": - return new ServiceCatalogV2(url, projectIdentifier, principal, credential, properties); - case "v3": - return new ServiceCatalogV3(url, projectIdentifier, principal, credential, domain, properties); - } + if("v2".equals(prefix)){ + return new ServiceCatalogV2(url, projectIdentifier, principal, credential, properties); + } + else if("v3".equals(prefix)){ + return new ServiceCatalogV3(url, projectIdentifier, principal, credential, domain, properties); } return null; } diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java index 1e057d147..4773603c3 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/impl/ServiceCatalogV3.java @@ -23,13 +23,25 @@ package org.onap.appc.adapter.iaas.impl; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import com.att.cdp.exceptions.ContextConnectionException; import com.att.cdp.exceptions.ZoneException; import com.att.cdp.openstack.util.ExceptionMapper; import com.att.cdp.pal.util.Time; import com.att.cdp.zones.ContextFactory; import com.att.cdp.zones.spi.RequestState; -import com.google.common.collect.Lists; import com.woorea.openstack.base.client.OpenStackBaseException; import com.woorea.openstack.base.client.OpenStackClientConnector; import com.woorea.openstack.base.client.OpenStackSimpleTokenProvider; @@ -42,19 +54,6 @@ import com.woorea.openstack.keystone.v3.model.Token; import com.woorea.openstack.keystone.v3.model.Token.Project; import com.woorea.openstack.keystone.v3.model.Token.Service; import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * This class is used to capture and cache the service catalog for a specific OpenStack provider. @@ -225,13 +224,7 @@ public class ServiceCatalogV3 extends ServiceCatalog { */ @Override public String getProjectName() { - Lock readLock = rwLock.readLock(); - readLock.lock(); - try { - return project.getName(); - } finally { - readLock.unlock(); - } + return getProject().getName(); } /** @@ -403,4 +396,14 @@ public class ServiceCatalogV3 extends ServiceCatalog { } return now.getTime(); } + + public Project getProject() { + Lock readLock = rwLock.readLock(); + readLock.lock(); + try { + return project; + } finally { + readLock.unlock(); + } + } } \ No newline at end of file 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 c99889ce4..29b9cd314 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 @@ -23,13 +23,6 @@ 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; @@ -42,6 +35,13 @@ 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; /** * This class maintains a cache of tenants within a specific provider. @@ -121,7 +121,6 @@ public class TenantCache implements Allocator, Destructor { configuration = ConfigurationFactory.getConfiguration(); logger = EELFManager.getInstance().getLogger(getClass()); this.provider = provider; - configuration = ConfigurationFactory.getConfiguration(); } /** @@ -157,12 +156,10 @@ public class TenantCache implements Allocator, Destructor { int max = configuration.getIntegerProperty(Constants.PROPERTY_MAX_POOL_SIZE); int delay = configuration.getIntegerProperty(Constants.PROPERTY_RETRY_DELAY); int limit = configuration.getIntegerProperty(Constants.PROPERTY_RETRY_LIMIT); - String url = provider.getIdentityURL(); String tenant = tenantName == null ? tenantId : tenantName; Properties properties = configuration.getProperties(); - catalog = ServiceCatalogFactory.getServiceCatalog(url, tenant, userid, password, domain, properties); - + catalog = getServiceCatalogFactory(url, tenant, properties); if (catalog == null) { logger.error(Msg.IAAS_UNSUPPORTED_IDENTITY_SERVICE, url); return; @@ -195,12 +192,16 @@ public class TenantCache implements Allocator, Destructor { } } + public ServiceCatalog getServiceCatalogFactory(String url, String tenant, Properties properties) { + return ServiceCatalogFactory.getServiceCatalog(url, tenant, userid, password, domain, properties); + } + private void createPools(int min, int max, String url, Properties properties) { for (String region : catalog.getRegions()) { try { Pool pool = new Pool<>(min, max); pool.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, url); - pool.setProperty(ContextFactory.PROPERTY_TENANT, tenantName); + pool.setProperty(ContextFactory.PROPERTY_TENANT, getTenantName()); pool.setProperty(ContextFactory.PROPERTY_CLIENT_CONNECTOR_CLASS, CLIENT_CONNECTOR_CLASS); pool.setProperty(ContextFactory.PROPERTY_RETRY_DELAY, configuration.getProperty(Constants.PROPERTY_RETRY_DELAY)); -- cgit 1.2.3-korg