Search in sources :

Example 1 with DataSourceInfo

use of psiprobe.model.DataSourceInfo in project psi-probe by psi-probe.

the class ListAllJdbcResourceGroupsController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    List<DataSourceInfoGroup> dataSourceGroups = new ArrayList<>();
    List<DataSourceInfo> dataSources = new ArrayList<>();
    List<ApplicationResource> privateResources = getContainerWrapper().getPrivateDataSources();
    List<ApplicationResource> globalResources = getContainerWrapper().getGlobalDataSources();
    // filter out anything that is not a datasource
    // and use only those datasources that are properly configured
    // as aggregated totals would not make any sense otherwise
    filterValidDataSources(privateResources, dataSources);
    filterValidDataSources(globalResources, dataSources);
    // sort datasources by JDBC URL
    Collections.sort(dataSources, new Comparator<DataSourceInfo>() {

        @Override
        public int compare(DataSourceInfo ds1, DataSourceInfo ds2) {
            String jdbcUrl1 = ds1.getJdbcUrl();
            String jdbcUrl2 = ds2.getJdbcUrl();
            return jdbcUrl1.compareToIgnoreCase(jdbcUrl2);
        }
    });
    // group datasources by JDBC URL and calculate aggregated totals
    DataSourceInfoGroup dsGroup = null;
    for (DataSourceInfo ds : dataSources) {
        if (dsGroup == null || !dsGroup.getJdbcUrl().equalsIgnoreCase(ds.getJdbcUrl())) {
            dsGroup = new DataSourceInfoGroup().builder(ds);
            dataSourceGroups.add(dsGroup);
        } else {
            dsGroup.addDataSourceInfo(ds);
        }
    }
    return new ModelAndView(getViewName(), "dataSourceGroups", dataSourceGroups);
}
Also used : DataSourceInfo(psiprobe.model.DataSourceInfo) ApplicationResource(psiprobe.model.ApplicationResource) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) DataSourceInfoGroup(psiprobe.model.DataSourceInfoGroup)

Example 2 with DataSourceInfo

use of psiprobe.model.DataSourceInfo in project psi-probe by psi-probe.

the class Tomcat85DbcpDatasourceAccessor method getInfo.

@Override
public DataSourceInfo getInfo(Object resource) throws Exception {
    DataSourceInfo dataSourceInfo = null;
    if (canMap(resource)) {
        BasicDataSource source = (BasicDataSource) resource;
        dataSourceInfo = new DataSourceInfo();
        dataSourceInfo.setBusyConnections(source.getNumActive());
        dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive());
        dataSourceInfo.setMaxConnections(source.getMaxTotal());
        dataSourceInfo.setJdbcUrl(source.getUrl());
        dataSourceInfo.setUsername(source.getUsername());
        dataSourceInfo.setResettable(false);
        dataSourceInfo.setType("tomcat-dbcp2");
    }
    return dataSourceInfo;
}
Also used : DataSourceInfo(psiprobe.model.DataSourceInfo) BasicDataSource(org.apache.tomcat.dbcp.dbcp2.BasicDataSource)

Example 3 with DataSourceInfo

use of psiprobe.model.DataSourceInfo in project psi-probe by psi-probe.

the class Tomcat9DbcpDatasourceAccessor method getInfo.

@Override
public DataSourceInfo getInfo(Object resource) throws Exception {
    DataSourceInfo dataSourceInfo = null;
    if (canMap(resource)) {
        BasicDataSource source = (BasicDataSource) resource;
        dataSourceInfo = new DataSourceInfo();
        dataSourceInfo.setBusyConnections(source.getNumActive());
        dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive());
        dataSourceInfo.setMaxConnections(source.getMaxTotal());
        dataSourceInfo.setJdbcUrl(source.getUrl());
        dataSourceInfo.setUsername(source.getUsername());
        dataSourceInfo.setResettable(false);
        dataSourceInfo.setType("tomcat-dbcp2");
    }
    return dataSourceInfo;
}
Also used : DataSourceInfo(psiprobe.model.DataSourceInfo) BasicDataSource(org.apache.tomcat.dbcp.dbcp2.BasicDataSource)

Example 4 with DataSourceInfo

use of psiprobe.model.DataSourceInfo in project psi-probe by psi-probe.

the class Tomcat7DbcpDatasourceAccessor method getInfo.

