- IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL));
- String identStr = (ident == null) ? null : ident.toString();
-
- // retrieve the optional parameters
- String rebuild_vm = params.get(ProviderAdapter.PROPERTY_REBUILD_VM);
- String targethost_id = params.get(ProviderAdapter.PROPERTY_TARGETHOST_ID);
-
- Context context = null;
- try {
- context = getContext(rc, vm_url, identStr);
- if (context != null) {
-
- server = lookupServer(rc, context, vm.getServerId());
- logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString());
-
- // check target host status
- if (isComputeNodeDown(context, targethost_id)) {
- msg = EELFResourceManager.format(Msg.EVACUATE_SERVER_FAILED, server.getName(), server.getId(),
- "Target host " + targethost_id + " status is not UP/ENABLED");
- logger.error(msg);
- metricsLogger.error(msg);
- throw new RequestFailedException("Evacuate Server", msg, HttpStatus.BAD_REQUEST_400, server);
- }
-
- // save hypervisor name before evacuate
- String hypervisor = server.getHypervisor().getHostName();
-
- evacuateServer(rc, server, targethost_id);
-
- server.refreshAll();
- String hypervisor_after_evacuate = server.getHypervisor().getHostName();
- logger.debug("Hostname before evacuate: " + hypervisor + ", After evacuate: "
- + hypervisor_after_evacuate);
-
- // check hypervisor host name after evacuate. If it is unchanged, the evacuate
- // failed.
- if ((hypervisor != null) && (hypervisor.equals(hypervisor_after_evacuate))) {
- msg = EELFResourceManager.format(Msg.EVACUATE_SERVER_FAILED, server.getName(), server.getId(),
- "Hypervisor host " + hypervisor
- + " after evacuate is the same as before evacuate. Provider (ex. Openstack) recovery actions may be needed.");
- logger.error(msg);
- metricsLogger.error(msg);
- throw new RequestFailedException("Evacuate Server", msg, HttpStatus.INTERNAL_SERVER_ERROR_500,
- server);
-
- }
-
- // check VM status after evacuate
- if (server.getStatus() == Server.Status.ERROR) {
- msg = EELFResourceManager.format(Msg.EVACUATE_SERVER_FAILED, server.getName(), server.getId(),
- "VM is in ERROR state after evacuate. Provider (ex. Openstack) recovery actions may be needed.");
- logger.error(msg);
- metricsLogger.error(msg);
- throw new RequestFailedException("Evacuate Server", msg, HttpStatus.INTERNAL_SERVER_ERROR_500,
- server);
- }
-
- context.close();
- doSuccess(rc);
- ctx.setAttribute("EVACUATE_STATUS", "SUCCESS");
-
- // If a snapshot exists, do a rebuild to apply the latest snapshot to the
- // evacuated server.
- // This is the default behavior unless the optional parameter is set to FALSE.
- if ((rebuild_vm == null) || !(rebuild_vm.equalsIgnoreCase("false"))) {
- List<Image> snapshots = server.getSnapshots();
- if (snapshots == null || snapshots.isEmpty()) {
- logger.debug("No snapshots available - skipping rebuild after evacuate");
- } else if (paImpl != null) {
- logger.debug("Executing a rebuild after evacuate");
- paImpl.rebuildServer(params, ctx);
- // Check error code for rebuild errors. Evacuate had set it to 200 after
- // a successful evacuate. Rebuild updates the error code.
- String rebuildErrorCode =
- ctx.getAttribute(org.onap.appc.Constants.ATTRIBUTE_ERROR_CODE);
- if (rebuildErrorCode != null) {
- try {
- int error_code = Integer.parseInt(rebuildErrorCode);
- if (error_code != HttpStatus.OK_200.getStatusCode()) {
- logger.debug("Rebuild after evacuate failed - error code=" + error_code
- + ", message=" + ctx.getAttribute(
- org.onap.appc.Constants.ATTRIBUTE_ERROR_MESSAGE));
- msg = EELFResourceManager.format(Msg.EVACUATE_SERVER_REBUILD_FAILED,
- server.getName(), hypervisor, hypervisor_after_evacuate,
- ctx.getAttribute(org.onap.appc.Constants.ATTRIBUTE_ERROR_MESSAGE));
- logger.error(msg);
- metricsLogger.error(msg);
- ctx.setAttribute("EVACUATE_STATUS", "ERROR");
- // update error message while keeping the error code the
- // same as before
- doFailure(rc, HttpStatus.getHttpStatus(error_code), msg);
- }
- } catch (NumberFormatException e) {
- // ignore
- }
- }
- }
+ private Server evacuateServerMapNestedFirst(Map<String, String> params, Server server, RequestContext rqstCtx,
+ SvcLogicContext ctx, VMURL vm, String vmUrl) throws APPCException {
+ String msg;
+ Context context;
+ IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL));
+ String identStr = (ident == null) ? null : ident.toString();
+ // retrieve the optional parameters
+ String rebuildVm = params.get(ProviderAdapter.PROPERTY_REBUILD_VM);
+ String targetHostId = params.get(ProviderAdapter.PROPERTY_TARGETHOST_ID);
+ String tenantName = "Unknown";// to be used also in case of exception
+ try {
+ context = getContext(rqstCtx, vmUrl, identStr);
+ if (context != null) {
+ tenantName = context.getTenantName();// this variable also is used in case of exception
+ server = lookupServer(rqstCtx, context, vm.getServerId());
+ logger.debug(Msg.SERVER_FOUND, vmUrl, tenantName, server.getStatus().toString());
+ // check target host status
+ checkHostStatus(server, targetHostId, context);
+ // save hypervisor name before evacuate
+ String hypervisor = server.getHypervisor().getHostName();
+ evacuateServer(rqstCtx, server, targetHostId);
+ server.refreshAll();
+ String hypervisorAfterEvacuate = server.getHypervisor().getHostName();
+ logger.debug(
+ "Hostname before evacuate: " + hypervisor + ", After evacuate: " + hypervisorAfterEvacuate);
+ // check hypervisor host name after evacuate. If it is unchanged, the evacuate
+ // failed.
+ checkHypervisor(server, hypervisor, hypervisorAfterEvacuate);
+ // check VM status after evacuate
+ checkStatus(server);
+ context.close();
+ doSuccess(rqstCtx);
+ ctx.setAttribute(EVACUATE_STATUS, "SUCCESS");
+ // If a snapshot exists, do a rebuild to apply the latest snapshot to the
+ // evacuated server.
+ // This is the default behavior unless the optional parameter is set to FALSE.
+ if (rebuildVm == null || !"false".equalsIgnoreCase(rebuildVm)) {
+ List<Image> snapshots = server.getSnapshots();
+ if (snapshots == null || snapshots.isEmpty()) {
+ logger.debug("No snapshots available - skipping rebuild after evacuate");
+ } else if (paImpl != null) {
+ logger.debug("Executing a rebuild after evacuate");
+ paImpl.rebuildServer(params, ctx);
+ // Check error code for rebuild errors. Evacuate had set it to 200 after
+ // a successful evacuate. Rebuild updates the error code.
+ evacuateServerMapNestedSecond(server, rqstCtx, ctx, hypervisor, hypervisorAfterEvacuate);