Search in sources :

Example 6 with DbClient

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

the class ExternalDeviceJob method poll.

/**
 * {@inheritDoc}
 */
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
    s_logger.info("Polled external device job for driver task {} on storage system {}", _driverTaskId, _storageSystemURI);
    DriverTask driverTask = null;
    DbClient dbClient = jobContext.getDbClient();
    try {
        // Update the job info.
        _pollResult.setJobName(_driverTaskId);
        _pollResult.setJobId(_driverTaskId);
        _pollResult.setJobPercentComplete(0);
        // Get the external storage system on which the driver task is running.
        StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, _storageSystemURI);
        if (storageSystem == null) {
            s_logger.error("Could not find external storage system {}", _storageSystemURI);
            throw ExternalDeviceException.exceptions.cantFindStorageSystemForDriverTask(_storageSystemURI.toString(), _driverTaskId);
        }
        String systemType = storageSystem.getSystemType();
        // Get the external storage driver for the system on which the task is executing.
        BlockStorageDriver driver = ExternalBlockStorageDevice.getBlockStorageDriver(systemType);
        if (driver == null) {
            s_logger.error("Could not find storage driver for system type {}", systemType);
            throw ExternalDeviceException.exceptions.noDriverDefinedForDevice(systemType);
        }
        // Get the storage driver task.
        driverTask = driver.getTask(_driverTaskId);
        if (driverTask == null) {
            s_logger.error("Could not find storage driver task {} for storage system {}", _driverTaskId, _storageSystemURI.toString());
            throw ExternalDeviceException.exceptions.cantFindDriverTaskOnSystem(_driverTaskId, _storageSystemURI.toString());
        }
        TaskStatus taskStatus = driverTask.getStatus();
        String taskStatusMsg = driverTask.getMessage();
        if (isTaskSuccessful(taskStatus)) {
            // Completed successfully
            s_logger.info(String.format("Task %s completed successfully with status %s:%s", _driverTaskId, taskStatus, taskStatusMsg));
            doTaskSucceeded(driverTask, dbClient);
            _pollResult.setJobPercentComplete(100);
            _status = JobStatus.SUCCESS;
        } else if (isTaskFailed(taskStatus)) {
            // Failed.
            s_logger.info(String.format("Task %s failed with status %s:%s", _driverTaskId, taskStatus, taskStatusMsg));
            doTaskFailed(driverTask, dbClient);
            _pollResult.setJobPercentComplete(100);
            _errorDescription = taskStatusMsg;
            _status = JobStatus.FAILED;
        }
    } catch (Exception e) {
        _errorDescription = e.getMessage();
        s_logger.error(String.format("Unexpected error getting external driver task status for task %s on storage system %s: %s", _driverTaskId, _storageSystemURI.toString(), _errorDescription), e);
        try {
            doTaskFailed(driverTask, dbClient);
        } catch (Exception dtfe) {
            s_logger.error("Unexpected error handling task failed", e);
        }
        _status = JobStatus.FAILED;
    } finally {
        updateStatus(dbClient);
    }
    _pollResult.setJobStatus(_status);
    _pollResult.setErrorDescription(_errorDescription);
    return _pollResult;
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) DbClient(com.emc.storageos.db.client.DbClient) TaskStatus(com.emc.storageos.storagedriver.DriverTask.TaskStatus) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) ExternalDeviceException(com.emc.storageos.volumecontroller.impl.externaldevice.ExternalDeviceException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 7 with DbClient

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

the class FrontEndPortStatsProcessor method processResult.

@SuppressWarnings("unchecked")
@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
    Iterator<CIMInstance> storagePortStatsResponseItr = (Iterator<CIMInstance>) resultObj;
    AccessProfile profile = (AccessProfile) keyMap.get(Constants.ACCESSPROFILE);
    URI systemId = profile.getSystemId();
    DbClient dbClient = (DbClient) keyMap.get(Constants.dbClient);
    logger.info("Processing FrontEnd Ports response");
    try {
        List<Stat> metricsObjList = (List<Stat>) keyMap.get(Constants._Stats);
        while (storagePortStatsResponseItr.hasNext()) {
            CIMInstance storagePortStatInstance = (CIMInstance) storagePortStatsResponseItr.next();
            Stat fePortStat = new Stat();
            fePortStat.setServiceType(Constants._Block);
            fePortStat.setTimeCollected((Long) keyMap.get(Constants._TimeCollected));
            Long providerCollectionTime = convertCIMStatisticTime(getCIMPropertyValue(storagePortStatInstance, STATISTICTIME));
            if (0 != providerCollectionTime) {
                fePortStat.setTimeInMillis(providerCollectionTime);
            } else {
                fePortStat.setTimeInMillis((Long) keyMap.get(Constants._TimeCollected));
            }
            fePortStat.setTotalIOs(ControllerUtils.getModLongValue(getCIMPropertyValue(storagePortStatInstance, TOTALIOS)));
            fePortStat.setKbytesTransferred(ControllerUtils.getModLongValue(getCIMPropertyValue(storagePortStatInstance, KBYTESTRANSFERRED)));
            setPortRelatedInfo(storagePortStatInstance, systemId, dbClient, fePortStat);
            metricsObjList.add(fePortStat);
        }
    } catch (Exception ex) {
        logger.error("Failed while extracting Stats for Front end ports: ", ex);
    } finally {
        resultObj = null;
    }
    logger.info("Processing FrontEnd Ports response completed");
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) Stat(com.emc.storageos.db.client.model.Stat) Iterator(java.util.Iterator) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) AccessProfile(com.emc.storageos.plugins.AccessProfile) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException)

