use of org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionException in project legend-engine by finos.
the class DataSourceSpecification method getConnection.
protected Connection getConnection(IdentityState identityState, Supplier<DataSource> dataSourcePoolBuilder) {
try (Scope scope = GlobalTracer.get().buildSpan("Get Connection").startActive(true)) {
ConnectionKey connectionKey = this.getConnectionKey();
// Logs and traces -----
String principal = identityState.getIdentity().getName();
scope.span().setTag("Principal", principal);
scope.span().setTag("DataSourceSpecification", this.toString());
LOGGER.info("Get Connection as [{}] for datasource [{}]", principal, connectionKey.shortId());
// ---------------------
try {
DataSourceWithStatistics dataSourceWithStatistics = this.connectionStateManager.getDataSourceForIdentityIfAbsentBuild(identityState, this, dataSourcePoolBuilder);
// Logs and traces and stats -----
String poolName = dataSourceWithStatistics.getPoolName();
scope.span().setTag("Pool", poolName);
int requests = dataSourceWithStatistics.requestConnection();
LOGGER.info("Principal [{}] has requested [{}] connections for pool [{}]", principal, requests, poolName);
return authenticationStrategy.getConnection(dataSourceWithStatistics, identityState.getIdentity());
} catch (ConnectionException ce) {
LOGGER.error("ConnectionException {{}} : pool stats [{}] ", principal, connectionStateManager.getPoolStatisticsAsJSON(poolNameFor(identityState.getIdentity())));
LOGGER.error("ConnectionException ", ce);
throw ce;
}
}
}
use of org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionException in project legend-engine by finos.
the class AuthenticationStrategy method getConnectionUsingKerberos.
protected Connection getConnectionUsingKerberos(DataSource ds, Subject subject) {
Connection connection;
try {
if (LOGGER.isDebugEnabled()) {
KerberosTicket kerberosTicket = subject.getPrivateCredentials(KerberosTicket.class).iterator().next();
boolean expired = kerberosTicket == null || !kerberosTicket.isCurrent();
boolean started = kerberosTicket.getStartTime() == null || kerberosTicket.getStartTime().getTime() <= System.currentTimeMillis();
LOGGER.debug("getConnectionUsingKerberos {}: started {} , ends {} expired {} ", subject.getPrincipals().iterator().next().getName(), started, kerberosTicket.getEndTime(), expired);
}
connection = Subject.doAs(subject, (PrivilegedExceptionAction<Connection>) ds::getConnection);
} catch (PrivilegedActionException e) {
this.authenticationStatistics.logAuthenticationError();
LOGGER.error("PrivilegedActionException for subject {} {}", subject, e);
throw new ConnectionException(e.getException());
} catch (RuntimeException e) {
LOGGER.error("RuntimeException for subject {} {}", subject, e);
throw new ConnectionException(e);
}
return connection;
}
Aggregations