Search in sources :

Example 1 with ConnectionException

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;
        }
    }
}
Also used : Scope(io.opentracing.Scope) ConnectionKey(org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionKey) ConnectionException(org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionException)

Example 2 with ConnectionException

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;
}
Also used : KerberosTicket(javax.security.auth.kerberos.KerberosTicket) PrivilegedActionException(java.security.PrivilegedActionException) Connection(java.sql.Connection) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ConnectionException(org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionException)

Aggregations

ConnectionException (org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionException)2 Scope (io.opentracing.Scope)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Connection (java.sql.Connection)1 KerberosTicket (javax.security.auth.kerberos.KerberosTicket)1 ConnectionKey (org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionKey)1