Search in sources :

Example 11 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSSnapshotOperations method restoreSingleVolumeSnapshot.

/**
 * 1. Find pair management server.
 * 2. Get SnapshotGroup's Object Id.
 * 3. Get ReplicationInfo's Object Id.
 * 4. Perform ReplicationInfo Restore operation.
 */
@Override
public void restoreSingleVolumeSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot from = dbClient.queryObject(BlockSnapshot.class, snapshot);
        Volume to = dbClient.queryObject(Volume.class, volume);
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSHost pairMgmtServer = hdsApiClient.getSnapshotGroupPairManagementServer(storage.getSerialNumber());
        if (pairMgmtServer == null) {
            log.error("Unable to find snapshot group information/pair management server for Thin Image");
            throw HDSException.exceptions.snapshotGroupNotAvailable(storage.getNativeGuid());
        }
        SnapshotGroup snapShotGrp = getViPRSnapshotGroup(pairMgmtServer, storage.getSerialNumber());
        log.debug("to.getNativeId() :{}", to.getNativeId());
        log.debug("from.getNativeId() :{}", from.getNativeId());
        ReplicationInfo repInfo = getReplicationInfo(snapShotGrp, to.getNativeId(), from.getNativeId());
        hdsApiClient.restoreThinImagePair(pairMgmtServer.getObjectID(), snapShotGrp.getObjectID(), repInfo.getObjectID(), storage.getModel());
        taskCompleter.ready(dbClient);
        log.info("Restore Snapshot volume completed");
    } catch (Exception e) {
        String message = String.format("Generic exception when trying to restore from snapshot %s on array %s", snapshot.toString(), storage.getSerialNumber());
        log.error(message, e);
        ServiceError error = DeviceControllerErrors.hds.methodFailed("restoreSingleVolumeSnapshot", e.getMessage());
        taskCompleter.error(dbClient, error);
    }
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) HDSHost(com.emc.storageos.hds.model.HDSHost) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) SnapshotGroup(com.emc.storageos.hds.model.SnapshotGroup) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 12 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSStorageDevice method doModifyVolumes.

@Override
public void doModifyVolumes(StorageSystem storage, StoragePool storagePool, String opId, List<Volume> volumes, TaskCompleter taskCompleter) throws DeviceControllerException {
    StringBuilder logMsgBuilder = new StringBuilder(String.format("Modify Volume Start - Array:%s, Pool:%s", storage.getSerialNumber(), storagePool.getNativeGuid()));
    String systemObjectID = HDSUtils.getSystemObjectID(storage);
    for (Volume volume : volumes) {
        try {
            HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
            logMsgBuilder.append(String.format("%nVolume:%s , IsThinlyProvisioned: %s, tieringPolicy: %s", volume.getLabel(), volume.getThinlyProvisioned(), volume.getAutoTieringPolicyUri()));
            LogicalUnit logicalUnit = hdsApiClient.getLogicalUnitInfo(systemObjectID, HDSUtils.getLogicalUnitObjectId(volume.getNativeId(), storage));
            String policyName = ControllerUtils.getAutoTieringPolicyName(volume.getId(), dbClient);
            String autoTierPolicyName = null;
            if (policyName.equals(Constants.NONE)) {
                autoTierPolicyName = null;
            } else {
                autoTierPolicyName = HitachiTieringPolicy.getPolicy(policyName.replaceAll(HDSConstants.SLASH_OPERATOR, HDSConstants.UNDERSCORE_OPERATOR)).getKey();
            }
            if (null != logicalUnit && null != logicalUnit.getLdevList() && !logicalUnit.getLdevList().isEmpty()) {
                Iterator<LDEV> ldevItr = logicalUnit.getLdevList().iterator();
                if (ldevItr.hasNext()) {
                    LDEV ldev = ldevItr.next();
                    String asyncMessageId = hdsApiClient.modifyThinVolumeTieringPolicy(systemObjectID, logicalUnit.getObjectID(), ldev.getObjectID(), autoTierPolicyName, storage.getModel());
                    if (null != asyncMessageId) {
                        HDSJob modifyHDSJob = new HDSModifyVolumeJob(asyncMessageId, volume.getStorageController(), taskCompleter, HDSModifyVolumeJob.VOLUME_MODIFY_JOB);
                        ControllerServiceImpl.enqueueJob(new QueueJob(modifyHDSJob));
                    } else {
                        throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the modify volume call");
                    }
                }
            } else {
                String errorMsg = String.format("No LDEV's found for volume: %s", volume.getId());
                log.info(errorMsg);
                ServiceError serviceError = DeviceControllerErrors.hds.methodFailed("doModifyVolumes", errorMsg);
                taskCompleter.error(dbClient, serviceError);
            }
        } catch (final Exception e) {
            log.error("Problem in doModifyVolumes: ", e);
            ServiceError serviceError = DeviceControllerErrors.hds.methodFailed("doModifyVolumes", e.getMessage());
            taskCompleter.error(dbClient, serviceError);
        }
    }
}
Also used : HDSModifyVolumeJob(com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSModifyVolumeJob) HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HDSJob(com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSJob) Volume(com.emc.storageos.db.client.model.Volume) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) LDEV(com.emc.storageos.hds.model.LDEV) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException)

