diff options
author | 2018-01-31 14:35:09 +0100 | |
---|---|---|
committer | 2018-02-02 15:08:58 +0000 | |
commit | 72931ce2fe5005f7855f1e2ce35fc67d6b10f4dc (patch) | |
tree | 896bcbb70eec28b3b4c24b96aa91ad5e8832500b /appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java | |
parent | 36ca66b20d827cac5a6a2199e31369f6ad9e6a9c (diff) |
Extraction of nested try catch in migrateServer
Try catch block placed in new private method conductServerMigration, UT for class added.
Issue-ID: APPC-557
Change-Id: I7f968dbc87ee3be4125da6a8a3e201af99aa420e
Signed-off-by: kjaniak <kornel.janiak@nokia.com>
Diffstat (limited to 'appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java')
-rw-r--r-- | appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/MigrateServer.java | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/MigrateServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/MigrateServer.java index e4ec73470..b93511ae2 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/MigrateServer.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/MigrateServer.java @@ -166,7 +166,6 @@ public class MigrateServer extends ProviderServerOperation { setTimeForMetricsLogger(); - String msg; try { validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL, ProviderAdapter.PROPERTY_PROVIDER_NAME); @@ -174,29 +173,15 @@ public class MigrateServer extends ProviderServerOperation { String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME); VMURL vm = VMURL.parseURL(vm_url); + if (validateVM(rc, appName, vm_url, vm)) return null; IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL)); String identStr = (ident == null) ? null : ident.toString(); - Context context = getContext(rc, vm_url, identStr); - try { - if (context != null) { - server = lookupServer(rc, context, vm.getServerId()); - logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString()); - migrateServer(rc, server, ctx); - server.refreshStatus(); - context.close(); - doSuccess(rc); - } - } catch (IOException | ZoneException e1) { - msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, e1, e1.getClass().getSimpleName(), - MIGRATE_SERVICE.toString(), vm_url, context.getTenantName()); - logger.error(msg, e1); - metricsLogger.error(msg); - doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg); - } + server = conductServerMigration(rc, vm_url, identStr, ctx); + } catch (RequestFailedException e) { doFailure(rc, e.getStatus(), e.getMessage()); } @@ -232,4 +217,29 @@ public class MigrateServer extends ProviderServerOperation { MDC.put("TargetServiceName", "migrate server"); MDC.put("ClassName", "org.onap.appc.adapter.iaas.provider.operation.impl.MigrateServer"); } + + private Server conductServerMigration(RequestContext rc, String vm_url, String identStr, SvcLogicContext ctx) throws RequestFailedException { + String msg; + Context context = getContext(rc, vm_url, identStr); + VMURL vm = VMURL.parseURL(vm_url); + Server server = null; + + try { + if (context != null) { + server = lookupServer(rc, context, vm.getServerId()); + logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString()); + migrateServer(rc, server, ctx); + server.refreshStatus(); + context.close(); + doSuccess(rc); + } + } catch (IOException | ZoneException e1) { + msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, e1, e1.getClass().getSimpleName(), + MIGRATE_SERVICE.toString(), vm_url, context.getTenantName()); + logger.error(msg, e1); + metricsLogger.error(msg); + doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg); + } + return server; + } } |