Search in sources :

Example 11 with CoordinatorException

use of com.emc.storageos.coordinator.exceptions.CoordinatorException in project coprhd-controller by CoprHD.

the class CoordinatorClientImpl method persistRuntimeState.

@Override
public <T extends CoordinatorSerializable> void persistRuntimeState(String key, T state) throws CoordinatorException {
    String path = String.format("%s/%s", ZkPath.STATE, key);
    try {
        int lastSlash = path.lastIndexOf('/');
        String parentPath = path.substring(0, lastSlash);
        EnsurePath ensurePath = new EnsurePath(parentPath);
        ensurePath.ensure(_zkConnection.curator().getZookeeperClient());
    } catch (Exception e) {
        log.error(String.format("Failed to ensure path to key: %s", path), e);
    }
    try {
        byte[] data = state.encodeAsString().getBytes("UTF-8");
        // Here the loop can end (break or throw Exception) from inside, safe to suppress
        for (boolean exist = _zkConnection.curator().checkExists().forPath(path) != null; ; exist = !exist) {
            // NOSONAR("squid:S1994")
            try {
                if (exist) {
                    _zkConnection.curator().setData().forPath(path, data);
                } else {
                    _zkConnection.curator().create().forPath(path, data);
                }
                break;
            } catch (KeeperException ex) {
                if (exist && ex.code() == KeeperException.Code.NONODE || !exist && ex.code() == KeeperException.Code.NODEEXISTS) {
                    continue;
                }
                throw ex;
            }
        }
    } catch (Exception e) {
        log.info("Failed to persist runtime state e=", e);
        throw CoordinatorException.fatals.unableToPersistTheState(e);
    }
}
Also used : EnsurePath(org.apache.curator.utils.EnsurePath) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) KeeperException(org.apache.zookeeper.KeeperException)

Example 12 with CoordinatorException

use of com.emc.storageos.coordinator.exceptions.CoordinatorException in project coprhd-controller by CoprHD.

the class CoordinatorClientImpl method getSemaphoreLock.

@Override
public InterProcessSemaphoreMutex getSemaphoreLock(String name) throws CoordinatorException {
    EnsurePath path = new EnsurePath(ZkPath.MUTEX.toString());
    try {
        path.ensure(_zkConnection.curator().getZookeeperClient());
    } catch (Exception e) {
        throw new RetryableCoordinatorException(ServiceCode.COORDINATOR_SVC_NOT_FOUND, e, "Unable to get lock {0}. Caused by: {1}", new Object[] { name, e.getMessage() });
    }
    String lockPath = ZKPaths.makePath(ZkPath.MUTEX.toString(), name);
    return new InterProcessSemaphoreMutex(_zkConnection.curator(), lockPath);
}
Also used : EnsurePath(org.apache.curator.utils.EnsurePath) InterProcessSemaphoreMutex(org.apache.curator.framework.recipes.locks.InterProcessSemaphoreMutex) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 13 with CoordinatorException

use of com.emc.storageos.coordinator.exceptions.CoordinatorException in project coprhd-controller by CoprHD.

the class CoordinatorClientImpl method lookupServicePath.

/**
 * Helper to retrieve zk service node children
 * Note that it could return an empty list if there's no ZNode under the specified path
 *
 * @param siteId
 * @param serviceRoot
 *            path under /service
 * @return child node ids under /service/<serviceRoot>
 * @throws CoordinatorException
 */
private List<String> lookupServicePath(String siteId, String serviceRoot) throws CoordinatorException {
    List<String> services = null;
    String fullPath = String.format("%1$s/%2$s", getServicePath(siteId), serviceRoot);
    try {
        services = _zkConnection.curator().getChildren().forPath(fullPath);
    } catch (KeeperException.NoNodeException e) {
        throw CoordinatorException.retryables.cannotFindNode(fullPath, e);
    } catch (Exception e) {
        throw CoordinatorException.retryables.errorWhileFindingNode(fullPath, e);
    }
    if (services == null) {
        return new ArrayList<>();
    }
    return services;
}
Also used : ArrayList(java.util.ArrayList) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) KeeperException(org.apache.zookeeper.KeeperException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 14 with CoordinatorException

use of com.emc.storageos.coordinator.exceptions.CoordinatorException in project coprhd-controller by CoprHD.

the class CoordinatorClientImpl method getReadWriteLock.

@Override
public InterProcessReadWriteLock getReadWriteLock(String name) throws CoordinatorException {
    EnsurePath path = new EnsurePath(ZkPath.MUTEX.toString());
    try {
        path.ensure(_zkConnection.curator().getZookeeperClient());
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw CoordinatorException.fatals.unableToGetLock(name, e);
    } catch (Exception e) {
        throw CoordinatorException.fatals.unableToGetLock(name, e);
    }
    String lockPath = ZKPaths.makePath(ZkPath.MUTEX.toString(), name);
    return new InterProcessReadWriteLock(_zkConnection.curator(), lockPath);
}
Also used : EnsurePath(org.apache.curator.utils.EnsurePath) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) InterProcessReadWriteLock(org.apache.curator.framework.recipes.locks.InterProcessReadWriteLock)

Example 15 with CoordinatorException

use of com.emc.storageos.coordinator.exceptions.CoordinatorException in project coprhd-controller by CoprHD.

the class CoordinatorClientExt method isDBServiceStarted.

public boolean isDBServiceStarted() {
    List<Service> svcs = null;
    try {
        svcs = locateAllServices(DBSVC_NAME, _coordinator.getTargetDbSchemaVersion(), (String) null, null);
    } catch (CoordinatorException e) {
        return false;
    }
    String dbSvcId = "db" + mySvcId.substring(mySvcId.lastIndexOf("-"));
    for (Service svc : svcs) {
        if (svc.getId().equals(dbSvcId)) {
            return true;
        }
    }
    return false;
}
Also used : CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) Service(com.emc.storageos.coordinator.common.Service)

Aggregations

CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)29 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)19 UnknownHostException (java.net.UnknownHostException)14 KeeperException (org.apache.zookeeper.KeeperException)13 PropertyInfoMapper.decodeFromString (com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString)12 IOException (java.io.IOException)12 Site (com.emc.storageos.coordinator.client.model.Site)6 Configuration (com.emc.storageos.coordinator.common.Configuration)6 EnsurePath (org.apache.curator.utils.EnsurePath)6 Service (com.emc.storageos.coordinator.common.Service)5 PropertyInfo (com.emc.storageos.model.property.PropertyInfo)3 ClusterInfo (com.emc.vipr.model.sys.ClusterInfo)3 ArrayList (java.util.ArrayList)3 CuratorTransaction (org.apache.curator.framework.api.transaction.CuratorTransaction)3 CuratorTransactionFinal (org.apache.curator.framework.api.transaction.CuratorTransactionFinal)3 CoordinatorClientImpl (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientImpl)2 ZkPath (com.emc.storageos.coordinator.common.impl.ZkPath)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)2