Example 13 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSStorageDevice method doDeleteVolumes.

/*
     * (non-Javadoc)
     * 
     * @see com.emc.storageos.volumecontroller.BlockStorageDevice#doDeleteVolumes(com.emc.storageos.db.client.model.StorageSystem,
     * java.lang.String, java.util.List, com.emc.storageos.volumecontroller.TaskCompleter)
     */
@Override
public void doDeleteVolumes(StorageSystem storageSystem, String opId, List<Volume> volumes, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Volume Start - Array:%s", storageSystem.getSerialNumber()));
        MultiVolumeTaskCompleter multiVolumeTaskCompleter = (MultiVolumeTaskCompleter) taskCompleter;
        Set<String> thickLogicalUnitIdList = new HashSet<String>();
        Set<String> thinLogicalUnitIdList = new HashSet<String>();
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
        String systemObjectId = HDSUtils.getSystemObjectID(storageSystem);
        log.info("volumes size: {}", volumes.size());
        for (Volume volume : volumes) {
            logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
            String logicalUnitObjectId = HDSUtils.getLogicalUnitObjectId(volume.getNativeId(), storageSystem);
            LogicalUnit logicalUnit = hdsApiClient.getLogicalUnitInfo(systemObjectId, logicalUnitObjectId);
            if (logicalUnit == null) {
                // related volume state (if any) has been deleted. skip
                // processing, if already deleted from array.
                log.info(String.format("Volume %s already deleted: ", volume.getNativeId()));
                volume.setInactive(true);
                dbClient.persistObject(volume);
                VolumeTaskCompleter deleteTaskCompleter = multiVolumeTaskCompleter.skipTaskCompleter(volume.getId());
                deleteTaskCompleter.ready(dbClient);
                continue;
            }
            if (volume.getThinlyProvisioned()) {
                thinLogicalUnitIdList.add(logicalUnitObjectId);
            } else {
                thickLogicalUnitIdList.add(logicalUnitObjectId);
            }
        }
        log.info(logMsgBuilder.toString());
        if (!multiVolumeTaskCompleter.isVolumeTaskCompletersEmpty()) {
            if (null != thickLogicalUnitIdList && !thickLogicalUnitIdList.isEmpty()) {
                String asyncThickLUsJobId = hdsApiClient.deleteThickLogicalUnits(systemObjectId, thickLogicalUnitIdList, storageSystem.getModel());
                if (null != asyncThickLUsJobId) {
                    ControllerServiceImpl.enqueueJob(new QueueJob(new HDSDeleteVolumeJob(asyncThickLUsJobId, volumes.get(0).getStorageController(), taskCompleter)));
                } else {
                    throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the delete volume call");
                }
            }
            if (null != thinLogicalUnitIdList && !thinLogicalUnitIdList.isEmpty()) {
                String asyncThinHDSJobId = hdsApiClient.deleteThinLogicalUnits(systemObjectId, thinLogicalUnitIdList, storageSystem.getModel());
                // in single operation.
                if (null != asyncThinHDSJobId) {
                    ControllerServiceImpl.enqueueJob(new QueueJob(new HDSDeleteVolumeJob(asyncThinHDSJobId, volumes.get(0).getStorageController(), taskCompleter)));
                } else {
                    throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the delete volume call");
                }
            }
        } else {
            // If we are here, there are no volumes to delete, we have
            // invoked ready() for the VolumeDeleteCompleter, and told
            // the multiVolumeTaskCompleter to skip these completers.
            // In this case, the multiVolumeTaskCompleter complete()
            // method will not be invoked and the result is that the
            // workflow that initiated this delete request will never
            // be updated. So, here we just call complete() on the
            // multiVolumeTaskCompleter to ensure the workflow status is
            // updated.
            multiVolumeTaskCompleter.ready(dbClient);
        }
    } catch (Exception e) {
        log.error("Problem in doDeleteVolume: ", e);
        ServiceError error = DeviceControllerErrors.hds.methodFailed("doDeleteVolume", e.getMessage());
        taskCompleter.error(dbClient, error);
    }
    StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Volume End - Array: %s", storageSystem.getSerialNumber()));
    for (Volume volume : volumes) {
        logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
    }
    log.info(logMsgBuilder.toString());
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) HDSDeleteVolumeJob(com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSDeleteVolumeJob) MultiVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) VolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter) MultiVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter) MetaVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MetaVolumeTaskCompleter) Volume(com.emc.storageos.db.client.model.Volume) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) HashSet(java.util.HashSet)

Example 14 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSBlockCreateSnapshotJob method updateStatus.

