Skip to content

Commit

Permalink
Remove connector ID from JMX connector
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Jan 17, 2017
1 parent ab77920 commit 944117f
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 77 deletions.
Expand Up @@ -27,27 +27,18 @@
public class JmxColumnHandle
implements ColumnHandle
{
private final String connectorId;
private final String columnName;
private final Type columnType;

@JsonCreator
public JmxColumnHandle(
@JsonProperty("connectorId") String connectorId,
@JsonProperty("columnName") String columnName,
@JsonProperty("columnType") Type columnType)
{
this.connectorId = requireNonNull(connectorId, "connectorId is null");
this.columnName = requireNonNull(columnName, "columnName is null");
this.columnType = requireNonNull(columnType, "columnType is null");
}

@JsonProperty
public String getConnectorId()
{
return connectorId;
}

@JsonProperty
public String getColumnName()
{
Expand All @@ -63,7 +54,7 @@ public Type getColumnType()
@Override
public int hashCode()
{
return Objects.hash(connectorId, columnName, columnType);
return Objects.hash(columnName, columnType);
}

@Override
Expand All @@ -76,16 +67,14 @@ public boolean equals(Object obj)
return false;
}
JmxColumnHandle other = (JmxColumnHandle) obj;
return Objects.equals(this.connectorId, other.connectorId) &&
Objects.equals(this.columnName, other.columnName) &&
return Objects.equals(this.columnName, other.columnName) &&
Objects.equals(this.columnType, other.columnType);
}

@Override
public String toString()
{
return toStringHelper(this)
.add("connectorId", connectorId)
.add("columnName", columnName)
.add("columnType", columnType)
.toString();
Expand Down
Expand Up @@ -27,8 +27,6 @@
public class JmxConnector
implements Connector
{
public static final String CONNECTOR_ID_PARAMETER = "jmx.connectorId";

private static final Logger log = Logger.get(JmxConnector.class);

private final JmxMetadata jmxMetadata;
Expand Down
Expand Up @@ -22,7 +22,6 @@
import com.google.common.base.Throwables;
import com.google.inject.Injector;
import com.google.inject.Scopes;
import com.google.inject.name.Names;
import io.airlift.bootstrap.Bootstrap;

import javax.management.MBeanServer;
Expand Down Expand Up @@ -63,7 +62,6 @@ public Connector create(String connectorId, Map<String, String> config, Connecto
configBinder(binder).bindConfig(JmxConnectorConfig.class);
binder.bind(MBeanServer.class).toInstance(new RebindSafeMBeanServer(mbeanServer));
binder.bind(NodeManager.class).toInstance(context.getNodeManager());
binder.bind(String.class).annotatedWith(Names.named(JmxConnector.CONNECTOR_ID_PARAMETER)).toInstance(connectorId);
binder.bind(JmxConnector.class).in(Scopes.SINGLETON);
binder.bind(JmxHistoricalData.class).in(Scopes.SINGLETON);
binder.bind(JmxMetadata.class).in(Scopes.SINGLETON);
Expand Down
Expand Up @@ -30,7 +30,6 @@
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.inject.name.Named;

import javax.inject.Inject;
import javax.management.JMException;
Expand Down Expand Up @@ -64,17 +63,12 @@ public class JmxMetadata
public static final String NODE_COLUMN_NAME = "node";
public static final String TIMESTAMP_COLUMN_NAME = "timestamp";

private final String connectorId;
private final MBeanServer mbeanServer;
private final JmxHistoricalData jmxHistoricalData;

@Inject
public JmxMetadata(
@Named(JmxConnector.CONNECTOR_ID_PARAMETER) String connectorId,
MBeanServer mbeanServer,
JmxHistoricalData jmxHistoricalData)
public JmxMetadata(MBeanServer mbeanServer, JmxHistoricalData jmxHistoricalData)
{
this.connectorId = requireNonNull(connectorId, "connectorId is null");
this.mbeanServer = requireNonNull(mbeanServer, "mbeanServer is null");
this.jmxHistoricalData = requireNonNull(jmxHistoricalData, "jmxStatsHolder is null");
}
Expand Down Expand Up @@ -110,9 +104,9 @@ private JmxTableHandle getJmxHistoryTableHandle(SchemaTableName tableName)
return null;
}
ImmutableList.Builder<JmxColumnHandle> builder = ImmutableList.builder();
builder.add(new JmxColumnHandle(connectorId, TIMESTAMP_COLUMN_NAME, TIMESTAMP));
builder.add(new JmxColumnHandle(TIMESTAMP_COLUMN_NAME, TIMESTAMP));
builder.addAll(handle.getColumnHandles());
return new JmxTableHandle(connectorId, handle.getObjectName(), builder.build(), false);
return new JmxTableHandle(handle.getObjectName(), builder.build(), false);
}

private JmxTableHandle getJmxTableHandle(SchemaTableName tableName)
Expand All @@ -128,17 +122,17 @@ private JmxTableHandle getJmxTableHandle(SchemaTableName tableName)
MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName.get());

