Search in sources :

Example 96 with Initiator

use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.

the class CinderExportOperations method removeVolumes.

@Override
public void removeVolumes(StorageSystem storage, URI exportMaskId, List<URI> volumeURIs, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} removeVolumes START...", storage.getSerialNumber());
    try {
        log.info("removeVolumes: Export mask id: {}", exportMaskId);
        log.info("removeVolumes: volumes: {}", Joiner.on(',').join(volumeURIs));
        if (initiatorList != null) {
            log.info("removeVolumes: impacted initiators: {}", Joiner.on(",").join(initiatorList));
        }
        ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskId);
        List<Volume> volumes = new ArrayList<Volume>();
        List<Initiator> userAddedInitiatorList = new ArrayList<Initiator>();
        StringMap initiators = exportMask.getUserAddedInitiators();
        for (URI volumeURI : volumeURIs) {
            Volume volume = dbClient.queryObject(Volume.class, volumeURI);
            volumes.add(volume);
        }
        for (String ini : initiators.values()) {
            Initiator initiator = dbClient.queryObject(Initiator.class, URI.create(ini));
            userAddedInitiatorList.add(initiator);
        }
        detachVolumesFromInitiators(storage, volumes, userAddedInitiatorList);
        taskCompleter.ready(dbClient);
    } catch (final Exception ex) {
        log.error("Problem in RemoveVolumes: ", ex);
        ServiceError serviceError = DeviceControllerErrors.cinder.operationFailed("doRemoveVolumes", ex.getMessage());
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("{} removeVolumes END...", storage.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StringMap(com.emc.storageos.db.client.model.StringMap) Volume(com.emc.storageos.db.client.model.Volume) Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 97 with Initiator

use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.

the class ExportAddInitiatorCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
        Operation operation = new Operation();
        switch(status) {
            case error:
                operation.error(coded);
                break;
            case ready:
                operation.ready();
                break;
            case suspended_no_error:
                operation.suspendedNoError();
                break;
            case suspended_error:
                operation.suspendedError(coded);
                break;
            default:
                break;
        }
        exportGroup.getOpStatus().updateTaskStatus(getOpId(), operation);
        _log.info("export_initiator_add: completed");
        _log.info(String.format("Done ExportMaskAddInitiator - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
        for (URI initiatorURI : _initiatorURIs) {
            Initiator initiator = dbClient.queryObject(Initiator.class, initiatorURI);
            recordBlockExportOperation(dbClient, OperationTypeEnum.ADD_EXPORT_INITIATOR, status, eventMessage(status, initiator, exportGroup), exportGroup, initiator);
            if (status.name().equals(Operation.Status.error.name())) {
                exportGroup.removeInitiator(initiator);
            }
        }
        dbClient.updateObject(exportGroup);
    } catch (Exception e) {
        _log.error(String.format("Failed updating status for ExportMaskAddInitiator - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 98 with Initiator

use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.

the class ExportMaskAddInitiatorCompleter method updateDatabase.

/**
 * Update the export mask and export group with the initiators are ports
 *
 * @param dbClient
 *            dbclient
 * @param uris
 *            uris of Initiators and storage ports
 */
private void updateDatabase(DbClient dbClient, Collection<URI> uris) {
    List<URI> targetURIs = _targetURIs;
    List<URI> initiatorURIs = _initiatorURIs;
    // initiators that appear in the context.
    if (uris != null && !uris.isEmpty()) {
        targetURIs = URIUtil.getURIsofType(uris, Initiator.class);
        initiatorURIs = URIUtil.getURIsofType(uris, StoragePort.class);
    }
    ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
    ExportMask exportMask = (getMask() != null) ? dbClient.queryObject(ExportMask.class, getMask()) : null;
    if (exportMask != null) {
        // Update the initiator tracking containers
        exportMask.addToUserCreatedInitiators(dbClient.queryObject(Initiator.class, initiatorURIs));
        // Save the initiators to the ExportMask
        for (URI initiatorURI : initiatorURIs) {
            Initiator initiator = dbClient.queryObject(Initiator.class, initiatorURI);
            if (initiator != null) {
                exportMask.removeFromExistingInitiators(initiator);
                exportMask.addInitiator(initiator);
                exportGroup.addInitiator(initiator);
            } else {
                _log.warn("Initiator {} does not exist.", initiatorURI);
            }
        }
        // Save the target StoragePort URIs to the ExportMask
        for (URI newTarget : targetURIs) {
            exportMask.addTarget(newTarget);
        }
        dbClient.updateObject(exportMask);
    }
    ExportUtils.reconcileExportGroupsHLUs(dbClient, exportGroup);
    dbClient.updateObject(exportGroup);
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI)

Example 99 with Initiator

use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.

the class ExportMaskCreateCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
        ExportMask exportMask = (getMask() != null) ? dbClient.queryObject(ExportMask.class, getMask()) : null;
        if (exportMask != null && status == Operation.Status.ready) {
            List<Initiator> initiators = dbClient.queryObject(Initiator.class, _initiatorURIs);
            exportMask.addInitiators(initiators);
            StorageSystem system = dbClient.queryObject(StorageSystem.class, exportMask.getStorageDevice());
            exportMask.addToUserCreatedInitiators(initiators);
            exportMask.addVolumes(_volumeMap);
            if (Type.xtremio.toString().equalsIgnoreCase(system.getSystemType())) {
                // XtremIO case, wwn's are updated only during export.
                // Clean up the existing volumes in export Mask which will have dummy wwns after provisioning.
                // The code below this method addToUserCreatedVolumes adds back the volumes with right wwns.
                _log.info("Cleaning existing xtremio volumes with dummy wwns");
                exportMask.getUserAddedVolumes().clear();
            }
            for (URI boURI : _volumeMap.keySet()) {
                BlockObject blockObject = BlockObject.fetch(dbClient, boURI);
                exportMask.addToUserCreatedVolumes(blockObject);
                // CTRL-11544: Set the hlu in the export group too
                if (exportMask.getCreatedBySystem() && exportMask.getVolumes() != null) {
                    String hlu = exportMask.getVolumes().get(boURI.toString());
                    exportGroup.addVolume(boURI, Integer.parseInt(hlu));
                }
            }
            ExportUtils.reconcileHLUs(dbClient, exportGroup, exportMask, _volumeMap);
            dbClient.updateObject(exportMask);
            exportGroup.addExportMask(exportMask.getId());
            dbClient.updateObject(exportGroup);
            updatePortGroupVolumeCount(exportMask.getPortGroup(), dbClient);
        }
        _log.info(String.format("Done ExportMaskCreate - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
    } catch (Exception e) {
        _log.error(String.format("Failed updating status for ExportMaskCreate - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 100 with Initiator

use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.

the class ExportMaskRemoveInitiatorCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
        ExportMask exportMask = (getMask() != null) ? dbClient.queryObject(ExportMask.class, getMask()) : null;
        boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(getOpId());
        if ((status == Operation.Status.error) && (isRollback) && (coded instanceof ServiceError)) {
            ServiceError error = (ServiceError) coded;
            String originalMessage = error.getMessage();
            StorageSystem storageSystem = exportMask != null ? dbClient.queryObject(StorageSystem.class, exportMask.getStorageDevice()) : null;
            List<Initiator> initiators = dbClient.queryObject(Initiator.class, _initiatorURIs);
            StringBuffer initiatorsJoined = new StringBuffer();
            if (initiators != null && !initiators.isEmpty()) {
                Iterator<Initiator> initIter = initiators.iterator();
                while (initIter.hasNext()) {
                    Initiator initiator = initIter.next();
                    initiatorsJoined.append(initiator.forDisplay());
                    if (initIter.hasNext()) {
                        initiatorsJoined.append(",");
                    }
                }
            }
            String additionMessage = String.format("Rollback encountered problems removing initiator(s) %s from export mask %s on storage system %s and may require manual clean up", initiatorsJoined.toString(), exportMask.getMaskName(), storageSystem != null ? storageSystem.forDisplay() : "Unknown");
            String updatedMessage = String.format("%s\n%s", originalMessage, additionMessage);
            error.setMessage(updatedMessage);
        }
        if (exportMask != null && (status == Operation.Status.ready || isRollback)) {
            List<Initiator> initiators = dbClient.queryObject(Initiator.class, _initiatorURIs);
            List<URI> targetPorts = ExportUtils.getRemoveInitiatorStoragePorts(exportMask, initiators, dbClient);
            exportMask.removeInitiators(initiators);
            exportMask.removeFromUserCreatedInitiators(initiators);
            if (exportMask.getExistingInitiators() != null && exportMask.getExistingInitiators().isEmpty()) {
                exportMask.setExistingInitiators(null);
            }
            if (exportMask.getInitiators() == null || exportMask.getInitiators().isEmpty()) {
                exportGroup.removeExportMask(exportMask.getId());
                dbClient.removeObject(exportMask);
                dbClient.updateObject(exportGroup);
            } else {
                if (targetPorts != null && !targetPorts.isEmpty()) {
                    for (URI targetPort : targetPorts) {
                        exportMask.removeTarget(targetPort);
                    }
                }
                removeUnusedTargets(exportMask);
                dbClient.updateObject(exportMask);
            }
            _log.info(String.format("Done ExportMaskRemoveInitiator - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
        }
    } catch (Exception e) {
        _log.error(String.format("Failed updating status for ExportMaskRemoveInitiator - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

Initiator (com.emc.storageos.db.client.model.Initiator)487 URI (java.net.URI)345 ArrayList (java.util.ArrayList)266 HashMap (java.util.HashMap)170 HashSet (java.util.HashSet)161 ExportMask (com.emc.storageos.db.client.model.ExportMask)156 List (java.util.List)119 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)102 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)98 Map (java.util.Map)85 StringSet (com.emc.storageos.db.client.model.StringSet)83 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)82 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)81 StoragePort (com.emc.storageos.db.client.model.StoragePort)78 NamedURI (com.emc.storageos.db.client.model.NamedURI)73 Set (java.util.Set)72 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)58 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)57 StringMap (com.emc.storageos.db.client.model.StringMap)55 Host (com.emc.storageos.db.client.model.Host)54