@Override
public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        // Do nothing if the job is not completed yet
        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()));
        StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
        HDSApiClient hdsApiClient = jobContext.getHdsApiFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
        URI snapshotId = getTaskCompleter().getId(0);
        log.info("snapshotId :{}", snapshotId);
        if (_status == JobStatus.SUCCESS) {
            LogicalUnit logicalUnit = (LogicalUnit) _javaResult.getBean("virtualVolume");
            BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotId);
            snapshot.setNativeId(String.valueOf(logicalUnit.getDevNum()));
            snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
            snapshot.setInactive(false);
            snapshot.setCreationTime(Calendar.getInstance());
            long capacityInBytes = Long.valueOf(logicalUnit.getCapacityInKB()) * 1024L;
            snapshot.setProvisionedCapacity(capacityInBytes);
            snapshot.setAllocatedCapacity(capacityInBytes);
            snapshot.setWWN(HDSUtils.generateHitachiWWN(logicalUnit.getObjectID(), String.valueOf(logicalUnit.getDevNum())));
            snapshot.setIsSyncActive(true);
            dbClient.persistObject(snapshot);
            changeSnapshotName(dbClient, hdsApiClient, snapshot);
            if (logMsgBuilder.length() != 0) {
                logMsgBuilder.append("\n");
            }
            logMsgBuilder.append(String.format("Created Snapshot successfully .. NativeId: %s, URI: %s", snapshot.getNativeId(), getTaskCompleter().getId()));
        } else if (_status == JobStatus.FAILED) {
            logMsgBuilder.append("\n");
            logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, getTaskCompleter().getId().toString()));
            Snapshot snapshot = dbClient.queryObject(Snapshot.class, snapshotId);
            if (snapshot != null) {
                snapshot.setInactive(true);
                dbClient.persistObject(snapshot);
            }
        }
        log.info(logMsgBuilder.toString());
    } catch (Exception e) {
        log.error("Caught an exception while trying to updateStatus for HDSBlockCreateSnapshotJob", e);
        setErrorStatus("Encountered an internal error during snapshot create job status processing : " + e.getMessage());
    } finally {
        _postProcessingStatus = JobStatus.SUCCESS;
        super.updateStatus(jobContext);
    }
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) Snapshot(com.emc.storageos.db.client.model.Snapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) DbClient(com.emc.storageos.db.client.DbClient) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 15 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSDeleteVolumeJob method updateStatus.

/**
 * Called to update the job status when the volume delete job completes.
 *
 * @param jobContext The job context.
 */
public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
        HDSApiClient hdsApiClient = jobContext.getHdsApiFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
        // Get list of volumes; get set of storage pool ids to which they
        // belong.
        List<Volume> volumes = new ArrayList<Volume>();
        Set<URI> poolURIs = new HashSet<URI>();
        for (URI id : getTaskCompleter().getIds()) {
            // Volume volume = dbClient.queryObject(Volume.class, id);
            Volume volume = (Volume) BlockObject.fetch(dbClient, id);
            if (volume != null && !volume.getInactive()) {
                volumes.add(volume);
                poolURIs.add(volume.getPool());
            }
        }
        // If terminal state update storage pool capacity
        if (_status == JobStatus.SUCCESS || _status == JobStatus.FAILED) {
            // Update capacity of storage pools.
            for (URI poolURI : poolURIs) {
                StoragePool storagePool = dbClient.queryObject(StoragePool.class, poolURI);
                HDSUtils.updateStoragePoolCapacity(dbClient, hdsApiClient, storagePool);
            }
        }
        StringBuilder logMsgBuilder = new StringBuilder();
        if (_status == JobStatus.SUCCESS) {
            for (Volume volume : volumes) {
                if (logMsgBuilder.length() != 0) {
                    logMsgBuilder.append("\n");
                }
                logMsgBuilder.append(String.format("Successfully deleted volume %s", volume.getId()));
            }
        } else if (_status == JobStatus.FAILED) {
            for (URI id : getTaskCompleter().getIds()) {
                if (logMsgBuilder.length() != 0) {
                    logMsgBuilder.append("\n");
                }
                logMsgBuilder.append(String.format("Failed to delete volume: %s", id));
            }
        }
        if (logMsgBuilder.length() > 0) {
            _log.info(logMsgBuilder.toString());
        }
    } catch (Exception e) {
        setPostProcessingErrorStatus("Encountered an internal error during delete volume job status processing: " + e.getMessage());
        _log.error("Caught exception while handling updateStatus for delete volume job.", e);
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) DbClient(com.emc.storageos.db.client.DbClient) StoragePool(com.emc.storageos.db.client.model.StoragePool) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet)

Aggregations

HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)45 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)26 HDSException (com.emc.storageos.hds.HDSException)26 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)21 Volume (com.emc.storageos.db.client.model.Volume)14 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)13 HDSApiExportManager (com.emc.storageos.hds.api.HDSApiExportManager)12 HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)12 ArrayList (java.util.ArrayList)12 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)11 HashSet (java.util.HashSet)11 ExportMask (com.emc.storageos.db.client.model.ExportMask)10 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)10 URI (java.net.URI)10 HDSJob (com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSJob)9 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)8 ReplicationInfo (com.emc.storageos.hds.model.ReplicationInfo)7 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 StoragePool (com.emc.storageos.db.client.model.StoragePool)6 HDSApiProtectionManager (com.emc.storageos.hds.api.HDSApiProtectionManager)6