Search in sources :

Example 36 with CoordinatorClient

use of com.emc.storageos.coordinator.client.service.CoordinatorClient in project coprhd-controller by CoprHD.

the class ConfigPropertyUtils method getPropertiesFromCoordinator.

public static Map<String, String> getPropertiesFromCoordinator() {
    // Only do this if we have coordinator available
    if (StorageOsPlugin.isEnabled()) {
        CoordinatorClient coordinatorClient = StorageOsPlugin.getInstance().getCoordinatorClient();
        com.emc.storageos.model.property.PropertyInfo propertyInfo = coordinatorClient.getPropertyInfo();
        if (propertyInfo != null) {
            return propertyInfo.getAllProperties();
        }
    }
    return Maps.newHashMap();
}
Also used : CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient)

Example 37 with CoordinatorClient

use of com.emc.storageos.coordinator.client.service.CoordinatorClient in project coprhd-controller by CoprHD.

the class LicenseUtils method isLicensed.

public static boolean isLicensed(LicenseType type, boolean useCache) {
    if (type == null) {
        return false;
    }
    String licensedCacheKey = getLicensedCacheKey(type);
    Boolean licensed = null;
    if (useCache) {
        licensed = (Boolean) Cache.get(licensedCacheKey);
    }
    if (licensed == null) {
        if (StorageOsPlugin.isEnabled()) {
            CoordinatorClient coordinatorClient = StorageOsPlugin.getInstance().getCoordinatorClient();
            licensed = coordinatorClient != null && coordinatorClient.isStorageProductLicensed(type);
        } else // In Dev mode if we don't have coordinator, assume always licensed
        if (Play.mode.isDev()) {
            licensed = Boolean.TRUE;
        } else {
            licensed = Boolean.FALSE;
        }
        // We don't really want to hit the license check each time.
        Cache.set(licensedCacheKey, licensed, LICENSE_CACHE_INTERVAL);
    }
    return licensed;
}
Also used : CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient)

Example 38 with CoordinatorClient

use of com.emc.storageos.coordinator.client.service.CoordinatorClient in project coprhd-controller by CoprHD.

the class TokenManagerTests method concurrentRequestedTokenMapUpdates.

/**
 * This test updates two objects in the RequestedTokenMap CF. One for token1,
 * one for token2. Each one is initially loaded with 10 entries:
 * token1: vdc1, vdc2, vdc3 ...
 * token2: vdc1, vdc2, vdc3 ...
 * 10 adder threads are adding 10 more entries to each token. vdc-11, vdc-12 ...
 * 10 remover threads are removing the 10 entries created initially
 * The result is each token should end up with 10 entries, from the adder threads.
 *
 * @throws Exception
 */
@Test
public void concurrentRequestedTokenMapUpdates() throws Exception {
    final DbClient sharedDbClient = getDbClient();
    final CoordinatorClient sharedCoordinator = new TestCoordinator();
    final RequestedTokenHelper requestedTokenMap = new RequestedTokenHelper();
    requestedTokenMap.setDbClient(sharedDbClient);
    requestedTokenMap.setCoordinator(sharedCoordinator);
    // pre load the map with 10 entries for a given token
    for (int i = 0; i < 10; i++) {
        requestedTokenMap.addOrRemoveRequestingVDC(Operation.ADD_VDC, "token1", String.format("vdc%d", i));
    }
    // pre load the map with 10 entries for another token
    for (int i = 0; i < 10; i++) {
        requestedTokenMap.addOrRemoveRequestingVDC(Operation.ADD_VDC, "token2", String.format("vdc%d", i));
    }
    int numAdderThreads = 10;
    int numRemoverThreads = 10;
    int numThreads = numAdderThreads + numRemoverThreads;
    ExecutorService executor = Executors.newFixedThreadPool(numThreads);
    final CountDownLatch waiter = new CountDownLatch(numThreads);
    final class Adders implements Callable {

        @Override
        public Object call() throws Exception {
            // synchronize all threads
            waiter.countDown();
            waiter.await();
            for (int i = 0; i < 10; i++) {
                requestedTokenMap.addOrRemoveRequestingVDC(Operation.ADD_VDC, "token1", String.format("vdc-1%d", i));
            }
            for (int i = 0; i < 10; i++) {
                requestedTokenMap.addOrRemoveRequestingVDC(Operation.ADD_VDC, "token2", String.format("vdc-2%d", i));
            }
            return null;
        }
    }
    final class Removers implements Callable {

        @Override
        public Object call() throws Exception {
            // synchronize all threads
            waiter.countDown();
            waiter.await();
            // pre load the map with 10 entries for a given token
            for (int i = 0; i < 10; i++) {
                requestedTokenMap.addOrRemoveRequestingVDC(Operation.REMOVE_VDC, "token1", String.format("vdc%d", i));
            }
            // pre load the map with 10 entries for another token
            for (int i = 0; i < 10; i++) {
                requestedTokenMap.addOrRemoveRequestingVDC(Operation.REMOVE_VDC, "token2", String.format("vdc%d", i));
            }
            return null;
        }
    }
    for (int i = 0; i < numAdderThreads; i++) {
        executor.submit(new Adders());
    }
    for (int i = 0; i < numRemoverThreads; i++) {
        executor.submit(new Removers());
    }
    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(60, TimeUnit.SECONDS));
    // Verification. We should be left with just 10 entries for each token
    // The 10 entries that were added by the adders.
    RequestedTokenMap mapToken1 = requestedTokenMap.getTokenMap("token1");
    Assert.assertEquals(10, mapToken1.getVDCIDs().size());
    StringSet entries = mapToken1.getVDCIDs();
    ArrayList<String> checkList = new ArrayList<String>();
    for (int i = 0; i < 10; i++) {
        checkList.add(String.format("vdc-1%d", i));
    }
    Assert.assertTrue(entries.containsAll(checkList));
    RequestedTokenMap mapToken2 = requestedTokenMap.getTokenMap("token2");
    Assert.assertEquals(10, mapToken2.getVDCIDs().size());
    StringSet entries2 = mapToken2.getVDCIDs();
    ArrayList<String> checkList2 = new ArrayList<String>();
    for (int i = 0; i < 10; i++) {
        checkList2.add(String.format("vdc-2%d", i));
    }
    Assert.assertTrue(entries2.containsAll(checkList2));
}
Also used : RequestedTokenMap(com.emc.storageos.db.client.model.RequestedTokenMap) DbClient(com.emc.storageos.db.client.DbClient) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) RequestedTokenHelper(com.emc.storageos.security.geo.RequestedTokenHelper) StringSet(com.emc.storageos.db.client.model.StringSet) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) Test(org.junit.Test)

