service: Add objects for deserializing sstable_info json
Objects + serial logic to automate the transform of scylla REST json object for sstable_info into compositedata that can be consumed by nodetool
This commit is contained in:
parent
b2f3eeee05
commit
cb42205061
@ -0,0 +1,66 @@
|
||||
package org.apache.cassandra.service;
|
||||
|
||||
import static com.sun.jmx.mbeanserver.MXBeanMappingFactory.DEFAULT;
|
||||
|
||||
import java.io.InvalidObjectException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.openmbean.CompositeData;
|
||||
import javax.management.openmbean.OpenDataException;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.sun.jmx.mbeanserver.MXBeanMapping;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
@XmlRootElement
|
||||
public class PerTableSSTableInfo {
|
||||
private static final MXBeanMapping mxBeanMapping;
|
||||
|
||||
static {
|
||||
try {
|
||||
mxBeanMapping = DEFAULT.mappingForType(PerTableSSTableInfo.class, DEFAULT);
|
||||
} catch (OpenDataException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String keyspace;
|
||||
private List<SSTableInfo> sstables;
|
||||
private String table;
|
||||
|
||||
public String getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public void setTable(String table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
public String getKeyspace() {
|
||||
return keyspace;
|
||||
}
|
||||
|
||||
public void setKeyspace(String keyspace) {
|
||||
this.keyspace = keyspace;
|
||||
}
|
||||
|
||||
public List<SSTableInfo> getSSTables() {
|
||||
return sstables;
|
||||
}
|
||||
|
||||
public void setSSTableInfos(List<SSTableInfo> sstableInfos) {
|
||||
this.sstables = sstableInfos;
|
||||
}
|
||||
|
||||
public CompositeData toCompositeData() {
|
||||
try {
|
||||
return (CompositeData) mxBeanMapping.toOpenValue(this);
|
||||
} catch (OpenDataException e) {
|
||||
throw new Error(e); // should not reach.
|
||||
}
|
||||
}
|
||||
|
||||
public static PerTableSSTableInfo from(CompositeData data) throws InvalidObjectException {
|
||||
return (PerTableSSTableInfo) mxBeanMapping.fromOpenValue(data);
|
||||
}
|
||||
}
|
143
src/main/java/org/apache/cassandra/service/SSTableInfo.java
Normal file
143
src/main/java/org/apache/cassandra/service/SSTableInfo.java
Normal file
@ -0,0 +1,143 @@
|
||||
package org.apache.cassandra.service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.scylladb.jmx.utils.DateXmlAdapter;
|
||||
|
||||
public class SSTableInfo {
|
||||
private long size;
|
||||
|
||||
@JsonProperty("data_size")
|
||||
private long dataSize;
|
||||
|
||||
@JsonProperty("index_size")
|
||||
private long indexSize;
|
||||
|
||||
@JsonProperty("filter_size")
|
||||
private long filterSize;
|
||||
|
||||
@XmlJavaTypeAdapter(type = Date.class, value = DateXmlAdapter.class)
|
||||
private Date timestamp;
|
||||
|
||||
private long generation;
|
||||
|
||||
private long level;
|
||||
|
||||
private String version;
|
||||
|
||||
private Map<String, String> properties;
|
||||
|
||||
public void setProperties(Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
private Map<String, Map<String, String>> extendedProperties;
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public long getDataSize() {
|
||||
return dataSize;
|
||||
}
|
||||
|
||||
public void setDataSize(long dataSize) {
|
||||
this.dataSize = dataSize;
|
||||
}
|
||||
|
||||
public long getIndexSize() {
|
||||
return indexSize;
|
||||
}
|
||||
|
||||
public void setIndexSize(long indexSize) {
|
||||
this.indexSize = indexSize;
|
||||
}
|
||||
|
||||
public long getFilterSize() {
|
||||
return filterSize;
|
||||
}
|
||||
|
||||
public void setFilterSize(long filterSize) {
|
||||
this.filterSize = filterSize;
|
||||
}
|
||||
|
||||
public Date getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Date timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public long getGeneration() {
|
||||
return generation;
|
||||
}
|
||||
|
||||
public void setGeneration(long generation) {
|
||||
this.generation = generation;
|
||||
}
|
||||
|
||||
public long getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(long level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, String>> getExtendedProperties() {
|
||||
return extendedProperties;
|
||||
}
|
||||
|
||||
public void setExtendedProperties(Map<String, Map<String, String>> extendedProperties) {
|
||||
this.extendedProperties = extendedProperties;
|
||||
}
|
||||
|
||||
@JsonProperty("extended_properties")
|
||||
private void unpackNested(List<Map<String, Object>> properties) {
|
||||
Map<String, Map<String, String>> result = new HashMap<String, Map<String, String>>();
|
||||
|
||||
for (Map<String, Object> map : properties) {
|
||||
Object name = map.get("group");
|
||||
if (name != null) {
|
||||
Map<String, String> dst = new HashMap<>();
|
||||
List<?> value = (List<?>) map.get("attributes");
|
||||
for (Object v : value) {
|
||||
Map<?, ?> subMap = (Map<?, ?>) v;
|
||||
dst.put(String.valueOf(subMap.get("key")), String.valueOf(subMap.get("value")));
|
||||
}
|
||||
result.put(String.valueOf(name), dst);
|
||||
} else {
|
||||
for (Map.Entry<String, Object> e : map.entrySet()) {
|
||||
result.put(e.getKey(), Collections.singletonMap(String.valueOf(e.getValue()), ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
extendedProperties = result;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user