ImmutableList.Builder<JmxColumnHandle> columns = ImmutableList.builder();
columns.add(new JmxColumnHandle(connectorId, NODE_COLUMN_NAME, createUnboundedVarcharType()));
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(connectorId, attribute.getName(), getColumnType(attribute)))
.map(attribute -> new JmxColumnHandle(attribute.getName(), getColumnType(attribute)))
.sorted((column1, column2) -> column1.getColumnName().compareTo(column2.getColumnName()))
.forEach(columns::add);

return new JmxTableHandle(connectorId, objectName.get().toString(), columns.build(), true);
return new JmxTableHandle(objectName.get().toString(), columns.build(), true);
}
catch (JMException e) {
return null;
Expand Down
Expand Up @@ -30,36 +30,21 @@
public class JmxTableHandle
implements ConnectorTableHandle
{
private final String connectorId;
private final String objectName;
private final List<JmxColumnHandle> columnHandles;
private final boolean liveData;

@Deprecated
public JmxTableHandle(String connectorId, String objectName, List<JmxColumnHandle> columnHandles)
{
this(connectorId, objectName, columnHandles, true);
}

@JsonCreator
public JmxTableHandle(
@JsonProperty("connectorId") String connectorId,
@JsonProperty("objectName") String objectName,
@JsonProperty("columnHandles") List<JmxColumnHandle> columnHandles,
@JsonProperty("liveData") boolean liveData)
{
this.connectorId = requireNonNull(connectorId, "connectorId is null");
this.objectName = requireNonNull(objectName, "objectName is null");
this.columnHandles = ImmutableList.copyOf(requireNonNull(columnHandles, "columnHandles is null"));
this.liveData = liveData;
}

@JsonProperty
public String getConnectorId()
{
return connectorId;
}

@JsonProperty
public String getObjectName()
{
Expand All @@ -81,7 +66,7 @@ public boolean isLiveData()
@Override
public int hashCode()
{
return Objects.hash(connectorId, objectName, columnHandles, liveData);
return Objects.hash(objectName, columnHandles, liveData);
}

@Override
Expand All @@ -94,8 +79,7 @@ public boolean equals(Object obj)
return false;
}
JmxTableHandle other = (JmxTableHandle) obj;
return Objects.equals(this.connectorId, other.connectorId) &&
Objects.equals(this.objectName, other.objectName) &&
return Objects.equals(this.objectName, other.objectName) &&
Objects.equals(this.columnHandles, other.columnHandles) &&
Objects.equals(this.liveData, other.liveData);
}
Expand All @@ -104,7 +88,6 @@ public boolean equals(Object obj)
public String toString()
{
return toStringHelper(this)
.add("connectorId", connectorId)
.add("objectName", objectName)
.add("columnHandles", columnHandles)
.add("liveData", liveData)
Expand Down
Expand Up @@ -26,7 +26,7 @@ public class TestJmxColumnHandle
@Test
public void testJsonRoundTrip()
{
JmxColumnHandle handle = new JmxColumnHandle("connectorId", "columnName", createUnboundedVarcharType());
JmxColumnHandle handle = new JmxColumnHandle("columnName", createUnboundedVarcharType());
String json = COLUMN_CODEC.toJson(handle);
JmxColumnHandle copy = COLUMN_CODEC.fromJson(json);
assertEquals(copy, handle);
Expand All @@ -37,17 +37,14 @@ public void testEquivalence()
{
EquivalenceTester.equivalenceTester()
.addEquivalentGroup(
new JmxColumnHandle("connectorId", "columnName", createUnboundedVarcharType()),
new JmxColumnHandle("connectorId", "columnName", createUnboundedVarcharType()))
new JmxColumnHandle("columnName", createUnboundedVarcharType()),
new JmxColumnHandle("columnName", createUnboundedVarcharType()))
.addEquivalentGroup(
new JmxColumnHandle("connectorIdX", "columnName", createUnboundedVarcharType()),
new JmxColumnHandle("connectorIdX", "columnName", createUnboundedVarcharType()))
new JmxColumnHandle("columnNameX", createUnboundedVarcharType()),
new JmxColumnHandle("columnNameX", createUnboundedVarcharType()))
.addEquivalentGroup(
new JmxColumnHandle("connectorId", "columnNameX", createUnboundedVarcharType()),
new JmxColumnHandle("connectorId", "columnNameX", createUnboundedVarcharType()))
.addEquivalentGroup(
new JmxColumnHandle("connectorId", "columnName", BIGINT),
new JmxColumnHandle("connectorId", "columnName", BIGINT))
new JmxColumnHandle("columnName", BIGINT),
new JmxColumnHandle("columnName", BIGINT))
.check();
}
}
Expand Up @@ -37,7 +37,7 @@ public class TestJmxMetadata
private static final SchemaTableName RUNTIME_TABLE = new SchemaTableName(JMX_SCHEMA_NAME, RUNTIME_OBJECT.toLowerCase(ENGLISH));
private static final SchemaTableName RUNTIME_HISTORY_TABLE = new SchemaTableName(HISTORY_SCHEMA_NAME, RUNTIME_OBJECT.toLowerCase(ENGLISH));

