Search in sources :

Example 21 with ServiceCoded

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

the class CephCloneOperations method createSingleClone.

@Override
public void createSingleClone(StorageSystem storageSystem, URI source, URI cloneVolume, Boolean createInactive, TaskCompleter taskCompleter) {
    _log.info("START createSingleClone operation");
    try (CephClient cephClient = getClient(storageSystem)) {
        Volume cloneObject = _dbClient.queryObject(Volume.class, cloneVolume);
        BlockObject sourceObject = BlockObject.fetch(_dbClient, source);
        BlockSnapshot sourceSnapshot = null;
        Volume parentVolume = null;
        if (sourceObject instanceof BlockSnapshot) {
            // Use source snapshot as clone source
            sourceSnapshot = (BlockSnapshot) sourceObject;
            parentVolume = _dbClient.queryObject(Volume.class, sourceSnapshot.getParent());
        } else if (sourceObject instanceof Volume) {
            // Use interim snapshot as clone source, since Ceph can clone snapshots only
            // http://docs.ceph.com/docs/master/rbd/rbd-snapshot/#getting-started-with-layering
            parentVolume = (Volume) sourceObject;
            sourceSnapshot = prepareInternalSnapshotForVolume(parentVolume);
        } else {
            String msg = String.format("Unsupported block object type URI %s", source);
            ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("createSingleClone", msg);
            taskCompleter.error(_dbClient, code);
            return;
        }
        StoragePool pool = _dbClient.queryObject(StoragePool.class, parentVolume.getPool());
        String poolId = pool.getPoolName();
        String parentVolumeId = parentVolume.getNativeId();
        String snapshotId = sourceSnapshot.getNativeId();
        String cloneId = null;
        try {
            if (snapshotId == null || snapshotId.isEmpty()) {
                // Create Ceph snapshot of volume requested to clone
                snapshotId = CephUtils.createNativeId(sourceSnapshot);
                cephClient.createSnap(poolId, parentVolumeId, snapshotId);
                sourceSnapshot.setNativeId(snapshotId);
                sourceSnapshot.setDeviceLabel(snapshotId);
                sourceSnapshot.setIsSyncActive(true);
                sourceSnapshot.setParent(new NamedURI(parentVolume.getId(), parentVolume.getLabel()));
                _dbClient.updateObject(sourceSnapshot);
                _log.info("Interim shapshot {} created for clone {}", sourceSnapshot.getId(), cloneObject.getId());
            }
            // Ceph requires cloning snapshot to be protected (from deleting)
            if (!cephClient.snapIsProtected(poolId, parentVolumeId, snapshotId)) {
                cephClient.protectSnap(poolId, parentVolumeId, snapshotId);
            }
            // Do cloning
            String cloneVolumeId = CephUtils.createNativeId(cloneObject);
            cephClient.cloneSnap(poolId, parentVolumeId, snapshotId, cloneVolumeId);
            cloneId = cloneVolumeId;
            // Update clone object
            cloneObject.setDeviceLabel(cloneId);
            cloneObject.setNativeId(cloneId);
            cloneObject.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, cloneObject));
            cloneObject.setProvisionedCapacity(parentVolume.getProvisionedCapacity());
            cloneObject.setAllocatedCapacity(parentVolume.getAllocatedCapacity());
            cloneObject.setAssociatedSourceVolume(sourceSnapshot.getId());
            _dbClient.updateObject(cloneObject);
            // Finish task
            taskCompleter.ready(_dbClient);
        } catch (Exception e) {
            // Clean up created objects
            cleanUpCloneObjects(cephClient, poolId, cloneId, snapshotId, parentVolumeId, sourceSnapshot);
            throw e;
        }
    } catch (Exception e) {
        BlockObject obj = BlockObject.fetch(_dbClient, cloneVolume);
        if (obj != null) {
            obj.setInactive(true);
            _dbClient.updateObject(obj);
        }
        _log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("createSingleClone", e.getMessage());
        taskCompleter.error(_dbClient, code);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CephClient(com.emc.storageos.ceph.CephClient) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 22 with ServiceCoded

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

the class CephStorageDevice method mapVolumes.

/**
 * Map volumes to hosts on the hosts themselves.
 *
 * @param storage
 *            [in] - Storage System object
 * @param volumeMap
 *            [in] - Volume URI to Integer LUN map
 * @param initiators
 *            [in] - Collection of Initiator objects
 * @param completer
 *            [in] - TaskCompleter
 */
private void mapVolumes(StorageSystem storage, Map<URI, Integer> volumeMap, Collection<Initiator> initiators, TaskCompleter completer) {
    _log.info("mapVolumes: volumeMap: {}", volumeMap);
    _log.info("mapVolumes: initiators: {}", initiators);
    try {
        for (Map.Entry<URI, Integer> volMapEntry : volumeMap.entrySet()) {
            URI objectUri = volMapEntry.getKey();
            BlockObject object = Volume.fetchExportMaskBlockObject(_dbClient, objectUri);
            String monitorAddress = storage.getSmisProviderIP();
            String monitorUser = storage.getSmisUserName();
            String monitorKey = storage.getSmisPassword();
            RBDMappingOptions rbdOptions = new RBDMappingOptions(object);
            for (Initiator initiator : initiators) {
                Host host = _dbClient.queryObject(Host.class, initiator.getHost());
                if (initiator.getProtocol().equalsIgnoreCase(HostInterface.Protocol.RBD.name())) {
                    _log.info(String.format("mapVolume: host %s pool %s volume %s", host.getHostName(), rbdOptions.poolName, rbdOptions.volumeName));
                    LinuxSystemCLI linuxClient = getLinuxClient(host);
                    linuxClient.mapRBD(monitorAddress, monitorUser, monitorKey, rbdOptions.poolName, rbdOptions.volumeName, rbdOptions.snapshotName);
                } else {
                    String msg = String.format("Unexpected initiator protocol %s, port %s, pool %s, volume %s", initiator.getProtocol(), initiator.getInitiatorPort(), rbdOptions.poolName, rbdOptions.volumeName);
                    ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("mapVolumes", msg);
                    completer.error(_dbClient, code);
                    return;
                }
            }
        }
        completer.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("mapVolumes", e.getMessage());
        completer.error(_dbClient, code);
    }
}
Also used : LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI) Initiator(com.emc.storageos.db.client.model.Initiator) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Host(com.emc.storageos.db.client.model.Host) HashMap(java.util.HashMap) Map(java.util.Map) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 23 with ServiceCoded

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

