summaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-iaas-adapter
diff options
context:
space:
mode:
authorbeili.zhou <beili.zhou@amdocs.com>2017-08-29 18:06:38 -0400
committerbeili.zhou <beili.zhou@amdocs.com>2017-08-29 18:06:45 -0400
commit63a1371d5b0fa6b2a500a38f88e7519d989d5b56 (patch)
tree277f03e1dc57ae4821ef4883cb754d29f7ad24ac /appc-adapters/appc-iaas-adapter
parent102df7f1a0024607c54038163e4ac7e0058042f6 (diff)
Remove duplicate code
Create a method for duplicated code to reduce code duplication in IAAS adapter provider operation. Issue-Id: APPC-175 Change-Id: Idfbfc7ffad433d0e7469b214e5b09d0dfd5dd7d2 Signed-off-by: beili.zhou <beili.zhou@amdocs.com>
Diffstat (limited to 'appc-adapters/appc-iaas-adapter')
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/CreateSnapshot.java144
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/EvacuateServer.java250
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/LookupServer.java25
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/MigrateServer.java242
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RebuildServer.java385
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RestartServer.java301
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RestoreStack.java45
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/SnapshotStack.java124
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/StartServer.java48
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/StopServer.java47
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/TerminateServer.java46
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/TerminateStack.java13
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/VmStatuschecker.java38
13 files changed, 701 insertions, 1007 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/CreateSnapshot.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/CreateSnapshot.java
index 7488f4e3b..6dced63b5 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/CreateSnapshot.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/CreateSnapshot.java
@@ -24,18 +24,6 @@
package org.openecomp.appc.adapter.iaas.provider.operation.impl;
-import org.openecomp.appc.Constants;
-import org.openecomp.appc.adapter.iaas.ProviderAdapter;
-import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
-import org.openecomp.appc.adapter.iaas.impl.RequestContext;
-import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
-import org.openecomp.appc.adapter.iaas.impl.VMURL;
-import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
-import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
-import org.openecomp.appc.configuration.Configuration;
-import org.openecomp.appc.configuration.ConfigurationFactory;
-import org.openecomp.appc.exceptions.APPCException;
-import org.openecomp.appc.i18n.Msg;
import com.att.cdp.exceptions.ContextConnectionException;
import com.att.cdp.exceptions.ResourceNotFoundException;
import com.att.cdp.exceptions.ZoneException;
@@ -48,52 +36,41 @@ import com.att.cdp.zones.model.Server;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.eelf.i18n.EELFResourceManager;
-import org.openecomp.sdnc.sli.SvcLogicContext;
import org.glassfish.grizzly.http.util.HttpStatus;
+import org.openecomp.appc.Constants;
+import org.openecomp.appc.adapter.iaas.ProviderAdapter;
+import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
+import org.openecomp.appc.adapter.iaas.impl.RequestContext;
+import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
+import org.openecomp.appc.adapter.iaas.impl.VMURL;
+import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
+import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
+import org.openecomp.appc.configuration.Configuration;
+import org.openecomp.appc.configuration.ConfigurationFactory;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.i18n.Msg;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.slf4j.MDC;
+import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
+import java.util.TimeZone;
import static org.openecomp.appc.adapter.iaas.provider.operation.common.constants.Constants.DATE_FORMAT;
import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-import org.slf4j.MDC;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.TimeZone;
-
-
public class CreateSnapshot extends ProviderServerOperation {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(CreateSnapshot.class);
private static EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
private static final Configuration configuration = ConfigurationFactory.getConfiguration();
-
private String generateSnapshotName(String server) {
+ setTimeForMetricsLogger();
+
SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
-
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df2.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "create snapshot");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.CreateSnapshot");
-
metricsLogger.info("Snapshot Name Generated: Snapshot of %s at %s", server, df.format(new Date()));
return String.format("Snapshot of %s at %s", server, df.format(new Date()));
@@ -105,30 +82,13 @@ public class CreateSnapshot extends ProviderServerOperation {
ImageService service = context.getImageService(); // Already checked access by this point
String snapshotName = generateSnapshotName(server.getName());
-
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "create snapshot");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.CreateSnapshot");
- logger.info(String.format("Creating snapshot of server %s (%s) with name %s", server.getName(), server.getId(),
- snapshotName));
- metricsLogger.info(String.format("Creating snapshot of server %s (%s) with name %s", server.getName(), server.getId(),
- snapshotName));
+ setTimeForMetricsLogger();
+
+ logger.info(String.format("Creating snapshot of server %s (%s) with name %s",
+ server.getName(), server.getId(), snapshotName));
+ metricsLogger.info(String.format("Creating snapshot of server %s (%s) with name %s",
+ server.getName(), server.getId(), snapshotName));
// Request Snapshot
String msg;
@@ -187,39 +147,19 @@ public class CreateSnapshot extends ProviderServerOperation {
}
private Image createSnapshot(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
-
Image snapshot = null;
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
- String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ setTimeForMetricsLogger();
+
String msg;
-
-
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "create snapshot");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.CreateSnapshot");
-
try {
validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
ProviderAdapter.PROPERTY_PROVIDER_NAME);
- String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
+ String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
VMURL vm = VMURL.parseURL(vm_url);
if (validateVM(rc, appName, vm_url, vm)) return null;
@@ -237,8 +177,8 @@ public class CreateSnapshot extends ProviderServerOperation {
snapshot = createSnapshot(rc, server);
doSuccess(rc);
} else {
- msg = EELFResourceManager.format(Msg.REBUILD_SERVER_FAILED, server.getName(), server.getId(),
- "Accessing Image Service Failed");
+ msg = EELFResourceManager.format(Msg.REBUILD_SERVER_FAILED,
+ server.getName(), server.getId(), "Accessing Image Service Failed");
logger.error(msg);
metricsLogger.error(msg);
doFailure(rc, HttpStatus.FORBIDDEN_403, msg);
@@ -252,7 +192,8 @@ public class CreateSnapshot extends ProviderServerOperation {
doFailure(rc, HttpStatus.NOT_FOUND_404, msg);
} catch (Throwable t) {
msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, t, t.getClass().getSimpleName(),
- Operation.SNAPSHOT_SERVICE.toString(), vm_url, context == null ? "Unknown" : context.getTenantName());
+ Operation.SNAPSHOT_SERVICE.toString(), vm_url,
+ context == null ? "Unknown" : context.getTenantName());
logger.error(msg, t);
doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
}
@@ -263,32 +204,31 @@ public class CreateSnapshot extends ProviderServerOperation {
}
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws APPCException {
setMDC(Operation.SNAPSHOT_SERVICE.toString(), "App-C IaaS Adapter:Snapshot", ADAPTER_NAME);
logOperation(Msg.SNAPSHOTING_SERVER, params, context);
+ setTimeForMetricsLogger();
+
+ metricsLogger.info("Executing Provider Operation: Create Snapshot");
- /*
- * Set Time for Metrics Logger
- */
+ return createSnapshot(params, context);
+ }
+
+ private void setTimeForMetricsLogger() {
long startTime = System.currentTimeMillis();
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
String durationStr = String.valueOf(duration);
String endTimeStrUTC = df.format(new Date());
MDC.put("EndTimestamp", endTimeStrUTC);
MDC.put("ElapsedTime", durationStr);
MDC.put("TargetEntity", "cdp");
MDC.put("TargetServiceName", "create snapshot");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.CreateSnapshot");
-
- metricsLogger.info("Executing Provider Operation: Create Snapshot");
-
- return createSnapshot(params, context);
+ MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.CreateSnapshot");
}
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/EvacuateServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/EvacuateServer.java
index 9fc6a8428..26fbe8d1b 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/EvacuateServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/EvacuateServer.java
@@ -74,54 +74,39 @@ public class EvacuateServer extends ProviderServerOperation {
private ProviderAdapterImpl paImpl = null;
- private void evacuateServer(RequestContext rc, @SuppressWarnings("unused") Server server, String target_host) throws ZoneException, RequestFailedException {
+ private void evacuateServer(RequestContext rc, @SuppressWarnings("unused") Server server, String target_host)
+ throws ZoneException, RequestFailedException {
- String msg;
Context ctx = server.getContext();
Provider provider = ctx.getProvider();
ComputeService service = ctx.getComputeService();
-
+
/*
* Pending is a bit of a special case. If we find the server is in a pending state, then the provider is in the
* process of changing state of the server. So, lets try to wait a little bit and see if the state settles down
* to one we can deal with. If not, then we have to fail the request.
*/
try {
- if (server.getStatus().equals(Server.Status.PENDING)) {
- waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING, Server.Status.ERROR, Server.Status.SUSPENDED, Server.Status.PAUSED);
- }
+ if (server.getStatus().equals(Server.Status.PENDING)) {
+ waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING, Server.Status.ERROR,
+ Server.Status.SUSPENDED, Server.Status.PAUSED);
+ }
} catch (RequestFailedException e) {
- // evacuate is a special case. If the server is still in a Pending state, we want to continue with evacuate
- logger.info("Evacuate server - ignore RequestFailedException from waitForStateChange() ...");
+ // evacuate is a special case. If the server is still in a Pending state, we want to continue with evacuate
+ logger.info("Evacuate server - ignore RequestFailedException from waitForStateChange() ...");
}
-
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "evacuate server");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.EvacuteServer");
-
+ SetTimeForMetricsLogger();
+
+ String msg;
try {
while (rc.attempt()) {
try {
- logger.debug("Calling CDP moveServer - server id = " + server.getId());
+ logger.debug("Calling CDP moveServer - server id = " + server.getId());
service.moveServer(server.getId(), target_host);
// Wait for completion, expecting the server to go to a non pending state
- waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING, Server.Status.ERROR, Server.Status.SUSPENDED, Server.Status.PAUSED);
+ waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING,
+ Server.Status.ERROR, Server.Status.SUSPENDED, Server.Status.PAUSED);
break;
} catch (ContextConnectionException e) {
msg = EELFResourceManager.format(Msg.CONNECTION_FAILED_RETRY, provider.getName(), service.getURL(),
@@ -129,14 +114,14 @@ public class EvacuateServer extends ProviderServerOperation {
Long.toString(rc.getRetryDelay()), Integer.toString(rc.getAttempts()),
Integer.toString(rc.getRetryLimit()));
logger.error(msg, e);
- metricsLogger.error(msg,e);
+ metricsLogger.error(msg, e);
rc.delay();
}
}
} catch (ZoneException e) {
- msg =
- EELFResourceManager.format(Msg.EVACUATE_SERVER_FAILED, server.getName(), server.getId(), e.getMessage());
+ msg = EELFResourceManager.format(Msg.EVACUATE_SERVER_FAILED,
+ server.getName(), server.getId(), e.getMessage());
logger.error(msg);
metricsLogger.error(msg);
throw new RequestFailedException("Evacute Server", msg, HttpStatus.BAD_GATEWAY_502, server);
@@ -160,126 +145,116 @@ public class EvacuateServer extends ProviderServerOperation {
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
- String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
- String msg;
+ SetTimeForMetricsLogger();
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "evacuate server");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.EvacuateServer");
-
+ String msg;
ctx.setAttribute("EVACUATE_STATUS", "ERROR");
try {
validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
ProviderAdapter.PROPERTY_PROVIDER_NAME);
- String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
+ String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
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();
-
+
// 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");
+ 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);
-
+ 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);
-
+ 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);
+ 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();
+ List<Image> snapshots = server.getSnapshots();
if (snapshots == null || snapshots.isEmpty()) {
- logger.debug("No snapshots available - skipping rebuild after evacuate");
+ 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.openecomp.appc.Constants.ATTRIBUTE_ERROR_CODE);
+ 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.openecomp.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.openecomp.appc.Constants.ATTRIBUTE_ERROR_MESSAGE));
- msg = EELFResourceManager.format(Msg.EVACUATE_SERVER_REBUILD_FAILED, server.getName(), hypervisor,
- hypervisor_after_evacuate, ctx.getAttribute(org.openecomp.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
- }
- }
- }
+ 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.openecomp.appc.Constants.ATTRIBUTE_ERROR_MESSAGE));
+ msg = EELFResourceManager.format(Msg.EVACUATE_SERVER_REBUILD_FAILED,
+ server.getName(), hypervisor, hypervisor_after_evacuate,
+ ctx.getAttribute(org.openecomp.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
+ }
+ }
+ }
}
-
+
}
} catch (ResourceNotFoundException e) {
msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url);
@@ -290,13 +265,14 @@ public class EvacuateServer extends ProviderServerOperation {
doFailure(rc, e.getStatus(), e.getMessage());
} catch (Throwable t) {
msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, t, t.getClass().getSimpleName(),
- Operation.EVACUATE_SERVICE.toString(), vm_url, context == null ? "Unknown" : context.getTenantName());
+ Operation.EVACUATE_SERVICE.toString(),
+ vm_url, context == null ? "Unknown" : context.getTenantName());
logger.error(msg, t);
metricsLogger.error(msg, t);
doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
}
} catch (RequestFailedException e) {
- msg = EELFResourceManager.format(Msg.EVACUATE_SERVER_FAILED, "n/a", "n/a", e.getMessage());
+ msg = EELFResourceManager.format(Msg.EVACUATE_SERVER_FAILED, "n/a", "n/a", e.getMessage());
logger.error(msg);
metricsLogger.error(msg);
doFailure(rc, e.getStatus(), e.getMessage());
@@ -313,69 +289,65 @@ public class EvacuateServer extends ProviderServerOperation {
* is found and it's state and status are not UP/ENABLED.
*
* @param context
- * The current context
+ * The current context
* @param host
- * The host name (short or fully qualified) of a compute node
+ * The host name (short or fully qualified) of a compute node
* @return true if the node is determined as down, false for all other cases
*/
private boolean isComputeNodeDown(Context context, String host) throws ZoneException {
- ComputeService service = context.getComputeService();
- boolean node_down = false;
-
+ ComputeService service = context.getComputeService();
+ boolean node_down = false;
+
// Check host status. A node is considered down only if a matching target host is
// found and it's state/status is not UP/ENABLED.
if ((host != null) && !(host.isEmpty())) {
- List<Hypervisor> hypervisors = service.getHypervisors();
- logger.debug("List of Hypervisors retrieved: " + Arrays.toString(hypervisors.toArray()));
+ List<Hypervisor> hypervisors = service.getHypervisors();
+ logger.debug("List of Hypervisors retrieved: " + Arrays.toString(hypervisors.toArray()));
for (Hypervisor h : hypervisors) {
if (h.getHostName().startsWith(host)) {
- // host matches one of the hypervisors
+ // host matches one of the hypervisors
State hstate = h.getState();
Status hstatus = h.getStatus();
logger.debug("Host matching hypervisor: " + h.getHostName() + ", State/Status: "
- + hstate.toString() + "/" + hstatus.toString());
- if ((hstate != null) && (hstatus != null)) {
- if (!(hstate.equals(State.UP)) || !(hstatus.equals(Status.ENABLED))) {
- node_down = true;
- }
+ + hstate.toString() + "/" + hstatus.toString());
+ if (hstate != State.UP || hstatus != Status.ENABLED) {
+ node_down = true;
}
}
}
}
return node_down;
}
-
- @Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
+ @Override
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws APPCException {
setMDC(Operation.EVACUATE_SERVICE.toString(), "App-C IaaS Adapter:Evacuate", ADAPTER_NAME);
logOperation(Msg.EVACUATING_SERVER, params, context);
-
- /*
- * Set Time for Metrics Logger
- */
+
+ SetTimeForMetricsLogger();
+
+ metricsLogger.info("Executing Provider Operation: Evacuate");
+ return evacuateServer(params, context);
+ }
+
+ private void SetTimeForMetricsLogger() {
long startTime = System.currentTimeMillis();
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
String durationStr = String.valueOf(duration);
String endTimeStrUTC = df.format(new Date());
MDC.put("EndTimestamp", endTimeStrUTC);
MDC.put("ElapsedTime", durationStr);
MDC.put("TargetEntity", "cdp");
MDC.put("TargetServiceName", "evacuate server");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.EvacuateServer");
-
-
- metricsLogger.info("Executing Provider Operation: Evacuate");
- return evacuateServer(params, context);
+ MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.EvacuateServer");
}
-
+
public void setProvideAdapterRef(ProviderAdapterImpl pai) {
- paImpl = pai;
+ paImpl = pai;
}
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/LookupServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/LookupServer.java
index 8dbea0af4..eb63f11a1 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/LookupServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/LookupServer.java
@@ -50,9 +50,6 @@ import java.util.Map;
import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-/**
- * @since September 26, 2016
- */
public class LookupServer extends ProviderServerOperation {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(EvacuateServer.class);
@@ -64,29 +61,29 @@ public class LookupServer extends ProviderServerOperation {
RequestContext rc = new RequestContext(ctx);
rc.isAlive(); //should we test the return and fail if false?
- String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
-
String vm_url = null;
- VMURL vm = null;
try {
-
//process vm_url
validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
ProviderAdapter.PROPERTY_PROVIDER_NAME);
- vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
- vm = VMURL.parseURL(vm_url);
- if (validateVM(rc, appName, vm_url, vm)) return null;
+ 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)) {
+ return null;
+ }
//use try with resource to ensure context is closed (returned to pool)
- try(Context context = resolveContext(rc, params, appName, vm_url)){
+ 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);
+ String msg =
+ EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "LookupServer", vm_url);
ctx.setAttribute(org.openecomp.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
doSuccess(rc);
}
@@ -118,8 +115,8 @@ public class LookupServer extends ProviderServerOperation {
}
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws APPCException {
setMDC(Operation.LOOKUP_SERVICE.toString(), "App-C IaaS Adapter:LookupServer", ADAPTER_NAME);
logOperation(Msg.LOOKING_SERVER_UP, params, context);
return lookupServer(params, context);
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/MigrateServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/MigrateServer.java
index 4f89592ad..20b4f1061 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/MigrateServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/MigrateServer.java
@@ -24,6 +24,17 @@
package org.openecomp.appc.adapter.iaas.provider.operation.impl;
+import com.att.cdp.exceptions.ContextConnectionException;
+import com.att.cdp.exceptions.ResourceNotFoundException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.ComputeService;
+import com.att.cdp.zones.Context;
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+import org.glassfish.grizzly.http.util.HttpStatus;
import org.openecomp.appc.Constants;
import org.openecomp.appc.adapter.iaas.ProviderAdapter;
import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
@@ -36,37 +47,20 @@ import org.openecomp.appc.configuration.Configuration;
import org.openecomp.appc.configuration.ConfigurationFactory;
import org.openecomp.appc.exceptions.APPCException;
import org.openecomp.appc.i18n.Msg;
-import com.att.cdp.exceptions.ContextConnectionException;
-import com.att.cdp.exceptions.ResourceNotFoundException;
-import com.att.cdp.exceptions.ZoneException;
-import com.att.cdp.zones.ComputeService;
-import com.att.cdp.zones.Context;
-import com.att.cdp.zones.model.ModelObject;
-import com.att.cdp.zones.model.Server;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.att.eelf.i18n.EELFResourceManager;
import org.openecomp.sdnc.sli.SvcLogicContext;
-import org.glassfish.grizzly.http.util.HttpStatus;
+import org.slf4j.MDC;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Date;
import java.util.Map;
+import java.util.TimeZone;
-import static org.openecomp.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE;
import static org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation.MIGRATE_SERVICE;
import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-import org.slf4j.MDC;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.TimeZone;
-
-
-/**
- * @since September 26, 2016
- */
public class MigrateServer extends ProviderServerOperation {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(EvacuateServer.class);
@@ -76,7 +70,8 @@ public class MigrateServer extends ProviderServerOperation {
/**
* A list of valid initial VM statuses for a migrate operations
*/
- private final Collection<Server.Status> migratableStatuses = Arrays.asList(Server.Status.READY, Server.Status.RUNNING, Server.Status.SUSPENDED);
+ private final Collection<Server.Status> migratableStatuses =
+ Arrays.asList(Server.Status.READY, Server.Status.RUNNING, Server.Status.SUSPENDED);
private String getConnectionExceptionMessage(RequestContext rc, Context ctx, ContextConnectionException e)
@@ -87,98 +82,76 @@ public class MigrateServer extends ProviderServerOperation {
Integer.toString(rc.getRetryLimit()));
}
- private void migrateServer(RequestContext rc, Server server, SvcLogicContext svcCtx)
- throws ZoneException, RequestFailedException {
- String msg;
- Context ctx = server.getContext();
- ComputeService service = ctx.getComputeService();
-
- // Init status will equal final status
- Server.Status initialStatus = server.getStatus();
+ private void migrateServer(RequestContext rc, Server server, SvcLogicContext svcCtx)
+ throws ZoneException, RequestFailedException {
+ String msg;
+ Context ctx = server.getContext();
+ ComputeService service = ctx.getComputeService();
- if (initialStatus == null) {
- throw new ZoneException("Failed to determine server's starting status");
- }
+ // Init status will equal final status
+ Server.Status initialStatus = server.getStatus();
- // We can only migrate certain statuses
- if (!migratableStatuses.contains(initialStatus)) {
- throw new ZoneException(String.format("Cannot migrate server that is in %s state. Must be in one of [%s]",
- initialStatus, migratableStatuses));
- }
+ if (initialStatus == null) {
+ throw new ZoneException("Failed to determine server's starting status");
+ }
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "migrate server");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.MigrateServer");
- // Is the skip Hypervisor check attribute populated?
- String skipHypervisorCheck = null;
- if (svcCtx != null) {
- skipHypervisorCheck = svcCtx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
+ // We can only migrate certain statuses
+ if (!migratableStatuses.contains(initialStatus)) {
+ throw new ZoneException(String.format("Cannot migrate server that is in %s state. Must be in one of [%s]",
+ initialStatus, migratableStatuses));
+ }
- }
+ setTimeForMetricsLogger();
- // // Always perform Hypervisor check
- // unless the skip is set to true
-
- if (skipHypervisorCheck == null || (!skipHypervisorCheck.equalsIgnoreCase("true"))) {
+ // Is the skip Hypervisor check attribute populated?
+ String skipHypervisorCheck = null;
+ if (svcCtx != null) {
+ skipHypervisorCheck = svcCtx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
+ }
- // Check of the Hypervisor for the VM Server is UP and reachable
-
- checkHypervisor(server);
-
- }
-
- boolean inConfirmPhase = false;
- try {
- while (rc.attempt()) {
- try {
- if (!inConfirmPhase) {
- // Initial migrate request
- service.migrateServer(server.getId());
- // Wait for change to verify resize
- waitForStateChange(rc, server, Server.Status.READY);
- inConfirmPhase = true;
- }
+ // Always perform Hypervisor check
+ // unless the skip is set to true
+ if (skipHypervisorCheck == null || (!skipHypervisorCheck.equalsIgnoreCase("true"))) {
+ // Check of the Hypervisor for the VM Server is UP and reachable
+ checkHypervisor(server);
+ }
- // Verify resize
- service.processResize(server);
- // Wait for complete. will go back to init status
- waitForStateChange(rc, server, initialStatus);
- logger.info("Completed migrate request successfully");
- metricsLogger.info("Completed migrate request successfully");
- return;
- } catch (ContextConnectionException e) {
- msg = getConnectionExceptionMessage(rc, ctx, e);
- logger.error(msg, e);
- metricsLogger.error(msg, e);
- rc.delay();
- }
- }
- } catch (ZoneException e) {
- String phase = inConfirmPhase ? "VERIFY MIGRATE" : "REQUEST MIGRATE";
- msg = EELFResourceManager.format(Msg.MIGRATE_SERVER_FAILED, server.getName(), server.getId(), phase,
- e.getMessage());
- generateEvent(rc, false, msg);
- logger.error(msg, e);
- metricsLogger.error(msg, e);
- throw new RequestFailedException("Migrate Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
- }
-
- }
+ boolean inConfirmPhase = false;
+ try {
+ while (rc.attempt()) {
+ try {
+ if (!inConfirmPhase) {
+ // Initial migrate request
+ service.migrateServer(server.getId());
+ // Wait for change to verify resize
+ waitForStateChange(rc, server, Server.Status.READY);
+ inConfirmPhase = true;
+ }
+
+ // Verify resize
+ service.processResize(server);
+ // Wait for complete. will go back to init status
+ waitForStateChange(rc, server, initialStatus);
+ logger.info("Completed migrate request successfully");
+ metricsLogger.info("Completed migrate request successfully");
+ return;
+ } catch (ContextConnectionException e) {
+ msg = getConnectionExceptionMessage(rc, ctx, e);
+ logger.error(msg, e);
+ metricsLogger.error(msg, e);
+ rc.delay();
+ }
+ }
+ } catch (ZoneException e) {
+ String phase = inConfirmPhase ? "VERIFY MIGRATE" : "REQUEST MIGRATE";
+ msg = EELFResourceManager.format(Msg.MIGRATE_SERVER_FAILED, server.getName(), server.getId(), phase,
+ e.getMessage());
+ generateEvent(rc, false, msg);
+ logger.error(msg, e);
+ metricsLogger.error(msg, e);
+ throw new RequestFailedException("Migrate Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+ }
+ }
/**
* @see org.openecomp.appc.adapter.iaas.ProviderAdapter#migrateServer(java.util.Map, org.openecomp.sdnc.sli.SvcLogicContext)
@@ -188,33 +161,15 @@ public class MigrateServer extends ProviderServerOperation {
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
- String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
- String msg;
-
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "migrate server");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.MigrateServer");
+ setTimeForMetricsLogger();
+ String msg;
try {
validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
ProviderAdapter.PROPERTY_PROVIDER_NAME);
String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
+ String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
VMURL vm = VMURL.parseURL(vm_url);
if (validateVM(rc, appName, vm_url, vm)) return null;
@@ -234,8 +189,7 @@ public class MigrateServer extends ProviderServerOperation {
}
} catch (RequestFailedException e) {
doFailure(rc, e.getStatus(), e.getMessage());
- }
- catch (ResourceNotFoundException e) {
+ } catch (ResourceNotFoundException e) {
msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url);
logger.error(msg);
metricsLogger.error(msg);
@@ -255,33 +209,31 @@ public class MigrateServer extends ProviderServerOperation {
}
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws APPCException {
setMDC(Operation.MIGRATE_SERVICE.toString(), "App-C IaaS Adapter:Migrate", ADAPTER_NAME);
logOperation(Msg.MIGRATING_SERVER, params, context);
-
- /*
- * Set Time for Metrics Logger
- */
+
+ setTimeForMetricsLogger();
+
+ metricsLogger.info("Executing Provider Operation: Migrate");
+
+ return migrateServer(params, context);
+ }
+
+ private void setTimeForMetricsLogger() {
long startTime = System.currentTimeMillis();
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
String durationStr = String.valueOf(duration);
String endTimeStrUTC = df.format(new Date());
MDC.put("EndTimestamp", endTimeStrUTC);
MDC.put("ElapsedTime", durationStr);
MDC.put("TargetEntity", "cdp");
MDC.put("TargetServiceName", "migrate server");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.MigrateServer");
-
-
- metricsLogger.info("Executing Provider Operation: Migrate");
-
- return migrateServer(params,context);
+ MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.MigrateServer");
}
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RebuildServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RebuildServer.java
index 43a9a09ce..a5b9b3fd7 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RebuildServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RebuildServer.java
@@ -24,19 +24,6 @@
package org.openecomp.appc.adapter.iaas.provider.operation.impl;
-import org.openecomp.appc.Constants;
-import org.openecomp.appc.adapter.iaas.ProviderAdapter;
-import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
-import org.openecomp.appc.adapter.iaas.impl.RequestContext;
-import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
-import org.openecomp.appc.adapter.iaas.impl.VMURL;
-import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
-import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Outcome;
-import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
-import org.openecomp.appc.configuration.Configuration;
-import org.openecomp.appc.configuration.ConfigurationFactory;
-import org.openecomp.appc.exceptions.APPCException;
-import org.openecomp.appc.i18n.Msg;
import com.att.cdp.exceptions.ContextConnectionException;
import com.att.cdp.exceptions.ResourceNotFoundException;
import com.att.cdp.exceptions.ZoneException;
@@ -51,25 +38,33 @@ import com.att.cdp.zones.model.ServerBootSource;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.eelf.i18n.EELFResourceManager;
-import org.openecomp.sdnc.sli.SvcLogicContext;
import org.glassfish.grizzly.http.util.HttpStatus;
+import org.openecomp.appc.Constants;
+import org.openecomp.appc.adapter.iaas.ProviderAdapter;
+import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
+import org.openecomp.appc.adapter.iaas.impl.RequestContext;
+import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
+import org.openecomp.appc.adapter.iaas.impl.VMURL;
+import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
+import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Outcome;
+import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
+import org.openecomp.appc.configuration.Configuration;
+import org.openecomp.appc.configuration.ConfigurationFactory;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.i18n.Msg;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.slf4j.MDC;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.List;
import java.util.Map;
+import java.util.TimeZone;
-import static org.openecomp.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE;
import static org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation.STOP_SERVICE;
import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-import org.slf4j.MDC;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.TimeZone;
-
-/**
- * @since September 26, 2016
- */
public class RebuildServer extends ProviderServerOperation {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(RebuildServer.class);
@@ -80,19 +75,16 @@ public class RebuildServer extends ProviderServerOperation {
* Rebuild the indicated server with the indicated image. This method assumes the server has been determined to be
* in the correct state to do the rebuild.
*
- * @param rc
- * The request context that manages the state and recovery of the request for the life of its processing.
- * @param server
- * the server to be rebuilt
- * @param image
- * The image to be used (or snapshot)
- * @throws RequestFailedException
- * if the server does not change state in the allotted time
+ * @param rc The request context that manages the state and recovery of the request for the life of
+ * its processing.
+ * @param server the server to be rebuilt
+ * @param image The image to be used (or snapshot)
+ * @throws RequestFailedException if the server does not change state in the allotted time
*/
@SuppressWarnings("nls")
private void rebuildServer(RequestContext rc, Server server, String image) throws RequestFailedException {
logger.debug(Msg.REBUILD_SERVER, server.getId());
-
+
String msg;
Context context = server.getContext();
Provider provider = context.getProvider();
@@ -101,21 +93,7 @@ public class RebuildServer extends ProviderServerOperation {
/*
* Set Time for Metrics Logger
*/
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "rebuild server");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.RebuildServer");
+ setTimeForMetricsLogger();
try {
while (rc.attempt()) {
@@ -128,7 +106,7 @@ public class RebuildServer extends ProviderServerOperation {
Long.toString(rc.getRetryDelay()), Integer.toString(rc.getAttempts()),
Integer.toString(rc.getRetryLimit()));
logger.error(msg, e);
- metricsLogger.error(msg,e);
+ metricsLogger.error(msg, e);
rc.delay();
}
}
@@ -143,8 +121,8 @@ public class RebuildServer extends ProviderServerOperation {
metricsLogger.trace("Sleep threw interrupted exception, should never occur");
}
} catch (ZoneException e) {
- msg =
- EELFResourceManager.format(Msg.REBUILD_SERVER_FAILED, server.getName(), server.getId(), e.getMessage());
+ msg = EELFResourceManager.format(Msg.REBUILD_SERVER_FAILED,
+ server.getName(), server.getId(), e.getMessage());
logger.error(msg);
metricsLogger.error(msg);
throw new RequestFailedException("Rebuild Server", msg, HttpStatus.BAD_GATEWAY_502, server);
@@ -173,128 +151,110 @@ public class RebuildServer extends ProviderServerOperation {
* a VM from a bootable volume, where the bootable volume itself is not rebuilt, serves no purpose.
* </p>
*
- * @param rc
- * The request context that manages the state and recovery of the request for the life of its processing.
- * @param server
- * @throws ZoneException
- * @throws RequestFailedException
+ * @param rc The request context that manages the state and recovery of the request for the life of
+ * its processing.
+ * @param server The server to be rebuilt
+ * @throws ZoneException When error occurs
+ * @throws RequestFailedException When server status is error
*/
@SuppressWarnings("nls")
- private void rebuildServer(RequestContext rc, Server server, SvcLogicContext ctx)
- throws ZoneException, RequestFailedException {
-
- ServerBootSource builtFrom = server.getBootSource();
- String msg;
-
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "rebuild server");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.RebuildServer");
-
- // Throw exception for non image/snap boot source
- if (ServerBootSource.VOLUME.equals(builtFrom)) {
- msg = String.format("Rebuilding is currently not supported for servers built from bootable volumes [%s]",
- server.getId());
- generateEvent(rc, false, msg);
- logger.error(msg);
- metricsLogger.error(msg);
- throw new RequestFailedException("Rebuild Server", msg, HttpStatus.FORBIDDEN_403, server);
- }
-
- /*
- * Pending is a bit of a special case. If we find the server is in a
- * pending state, then the provider is in the process of changing state
- * of the server. So, lets try to wait a little bit and see if the state
- * settles down to one we can deal with. If not, then we have to fail
- * the request.
- */
- Context context = server.getContext();
- Provider provider = context.getProvider();
- ComputeService service = context.getComputeService();
- if (server.getStatus().equals(Server.Status.PENDING)) {
+ private void rebuildServer(RequestContext rc, Server server, SvcLogicContext ctx)
+ throws ZoneException, RequestFailedException {
+ ServerBootSource builtFrom = server.getBootSource();
+
+ /*
+ * Set Time for Metrics Logger
+ */
+ setTimeForMetricsLogger();
+
+ String msg;
+ // Throw exception for non image/snap boot source
+ if (ServerBootSource.VOLUME.equals(builtFrom)) {
+ msg = String.format("Rebuilding is currently not supported for servers built from bootable volumes [%s]",
+ server.getId());
+ generateEvent(rc, false, msg);
+ logger.error(msg);
+ metricsLogger.error(msg);
+ throw new RequestFailedException("Rebuild Server", msg, HttpStatus.FORBIDDEN_403, server);
+ }
+
+ /*
+ * Pending is a bit of a special case. If we find the server is in a
+ * pending state, then the provider is in the process of changing state
+ * of the server. So, lets try to wait a little bit and see if the state
+ * settles down to one we can deal with. If not, then we have to fail
+ * the request.
+ */
+ Context context = server.getContext();
+ Provider provider = context.getProvider();
+ ComputeService service = context.getComputeService();
+ if (server.getStatus().equals(Server.Status.PENDING)) {
rc.reset();
waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING, Server.Status.ERROR,
- Server.Status.SUSPENDED, Server.Status.PAUSED);
- }
-
- // Is the skip Hypervisor check attribute populated?
- String skipHypervisorCheck = null;
- if (ctx != null) {
- skipHypervisorCheck = ctx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
-
- }
-
- // Always perform Hypervisor Status checks
- // unless the skip is set to true
- if (skipHypervisorCheck == null || (!skipHypervisorCheck.equalsIgnoreCase("true"))) {
-
- // Check of the Hypervisor for the VM Server is UP and reachable
- checkHypervisor(server);
- }
-
- /*
- * Get the image to use. This is determined by the presence or
- * absence of snapshot images. If any snapshots exist, then the
- * latest snapshot is used, otherwise the image used to construct
- * the VM is used.
- */
- List<Image> snapshots = server.getSnapshots();
- String imageToUse;
- if (snapshots != null && !snapshots.isEmpty()) {
- imageToUse = snapshots.get(0).getId();
- } else {
- imageToUse = server.getImage();
- ImageService imageService = server.getContext().getImageService();
- rc.reset();
- try {
- while (rc.attempt()) {
- try {
- /*
- * We are just trying to make sure that the image
- * exists. We arent interested in the details at
- * this point.
- */
- imageService.getImage(imageToUse);
- break;
- } catch (ContextConnectionException e) {
- msg = EELFResourceManager.format(Msg.CONNECTION_FAILED_RETRY, provider.getName(),
- imageService.getURL(), context.getTenant().getName(), context.getTenant().getId(),
- e.getMessage(), Long.toString(rc.getRetryDelay()),
- Integer.toString(rc.getAttempts()), Integer.toString(rc.getRetryLimit()));
- logger.error(msg, e);
- metricsLogger.error(msg);
- rc.delay();
- }
- }
- } catch (ZoneException e) {
- msg = EELFResourceManager.format(Msg.IMAGE_NOT_FOUND, imageToUse, "rebuild");
- generateEvent(rc, false, msg);
- logger.error(msg);
- metricsLogger.error(msg);
- throw new RequestFailedException("Rebuild Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
- }
- }
- if (rc.isFailed()) {
- msg = EELFResourceManager.format(Msg.CONNECTION_FAILED, provider.getName(), service.getURL());
- logger.error(msg);
- metricsLogger.error(msg);
- throw new RequestFailedException("Rebuild Server", msg, HttpStatus.BAD_GATEWAY_502, server);
- }
- rc.reset();
+ Server.Status.SUSPENDED, Server.Status.PAUSED);
+ }
+
+ // Is the skip Hypervisor check attribute populated?
+ String skipHypervisorCheck = null;
+ if (ctx != null) {
+ skipHypervisorCheck = ctx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
+ }
+
+ // Always perform Hypervisor Status checks
+ // unless the skip is set to true
+ if (skipHypervisorCheck == null || (!skipHypervisorCheck.equalsIgnoreCase("true"))) {
+ // Check of the Hypervisor for the VM Server is UP and reachable
+ checkHypervisor(server);
+ }
+
+ /*
+ * Get the image to use. This is determined by the presence or
+ * absence of snapshot images. If any snapshots exist, then the
+ * latest snapshot is used, otherwise the image used to construct
+ * the VM is used.
+ */
+ List<Image> snapshots = server.getSnapshots();
+ String imageToUse;
+ if (snapshots != null && !snapshots.isEmpty()) {
+ imageToUse = snapshots.get(0).getId();
+ } else {
+ imageToUse = server.getImage();
+ ImageService imageService = server.getContext().getImageService();
+ rc.reset();
+ try {
+ while (rc.attempt()) {
+ try {
+ /*
+ * We are just trying to make sure that the image exists.
+ * We arent interested in the details at this point.
+ */
+ imageService.getImage(imageToUse);
+ break;
+ } catch (ContextConnectionException e) {
+ msg = EELFResourceManager.format(Msg.CONNECTION_FAILED_RETRY, provider.getName(),
+ imageService.getURL(), context.getTenant().getName(), context.getTenant().getId(),
+ e.getMessage(), Long.toString(rc.getRetryDelay()),
+ Integer.toString(rc.getAttempts()), Integer.toString(rc.getRetryLimit()));
+ logger.error(msg, e);
+ metricsLogger.error(msg);
+ rc.delay();
+ }
+ }
+ } catch (ZoneException e) {
+ msg = EELFResourceManager.format(Msg.IMAGE_NOT_FOUND, imageToUse, "rebuild");
+ generateEvent(rc, false, msg);
+ logger.error(msg);
+ metricsLogger.error(msg);
+ throw new RequestFailedException("Rebuild Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+ }
+ }
+ if (rc.isFailed()) {
+ msg = EELFResourceManager.format(Msg.CONNECTION_FAILED, provider.getName(), service.getURL());
+ logger.error(msg);
+ metricsLogger.error(msg);
+ throw new RequestFailedException("Rebuild Server", msg, HttpStatus.BAD_GATEWAY_502, server);
+ }
+ rc.reset();
/*
* We determine what to do based on the current state of the server
@@ -363,18 +323,16 @@ public class RebuildServer extends ProviderServerOperation {
metricsLogger.info("Server status: SUSPENDED");
break;
- default:
- // Hmmm, unknown status, should never occur
- msg = EELFResourceManager.format(Msg.UNKNOWN_SERVER_STATE, server.getName(), server.getId(),
- server.getTenantId(), server.getStatus().name());
- generateEvent(rc, false, msg);
- logger.error(msg);
- metricsLogger.error(msg);
- throw new RequestFailedException("Rebuild Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
- }
-
-
- }
+ default:
+ // Hmmm, unknown status, should never occur
+ msg = EELFResourceManager.format(Msg.UNKNOWN_SERVER_STATE, server.getName(), server.getId(),
+ server.getTenantId(), server.getStatus().name());
+ generateEvent(rc, false, msg);
+ logger.error(msg);
+ metricsLogger.error(msg);
+ throw new RequestFailedException("Rebuild Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+ }
+ }
/**
* @see org.openecomp.appc.adapter.iaas.ProviderAdapter#rebuildServer(java.util.Map, org.openecomp.sdnc.sli.SvcLogicContext)
@@ -385,33 +343,15 @@ public class RebuildServer extends ProviderServerOperation {
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
- String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
- String msg;
-
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "rebuild server");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.RebuildServer");
+ setTimeForMetricsLogger();
+ String msg;
try {
validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
ProviderAdapter.PROPERTY_PROVIDER_NAME);
- String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
+ String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
VMURL vm = VMURL.parseURL(vm_url);
if (validateVM(rc, appName, vm_url, vm)) return null;
@@ -433,24 +373,20 @@ public class RebuildServer extends ProviderServerOperation {
doSuccess(rc);
ctx.setAttribute("REBUILD_STATUS", "SUCCESS");
} else {
- msg = EELFResourceManager.format(Msg.REBUILD_SERVER_FAILED, server.getName(), server.getId(),
- "Accessing Image Service Failed");
+ msg = EELFResourceManager.format(Msg.REBUILD_SERVER_FAILED,
+ server.getName(), server.getId(), "Accessing Image Service Failed");
logger.error(msg);
metricsLogger.error(msg);
doFailure(rc, HttpStatus.FORBIDDEN_403, msg);
}
context.close();
- }
- else
- {
+ } else {
ctx.setAttribute("REBUILD_STATUS", "CONTEXT_NOT_FOUND");
}
- }
- catch (RequestFailedException e) {
+ } catch (RequestFailedException e) {
doFailure(rc, e.getStatus(), e.getMessage());
ctx.setAttribute("REBUILD_STATUS", "ERROR");
- }
- catch (ResourceNotFoundException e) {
+ } catch (ResourceNotFoundException e) {
msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url);
ctx.setAttribute("REBUILD_STATUS", "ERROR");
logger.error(msg);
@@ -473,22 +409,25 @@ public class RebuildServer extends ProviderServerOperation {
}
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws APPCException {
setMDC(Operation.REBUILD_SERVICE.toString(), "App-C IaaS Adapter:Rebuild", ADAPTER_NAME);
logOperation(Msg.REBUILDING_SERVER, params, context);
-
- /*
- * Set Time for Metrics Logger
- */
+
+ setTimeForMetricsLogger();
+
+ metricsLogger.info("Executing Provider Operation: Rebuild");
+
+ return rebuildServer(params, context);
+ }
+
+ private void setTimeForMetricsLogger() {
long startTime = System.currentTimeMillis();
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
String durationStr = String.valueOf(duration);
String endTimeStrUTC = df.format(new Date());
MDC.put("EndTimestamp", endTimeStrUTC);
@@ -496,11 +435,5 @@ public class RebuildServer extends ProviderServerOperation {
MDC.put("TargetEntity", "cdp");
MDC.put("TargetServiceName", "rebuild server");
MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.RebuildServer");
-
-
- metricsLogger.info("Executing Provider Operation: Rebuild");
-
-
- return rebuildServer(params, context);
}
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RestartServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RestartServer.java
index 64ddb2f34..dd825f9c9 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RestartServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RestartServer.java
@@ -24,6 +24,15 @@
package org.openecomp.appc.adapter.iaas.provider.operation.impl;
+import com.att.cdp.exceptions.ResourceNotFoundException;
+import com.att.cdp.exceptions.ZoneException;
+import com.att.cdp.zones.Context;
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+import org.glassfish.grizzly.http.util.HttpStatus;
import org.openecomp.appc.Constants;
import org.openecomp.appc.adapter.iaas.ProviderAdapter;
import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
@@ -34,34 +43,18 @@ import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Outcome;
import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
import org.openecomp.appc.exceptions.UnknownProviderException;
import org.openecomp.appc.i18n.Msg;
-import com.att.cdp.exceptions.ResourceNotFoundException;
-import com.att.cdp.exceptions.ZoneException;
-import com.att.cdp.zones.Context;
-import com.att.cdp.zones.NetworkService;
-import com.att.cdp.zones.model.ModelObject;
-import com.att.cdp.zones.model.Network;
-import com.att.cdp.zones.model.Port;
-import com.att.cdp.zones.model.Server;
-import com.att.cdp.zones.model.Subnet;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.att.eelf.i18n.EELFResourceManager;
import org.openecomp.sdnc.sli.SvcLogicContext;
-import org.glassfish.grizzly.http.util.HttpStatus;
import org.slf4j.MDC;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
-import java.util.List;
import java.util.Map;
import java.util.TimeZone;
-import static org.openecomp.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE;
import static org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation.RESTART_SERVICE;
import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-
public class RestartServer extends ProviderServerOperation {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestartServer.class);
@@ -72,127 +65,104 @@ public class RestartServer extends ProviderServerOperation {
* This method handles the case of restarting a server once we have found the server and have obtained the abstract
* representation of the server via the context (i.e., the "Server" object from the CDP-Zones abstraction).
*
- * @param rc
- * The request context that manages the state and recovery of the request for the life of its processing.
- * @param server
- * The server object representing the server we want to operate on
- * @throws ZoneException
+ * @param rc The request context that manages the state and recovery of the request for the life of
+ * its processing.
+ * @param server The server object representing the server we want to operate on
+ * @throws ZoneException when error occurs.
+ * @throws RequestFailedException when server status is error.
*/
- @SuppressWarnings("nls")
- private void restartServer(RequestContext rc, Server server, SvcLogicContext ctx)
- throws ZoneException, RequestFailedException {
-
- /*
- * Pending is a bit of a special case. If we find the server is in a
- * pending state, then the provider is in the process of changing state
- * of the server. So, lets try to wait a little bit and see if the state
- * settles down to one we can deal with. If not, then we have to fail
- * the request.
- */
- String msg;
- if (server.getStatus().equals(Server.Status.PENDING)) {
- waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING, Server.Status.ERROR,
- Server.Status.SUSPENDED, Server.Status.PAUSED);
- }
-
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "restart server");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.RestartServer");
-
- String skipHypervisorCheck = null;
- if (ctx != null) {
- skipHypervisorCheck = ctx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
-
- }
-
- // Always perform Virtual Machine/Hypervisor Status/Network checks
- // unless the skip is set to true
- if (skipHypervisorCheck == null || (!skipHypervisorCheck.equalsIgnoreCase("true"))) {
-
- // Check of the Hypervisor for the VM Server is UP and reachable
-
- checkHypervisor(server);
-
- }
-
- /*
- * We determine what to do based on the current state of the server
- */
-
- switch (server.getStatus()) {
- case DELETED:
- // Nothing to do, the server is gone
- msg = EELFResourceManager.format(Msg.SERVER_DELETED, server.getName(), server.getId(),
- server.getTenantId(), "restarted");
- generateEvent(rc, false, msg);
- logger.error(msg);
- metricsLogger.error(msg);
- break;
-
- case RUNNING:
- // Attempt to stop and start the server
- stopServer(rc, server);
- startServer(rc, server);
- generateEvent(rc, true, Outcome.SUCCESS.toString());
- metricsLogger.info("Server status: RUNNING");
- break;
-
- case ERROR:
- msg = EELFResourceManager.format(Msg.SERVER_ERROR_STATE, server.getName(), server.getId(),
- server.getTenantId(), "rebuild");
- generateEvent(rc, false, msg);
- logger.error(msg);
- metricsLogger.error(msg);
- throw new RequestFailedException("Rebuild Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
-
- case READY:
- // Attempt to start the server
- startServer(rc, server);
- generateEvent(rc, true, Outcome.SUCCESS.toString());
- metricsLogger.info("Server status: READY");
- break;
-
- case PAUSED:
- // if paused, un-pause it
- unpauseServer(rc, server);
- generateEvent(rc, true, Outcome.SUCCESS.toString());
- metricsLogger.info("Server status: PAUSED");
- break;
-
- case SUSPENDED:
- // Attempt to resume the suspended server
- resumeServer(rc, server);
- generateEvent(rc, true, Outcome.SUCCESS.toString());
- metricsLogger.info("Server status: SUSPENDED");
- break;
-
- default:
- // Hmmm, unknown status, should never occur
- msg = EELFResourceManager.format(Msg.UNKNOWN_SERVER_STATE, server.getName(), server.getId(),
- server.getTenantId(), server.getStatus().name());
- generateEvent(rc, false, msg);
- logger.error(msg);
- metricsLogger.error(msg);
- break;
- }
-
-
- }
+ @SuppressWarnings("nls")
+ private void restartServer(RequestContext rc, Server server, SvcLogicContext ctx)
+ throws ZoneException, RequestFailedException {
+ /*
+ * Pending is a bit of a special case. If we find the server is in a
+ * pending state, then the provider is in the process of changing state
+ * of the server. So, lets try to wait a little bit and see if the state
+ * settles down to one we can deal with. If not, then we have to fail
+ * the request.
+ */
+ String msg;
+ if (server.getStatus().equals(Server.Status.PENDING)) {
+ waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING, Server.Status.ERROR,
+ Server.Status.SUSPENDED, Server.Status.PAUSED);
+ }
+
+ setTimeForMetricsLogger("restart server");
+
+ String skipHypervisorCheck = null;
+ if (ctx != null) {
+ skipHypervisorCheck = ctx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
+ }
+
+ // Always perform Virtual Machine/Hypervisor Status/Network checks
+ // unless the skip is set to true
+ if (skipHypervisorCheck == null || (!skipHypervisorCheck.equalsIgnoreCase("true"))) {
+ // Check of the Hypervisor for the VM Server is UP and reachable
+ checkHypervisor(server);
+ }
+
+ /*
+ * We determine what to do based on the current state of the server
+ */
+ switch (server.getStatus()) {
+ case DELETED:
+ // Nothing to do, the server is gone
+ msg = EELFResourceManager.format(Msg.SERVER_DELETED, server.getName(), server.getId(),
+ server.getTenantId(), "restarted");
+ generateEvent(rc, false, msg);
+ logger.error(msg);
+ metricsLogger.error(msg);
+ break;
+
+ case RUNNING:
+ // Attempt to stop and start the server
+ stopServer(rc, server);
+ startServer(rc, server);
+ generateEvent(rc, true, Outcome.SUCCESS.toString());
+ metricsLogger.info("Server status: RUNNING");
+ break;
+
+ case ERROR:
+ msg = EELFResourceManager.format(Msg.SERVER_ERROR_STATE, server.getName(), server.getId(),
+ server.getTenantId(), "rebuild");
+ generateEvent(rc, false, msg);
+ logger.error(msg);
+ metricsLogger.error(msg);
+ throw new RequestFailedException("Rebuild Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+
+ case READY:
+ // Attempt to start the server
+ startServer(rc, server);
+ generateEvent(rc, true, Outcome.SUCCESS.toString());
+ metricsLogger.info("Server status: READY");
+ break;
+
+ case PAUSED:
+ // if paused, un-pause it
+ unpauseServer(rc, server);
+ generateEvent(rc, true, Outcome.SUCCESS.toString());
+ metricsLogger.info("Server status: PAUSED");
+ break;
+
+ case SUSPENDED:
+ // Attempt to resume the suspended server
+ resumeServer(rc, server);
+ generateEvent(rc, true, Outcome.SUCCESS.toString());
+ metricsLogger.info("Server status: SUSPENDED");
+ break;
+
+ default:
+ // Hmmm, unknown status, should never occur
+ msg = EELFResourceManager.format(Msg.UNKNOWN_SERVER_STATE, server.getName(), server.getId(),
+ server.getTenantId(), server.getStatus().name());
+ generateEvent(rc, false, msg);
+ logger.error(msg);
+ metricsLogger.error(msg);
+ break;
+ }
+
+
+ }
/**
* This method is used to restart an existing virtual machine given the fully qualified URL of the machine.
@@ -205,10 +175,8 @@ public class RestartServer extends ProviderServerOperation {
* server by its UUID, and then perform the restart.
* </p>
*
- * @throws UnknownProviderException
- * If the provider cannot be found
- * @throws IllegalArgumentException
- * if the expected argument(s) are not defined or are invalid
+ * @throws UnknownProviderException If the provider cannot be found
+ * @throws IllegalArgumentException if the expected argument(s) are not defined or are invalid
* @see org.openecomp.appc.adapter.iaas.ProviderAdapter#restartServer(java.util.Map, org.openecomp.sdnc.sli.SvcLogicContext)
*/
@SuppressWarnings("nls")
@@ -220,25 +188,10 @@ public class RestartServer extends ProviderServerOperation {
String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
-
/*
* Set Time for Metrics Logger
*/
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "GET server status");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.RestartServer");
+ setTimeForMetricsLogger("GET server status");
ctx.setAttribute("RESTART_STATUS", "ERROR");
try {
@@ -265,13 +218,13 @@ public class RestartServer extends ProviderServerOperation {
context.close();
doSuccess(rc);
ctx.setAttribute("RESTART_STATUS", "SUCCESS");
- String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "RestartServer", vm_url);
+ String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE,
+ "RestartServer", vm_url);
ctx.setAttribute(org.openecomp.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
}
} catch (RequestFailedException e) {
- doFailure(rc, e.getStatus(), e.getMessage());
- }
- catch (ResourceNotFoundException e) {
+ doFailure(rc, e.getStatus(), e.getMessage());
+ } catch (ResourceNotFoundException e) {
String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url);
logger.error(msg);
metricsLogger.error(msg);
@@ -291,33 +244,31 @@ public class RestartServer extends ProviderServerOperation {
}
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws UnknownProviderException {
-
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws UnknownProviderException {
setMDC(RESTART_SERVICE.toString(), "App-C IaaS Adapter:Restart", ADAPTER_NAME);
logOperation(Msg.RESTARTING_SERVER, params, context);
-
- /*
- * Set Time for Metrics Logger
- */
+
+ setTimeForMetricsLogger("execute restart");
+
+ metricsLogger.info("Executing Provider Operation: Restart");
+
+ return restartServer(params, context);
+ }
+
+ private void setTimeForMetricsLogger(String targetServiceName) {
long startTime = System.currentTimeMillis();
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
String durationStr = String.valueOf(duration);
String endTimeStrUTC = df.format(new Date());
MDC.put("EndTimestamp", endTimeStrUTC);
MDC.put("ElapsedTime", durationStr);
MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "execute restart");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.RestartServer");
-
- metricsLogger.info("Executing Provider Operation: Restart");
-
-
- return restartServer(params, context);
+ MDC.put("TargetServiceName", targetServiceName);
+ MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.RestartServer");
}
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RestoreStack.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RestoreStack.java
index afd54963c..8ce1707ad 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RestoreStack.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/RestoreStack.java
@@ -24,17 +24,6 @@
package org.openecomp.appc.adapter.iaas.provider.operation.impl;
-import org.openecomp.appc.Constants;
-import org.openecomp.appc.adapter.iaas.ProviderAdapter;
-import org.openecomp.appc.adapter.iaas.impl.RequestContext;
-import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
-import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
-import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderStackOperation;
-import org.openecomp.appc.adapter.openstack.heat.SnapshotResource;
-import org.openecomp.appc.adapter.openstack.heat.StackResource;
-import org.openecomp.appc.exceptions.APPCException;
-import org.openecomp.appc.exceptions.UnknownProviderException;
-import org.openecomp.appc.i18n.Msg;
import com.att.cdp.exceptions.ResourceNotFoundException;
import com.att.cdp.exceptions.ZoneException;
import com.att.cdp.openstack.OpenStackContext;
@@ -47,17 +36,25 @@ import com.att.cdp.zones.spi.RequestState;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.eelf.i18n.EELFResourceManager;
-import org.openecomp.sdnc.sli.SvcLogicContext;
import com.woorea.openstack.base.client.OpenStackBaseException;
import com.woorea.openstack.heat.Heat;
import org.glassfish.grizzly.http.util.HttpStatus;
+import org.openecomp.appc.Constants;
+import org.openecomp.appc.adapter.iaas.ProviderAdapter;
+import org.openecomp.appc.adapter.iaas.impl.RequestContext;
+import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
+import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
+import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderStackOperation;
+import org.openecomp.appc.adapter.openstack.heat.SnapshotResource;
+import org.openecomp.appc.adapter.openstack.heat.StackResource;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.i18n.Msg;
+import org.openecomp.sdnc.sli.SvcLogicContext;
import java.util.Map;
-import static org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation.RESTART_SERVICE;
import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-
public class RestoreStack extends ProviderStackOperation {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestoreStack.class);
@@ -94,7 +91,8 @@ public class RestoreStack extends ProviderStackOperation {
}
- public Stack restoreStack(Map<String, String> params, SvcLogicContext ctx) throws IllegalArgumentException, APPCException {
+ public Stack restoreStack(Map<String, String> params, SvcLogicContext ctx)
+ throws IllegalArgumentException, APPCException {
Stack stack = null;
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
@@ -107,8 +105,11 @@ public class RestoreStack extends ProviderStackOperation {
try {
- validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL, ProviderAdapter.PROPERTY_PROVIDER_NAME,
- ProviderAdapter.PROPERTY_STACK_ID, ProviderAdapter.PROPERTY_INPUT_SNAPSHOT_ID);
+ validateParametersExist(params,
+ ProviderAdapter.PROPERTY_INSTANCE_URL,
+ ProviderAdapter.PROPERTY_PROVIDER_NAME,
+ ProviderAdapter.PROPERTY_STACK_ID,
+ ProviderAdapter.PROPERTY_INPUT_SNAPSHOT_ID);
String stackId = params.get(ProviderAdapter.PROPERTY_STACK_ID);
vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
@@ -116,7 +117,6 @@ public class RestoreStack extends ProviderStackOperation {
context = resolveContext(rc, params, appName, vm_url);
-
if (context != null) {
stack = lookupStack(rc, context, stackId);
logger.debug(Msg.STACK_FOUND, vm_url, context.getTenantName(), stack.getStatus().toString());
@@ -125,7 +125,7 @@ public class RestoreStack extends ProviderStackOperation {
logger.info(EELFResourceManager.format(Msg.TERMINATE_STACK, stack.getName()));
context.close();
doSuccess(rc);
- }else {
+ } else {
ctx.setAttribute(Constants.DG_ATTRIBUTE_STATUS, "failure");
}
@@ -134,7 +134,8 @@ public class RestoreStack extends ProviderStackOperation {
logger.error(msg);
doFailure(rc, HttpStatus.NOT_FOUND_404, msg, e);
} catch (RequestFailedException e) {
- logger.error(EELFResourceManager.format(Msg.MISSING_PARAMETER_IN_REQUEST, e.getReason(), "restoreStack"));
+ logger.error(EELFResourceManager.format(Msg.MISSING_PARAMETER_IN_REQUEST,
+ e.getReason(), "restoreStack"));
doFailure(rc, e.getStatus(), e.getMessage(), e);
} catch (Throwable t) {
String msg = EELFResourceManager.format(Msg.STACK_OPERATION_EXCEPTION, t, t.getClass().getSimpleName(),
@@ -146,8 +147,8 @@ public class RestoreStack extends ProviderStackOperation {
}
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws APPCException {
setMDC(Operation.RESTORE_STACK.toString(), "App-C IaaS Adapter:Restore-Stack", ADAPTER_NAME);
logOperation(Msg.RESTORING_STACK, params, context);
return restoreStack(params, context);
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/SnapshotStack.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/SnapshotStack.java
index 9b2c3f58c..35bbae3ae 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/SnapshotStack.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/SnapshotStack.java
@@ -24,21 +24,6 @@
package org.openecomp.appc.adapter.iaas.provider.operation.impl;
-import org.openecomp.appc.Constants;
-import org.openecomp.appc.adapter.iaas.ProviderAdapter;
-import org.openecomp.appc.adapter.iaas.impl.RequestContext;
-import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
-import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
-import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
-import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderStackOperation;
-import org.openecomp.appc.adapter.openstack.heat.SnapshotResource;
-import org.openecomp.appc.adapter.openstack.heat.StackResource;
-import org.openecomp.appc.adapter.openstack.heat.model.CreateSnapshotParams;
-import org.openecomp.appc.adapter.openstack.heat.model.Snapshot;
-import org.openecomp.appc.configuration.Configuration;
-import org.openecomp.appc.configuration.ConfigurationFactory;
-import org.openecomp.appc.exceptions.APPCException;
-import org.openecomp.appc.i18n.Msg;
import com.att.cdp.exceptions.ResourceNotFoundException;
import com.att.cdp.exceptions.ZoneException;
import com.att.cdp.openstack.OpenStackContext;
@@ -51,32 +36,40 @@ import com.att.cdp.zones.spi.RequestState;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.eelf.i18n.EELFResourceManager;
-import org.openecomp.sdnc.sli.SvcLogicContext;
import com.woorea.openstack.base.client.OpenStackBaseException;
import com.woorea.openstack.heat.Heat;
import org.glassfish.grizzly.http.util.HttpStatus;
-
-import java.util.Map;
-
-import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-
+import org.openecomp.appc.Constants;
+import org.openecomp.appc.adapter.iaas.ProviderAdapter;
+import org.openecomp.appc.adapter.iaas.impl.RequestContext;
+import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
+import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
+import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderStackOperation;
+import org.openecomp.appc.adapter.openstack.heat.SnapshotResource;
+import org.openecomp.appc.adapter.openstack.heat.StackResource;
+import org.openecomp.appc.adapter.openstack.heat.model.CreateSnapshotParams;
+import org.openecomp.appc.adapter.openstack.heat.model.Snapshot;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.i18n.Msg;
+import org.openecomp.sdnc.sli.SvcLogicContext;
import org.slf4j.MDC;
+
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Map;
import java.util.TimeZone;
+import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-/**
- * @since September 26, 2016
- */
public class SnapshotStack extends ProviderStackOperation {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(SnapshotStack.class);
private static EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
- private Snapshot snapshotStack(@SuppressWarnings("unused") RequestContext rc, Stack stack) throws ZoneException, RequestFailedException {
+ private Snapshot snapshotStack(@SuppressWarnings("unused") RequestContext rc, Stack stack)
+ throws ZoneException, RequestFailedException {
Snapshot snapshot = new Snapshot();
Context context = stack.getContext();
@@ -92,25 +85,8 @@ public class SnapshotStack extends ProviderStackOperation {
Heat heat = heatConnector.getClient();
SnapshotResource snapshotResource = new SnapshotResource(heat);
-
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "snapshot stack");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.SnapshotStack");
+
+ setTimeForMetricsLogger();
try {
@@ -129,46 +105,24 @@ public class SnapshotStack extends ProviderStackOperation {
return snapshot;
}
-
- public Stack snapshotStack(Map<String, String> params, SvcLogicContext ctx) throws IllegalArgumentException, APPCException {
+ public Stack snapshotStack(Map<String, String> params, SvcLogicContext ctx)
+ throws IllegalArgumentException, APPCException {
Stack stack = null;
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
-
ctx.setAttribute("SNAPSHOT_STATUS", "STACK_NOT_FOUND");
- String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+
+ setTimeForMetricsLogger();
String vm_url = null;
Context context = null;
-
- /*
- * Set Time for Metrics Logger
- */
- long startTime = System.currentTimeMillis();
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
- String durationStr = String.valueOf(duration);
- String endTimeStrUTC = df.format(new Date());
- MDC.put("EndTimestamp", endTimeStrUTC);
- MDC.put("ElapsedTime", durationStr);
- MDC.put("TargetEntity", "cdp");
- MDC.put("TargetServiceName", "snapshot stack");
- MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.SnapshotStack");
-
-
try {
-
validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
ProviderAdapter.PROPERTY_PROVIDER_NAME, ProviderAdapter.PROPERTY_STACK_ID);
String stackId = params.get(ProviderAdapter.PROPERTY_STACK_ID);
+ String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
-
context = resolveContext(rc, params, appName, vm_url);
if (context != null) {
@@ -196,8 +150,10 @@ public class SnapshotStack extends ProviderStackOperation {
metricsLogger.error(msg);
doFailure(rc, HttpStatus.NOT_FOUND_404, msg, e);
} catch (RequestFailedException e) {
- logger.error(EELFResourceManager.format(Msg.MISSING_PARAMETER_IN_REQUEST, e.getReason(), "snapshotStack"));
- metricsLogger.error(EELFResourceManager.format(Msg.MISSING_PARAMETER_IN_REQUEST, e.getReason(), "snapshotStack"));
+ logger.error(EELFResourceManager.format(Msg.MISSING_PARAMETER_IN_REQUEST,
+ e.getReason(), "snapshotStack"));
+ metricsLogger.error(EELFResourceManager.format(Msg.MISSING_PARAMETER_IN_REQUEST,
+ e.getReason(), "snapshotStack"));
doFailure(rc, e.getStatus(), e.getMessage(), e);
} catch (Throwable t) {
String msg = EELFResourceManager.format(Msg.STACK_OPERATION_EXCEPTION, t, t.getClass().getSimpleName(),
@@ -210,21 +166,25 @@ public class SnapshotStack extends ProviderStackOperation {
}
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws APPCException {
setMDC(Operation.SNAPSHOT_STACK.toString(), "App-C IaaS Adapter:Snapshot-Stack", ADAPTER_NAME);
logOperation(Msg.SNAPSHOTING_STACK, params, context);
-
- /*
- * Set Time for Metrics Logger
- */
+
+ setTimeForMetricsLogger();
+
+ metricsLogger.info("Executing Provider Operation: Snapshot Stack");
+
+ return snapshotStack(params, context);
+ }
+
+ private void setTimeForMetricsLogger() {
long startTime = System.currentTimeMillis();
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
String durationStr = String.valueOf(duration);
String endTimeStrUTC = df.format(new Date());
MDC.put("EndTimestamp", endTimeStrUTC);
@@ -232,9 +192,5 @@ public class SnapshotStack extends ProviderStackOperation {
MDC.put("TargetEntity", "cdp");
MDC.put("TargetServiceName", "snapshot stack");
MDC.put("ClassName", "org.openecomp.appc.adapter.iaas.provider.operation.impl.SnapshotStack");
-
- metricsLogger.info("Executing Provider Operation: Snapshot Stack");
-
- return snapshotStack(params, context);
}
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/StartServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/StartServer.java
index d23c1ed99..f2186e195 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/StartServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/StartServer.java
@@ -86,17 +86,17 @@ public class StartServer extends ProviderServerOperation {
logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString());
String msg;
- /*
- * We determine what to do based on the current state of the server
- */
-
- /*
- * Pending is a bit of a special case. If we find the server is in a
- * pending state, then the provider is in the process of changing state
- * of the server. So, lets try to wait a little bit and see if the state
- * settles down to one we can deal with. If not, then we have to fail
- * the request.
- */
+ /*
+ * We determine what to do based on the current state of the server
+ */
+
+ /*
+ * Pending is a bit of a special case. If we find the server is in a
+ * pending state, then the provider is in the process of changing state
+ * of the server. So, lets try to wait a little bit and see if the state
+ * settles down to one we can deal with. If not, then we have to fail
+ * the request.
+ */
if (server.getStatus().equals(Server.Status.PENDING)) {
waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING, Server.Status.ERROR,
@@ -106,11 +106,11 @@ public class StartServer extends ProviderServerOperation {
switch (server.getStatus()) {
case DELETED:
// Nothing to do, the server is gone
- msg = EELFResourceManager.format(Msg.SERVER_DELETED, server.getName(), server.getId(),
- server.getTenantId(), "started");
+ msg = EELFResourceManager.format(Msg.SERVER_DELETED,
+ server.getName(), server.getId(), server.getTenantId(), "started");
logger.error(msg);
- // metricsLogger.error(msg);
- throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+ throw new RequestFailedException(
+ "Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
case RUNNING:
// Nothing to do, the server is already running
@@ -119,11 +119,11 @@ public class StartServer extends ProviderServerOperation {
case ERROR:
// Server is in error state
- msg = EELFResourceManager.format(Msg.SERVER_ERROR_STATE, server.getName(), server.getId(),
- server.getTenantId(), "start");
+ msg = EELFResourceManager.format(Msg.SERVER_ERROR_STATE,
+ server.getName(), server.getId(), server.getTenantId(), "start");
logger.error(msg);
- // metricsLogger.error(msg);
- throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+ throw new RequestFailedException(
+ "Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
case READY:
// Server is stopped attempt to start the server
@@ -135,14 +135,12 @@ public class StartServer extends ProviderServerOperation {
// if paused, un-pause it
rc.reset();
unpauseServer(rc, server);
- // metricsLogger.info("Server status: PAUSED");
break;
case SUSPENDED:
// Attempt to resume the suspended server
rc.reset();
resumeServer(rc, server);
- // metricsLogger.info("Server status: SUSPENDED");
break;
default:
@@ -151,8 +149,8 @@ public class StartServer extends ProviderServerOperation {
server.getTenantId(), server.getStatus().name());
generateEvent(rc, false, msg);
logger.error(msg);
- // metricsLogger.error(msg);
- throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+ throw new RequestFailedException(
+ "Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
}
context.close();
doSuccess(rc);
@@ -180,8 +178,8 @@ public class StartServer extends ProviderServerOperation {
}
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws APPCException {
setMDC(Operation.START_SERVICE.toString(), "App-C IaaS Adapter:Start", ADAPTER_NAME);
logOperation(Msg.STARTING_SERVER, params, context);
return startServer(params, context);
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/StopServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/StopServer.java
index b6e13d86e..e5a6e8e4a 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/StopServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/StopServer.java
@@ -49,7 +49,6 @@ import java.util.Map;
import static org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation.STOP_SERVICE;
import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-
public class StopServer extends ProviderServerOperation {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(StopServer.class);
@@ -90,16 +89,16 @@ public class StopServer extends ProviderServerOperation {
String msg;
/*
- * We determine what to do based on the current state of the server
- */
+ * We determine what to do based on the current state of the server
+ */
- /*
- * Pending is a bit of a special case. If we find the server is in a
- * pending state, then the provider is in the process of changing state
- * of the server. So, lets try to wait a little bit and see if the state
- * settles down to one we can deal with. If not, then we have to fail
- * the request.
- */
+ /*
+ * Pending is a bit of a special case. If we find the server is in a
+ * pending state, then the provider is in the process of changing state
+ * of the server. So, lets try to wait a little bit and see if the state
+ * settles down to one we can deal with. If not, then we have to fail
+ * the request.
+ */
if (server.getStatus().equals(Server.Status.PENDING)) {
waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING, Server.Status.ERROR,
@@ -109,12 +108,13 @@ public class StopServer extends ProviderServerOperation {
switch (server.getStatus()) {
case DELETED:
// Nothing to do, the server is gone
- msg = EELFResourceManager.format(Msg.SERVER_DELETED, server.getName(), server.getId(),
- server.getTenantId(), "stopped");
+ msg = EELFResourceManager.format(Msg.SERVER_DELETED,
+ server.getName(), server.getId(), server.getTenantId(), "stopped");
generateEvent(rc, false, msg);
logger.error(msg);
metricsLogger.error(msg);
- throw new RequestFailedException("Stop Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+ throw new RequestFailedException(
+ "Stop Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
case RUNNING:
// Attempt to stop the server
@@ -125,12 +125,13 @@ public class StopServer extends ProviderServerOperation {
case ERROR:
// Server is in error state
- msg = EELFResourceManager.format(Msg.SERVER_ERROR_STATE, server.getName(), server.getId(),
- server.getTenantId(), "stop");
+ msg = EELFResourceManager.format(Msg.SERVER_ERROR_STATE,
+ server.getName(), server.getId(), server.getTenantId(), "stop");
generateEvent(rc, false, msg);
logger.error(msg);
metricsLogger.error(msg);
- throw new RequestFailedException("Stop Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+ throw new RequestFailedException(
+ "Stop Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
case READY:
// Nothing to do, the server was already stopped
@@ -157,12 +158,13 @@ public class StopServer extends ProviderServerOperation {
default:
// Hmmm, unknown status, should never occur
- msg = EELFResourceManager.format(Msg.UNKNOWN_SERVER_STATE, server.getName(), server.getId(),
- server.getTenantId(), server.getStatus().name());
+ msg = EELFResourceManager.format(Msg.UNKNOWN_SERVER_STATE,
+ server.getName(), server.getId(), server.getTenantId(), server.getStatus().name());
generateEvent(rc, false, msg);
logger.error(msg);
metricsLogger.error(msg);
- throw new RequestFailedException("Stop Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+ throw new RequestFailedException(
+ "Stop Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
}
context.close();
doSuccess(rc);
@@ -184,7 +186,8 @@ public class StopServer extends ProviderServerOperation {
doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
}
} catch (RequestFailedException e) {
- logger.error(EELFResourceManager.format(Msg.STOP_SERVER_FAILED, appName, "n/a", "n/a", e.getMessage()));
+ logger.error(EELFResourceManager.format(Msg.STOP_SERVER_FAILED,
+ appName, "n/a", "n/a", e.getMessage()));
doFailure(rc, e.getStatus(), e.getMessage());
}
@@ -192,8 +195,8 @@ public class StopServer extends ProviderServerOperation {
}
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws APPCException {
setMDC(STOP_SERVICE.toString(), "App-C IaaS Adapter:Stop", ADAPTER_NAME);
logOperation(Msg.STOPPING_SERVER, params, context);
return stopServer(params, context);
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/TerminateServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/TerminateServer.java
index 77c325b92..c6ea1f40f 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/TerminateServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/TerminateServer.java
@@ -24,19 +24,6 @@
package org.openecomp.appc.adapter.iaas.provider.operation.impl;
-import org.openecomp.appc.Constants;
-import org.openecomp.appc.adapter.iaas.ProviderAdapter;
-import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
-import org.openecomp.appc.adapter.iaas.impl.RequestContext;
-import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
-import org.openecomp.appc.adapter.iaas.impl.VMURL;
-import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Outcome;
-import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
-import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
-import org.openecomp.appc.configuration.Configuration;
-import org.openecomp.appc.configuration.ConfigurationFactory;
-import org.openecomp.appc.exceptions.UnknownProviderException;
-import org.openecomp.appc.i18n.Msg;
import com.att.cdp.exceptions.ContextConnectionException;
import com.att.cdp.exceptions.ResourceNotFoundException;
import com.att.cdp.exceptions.ZoneException;
@@ -48,17 +35,24 @@ import com.att.cdp.zones.model.Server;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.eelf.i18n.EELFResourceManager;
-import org.openecomp.sdnc.sli.SvcLogicContext;
import org.glassfish.grizzly.http.util.HttpStatus;
-import org.slf4j.MDC;
+import org.openecomp.appc.Constants;
+import org.openecomp.appc.adapter.iaas.ProviderAdapter;
+import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
+import org.openecomp.appc.adapter.iaas.impl.RequestContext;
+import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
+import org.openecomp.appc.adapter.iaas.impl.VMURL;
+import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Outcome;
+import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
+import org.openecomp.appc.exceptions.UnknownProviderException;
+import org.openecomp.appc.i18n.Msg;
+import org.openecomp.sdnc.sli.SvcLogicContext;
import java.util.Map;
import static org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation.RESTART_SERVICE;
-import static org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation.STOP_SERVICE;
import static org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation.TERMINATE_SERVICE;
import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
public class TerminateServer extends ProviderServerOperation {
@@ -71,8 +65,8 @@ public class TerminateServer extends ProviderServerOperation {
* The request context that manages the state and recovery of the request for the life of its processing.
* @param server
* The server to be started
- * @throws ZoneException
- * @throws RequestFailedException
+ * @throws ZoneException when error occurs
+ * @throws RequestFailedException when request failed
*/
@SuppressWarnings("nls")
private void deleteServer(RequestContext rc, Server server) throws ZoneException, RequestFailedException {
@@ -110,7 +104,7 @@ public class TerminateServer extends ProviderServerOperation {
* The request context that manages the state and recovery of the request for the life of its processing.
* @param server
* The server object representing the server we want to operate on
- * @throws ZoneException
+ * @throws ZoneException when error occurs
*/
@SuppressWarnings("nls")
private void terminateServer(RequestContext rc, Server server) throws ZoneException, RequestFailedException {
@@ -121,7 +115,8 @@ public class TerminateServer extends ProviderServerOperation {
*/
String msg;
if (server.getStatus().equals(Server.Status.PENDING)) {
- waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING, Server.Status.ERROR, Server.Status.SUSPENDED, Server.Status.PAUSED);
+ waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING, Server.Status.ERROR,
+ Server.Status.SUSPENDED, Server.Status.PAUSED);
}
/*
@@ -218,7 +213,7 @@ public class TerminateServer extends ProviderServerOperation {
logger.info(EELFResourceManager.format(Msg.TERMINATE_SERVER, server.getName()));
context.close();
doSuccess(rc);
- }else{
+ } else {
ctx.setAttribute("TERMINATE_STATUS", "SERVER_NOT_FOUND");
}
} catch (ResourceNotFoundException e) {
@@ -233,7 +228,8 @@ public class TerminateServer extends ProviderServerOperation {
doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
}
} catch (RequestFailedException e) {
- logger.error(EELFResourceManager.format(Msg.TERMINATE_SERVER_FAILED, appName, "n/a", "n/a", e.getMessage()));
+ logger.error(EELFResourceManager.format(Msg.TERMINATE_SERVER_FAILED,
+ appName, "n/a", "n/a", e.getMessage()));
doFailure(rc, e.getStatus(), e.getMessage());
ctx.setAttribute("TERMINATE_STATUS", "ERROR");
}
@@ -242,8 +238,8 @@ public class TerminateServer extends ProviderServerOperation {
}
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws UnknownProviderException {
-
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws UnknownProviderException {
setMDC(TERMINATE_SERVICE.toString(), "App-C IaaS Adapter:Terminate", ADAPTER_NAME);
logOperation(Msg.TERMINATING_SERVER, params, context);
return terminateServer(params,context);
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/TerminateStack.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/TerminateStack.java
index d2cbf7a6d..4a82e160b 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/TerminateStack.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/TerminateStack.java
@@ -48,9 +48,6 @@ import java.util.Map;
import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-/**
- * @since September 26, 2016
- */
public class TerminateStack extends ProviderStackOperation {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(EvacuateServer.class);
@@ -73,7 +70,8 @@ public class TerminateStack extends ProviderStackOperation {
}
@SuppressWarnings("nls")
- public Stack terminateStack(Map<String, String> params, SvcLogicContext ctx) throws IllegalArgumentException, APPCException {
+ public Stack terminateStack(Map<String, String> params, SvcLogicContext ctx)
+ throws IllegalArgumentException, APPCException {
Stack stack = null;
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
@@ -101,7 +99,8 @@ public class TerminateStack extends ProviderStackOperation {
logger.info(EELFResourceManager.format(Msg.TERMINATE_STACK, stack.getName()));
context.close();
doSuccess(rc);
- String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "TerminateStack", vm_url);
+ String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE,
+ "TerminateStack", vm_url);
ctx.setAttribute(org.openecomp.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
}
} catch (ResourceNotFoundException e) {
@@ -122,8 +121,8 @@ public class TerminateStack extends ProviderStackOperation {
}
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws APPCException {
setMDC(Operation.TERMINATE_STACK.toString(), "App-C IaaS Adapter:Terminate-Stack", ADAPTER_NAME);
logOperation(Msg.TERMINATING_STACK, params, context);
return terminateStack(params, context);
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/VmStatuschecker.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/VmStatuschecker.java
index c2258b1bb..e5464302a 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/VmStatuschecker.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/openecomp/appc/adapter/iaas/provider/operation/impl/VmStatuschecker.java
@@ -24,6 +24,14 @@
package org.openecomp.appc.adapter.iaas.provider.operation.impl;
+import com.att.cdp.exceptions.ResourceNotFoundException;
+import com.att.cdp.zones.Context;
+import com.att.cdp.zones.model.ModelObject;
+import com.att.cdp.zones.model.Server;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+import org.glassfish.grizzly.http.util.HttpStatus;
import org.openecomp.appc.Constants;
import org.openecomp.appc.adapter.iaas.ProviderAdapter;
import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
@@ -32,39 +40,28 @@ import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
import org.openecomp.appc.adapter.iaas.impl.VMURL;
import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Outcome;
-import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
import org.openecomp.appc.configuration.Configuration;
import org.openecomp.appc.configuration.ConfigurationFactory;
import org.openecomp.appc.exceptions.UnknownProviderException;
import org.openecomp.appc.i18n.Msg;
-import com.att.cdp.exceptions.ResourceNotFoundException;
-import com.att.cdp.zones.Context;
-import com.att.cdp.zones.model.ModelObject;
-import com.att.cdp.zones.model.Server;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.att.eelf.i18n.EELFResourceManager;
import org.openecomp.sdnc.sli.SvcLogicContext;
-import org.glassfish.grizzly.http.util.HttpStatus;
-import org.slf4j.MDC;
import java.util.Map;
import static org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation.RESTART_SERVICE;
import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
-import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
-
public class VmStatuschecker extends ProviderServerOperation {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(VmStatuschecker.class);
private static final Configuration configuration = ConfigurationFactory.getConfiguration();
- /* *********************************************************************************/
- /* DEVEN PANCHAL: This method is used to check the status of the VM */
- /**********************************************************************************/
- public Server vmStatuschecker(Map<String, String> params, SvcLogicContext ctx) throws UnknownProviderException, IllegalArgumentException {
+ /**
+ * to check the status of the VM
+ */
+ public Server vmStatuschecker(Map<String, String> params, SvcLogicContext ctx)
+ throws UnknownProviderException, IllegalArgumentException {
Server server = null;
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
@@ -132,7 +129,8 @@ public class VmStatuschecker extends ProviderServerOperation {
svcLogic.setStatus(Outcome.SUCCESS.toString());
svcLogic.setAttribute("org.openecomp.statusofvm", statusofVM);
svcLogic.setAttribute(Constants.STATUS_OF_VM, statusofVM);
- svcLogic.setAttribute(Constants.ATTRIBUTE_ERROR_CODE, Integer.toString(HttpStatus.OK_200.getStatusCode()));
+ svcLogic.setAttribute(Constants.ATTRIBUTE_ERROR_CODE,
+ Integer.toString(HttpStatus.OK_200.getStatusCode()));
}
} catch (ResourceNotFoundException e) {
String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url);
@@ -151,11 +149,9 @@ public class VmStatuschecker extends ProviderServerOperation {
return server;
}
- /* *********************************************************************************/
-
@Override
- protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws UnknownProviderException {
-
+ protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+ throws UnknownProviderException {
setMDC(Operation.VMSTATUSCHECK_SERVICE.toString(), "App-C IaaS Adapter:VmStatusCheck", ADAPTER_NAME);
logOperation(Msg.CHECKING_SERVER, params, context);
return vmStatuschecker(params, context);