use of com.emc.storageos.coordinator.client.service.DistributedPersistentLock in project coprhd-controller by CoprHD.
the class ControllerLockingServiceImpl method releasePersistentLock.
@Override
public boolean releasePersistentLock(String lockName, String clientName) {
if (lockName == null || lockName.isEmpty()) {
return false;
}
try {
DistributedPersistentLock lock = _coordinator.getPersistentLock(lockName);
if (lock != null) {
boolean result = lock.releaseLock(clientName);
log.info("Released lock: " + lockName);
return result;
} else {
log.error(String.format("Release of mutex lock: %s failed: ", lockName));
}
} catch (Exception e) {
log.error(String.format("Release of mutex lock: %s failed with Exception: ", lockName), e);
}
return false;
}
use of com.emc.storageos.coordinator.client.service.DistributedPersistentLock in project coprhd-controller by CoprHD.
the class CoordinatorClientExt method releasePersistentLock.
/**
* The method to release the persistent upgrade lock.
* Any node which calls the method can release the lock.
*
* @param lockId
* - lock id
* @return true if succeed; false otherwise
* @throws Exception
*/
public boolean releasePersistentLock(String lockId) throws Exception {
DistributedPersistentLock lock = _coordinator.getSiteLocalPersistentLock(lockId);
if (lock != null) {
String lockOwner = lock.getLockOwner();
if (lockOwner == null) {
_log.info("Upgrade lock is not held by any node");
return true;
}
boolean result = lock.releaseLock(lockOwner);
if (result) {
_log.info("Upgrade lock {} released successfully", lockId);
return true;
} else {
_log.info("Upgrade lock {} released failed", lockId);
}
}
return false;
}
use of com.emc.storageos.coordinator.client.service.DistributedPersistentLock in project coprhd-controller by CoprHD.
the class UpgradeManager method releaseUpgradeLock.
/**
* Helper method to provide backward compatibility for upgrade from pre-Yoda releases
* This should be replaced with releaseRebootLock() when pre-Yoda releases are no longer in the direct upgrade path
*
* @param svcId
* @return
*/
private void releaseUpgradeLock(String svcId) {
if (backCompatPreYoda) {
log.info("Pre-yoda back compatible flag detected. Check upgrade lock from the global area");
// The lock content has changed in Yoda, previously there's only svcId in the lock node
String oldSvcId = coordinator.getMySvcId();
try {
DistributedPersistentLock lock = coordinator.getCoordinatorClient().getPersistentLock(DISTRIBUTED_UPGRADE_LOCK);
if (lock != null) {
String lockOwner = lock.getLockOwner();
if (lockOwner == null) {
log.info("Upgrade lock is not held by any node");
return;
}
if (!lockOwner.equals(oldSvcId)) {
log.error("Lock owner is {}", lockOwner);
} else {
boolean result = lock.releaseLock(lockOwner);
if (result) {
log.info("Upgrade lock released by owner {} successfully", lockOwner);
} else {
log.info("Upgrade lock release failed for owner {}", lockOwner);
}
}
}
} catch (Exception e) {
log.error("Failed to release the upgrade lock:", e);
}
} else {
releaseRebootLock(svcId);
}
}
use of com.emc.storageos.coordinator.client.service.DistributedPersistentLock in project coprhd-controller by CoprHD.
the class ControllerLockingServiceImpl method acquirePersistentLock.
@Override
public boolean acquirePersistentLock(String lockName, String clientName, long seconds) {
if (lockName == null || lockName.isEmpty()) {
return false;
}
try {
Throwable t = null;
DistributedPersistentLock lock = null;
boolean acquired = false;
if (seconds >= 0) {
log.info("Attempting to acquire lock: " + lockName + (seconds > 0 ? (" for a maximum of " + seconds + " seconds.") : ""));
while (seconds-- >= 0 && !acquired) {
try {
lock = _coordinator.getPersistentLock(lockName);
acquired = lock.acquireLock(clientName);
} catch (CoordinatorException ce) {
t = ce;
Thread.sleep(1000);
}
}
} else if (seconds == -1) {
log.info("Attempting to acquire lock: " + lockName + " for as long as it takes.");
while (true) {
try {
lock = _coordinator.getPersistentLock(lockName);
acquired = lock.acquireLock(clientName);
} catch (CoordinatorException ce) {
t = ce;
Thread.sleep(1000);
}
}
} else {
log.error("Invalid value for seconds to acquireLock");
return false;
}
if (lock == null || !acquired) {
if (t != null) {
log.error(String.format("Acquisition of mutex lock: %s failed with Exception: ", lockName), t);
} else {
log.error(String.format("Acquisition of mutex lock: %s failed", lockName));
}
return false;
}
log.info("Acquired lock: " + lockName);
return true;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
} catch (Exception e) {
return false;
}
}
use of com.emc.storageos.coordinator.client.service.DistributedPersistentLock in project coprhd-controller by CoprHD.
the class CoordinatorClientExt method getPersistentLock.
/**
* The method to try and grab the persistent upgrade lock for given node
*
* @param svcId
* - The candidate node who wants to grab the lock
* @param lockId
* - lock id
* @return True - If node can get the lock False - Otherwise
*/
public boolean getPersistentLock(String svcId, String lockId) {
try {
DistributedPersistentLock lock = _coordinator.getSiteLocalPersistentLock(lockId);
_log.info("Acquiring the {} lock for {}...", lockId, svcId);
boolean result = lock.acquireLock(svcId);
if (result) {
return true;
}
} catch (Exception e) {
_log.info("Can not get {} lock", lockId, e);
}
return false;
}
Aggregations