use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class NetworkDeviceController method updateSanZones.
@Override
public void updateSanZones(URI uri, String fabricId, String fabricWwn, List<ZoneUpdate> zones, boolean activateZones, String taskId) throws ControllerException {
NetworkSystem device = getNetworkSystemObject(uri);
// Lock to prevent concurrent operations on the same VSAN / FABRIC.
InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricId, _coordinator);
try {
// Get the file device reference for the type of file device managed
// by the controller.
NetworkSystemDevice networkDevice = getDevice(device.getSystemType());
if (networkDevice == null) {
throw NetworkDeviceControllerException.exceptions.updateSanZonesFailedNull(device.getSystemType());
}
BiosCommandResult result = networkDevice.updateZones(device, zones, fabricId, fabricWwn, activateZones);
setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
_auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.UPDATE_SAN_ZONE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL());
} catch (Exception ex) {
ServiceError serviceError = NetworkDeviceControllerException.errors.updateSanZonesFailedExc(device.getSystemType(), ex);
_dbClient.error(NetworkSystem.class, device.getId(), taskId, serviceError);
} finally {
NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
}
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class NetworkDeviceController method addSanZones.
@Override
public void addSanZones(URI uri, String fabricId, String fabricWwn, List<Zone> zones, boolean activateZones, String taskId) throws ControllerException {
NetworkSystem device = getNetworkSystemObject(uri);
// Lock to prevent concurrent operations on the same VSAN / FABRIC.
InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricId, _coordinator);
try {
// Get the file device reference for the type of file device managed
// by the controller.
NetworkSystemDevice networkDevice = getDevice(device.getSystemType());
if (networkDevice == null) {
throw NetworkDeviceControllerException.exceptions.addSanZonesFailedNull(device.getSystemType());
}
BiosCommandResult result = networkDevice.addZones(device, zones, fabricId, fabricWwn, activateZones);
setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
_auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.ADD_SAN_ZONE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL());
} catch (Exception ex) {
ServiceError serviceError = NetworkDeviceControllerException.errors.addSanZonesFailedExc(device.getSystemType(), ex);
_dbClient.error(NetworkSystem.class, device.getId(), taskId, serviceError);
} finally {
NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
}
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class NetworkFabricLocker method lockFabric.
/**
* Acquires a fabric exclusive lock based on the fabricId.
*
* @param fabricId - String
* @param coordinator
* @return InterProcessLock (must be passed to unlock)
*/
public static InterProcessLock lockFabric(String fabricId, CoordinatorClient coordinator) {
boolean acquired = false;
InterProcessLock lock = getFabricLock(fabricId, coordinator);
try {
acquired = lock.acquire(60, TimeUnit.MINUTES);
} catch (Exception ex) {
_log.error("Exception locking fabric: " + fabricId);
throw NetworkDeviceControllerException.exceptions.exceptionAcquiringFabricLock(fabricId, ex);
}
if (acquired == false) {
_log.error("Unable to lock fabric lock: " + fabricId);
throw NetworkDeviceControllerException.exceptions.couldNotAcquireFabricLock(fabricId);
}
return lock;
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class ControllerLockingServiceImpl method releaseLock.
@Override
public boolean releaseLock(String lockName) {
if (lockName == null || lockName.isEmpty()) {
return false;
}
try {
InterProcessLock lock = getInterProcessLock(lockName);
lock.release();
synchronized (this) {
if (!lock.isAcquiredInThisProcess()) {
Map<String, InterProcessLock> lockMap = locks.get();
lockMap.remove(lockName);
}
}
log.info("Released lock: " + lockName);
return true;
} catch (Exception e) {
log.error(String.format("Release of mutex lock: %s failed with Exception: ", lockName), e);
}
return false;
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class ControllerLockingServiceImpl method acquireLock.
@Override
public boolean acquireLock(String lockName, long seconds) {
if (lockName == null || lockName.isEmpty()) {
return false;
}
try {
InterProcessLock lock = getInterProcessLock(lockName);
log.info("Attempting to acquire lock: " + lockName + (seconds > 0 ? (" for a maximum of " + seconds + " seconds.") : ""));
return lock.acquire(seconds, TimeUnit.SECONDS);
} catch (Exception e) {
log.error(String.format("Acquire of mutex lock: %s failed with Exception: ", lockName), e);
return false;
}
}
Aggregations