Example 39 with CoordinatorClient

use of com.emc.storageos.coordinator.client.service.CoordinatorClient in project coprhd-controller by CoprHD.

the class TokenManagerTests method testConcurrentRotations.

/**
 * Have 15 threads attempt a rotation. 14 should realize that rotation have already happen
 * and not do anything. At the end, the current key id should be uniform across all 15 threads.
 * Additionally, the previous key id should still be valid.
 */
@Test
public void testConcurrentRotations() throws Exception {
    // For this test, we need our custom setup, with several
    // tokenManagers sharing a common TestCoordinator. This will
    // simulate shared zookeeper data on the cluster. And the different
    // tokenManagers/KeyGenerators will simulate the different nodes.
    DbClient dbClient = getDbClient();
    CoordinatorClient coordinator = new TestCoordinator();
    final int ROTATION_INTERVAL_MSECS = 5000;
    int numThreads = 15;
    ExecutorService executor = Executors.newFixedThreadPool(numThreads);
    final CountDownLatch waiter = new CountDownLatch(numThreads);
    final class InitTester implements Callable {

        CoordinatorClient _coordinator = null;

        DbClient _client = null;

        KeyIdsHolder _holder = null;

        public InitTester(CoordinatorClient coord, DbClient client, KeyIdsHolder holder) {
            _coordinator = coord;
            _client = client;
            _holder = holder;
        }

        @Override
        public Object call() throws Exception {
            // create node artifacts
            CassandraTokenManager tokenManager1 = new CassandraTokenManager();
            Base64TokenEncoder encoder1 = new Base64TokenEncoder();
            TokenKeyGenerator tokenKeyGenerator1 = new TokenKeyGenerator();
            tokenManager1.setDbClient(_client);
            tokenManager1.setCoordinator(_coordinator);
            encoder1.setCoordinator(_coordinator);
            tokenManager1.setTokenEncoder(encoder1);
            TokenMaxLifeValuesHolder holder = new TokenMaxLifeValuesHolder();
            tokenManager1.setTokenMaxLifeValuesHolder(holder);
            tokenKeyGenerator1.setTokenMaxLifeValuesHolder(holder);
            encoder1.setTokenKeyGenerator(tokenKeyGenerator1);
            holder.setKeyRotationIntervalInMSecs(ROTATION_INTERVAL_MSECS);
            encoder1.managerInit();
            // synchronize all threads
            waiter.countDown();
            waiter.await();
            // everybody gets a token using the key before the rotation
            StorageOSUserDAO userDAO = new StorageOSUserDAO();
            userDAO.setUserName("user1");
            final String token = tokenManager1.getToken(userDAO);
            Assert.assertNotNull(token);
            TokenOnWire tw = encoder1.decode(token);
            String previousKey = tw.getEncryptionKeyId();
            // cause the rotation
            Thread.sleep((ROTATION_INTERVAL_MSECS + 1000));
            final String token2 = tokenManager1.getToken(userDAO);
            Assert.assertNotNull(token2);
            TokenOnWire tw2 = encoder1.decode(token2);
            // save the new key in the set to check later that all threads agree
            // this is the new key
            _holder.addToSet(tw2.getEncryptionKeyId());
            // validate token created with the previous key to make sure
            // rotation didn't mess up the previous key
            StorageOSUserDAO gotUser = tokenManager1.validateToken(token);
            Assert.assertNotNull(gotUser);
            return null;
        }
    }
    KeyIdsHolder holder = new KeyIdsHolder();
    for (int i = 0; i < numThreads; i++) {
        executor.submit(new InitTester(coordinator, dbClient, holder));
    }
    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(60, TimeUnit.SECONDS));
    // after all is said and done, all tokens created in all 15 threads, should have been
    // created with the same key id.
    Assert.assertEquals(1, holder.getSetSize());
}
Also used : TokenMaxLifeValuesHolder(com.emc.storageos.security.authentication.TokenMaxLifeValuesHolder) CassandraTokenManager(com.emc.storageos.auth.impl.CassandraTokenManager) DbClient(com.emc.storageos.db.client.DbClient) TokenKeyGenerator(com.emc.storageos.security.authentication.TokenKeyGenerator) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) Base64TokenEncoder(com.emc.storageos.security.authentication.Base64TokenEncoder) TokenOnWire(com.emc.storageos.security.authentication.TokenOnWire) Test(org.junit.Test)

