Search in sources :

Example 1 with InterState

use of com.emc.storageos.coordinator.client.model.DrOperationStatus.InterState in project coprhd-controller by CoprHD.

the class VdcManager method auditCompletedDrOperation.

/**
 * Check if ongoing DR operation succeeded or failed, then record audit log accordingly and remove this operation record from ZK.
 */
private void auditCompletedDrOperation() {
    if (!drUtil.isActiveSite()) {
        return;
    }
    InterProcessLock lock = coordinator.getCoordinatorClient().getSiteLocalLock(AUDIT_DR_OPERATION_LOCK);
    boolean hasLock = false;
    try {
        hasLock = lock.acquire(AUDIT_LOCK_WAIT_TIME_SEC, TimeUnit.SECONDS);
        if (!hasLock) {
            return;
        }
        log.info("Local site is active, local node acquired lock, starting audit complete DR operations ...");
        List<Configuration> configs = coordinator.getCoordinatorClient().queryAllConfiguration(DrOperationStatus.CONFIG_KIND);
        if (configs == null || configs.isEmpty()) {
            return;
        }
        for (Configuration config : configs) {
            DrOperationStatus operation = new DrOperationStatus(config);
            String siteId = operation.getSiteUuid();
            InterState interState = operation.getInterState();
            Site site = null;
            try {
                site = drUtil.getSiteFromLocalVdc(siteId);
            } catch (RetryableCoordinatorException e) {
                // Under this situation, just record audit log and clear DR operation status
                if (interState.equals(InterState.REMOVING_STANDBY) && e.getServiceCode() == ServiceCode.COORDINATOR_SITE_NOT_FOUND) {
                    this.auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, getOperationType(interState), System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, siteId);
                    coordinator.getCoordinatorClient().removeServiceConfiguration(config);
                    log.info("DR operation status has been cleared: {}", operation);
                    continue;
                }
                throw e;
            }
            SiteState currentState = site.getState();
            if (currentState.equals(SiteState.STANDBY_ERROR)) {
                // Failed
                this.auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, getOperationType(interState), System.currentTimeMillis(), AuditLogManager.AUDITLOG_FAILURE, AuditLogManager.AUDITOP_END, site.toBriefString());
            } else if (!currentState.isDROperationOngoing()) {
                // Succeeded
                this.auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, getOperationType(interState), System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, site.toBriefString());
            } else {
                // Still ongoing, do nothing
                continue;
            }
            log.info(String.format("Site %s state has transformed from %s to %s", siteId, interState, currentState));
            // clear this operation status
            coordinator.getCoordinatorClient().removeServiceConfiguration(config);
            log.info("DR operation status has been cleared: {}", operation);
        }
    } catch (Exception e) {
        log.error("Auditing DR operation failed with exception", e);
    } finally {
        try {
            if (hasLock) {
                lock.release();
            }
        } catch (Exception e) {
            log.error("Failed to release DR operation audit lock", e);
        }
    }
}
Also used : InterState(com.emc.storageos.coordinator.client.model.DrOperationStatus.InterState) Configuration(com.emc.storageos.coordinator.common.Configuration) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) InvalidLockOwnerException(com.emc.storageos.systemservices.exceptions.InvalidLockOwnerException) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException)

Aggregations

InterState (com.emc.storageos.coordinator.client.model.DrOperationStatus.InterState)1 Configuration (com.emc.storageos.coordinator.common.Configuration)1 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 CoordinatorClientException (com.emc.storageos.systemservices.exceptions.CoordinatorClientException)1 InvalidLockOwnerException (com.emc.storageos.systemservices.exceptions.InvalidLockOwnerException)1 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)1