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);
}
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations