net.opentsdb.tsd
public abstract class HttpSerializer extends Object
The serializer workflow is as follows:
initialize(net.opentsdb.core.TSDB)
method to instantiate thread-safe, static objects that
you need for de/serializtion. It will be called once on TSD startup.
Note: If a method needs to throw an exception due to user error, such
as missing data or a bad request, throw a BadRequestException
with
a status code, error message and optional details.
Runtime exceptions, anything that goes wrong internally with your serializer, will be returned with a 500 Internal Server Error status.
Note: You can change the HTTP status code before returning from a
"formatX" method by accessing "this.query.response().setStatus()" and
providing an HttpResponseStatus
object.
Note: You can also set response headers via "this.query.response().setHeader()". The "Content-Type" header will be set automatically with the "response_content_type" field value that can be overridden by the plugin. HttpQuery will also set some other headers before returning
Modifier and Type | Field and Description |
---|---|
protected net.opentsdb.tsd.HttpQuery |
query
The query used for accessing the DefaultHttpResponse object and other
information
|
protected String |
request_content_type
Content type to use for matching a serializer to incoming requests
|
protected String |
response_content_type
Content type to return with data from this serializer
|
Constructor and Description |
---|
HttpSerializer()
Empty constructor required for plugin operation
|
HttpSerializer(net.opentsdb.tsd.HttpQuery query)
Constructor that serializers must implement.
|
Modifier and Type | Method and Description |
---|---|
org.jboss.netty.buffer.ChannelBuffer |
formatAggregatorsV1(Set<String> aggregators)
Format the list of implemented aggregators
|
org.jboss.netty.buffer.ChannelBuffer |
formatAnnotationV1(Annotation note)
Format an annotation object
|
org.jboss.netty.buffer.ChannelBuffer |
formatBranchV1(Branch branch)
Format a single Branch object
|
org.jboss.netty.buffer.ChannelBuffer |
formatConfigV1(Config config)
Format the running configuration
|
org.jboss.netty.buffer.ChannelBuffer |
formatDropCachesV1(Map<String,String> response)
Format a response from the DropCaches call
|
org.jboss.netty.buffer.ChannelBuffer |
formatErrorV1(net.opentsdb.tsd.BadRequestException exception)
Format a bad request exception, indicating an invalid request from the
user
|
org.jboss.netty.buffer.ChannelBuffer |
formatErrorV1(Exception exception)
Format an internal error exception that was caused by the system
Should return a 500 error
|
org.jboss.netty.buffer.ChannelBuffer |
formatNotFoundV1()
Formats a 404 error when an endpoint or file wasn't found
|
org.jboss.netty.buffer.ChannelBuffer |
formatPutV1(Map<String,Object> results)
Formats the results of an HTTP data point storage request
|
org.jboss.netty.buffer.ChannelBuffer |
formatQueryV1(TSQuery query,
List<DataPoints[]> results,
List<Annotation> globals)
Format the results from a timeseries data query
|
org.jboss.netty.buffer.ChannelBuffer |
formatSearchResultsV1(SearchQuery results)
Format the response from a search query
|
org.jboss.netty.buffer.ChannelBuffer |
formatSerializersV1()
Format the serializers status map
|
org.jboss.netty.buffer.ChannelBuffer |
formatStatsV1(List<IncomingDataPoint> stats)
Format a list of statistics
|
org.jboss.netty.buffer.ChannelBuffer |
formatSuggestV1(List<String> suggestions)
Formats a suggestion response
|
org.jboss.netty.buffer.ChannelBuffer |
formatTreeCollisionNotMatchedV1(Map<String,String> results,
boolean is_collisions)
Format a map of one or more TSUIDs that collided or were not matched
|
org.jboss.netty.buffer.ChannelBuffer |
formatTreeRuleV1(TreeRule rule)
Format a single TreeRule object
|
org.jboss.netty.buffer.ChannelBuffer |
formatTreesV1(List<Tree> trees)
Format a list of tree objects.
|
org.jboss.netty.buffer.ChannelBuffer |
formatTreeTestV1(HashMap<String,HashMap<String,Object>> results)
Format the results of testing one or more TSUIDs through a tree's ruleset
|
org.jboss.netty.buffer.ChannelBuffer |
formatTreeV1(Tree tree)
Format a single tree object
|
org.jboss.netty.buffer.ChannelBuffer |
formatTSMetaV1(TSMeta meta)
Format a single TSMeta object
|
org.jboss.netty.buffer.ChannelBuffer |
formatUidAssignV1(Map<String,TreeMap<String,String>> response)
Format a response from the Uid Assignment RPC
|
org.jboss.netty.buffer.ChannelBuffer |
formatUidMetaV1(UIDMeta meta)
Format a single UIDMeta object
|
org.jboss.netty.buffer.ChannelBuffer |
formatVersionV1(Map<String,String> version)
Format a hash map of information about the OpenTSDB version
|
abstract void |
initialize(TSDB tsdb)
Initializer called one time when the TSD starts up and loads serializer
plugins.
|
Annotation |
parseAnnotationV1()
Parses an annotation object
|
List<IncomingDataPoint> |
parsePutV1()
Parses one or more data points for storage
|
TSQuery |
parseQueryV1()
Parses a timeseries data query
|
SearchQuery |
parseSearchQueryV1()
Parses a SearchQuery request
|
HashMap<String,String> |
parseSuggestV1()
Parses a suggestion query
|
List<TreeRule> |
parseTreeRulesV1()
Parses one or more tree rules
|
TreeRule |
parseTreeRuleV1()
Parses a single TreeRule object
|
Map<String,Object> |
parseTreeTSUIDsListV1()
Parses a tree ID and optional list of TSUIDs to search for collisions or
not matched TSUIDs.
|
Tree |
parseTreeV1()
Parses a single Tree object
|
TSMeta |
parseTSMetaV1()
Parses a single TSMeta object
|
HashMap<String,List<String>> |
parseUidAssignV1()
Parses a list of metrics, tagk and/or tagvs to assign UIDs to
|
UIDMeta |
parseUidMetaV1()
Parses a single UIDMeta object
|
String |
requestContentType() |
String |
responseContentType() |
abstract String |
shortName()
The simple name for this serializer referenced by users.
|
abstract com.stumbleupon.async.Deferred<Object> |
shutdown()
Called when the TSD is shutting down so implementations can gracefully
close their objects or connections if necessary
|
abstract String |
version()
The version of this serializer plugin in the format "MAJOR.MINOR.MAINT"
The MAJOR version should match the major version of OpenTSDB, e.g.
|
protected String request_content_type
protected String response_content_type
protected final net.opentsdb.tsd.HttpQuery query
public HttpSerializer()
public HttpSerializer(net.opentsdb.tsd.HttpQuery query)
Note: A new serializer is instantiated for every HTTP connection, so
don't do any heavy object creation here. Instead, use the
initialize(net.opentsdb.core.TSDB)
method to setup static, thread-safe objects if you
need stuff like that
query
- public abstract void initialize(TSDB tsdb)
tsdb
- The TSD this plugin belongs to. Use it to fetch config data
if require.public abstract com.stumbleupon.async.Deferred<Object> shutdown()
public abstract String version()
public abstract String shortName()
public String requestContentType()
public String responseContentType()
public List<IncomingDataPoint> parsePutV1()
BadRequestException
- if the plugin has not implemented this methodpublic HashMap<String,String> parseSuggestV1()
BadRequestException
- if the plugin has not implemented this methodpublic HashMap<String,List<String>> parseUidAssignV1()
BadRequestException
- if the plugin has not implemented this methodpublic SearchQuery parseSearchQueryV1()
BadRequestException
- if the plugin has not implemented this methodpublic TSQuery parseQueryV1()
BadRequestException
- if the plugin has not implemented this methodpublic UIDMeta parseUidMetaV1()
BadRequestException
- if the plugin has not implemented this methodpublic TSMeta parseTSMetaV1()
BadRequestException
- if the plugin has not implemented this methodpublic Tree parseTreeV1()
BadRequestException
- if the plugin has not implemented this methodpublic TreeRule parseTreeRuleV1()
BadRequestException
- if the plugin has not implemented this methodpublic List<TreeRule> parseTreeRulesV1()
BadRequestException
- if the plugin has not implemented this methodpublic Map<String,Object> parseTreeTSUIDsListV1()
BadRequestException
- if the plugin has not implemented this methodpublic Annotation parseAnnotationV1()
BadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatPutV1(Map<String,Object> results)
results
- A map of results. The map will consist of:
BadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatSuggestV1(List<String> suggestions)
suggestions
- List of suggestions for the given typeBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatSerializersV1()
BadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatAggregatorsV1(Set<String> aggregators)
aggregators
- The list of aggregation functionsBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatVersionV1(Map<String,String> version)
version
- A hash map with version informationBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatDropCachesV1(Map<String,String> response)
response
- A hash map with a responseBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatUidAssignV1(Map<String,TreeMap<String,String>> response)
response
- A map of lists of pairs representing the results of the
assignmentBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatQueryV1(TSQuery query, List<DataPoints[]> results, List<Annotation> globals)
query
- The TSQuery object used to fetch the resultsresults
- The data fetched from storageglobals
- An optional list of global annotation objectsBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatUidMetaV1(UIDMeta meta)
meta
- The UIDMeta object to serializeBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatTSMetaV1(TSMeta meta)
meta
- The TSMeta object to serializeBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatBranchV1(Branch branch)
branch
- The branch to serializeBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatTreeV1(Tree tree)
tree
- tree to serializeBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatTreesV1(List<Tree> trees)
trees
- A list of one or more trees to serializeBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatTreeRuleV1(TreeRule rule)
rule
- The rule to serializeBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatTreeCollisionNotMatchedV1(Map<String,String> results, boolean is_collisions)
results
- The list of results. Collisions: key = tsuid, value =
collided TSUID. Not Matched: key = tsuid, value = message about non matched
rules.is_collisions
- Whether or the map is a collision result set (true) or
a not matched set (false).BadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatTreeTestV1(HashMap<String,HashMap<String,Object>> results)
results
- The list of results. Main map key is the tsuid. Child map:
"branch" : Parsed branch result, may be null
"meta" : TSMeta object, may be null
"messages" : An ArrayListBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatAnnotationV1(Annotation note)
note
- The annotation object to formatBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatStatsV1(List<IncomingDataPoint> stats)
stats
- The statistics list to formatBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatSearchResultsV1(SearchQuery results)
results
- The query (hopefully filled with results) to serializeBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatConfigV1(Config config)
config
- The running config to serializeBadRequestException
- if the plugin has not implemented this methodpublic org.jboss.netty.buffer.ChannelBuffer formatNotFoundV1()
WARNING: If overriding, make sure this method catches all errors and returns a byte array with a simple string error at the minimum
public org.jboss.netty.buffer.ChannelBuffer formatErrorV1(net.opentsdb.tsd.BadRequestException exception)
WARNING: If overriding, make sure this method catches all errors and returns a byte array with a simple string error at the minimum
exception
- The exception to formatpublic org.jboss.netty.buffer.ChannelBuffer formatErrorV1(Exception exception)
WARNING: If overriding, make sure this method catches all errors and returns a byte array with a simple string error at the minimum
exception
- The system exception to format