Search in sources :

Example 76 with InterProcessLock

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;
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock)

Example 77 with InterProcessLock

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 78 with InterProcessLock

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 79 with InterProcessLock

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 80 with InterProcessLock

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Aggregations

InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)98 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)25 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)21 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 IOException (java.io.IOException)15 ControllerException (com.emc.storageos.volumecontroller.ControllerException)14 Configuration (com.emc.storageos.coordinator.common.Configuration)12 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)12 UnknownHostException (java.net.UnknownHostException)12 Site (com.emc.storageos.coordinator.client.model.Site)11 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)11 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)10 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)9 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)9 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)9 ArrayList (java.util.ArrayList)9 POST (javax.ws.rs.POST)9 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)8 Path (javax.ws.rs.Path)8 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)6