Search in sources :

Example 1 with CoordinatorException

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

the class DisasterRecoveryService method getSiteDetails.

/**
 * Query the site details, such as transition timings, for specific standby site
 *
 * @param uuid site UUID
 * @brief Get site details
 * @return SiteActionsTime with detail information
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN, Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
@Path("/{uuid}/details")
public SiteDetailRestRep getSiteDetails(@PathParam("uuid") String uuid) {
    log.info("Begin to get site paused time by uuid {}", uuid);
    SiteDetailRestRep standbyDetails = new SiteDetailRestRep();
    try {
        Site standby = drUtil.getSiteFromLocalVdc(uuid);
        standbyDetails.setCreationTime(new Date(standby.getCreationTime()));
        Double latency = drUtil.getSiteNetworkState(uuid).getNetworkLatencyInMs();
        standbyDetails.setNetworkLatencyInMs(latency);
        Date lastSyncTime = drUtil.getLastSyncTime(standby);
        if (lastSyncTime != null) {
            standbyDetails.setLastSyncTime(lastSyncTime);
        }
        standbyDetails.setDataSynced(isDataSynced(standby));
        ClusterInfo.ClusterState clusterState = coordinator.getControlNodesState(standby.getUuid());
        if (clusterState != null) {
            standbyDetails.setClusterState(clusterState.toString());
        } else {
            standbyDetails.setClusterState(ClusterInfo.ClusterState.UNKNOWN.toString());
        }
        standbyDetails.setSiteState(standby.getState().toString());
    } catch (CoordinatorException e) {
        log.error("Can't find site {} from ZK", uuid);
        throw APIException.badRequests.siteIdNotFound();
    } catch (Exception e) {
        log.error("Find find site from ZK for UUID {} : {}" + uuid, e);
    }
    return standbyDetails;
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) SiteDetailRestRep(com.emc.storageos.model.dr.SiteDetailRestRep) Date(java.util.Date) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) UnknownHostException(java.net.UnknownHostException) Path(javax.ws.rs.Path) ZkPath(com.emc.storageos.coordinator.common.impl.ZkPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with CoordinatorException

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

the class StorageOSLocalAuthenticationHandler method verifyUserPassword.

/**
 * Verify that the user's password matches with the hashed and salted value stored.
 * Return false if user is not found.
 *
 * @param username the user
 * @param clearTextPassword the clear text password
 * @return true if user's password matches, otherwise false.
 */
public boolean verifyUserPassword(final String username, final String clearTextPassword) {
    if (clearTextPassword == null || clearTextPassword.isEmpty()) {
        _log.error("Login with blank password is not allowed");
        return false;
    }
    String encpassword = null;
    PropertyInfo props = null;
    try {
        props = _coordinatorClient.getPropertyInfo();
    } catch (CoordinatorException e) {
        _log.error("Access local user properties failed", e);
        return false;
    }
    if (props == null) {
        _log.error("Access local user properties failed");
        return false;
    }
    encpassword = props.getProperty("system_" + username + "_encpassword");
    if (StringUtils.isBlank(encpassword)) {
        _log.error("No password set for user {} ", username);
        return false;
    }
    // A hashed value will start with the SHA-512 identifier ($6$)
    if (StringUtils.startsWith(encpassword, CRYPT_SHA_512)) {
        // Hash the clear text password and compare against the stored value
        String hashedValue = Crypt.crypt(clearTextPassword, encpassword);
        return encpassword.equals(hashedValue);
    } else {
        // Encrypt the clear text password and compare against the stored value
        String encryptedValue = encrypt(clearTextPassword);
        return encpassword.equals(encryptedValue);
    }
}
Also used : CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) PropertyInfo(com.emc.storageos.model.property.PropertyInfo)

Example 3 with CoordinatorException

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

the class CoordinatorClientImpl method getTargetInfo.

private <T extends CoordinatorSerializable> T getTargetInfo(String siteId, final Class<T> clazz, String id, String kind) throws CoordinatorException {
    T info;
    try {
        info = clazz.newInstance();
    } catch (Exception e) {
        log.error("Failed to create instance according class {}, {}", clazz, e);
        throw CoordinatorException.fatals.unableToCreateInstanceOfTargetInfo(clazz.getName(), e);
    }
    final Configuration config = queryConfiguration(siteId, kind, id);
    if (config != null && config.getConfig(TARGET_INFO) != null) {
        final String infoStr = config.getConfig(TARGET_INFO);
        log.debug("getTargetInfo({}): info={}", clazz.getName(), Strings.repr(infoStr));
        final T decodeInfo = info.decodeFromString(infoStr);
        log.debug("getTargetInfo({}): info={}", clazz.getName(), decodeInfo);
        return decodeInfo;
    }
    return null;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) 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 4 with CoordinatorException

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

the class CoordinatorClientImpl method queryRuntimeState.

@Override
public <T extends CoordinatorSerializable> T queryRuntimeState(String key, Class<T> clazz) throws CoordinatorException {
    String path = String.format("%s/%s", ZkPath.STATE, key);
    try {
        byte[] data = _zkConnection.curator().getData().forPath(path);
        CoordinatorSerializable state = clazz.newInstance();
        return (T) state.decodeFromString(new String(data, "UTF-8"));
    } catch (KeeperException.NoNodeException ignore) {
        // Ignore exception, don't re-throw
        log.debug("Caught exception but ignoring it: " + ignore);
        return null;
    } catch (Exception e) {
        throw CoordinatorException.fatals.unableToFindTheState(key, e);
    }
}
Also used : CoordinatorSerializable(com.emc.storageos.coordinator.client.model.CoordinatorSerializable) 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 5 with CoordinatorException

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

the class CoordinatorClientImpl method getPropertyInfo.

/**
 * Get property
 *
 * This method gets target properties from coordinator service as a string
 * and merges it with the defaults and the ovf properties
 * Syssvc is responsible for publishing the target property information into coordinator
 *
 * @return property object
 * @throws CoordinatorException
 */
@Override
public PropertyInfo getPropertyInfo() throws CoordinatorException {
    PropertyInfo info = new PropertyInfo();
    Map<String, String> defaults = new HashMap<String, String>((Map) defaultProperties);
    final Configuration config = queryConfiguration(TARGET_PROPERTY, TARGET_PROPERTY_ID);
    if (null == config || null == config.getConfig(TARGET_INFO)) {
        log.debug("getPropertyInfo(): no properties saved in coordinator returning defaults");
        info.setProperties(defaults);
    } else {
        final String infoStr = config.getConfig(TARGET_INFO);
        try {
            log.debug("getPropertyInfo(): properties saved in coordinator=" + Strings.repr(infoStr));
            info.setProperties(mergeProps(defaults, decodeFromString(infoStr).getProperties()));
        } catch (final Exception e) {
            throw CoordinatorException.fatals.unableToDecodeDataFromCoordinator(e);
        }
    }
    // add site specific properties
    PropertyInfoExt siteScopePropInfo = getTargetInfo(getSiteId(), PropertyInfoExt.class);
    if (siteScopePropInfo != null) {
        info.getProperties().putAll(siteScopePropInfo.getProperties());
    }
    // add the ovf properties
    info.getProperties().putAll((Map) ovfProperties);
    return info;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PropertyInfoExt(com.emc.storageos.coordinator.client.model.PropertyInfoExt) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) PropertyInfo(com.emc.storageos.model.property.PropertyInfo) 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)

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