Search in sources :

Example 96 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXUnitySnapshotOperations method restoreSingleVolumeSnapshot.

@Override
public void restoreSingleVolumeSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot snapshotObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        VNXeApiClient apiClient = getVnxeClient(storage);
        Snap snap = apiClient.getSnapshot(snapshotObj.getNativeId());
        // Error out if the snapshot is attached
        if (snap.isAttached()) {
            log.error("Snapshot {})is exported and cannot be used for restore, please unexport it first", snapshotObj.getLabel());
            ServiceError error = DeviceControllerErrors.vnxe.cannotRestoreAttachedSnapshot(snapshotObj.getLabel());
            taskCompleter.error(_dbClient, error);
        }
        VNXeCommandJob job = apiClient.restoreSnap(snap.getId());
        if (job != null) {
            ControllerServiceImpl.enqueueJob(new QueueJob(new VNXUnityRestoreSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
        }
    } catch (Exception ex) {
        log.error("Restore snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("RestoreSnapshotJob", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXUnityRestoreSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxunity.job.VNXUnityRestoreSnapshotJob) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Snap(com.emc.storageos.vnxe.models.Snap) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 97 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXUnityCreateFileSystemQuotaDirectoryJob method updateStatus.

/**
 * Called to update the job status when the file system Quota Directory create job completes.
 *
 * @param jobContext
 *            The job context.
 */
@Override
public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, _status.name()));
        VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
        URI quotaId = getTaskCompleter().getId();
        QuotaDirectory quotaObj = dbClient.queryObject(QuotaDirectory.class, quotaId);
        URI fsUri = quotaObj.getParent().getURI();
        FileShare fsObj = dbClient.queryObject(FileShare.class, fsUri);
        String event = null;
        if (_status == JobStatus.SUCCESS && quotaObj != null) {
            updateQuota(quotaObj, dbClient, logMsgBuilder, vnxeApiClient);
            event = String.format("Create file system quota directory successfully for URI: %s", getTaskCompleter().getId());
        } else if (_status == JobStatus.FAILED && quotaObj != null) {
            if (!quotaObj.getInactive()) {
                quotaObj.setInactive(true);
                dbClient.updateObject(quotaObj);
            }
            event = String.format("Task %s failed to create file system quota directory: %s", opId, quotaObj.getName());
            logMsgBuilder.append("\n");
            logMsgBuilder.append(event);
        } else {
            logMsgBuilder.append(String.format("Could not find the quota directory:%s", quotaId.toString()));
        }
        _logger.info(logMsgBuilder.toString());
        FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, _isSuccess, event, "", quotaObj, fsObj);
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXUnityCreateFileSystemQuotaDirectoryJob", e);
        setErrorStatus("Encountered an internal error during file system quota create job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) IOException(java.io.IOException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 98 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXeUnManagedObjectDiscoverer method discoverUnManagedVolumes.

public void discoverUnManagedVolumes(AccessProfile accessProfile, DbClient dbClient, CoordinatorClient coordinator, PartitionManager partitionManager) throws Exception {
    log.info("Started discovery of UnManagedVolumes for system {}", accessProfile.getSystemId());
    VNXeApiClient apiClient = getVnxeClient(accessProfile);
    unManagedVolumesInsert = new ArrayList<UnManagedVolume>();
    unManagedVolumesUpdate = new ArrayList<UnManagedVolume>();
    StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
    List<VNXeLun> luns = apiClient.getAllLuns();
    if (luns != null && !luns.isEmpty()) {
        Map<String, StoragePool> pools = getStoragePoolMap(storageSystem, dbClient);
        for (VNXeLun lun : luns) {
            UnManagedVolume unManagedVolume = null;
            String managedVolumeNativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(storageSystem.getNativeGuid(), lun.getId());
            if (null != DiscoveryUtils.checkStorageVolumeExistsInDB(dbClient, managedVolumeNativeGuid)) {
                log.info("Skipping volume {} as it is already managed by ViPR", managedVolumeNativeGuid);
            }
            StoragePool storagePool = getStoragePoolOfUnManagedObject(lun.getPool().getId(), storageSystem, pools);
            if (null == storagePool) {
                log.error("Skipping unmanaged volume discovery as the volume {} storage pool doesn't exist in ViPR", lun.getId());
                continue;
            }
            String unManagedVolumeNatvieGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingVolume(storageSystem.getNativeGuid(), lun.getId());
            unManagedVolume = DiscoveryUtils.checkUnManagedVolumeExistsInDB(dbClient, unManagedVolumeNatvieGuid);
            unManagedVolume = createUnManagedVolume(unManagedVolume, unManagedVolumeNatvieGuid, lun, storageSystem, storagePool, dbClient);
            unManagedVolumesReturnedFromProvider.add(unManagedVolume.getId());
        }
        if (!unManagedVolumesInsert.isEmpty()) {
            partitionManager.insertInBatches(unManagedVolumesInsert, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_VOLUME);
        }
        if (!unManagedVolumesUpdate.isEmpty()) {
            partitionManager.updateAndReIndexInBatches(unManagedVolumesUpdate, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_VOLUME);
        }
        // Process those active unmanaged volume objects available in database but not in newly discovered items, to mark them inactive.
        DiscoveryUtils.markInActiveUnManagedVolumes(storageSystem, unManagedVolumesReturnedFromProvider, dbClient, partitionManager);
    } else {
        log.info("There are no luns found on the system: {}", storageSystem.getId());
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 99 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXeBlockCreateCGSnapshotJob method updateStatus.

public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        BlockSnapshotCreateCompleter completer = (BlockSnapshotCreateCompleter) getTaskCompleter();
        List<BlockSnapshot> snapshots = dbClient.queryObject(BlockSnapshot.class, completer.getSnapshotURIs());
        StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
        if (_status == JobStatus.SUCCESS) {
            VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
            VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
            ParametersOut output = vnxeJob.getParametersOut();
            // get the luns belonging to the lun group
            String lunGroupSnapId = output.getId();
            VNXeLunGroupSnap groupSnap = vnxeApiClient.getLunGroupSnapshot(lunGroupSnapId);
            List<VNXeLun> groupLuns = vnxeApiClient.getLunByStorageResourceId(groupSnap.getStorageResource().getId());
            // Create mapping of volume.nativeDeviceId to BlockSnapshot object
            Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
            for (BlockSnapshot snapshot : snapshots) {
                Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
                volumeToSnapMap.put(volume.getNativeId(), snapshot);
            }
            for (VNXeLun groupLun : groupLuns) {
                BlockSnapshot snapshot = volumeToSnapMap.get(groupLun.getId());
                if (snapshot == null) {
                    _logger.info("No snapshot found for the vnxe lun - ", groupLun.getId());
                    continue;
                }
                snapshot.setNativeId(output.getId());
                snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
                snapshot.setDeviceLabel(groupLun.getName());
                snapshot.setReplicationGroupInstance(lunGroupSnapId);
                snapshot.setIsSyncActive(true);
                snapshot.setInactive(false);
                snapshot.setCreationTime(Calendar.getInstance());
                snapshot.setWWN(groupLun.getSnapWwn());
                snapshot.setAllocatedCapacity(groupLun.getSnapsSizeAllocated());
                snapshot.setProvisionedCapacity(groupLun.getSnapsSize());
                _logger.info(String.format("Going to set blocksnapshot %1$s nativeId to %2$s (%3$s). Associated lun is %4$s (%5$s)", snapshot.getId().toString(), output.getId(), snapshot.getLabel(), groupLun.getId(), groupLun.getName()));
                dbClient.persistObject(snapshot);
            }
        } else if (_status == JobStatus.FAILED) {
            _logger.info("Failed to create snapshot");
            for (BlockSnapshot snapshot : snapshots) {
                snapshot.setInactive(true);
            }
            dbClient.persistObject(snapshots);
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeBlockCreateCGSnapshotJob", e);
        setErrorStatus("Encountered an internal error during group snapshot create job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : VNXeLunGroupSnap(com.emc.storageos.vnxe.models.VNXeLunGroupSnap) DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) BlockSnapshotCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) Volume(com.emc.storageos.db.client.model.Volume) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 100 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXeJob method poll.

@Override
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
    String currentJob = _jobIds.get(0);
    try {
        _logger.info("VNXeJob: Looking up job: id {}", _jobIds.get(0));
        VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
        StringBuilder prettyMsg = new StringBuilder();
        if (vnxeApiClient == null) {
            String errorMessage = "No VNXe client found for: " + _storageSystemUri;
            processTransientError(currentJob, trackingPeriodInMillis, errorMessage, null);
        } else {
            _pollResult.setJobName(_jobName);
            _pollResult.setJobId(_taskCompleter.getOpId());
            int completeCount = 0;
            boolean isSuccess = true;
            StringBuilder msg = new StringBuilder();
            for (String jobId : _jobIds) {
                currentJob = jobId;
                VNXeCommandJob jobResult = vnxeApiClient.getJob(jobId);
                MessageOut msgOut = jobResult.getMessageOut();
                int progressPct = jobResult.getProgressPct();
                int state = jobResult.getState();
                if (state == VNXeCommandJob.JobStatusEnum.FAILED.getValue()) {
                    completeCount++;
                    isSuccess = false;
                    msg.append("Async task failed for jobID ");
                    msg.append(jobId);
                    if (msgOut != null) {
                        msg.append(" " + msgOut.getMessage());
                        String cleanMsg = msgOut.getMessage().split("\\(Error Code")[0];
                        prettyMsg.append(cleanMsg);
                    }
                    continue;
                }
                if (progressPct == 100 && state != VNXeCommandJob.JobStatusEnum.RUNNING.getValue()) {
                    completeCount++;
                    if (state != VNXeCommandJob.JobStatusEnum.COMPLETED.getValue()) {
                        msg.append("Async task failed for jobID ");
                        msg.append(jobId);
                        if (msgOut != null) {
                            msg.append(" " + msgOut.getMessage());
                            String cleanMsg = msgOut.getMessage().split("\\(Error Code")[0];
                            prettyMsg.append(cleanMsg);
                        }
                    }
                }
            }
            if (completeCount == _jobIds.size()) {
                // all completed
                _pollResult.setJobPercentComplete(100);
                if (isSuccess) {
                    _status = JobStatus.SUCCESS;
                    _logger.info("Job: {} succeeded", _jobName);
                } else {
                    _status = JobStatus.FAILED;
                    _errorDescription = prettyMsg.toString();
                    _logger.info(msg.toString());
                }
            } else {
                _pollResult.setJobPercentComplete(100 * completeCount / _jobIds.size());
            }
        }
    } catch (Exception e) {
        processTransientError(currentJob, trackingPeriodInMillis, e.getMessage(), e);
    } finally {
        try {
            updateStatus(jobContext);
        } catch (Exception e) {
            setErrorStatus(e.getMessage());
            _logger.error("Problem while trying to update status", e);
        }
    }
    _pollResult.setJobStatus(_status);
    _pollResult.setErrorDescription(_errorDescription);
    return _pollResult;
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) MessageOut(com.emc.storageos.vnxe.models.MessageOut)

Aggregations

VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)123 VNXeException (com.emc.storageos.vnxe.VNXeException)79 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)66 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)55 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)48 ControllerException (com.emc.storageos.volumecontroller.ControllerException)44 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)40 URI (java.net.URI)37 ArrayList (java.util.ArrayList)34 FileShare (com.emc.storageos.db.client.model.FileShare)33 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)33 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)30 Snapshot (com.emc.storageos.db.client.model.Snapshot)27 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)24 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)23 DbClient (com.emc.storageos.db.client.DbClient)21 Volume (com.emc.storageos.db.client.model.Volume)18 VNXeFileTaskCompleter (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter)18 FileExport (com.emc.storageos.db.client.model.FileExport)14 HashMap (java.util.HashMap)14