Search in sources :

Example 6 with CoordinatorException

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

the class CoordinatorClientImpl method persistServiceConfiguration.

@Override
public void persistServiceConfiguration(String siteId, Configuration... configs) throws CoordinatorException {
    try {
        for (Configuration config : configs) {
            String configParentPath = getKindPath(siteId, config.getKind());
            EnsurePath path = new EnsurePath(configParentPath);
            path.ensure(_zkConnection.curator().getZookeeperClient());
            String servicePath = String.format("%1$s/%2$s", configParentPath, config.getId());
            Stat stat = _zkConnection.curator().checkExists().forPath(servicePath);
            CuratorTransaction handler = zkTransactionHandler.get();
            if (stat != null) {
                if (handler != null) {
                    CuratorTransactionFinal tx = handler.setData().forPath(servicePath, config.serialize()).and();
                    zkTransactionHandler.set(tx);
                } else {
                    _zkConnection.curator().setData().forPath(servicePath, config.serialize());
                }
            } else {
                if (handler != null) {
                    CuratorTransactionFinal tx = handler.create().forPath(servicePath, config.serialize()).and();
                    zkTransactionHandler.set(tx);
                } else {
                    _zkConnection.curator().create().forPath(servicePath, config.serialize());
                }
            }
        }
    } catch (final Exception e) {
        log.error("Failed to persist service configuration e=", e);
        throw CoordinatorException.fatals.unableToPersistTheConfiguration(e);
    }
}
Also used : EnsurePath(org.apache.curator.utils.EnsurePath) Stat(org.apache.zookeeper.data.Stat) Configuration(com.emc.storageos.coordinator.common.Configuration) CuratorTransaction(org.apache.curator.framework.api.transaction.CuratorTransaction) CuratorTransactionFinal(org.apache.curator.framework.api.transaction.CuratorTransactionFinal) 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 7 with CoordinatorException

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

the class CoordinatorClientImpl method queryAllConfiguration.

@Override
public List<Configuration> queryAllConfiguration(String siteId, String kind) throws CoordinatorException {
    String serviceParentPath = getKindPath(siteId, kind);
    List<String> configPaths;
    try {
        configPaths = _zkConnection.curator().getChildren().forPath(serviceParentPath);
    } catch (KeeperException.NoNodeException ignore) {
        // Ignore exception, don't re-throw
        log.debug("Caught exception but ignoring it: " + ignore);
        return Arrays.asList(new Configuration[0]);
    } catch (Exception e) {
        throw CoordinatorException.fatals.unableToListAllConfigurationForKind(kind, e);
    }
    List<Configuration> configs = new ArrayList<Configuration>(configPaths.size());
    for (String configPath : configPaths) {
        Configuration config = queryConfiguration(siteId, kind, configPath);
        if (config != null) {
            configs.add(config);
        }
    }
    return configs;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) 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 8 with CoordinatorException

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

the class GenericSerializer method serialize.

/**
 * Will serialize any serializable object.
 * @param object -- Java object that is serializable.
 * @param logName -- Name of object for log messages (can be null)
 * @param zkData -- if true, will impose a maximum size limit of MAX_ZK_OBJECT_SIZE_IN_BYTES, which is maximum size for zookeeper data
 * @return byte[] representing serialized data
 * @throws CoordinatorException for exceedingLimit if checked
 */
public static byte[] serialize(Object object, String logName, boolean zkData) {
    String className = (object != null) ? object.getClass().getSimpleName() : "";
    String label = (logName != null) ? logName : "";
    try {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        ObjectOutputStream ostream = new ObjectOutputStream(stream);
        ostream.writeObject(object);
        byte[] byteArray = stream.toByteArray();
        if (zkData && byteArray.length > MAX_ZK_OBJECT_SIZE_IN_BYTES) {
            _log.error(String.format("Serialization failure: Class %s %s Byte Array length is %d limit is %d", className, label, byteArray.length, MAX_ZK_OBJECT_SIZE_IN_BYTES));
            throw CoordinatorException.fatals.exceedingLimit("byte array size", MAX_ZK_OBJECT_SIZE_IN_BYTES);
        } else if (byteArray.length > LOG_SIZE_IN_BYTES) {
            _log.info(String.format("Serialization large object class %s %s size %d", className, label, byteArray.length));
        }
        return byteArray;
    } catch (Exception ex) {
        throw CoordinatorException.fatals.failedToSerialize(ex);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException)

Example 9 with CoordinatorException

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

the class DrUtil method isAllSyssvcUp.

/**
 * Check if all syssvc is up and running for specified site
 * @param siteId
 * @return true if all syssvc is running
 */
public boolean isAllSyssvcUp(String siteId) {
    // Get service beacons for given site - - assume syssvc on all sites share same service name in beacon
    try {
        String syssvcName = ((CoordinatorClientImpl) coordinator).getSysSvcName();
        String syssvcVersion = ((CoordinatorClientImpl) coordinator).getSysSvcVersion();
        List<Service> svcs = coordinator.locateAllServices(siteId, syssvcName, syssvcVersion, null, null);
        Site site = this.getSiteFromLocalVdc(siteId);
        log.info("Node count is {}, running syssvc count is", site.getNodeCount(), svcs.size());
        return svcs.size() == site.getNodeCount();
    } catch (CoordinatorException ex) {
        return false;
    }
}
Also used : CoordinatorClientImpl(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientImpl) Site(com.emc.storageos.coordinator.client.model.Site) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) Service(com.emc.storageos.coordinator.common.Service)

Example 10 with CoordinatorException

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

the class CoordinatorClientImpl method isDatabaseServiceUp.

private Boolean isDatabaseServiceUp(String serviceName) {
    try {
        String siteId = _zkConnection.getSiteId();
        List<Service> services = locateAllServices(siteId, serviceName, dbVersionInfo.getSchemaVersion(), null, null);
        DrUtil drUtil = new DrUtil(this);
        Site site = drUtil.getSiteFromLocalVdc(siteId);
        log.info("Node count is {}, running {} count is {}", site.getNodeCount(), serviceName, services.size());
        return services.size() == site.getNodeCount();
    } catch (CoordinatorException e) {
        return false;
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) DrUtil(com.emc.storageos.coordinator.client.service.DrUtil) Service(com.emc.storageos.coordinator.common.Service) ExecutorService(java.util.concurrent.ExecutorService) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString)

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