Search in sources :

Example 66 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method checkClusterVms.

/**
 * Checks if the cluster in Vcenter has VMs. Exception is thrown if VMs are
 * present.
 *
 * @param clusterId
 * @param datacenterId
 * @param stepId
 */
// TODO COP-28962 verify whether this really throws an exception
// seems like we throw an exception, and catch it again, and throw another exception
// logic is somewhat difficult to understand
public void checkClusterVms(URI clusterId, URI datacenterId, String stepId) {
    log.info("checkClusterVms {} {}", clusterId, datacenterId);
    Cluster cluster = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        cluster = _dbClient.queryObject(Cluster.class, clusterId);
        List<String> vmList = vcenterController.getVirtualMachines(datacenterId, clusterId);
        if (!vmList.isEmpty()) {
            log.error("there are {} VMs in the cluster", vmList.size());
            throw ComputeSystemControllerException.exceptions.clusterHasVms(cluster != null ? cluster.getLabel() : clusterId.toString());
        } else {
            log.info("there are no VMs in the cluster, step successful");
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (VcenterControllerException e) {
        log.warn("VcenterControllerException when trying to checkClusterVms: " + e.getMessage(), e);
        if (e.getCause() instanceof VcenterObjectNotFoundException) {
            log.info("did not find the datacenter or cluster, considering success");
            WorkflowStepCompleter.stepSucceded(stepId);
        } else {
            log.error("failure " + e);
            WorkflowStepCompleter.stepFailed(stepId, e);
        }
    } catch (InternalException e) {
        log.error("InternalException when trying to checkClusterVms: " + e.getMessage(), e);
        WorkflowStepCompleter.stepFailed(stepId, e);
    } catch (Exception e) {
        log.error("unexpected exception " + e);
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToCheckClusterVms(cluster != null ? cluster.getLabel() : clusterId.toString(), e);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Cluster(com.emc.storageos.db.client.model.Cluster) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 67 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method untagBlockBootVolume.

/**
 * Untags the boot volume before it is deleted.
 *
 * @param hostId
 *            {@link URI} hostId URI
 * @param volumeDescriptors
 *            {@link List<VolumeDescriptor>} list of boot volumes to untag
 * @param stepId
 *            {@link String} step id
 */
public void untagBlockBootVolume(URI hostId, List<VolumeDescriptor> volumeDescriptors, String stepId) {
    log.info("untagBlockBootVolume START");
    Host host = null;
    Volume bootVolume = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (host == null || NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
            WorkflowStepCompleter.stepSucceded(stepId);
            log.info("untagBlockBootVolume END");
            return;
        }
        URI bootVolumeId = getBootVolumeIdFromDescriptors(volumeDescriptors, host);
        bootVolume = _dbClient.queryObject(Volume.class, bootVolumeId);
        if (bootVolume == null || (bootVolume.getTag() == null)) {
            WorkflowStepCompleter.stepSucceded(stepId);
            log.info("untagBlockBootVolume END");
            return;
        }
        // Untag volume.  Slightly unconventional way of doing it, however our scope and label
        // both contain colons and equal signs making the ScopedLabel constructor and ScopedLabelSet.contains()
        // difficult to trust.
        String tagLabel = TagUtils.getBootVolumeTagName() + "=" + host.getId().toASCIIString();
        ScopedLabel foundSL = null;
        for (ScopedLabel sl : bootVolume.getTag()) {
            if (sl.getLabel().contains(tagLabel)) {
                foundSL = sl;
                break;
            }
        }
        if (foundSL != null) {
            bootVolume.getTag().remove(foundSL);
        }
        // If we are deleting a boot volume, there may still be a reference to the volume
        // in the decommissioned host.  We will clear out this reference in the host.
        host.setBootVolumeId(NullColumnValueGetter.getNullURI());
        _dbClient.updateObject(host);
        _dbClient.updateObject(bootVolume);
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception exception) {
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToUntagVolume(bootVolume != null ? bootVolume.forDisplay() : "none found", host != null ? host.getHostName() : hostId.toString(), exception);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
    log.info("untagBlockBootVolume END");
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Example 68 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.

the class ComputeSystemControllerImpl method validateBootVolumeExport.

public void validateBootVolumeExport(URI hostId, URI volumeId, String stepId) throws ControllerException {
    _log.info("validateBootVolumeExport :" + hostId.toString() + " volume: " + volumeId.toString());
    Host host = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (host == null) {
            throw ComputeSystemControllerException.exceptions.hostNotFound(hostId.toString());
        }
        Volume volume = _dbClient.queryObject(Volume.class, volumeId);
        if (volume == null) {
            throw ComputeSystemControllerException.exceptions.volumeNotFound(volumeId.toString());
        }
        boolean validExport = computeDeviceController.validateBootVolumeExport(hostId, volumeId);
        if (validExport) {
            WorkflowStepCompleter.stepSucceded(stepId);
        } else {
            ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.invalidBootVolumeExport(host.getLabel(), volume.getLabel());
            WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
        }
    } catch (Exception e) {
        _log.error("unexpected exception: " + e.getMessage(), e);
        String hostString = hostId.toString();
        if (host != null) {
            hostString = host.getHostName();
        }
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToValidateBootVolumeExport(hostString, volumeId.toString(), e);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Host(com.emc.storageos.db.client.model.Host) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) RemoteException(java.rmi.RemoteException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) ClientControllerException(com.emc.storageos.exceptions.ClientControllerException)

Example 69 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.

the class ComputeSystemControllerImpl method setHostSanBootTargets.

public void setHostSanBootTargets(URI hostId, URI volumeId, String stepId) throws ControllerException {
    Host host = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (host == null) {
            throw ComputeSystemControllerException.exceptions.hostNotFound(hostId.toString());
        }
        if (host.getComputeElement() != null) {
            ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
            if (computeElement != null) {
                computeDeviceController.setSanBootTarget(computeElement.getComputeSystem(), computeElement.getId(), hostId, volumeId, false);
            } else {
                _log.error("Invalid compute element association");
                throw ComputeSystemControllerException.exceptions.cannotSetSanBootTargets(host.getHostName(), "Invalid compute elemnt association");
            }
        } else {
            _log.error("Host " + host.getHostName() + " does not have a compute element association.");
            throw ComputeSystemControllerException.exceptions.cannotSetSanBootTargets(host.getHostName(), "Host does not have a blade association");
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception e) {
        _log.error("unexpected exception: " + e.getMessage(), e);
        String hostString = hostId.toString();
        if (host != null) {
            hostString = host.getHostName();
        }
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToSetSanBootTargets(hostString, e);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) RemoteException(java.rmi.RemoteException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) ClientControllerException(com.emc.storageos.exceptions.ClientControllerException)

Example 70 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.

the class VPlexBlockServiceApiImpl method deactivateMirror.

/**
 * {@inheritDoc}
 */
@Override
public TaskList deactivateMirror(StorageSystem vplexStorageSystem, URI mirrorURI, String taskId, String deleteType) {
    TaskList taskList = new TaskList();
    try {
        VplexMirror mirror = _dbClient.queryObject(VplexMirror.class, mirrorURI);
        Volume sourceVolume = _dbClient.queryObject(Volume.class, mirror.getSource().getURI());
        Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, mirror.getId().toString());
        taskList.getTaskList().add(toTask(sourceVolume, Arrays.asList(mirror), taskId, op));
        if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType)) {
            s_logger.info("Perform ViPR-only delete for VPLEX mirrors %s", mirrorURI);
            // Perform any database cleanup that is required.
            cleanupForViPROnlyMirrorDelete(Arrays.asList(mirrorURI));
            // Mark them inactive.
            _dbClient.markForDeletion(_dbClient.queryObject(VplexMirror.class, mirrorURI));
            // We must get the volume from the DB again, to properly update the status.
            sourceVolume = _dbClient.queryObject(Volume.class, mirror.getSource().getURI());
            op = sourceVolume.getOpStatus().get(taskId);
            op.ready("VPLEX continuous copy succesfully deleted from ViPR");
            sourceVolume.getOpStatus().updateTaskStatus(taskId, op);
            _dbClient.updateObject(sourceVolume);
        } else {
            List<VolumeDescriptor> descriptors = new ArrayList<VolumeDescriptor>();
            // Add a descriptor for each of the associated volumes.There will be only one associated volume
            if (mirror.getAssociatedVolumes() != null) {
                for (String assocVolId : mirror.getAssociatedVolumes()) {
                    Volume assocVolume = _dbClient.queryObject(Volume.class, URI.create(assocVolId));
                    if (assocVolume != null && !assocVolume.getInactive() && assocVolume.getNativeId() != null) {
                        // In order to add descriptor for the the backend volumes that needs to be
                        // deleted we are checking for volume nativeId as well, because its possible
                        // that we were not able to create backend volume due to SMIS communication
                        // and rollback didn't clean up VplexMirror and its associated volumes in
                        // database. So in such a case nativeId will be null and we just want to skip
                        // sending this volume to SMIS, else it fails with null reference when user
                        // attempts to cleanup this failed mirror.
                        VolumeDescriptor assocDesc = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, assocVolume.getStorageController(), assocVolume.getId(), null, null);
                        descriptors.add(assocDesc);
                    }
                }
            }
            VPlexController controller = getController();
            controller.deactivateMirror(vplexStorageSystem.getId(), mirror.getId(), descriptors, taskId);
        }
    } catch (ControllerException e) {
        String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirrorURI.toString(), e.getMessage());
        s_logger.error(errorMsg, e);
        for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(errorMsg);
            _dbClient.error(Volume.class, taskResourceRep.getResource().getId(), taskId, e);
        }
    } catch (Exception e) {
        String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirrorURI.toString(), e.getMessage());
        s_logger.error(errorMsg, e);
        ServiceCoded sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
        for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(sc.getMessage());
            _dbClient.error(Volume.class, taskResourceRep.getResource().getId(), taskId, sc);
        }
    }
    return taskList;
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) VPlexController(com.emc.storageos.vplexcontroller.VPlexController) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) VplexMirror(com.emc.storageos.db.client.model.VplexMirror)

Aggregations

ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)94 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)48 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)44 URI (java.net.URI)41 Volume (com.emc.storageos.db.client.model.Volume)31 ControllerException (com.emc.storageos.volumecontroller.ControllerException)27 NamedURI (com.emc.storageos.db.client.model.NamedURI)26 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)22 WorkflowException (com.emc.storageos.workflow.WorkflowException)22 ArrayList (java.util.ArrayList)22 BlockObject (com.emc.storageos.db.client.model.BlockObject)18 Operation (com.emc.storageos.db.client.model.Operation)17 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)17 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)16 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)15 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)14 HashMap (java.util.HashMap)14 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)13 URISyntaxException (java.net.URISyntaxException)13 Host (com.emc.storageos.db.client.model.Host)12