Example 40 with CoordinatorClient

use of com.emc.storageos.coordinator.client.service.CoordinatorClient in project coprhd-controller by CoprHD.

the class TokenManagerTests method testConcurrentIntraVDCTokenCaching.

/**
 * testConcurrentIntraVDCTokenCaching
 * Tests that multiple nodes in a single foreign VDC can cache the same token without collision
 *
 * @throws Exception
 */
@Test
public void testConcurrentIntraVDCTokenCaching() throws Exception {
    // common setup and create a token
    commonDefaultSetupForSingleNodeTests();
    VirtualDataCenter localVdc = VdcUtil.getLocalVdc();
    localVdc.setShortId("externalVDCId");
    _dbClient.persistObject(localVdc);
    VdcUtil.invalidateVdcUrnCache();
    StorageOSUserDAO userDAO = new StorageOSUserDAO();
    userDAO.setUserName("user1@domain.com");
    userDAO.setIsLocal(false);
    String token = _tokenManager.getToken(userDAO);
    Assert.assertNotNull(token);
    TokenOnWire tw1 = _encoder.decode(token);
    final Token tokenObj = _dbClient.queryObject(Token.class, tw1.getTokenId());
    Assert.assertNotNull(tokenObj);
    URI userId = tokenObj.getUserId();
    Assert.assertNotNull(userId);
    final StorageOSUserDAO gotUser = _tokenManager.validateToken(token);
    Assert.assertNotNull(gotUser);
    // because we are running this on the same "db" as opposed to 2 different VDCs,
    // there will be a conflict when caching the token, since the original is already there
    // with the same id. So we are changing the token id and user record id for this
    // purpose.
    tokenObj.setId(URIUtil.createId(Token.class));
    gotUser.setId(URIUtil.createId(StorageOSUserDAO.class));
    tokenObj.setUserId(gotUser.getId());
    TokenOnWire tokenToBeCached = TokenOnWire.createTokenOnWire(tokenObj);
    // this re-encoded alternate token is the token that will be cached and validated
    // from cache.
    final String newEncoded = _encoder.encode(tokenToBeCached);
    final DbClient dbClient = getDbClient();
    // note: the same coordinator is being used in all threads. This means that
    // token keys will be present in this simulated foreign vdc eventhough we didn't
    // explicitly cache them. This should normally fail since we don't have the keys
    // but to focus this test on just the token validation from cache, we leave this be.
    // A separate test will deal with multiple TestCoordinator() representing different
    // zk, in other words true multiple VDCs.
    final CoordinatorClient coordinator = new TestCoordinator();
    // change it back to vdc1, so that it will not match the vdcid in the token
    // created earlier and therefore will be considered a foreign token.
    localVdc.setShortId("vdc1");
    _dbClient.persistObject(localVdc);
    VdcUtil.invalidateVdcUrnCache();
    int numThreads = 5;
    ExecutorService executor = Executors.newFixedThreadPool(numThreads);
    final CountDownLatch waiter = new CountDownLatch(numThreads);
    final class InitTester implements Callable {

        @Override
        public Object call() throws Exception {
            // create node artifacts
            TokenMaxLifeValuesHolder holder = new TokenMaxLifeValuesHolder();
            holder.setForeignTokenCacheExpirationInMins(1);
            InterVDCTokenCacheHelper cacheHelper = new InterVDCTokenCacheHelper();
            cacheHelper.setCoordinator(coordinator);
            cacheHelper.setDbClient(dbClient);
            cacheHelper.setMaxLifeValuesHolder(holder);
            TokenKeyGenerator tokenKeyGenerator1 = new TokenKeyGenerator();
            tokenKeyGenerator1.setTokenMaxLifeValuesHolder(holder);
            Base64TokenEncoder encoder1 = new Base64TokenEncoder();
            encoder1.setCoordinator(coordinator);
            encoder1.setInterVDCTokenCacheHelper(cacheHelper);
            encoder1.setTokenKeyGenerator(tokenKeyGenerator1);
            encoder1.managerInit();
            CassandraTokenManager tokenManager1 = new CassandraTokenManager();
            tokenManager1.setDbClient(dbClient);
            tokenManager1.setCoordinator(coordinator);
            tokenManager1.setTokenMaxLifeValuesHolder(holder);
            tokenManager1.setInterVDCTokenCacheHelper(cacheHelper);
            tokenManager1.setTokenEncoder(encoder1);
            TokenResponseArtifacts artifacts = new TokenResponseArtifacts(gotUser, tokenObj, null);
            // synchronize all threads
            waiter.countDown();
            waiter.await();
            // Cache the token artifacts. Each thread will try at the same time
            // End result is, the token/user values will all be the same anyway
            // but the important is there is no concurrency issue between the first
            // thread that will try to add to the cache, and the others that will simply
            // update it.
            cacheHelper.cacheForeignTokenAndKeys(artifacts, null);
            // First validation should work. It validates from the cache.
            StorageOSUserDAO userFromDB = tokenManager1.validateToken(newEncoded);
            Assert.assertNotNull(userFromDB);
            Assert.assertEquals(userFromDB.getUserName(), gotUser.getUserName());
            // wait longer than cache expiration (longer than 1 minute in our case)
            // token's cache expiration should be expired
            Thread.sleep((holder.getForeignTokenCacheExpirationInMins() + 1) * 60000);
            userFromDB = tokenManager1.validateToken(newEncoded);
            Assert.assertNull(userFromDB);
            return null;
        }
    }
    for (int i = 0; i < numThreads; i++) {
        executor.submit(new InitTester());
    }
    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(180, TimeUnit.SECONDS));
}
Also used : TokenMaxLifeValuesHolder(com.emc.storageos.security.authentication.TokenMaxLifeValuesHolder) CassandraTokenManager(com.emc.storageos.auth.impl.CassandraTokenManager) DbClient(com.emc.storageos.db.client.DbClient) SignedToken(com.emc.storageos.security.authentication.Base64TokenEncoder.SignedToken) ProxyToken(com.emc.storageos.db.client.model.ProxyToken) Token(com.emc.storageos.db.client.model.Token) BaseToken(com.emc.storageos.db.client.model.BaseToken) TokenKeyGenerator(com.emc.storageos.security.authentication.TokenKeyGenerator) URI(java.net.URI) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO) InterVDCTokenCacheHelper(com.emc.storageos.security.geo.InterVDCTokenCacheHelper) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) TokenOnWire(com.emc.storageos.security.authentication.TokenOnWire) Base64TokenEncoder(com.emc.storageos.security.authentication.Base64TokenEncoder) TokenResponseArtifacts(com.emc.storageos.security.geo.TokenResponseBuilder.TokenResponseArtifacts) Test(org.junit.Test)

Aggregations

CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)49 Test (org.junit.Test)11 Base64TokenEncoder (com.emc.storageos.security.authentication.Base64TokenEncoder)8 TokenKeyGenerator (com.emc.storageos.security.authentication.TokenKeyGenerator)8 TokenMaxLifeValuesHolder (com.emc.storageos.security.authentication.TokenMaxLifeValuesHolder)8 Configuration (com.emc.storageos.coordinator.common.Configuration)7 DbClient (com.emc.storageos.db.client.DbClient)7 CassandraTokenManager (com.emc.storageos.auth.impl.CassandraTokenManager)6 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)6 StorageOSUserDAO (com.emc.storageos.db.client.model.StorageOSUserDAO)6 TokenOnWire (com.emc.storageos.security.authentication.TokenOnWire)6 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)5 URI (java.net.URI)5 Service (com.emc.storageos.coordinator.common.Service)4 InterVDCTokenCacheHelper (com.emc.storageos.security.geo.InterVDCTokenCacheHelper)4 ArrayList (java.util.ArrayList)4 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)3 BaseToken (com.emc.storageos.db.client.model.BaseToken)3 ProxyToken (com.emc.storageos.db.client.model.ProxyToken)3 Token (com.emc.storageos.db.client.model.Token)3