Example 8 with DbClient

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

the class HDSMetaVolumeOperations method waitForAsyncHDSJob.

/**
 * Waits the thread to till the operation completes.
 *
 * @param storageDeviceURI
 * @param messageId
 * @param job
 * @param hdsApiFactory
 * @return
 * @throws HDSException
 */
private JobStatus waitForAsyncHDSJob(URI storageDeviceURI, String messageId, HDSJob job, HDSApiFactory hdsApiFactory) throws HDSException {
    JobStatus status = JobStatus.IN_PROGRESS;
    if (job == null) {
        TaskCompleter taskCompleter = new TaskCompleter() {

            @Override
            public void ready(DbClient dbClient) throws DeviceControllerException {
            }

            @Override
            public void error(DbClient dbClient, ServiceCoded serviceCoded) throws DeviceControllerException {
            }

            @Override
            protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
            }
        };
        job = new HDSJob(messageId, storageDeviceURI, taskCompleter, "");
    } else {
        job.setHDSJob(messageId);
    }
    JobContext jobContext = new JobContext(dbClient, null, null, hdsApiFactory, null, null, null, null);
    long startTime = System.currentTimeMillis();
    while (true) {
        JobPollResult result = job.poll(jobContext, SYNC_WRAPPER_WAIT);
        if (result.getJobStatus().equals(JobStatus.IN_PROGRESS) || result.getJobStatus().equals(JobStatus.ERROR)) {
            if (System.currentTimeMillis() - startTime > SYNC_WRAPPER_TIME_OUT) {
                HDSException.exceptions.asyncTaskFailedTimeout(System.currentTimeMillis() - startTime);
            } else {
                try {
                    Thread.sleep(SYNC_WRAPPER_WAIT);
                } catch (InterruptedException e) {
                    log.error("Thread waiting for hds job to complete was interrupted and " + "will be resumed");
                }
            }
        } else {
            status = result.getJobStatus();
            if (!status.equals(JobStatus.SUCCESS)) {
                HDSException.exceptions.asyncTaskFailedWithErrorResponseWithoutErrorCode(messageId, result.getErrorDescription());
            }
            break;
        }
    }
    return status;
}
Also used : JobStatus(com.emc.storageos.volumecontroller.Job.JobStatus) JobStatus(com.emc.storageos.volumecontroller.Job.JobStatus) DbClient(com.emc.storageos.db.client.DbClient) HDSJob(com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSJob) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) MetaVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MetaVolumeTaskCompleter) JobContext(com.emc.storageos.volumecontroller.JobContext) JobPollResult(com.emc.storageos.volumecontroller.impl.JobPollResult)

Example 9 with DbClient

use of com.emc.storageos.db.client.DbClient 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 10 with DbClient

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

the class HDSDeleteSnapshotJob method updateStatus.

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()));
        URI snapshotId = getTaskCompleter().getId(0);
        log.debug("snapshotId :{}", snapshotId);
        BlockSnapshot snapshotObj = (BlockSnapshot) BlockObject.fetch(dbClient, snapshotId);
        if (_status == JobStatus.SUCCESS) {
            snapshotObj.setInactive(true);
            dbClient.persistObject(snapshotObj);
            if (logMsgBuilder.length() != 0) {
                logMsgBuilder.append("\n");
            }
            logMsgBuilder.append(String.format("Successfully deleted snapshot %s", snapshotId));
        } else if (_status == JobStatus.FAILED) {
            logMsgBuilder.append(String.format("Failed to delete snapshot: %s", snapshotId));
        }
        if (logMsgBuilder.length() > 0) {
            log.info(logMsgBuilder.toString());
        }
    } catch (Exception e) {
        setErrorStatus("Encountered an internal error during delete snapshot job status processing: " + e.getMessage());
        super.updateStatus(jobContext);
        log.error("Caught exception while handling updateStatus for delete snapshot job.", e);
    } finally {
        _postProcessingStatus = JobStatus.SUCCESS;
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI)

Aggregations

DbClient (com.emc.storageos.db.client.DbClient)253 URI (java.net.URI)155 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)73 Volume (com.emc.storageos.db.client.model.Volume)67 ArrayList (java.util.ArrayList)58 Test (org.junit.Test)42 FileShare (com.emc.storageos.db.client.model.FileShare)34 NamedURI (com.emc.storageos.db.client.model.NamedURI)31 CIMObjectPath (javax.cim.CIMObjectPath)31 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)29 WBEMClient (javax.wbem.client.WBEMClient)29 StringSet (com.emc.storageos.db.client.model.StringSet)28 CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)28 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)26 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)25 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)22 InternalDbClient (com.emc.storageos.db.client.upgrade.InternalDbClient)22 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)21 CIMInstance (javax.cim.CIMInstance)21 BlockObject (com.emc.storageos.db.client.model.BlockObject)20