use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class CoordinatorClientImpl method setNodeDualInetAddressInfo.
/**
* Set node info to zk so that it can be available for lookup in coordinatorclient.
*
* @param nodeId the node_id to be persisted
* @param addresses A string of ip addresses(v4/v6) with ',' as separator
*/
public void setNodeDualInetAddressInfo(String nodeId, String addresses) {
// grab a lock and verifyPublishedDualInetAddress first
InterProcessLock lock = null;
try {
lock = getLock(Constants.NODE_DUALINETADDR_CONFIG + nodeId);
lock.acquire();
if (!verifyPublishedDualInetAddress(nodeId)) {
ConfigurationImpl cfg = new ConfigurationImpl();
cfg.setId(nodeId);
cfg.setKind(Constants.NODE_DUALINETADDR_CONFIG);
cfg.setConfig(Constants.CONFIG_DUAL_INETADDRESSES, addresses);
persistServiceConfiguration(cfg);
}
} catch (Exception e) {
log.warn("Unexpected exception during setNodeDualInetAddressInfo()", e);
} finally {
if (lock != null) {
try {
lock.release();
} catch (Exception e) {
log.warn("Unexpected exception unlocking in setNodeDualInetAddressInfo()", e);
}
}
}
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class OrderService method saveJobInfo.
public void saveJobInfo(OrderJobStatus status) throws Exception {
InterProcessLock lock = coordinatorClient.getLock(ORDER_JOB_LOCK);
lock.acquire();
coordinatorClient.persistRuntimeState(status.getType().name(), status);
lock.release();
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class RecoveryManager method checkRecoveryStatus.
/**
* Check the recovery status saved in ZK.
* a. No recovery required(DONE/FAILED/NULL): nothing to do. simply wait
* b. In progress(PREPARING/REPAIRING/SYNCING): fail new request if there is one in progress
* c. Triggering(INIT): current node should take charge of node recovery
*/
private void checkRecoveryStatus() throws Exception {
while (true) {
InterProcessLock lock = null;
try {
lock = getRecoveryLock();
RecoveryStatus status = queryNodeRecoveryStatus();
if (isRecovering(status)) {
log.warn("This is a stale recovery request due to recovery leader change");
return;
} else if (isTriggering(status)) {
log.info("The recovery status is triggering so run recovery directly");
return;
}
setWaitingRecoveryTriggeringFlag(true);
} catch (Exception e) {
markRecoveryFailed(RecoveryStatus.ErrorCode.INTERNAL_ERROR);
throw e;
} finally {
releaseLock(lock);
}
log.info("Wait to be triggered");
waitOnRecoveryTriggering();
}
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class RecoveryManager method informHibernateNodeToReconfigure.
private void informHibernateNodeToReconfigure() {
DrUtil drUtil = new DrUtil(coordinator.getCoordinatorClient());
if (drUtil.isMultisite()) {
InterProcessLock lock = null;
try {
lock = drUtil.getDROperationLock();
long vdcConfigVersion = DrUtil.newVdcConfigVersion();
log.info("Has multi sites, informing the hibernate nodes to reconfigure..");
drUtil.updateVdcTargetVersion(coordinator.getCoordinatorClient().getSiteId(), SiteInfo.DR_OP_NODE_RECOVERY, vdcConfigVersion);
} catch (Exception e) {
log.error("Failed to inform the hibernate nodes to reconfigure", e);
} finally {
try {
if (lock != null) {
lock.release();
}
} catch (Exception ignore) {
log.error("Release lock failed when node recovery", ignore);
}
}
}
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class RecoveryManager method markRecoveryCancelled.
/**
* Set node recovery status as 'CANCELLED'
*/
private void markRecoveryCancelled() {
InterProcessLock lock = null;
try {
lock = getRecoveryLock();
setRecoveryStatusWithEndTimeMarked(RecoveryStatus.Status.CANCELLED);
} finally {
releaseLock(lock);
}
}
Aggregations