aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main
diff options
context:
space:
mode:
authorTaka <tc012c@att.com>2018-02-11 14:31:37 -0500
committerPatrick Brady <pb071s@att.com>2018-02-18 21:31:24 +0000
commit39b6b136b115e4ee15a599546b23cd9a68f7b673 (patch)
tree40069bd1dd4c5473ead4c6bdbf06c9ba9219e0a9 /appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main
parent43ea61ecad28fb683f31fc06234a3ed03e64dd39 (diff)
refactor LookupServer for nesting try
Change-Id: Id27025cd6d4f5a4f8ba9653b656d263585edb24e Issue-ID: APPC-599 Signed-off-by: Taka <tc012c@att.com>
Diffstat (limited to 'appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main')
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/LookupServer.java80
1 files changed, 43 insertions, 37 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/LookupServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/LookupServer.java
index 924322d1f..dd58b6a5d 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/LookupServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/LookupServer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -59,51 +59,22 @@ public class LookupServer extends ProviderServerOperation {
RequestContext rc = new RequestContext(ctx);
rc.isAlive(); // should we test the return and fail if false?
- String vm_url = null;
+ String vmUrl = null;
try {
- // process vm_url
+ // process vmUrl
validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
ProviderAdapter.PROPERTY_PROVIDER_NAME);
String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
- vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
- VMURL vm = VMURL.parseURL(vm_url);
- if (validateVM(rc, appName, vm_url, vm)) {
+ vmUrl = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
+ VMURL vm = VMURL.parseURL(vmUrl);
+ if (validateVM(rc, appName, vmUrl, vm)) {
return null;
}
-
- // use try with resource to ensure context is closed (returned to pool)
- try (Context context = resolveContext(rc, params, appName, vm_url)) {
- // resloveContext & getContext call doFailure and log errors before returning null
- if (context != null) {
- rc.reset();
- server = lookupServer(rc, context, vm.getServerId());
- logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString());
- ctx.setAttribute("serverFound", "success");
- String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "LookupServer", vm_url);
- ctx.setAttribute(org.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
- doSuccess(rc);
- }
- } catch (ZoneException e) {
- // server not found
- String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url);
- logger.error(msg);
- doFailure(rc, HttpStatus.NOT_FOUND_404, msg);
- ctx.setAttribute("serverFound", "failure");
- } catch (IOException e) {
- // exception closing context
- String msg = EELFResourceManager.format(Msg.CLOSE_CONTEXT_FAILED, e, vm_url);
- logger.error(msg);
- } catch (Exception e1) {
- String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, e1,
- e1.getClass().getSimpleName(), Operation.LOOKUP_SERVICE.toString(), vm_url, "Unknown");
- logger.error(msg, e1);
- doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
- }
-
+ server = lookupServerNested(params, server, rc, ctx, appName, vm, vmUrl);
} catch (RequestFailedException e) {
// parameters not valid, unable to connect to provider
- String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url);
+ String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vmUrl);
logger.error(msg);
doFailure(rc, HttpStatus.NOT_FOUND_404, msg);
ctx.setAttribute("serverFound", "failure");
@@ -111,6 +82,41 @@ public class LookupServer extends ProviderServerOperation {
return server;
}
+ private Server lookupServerNested(Map<String, String> params, Server server, RequestContext rqstCtx, SvcLogicContext ctx,
+ String appName, VMURL vm, String vmUrl)
+ throws APPCException {
+
+ // use try with resource to ensure context is closed (returned to pool)
+ try (Context context = resolveContext(rqstCtx, params, appName, vmUrl)) {
+ // resloveContext & getContext call doFailure and log errors before returning null
+ if (context != null) {
+ rqstCtx.reset();
+ server = lookupServer(rqstCtx, context, vm.getServerId());
+ logger.debug(Msg.SERVER_FOUND, vmUrl, context.getTenantName(), server.getStatus().toString());
+ ctx.setAttribute("serverFound", "success");
+ String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "LookupServer", vmUrl);
+ ctx.setAttribute(org.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
+ doSuccess(rqstCtx);
+ }
+ } catch (ZoneException e) {
+ // server not found
+ String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vmUrl);
+ logger.error(msg);
+ doFailure(rqstCtx, HttpStatus.NOT_FOUND_404, msg);
+ ctx.setAttribute("serverFound", "failure");
+ } catch (IOException e) {
+ // exception closing context
+ String msg = EELFResourceManager.format(Msg.CLOSE_CONTEXT_FAILED, e, vmUrl);
+ logger.error(msg);
+ } catch (Exception e1) {
+ String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, e1,
+ e1.getClass().getSimpleName(), Operation.LOOKUP_SERVICE.toString(), vmUrl, "Unknown");
+ logger.error(msg, e1);
+ doFailure(rqstCtx, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
+ }
+ return server;
+ }
+
@Override
protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
throws APPCException {