Search in sources :

Example 71 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class RecoveryManager method runNodeRecovery.

/**
 * Start cluster recovery in minority nodes corrupted scenario
 * a. PREPARING: start a multicast thread and then the user do node redeployment
 * b. REPAIRING: run db node repair between the alive nodes to make sure the consistency
 * c. SYNCING: wake the redeployed nodes from hibernate status and do data syncing
 * d. DONE: dbsvc and geodbsvc on all nodes are get started
 * e. FAILED: any error occurred during node recovery
 */
private synchronized void runNodeRecovery() throws Exception {
    InterProcessLock lock = null;
    try {
        log.info("Node recovery begins");
        lock = getRecoveryLock();
        setRecoveryStatus(RecoveryStatus.Status.PREPARING);
        if (!isVMwareVapp()) {
            startMulticastService();
        }
        setRecoveryStatus(RecoveryStatus.Status.REPAIRING);
        runDbRepair();
        if (isVMwareVapp()) {
            restartServices();
        }
        setRecoveryStatus(RecoveryStatus.Status.SYNCING);
        waitDbsvcStarted();
        validateAutoBootFlag();
        markRecoverySuccessful();
        log.info("Node recovery is done successful");
    } catch (Exception ex) {
        markRecoveryFailed(RecoveryStatus.ErrorCode.INTERNAL_ERROR);
        log.error("Node recovery failed:", ex);
        throw ex;
    } finally {
        releaseLock(lock);
    }
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SysClientException(com.emc.storageos.systemservices.exceptions.SysClientException)

Example 72 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class SignatureKeyGenerator method getSignatureKey2.

/**
 * getSignatureKey2 (keeping the original getSignature() as deprecated because portal uses this method from
 * our jar still).
 *
 * @param relKeyLocation "leaf" node under \getSignatureKeyConfig()\getSignatureKeyId()\
 * @param algo algorithm to use for that key
 * @return the key
 * @throws Exception
 */
protected synchronized SecretKey getSignatureKey2(String relKeyLocation, String algo) throws Exception {
    Configuration config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
    if (config != null && config.getConfig(relKeyLocation) != null) {
        final String encodedKey = config.getConfig(relKeyLocation);
        return SignatureHelper.createKey(encodedKey, algo);
    } else {
        InterProcessLock lock = null;
        try {
            lock = _coordinator.getLock(getDistributedSignatureKeyLock());
            lock.acquire();
            config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
            ConfigurationImpl cfg = (ConfigurationImpl) config;
            if (cfg == null) {
                cfg = new ConfigurationImpl();
                cfg.setId(getSignatureKeyId());
                cfg.setKind(getSignatureKeyConfig());
            }
            String keyEncoded = SignatureHelper.generateKey(algo);
            cfg.setConfig(relKeyLocation, keyEncoded);
            _coordinator.persistServiceConfiguration(cfg);
            config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
            final String encodedKey = config.getConfig(relKeyLocation);
            return SignatureHelper.createKey(encodedKey, algo);
        } finally {
            if (lock != null) {
                lock.release();
            }
        }
    }
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) ConfigurationImpl(com.emc.storageos.coordinator.common.impl.ConfigurationImpl)

Example 73 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class SignatureKeyGenerator method getSignatureKey.

/**
 * TODO: DELETE in phase 2 when UI has switched to LoginSignatureKeyGenerator api.
 * Used by the UI to get a key.
 *
 * @param algo
 * @return
 * @throws Exception
 */
@Deprecated
public synchronized SecretKey getSignatureKey(String algo) throws Exception {
    Configuration config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
    if (config != null && config.getConfig(getSignatureKey()) != null) {
        final String encodedKey = config.getConfig(getSignatureKey());
        return new SignatureHelper().createKey(encodedKey, algo);
    } else {
        InterProcessLock lock = null;
        try {
            lock = _coordinator.getLock(getDistributedSignatureKeyLock());
            lock.acquire();
            config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
            if (config == null || config.getConfig(getSignatureKey()) == null) {
                ConfigurationImpl cfg = new ConfigurationImpl();
                cfg.setId(getSignatureKeyId());
                cfg.setKind(getSignatureKeyConfig());
                String keyEncoded = SignatureHelper.generateKey(algo);
                cfg.setConfig(getSignatureKey(), keyEncoded);
                _coordinator.persistServiceConfiguration(cfg);
            }
            config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
            final String encodedKey = config.getConfig(getSignatureKey());
            return SignatureHelper.createKey(encodedKey, algo);
        } finally {
            if (lock != null) {
                lock.release();
            }
        }
    }
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) ConfigurationImpl(com.emc.storageos.coordinator.common.impl.ConfigurationImpl)

Example 74 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method setUp.

@Before
public void setUp() throws Exception {
    Constructor constructor = ProductName.class.getDeclaredConstructors()[0];
    constructor.setAccessible(true);
    ProductName productName = (ProductName) constructor.newInstance();
    productName.setName("vipr");
    SoftwareVersion version = new SoftwareVersion("vipr-2.4.0.0.100");
    LinkedList<SoftwareVersion> available = new LinkedList<SoftwareVersion>();
    available.add(version);
    RepositoryInfo repositoryInfo = new RepositoryInfo(new SoftwareVersion("vipr-2.4.0.0.100"), available);
    standby = new SiteConfigRestRep();
    standby.setClusterStable(true);
    standby.setFreshInstallation(true);
    standby.setDbSchemaVersion("2.4");
    standby.setSoftwareVersion("vipr-2.4.0.0.150");
    standby.setHostIPv4AddressMap(new HashMap<String, String>());
    standby.getHostIPv4AddressMap().put("vipr1", "10.247.101.100");
    // setup standby site
    standbySite1 = new Site();
    standbySite1.setUuid("site-uuid-1");
    standbySite1.setVip("10.247.101.110");
    standbySite1.getHostIPv4AddressMap().put("vipr1", "10.247.101.111");
    standbySite1.getHostIPv4AddressMap().put("vipr2", "10.247.101.112");
    standbySite1.getHostIPv4AddressMap().put("vipr3", "10.247.101.113");
    standbySite1.setState(SiteState.STANDBY_PAUSED);
    standbySite1.setVdcShortId("vdc1");
    standbySite1.setNodeCount(1);
    standbySite2 = new Site();
    standbySite2.setUuid("site-uuid-2");
    standbySite2.setState(SiteState.STANDBY_SYNCED);
    standbySite2.setVdcShortId("vdc1");
    standbySite2.setVip("10.247.101.158");
    standbySite2.setNodeCount(1);
    standbySite3 = new Site();
    standbySite3.setUuid("site-uuid-3");
    standbySite3.setVdcShortId("fake-vdc-id");
    standbySite3.setState(SiteState.ACTIVE);
    standbySite3.setVdcShortId("vdc1");
    standbySite3.setNodeCount(1);
    primarySite = new Site();
    primarySite.setUuid("primary-site-uuid");
    primarySite.setVip("127.0.0.1");
    primarySite.setHostIPv4AddressMap(standbySite1.getHostIPv4AddressMap());
    primarySite.setHostIPv6AddressMap(standbySite1.getHostIPv6AddressMap());
    primarySite.setVdcShortId("vdc1");
    primarySite.setState(SiteState.ACTIVE);
    primarySite.setNodeCount(3);
    // mock DBClient
    dbClientMock = mock(DbClientImpl.class);
    // mock coordinator client
    coordinator = mock(CoordinatorClient.class);
    // mock ipsecconfig
    IPsecConfig ipsecConfig = mock(IPsecConfig.class);
    doReturn("ipsec-preshared-key").when(ipsecConfig).getPreSharedKey();
    drUtil = mock(DrUtil.class);
    natCheckParam = new DRNatCheckParam();
    apiSignatureGeneratorMock = mock(InternalApiSignatureKeyGenerator.class);
    try {
        KeyGenerator keyGenerator = null;
        keyGenerator = KeyGenerator.getInstance("HmacSHA256");
        secretKey = keyGenerator.generateKey();
    } catch (NoSuchAlgorithmException e) {
        fail("generate key fail");
    }
    drService = spy(new DisasterRecoveryService());
    drService.setDbClient(dbClientMock);
    drService.setCoordinator(coordinator);
    drService.setDrUtil(drUtil);
    drService.setSiteMapper(new SiteMapper());
    drService.setSysUtils(new SysUtils());
    drService.setIpsecConfig(ipsecConfig);
    drService.setApiSignatureGenerator(apiSignatureGeneratorMock);
    standbyConfig = new Site();
    standbyConfig.setUuid("standby-site-uuid-1");
    standbyConfig.setVip(standbySite1.getVip());
    standbyConfig.setHostIPv4AddressMap(standbySite1.getHostIPv4AddressMap());
    standbyConfig.setHostIPv6AddressMap(standbySite1.getHostIPv6AddressMap());
    standbyConfig.setNodeCount(3);
    doReturn(standbyConfig.getUuid()).when(coordinator).getSiteId();
    Configuration config = new ConfigurationImpl();
    config.setConfig(Constants.CONFIG_DR_ACTIVE_SITEID, primarySite.getUuid());
    doReturn(config).when(coordinator).queryConfiguration(Constants.CONFIG_DR_ACTIVE_KIND, Constants.CONFIG_DR_ACTIVE_ID);
    doReturn("2.4").when(coordinator).getCurrentDbSchemaVersion();
    doReturn(primarySite.getUuid()).when(coordinator).getSiteId();
    doReturn(ClusterInfo.ClusterState.STABLE).when(coordinator).getControlNodesState();
    // Don't need to record audit log in UT
    doNothing().when(drService).auditDisasterRecoveryOps(any(OperationTypeEnum.class), anyString(), anyString(), anyVararg());
    doReturn(repositoryInfo).when(coordinator).getTargetInfo(RepositoryInfo.class);
    doReturn(standbySite1).when(drUtil).getSiteFromLocalVdc(standbySite1.getUuid());
    doReturn(standbySite2).when(drUtil).getSiteFromLocalVdc(standbySite2.getUuid());
    doThrow(CoordinatorException.retryables.cannotFindSite(NONEXISTENT_ID)).when(drUtil).getSiteFromLocalVdc(NONEXISTENT_ID);
    doReturn(primarySite).when(drUtil).getSiteFromLocalVdc(primarySite.getUuid());
    SiteNetworkState siteNetworkState = new SiteNetworkState();
    siteNetworkState.setNetworkHealth(SiteNetworkState.NetworkHealth.GOOD);
    doReturn(siteNetworkState).when(drUtil).getSiteNetworkState(any(String.class));
    CoordinatorClientInetAddressMap addressMap = new CoordinatorClientInetAddressMap();
    addressMap.setDualInetAddress(DualInetAddress.fromAddresses("10.247.101.110", ""));
    doReturn(addressMap).when(coordinator).getInetAddessLookupMap();
    InterProcessLock lock = mock(InterProcessLock.class);
    doReturn(lock).when(coordinator).getLock(anyString());
    doReturn(true).when(lock).acquire(anyInt(), any(TimeUnit.class));
    doNothing().when(lock).release();
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) IPsecConfig(com.emc.storageos.security.ipsec.IPsecConfig) ProductName(com.emc.storageos.coordinator.client.model.ProductName) Configuration(com.emc.storageos.coordinator.common.Configuration) OperationTypeEnum(com.emc.storageos.services.OperationTypeEnum) Matchers.anyString(org.mockito.Matchers.anyString) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) TimeUnit(java.util.concurrent.TimeUnit) SiteConfigRestRep(com.emc.storageos.model.dr.SiteConfigRestRep) KeyGenerator(javax.crypto.KeyGenerator) InternalApiSignatureKeyGenerator(com.emc.storageos.security.authentication.InternalApiSignatureKeyGenerator) ConfigurationImpl(com.emc.storageos.coordinator.common.impl.ConfigurationImpl) InternalApiSignatureKeyGenerator(com.emc.storageos.security.authentication.InternalApiSignatureKeyGenerator) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo) Constructor(java.lang.reflect.Constructor) SiteMapper(com.emc.storageos.api.mapper.SiteMapper) DrUtil(com.emc.storageos.coordinator.client.service.DrUtil) LinkedList(java.util.LinkedList) SysUtils(com.emc.storageos.services.util.SysUtils) SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) DRNatCheckParam(com.emc.storageos.model.dr.DRNatCheckParam) CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) SiteNetworkState(com.emc.storageos.coordinator.client.model.SiteNetworkState) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) Before(org.junit.Before)

