\r
try {\r
access = authenticate.execute();\r
+ //Ensure that access or the access token is not null before\r
+ //checking local expiration or accessing the tenant information\r
+ if (access == null || access.getToken() == null) {\r
+ throw new NullPointerException("The access key used to access the provider or access token is null." +\r
+ "Failed to init ServiceCatalogV2");\r
+ }\r
expiresLocal = getLocalExpiration(access);\r
tenant = access.getToken().getTenant();\r
tokenProvider = new OpenStackSimpleTokenProvider(access.getToken().getId());\r
*/\r
private static long getLocalExpiration(Access accessKey) {\r
Date now = Time.getCurrentUTCDate();\r
- if (accessKey != null && accessKey.getToken() != null) {\r
- Calendar issued = accessKey.getToken().getIssued_at();\r
- Calendar expires = accessKey.getToken().getExpires();\r
- if (issued != null && expires != null) {\r
- long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();\r
- return now.getTime() + tokenLife;\r
- }\r
+ Calendar issued = accessKey.getToken().getIssued_at();\r
+ Calendar expires = accessKey.getToken().getExpires();\r
+ if (issued != null && expires != null) {\r
+ long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();\r
+ return now.getTime() + tokenLife;\r
}\r
return now.getTime();\r
}\r
import com.woorea.openstack.keystone.v3.model.Token.Service;\r
import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint;\r
\r
+import javax.validation.constraints.Null;\r
+\r
/**\r
* This class is used to capture and cache the service catalog for a specific OpenStack provider.\r
* <p>\r
\r
try {\r
token = authenticate.execute();\r
+ // Ensure that token is not null before accessing\r
+ // local expiration or the internal details of token\r
+ if (token == null) {\r
+ throw new NullPointerException("Access token is null. Failed to init ServiceCatalogV3");\r
+ }\r
expiresLocal = getLocalExpiration(token);\r
project = token.getProject();\r
tokenProvider = new OpenStackSimpleTokenProvider(token.getId());\r
*/\r
private static long getLocalExpiration(Token accessToken) {\r
Date now = Time.getCurrentUTCDate();\r
- if (accessToken != null) {\r
- Calendar issued = accessToken.getIssuedAt();\r
- Calendar expires = accessToken.getExpiresAt();\r
- if (issued != null && expires != null) {\r
- long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();\r
- return now.getTime() + tokenLife;\r
- }\r
+ Calendar issued = accessToken.getIssuedAt();\r
+ Calendar expires = accessToken.getExpiresAt();\r
+ if (issued != null && expires != null) {\r
+ long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis();\r
+ return now.getTime() + tokenLife;\r
}\r
return now.getTime();\r
}\r
log.debug("Caught Exception", e);
log.info("Caught exception", e);
log.info("APPC-MESSAGE:" + e.getMessage());
- dbResourceManager.cleanUp();
-
} finally {
- dbResourceManager.cleanUp();
+ //When dbResourceManager is not created then no need to cleanup
+ if (dbResourceManager != null) {
+ dbResourceManager.cleanUp();
+ }
}
}
if(dependencyModel == null){
logger.debug("Dependency model not found in cache, creating strategy for reading it");
DependencyType strategy = getStrategy(dependencyType);
+ // Throw exception if strategy could not be created because it is required
+ // to retrieve the vnfc dependency model later
+ if (strategy == null) {
+ throw new NullPointerException("Strategy is null. Failed to retrieve Vnfc Dependency Model");
+ }
dependencyModel = strategy.getVnfcDependencyModel(modelIdentifier);
}
if (logger.isTraceEnabled()) {
if (logger.isDebugEnabled())
logger.debug("Metric getting initialized");
MetricService metricService = getMetricservice();
+ // Check for the metric service created before trying to create registry using
+ // the metricService object
+ if (metricService == null) {
+ // Cannot find service reference for org.onap.appc.metricservice.MetricService
+ throw new NullPointerException("org.onap.appc.metricservice.MetricService is null. " +
+ "Failed to init Metric");
+ }
metricRegistry = metricService.createRegistry("APPC");
DispatchingFuntionMetric dispatchingFuntionMetric = metricRegistry.metricBuilderFactory().
dispatchingFunctionCounterBuilder().