private final JmxMetadata metadata = new JmxMetadata("test", getPlatformMBeanServer(), new JmxHistoricalData(1000, ImmutableSet.of(RUNTIME_OBJECT.toLowerCase())));
private final JmxMetadata metadata = new JmxMetadata(getPlatformMBeanServer(), new JmxHistoricalData(1000, ImmutableSet.of(RUNTIME_OBJECT.toLowerCase())));

@Test
public void testListSchemas()
Expand All @@ -58,27 +58,25 @@ public void testGetTableHandle()
throws Exception
{
JmxTableHandle handle = metadata.getTableHandle(SESSION, RUNTIME_TABLE);
assertEquals(handle.getConnectorId(), "test");
assertEquals(handle.getObjectName(), RUNTIME_OBJECT);

List<JmxColumnHandle> columns = handle.getColumnHandles();
assertTrue(columns.contains(new JmxColumnHandle("test", "node", createUnboundedVarcharType())));
assertTrue(columns.contains(new JmxColumnHandle("test", "Name", createUnboundedVarcharType())));
assertTrue(columns.contains(new JmxColumnHandle("test", "StartTime", BIGINT)));
assertTrue(columns.contains(new JmxColumnHandle("node", createUnboundedVarcharType())));
assertTrue(columns.contains(new JmxColumnHandle("Name", createUnboundedVarcharType())));
assertTrue(columns.contains(new JmxColumnHandle("StartTime", BIGINT)));
}

