Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
HAWKULAR-455 Migrate gson library with jackson on hawkular/modules
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasponce committed Jul 20, 2015
1 parent 8ffd185 commit e8e5ee7
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
15 changes: 5 additions & 10 deletions modules/avail-creator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<version>1.1-rev-1</version> <!-- TODO move to parent -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand All @@ -59,11 +64,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version> <!-- TODO move to parent -->
</dependency>

<dependency>
<groupId>org.hawkular.bus</groupId>
Expand Down Expand Up @@ -99,11 +99,6 @@
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</artifactItem>
<artifactItem>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
import org.hawkular.bus.common.ObjectMessage;
import org.hawkular.bus.common.producer.ProducerConnectionContext;

import com.google.gson.Gson;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Publish Avail data
Expand Down Expand Up @@ -77,7 +78,12 @@ public void sendToMetricsViaRest(List<SingleAvail> availabilities) {
Availability availability = new Availability(avr.timestamp, avr.avail.toLowerCase());
List<Availability> list = new ArrayList<>(1);
list.add(availability);
String payload = new Gson().toJson(list);
String payload = null;
try {
payload = new ObjectMapper().writeValueAsString(list);
} catch (JsonProcessingException e) {
Log.LOG.eCouldNotParseMessage(e);
}
request.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ public interface Log extends BasicLogger {
@Message(id = 5103, value = "Could not handle a message from Hawkular Bus")
void eCouldNotHandleBusMessage(@Cause Exception e);

@LogMessage(level = Logger.Level.ERROR)
@Message(id = 5104, value = "Could not parse a message to json format")
void eCouldNotParseMessage(@Cause Throwable e);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import com.google.gson.GsonBuilder;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Receiver that listens on JMS Topic and checks for metrics *.status.code
Expand Down Expand Up @@ -67,16 +67,14 @@ public void onMessage(Message message) {

try {
String payload = ((TextMessage) message).getText();
Map map = new GsonBuilder().create().fromJson(payload, Map.class);
Map map = new ObjectMapper().readValue(payload, Map.class);

Map metricDataMap = (Map) map.get("metricData");
// Get <rid>.status.code metrics
String tenant = (String) metricDataMap.get("tenantId");
List<Map<String, Object>> inputList = (List<Map<String, Object>>) metricDataMap.get("data");
List<SingleAvail> outer = new ArrayList<>();

List<Availability> availabilityList = new ArrayList<>();

for (Map<String, Object> item : inputList) {

String source = (String) item.get("source");
Expand All @@ -85,8 +83,7 @@ public void onMessage(Message message) {
int code = (int) codeD;

String id = source.substring(0, source.indexOf("."));
double timestampD = (double) item.get("timestamp");
long timestamp = (long) timestampD;
long timestamp = (long) item.get("timestamp");

String avail = computeAvail(code);

Expand Down
17 changes: 6 additions & 11 deletions modules/pinger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down Expand Up @@ -110,12 +116,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${version.com.google.code.gson}</version> <!-- TODO move to parent -->
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -158,11 +158,6 @@
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${version.com.google.code.gson}</version>
</artifactItem>
<artifactItem>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,7 @@ public interface Log extends BasicLogger {
@Message(id = 5008, value = "IOException accessing Hawkular Metrics")
void eMetricsIoException(@Cause IOException e);

@LogMessage(level = Logger.Level.ERROR)
@Message(id = 5009, value = "Could not parse a message to json format")
void eCouldNotParseMessage(@Cause Throwable e);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/
package org.hawkular.component.pinger;

import com.google.gson.Gson;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
Expand Down Expand Up @@ -89,7 +90,12 @@ public void sendToMetricsViaRest(PingStatus status) {
addDataItem(mMetrics, resourceId, timestamp, status.getCode(), "code");

// Send it to metrics via rest
String payload = new Gson().toJson(mMetrics);
String payload = null;
try {
payload = new ObjectMapper().writeValueAsString(mMetrics);
} catch (JsonProcessingException e) {
Log.LOG.eCouldNotParseMessage(e);
}
HttpClient client = HttpClientBuilder.create().build();

HttpPost request = new HttpPost(configuration.getMetricsBaseUri() + "/gauges/data");
Expand Down

0 comments on commit e8e5ee7

Please sign in to comment.