summaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main
diff options
context:
space:
mode:
authorModaboina, Kusumakumari (km583p) <km583p@us.att.com>2019-03-01 15:38:31 -0500
committerPatrick Brady <patrick.brady@att.com>2019-03-05 22:38:01 +0000
commit6a0305cdb8a3d1ceb3038dd701bfc73de5d9a05e (patch)
tree04ae6cd652595c72a8c336d19f0cab58b4d29026 /appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main
parent20b518d37241d49088a3a5aae1208a5f79e4c306 (diff)
added skip hpervisor check and other adapterchange
Issue-ID: APPC-1378 Change-Id: Ia8db114af1347a9523676034fce56640f523e523 Signed-off-by: Modaboina, Kusumakumari (km583p) <km583p@us.att.com>
Diffstat (limited to 'appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main')
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java43
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/CreateSnapshot.java22
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java11
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebootServer.java38
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebuildServer.java69
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/StartServer.java127
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/StopServer.java15
7 files changed, 225 insertions, 100 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java
index ccfcf9dbf..aa3c6c1d6 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* ================================================================================
@@ -57,6 +57,8 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.eelf.i18n.EELFResourceManager;
import com.woorea.openstack.base.client.OpenStackBaseException;
+import org.apache.commons.lang.StringUtils;
+import org.onap.appc.adapter.iaas.provider.operation.common.constants.Property;
public class AttachVolumeServer extends ProviderServerOperation {
@@ -71,6 +73,10 @@ public class AttachVolumeServer extends ProviderServerOperation {
String vmUrl = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
String volumeId = params.get(ProviderAdapter.VOLUME_ID);
String device = params.get(ProviderAdapter.DEVICE);
+ if (StringUtils.isBlank(device)) {
+ logger.info("Setting device to null");
+ device = null;
+ }
VMURL vm = VMURL.parseURL(vmUrl);
Context context;
String tenantName = "Unknown";// to be used also in case of exception
@@ -81,6 +87,10 @@ public class AttachVolumeServer extends ProviderServerOperation {
IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL));
String identStr = (ident == null) ? null : ident.toString();
context = getContext(requestContext, vmUrl, identStr);
+ String skipHypervisorCheck = configuration.getProperty(Property.SKIP_HYPERVISOR_CHECK);
+ if (skipHypervisorCheck == null && ctx != null) {
+ skipHypervisorCheck = ctx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
+ }
if (context != null) {
tenantName = context.getTenantName();// this variable also is
// used in case of
@@ -89,6 +99,10 @@ public class AttachVolumeServer extends ProviderServerOperation {
server = lookupServer(requestContext, context, vm.getServerId());
logger.debug(Msg.SERVER_FOUND, vmUrl, context.getTenantName(), server.getStatus().toString());
Context contx = server.getContext();
+ if (!"true".equalsIgnoreCase(skipHypervisorCheck)) {
+ // Check of the Hypervisor for the VM Server is UP and reachable
+ checkHypervisor(server);
+ }
ComputeService service = contx.getComputeService();
if ((volumeId == null || volumeId.isEmpty()) || (device == null || device.isEmpty())) {
ctx.setAttribute("VOLUME_STATUS", "FAILURE");
@@ -165,14 +179,19 @@ public class AttachVolumeServer extends ProviderServerOperation {
Map.Entry volumes = (Map.Entry) it.next();
if (map != null && !(map.isEmpty())) {
logger.info("volumes available before attach");
- logger.info("device" + volumes.getKey() + "Values" + volumes.getValue());
- if (volumes.getKey().equals(device) && (volumes.getValue().equals(volumeId))) {
- logger.info("Device " + volumes.getKey() + "Volumes" + volumes.getValue());
+ logger.info("device" + volumes.getKey() + " Values " + volumes.getValue());
+ if (StringUtils.isBlank(device)) {
+ if (volumes.getValue().equals(volumeId)) {
+ logger.info("Device " + volumes.getKey() + " Volumes " + volumes.getValue());
+ isValid = true;
+ }
+ } else if (volumes.getKey().equals(device) && (volumes.getValue().equals(volumeId))) {
+ logger.info("Device " + volumes.getKey() + " Volumes " + volumes.getValue());
isValid = true;
}
}
}
- logger.info("AttachVolumeFlag" + isValid);
+ logger.info("AttachVolumeFlag " + isValid);
return isValid;
}
@@ -189,15 +208,21 @@ public class AttachVolumeServer extends ProviderServerOperation {
logger.info("volumes available after attach ");
while (it.hasNext()) {
Map.Entry volumes = (Map.Entry) it.next();
- logger.info(" devices " + volumes.getKey() + "volumes" + volumes.getValue());
- if (volumes.getKey().equals(device) && (volumes.getValue().equals(volumeId))) {
- logger.info("Device" + volumes.getKey() + "Volume" + volumes.getValue());
+ logger.info(" devices " + volumes.getKey() + " volumes " + volumes.getValue());
+ if (StringUtils.isBlank(device)) {
+ if (volumes.getValue().equals(volumeId)) {
+ logger.info("Device " + volumes.getKey() + "Volumes " + volumes.getValue());
+ isValid = true;
+ break;
+ }
+ } else if (volumes.getKey().equals(device) && (volumes.getValue().equals(volumeId))) {
+ logger.info("Device " + volumes.getKey() + " Volume " + volumes.getValue());
isValid = true;
break;
}
}
if (isValid) {
- logger.info("AttachVolume" + rc.getAttempts() + "No.of attempts");
+ logger.info("AttachVolume " + rc.getAttempts() + " No.of attempts ");
break;
} else {
rc.delay();
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/CreateSnapshot.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/CreateSnapshot.java
index fe08e1856..909f31fd1 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/CreateSnapshot.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/CreateSnapshot.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -60,6 +60,7 @@ import java.util.Date;
import java.util.Map;
import static org.onap.appc.adapter.iaas.provider.operation.common.constants.Constants.DATE_FORMAT;
import static org.onap.appc.adapter.utils.Constants.ADAPTER_NAME;
+import org.onap.appc.adapter.iaas.provider.operation.common.constants.Property;
public class CreateSnapshot extends ProviderServerOperation {
@@ -107,7 +108,8 @@ public class CreateSnapshot extends ProviderServerOperation {
throw new RequestFailedException("Stop Server", msg, HttpStatus.BAD_GATEWAY_502, server);
}
rc.reset();
- // Locate snapshot image - image names containing colon must be prefixed by in: and surrounded with quotes
+ // Locate snapshot image - image names containing colon must be prefixed by in:
+ // and surrounded with quotes
Image snapshot = null;
while (rc.attempt()) {
try {
@@ -152,7 +154,7 @@ public class CreateSnapshot extends ProviderServerOperation {
return null;
IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL));
String identStr = (ident == null) ? null : ident.toString();
- snapshot = createSnapshotNested(snapshot, rc, vm, vm_url, identStr);
+ snapshot = createSnapshotNested(snapshot, rc, vm, vm_url, identStr,ctx);
} catch (RequestFailedException e) {
doFailure(rc, e.getStatus(), e.getMessage());
}
@@ -160,7 +162,7 @@ public class CreateSnapshot extends ProviderServerOperation {
}
private Image createSnapshotNested(Image SnapShot, RequestContext RcContext, VMURL vm, String vmUrl,
- String identStr) throws APPCException {
+ String identStr, SvcLogicContext ctx) throws APPCException {
String msg;
Context context = null;
String tenantName = "Unknown";// this variable is also used in catch
@@ -169,6 +171,18 @@ public class CreateSnapshot extends ProviderServerOperation {
if (context != null) {
tenantName = context.getTenantName();
Server server = lookupServer(RcContext, context, vm.getServerId());
+ // Is the skip Hypervisor check attribute populated?
+ String skipHypervisorCheck = configuration.getProperty(Property.SKIP_HYPERVISOR_CHECK);
+ if (skipHypervisorCheck == null && ctx != null) {
+ skipHypervisorCheck = ctx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
+ }
+ // 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);
+ }
+
logger.debug(Msg.SERVER_FOUND, vmUrl, tenantName, server.getStatus().toString());
if (hasImageAccess(RcContext, context)) {
SnapShot = createSnapshot(RcContext, server);
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java
index a9014a066..0f79d64bd 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java
@@ -56,6 +56,7 @@ import com.att.cdp.openstack.util.ExceptionMapper;
import org.onap.appc.i18n.Msg;
import com.woorea.openstack.base.client.OpenStackBaseException;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.appc.adapter.iaas.provider.operation.common.constants.Property;
public class DettachVolumeServer extends ProviderServerOperation {
private final EELFLogger logger = EELFManager.getInstance().getLogger(DettachVolumeServer.class);
@@ -86,12 +87,22 @@ public class DettachVolumeServer extends ProviderServerOperation {
IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL));
String identStr = (ident == null) ? null : ident.toString();
context = getContext(requestContext, vmUrl, identStr);
+ String skipHypervisorCheck = configuration.getProperty(Property.SKIP_HYPERVISOR_CHECK);
+ if (skipHypervisorCheck == null && ctx != null) {
+ skipHypervisorCheck = ctx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
+ }
if (context != null) {
tenantName = context.getTenantName();// this variable also is
// used in case of
// exception
requestContext.reset();
server = lookupServer(requestContext, context, vm.getServerId());
+ // Always perform Hypervisor check
+ // unless the skip is set to true
+ if (!"true".equalsIgnoreCase(skipHypervisorCheck)) {
+ // Check of the Hypervisor for the VM Server is UP and reachable
+ checkHypervisor(server);
+ }
logger.debug(Msg.SERVER_FOUND, vmUrl, context.getTenantName(), server.getStatus().toString());
if (volumeId == null || volumeId.isEmpty()) {
ctx.setAttribute("VOLUME_STATUS", "FAILURE");
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebootServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebootServer.java
index b6cf8cc58..363f61455 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebootServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebootServer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* ================================================================================
@@ -50,12 +50,15 @@ 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 static org.onap.appc.adapter.iaas.provider.operation.common.enums.Operation.REBOOT_SERVICE;
+import org.onap.appc.adapter.iaas.provider.operation.common.constants.Property;
public class RebootServer extends ProviderServerOperation {
private final EELFLogger logger = EELFManager.getInstance().getLogger(RebootServer.class);
private static final Configuration config = ConfigurationFactory.getConfiguration();
- private static final Integer NO_OF_ATTEMPTS=30;
- private static final Integer RETRY_INTERVAL=10;
+ private static final Integer NO_OF_ATTEMPTS = 30;
+ private static final Integer RETRY_INTERVAL = 10;
+ private static final int MILLI_SECONDS = 1000;
@Override
protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
@@ -72,7 +75,7 @@ public class RebootServer extends ProviderServerOperation {
String vmUrl = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
String rebooType = params.get(ProviderAdapter.REBOOT_TYPE);
String tenantName = "Unknown";
- if (rebooType.isEmpty() ) {
+ if (rebooType.isEmpty()) {
rebooType = "SOFT";
}
logger.info("reboot type" + rebooType);
@@ -86,12 +89,23 @@ public class RebootServer extends ProviderServerOperation {
IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL));
String identStr = (ident == null) ? null : ident.toString();
context = getContext(requestContext, vmUrl, identStr);
+ // Is the skip Hypervisor check attribute populated?
+ String skipHypervisorCheck = configuration.getProperty(Property.SKIP_HYPERVISOR_CHECK);
+ if (skipHypervisorCheck == null && ctx != null) {
+ skipHypervisorCheck = ctx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
+ }
if (context != null) {
tenantName = context.getTenantName();// this variable also is
// used in case of exception
requestContext.reset();
server = lookupServer(requestContext, context, vm.getServerId());
logger.debug(Msg.SERVER_FOUND, vmUrl, context.getTenantName(), server.getStatus().toString());
+ // 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);
+ }
Context contx = server.getContext();
ComputeService service = contx.getComputeService();
logger.info("performing reboot action for " + server.getId() + " rebootype " + rebooType);
@@ -108,7 +122,8 @@ public class RebootServer extends ProviderServerOperation {
}
} catch (ResourceNotFoundException | StateException ex) {
- logger.info(ex.getMessage());
+ String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, ex, ex.getClass().getSimpleName(),
+ REBOOT_SERVICE.toString(), vmUrl, tenantName);
ctx.setAttribute("REBOOT_STATUS", "FAILURE");
if (ex instanceof ResourceNotFoundException) {
doFailure(requestContext, HttpStatus.NOT_FOUND_404, ex.getMessage());
@@ -116,7 +131,8 @@ public class RebootServer extends ProviderServerOperation {
doFailure(requestContext, HttpStatus.CONFLICT_409, ex.getMessage());
}
} catch (Exception ex) {
- logger.info(ex.getMessage());
+ String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, ex, ex.getClass().getSimpleName(),
+ REBOOT_SERVICE.toString(), vmUrl, tenantName);
ctx.setAttribute("REBOOT_STATUS", "FAILURE");
doFailure(requestContext, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.getMessage());
}
@@ -133,11 +149,17 @@ public class RebootServer extends ProviderServerOperation {
String msg;
boolean status = false;
while (rc.attempt()) {
+ if ( Server.Status.ERROR.equals(server.getStatus())) {
+ msg = "Device status " + Server.Status.ERROR + " cannot proceed further";
+ throw new RequestFailedException("Waiting for State Change", msg, HttpStatus.CONFLICT_409, server);
+ } else {
server.waitForStateChange(pollInterval, timeout, desiredStates);
- if ((server.getStatus().equals(Server.Status.RUNNING)) || (server.getStatus().equals(Server.Status.READY))) {
+ if (Server.Status.RUNNING.equals(server.getStatus())
+ || Server.Status.READY.equals(server.getStatus())) {
status = true;
}
logger.info(server.getStatus() + " status ");
+ }
if (status) {
logger.info("Done Trying " + rc.getAttempts() + " attempts");
break;
@@ -145,7 +167,6 @@ public class RebootServer extends ProviderServerOperation {
rc.delay();
}
}
-
if (rc.isFailed()) {
msg = EELFResourceManager.format(Msg.CONNECTION_FAILED, vmUrl);
logger.info("waitForStateChange Failed");
@@ -159,7 +180,6 @@ public class RebootServer extends ProviderServerOperation {
logger.error(msg);
throw new TimeoutException(msg);
}
-
rc.reset();
logger.info("Reboot server status flag --> " + status);
return status;
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebuildServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebuildServer.java
index 7a6688709..09beb9831 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebuildServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebuildServer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
-* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -11,15 +11,15 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
-*
+*
* http://www.apache.org/licenses/LICENSE-2.0
-*
+*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-*
+*
* ============LICENSE_END=========================================================
*/
@@ -79,7 +79,7 @@ public class RebuildServer extends ProviderServerOperation {
// processing the request"
private long rebuildSleepTime = 10L * 1000L;
- /*
+ /**
* 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.
*
@@ -179,18 +179,19 @@ public class RebuildServer extends ProviderServerOperation {
*/
setTimeForMetricsLogger();
String msg;
- //Throw error if boot source is unknown
+ // Throw error if boot source is unknown
if (ServerBootSource.UNKNOWN.equals(builtFrom)) {
- logger.debug("Boot Source Unknown" );
+ logger.debug("Boot Source Unknown");
msg = String.format("Error occured when retrieving server boot source [%s]!!!", server.getId());
logger.error(msg);
- generateEvent(rc, false,msg);
+ generateEvent(rc, false, msg);
metricsLogger.error(msg);
throw new RequestFailedException("Rebuild Server", msg, HttpStatus.INTERNAL_SERVER_ERROR_500, server);
}
// Throw exception for non image/snap boot source
if (ServerBootSource.VOLUME.equals(builtFrom)) {
+ logger.debug("Boot Source Not Supported built from bootable volume");
msg = String.format("Rebuilding is currently not supported for servers built from bootable volumes [%s]",
server.getId());
generateEvent(rc, false, msg);
@@ -242,13 +243,25 @@ public class RebuildServer extends ProviderServerOperation {
logger.debug("Exception attempting to pull snapshot-id from the payload: " + e.toString());
}
List<Image> snapshots = server.getSnapshots();
+ ImageService imageService = server.getContext().getImageService();
+ List<Image> imageList = imageService.listImages();
if (!imageToUse.isEmpty()) {
logger.debug("Using snapshot-id " + imageToUse + " for the rebuild request");
+ boolean imgFound = validateSnapshotId(imageToUse, snapshots, imageList);
+
+ if (!imgFound) {
+ logger.debug("Image Snapshot Not Found");
+ msg = EELFResourceManager.format(Msg.REBUILD_SERVER_FAILED, server.getName(), server.getId(),
+ "Invalid Snapshot-Id");
+ logger.error(msg);
+ metricsLogger.error(msg);
+ throw new RequestFailedException("Rebuild Server", msg, HttpStatus.FORBIDDEN_403, server);
+ }
} else if (snapshots != null && !snapshots.isEmpty()) {
+ logger.debug("Using snapshot-id when image is Empty" + imageToUse + " for the rebuild request");
imageToUse = snapshots.get(0).getId();
} else {
imageToUse = server.getImage();
- ImageService imageService = server.getContext().getImageService();
rc.reset();
try {
while (rc.attempt()) {
@@ -370,7 +383,6 @@ public class RebuildServer extends ProviderServerOperation {
try {
validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
ProviderAdapter.PROPERTY_PROVIDER_NAME);
-
String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
VMURL vm = VMURL.parseURL(vm_url);
@@ -408,8 +420,7 @@ public class RebuildServer extends ProviderServerOperation {
logger.error(ex.getMessage());
ctx.setAttribute("REBUILD_STATUS", "ERROR");
doFailure(rc, HttpStatus.CONFLICT_409, ex.getMessage());
- }
- catch (RequestFailedException e) {
+ } catch (RequestFailedException e) {
doFailure(rc, e.getStatus(), e.getMessage());
ctx.setAttribute("REBUILD_STATUS", "ERROR");
} catch (ResourceNotFoundException e) {
@@ -427,7 +438,6 @@ public class RebuildServer extends ProviderServerOperation {
doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
}
} catch (RequestFailedException e) {
-
ctx.setAttribute("REBUILD_STATUS", "ERROR");
doFailure(rc, e.getStatus(), e.getMessage());
}
@@ -467,4 +477,37 @@ public class RebuildServer extends ProviderServerOperation {
public void setRebuildSleepTime(long millis) {
this.rebuildSleepTime = millis;
}
+
+ private boolean validateSnapshotId(String imageToUse, List<Image> snapshotList, List<Image> imageList) {
+
+ logger.debug("Validating snapshot-id " + imageToUse + " for the rebuild request from payload");
+ boolean imageFound = false;
+ // If image is empty , the validation si not required . Hence return false.
+ // Ideally function should not be called with empty image Id
+ if (imageToUse.isEmpty()) {
+ return imageFound;
+ } else {
+ // The supplied snapshot id can be a snapshot id or an image Id. Check both
+ // available for the vnf.
+ // Check against snapshot id list and image list
+ return findImageExists(snapshotList, imageToUse, "snapshotidList")
+ || findImageExists(imageList, imageToUse, "imageidList");
+ }
+ }
+
+ boolean findImageExists(List<Image> list, String imageToUse, String source) {
+ boolean imageExists = false;
+ logger.debug("Available Image-ids from :" + source + "Start\n");
+ for (Image img : list) {
+ String imgId = img.getId();
+ logger.debug("Image Id - " + imgId + "\n");
+ if (imgId.equals(imageToUse)) {
+ logger.debug("Image found in available " + source);
+ imageExists = true;
+ break;
+ }
+ }
+ return imageExists;
+
+ }
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/StartServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/StartServer.java
index 6729ab1d6..cdff1673a 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/StartServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/StartServer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -45,6 +45,7 @@ import org.glassfish.grizzly.http.util.HttpStatus;
import java.util.Map;
import static org.onap.appc.adapter.iaas.provider.operation.common.enums.Operation.START_SERVICE;
import static org.onap.appc.adapter.utils.Constants.ADAPTER_NAME;
+import org.onap.appc.adapter.iaas.provider.operation.common.constants.Property;
public class StartServer extends ProviderServerOperation {
@@ -59,97 +60,97 @@ public class StartServer extends ProviderServerOperation {
Server server = null;
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
-
String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
-
try {
validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
ProviderAdapter.PROPERTY_PROVIDER_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();
-
Context context = null;
- String tenantName = "Unknown";//to be used also in case of exception
+ String tenantName = "Unknown";// to be used also in case of exception
ctx.setAttribute("START_STATUS", "ERROR");
+ // Is the skip Hypervisor check attribute populated?
+ String skipHypervisorCheck = configuration.getProperty(Property.SKIP_HYPERVISOR_CHECK);
+ if (skipHypervisorCheck == null && ctx != null) {
+ skipHypervisorCheck = ctx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
+ }
try {
context = getContext(rc, vm_url, identStr);
if (context != null) {
- tenantName = context.getTenantName();//this varaible also is used in case of exception
+ tenantName = context.getTenantName();// this varaible also is used in case of exception
rc.reset();
server = lookupServer(rc, context, vm.getServerId());
logger.debug(Msg.SERVER_FOUND, vm_url, tenantName, server.getStatus().toString());
+ if (skipHypervisorCheck == null || (!skipHypervisorCheck.equalsIgnoreCase("true"))) {
+ // Check of the Hypervisor for the VM Server is UP and reachable
+ checkHypervisor(server);
+ }
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.
+ * 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,
Server.Status.SUSPENDED, Server.Status.PAUSED, Server.Status.DELETED);
}
-
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");
- logger.error(msg);
- throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405,
- server);
-
- case RUNNING:
- // Nothing to do, the server is already running
- logger.info("Server was already running");
- break;
-
- case ERROR:
- // Server is in error state
- msg = EELFResourceManager.format(Msg.SERVER_ERROR_STATE, server.getName(), server.getId(),
- server.getTenantId(), "start");
- logger.error(msg);
- throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405,
- server);
-
- case READY:
- // Server is stopped attempt to start the server
- rc.reset();
- startServer(rc, server);
- break;
-
- case PAUSED:
- // if paused, un-pause it
- rc.reset();
- unpauseServer(rc, server);
- break;
-
- case SUSPENDED:
- // Attempt to resume the suspended server
- rc.reset();
- resumeServer(rc, server);
- 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);
- throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405,
- server);
+ case DELETED:
+ // Nothing to do, the server is gone
+ msg = EELFResourceManager.format(Msg.SERVER_DELETED, server.getName(), server.getId(),
+ server.getTenantId(), "started");
+ logger.error(msg);
+ throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405,
+ server);
+ case RUNNING:
+ // Nothing to do, the server is already running
+ logger.info("Server was already running");
+ break;
+ case ERROR:
+ // Server is in error state
+ msg = EELFResourceManager.format(Msg.SERVER_ERROR_STATE, server.getName(), server.getId(),
+ server.getTenantId(), "start");
+ logger.error(msg);
+ throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405,
+ server);
+
+ case READY:
+ // Server is stopped attempt to start the server
+ rc.reset();
+ startServer(rc, server);
+ break;
+
+ case PAUSED:
+ // if paused, un-pause it
+ rc.reset();
+ unpauseServer(rc, server);
+ break;
+
+ case SUSPENDED:
+ // Attempt to resume the suspended server
+ rc.reset();
+ resumeServer(rc, server);
+ 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);
+ throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405,
+ server);
}
context.close();
doSuccess(rc);
@@ -163,15 +164,13 @@ public class StartServer extends ProviderServerOperation {
doFailure(rc, HttpStatus.NOT_FOUND_404, msg);
} catch (Exception e1) {
String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, e1,
- e1.getClass().getSimpleName(), START_SERVICE.toString(), vm_url,
- tenantName);
+ e1.getClass().getSimpleName(), START_SERVICE.toString(), vm_url, tenantName);
logger.error(msg, e1);
doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
}
} catch (RequestFailedException e) {
doFailure(rc, e.getStatus(), e.getMessage());
}
-
return server;
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/StopServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/StopServer.java
index 10236a80b..72b2ba26b 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/StopServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/StopServer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -49,6 +49,7 @@ import java.util.Map;
import org.slf4j.MDC;
import static org.onap.appc.adapter.iaas.provider.operation.common.enums.Operation.STOP_SERVICE;
import static org.onap.appc.adapter.utils.Constants.ADAPTER_NAME;
+import org.onap.appc.adapter.iaas.provider.operation.common.constants.Property;
public class StopServer extends ProviderServerOperation {
@@ -78,12 +79,23 @@ public class StopServer extends ProviderServerOperation {
String identStr = (ident == null) ? null : ident.toString();
Context context = null;
ctx.setAttribute("STOP_STATUS", "ERROR");
+ // Is the skip Hypervisor check attribute populated?
+ String skipHypervisorCheck = configuration.getProperty(Property.SKIP_HYPERVISOR_CHECK);
+ if (skipHypervisorCheck == null && ctx != null) {
+ skipHypervisorCheck = ctx.getAttribute(ProviderAdapter.SKIP_HYPERVISOR_CHECK);
+ }
try {
context = getContext(rc, vm_url, identStr);
if (context != null) {
rc.reset();
server = lookupServer(rc, context, vm.getServerId());
logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString());
+ // 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);
+ }
String msg;
/*
* We determine what to do based on the current state of the server
@@ -183,6 +195,7 @@ public class StopServer extends ProviderServerOperation {
logOperation(Msg.STOPPING_SERVER, params, context);
return stopServer(params, context);
}
+
private void setTimeForMetricsLogger() {
String timestamp = LoggingUtils.generateTimestampStr(((Date) new Date()).toInstant());
MDC.put(LoggingConstants.MDCKeys.BEGIN_TIMESTAMP, timestamp);