@Override
public DataSourceInfo getInfo(Object resource) throws Exception {
    DataSourceInfo dataSourceInfo = null;
    if (canMap(resource)) {
        BasicDataSource source = (BasicDataSource) resource;
        dataSourceInfo = new DataSourceInfo();
        dataSourceInfo.setBusyConnections(source.getNumActive());
        dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive());
        dataSourceInfo.setMaxConnections(source.getMaxActive());
        dataSourceInfo.setJdbcUrl(source.getUrl());
        dataSourceInfo.setUsername(source.getUsername());
        dataSourceInfo.setResettable(false);
        dataSourceInfo.setType("tomcat-dbcp");
    }
    return dataSourceInfo;
}
Also used : DataSourceInfo(psiprobe.model.DataSourceInfo) BasicDataSource(org.apache.tomcat.dbcp.dbcp.BasicDataSource)

Example 5 with DataSourceInfo

use of psiprobe.model.DataSourceInfo in project psi-probe by psi-probe.

the class JBossResourceResolverBean method getApplicationResources.

@Override
public List<ApplicationResource> getApplicationResources() throws NamingException {
    List<ApplicationResource> resources = new ArrayList<>();
    MBeanServer server = getMBeanServer();
    if (server != null) {
        try {
            Set<ObjectName> dsNames = server.queryNames(new ObjectName("jboss.jca:service=ManagedConnectionPool,*"), null);
            for (ObjectName managedConnectionPoolOName : dsNames) {
                ApplicationResource resource = new ApplicationResource();
                resource.setName(managedConnectionPoolOName.getKeyProperty("name"));
                resource.setType("jboss");
                String criteria = (String) server.getAttribute(managedConnectionPoolOName, "Criteria");
                if ("ByApplication".equals(criteria)) {
                    resource.setAuth("Application");
                } else if ("ByContainerAndApplication".equals(criteria)) {
                    resource.setAuth("Both");
                } else {
                    resource.setAuth("Container");
                }
                DataSourceInfo dsInfo = new DataSourceInfo();
                dsInfo.setMaxConnections((Integer) server.getAttribute(managedConnectionPoolOName, "MaxSize"));
                dsInfo.setEstablishedConnections((Integer) server.getAttribute(managedConnectionPoolOName, "ConnectionCount"));
                dsInfo.setBusyConnections(((Long) server.getAttribute(managedConnectionPoolOName, "InUseConnectionCount")).intValue());
                ObjectName connectionFactoryOName = new ObjectName("jboss.jca:service=ManagedConnectionFactory,name=" + resource.getName());
                Element elm = (Element) server.getAttribute(connectionFactoryOName, "ManagedConnectionFactoryProperties");
                if (elm != null) {
                    NodeList nl = elm.getChildNodes();
                    for (int i = 0; i < nl.getLength(); i++) {
                        Node node = nl.item(i);
                        Node na = node.getAttributes().getNamedItem("name");
                        if (na != null) {
                            if ("ConnectionURL".equals(na.getNodeValue())) {
                                dsInfo.setJdbcUrl(node.getFirstChild().getNodeValue());
                            }
                            if ("UserName".equals(na.getNodeValue())) {
                                dsInfo.setUsername(node.getFirstChild().getNodeValue());
                            }
                            // JMS datasource
                            if ("JmsProviderAdapterJNDI".equals(na.getNodeValue())) {
                                dsInfo.setJdbcUrl(node.getFirstChild().getNodeValue());
                                resource.setType("jms");
                            }
                        }
                    }
                }
                dsInfo.setResettable(true);
                resource.setDataSourceInfo(dsInfo);
                resources.add(resource);
            }
        } catch (Exception e) {
            logger.error("There was an error querying JBoss JMX server:", e);
        }
    }
    return resources;
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) NamingException(javax.naming.NamingException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName) DataSourceInfo(psiprobe.model.DataSourceInfo) ApplicationResource(psiprobe.model.ApplicationResource) MBeanServer(javax.management.MBeanServer)

Aggregations

DataSourceInfo (psiprobe.model.DataSourceInfo)19 ApplicationResource (psiprobe.model.ApplicationResource)4 ArrayList (java.util.ArrayList)3 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 BasicDataSource (org.apache.tomcat.dbcp.dbcp2.BasicDataSource)3 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 NamingException (javax.naming.NamingException)2 BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)2 DataSource (org.apache.tomcat.jdbc.pool.DataSource)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 BoneCP (com.jolbox.bonecp.BoneCP)1 BoneCPDataSource (com.jolbox.bonecp.BoneCPDataSource)1 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 HikariPoolMXBean (com.zaxxer.hikari.HikariPoolMXBean)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1