@Test
public void testGetTimeTableHandle()
throws Exception
{
JmxTableHandle handle = metadata.getTableHandle(SESSION, RUNTIME_HISTORY_TABLE);
assertEquals(handle.getConnectorId(), "test");
assertEquals(handle.getObjectName(), RUNTIME_OBJECT);

List<JmxColumnHandle> columns = handle.getColumnHandles();
assertTrue(columns.contains(new JmxColumnHandle("test", "timestamp", TIMESTAMP)));
assertTrue(columns.contains(new JmxColumnHandle("test", "node", createUnboundedVarcharType())));
assertTrue(columns.contains(new JmxColumnHandle("test", "Name", createUnboundedVarcharType())));
assertTrue(columns.contains(new JmxColumnHandle("test", "StartTime", BIGINT)));
assertTrue(columns.contains(new JmxColumnHandle("timestamp", TIMESTAMP)));
assertTrue(columns.contains(new JmxColumnHandle("node", createUnboundedVarcharType())));
assertTrue(columns.contains(new JmxColumnHandle("Name", createUnboundedVarcharType())));
assertTrue(columns.contains(new JmxColumnHandle("StartTime", BIGINT)));
}
}
Expand Up @@ -82,8 +82,8 @@ public NodeManager getNodeManager()
}
});

private final JmxColumnHandle columnHandle = new JmxColumnHandle("test", "node", createUnboundedVarcharType());
private final JmxTableHandle tableHandle = new JmxTableHandle("test", "objectName", ImmutableList.of(columnHandle), true);
private final JmxColumnHandle columnHandle = new JmxColumnHandle("node", createUnboundedVarcharType());
private final JmxTableHandle tableHandle = new JmxTableHandle("objectName", ImmutableList.of(columnHandle), true);

private final JmxSplitManager splitManager = jmxConnector.getSplitManager();
private final JmxMetadata metadata = jmxConnector.getMetadata(new ConnectorTransactionHandle() {});
Expand Down
Expand Up @@ -27,10 +27,10 @@
public class TestJmxTableHandle
{
public static final List<JmxColumnHandle> COLUMNS = ImmutableList.<JmxColumnHandle>builder()
.add(new JmxColumnHandle("connectorId", "id", BIGINT))
.add(new JmxColumnHandle("connectorId", "name", createUnboundedVarcharType()))
.add(new JmxColumnHandle("id", BIGINT))
.add(new JmxColumnHandle("name", createUnboundedVarcharType()))
.build();
public static final JmxTableHandle TABLE = new JmxTableHandle("connectorId", "objectName", COLUMNS);
public static final JmxTableHandle TABLE = new JmxTableHandle("objectName", COLUMNS, true);

@Test
public void testJsonRoundTrip()
Expand All @@ -45,10 +45,24 @@ public void testEquivalence()
{
List<JmxColumnHandle> singleColumn = ImmutableList.of(COLUMNS.get(0));
EquivalenceTester.equivalenceTester()
.addEquivalentGroup(new JmxTableHandle("connector", "name", COLUMNS), new JmxTableHandle("connector", "name", COLUMNS))
.addEquivalentGroup(new JmxTableHandle("connectorX", "name", COLUMNS), new JmxTableHandle("connectorX", "name", COLUMNS))
.addEquivalentGroup(new JmxTableHandle("connector", "nameX", COLUMNS), new JmxTableHandle("connector", "nameX", COLUMNS))
.addEquivalentGroup(new JmxTableHandle("connector", "name", singleColumn), new JmxTableHandle("connector", "name", singleColumn))
.addEquivalentGroup(
new JmxTableHandle("name", COLUMNS, true),
new JmxTableHandle("name", COLUMNS, true))
.addEquivalentGroup(
new JmxTableHandle("name", COLUMNS, false),
new JmxTableHandle("name", COLUMNS, false))
.addEquivalentGroup(
new JmxTableHandle("nameX", COLUMNS, true),
new JmxTableHandle("nameX", COLUMNS, true))
.addEquivalentGroup(
new JmxTableHandle("nameX", COLUMNS, false),
new JmxTableHandle("nameX", COLUMNS, false))
.addEquivalentGroup(
new JmxTableHandle("name", singleColumn, true),
new JmxTableHandle("name", singleColumn, true))
.addEquivalentGroup(
new JmxTableHandle("name", singleColumn, false),
new JmxTableHandle("name", singleColumn, false))
.check();
}
}

0 comments on commit 944117f

Please sign in to comment.