Search in sources :

Example 46 with VirtualDataCenter

use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.

the class DBClient method readRecoverBackupInfo.

private List<VdcConfig> readRecoverBackupInfo() {
    List<VdcConfig> newVdcConfigList = new ArrayList<VdcConfig>();
    List<URI> ids = _dbClient.queryByType(VdcOpLog.class, true);
    VdcOpLog latestOp = null;
    for (URI id : ids) {
        if (latestOp == null) {
            latestOp = _dbClient.queryObject(VdcOpLog.class, id);
        } else {
            VdcOpLog thisOp = _dbClient.queryObject(VdcOpLog.class, id);
            if (thisOp.getCreationTime().getTimeInMillis() > latestOp.getCreationTime().getTimeInMillis()) {
                latestOp = thisOp;
            }
        }
    }
    if (latestOp != null) {
        byte[] vdcConfigInfo = latestOp.getVdcConfigInfo();
        try {
            List<VirtualDataCenter> vdcList = (List<VirtualDataCenter>) SerializerUtils.deserialize(vdcConfigInfo);
            if (vdcList != null) {
                for (VirtualDataCenter vdc : vdcList) {
                    newVdcConfigList.add(vdcConfHelper.toConfigParam(vdc));
                }
            }
        } catch (Exception e) {
            log.error("error in recovervdcinfo: " + e);
        }
    }
    return newVdcConfigList;
}
Also used : VdcConfig(com.emc.storageos.geomodel.VdcConfig) ArrayList(java.util.ArrayList) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) URI(java.net.URI) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) IOException(java.io.IOException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) VdcOpLog(com.emc.storageos.db.client.model.VdcOpLog)

Example 47 with VirtualDataCenter

use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.

the class DBClient method setGeoBlacklist.

/**
 * Set geo blacklist
 *
 * @param vdcShortId
 */
public void setGeoBlacklist(String vdcShortId) {
    InternalDbClient geoDbClient = (InternalDbClient) ctx.getBean("geodbclient");
    List<URI> vdcList = geoDbClient.queryByType(VirtualDataCenter.class, true);
    for (URI vdcId : vdcList) {
        VirtualDataCenter vdc = geoDbClient.queryObject(VirtualDataCenter.class, vdcId);
        if (vdc.getShortId().equals(vdcShortId)) {
            System.out.println("Add black list for vdc: " + vdcShortId);
            geoDbClient.addVdcNodesToBlacklist(vdc);
            break;
        }
    }
}
Also used : InternalDbClient(com.emc.storageos.geo.vdccontroller.impl.InternalDbClient) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI)

Example 48 with VirtualDataCenter

use of com.emc.storageos.db.client.model.VirtualDataCenter 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)

Example 49 with VirtualDataCenter

use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.

the class InternalVdcService method getVdc.

@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VirtualDataCenterRestRep getVdc(@PathParam("id") URI id) {
    ArgValidator.checkUri(id);
    VirtualDataCenter vdc = _dbClient.queryObject(VirtualDataCenter.class, id);
    return map(vdc);
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 50 with VirtualDataCenter

use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.

the class ConnectVdcTaskOp method sendVdcNodeCheckRequest.

/**
 * Send node check request to target vdc.
 *
 * @param vdcProp vdc to send msg to
 * @param vdcsToCheck list of vdc's with nodes to check
 * @return
 * @throws Exception
 */
private VdcNodeCheckResponse sendVdcNodeCheckRequest(Properties vdcProp, Collection<VirtualDataCenter> vdcsToCheck) {
    List<VdcConfig> virtualDataCenters = new ArrayList<VdcConfig>();
    for (VirtualDataCenter vdc : vdcsToCheck) {
        VdcConfig vdcConfig = new VdcConfig();
        Site activeSite = drUtil.getActiveSite(vdc.getShortId());
        vdcConfig.setId(vdc.getId());
        vdcConfig.setShortId(vdc.getShortId());
        if (activeSite.getHostIPv4AddressMap() != null && !activeSite.getHostIPv4AddressMap().isEmpty() && activeSite.isUsingIpv4()) {
            HashMap<String, String> ipv4AddrMap = new HashMap<String, String>(activeSite.getHostIPv4AddressMap());
            vdcConfig.setHostIPv4AddressesMap(ipv4AddrMap);
        } else if (activeSite.getHostIPv6AddressMap() != null && !activeSite.getHostIPv6AddressMap().isEmpty()) {
            HashMap<String, String> ipv6AddrMap = new HashMap<String, String>(activeSite.getHostIPv6AddressMap());
            vdcConfig.setHostIPv6AddressesMap(ipv6AddrMap);
        } else {
            throw GeoException.fatals.cannotPerformOperation(vdc.getId().toString(), " no nodes were found on VirtualDataCenter object");
        }
        virtualDataCenters.add(vdcConfig);
    }
    return sendVdcNodeCheckRequest(vdcProp, virtualDataCenters);
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) HashMap(java.util.HashMap) VdcConfig(com.emc.storageos.geomodel.VdcConfig) ArrayList(java.util.ArrayList) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter)

Aggregations

VirtualDataCenter (com.emc.storageos.db.client.model.VirtualDataCenter)80 URI (java.net.URI)47 ArrayList (java.util.ArrayList)20 VdcConfig (com.emc.storageos.geomodel.VdcConfig)14 GeoException (com.emc.storageos.security.geo.exceptions.GeoException)13 Test (org.junit.Test)10 Site (com.emc.storageos.coordinator.client.model.Site)7 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)7 VdcConfigSyncParam (com.emc.storageos.geomodel.VdcConfigSyncParam)7 FatalGeoException (com.emc.storageos.security.geo.exceptions.FatalGeoException)7 NamedURI (com.emc.storageos.db.client.model.NamedURI)6 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)5 Produces (javax.ws.rs.Produces)5 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)4 DataObject (com.emc.storageos.db.client.model.DataObject)4 TestGeoObject (com.emc.storageos.db.client.model.TestGeoObject)4 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)4 KeyStoreException (java.security.KeyStoreException)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4