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);
}
}
}
}
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);
}
}
}
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);
}
}
}
}
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;
}
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();
}
}
}
}
Aggregations