Search in sources :

Example 1 with WILDCARD

use of javax.management.ObjectName.WILDCARD in project presto by prestodb.

the class JmxMetadata method getJmxTableHandle.

private JmxTableHandle getJmxTableHandle(SchemaTableName tableName) {
    try {
        String canonicalName = new ObjectName(tableName.getTableName()).getCanonicalName();
        Optional<ObjectName> objectName = mbeanServer.queryNames(WILDCARD, null).stream().filter(name -> canonicalName.equalsIgnoreCase(name.getCanonicalName())).findFirst();
        if (!objectName.isPresent()) {
            return null;
        }
        MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName.get());
        ImmutableList.Builder<JmxColumnHandle> columns = ImmutableList.builder();
        columns.add(new JmxColumnHandle(NODE_COLUMN_NAME, createUnboundedVarcharType()));
        // Since this method is being called on all nodes in the cluster, we must ensure (by sorting)
        // that attributes are in the same order on all of them.
        Arrays.stream(mbeanInfo.getAttributes()).filter(MBeanAttributeInfo::isReadable).map(attribute -> new JmxColumnHandle(attribute.getName(), getColumnType(attribute))).sorted((column1, column2) -> column1.getColumnName().compareTo(column2.getColumnName())).forEach(columns::add);
        return new JmxTableHandle(objectName.get().toString(), columns.build(), true);
    } catch (JMException e) {
        return null;
    }
}
Also used : ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) Arrays(java.util.Arrays) DOUBLE(com.facebook.presto.spi.type.DoubleType.DOUBLE) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) Inject(javax.inject.Inject) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) Type(com.facebook.presto.spi.type.Type) MBeanServer(javax.management.MBeanServer) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) TIMESTAMP(com.facebook.presto.spi.type.TimestampType.TIMESTAMP) ENGLISH(java.util.Locale.ENGLISH) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ImmutableMap(com.google.common.collect.ImmutableMap) WILDCARD(javax.management.ObjectName.WILDCARD) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Set(java.util.Set) Constraint(com.facebook.presto.spi.Constraint) ObjectName(javax.management.ObjectName) Maps(com.google.common.collect.Maps) MBeanInfo(javax.management.MBeanInfo) ConnectorSession(com.facebook.presto.spi.ConnectorSession) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) JMException(javax.management.JMException) Optional(java.util.Optional) Builder(com.google.common.collect.ImmutableList.Builder) MBeanInfo(javax.management.MBeanInfo) ImmutableList(com.google.common.collect.ImmutableList) JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Aggregations

ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)1 ConnectorSession (com.facebook.presto.spi.ConnectorSession)1 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)1 ConnectorTableLayout (com.facebook.presto.spi.ConnectorTableLayout)1 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)1 ConnectorTableLayoutResult (com.facebook.presto.spi.ConnectorTableLayoutResult)1 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)1 Constraint (com.facebook.presto.spi.Constraint)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 SchemaTablePrefix (com.facebook.presto.spi.SchemaTablePrefix)1 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)1 BIGINT (com.facebook.presto.spi.type.BigintType.BIGINT)1 BOOLEAN (com.facebook.presto.spi.type.BooleanType.BOOLEAN)1 DOUBLE (com.facebook.presto.spi.type.DoubleType.DOUBLE)1 TIMESTAMP (com.facebook.presto.spi.type.TimestampType.TIMESTAMP)1 Type (com.facebook.presto.spi.type.Type)1 VarcharType.createUnboundedVarcharType (com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType)1 ImmutableList (com.google.common.collect.ImmutableList)1 Builder (com.google.common.collect.ImmutableList.Builder)1