use of com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore in project athenz by yahoo.
the class JDBCObjectStoreTest method testGetConnection.
@Test
public void testGetConnection() throws SQLException {
PoolableDataSource mockDataRwSrc = Mockito.mock(PoolableDataSource.class);
Connection rwMockConn = Mockito.mock(Connection.class);
Mockito.doReturn(rwMockConn).when(mockDataRwSrc).getConnection();
PoolableDataSource mockDataRoSrc = Mockito.mock(PoolableDataSource.class);
Connection roMockConn = Mockito.mock(Connection.class);
Mockito.doReturn(roMockConn).when(mockDataRoSrc).getConnection();
JDBCObjectStore store = new JDBCObjectStore(mockDataRwSrc, mockDataRoSrc);
JDBCConnection jdbcConn = (JDBCConnection) store.getConnection(true, true);
assertEquals(jdbcConn.con, rwMockConn);
jdbcConn = (JDBCConnection) store.getConnection(true, false);
assertEquals(jdbcConn.con, roMockConn);
}
use of com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore in project athenz by yahoo.
the class JDBCObjectStoreTest method testGetConnectionReadWriteOnly.
@Test
public void testGetConnectionReadWriteOnly() throws SQLException {
PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
Connection mockConn = Mockito.mock(Connection.class);
Mockito.doReturn(mockConn).when(mockDataSrc).getConnection();
JDBCObjectStore store = new JDBCObjectStore(mockDataSrc, null);
store.setOperationTimeout(60);
assertNotNull(store.getConnection(true, true));
// without read store we should also get a connection for a read
// only operation
assertNotNull(store.getConnection(true, true));
store.clearConnections();
}
use of com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore in project athenz by yahoo.
the class JDBCObjectStoreTest method testGetConnectionReadOnly.
@Test
public void testGetConnectionReadOnly() throws SQLException {
PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
Connection mockConn = Mockito.mock(Connection.class);
Mockito.doReturn(mockConn).when(mockDataSrc).getConnection();
JDBCObjectStore store = new JDBCObjectStore(null, mockDataSrc);
assertNotNull(store.getConnection(true, false));
}
use of com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore in project athenz by yahoo.
the class AWSObjectStoreFactory method create.
@Override
public ObjectStore create(PrivateKeyStore keyStore) {
rdsUser = System.getProperty(ZMSConsts.ZMS_PROP_AWS_RDS_USER);
rdsMaster = System.getProperty(ZMSConsts.ZMS_PROP_AWS_RDS_MASTER_INSTANCE);
rdsReplica = System.getProperty(ZMSConsts.ZMS_PROP_AWS_RDS_REPLICA_INSTANCE);
rdsPort = Integer.parseInt(System.getProperty(ZMSConsts.ZMS_PROP_AWS_RDS_MASTER_PORT, "3306"));
final String rdsEngine = System.getProperty(ZMSConsts.ZMS_PROP_AWS_RDS_ENGINE, "mysql");
final String rdsDatabase = System.getProperty(ZMSConsts.ZMS_PROP_AWS_RDS_DATABASE, "zms_server");
final String jdbcMasterStore = String.format("jdbc:%s://%s:%d/%s", rdsEngine, rdsMaster, rdsPort, rdsDatabase);
final String rdsMasterToken = getAuthToken(rdsMaster, rdsPort, rdsUser);
if (LOG.isDebugEnabled()) {
LOG.debug("Connecting to master {} with auth token {}", jdbcMasterStore, rdsMasterToken);
}
setConnectionProperties(mysqlMasterConnectionProperties, rdsMasterToken);
PoolableDataSource dataMasterSource = DataSourceFactory.create(jdbcMasterStore, mysqlMasterConnectionProperties);
// now check to see if we also have a read-only replica jdbc store configured
PoolableDataSource dataReplicaSource = null;
if (rdsReplica != null) {
final String jdbcReplicaStore = String.format("jdbc:%s://%s:%d/%s", rdsEngine, rdsReplica, rdsPort, rdsDatabase);
final String rdsReplicaToken = getAuthToken(rdsReplica, rdsPort, rdsUser);
if (LOG.isDebugEnabled()) {
LOG.debug("Connecting to replica {} with auth token {}", jdbcReplicaStore, rdsReplicaToken);
}
setConnectionProperties(mysqlReplicaConnectionProperties, rdsReplicaToken);
dataReplicaSource = DataSourceFactory.create(jdbcReplicaStore, mysqlReplicaConnectionProperties);
}
// start our credentials refresh task
long credsRefreshTime = Integer.parseInt(System.getProperty(ZMSConsts.ZMS_PROP_AWS_RDS_CREDS_REFRESH_TIME, "300"));
scheduledThreadPool = Executors.newScheduledThreadPool(1);
scheduledThreadPool.scheduleAtFixedRate(new CredentialsUpdater(), credsRefreshTime, credsRefreshTime, TimeUnit.SECONDS);
return new JDBCObjectStore(dataMasterSource, dataReplicaSource);
}
use of com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore in project athenz by yahoo.
the class JDBCObjectStoreFactory method create.
@Override
public ObjectStore create(PrivateKeyStore keyStore) {
final String jdbcStore = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_RW_STORE);
final String jdbcUser = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_RW_USER);
final String password = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_RW_PASSWORD, "");
final String jdbcAppName = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_APP_NAME, JDBC_APP_NAME);
String jdbcPassword = keyStore.getApplicationSecret(jdbcAppName, password);
Properties readWriteProperties = getProperties(jdbcUser, jdbcPassword);
PoolableDataSource readWriteSrc = DataSourceFactory.create(jdbcStore, readWriteProperties);
// now check to see if we also have a read-only jdbc store configured
// if no username and password are specified then we'll use the
// read-write store credentials
PoolableDataSource readOnlySrc = null;
String jdbcReadOnlyStore = System.getProperty(ZMSConsts.ZMS_PROP_JDBC_RO_STORE);
if (jdbcReadOnlyStore != null && jdbcReadOnlyStore.startsWith(JDBC_APP_NAME)) {
final String jdbcReadOnlyUser = getDefaultSetting(ZMSConsts.ZMS_PROP_JDBC_RO_USER, jdbcUser);
final String readOnlyPassword = getDefaultSetting(ZMSConsts.ZMS_PROP_JDBC_RO_PASSWORD, password);
final String jdbcReadOnlyPassword = keyStore.getApplicationSecret(jdbcAppName, readOnlyPassword);
Properties readOnlyProperties = getProperties(jdbcReadOnlyUser, jdbcReadOnlyPassword);
readOnlySrc = DataSourceFactory.create(jdbcReadOnlyStore, readOnlyProperties);
}
return new JDBCObjectStore(readWriteSrc, readOnlySrc);
}
Aggregations