Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups in connectors logging #24361

Merged
merged 8 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions appserver/connectors/connectors-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -51,6 +51,7 @@

import java.io.Serializable;
import java.security.Principal;
import java.text.MessageFormat;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -255,10 +256,8 @@ protected Object internalGetConnection(ManagedConnectionFactory mcf,
resourceSpec.setPoolInfo(this.poolInfo);
ManagedConnectionFactory freshManagedConnectionFactory = poolMetaData.getMCF();

if (LOG.isLoggable(Level.INFO)) {
if (!freshManagedConnectionFactory.equals(mcf)) {
LOG.info("conmgr.mcf_not_equal");
}
if (!freshManagedConnectionFactory.equals(mcf)) {
LOG.info("conmgr.mcf_not_equal");
}
ConnectorDescriptor rarConnectorDescriptor = registry.getDescriptor(rarName);

Expand Down Expand Up @@ -298,23 +297,23 @@ protected Object internalGetConnection(ManagedConnectionFactory mcf,

return getResource(txLevel, poolManager, mcf, resourceSpec, subject, cxRequestInfo, info, rarConnectorDescriptor, shareable);

} catch (PoolingException ex) {
LOG.log(Level.WARNING, "poolmgr.get_connection_failure", new Object[]{poolInfo, ex});
} catch (PoolingException e) {
// We can't simply look for ResourceException and throw back since
// Connector Container also throws ResourceException which might
// hide the SecurityException thrown by RA.
// So, we try to track SecurityException
unwrapSecurityException(ex);
String i18nMsg = I18N.getString("con_mgr.error_creating_connection", ex.getMessage());
ResourceAllocationException rae = new ResourceAllocationException(i18nMsg);
rae.initCause(ex);
throw rae;
unwrapSecurityException(e);
throw new ResourceAllocationException(
MessageFormat.format("Failed to obtain/create connection from connection pool [{0}]. Reason: {1}",
poolInfo.getName(), e.getMessage()),
e);
}
}

private void unwrapSecurityException(Throwable ex) throws ResourceException{
private void unwrapSecurityException(Throwable ex) throws ResourceException {
if (ex != null) {
if (ex instanceof SecurityException) {
LOG.log(Level.WARNING, "poolmgr.get_connection_failure", new Object[] {poolInfo, ex});
throw (SecurityException) ex;
}
unwrapSecurityException(ex.getCause());
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,13 +17,6 @@

package com.sun.enterprise.resource.allocator;

import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.security.auth.Subject;

import com.sun.appserv.connectors.internal.api.ConnectorConstants;
import com.sun.appserv.connectors.internal.api.ConnectorRuntimeException;
import com.sun.appserv.connectors.internal.api.PoolingException;
Expand All @@ -42,6 +35,13 @@
import jakarta.resource.spi.ManagedConnectionFactory;
import jakarta.resource.spi.ValidatingManagedConnectionFactory;

import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.security.auth.Subject;


/**
* An abstract implementation of the <code>ResourceAllocator</code> interface
Expand All @@ -51,8 +51,8 @@
*
* @author Sivakumar Thyagarajan
*/
public abstract class AbstractConnectorAllocator
implements ResourceAllocator {
public abstract class AbstractConnectorAllocator implements ResourceAllocator {
protected final static Logger _logger = LogDomains.getLogger(AbstractConnectorAllocator.class,LogDomains.RSR_LOGGER);

protected PoolManager poolMgr;
protected ResourceSpec spec;
Expand All @@ -62,7 +62,6 @@ public abstract class AbstractConnectorAllocator
protected ConnectorDescriptor desc;
protected ClientSecurityInfo info;

protected final static Logger _logger = LogDomains.getLogger(AbstractConnectorAllocator.class,LogDomains.RSR_LOGGER);

public AbstractConnectorAllocator() {
}
Expand All @@ -81,15 +80,12 @@ public AbstractConnectorAllocator(PoolManager poolMgr,
this.reqInfo = reqInfo;
this.info = info;
this.desc = desc;

}

@Override
public Set getInvalidConnections(Set connectionSet)
throws ResourceException {
public Set getInvalidConnections(Set connectionSet) throws ResourceException {
if (mcf instanceof ValidatingManagedConnectionFactory) {
return ((ValidatingManagedConnectionFactory) this.mcf).
getInvalidConnections(connectionSet);
return ((ValidatingManagedConnectionFactory) this.mcf).getInvalidConnections(connectionSet);
}
return null;
}
Expand All @@ -98,7 +94,7 @@ public Set getInvalidConnections(Set connectionSet)
public boolean isConnectionValid(ResourceHandle h) {
HashSet<ManagedConnection> conn = new HashSet<>();
conn.add((ManagedConnection) h.getResource());
Set invalids = null;
Set<?> invalids = null;
try {
invalids = getInvalidConnections(conn);
} catch (ResourceException re) {
Expand All @@ -115,12 +111,7 @@ public boolean isConnectionValid(ResourceHandle h) {
}
}

if ((invalids != null && invalids.size() > 0) ||
h.hasConnectionErrorOccurred()) {
return false;
}

return true;
return (invalids == null || invalids.isEmpty()) && !h.hasConnectionErrorOccurred();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,12 +17,6 @@

package com.sun.enterprise.resource.allocator;


import java.util.logging.Level;

import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;

import com.sun.appserv.connectors.internal.api.PoolingException;
import com.sun.enterprise.deployment.ConnectorDescriptor;
import com.sun.enterprise.resource.ClientSecurityInfo;
Expand All @@ -37,19 +31,22 @@
import jakarta.resource.spi.ManagedConnection;
import jakarta.resource.spi.ManagedConnectionFactory;

import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;


/**
* @author Tony Ng
*/
public class ConnectorAllocator extends AbstractConnectorAllocator {

private boolean shareable;
private final boolean shareable;


class ConnectionListenerImpl extends com.sun.enterprise.resource.listener.ConnectionEventListener {
private ResourceHandle resource;
private final ResourceHandle resource;

public ConnectionListenerImpl(ResourceHandle resource) {
ConnectionListenerImpl(ResourceHandle resource) {
this.resource = resource;
}

Expand Down Expand Up @@ -143,30 +140,14 @@ public ConnectorAllocator(PoolManager poolMgr,


@Override
public ResourceHandle createResource()
throws PoolingException {
public ResourceHandle createResource() throws PoolingException {
try {
ManagedConnection mc =
mcf.createManagedConnection(subject, reqInfo);

ResourceHandle resource =
createResourceHandle(mc, spec, this, info);
ConnectionEventListener l =
new ConnectionListenerImpl(resource);
ManagedConnection mc = mcf.createManagedConnection(subject, reqInfo);
ResourceHandle resource = createResourceHandle(mc, spec, this, info);
ConnectionEventListener l = new ConnectionListenerImpl(resource);
mc.addConnectionEventListener(l);
return resource;
} catch (ResourceException ex) {
Object[] params = new Object[]{spec.getPoolInfo(), ex.toString()};
_logger.log(Level.WARNING,"poolmgr.create_resource_error",params);
if(_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE,"Resource Exception while creating resource",ex);
}

if (ex.getLinkedException() != null) {
dmatej marked this conversation as resolved.
Show resolved Hide resolved
_logger.log(Level.WARNING,
"poolmgr.create_resource_linked_error", ex
.getLinkedException().toString());
}
throw new PoolingException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021, 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,11 +17,6 @@

package com.sun.enterprise.resource.allocator;

import java.util.logging.Level;

import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;

import com.sun.appserv.connectors.internal.api.PoolingException;
import com.sun.enterprise.deployment.ConnectorDescriptor;
import com.sun.enterprise.resource.ClientSecurityInfo;
Expand All @@ -40,6 +35,11 @@
import jakarta.transaction.Status;
import jakarta.transaction.SystemException;

import java.util.logging.Level;

import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;

/**
* @author Tony Ng
*/
Expand All @@ -66,8 +66,7 @@ public LocalTxConnectorAllocator(PoolManager poolMgr,
}

@Override
public ResourceHandle createResource()
throws PoolingException {
public ResourceHandle createResource() throws PoolingException {
try {
ManagedConnection mc = mcf.createManagedConnection(subject, reqInfo);

Expand All @@ -81,17 +80,6 @@ public ResourceHandle createResource()

return resource;
} catch (ResourceException ex) {
Object[] params = new Object[]{spec.getPoolInfo(), ex.toString()};
_logger.log(Level.WARNING, "poolmgr.create_resource_error", params);
hs536 marked this conversation as resolved.
Show resolved Hide resolved
if(_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Resource Exception while creating resource", ex);
}

if (ex.getLinkedException() != null) {
_logger.log(Level.WARNING,
"poolmgr.create_resource_linked_error", ex
.getLinkedException().toString());
}
throw new PoolingException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,10 +17,6 @@

package com.sun.enterprise.resource.allocator;

import java.util.logging.Level;

import javax.security.auth.Subject;

import com.sun.appserv.connectors.internal.api.PoolingException;
import com.sun.enterprise.deployment.ConnectorDescriptor;
import com.sun.enterprise.resource.ClientSecurityInfo;
Expand All @@ -35,15 +31,17 @@
import jakarta.resource.spi.ManagedConnection;
import jakarta.resource.spi.ManagedConnectionFactory;

import javax.security.auth.Subject;

/**
* @author Tony Ng
*/
public class NoTxConnectorAllocator extends AbstractConnectorAllocator {

class ConnectionListenerImpl extends ConnectionEventListener {
private ResourceHandle resource;
private final ResourceHandle resource;

public ConnectionListenerImpl(ResourceHandle resource) {
ConnectionListenerImpl(ResourceHandle resource) {
this.resource = resource;
}

Expand Down Expand Up @@ -108,29 +106,14 @@ public NoTxConnectorAllocator(PoolManager poolMgr,


@Override
public ResourceHandle createResource()
throws PoolingException {
public ResourceHandle createResource() throws PoolingException {
try {
ManagedConnection mc =
mcf.createManagedConnection(subject, reqInfo);
ResourceHandle resource =
createResourceHandle(mc, spec, this, info);
ConnectionEventListener l =
new ConnectionListenerImpl(resource);
ManagedConnection mc = mcf.createManagedConnection(subject, reqInfo);
ResourceHandle resource = createResourceHandle(mc, spec, this, info);
ConnectionEventListener l = new ConnectionListenerImpl(resource);
mc.addConnectionEventListener(l);
return resource;
} catch (ResourceException ex) {
Object[] params = new Object[]{spec.getPoolInfo(), ex.toString()};
_logger.log(Level.WARNING,"poolmgr.create_resource_error",params);
if(_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE,"Resource Exception while creating resource",ex);
}

if (ex.getLinkedException() != null) {
_logger.log(Level.WARNING,
"poolmgr.create_resource_linked_error", ex
.getLinkedException().toString());
}
throw new PoolingException(ex);
}
}
Expand Down
Loading