Search in sources :

Example 41 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class DrDbHealthMonitor method checkAndRejoinSite.

private void checkAndRejoinSite(Site standbySite) {
    String siteId = standbySite.getUuid();
    int nodeCount = standbySite.getNodeCount();
    // or the data sync will fail anyways
    if (drUtil.getNumberOfLiveServices(siteId, Constants.DBSVC_NAME) == nodeCount || drUtil.getNumberOfLiveServices(siteId, Constants.GEODBSVC_NAME) == nodeCount) {
        log.info("All the dbsvc/geodbsvc instances are back. Rejoining site {}", standbySite.getUuid());
        InterProcessLock lock;
        try {
            lock = drUtil.getDROperationLock();
        } catch (APIException e) {
            log.warn("There are ongoing dr operations. Try again later.");
            return;
        }
        try {
            long vdcVersion = DrUtil.newVdcConfigVersion();
            standbySite.setState(SiteState.STANDBY_RESUMING);
            coordinatorClient.persistServiceConfiguration(standbySite.toConfiguration());
            long dataRevision = vdcVersion;
            drUtil.updateVdcTargetVersion(standbySite.getUuid(), SiteInfo.DR_OP_CHANGE_DATA_REVISION, vdcVersion, dataRevision);
            // Update version on other connected standby sites if any
            for (Site site : drUtil.listSites()) {
                if (site.equals(standbySite) || site.getUuid().equals(coordinatorClient.getSiteId())) {
                    // target site or local site
                    continue;
                }
                drUtil.updateVdcTargetVersion(site.getUuid(), SiteInfo.NONE, vdcVersion);
            }
            // Update version on active site but do nothing
            drUtil.updateVdcTargetVersion(coordinatorClient.getSiteId(), SiteInfo.NONE, vdcVersion);
        } catch (Exception e) {
            log.error("Failed to initiate rejoin standby operation. Try again later", e);
        } finally {
            try {
                lock.release();
            } catch (Exception e) {
                log.error("Failed to release the dr operation lock", e);
            }
        }
    }
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) IOException(java.io.IOException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 42 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class DrDbHealthMonitor method degradeSites.

private void degradeSites(List<Site> sitesToDegrade) {
    InterProcessLock lock;
    try {
        lock = drUtil.getDROperationLock();
    } catch (APIException e) {
        log.warn("There are ongoing dr operations. Try again later.");
        return;
    }
    try {
        long vdcVersion = DrUtil.newVdcConfigVersion();
        // Update degraded sites
        for (Site standbySite : sitesToDegrade) {
            standbySite.setState(SiteState.STANDBY_DEGRADING);
            coordinatorClient.persistServiceConfiguration(standbySite.toConfiguration());
            drUtil.updateVdcTargetVersion(standbySite.getUuid(), SiteInfo.DR_OP_DEGRADE_STANDBY, vdcVersion);
            drUtil.recordDrOperationStatus(standbySite.getUuid(), InterState.DEGRADING_STANDBY);
        }
        // Update all other connected sites
        List<Site> connectedSites = getOtherConnectedSites(sitesToDegrade);
        for (Site site : connectedSites) {
            drUtil.updateVdcTargetVersion(site.getUuid(), SiteInfo.NONE, vdcVersion);
        }
        // Update local site
        drUtil.updateVdcTargetVersion(coordinatorClient.getSiteId(), SiteInfo.DR_OP_DEGRADE_STANDBY, vdcVersion);
    } catch (Exception e) {
        log.error("Failed to initiate degrade standby operation. Try again later", e);
    } finally {
        try {
            lock.release();
        } catch (Exception e) {
            log.error("Failed to release the dr operation lock", e);
        }
    }
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) IOException(java.io.IOException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 43 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class IpReconfigManager method assureIPConsistent.

/**
 * Assure local site IP info is consistent with that in ZK.
 * (DR/GEO procedures store IP info in ZK even for single site since Yoda.)
 */
void assureIPConsistent() {
    InterProcessLock lock = null;
    try {
        log.info("Assuring local site IPs are consistent with ZK ...");
        lock = _coordinator.getCoordinatorClient().getLock(UPDATE_ZKIP_LOCK);
        lock.acquire();
        log.info("Got lock for updating local site IPs into ZK ...");
        Site site = drUtil.getLocalSite();
        if (localIpinfo.weakEqual(site.getVip(), site.getVip6(), site.getHostIPv4AddressMap(), site.getHostIPv6AddressMap())) {
            log.info("local site IPs are consistent with ZK, no need to update.");
            return;
        } else {
            log.info("local site IPs are not consistent with ZK, updating.");
            log.info("    local ipinfo:{}", localIpinfo.toString());
            log.info("    zk ipinfo: vip={}", site.getVip());
            log.info("    zk ipinfo: vip6={}", site.getVip6());
            SortedSet<String> nodeIds = new TreeSet<String>(site.getHostIPv4AddressMap().keySet());
            for (String nodeId : nodeIds) {
                log.info("    {}: ipv4={}", nodeId, site.getHostIPv4AddressMap().get(nodeId));
                log.info("    {}: ipv6={}", nodeId, site.getHostIPv6AddressMap().get(nodeId));
            }
        }
        site.setVip6(localIpinfo.getIpv6Setting().getNetworkVip6());
        site.setVip(localIpinfo.getIpv4Setting().getNetworkVip());
        Map<String, String> ipv4Addresses = new HashMap<>();
        Map<String, String> ipv6Addresses = new HashMap<>();
        int nodeIndex = 1;
        for (String nodeip : localIpinfo.getIpv4Setting().getNetworkAddrs()) {
            String nodeId;
            nodeId = IpReconfigConstants.VDC_NODE_PREFIX + nodeIndex++;
            ipv4Addresses.put(nodeId, nodeip);
        }
        nodeIndex = 1;
        for (String nodeip : localIpinfo.getIpv6Setting().getNetworkAddrs()) {
            String nodeId;
            nodeId = IpReconfigConstants.VDC_NODE_PREFIX + nodeIndex++;
            ipv6Addresses.put(nodeId, nodeip);
        }
        site.setHostIPv4AddressMap(ipv4Addresses);
        site.setHostIPv6AddressMap(ipv6Addresses);
        site.setNodeCount(localIpinfo.getNodeCount());
        _coordinator.getCoordinatorClient().persistServiceConfiguration(site.toConfiguration());
        // wake up syssvc to regenerate configurations
        drUtil.updateVdcTargetVersion(_coordinator.getCoordinatorClient().getSiteId(), SiteInfo.IP_OP_CHANGE, System.currentTimeMillis());
        log.info("Finished update local site IPs into ZK");
    } catch (Exception e) {
        log.warn("Unexpected exception during updating local site IPs into ZK", e);
    } finally {
        if (lock != null) {
            try {
                lock.release();
            } catch (Exception e) {
                log.warn("Unexpected exception during unlocking update_zkip lock", e);
            }
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException)

Example 44 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class RecoveryManager method getRecoveryLock.

/**
 * Get recovery lock to protect the setting of recovery status
 */
private InterProcessLock getRecoveryLock() {
    InterProcessLock lock = null;
    log.info("Try to acquire recovery lock");
    try {
        lock = coordinator.getCoordinatorClient().getLock(RecoveryConstants.RECOVERY_LOCK);
        boolean acquired = lock.acquire(RecoveryConstants.RECOVERY_LOCK_TIMEOUT, TimeUnit.MILLISECONDS);
        if (!acquired) {
            throw new IllegalStateException("Unable to get recovery lock");
        }
    } catch (Exception e) {
        log.error("Get recovery lock failed", e);
        throw APIException.internalServerErrors.getLockFailed();
    }
    log.info("Got recovery lock");
    return lock;
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SysClientException(com.emc.storageos.systemservices.exceptions.SysClientException)

Example 45 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class SignatureKeyGenerator method deleteSignatureKey.

/**
 * Delete a particular signature key
 *
 * @param relKeyLocation "leaf" node under \getSignatureKeyConfig()\getSignatureKeyId()\
 * @param relKeyLocation
 * @throws Exception
 */
protected synchronized void deleteSignatureKey(String relKeyLocation) throws Exception {
    Configuration config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
    if (config != null && config.getConfig(relKeyLocation) != null) {
        InterProcessLock lock = null;
        try {
            lock = _coordinator.getLock(getDistributedSignatureKeyLock());
            lock.acquire();
            config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
            config.removeConfig(relKeyLocation);
            _coordinator.persistServiceConfiguration(config);
        } finally {
            if (lock != null) {
                lock.release();
            }
        }
    }
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock)

Aggregations

InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)98 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)25 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)21 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 IOException (java.io.IOException)15 ControllerException (com.emc.storageos.volumecontroller.ControllerException)14 Configuration (com.emc.storageos.coordinator.common.Configuration)12 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)12 UnknownHostException (java.net.UnknownHostException)12 Site (com.emc.storageos.coordinator.client.model.Site)11 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)11 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)10 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)9 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)9 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)9 ArrayList (java.util.ArrayList)9 POST (javax.ws.rs.POST)9 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)8 Path (javax.ws.rs.Path)8 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)6