use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class DistributedOwnerLockServiceImpl method releaseLock.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.impl.DistributedOwnerLock#releaseLock(java.lang.String, java.lang.String)
*/
@Override
public boolean releaseLock(String lockName, String owner) {
log.info(String.format("releasing lockName: %s owner: %s", lockName, owner));
InterProcessLock lock = null;
boolean retval = false;
try {
// Get semaphore
lock = lockIPL(lockName);
DistributedOwnerLockData data = loadLockData(lockName);
if (data != null) {
if (!data.owner.equals(owner)) {
log.error(String.format("Failed to release lock: %s for owner: %s because lock held by another owner: %s", lockName, owner, data.getOwner()));
throw DeviceControllerException.exceptions.failedToReleaseLock(lockName);
}
// remove the lock data
removeLockData(lockName, data.getOwner());
Long heldTime = (System.currentTimeMillis() - data.timeAcquired) / 1000;
log.info(String.format("Lock %s released after %d seconds", lockName, heldTime));
} else {
log.info(String.format("unable to unlock lockname: %s owner: %s lock not found in zk", lockName, owner));
}
retval = true;
// Trigger a dequeue event for any items on the DistributedLockQueue waiting for this particular lock
checkLockQueueAndDequeue(lockName);
} finally {
unlockIPL(lock);
}
return retval;
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class NetworkDeviceController method activateSanZones.
@Override
public void activateSanZones(URI uri, String fabricId, String fabricWwn, 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.activateZones(device, fabricId, fabricWwn);
ServiceError serviceError = NetworkDeviceControllerException.errors.activateSanZonesFailed(uri.toString(), device.getSystemType());
setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), serviceError);
_auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.ACTIVATE_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.activateSanZonesFailedExc(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 updateAliases.
@Override
public void updateAliases(URI uri, String fabricId, String fabricWwn, List<ZoneWwnAliasUpdate> updateAliases, 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.updateAliasesFailedNull(device.getSystemType());
}
BiosCommandResult result = networkDevice.updateAliases(device, updateAliases, fabricId, fabricWwn);
setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
_auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.UPDATE_ALIAS, 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.updateAliasesFailedExc(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 addAliases.
@Override
public void addAliases(URI uri, String fabricId, String fabricWwn, List<ZoneWwnAlias> aliases, 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.addAliasesFailedNull(device.getSystemType());
}
BiosCommandResult result = networkDevice.addAliases(device, aliases, fabricId, fabricWwn);
setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
_auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.ADD_ALIAS, 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.addAliasesFailedExc(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 removeAliases.
@Override
public void removeAliases(URI uri, String fabricId, String fabricWwn, List<ZoneWwnAlias> aliases, 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.removeAliasesFailedNull(device.getSystemType());
}
BiosCommandResult result = networkDevice.removeAliases(device, aliases, fabricId, fabricWwn);
setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
_auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.REMOVE_ALIAS, 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.removeAliasesFailedExc(device.getSystemType(), ex);
_dbClient.error(NetworkSystem.class, device.getId(), taskId, serviceError);
} finally {
NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
}
}
Aggregations