Search in sources :

Example 1 with GeoServiceJob

use of com.emc.storageos.security.geo.GeoServiceJob in project coprhd-controller by CoprHD.

the class GeoServiceJobQueue method consumeItem.

/**
 * Verify the hosting device has not migrated states while waiting for dispatching and continue task
 *
 * @param job The object provisioning job which is being worked on. This could be either creation or deletion job
 * @param callback This must be executed, after the item is processed successfully to remove the item
 *            from the distributed queue
 *
 * @throws Exception
 */
@Override
public void consumeItem(GeoServiceJob job, DistributedQueueItemProcessedCallback callback) throws Exception {
    // verify job, db may not stable right now after reboot, retry may need
    VirtualDataCenter vdcInfo = null;
    int retry = 0;
    while (retry < MAX_DB_RETRY) {
        try {
            vdcInfo = _dbClient.queryObject(VirtualDataCenter.class, job.getVdcId());
            break;
        } catch (DatabaseException e) {
            _log.info("db not stable yet, retry");
            try {
                TimeUnit.SECONDS.sleep(WAIT_INTERVAL_IN_SEC);
            } catch (InterruptedException ex) {
            // Ignore this exception
            }
        }
        retry = retry + 1;
    }
    if (vdcInfo == null) {
        _log.info("Failed to query vdc {} from DB. Retry later", job.getVdcId());
        return;
    }
    String task = job.getTask();
    if (task == null) {
        _log.error("The vdc connect job for {} does not have an associated task", job.getVdcId());
        return;
    }
    try {
        _controller.setKeystore(viprKeyStore);
        // these methods will obtain lock and do nothing if operation is already in progress
        GeoServiceJob.JobType type = job.getType();
        switch(type) {
            case VDC_CONNECT_JOB:
                _log.info("Continuing initialization operation {} for {}", task, job.getVdcId());
                _controller.connectVdc(vdcInfo, task, job.getParams());
                break;
            case VDC_REMOVE_JOB:
                _log.info("vdc operation {} for {}", task, job.getVdcId());
                _controller.removeVdc(vdcInfo, task, job.getParams());
                break;
            case VDC_UPDATE_JOB:
                _log.info("Updating operation {} for {}", task, job.getVdcId());
                _controller.updateVdc(job.getVdc(), task, job.getParams());
                break;
            case VDC_DISCONNECT_JOB:
                _log.info("Disconnecting operation {} for {}", task, job.getVdcId());
                _controller.disconnectVdc(vdcInfo, task, job.getParams());
                break;
            case VDC_RECONNECT_JOB:
                _log.info("Reconnecting operation {} for {}", task, job.getVdcId());
                _controller.reconnectVdc(vdcInfo, task, job.getParams());
                break;
            default:
                _log.error("Invalid operation type {} on {}/{}", new Object[] { job.getType(), task, job.getVdcId() });
        }
    } catch (Exception e) {
        // TODO: retry the task if it is retryable exception
        _log.error("Execute job failed", e);
    }
    // removes item from queue
    callback.itemProcessed();
    _log.info("The job type={} vdcId={} task={} is removed", new Object[] { job.getType(), job.getVdcId(), job.getTask() });
}
Also used : GeoServiceJob(com.emc.storageos.security.geo.GeoServiceJob) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 2 with GeoServiceJob

use of com.emc.storageos.security.geo.GeoServiceJob in project coprhd-controller by CoprHD.

the class VirtualDataCenterService method enqueueJob.

private TaskResourceRep enqueueJob(VirtualDataCenter vdc, JobType jobType, List<Object> params) {
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(VirtualDataCenter.class, vdc.getId(), taskId, jobType.toResourceOperationType());
    // add to the job queue
    try {
        GeoServiceJob job = new GeoServiceJob(vdc, taskId, jobType, params);
        _geoHelper.enqueueJob(job);
    } catch (Exception ex) {
        _log.error("Exception occurred while enqueue job on due to:", ex);
        ServiceCoded coded = ServiceError.buildServiceError(ServiceCode.COORDINATOR_UNABLE_TO_QUEUE_JOB, ex.getMessage());
        op.error(coded);
    }
    return TaskMapper.toTask(vdc, taskId, op);
}
Also used : GeoServiceJob(com.emc.storageos.security.geo.GeoServiceJob) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) KeyStoreException(java.security.KeyStoreException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) SecurityException(com.emc.storageos.security.exceptions.SecurityException) UnknownHostException(java.net.UnknownHostException)

Aggregations

DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 GeoServiceJob (com.emc.storageos.security.geo.GeoServiceJob)2 VirtualDataCenter (com.emc.storageos.db.client.model.VirtualDataCenter)1 SecurityException (com.emc.storageos.security.exceptions.SecurityException)1 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 UnknownHostException (java.net.UnknownHostException)1 KeyStoreException (java.security.KeyStoreException)1