the class IsilonFileStorageDevice method updateStorageSystemFileProtectionPolicy.

@Override
public BiosCommandResult updateStorageSystemFileProtectionPolicy(StorageSystem storage, FileDeviceInputOutput args) {
    FilePolicy existingPolicy = args.getFileProtectionPolicy();
    PolicyStorageResource policyRes = args.getPolicyStorageResource();
    FilePolicyUpdateParam policyUpdateParam = args.getFileProtectionPolicyUpdateParam();
    IsilonApi isi = getIsilonDevice(storage);
    BiosCommandResult result = null;
    try {
        if (existingPolicy.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_replication.name())) {
            boolean isVersion8above = false;
            if (VersionChecker.verifyVersionDetails(ONEFS_V8, storage.getFirmwareVersion()) >= 0) {
                isVersion8above = true;
            }
            return updateStorageSystemFileReplicationPolicy(isi, policyRes, existingPolicy, policyUpdateParam, isVersion8above);
        } else if (existingPolicy.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_snapshot.name())) {
            return updateStorageSystemFileSnapshotPolicy(isi, policyRes, existingPolicy, policyUpdateParam);
        } else {
            String errorMsg = "Invalid policy type {} " + existingPolicy.getFilePolicyType();
            _log.error(errorMsg);
            final ServiceCoded serviceCoded = DeviceControllerException.errors.jobFailedOpMsg(OperationTypeEnum.UPDATE_STORAGE_SYSTEM_POLICY_BY_POLICY_RESOURCE.toString(), errorMsg);
            result = BiosCommandResult.createErrorResult(serviceCoded);
            existingPolicy.getOpStatus().updateTaskStatus(args.getOpId(), result.toOperation());
            return result;
        }
    } catch (IsilonException e) {
        _log.error("Update storage system policy for file policy failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FilePolicyUpdateParam(com.emc.storageos.model.file.policy.FilePolicyUpdateParam) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 24 with ServiceCoded

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

the class IsilonFileStorageDevice method updateNfsACLs.

@Override
public BiosCommandResult updateNfsACLs(StorageSystem storage, FileDeviceInputOutput args) {
    try {
        // read nameToSid flag from controller config.
        Boolean sidEnable = customConfigHandler.getComputedCustomConfigBooleanValue(CustomConfigConstants.ISILON_USER_TO_SID_MAPPING_FOR_NFS_ENABLED, storage.getSystemType(), null);
        // get sid mapping based on Controller config and it belong to VirtualNAS.
        if (sidEnable && args.getvNAS() != null) {
            updateSidInfoForNfsACE(args, storage);
        }
        IsilonNFSACL isilonAcl = new IsilonNFSACL();
        ArrayList<Acl> aclCompleteList = new ArrayList<Acl>();
        List<NfsACE> aceToAdd = args.getNfsAclsToAdd();
        for (NfsACE nfsACE : aceToAdd) {
            Acl acl = getIsilonAclFromNfsACE(nfsACE);
            acl.setOp("add");
            aclCompleteList.add(acl);
        }
        List<NfsACE> aceToModify = args.getNfsAclsToModify();
        for (NfsACE nfsACE : aceToModify) {
            Acl acl = getIsilonAclFromNfsACE(nfsACE);
            acl.setOp("replace");
            aclCompleteList.add(acl);
        }
        List<NfsACE> aceToDelete = args.getNfsAclsToDelete();
        for (NfsACE nfsACE : aceToDelete) {
            Acl acl = getIsilonAclFromNfsACE(nfsACE);
            acl.setOp("delete");
            aclCompleteList.add(acl);
        }
        isilonAcl.setAction("update");
        isilonAcl.setAuthoritative("acl");
        isilonAcl.setAcl(aclCompleteList);
        String path = args.getFileSystemPath();
        if (args.getSubDirectory() != null && !args.getSubDirectory().isEmpty()) {
            path = path + "/" + args.getSubDirectory();
        }
        // Process new ACLs
        IsilonApi isi = getIsilonDevice(storage);
        _log.info("Calling Isilon API: modify NFS Acl for {}, acl  {}", args.getFileSystemPath(), isilonAcl);
        isi.modifyNFSACL(path, isilonAcl);
        _log.info("End updateNfsACLs");
        BiosCommandResult result = BiosCommandResult.createSuccessfulResult();
        return result;
    } catch (IsilonException e) {
        _log.error("updateNfsACLs failed ", e);
        return BiosCommandResult.createErrorResult(e);
    } catch (Exception e) {
        _log.error("updateNfsACLs failed ", e);
        final ServiceCoded serviceCoded = DeviceControllerException.errors.jobFailedOpMsg(OperationTypeEnum.UPDATE_FILE_SYSTEM_NFS_ACL.toString(), e.getMessage());
        return BiosCommandResult.createErrorResult(serviceCoded);
    }
}
Also used : NfsACE(com.emc.storageos.model.file.NfsACE) ArrayList(java.util.ArrayList) Acl(com.emc.storageos.isilon.restapi.IsilonNFSACL.Acl) IsilonException(com.emc.storageos.isilon.restapi.IsilonException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IsilonCollectionException(com.emc.storageos.plugins.metering.isilon.IsilonCollectionException) IsilonNFSACL(com.emc.storageos.isilon.restapi.IsilonNFSACL) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 25 with ServiceCoded

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

the class ScaleIOCloneOperations method createGroupClone.

@Override
public void createGroupClone(StorageSystem storage, List<URI> cloneList, Boolean createInactive, TaskCompleter taskCompleter) {
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(dbClient).getClientHandle(storage);
        List<Volume> clones = dbClient.queryObject(Volume.class, cloneList);
        Map<String, String> parent2snap = new HashMap<>();
        Set<URI> poolsToUpdate = new HashSet<>();
        for (Volume clone : clones) {
            Volume parent = dbClient.queryObject(Volume.class, clone.getAssociatedSourceVolume());
            parent2snap.put(parent.getNativeId(), clone.getLabel());
            poolsToUpdate.add(parent.getPool());
        }
        String systemId = scaleIOHandle.getSystemId();
        ScaleIOSnapshotVolumeResponse result = scaleIOHandle.snapshotMultiVolume(parent2snap, systemId);
        List<String> nativeIds = result.getVolumeIdList();
        Map<String, ScaleIOVolume> cloneNameMap = scaleIOHandle.getVolumeNameMap(nativeIds);
        Multimap<URI, String> poolToVolumesMap = ArrayListMultimap.create();
        for (Volume clone : clones) {
            String name = clone.getLabel();
            ScaleIOVolume sioVolume = cloneNameMap.get(name);
            ScaleIOHelper.updateSnapshotWithSnapshotVolumeResult(dbClient, clone, systemId, sioVolume.getId(), storage);
            clone.setAllocatedCapacity(Long.parseLong(sioVolume.getSizeInKb()) * 1024L);
            clone.setProvisionedCapacity(clone.getAllocatedCapacity());
            clone.setCapacity(clone.getAllocatedCapacity());
            clone.setReplicationGroupInstance(result.getSnapshotGroupId());
            poolToVolumesMap.put(clone.getPool(), clone.getId().toString());
        }
        dbClient.updateObject(clones);
        List<StoragePool> pools = dbClient.queryObject(StoragePool.class, Lists.newArrayList(poolsToUpdate));
        for (StoragePool pool : pools) {
            pool.removeReservedCapacityForVolumes(poolToVolumesMap.get(pool.getId()));
            ScaleIOHelper.updateStoragePoolCapacity(dbClient, scaleIOHandle, pool, storage);
        }
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("createGroupClone", e.getMessage());
        taskCompleter.error(dbClient, code);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) HashMap(java.util.HashMap) ScaleIOVolume(com.emc.storageos.scaleio.api.restapi.response.ScaleIOVolume) URI(java.net.URI) Volume(com.emc.storageos.db.client.model.Volume) ScaleIOVolume(com.emc.storageos.scaleio.api.restapi.response.ScaleIOVolume) ScaleIOSnapshotVolumeResponse(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSnapshotVolumeResponse) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) HashSet(java.util.HashSet)

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