Search in sources :

Example 6 with DbClientContext

use of com.emc.storageos.db.client.impl.DbClientContext in project coprhd-controller by CoprHD.

the class DbsvcGeoTestBase method getDbClient.

protected static TestGeoDbClientImpl getDbClient() {
    try {
        TestGeoDbClientImpl dbClient = getDbClientBase();
        DbClientContext geoCtx = new DbClientContext();
        geoCtx.setClusterName("GeoStorageOS");
        geoCtx.setKeyspaceName("GeoStorageOS");
        dbClient.setGeoContext(geoCtx);
        DbClientContext localCtx = new DbClientContext();
        localCtx.setClusterName("StorageOS");
        localCtx.setKeyspaceName("StorageOS");
        dbClient.setLocalContext(localCtx);
        // dbClient.setGeoContext(new DbClientContext());
        dbClient.start();
        VdcUtil.setDbClient(dbClient);
        return dbClient;
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : DbClientContext(com.emc.storageos.db.client.impl.DbClientContext) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) IOException(java.io.IOException)

Example 7 with DbClientContext

use of com.emc.storageos.db.client.impl.DbClientContext in project coprhd-controller by CoprHD.

the class GeoDbSvcStartupTest method getDbClient.

protected static DbClient getDbClient() throws URISyntaxException, IOException {
    if (dbClient == null) {
        dbClient = new DbClientImpl();
        CoordinatorClient coordinator = runner.getCoordinator();
        dbClient.setCoordinatorClient(coordinator);
        DbVersionInfo dbVersionInfo = new DbVersionInfo();
        dbVersionInfo.setSchemaVersion(DbSvcRunner.SVC_VERSION);
        dbClient.setDbVersionInfo(dbVersionInfo);
        dbClient.setBypassMigrationLock(true);
        EncryptionProviderImpl encryptionProvider = new EncryptionProviderImpl();
        encryptionProvider.setCoordinator(coordinator);
        dbClient.setEncryptionProvider(encryptionProvider);
        EncryptionProviderImpl geoEncryptionProvider = new EncryptionProviderImpl();
        geoEncryptionProvider.setCoordinator(coordinator);
        geoEncryptionProvider.setEncryptId("geoid");
        dbClient.setGeoEncryptionProvider(geoEncryptionProvider);
        DbClientContext geoCtx = new DbClientContext();
        geoCtx.setClusterName("GeoStorageOS");
        geoCtx.setKeyspaceName("GeoStorageOS");
        dbClient.setGeoContext(geoCtx);
        dbClient.start();
    }
    return dbClient;
}
Also used : DbClientContext(com.emc.storageos.db.client.impl.DbClientContext) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) EncryptionProviderImpl(com.emc.storageos.db.client.impl.EncryptionProviderImpl) DbVersionInfo(com.emc.storageos.coordinator.client.model.DbVersionInfo)

Example 8 with DbClientContext

use of com.emc.storageos.db.client.impl.DbClientContext in project coprhd-controller by CoprHD.

the class DbServiceImpl method initKeystoreAndTruststore.

/**
 * Initializes the keystore/truststore if the paths have been provided.
 */
private void initKeystoreAndTruststore() {
    try {
        DbClientContext ctx = _dbClient.getLocalContext();
        if (isGeoDbsvc()) {
            ctx = _dbClient.getGeoContext();
        }
        String keystorePath = ctx.getKeyStoreFile();
        String truststorePath = ctx.getTrustStoreFile();
        if (keystorePath == null && truststorePath == null) {
            _log.info("Skipping keystore/truststore initialization, no paths provided");
            return;
        }
        String password = ctx.getTrustStorePassword();
        CassandraKeystoreHandler keystoreHandler = new CassandraKeystoreHandler(_coordinator, keystorePath, truststorePath, password);
        if (keystorePath != null) {
            _log.info("Initializing keystore for current node: {}", keystorePath);
            keystoreHandler.saveKeyStore();
        } else {
            _log.info("Skipping keystore initialization, no path provided");
        }
        if (truststorePath != null) {
            _log.info("Initializing truststore for current node: {}", truststorePath);
            keystoreHandler.saveTrustStore();
        } else {
            _log.info("Skipping truststore initialization, no path provided");
        }
    } catch (Exception e) {
        _log.error("Unexpected exception during initializing cassandra keystore", e);
        throw new IllegalStateException(e);
    }
}
Also used : DbClientContext(com.emc.storageos.db.client.impl.DbClientContext) IOException(java.io.IOException)

Example 9 with DbClientContext

use of com.emc.storageos.db.client.impl.DbClientContext in project coprhd-controller by CoprHD.

