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);
}
}
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);
}
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;
}
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);
}
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;
}
Aggregations