Example 75 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class CassandraTokenManager method getProxyToken.

/**
 * Gets a proxy token for the given user
 * If a proxy token for the given user already exists, it will be reused
 *
 * @return proxy-token
 */
@Override
public String getProxyToken(StorageOSUserDAO userDAO) {
    InterProcessLock userLock = null;
    try {
        userLock = _coordinator.getLock(userDAO.getUserName());
        if (userLock == null) {
            _log.error("Could not acquire lock for user: {}", userDAO.getUserName());
            throw SecurityException.fatals.couldNotAcquireLockForUser(userDAO.getUserName());
        }
        userLock.acquire();
        // Look for proxy tokens based on that username.
        // If any is found, use that. Else, create a new one.
        ProxyToken proxyToken = getProxyTokenForUserName(userDAO.getUserName());
        if (proxyToken != null) {
            _log.debug("Found proxy token {} for user {}.  Reusing...", proxyToken.getId(), userDAO.getUserName());
            return _tokenEncoder.encode(TokenOnWire.createTokenOnWire(proxyToken));
        }
        // No proxy token found for this user. Create a new one.
        // Create the actual proxy token
        ProxyToken pToken = new ProxyToken();
        pToken.setId(URIUtil.createId(ProxyToken.class));
        pToken.addKnownId(userDAO.getId());
        pToken.setUserName(userDAO.getUserName());
        // for now
        pToken.setZoneId("zone1");
        pToken.setIssuedTime(getCurrentTimeInMins());
        pToken.setLastValidatedTime(getCurrentTimeInMins());
        _dbClient.persistObject(pToken);
        return _tokenEncoder.encode(TokenOnWire.createTokenOnWire(pToken));
    } catch (DatabaseException ex) {
        _log.error("DatabaseException while persisting proxy token", ex);
    } catch (SecurityException ex) {
        _log.error("Proxy Token encoding exception. ", ex);
    } catch (Exception ex) {
        _log.error("Could not acquire lock while trying to get a proxy token.", ex);
    } finally {
        try {
            if (userLock != null) {
                userLock.release();
            }
        } catch (Exception ex) {
            _log.error("Unable to release proxytoken creation lock", ex);
        }
    }
    return null;
}
Also used : ProxyToken(com.emc.storageos.db.client.model.ProxyToken) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) SecurityException(com.emc.storageos.security.exceptions.SecurityException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) SecurityException(com.emc.storageos.security.exceptions.SecurityException)

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