the class MigrationHandlerImpl method runMigrationCallbacks.

/**
 * Figure out all migration callbacks and run from given checkpoint
 *
 * @param diff
 * @param checkpoint
 * @throws MigrationCallbackException
 */
private void runMigrationCallbacks(DbSchemasDiff diff, String checkpoint) throws MigrationCallbackException {
    List<MigrationCallback> callbacks = new ArrayList<>();
    // TODO: we are putting class annotations at the first place since that's where
    // @Keyspace belongs, but we probably need some explicit ordering to make sure
    // that the geo resources gets migrated into geodb first.
    callbacks.addAll(generateDefaultMigrationCallbacks(diff.getNewClassAnnotations()));
    callbacks.addAll(generateDefaultMigrationCallbacks(diff.getNewFieldAnnotations()));
    // now, see if there is any extra ones we need to run from the specified source
    // version
    callbacks.addAll(generateCustomMigrationCallbacks());
    log.info("Total {} migration callbacks ", callbacks.size());
    DbClientContext geoContext = disableGeoAccess();
    boolean startProcessing = false;
    try {
        for (MigrationCallback callback : callbacks) {
            // ignore the callback if it is before given checkpoint
            if (!startProcessing && checkpoint != null) {
                if (!callback.getName().equals(checkpoint)) {
                    log.info("Ignore migration callback: " + callback.getName());
                    continue;
                } else {
                    // Start from next callback
                    startProcessing = true;
                    continue;
                }
            }
            long beginTime = System.currentTimeMillis();
            log.info("Invoking migration callback: {}", callback.getName());
            try {
                callback.process();
            } catch (MigrationCallbackException ex) {
                throw ex;
            } catch (Exception e) {
                String msg = String.format("%s fail,Please contract the EMC support team", callback.getName());
                throw new MigrationCallbackException(msg, e);
            } finally {
                log.info("Migration callback {} finished with time: {}", callback.getName(), DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - beginTime));
            }
            // Update checkpoint
            schemaUtil.setMigrationCheckpoint(callback.getName());
        }
    } finally {
        enableGeoAccess(geoContext);
    }
}
Also used : DbClientContext(com.emc.storageos.db.client.impl.DbClientContext) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) GeoDbMigrationCallback(com.emc.storageos.db.client.upgrade.callbacks.GeoDbMigrationCallback) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) FatalCoordinatorException(com.emc.storageos.coordinator.exceptions.FatalCoordinatorException) FatalDatabaseException(com.emc.storageos.db.exceptions.FatalDatabaseException)

Example 10 with DbClientContext

use of com.emc.storageos.db.client.impl.DbClientContext in project coprhd-controller by CoprHD.

the class MigrationHandlerImpl method disableGeoAccess.

/*
     * don't allow geo db migration callback.
     */
private DbClientContext disableGeoAccess() {
    log.info("disable geo access temporary since we don't support geo db migration callback now");
    DbClientContext geoContext = this.dbClient.getGeoContext();
    this.dbClient.setGeoContext(new DbClientContext() {

        @Override
        public Keyspace getKeyspace() {
            log.error("doesn't support migration callback for Geo");
            for (StackTraceElement st : Thread.currentThread().getStackTrace()) {
                log.error(st.getClassName() + ":" + st.getMethodName() + ", (" + st.getLineNumber() + ") \n");
            }
            throw new IllegalArgumentException("doesn't support migration callback for Geo");
        }
    });
    return geoContext;
}
Also used : DbClientContext(com.emc.storageos.db.client.impl.DbClientContext) Keyspace(com.netflix.astyanax.Keyspace)

Aggregations

DbClientContext (com.emc.storageos.db.client.impl.DbClientContext)17 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)4 Before (org.junit.Before)4 DbVersionInfo (com.emc.storageos.coordinator.client.model.DbVersionInfo)3 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)3 DbClientImplUnitTester (com.emc.storageos.db.server.DbClientTest.DbClientImplUnitTester)3 CoordinatorClientInetAddressMap (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SiteInfo (com.emc.storageos.coordinator.client.model.SiteInfo)1 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)1 CoordinatorClientImpl (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientImpl)1 DualInetAddress (com.emc.storageos.coordinator.client.service.impl.DualInetAddress)1 Configuration (com.emc.storageos.coordinator.common.Configuration)1 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)1 ServiceImpl (com.emc.storageos.coordinator.common.impl.ServiceImpl)1 ZkConnection (com.emc.storageos.coordinator.common.impl.ZkConnection)1 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)1 FatalCoordinatorException (com.emc.storageos.coordinator.exceptions.FatalCoordinatorException)1