@Override public Integer getValue() { if (ds.getPool() != null) { return ds.getPool().getStatistics().getTotalCreatedConnections(); } else { return 0; } } });
@Override public Integer getValue() { if (ds.getPool() != null) { return ds.getPool().getStatistics().getTotalFree(); } else { return 0; } } });
@Override public Double getValue() { if (ds.getPool() != null) { return ds.getPool().getStatistics().getConnectionWaitTimeAvg(); } else { return 0.0; } } });
@Override public DataSource create(Configuration hdpConfig) throws SQLException { LOG.debug("Creating BoneCP connection pool for the MetaStore"); String driverUrl = DataSourceProvider.getMetastoreJdbcDriverUrl(hdpConfig); String user = DataSourceProvider.getMetastoreJdbcUser(hdpConfig); String passwd = DataSourceProvider.getMetastoreJdbcPasswd(hdpConfig); int maxPoolSize = MetastoreConf.getIntVar(hdpConfig, MetastoreConf.ConfVars.CONNECTION_POOLING_MAX_CONNECTIONS); Properties properties = DataSourceProvider.getPrefixedProperties(hdpConfig, BONECP); long connectionTimeout = hdpConfig.getLong(CONNECTION_TIMEOUT_PROPERTY, 30000L); String partitionCount = properties.getProperty(PARTITION_COUNT_PROPERTY, "1"); BoneCPConfig config = null; try { config = new BoneCPConfig(properties); } catch (Exception e) { throw new SQLException("Cannot create BoneCP configuration: ", e); } config.setJdbcUrl(driverUrl); // if we are waiting for connection for a long time, something is really wrong // better raise an error than hang forever // see DefaultConnectionStrategy.getConnectionInternal() config.setConnectionTimeoutInMs(connectionTimeout); config.setMaxConnectionsPerPartition(maxPoolSize); config.setPartitionCount(Integer.parseInt(partitionCount)); config.setUser(user); config.setPassword(passwd); return initMetrics(new BoneCPDataSource(config)); }
@Override public BoneCPDataSource load(UsernamePassword key) throws Exception { BoneCPDataSource ds = null; ds = new BoneCPDataSource(getConfig()); ds.setUsername(key.getUsername()); ds.setPassword(key.getPassword()); return ds; } });
BoneCP pool; try { pool = source.getPool(); } catch (NoSuchMethodError ex) { logger.trace("", ex); dataSourceInfo.setBusyConnections(source.getTotalLeased()); dataSourceInfo.setEstablishedConnections(source.getMinConnectionsPerPartition()); logger.warn("pool is null {}", source.getJdbcUrl()); } else { dataSourceInfo.setEstablishedConnections(pool.getTotalCreatedConnections()); .setMaxConnections(source.getPartitionCount() * source.getMaxConnectionsPerPartition()); dataSourceInfo.setJdbcUrl(source.getJdbcUrl()); dataSourceInfo.setUsername(source.getUsername()); dataSourceInfo.setResettable(false); dataSourceInfo.setType("bonecp");
@Override public int maximumPoolSize(DataSource dataSource, JsonObject config) { if (dataSource instanceof BoneCPDataSource) { BoneCPConfig cfg = ((BoneCPDataSource) dataSource).getPool().getConfig(); return cfg.getMaxConnectionsPerPartition() * cfg.getPartitionCount(); } return -1; }
@Override public Integer getValue() { if (ds.getPool() != null) { return ds.getPool().getStatistics().getTotalLeased(); } else { return 0; } } });
/** Thread constructor * @param connectionPartition partition to monitor * @param pool Pool handle. */ public PoolWatchThread(ConnectionPartition connectionPartition, BoneCP pool) { this.partition = connectionPartition; this.pool = pool; this.lazyInit = this.pool.getConfig().isLazyInit(); this.acquireRetryDelayInMs = this.pool.getConfig().getAcquireRetryDelayInMs(); this.poolAvailabilityThreshold = this.pool.getConfig().getPoolAvailabilityThreshold(); }
/** * Returns the total leased connections. * * @return total leased connections */ public int getTotalLeased() { return getPool() == null ? 0 : getPool().getTotalLeased(); }
/** Sends any configured SQL init statement. * @throws SQLException on error */ public void sendInitSQL() throws SQLException { sendInitSQL(this.connection, this.pool.getConfig().getInitSQL()); }
/** * @return the connection * @throws SQLException */ public synchronized Connection getConnection() throws SQLException { if (this.mockJDBCAnswer == null){ return new MockConnection(); } return this.mockJDBCAnswer.answer(); }
/** {@inheritDoc} * @see java.sql.Connection#prepareStatement(java.lang.String) */ // @Override public PreparedStatement prepareStatement(String sql) throws SQLException { return new MockPreparedStatement(); }
private BoneCPMetrics(final BoneCPDataSource ds) { this.ds = ds; this.poolName = Optional.ofNullable(ds.getPoolName()); }
@Test public void testSetBoneCpBooleanProperty() throws SQLException { MetastoreConf.setVar(conf, ConfVars.CONNECTION_POOLING_TYPE, BoneCPDataSourceProvider.BONECP); conf.set(BoneCPDataSourceProvider.BONECP + ".disableJMX", "true"); DataSourceProvider dsp = DataSourceProviderFactory.tryGetDataSourceProviderOrNull(conf); Assert.assertNotNull(dsp); DataSource ds = dsp.create(conf); Assert.assertTrue(ds instanceof BoneCPDataSource); Assert.assertEquals(true, ((BoneCPDataSource)ds).isDisableJMX()); }
@Test public void testSetBoneCpStringProperty() throws SQLException { MetastoreConf.setVar(conf, ConfVars.CONNECTION_POOLING_TYPE, BoneCPDataSourceProvider.BONECP); conf.set(BoneCPDataSourceProvider.BONECP + ".initSQL", "select 1 from dual"); DataSourceProvider dsp = DataSourceProviderFactory.tryGetDataSourceProviderOrNull(conf); Assert.assertNotNull(dsp); DataSource ds = dsp.create(conf); Assert.assertTrue(ds instanceof BoneCPDataSource); Assert.assertEquals("select 1 from dual", ((BoneCPDataSource)ds).getInitSQL()); }
@Test public void testSetBoneCpNumberProperty() throws SQLException { MetastoreConf.setVar(conf, ConfVars.CONNECTION_POOLING_TYPE, BoneCPDataSourceProvider.BONECP); conf.set(BoneCPDataSourceProvider.BONECP + ".acquireRetryDelayInMs", "599"); DataSourceProvider dsp = DataSourceProviderFactory.tryGetDataSourceProviderOrNull(conf); Assert.assertNotNull(dsp); DataSource ds = dsp.create(conf); Assert.assertTrue(ds instanceof BoneCPDataSource); Assert.assertEquals(599L, ((BoneCPDataSource)ds).getAcquireRetryDelayInMs()); }
/** * @return the connection * @throws SQLException */ public synchronized Connection getConnection() throws SQLException { if (this.mockJDBCAnswer == null){ return new MockConnection(); } return this.mockJDBCAnswer.answer(); }
/** {@inheritDoc} * @see java.sql.Connection#prepareStatement(java.lang.String, int) */ // @Override public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { return new MockPreparedStatement(); }
/** {@inheritDoc} * @see java.sql.Connection#prepareStatement(java.lang.String, java.lang.String[]) */ // @Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { return new MockPreparedStatement(); }