result set

This commit is contained in:
jackdaw@loafle.com 2017-04-26 11:54:43 +09:00
parent 0aef8f100b
commit a647c230e1
8 changed files with 152 additions and 37 deletions

View File

@ -8,30 +8,31 @@ import java.util.Map;
*/
public class Item {
List<String> metrics;
List<String> keys;
Map<String,Object> queryInfo;
private List<Keys> keys;
private QueryInfo queryInfo;
private MappingInfo mappingInfo;
public List<String> getMetrics() {
return metrics;
}
public void setMetrics(List<String> metrics) {
this.metrics = metrics;
}
public List<String> getKeys() {
public List<Keys> getKeys() {
return keys;
}
public void setKeys(List<String> keys) {
public void setKeys(List<Keys> keys) {
this.keys = keys;
}
public Map<String, Object> getQueryInfo() {
public QueryInfo getQueryInfo() {
return queryInfo;
}
public void setQueryInfo(Map<String, Object> queryInfo) {
public void setQueryInfo(QueryInfo queryInfo) {
this.queryInfo = queryInfo;
}
public MappingInfo getMappingInfo() {
return mappingInfo;
}
public void setMappingInfo(MappingInfo mappingInfo) {
this.mappingInfo = mappingInfo;
}
}

View File

@ -0,0 +1,26 @@
package com.loafle.overflow.crawler.config;
/**
* Created by root on 17. 4. 26.
*/
public class Keys {
private String metric;
private String key;
public String getMetric() {
return metric;
}
public void setMetric(String metric) {
this.metric = metric;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}

View File

@ -0,0 +1,46 @@
package com.loafle.overflow.crawler.config;
import java.util.List;
/**
* Created by root on 17. 4. 26.
*/
public class MappingInfo {
private String parseDirection;
private List<String> arrayColumns;
private List<String> keyColumns;
private String valueColumn;
public String getParseDirection() {
return parseDirection;
}
public void setParseDirection(String parseDirection) {
this.parseDirection = parseDirection;
}
public List<String> getArrayColumns() {
return arrayColumns;
}
public void setArrayColumns(List<String> arrayColumns) {
this.arrayColumns = arrayColumns;
}
public List<String> getKeyColumns() {
return keyColumns;
}
public void setKeyColumns(List<String> keyColumns) {
this.keyColumns = keyColumns;
}
public String getValueColumn() {
return valueColumn;
}
public void setValueColumn(String valueColumn) {
this.valueColumn = valueColumn;
}
}

View File

@ -0,0 +1,27 @@
package com.loafle.overflow.crawler.config;
import java.util.Map;
/**
* Created by root on 17. 4. 26.
*/
public class QueryInfo {
private String query;
private Map<String,String> extend;
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
public Map<String, String> getExtend() {
return extend;
}
public void setExtend(Map<String, String> extend) {
this.extend = extend;
}
}

View File

@ -42,7 +42,7 @@ public abstract class OFResultSet {
// methods
static public OFResultSet newInstance(Item item) {
String type = (String) item.getQueryInfo().get("parseDirection");
String type = (String) item.getMappingInfo().getParseDirection();
if (type != null && type.equals("row")) {
return new OFResultSetRow(item);
} else {

View File

@ -1,6 +1,7 @@
package com.loafle.overflow.crawler.result;
import com.loafle.overflow.crawler.config.Item;
import com.loafle.overflow.crawler.config.Keys;
import java.util.*;
@ -16,15 +17,15 @@ public class OFResultSetCol extends OFResultSet{
public void setMeta() {
List<String> meta = this.item.getKeys();
List<String> arrayColumns = (List<String>)this.item.getQueryInfo().get("arrayColumns");
List<Keys> meta = this.item.getKeys();
List<String> arrayColumns = (List<String>)this.item.getMappingInfo().getArrayColumns();
if(this.meta == null) {
this.meta = new HashMap<>();
}
for(int indexI = 0; indexI < meta.size(); ++indexI) {
this.meta.put(meta.get(indexI), indexI);
this.meta.put(meta.get(indexI).getKey(), indexI);
}
if( arrayColumns != null) {
@ -39,8 +40,8 @@ public class OFResultSetCol extends OFResultSet{
public Map<String, String> parse() {
List<String> metrics = this.item.getMetrics();
List<String> arrayColumns = (List<String>)this.item.getQueryInfo().get("arrayColumns");
List<Keys> metrics = this.item.getKeys();
List<String> arrayColumns = (List<String>)this.item.getMappingInfo().getArrayColumns();
// this.meta
Map<String, String> resultMap = new HashMap<>();
@ -72,7 +73,7 @@ public class OFResultSetCol extends OFResultSet{
for(int indexK = 0 ; indexK < metrics.size(); ++indexK) {
metric = metrics.get(indexK);
metric = metrics.get(indexK).getMetric();
metric = convertMetric(metric, arrayValue);

View File

@ -1,6 +1,7 @@
package com.loafle.overflow.crawler.result;
import com.loafle.overflow.crawler.config.Item;
import com.loafle.overflow.crawler.config.Keys;
import java.util.ArrayList;
import java.util.HashMap;
@ -21,9 +22,9 @@ public class OFResultSetRow extends OFResultSet{
List<String> meta = new ArrayList<>();
List<String> arrayColumns = (List<String>) this.item.getQueryInfo().get("arrayColumns");
List<String> keyColumns = (List<String>) this.item.getQueryInfo().get("keyColumns");
String valueColumn = (String) this.item.getQueryInfo().get("valueColumn");
List<String> arrayColumns = (List<String>) this.item.getMappingInfo().getArrayColumns();
List<String> keyColumns = (List<String>) this.item.getMappingInfo().getKeyColumns();
String valueColumn = (String) this.item.getMappingInfo().getValueColumn();
if (arrayColumns != null) {
for (String c : arrayColumns) {
meta.add(c);
@ -53,7 +54,7 @@ public class OFResultSetRow extends OFResultSet{
Map<String, String> returnMap = new HashMap<>();
String valueColumn = (String) this.item.getQueryInfo().get("valueColumn");
String valueColumn = (String) this.item.getMappingInfo().getValueColumn();
for (List<String> row : this.rows) {
String key = makeKey(row);
@ -65,11 +66,11 @@ public class OFResultSetRow extends OFResultSet{
private String makeKey(List<String> data) {
List<String> metrics = this.item.getMetrics();
List<Keys> metrics = this.item.getKeys();
List<String> arrayColumns = (List<String>) this.item.getQueryInfo().get("arrayColumns");
List<String> keyColumns = (List<String>) this.item.getQueryInfo().get("keyColumns");
List<String> keys = this.item.getKeys();
List<String> arrayColumns = (List<String>) this.item.getMappingInfo().getArrayColumns();
List<String> keyColumns = (List<String>) this.item.getMappingInfo().getKeyColumns();
List<Keys> keys = this.item.getKeys();
boolean find = false;
int findIndex = -1;
@ -85,7 +86,7 @@ public class OFResultSetRow extends OFResultSet{
if (find == true) {break;}
}
String metric = metrics.get(findIndex);
String metric = metrics.get(findIndex).getMetric();
if (arrayColumns != null) {
for (int i =0 ; i< arrayColumns.size() ; ++i) {

View File

@ -20,15 +20,28 @@
},
"items" : [
{
"query":
"keys" : [
{
"queryInfo" : {
"query" : "show session status",
"direction" : "col"
"metric" : "object[$0].db[$1].datafile_size",
"key" : "Data File(s) Size (KB)"
},
"keys" : []
{
"metric" : "object[$0].db[$1].logfile_size",
"key" : "Log File(s) Size (KB)"
}
],
"queryInfo" : {
"query": "select object_name,instance_name, counter_name, cntr_value from sys.dm_os_performance_counters where ( counter_name = 'Data File(s) Size (KB)' or counter_name = 'Log File(s) Size (KB)' ) AND object_name = 'SQLServer:Databases'",
"extend" : {
"command":""
}
},
"mappingInfo" : {
"parseDirection" : "row",
"arrayColumns" : [ "object_name","instance_name"],
"keyColumns" : ["counter_name"],
"valueColumn" : "cntr_value"
}
}
]
}