use of com.emc.sa.engine.ExecutionException in project coprhd-controller by CoprHD.
the class ComputeUtils method validateBootVolumes.
/**
* Validate that the boot volume for this host is still on the server.
* This prevents us from deleting a re-purposed volume that was originally
* a boot volume.
*
* @return true if the volumes are valid, or the volumes are not able to be validated, so we can go ahead anyway.
*/
public static boolean validateBootVolumes(Cluster cluster, List<HostRestRep> hostsToValidate) {
// the references are fixed.
if (cluster == null || cluster.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.cluster");
return false;
}
// so return that the boot volume is valid due to lack of technical ability to dig any deeper.
if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.noVcenterDataCenter", cluster.forDisplay());
return true;
}
VcenterDataCenter dataCenter = execute(new GetVcenterDataCenter(cluster.getVcenterDataCenter()));
// until that's fixed.
if (dataCenter == null || dataCenter.getInactive() || NullColumnValueGetter.isNullURI(dataCenter.getVcenter())) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.datacenter", cluster.forDisplay());
return false;
}
Vcenter vcenter = execute(new GetVcenter(dataCenter.getVcenter()));
// until that's fixed.
if (vcenter == null || vcenter.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.vcenter", cluster.forDisplay());
return false;
}
VMwareSupport vmware = null;
try {
vmware = new VMwareSupport();
vmware.connect(vcenter.getId());
for (HostRestRep clusterHost : hostsToValidate) {
Host host = BlockStorageUtils.getHost(clusterHost.getId());
// Do not validate a host no longer in our database
if (host == null || host.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.host", "N/A", "host not found or inactive");
return false;
}
// in the vCenter cluster, and therefore we can not perform a deep validation.
if (NullColumnValueGetter.isNullURI(host.getVcenterDataCenter())) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.vcenternotinhost", host.getHostName());
continue;
}
// any update to the host using the hostService automatically adds this association.
if (!NullColumnValueGetter.isNullURI(host.getVcenterDataCenter()) && host.getType() != null && host.getType().equalsIgnoreCase((Host.HostType.No_OS).name())) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.noOShost", host.getHostName());
continue;
}
// flag it as an issue.
if (clusterHost.getBootVolume() == null || NullColumnValueGetter.isNullURI(clusterHost.getBootVolume().getId())) {
ExecutionUtils.currentContext().logWarn("computeutils.removebootvolumes.failure.host", host.getHostName(), "no boot volume associated with host");
continue;
}
BlockObjectRestRep bootVolume = execute(new GetBlockResource(clusterHost.getBootVolume().getId()));
// Do not validate an old/non-existent boot volume representation
if (bootVolume == null || bootVolume.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.host", host.getHostName(), "boot volume not found or inactive");
return false;
}
HostSystem hostSystem = null;
try {
hostSystem = vmware.getHostSystem(dataCenter.getLabel(), clusterHost.getName(), false);
// we can't perform the validation.
if (hostSystem == null) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.hostnotinvcenter", host.getHostName());
continue;
}
HostSystemConnectionState connectionState = VMwareUtils.getConnectionState(hostSystem);
if (connectionState == null || connectionState == HostSystemConnectionState.notResponding || connectionState == HostSystemConnectionState.disconnected) {
String exMsg = "Validation of boot volume usage on host %s failed. " + "Validation failed because host is in a disconnected state or not responding state, and therefore cannot be validated. " + "Cannot decommission in current state. Recommended to either re-connect the host or remove the host from vCenter, " + "run vCenter discovery and address actionable events before attempting decommission of hosts in this cluster.";
// will print a boot volume re-purposed error message which is kind of misleading or incorrect reason for the failure.
throw new IllegalStateException(String.format(exMsg, host.getHostName()));
}
} catch (ExecutionException e) {
if (e.getCause() instanceof IllegalStateException) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.hostnotinvcenter", host.getHostName());
continue;
}
// If it's anything other than the IllegalStateException, re-throw the base exception
throw e;
}
if (vmware.findScsiDisk(hostSystem, null, bootVolume, false, false) == null) {
// fail, host can't see its boot volume
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.bootvolume", bootVolume.getDeviceLabel(), bootVolume.getWwn());
return false;
} else {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validated", host.getHostName(), bootVolume.getDeviceLabel());
}
}
} finally {
if (vmware != null) {
vmware.disconnect();
}
}
return true;
}
use of com.emc.sa.engine.ExecutionException in project coprhd-controller by CoprHD.
the class InstallOsHelper method installOs.
public void installOs() {
ExecutionContext context = ExecutionUtils.currentContext();
List<ViPRTaskMonitor<HostRestRep>> tasks = new ArrayList<>();
for (HostRestRep host : hostToOsInstall.keySet()) {
OsInstallParam osInstall = hostToOsInstall.get(host);
if (osInstall != null) {
try {
// tasks.add(ExecutionUtils.startViprTask(new InstallOs(host, osInstall)));
} catch (ExecutionException e) {
context.logError("computeutils.installOs.failure", host.getId(), e.getMessage());
}
}
}
if (!ExecutionUtils.waitForTask(tasks, this)) {
// TODO: Re-throw the error?
// ExecutionUtils.checkForError(tasks);
}
}
use of com.emc.sa.engine.ExecutionException in project coprhd-controller by CoprHD.
the class BlockStorageUtils method removeExportIfEmpty.
public static void removeExportIfEmpty(URI exportId) {
boolean retryNeeded = false;
int retryCount = 0;
do {
retryNeeded = false;
ExportGroupRestRep export = getExport(exportId);
if (ResourceUtils.isActive(export) && export.getVolumes().isEmpty()) {
try {
log.info(String.format("Attampting deletion of ExportGroup %s (%s)", export.getGeneratedName(), export.getId()));
Task<ExportGroupRestRep> response = execute(new DeactivateBlockExport(exportId));
addAffectedResource(response);
} catch (ExecutionException e) {
if (e.getCause() instanceof ServiceErrorException) {
ServiceErrorException svcexp = (ServiceErrorException) e.getCause();
if (retryCount++ < MAX_RETRY_COUNT && ServiceCode.toServiceCode(svcexp.getCode()) == ServiceCode.API_TASK_EXECUTION_IN_PROGRESS) {
log.info(String.format("ExportGroup %s deletion waiting on pending task execution", export.getId()));
retryNeeded = true;
try {
Thread.sleep(RETRY_DELAY_MSEC);
} catch (InterruptedException ex) {
log.debug("Sleep interrupted");
}
} else {
throw e;
}
}
}
}
} while (retryNeeded);
}
use of com.emc.sa.engine.ExecutionException in project coprhd-controller by CoprHD.
the class ComputeUtils method makeBootVolumes.
/**
* Attempts to create a boot volume for each host sent in.
* Guarantees a map with all hosts, even if that host's boot volume creation failed.
*
* @param project project
* @param virtualArray virtual array
* @param virtualPool virtual pool
* @param size size of boot volumes
* @param hosts host list
* @param client NB API
* @param URI portGroup
* @return map of host objects to volume IDs. (volume ID is null if that host didn't get a good boot volume)
*/
public static Map<Host, URI> makeBootVolumes(URI project, URI virtualArray, URI virtualPool, Double size, List<Host> hosts, ViPRCoreClient client, URI portGroup) {
Map<String, Host> volumeNameToHostMap = new HashMap<>();
Map<Host, URI> hostToBootVolumeIdMap = new HashMap<>();
if (hosts == null || hosts.isEmpty()) {
return Maps.newHashMap();
}
List<Task<VolumeRestRep>> tasks = new ArrayList<>();
ArrayList<String> volumeNames = new ArrayList<>();
for (Host host : hosts) {
if (host == null) {
volumeNames.add(null);
continue;
}
String volumeName = host.getHostName().replaceAll("[^A-Za-z0-9_]", "_").concat("_boot");
while (!BlockStorageUtils.getVolumeByName(volumeName).isEmpty()) {
// vol name used?
if (volumeName.matches(".*_\\d+$")) {
// incr suffix number
int volNumber = Integer.parseInt(volumeName.substring(volumeName.lastIndexOf("_") + 1));
volumeName = volumeName.replaceAll("_\\d+$", "_" + ++volNumber);
} else {
// add suffix number
volumeName = volumeName.concat("_0");
}
}
try {
tasks.add(BlockStorageUtils.createVolumesByName(project, virtualArray, virtualPool, size, nullConsistencyGroup, volumeName, portGroup, // does not wait for task
host.getId()));
volumeNameToHostMap.put(volumeName, host);
} catch (ExecutionException e) {
String errorMessage = e.getMessage() == null ? "" : e.getMessage();
ExecutionUtils.currentContext().logError("computeutils.makebootvolumes.failure", host.getHostName(), errorMessage);
}
}
// monitor tasks
List<URI> bootVolsToRemove = new ArrayList<URI>();
while (!tasks.isEmpty()) {
tasks = waitAndRefresh(tasks);
for (Task<VolumeRestRep> successfulTask : getSuccessfulTasks(tasks)) {
URI volumeId = successfulTask.getResourceId();
String volumeName = successfulTask.getResource().getName();
Host tempHost = volumeNameToHostMap.get(volumeName);
tempHost.setBootVolumeId(volumeId);
addAffectedResource(volumeId);
tasks.remove(successfulTask);
addBootVolumeTag(volumeId, tempHost.getId());
BlockObjectRestRep volume = BlockStorageUtils.getBlockResource(volumeId);
if (BlockStorageUtils.isVolumeBootVolume(volume)) {
hostToBootVolumeIdMap.put(tempHost, volumeId);
} else {
bootVolsToRemove.add(volumeId);
tempHost.setBootVolumeId(NullColumnValueGetter.getNullURI());
hostToBootVolumeIdMap.put(tempHost, null);
}
}
for (Task<VolumeRestRep> failedTask : getFailedTasks(tasks)) {
String volumeName = failedTask.getResource().getName();
hostToBootVolumeIdMap.put(volumeNameToHostMap.get(volumeName), null);
String errorMessage = failedTask.getMessage() == null ? "" : failedTask.getMessage();
ExecutionUtils.currentContext().logError("computeutils.makebootvolumes.createvolume.failure", volumeName, errorMessage);
tasks.remove(failedTask);
}
}
if (!bootVolsToRemove.isEmpty()) {
try {
// No need to untag, this bootVolsToRemove list is based on volumes that never got the boot tag.
BlockStorageUtils.deactivateVolumes(bootVolsToRemove, VolumeDeleteTypeEnum.FULL);
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.bootvolume.deactivate.failure", e.getMessage());
}
}
return hostToBootVolumeIdMap;
}
use of com.emc.sa.engine.ExecutionException in project coprhd-controller by CoprHD.
the class ComputeUtils method verifyClusterInVcenter.
/**
* Precheck to verify if cluster is associated to a datacenter and if it still
* on the same datacenter and vcenter. Precheck fails the order if the cluster
* has datacenter association and is not found on the vcenter under the same datacenter
* Precheck also fails if the cluster found by name in vcenter does not match externalId
* in ViPR Cluster.
* If cluster does not have a datacenter association, then the cluster is
* a vipr cluster and precheck passes.
* @param cluster {@link Cluster} cluster instance
* @param preCheckErrors {@link StringBuilder} instance
* @return preCheckErrors
*/
public static StringBuilder verifyClusterInVcenter(Cluster cluster, StringBuilder preCheckErrors) {
// else fail order
if (!NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
VcenterDataCenter dataCenter = execute(new GetVcenterDataCenter(cluster.getVcenterDataCenter()));
if (dataCenter != null && !dataCenter.getInactive()) {
if (!NullColumnValueGetter.isNullURI(dataCenter.getVcenter())) {
Vcenter vcenter = execute(new GetVcenter(dataCenter.getVcenter()));
if (vcenter != null && !vcenter.getInactive()) {
VMwareSupport vmware = null;
try {
vmware = new VMwareSupport();
vmware.connect(vcenter.getId());
ClusterComputeResource vcenterCluster = vmware.getCluster(dataCenter.getLabel(), cluster.getLabel(), false);
if (null == vcenterCluster) {
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.notfound.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel()));
} else if (vcenterCluster.getMOR() != null && vcenterCluster.getMOR().getVal() != null && vcenterCluster.getMOR().getVal().equalsIgnoreCase(cluster.getExternalId())) {
ExecutionUtils.currentContext().logInfo("compute.cluster.precheck.cluster.VcenterDataCenter.found.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel());
} else {
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.nomatch.in.vcenter", cluster.getLabel(), vcenter.getLabel()));
}
} catch (ExecutionException e) {
if (e.getCause() instanceof IllegalStateException) {
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.notfound.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel()));
} else {
// exception
throw e;
}
} finally {
if (vmware != null) {
vmware.disconnect();
}
}
} else {
// If the vcenter isn't returned properly, not found in
// DB, but the cluster has a reference to
// it, there's an issue with the sync of the DB object.
// Do not allow the validation to pass
// until that's fixed.
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.improper.vcenter", dataCenter.getVcenter()));
}
} else {
// If datacenter does not have reference to a vcenter then
// there's an issue with the sync of the DB object. Do not allow the validation to pass
// until that's fixed.
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.noVcenter", dataCenter.getLabel()));
}
} else {
// If the datacenter isn't returned properly, not found in DB,
// but the cluster has a reference to
// it, there's an issue with the sync of the DB object. Do not
// allow the validation to pass
// until that's fixed.
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.improper.VcenterDataCenter", cluster.getVcenterDataCenter()));
}
} else {
// cluster is a vipr cluster only no need to check anything further.
ExecutionUtils.currentContext().logInfo("compute.cluster.precheck.cluster.noVCenterDataCenter", cluster.getLabel());
}
return preCheckErrors;
}
Aggregations