private String[] buildMembersValues(final List<? extends EventMessage> pendingEvents) { final String[] members = new String[pendingEvents.size()]; int i = 0; for (final EventMessage eventMessage : pendingEvents) { members[i] = converter.marshal(eventMessage); i++; } return members; } }
public void onMessage(final Message message, final byte[] pattern) { final String info = getInfo(message); final String channel = getChannel(message); LOGGER.debug("{} --> Received message on channel {}", name, channel); LOGGER.debug("{} --> Message content {}", name, info); try { // The received message corresponds to a JSON representation of an object of type // EventMessage. final EventMessage eventMessage = (EventMessage) eventConverter.unmarshal(info, EventMessage.class); doWithMessage(eventMessage); } catch (final MessageNotWritableException mnwe) { LOGGER.error("Error unmarshalling message: {}. ", info, mnwe); } }
private void updateRedeliveryFields(final NotificationRetryEvent notificationRetryEvent) { final String currentEntity = notificationRetryEvent.getNotificationDeliveryContext().getEntity(); notificationRetryEvent.incrementRetryCount(); notificationRetryEvent.getNotificationDeliveryContext().setEntity(currentEntity + "_RetryProcessor"); final EventMessage eventMessage = (EventMessage) converter.unmarshal(notificationRetryEvent.getMessage(), EventMessage.class); eventMessage.setRetryAttempt(notificationRetryEvent.getRetryCount()); notificationRetryEvent.setMessage(converter.marshal(eventMessage)); } }
/** * Returns the body associated with the bulk call * * @param eventsToProcess * @return */ private String buildBody(final List<EventMessage> eventsToProcess) { final StringBuilder sb = new StringBuilder(); for (final EventMessage event : eventsToProcess) { sb.append("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_type\" : \"" + event.getType().toLowerCase() + "\" }}"); sb.append("\n"); sb.append(converter.marshal(event)); sb.append("\n"); } return sb.toString(); }
@Override public PlatformStatsMessage getCurrentPlatformStats() { final RequestContext rc = new RequestContext("admin/stats"); final String response = restClient.get(rc); return (PlatformStatsMessage) parser.unmarshal(response, PlatformStatsMessage.class); }
/** * Returns the body associated with the bulk call * * @param eventsToProcess * @return */ private String buildBody(final List<EventMessage> eventsToProcess) { final List<OpenTSDBDataPoint> dataPoints = new ArrayList<OpenTSDBDataPoint>(); for (final EventMessage event : eventsToProcess) { try { final OpenTSDBDataPoint dataPoint = OpenTSDBDataPointMarshaller.unmarshal(event); dataPoints.add(dataPoint); } catch (final ParseException pe) { LOGGER.error("Got error when trying to parse an event message: {}. EventMessage: {}", pe.getMessage(), event); continue; } } return converter.marshal(dataPoints); }
@Override public SubscriptionsOutputMessage get(final SubscribeInputMessage message) { LOGGER.debug("Retrieving subscriptions {}", message); final RequestContext rc = RequestUtils.buildContext(message); final String response = getRestClient().get(rc); LOGGER.debug("Subscriptions retrieved"); return (SubscriptionsOutputMessage) converter.unmarshal(response, SubscriptionsOutputMessage.class); }
@Override public void registerSensors(final CatalogInputMessage message) { LOGGER.debug("Registering sensors"); final RequestContext rc = RequestUtils.buildContext(message, converter.marshal(message)); getRestClient().post(rc); LOGGER.debug("Sensors registered "); }
@Override public PlatformMetricsMessage getPlatformActivity() { final RequestContext rc = new RequestContext("admin/activity"); final String response = restClient.get(rc); return (PlatformMetricsMessage) parser.unmarshal(response, PlatformMetricsMessage.class); }
public void updateAlerts(final CatalogAlertInputMessage message) { LOGGER.debug("Updating alerts"); final RequestContext rc = RequestUtils.buildContext(message, converter.marshal(message)); getRestClient().put(rc); LOGGER.debug("alerts updated "); }
@Override public PlatformMetricsMessage getPlatformPerformance() { final RequestContext rc = new RequestContext("admin/performance"); final String response = restClient.get(rc); return (PlatformMetricsMessage) parser.unmarshal(response, PlatformMetricsMessage.class); }
@Override public void publish(final AlarmInputMessage message) { LOGGER.debug("Publishing alarm message {}", message); final RequestContext rc = RequestUtils.buildContext(message, converter.marshal(message)); getRestClient().put(rc); LOGGER.debug("alarm published "); }
public List<Subscription> getActiveSubscriptions(final String entity) { final String path = String.format("admin/subscriptions/%s", entity); final RequestContext rc = new RequestContext(path); final String response = restClient.get(rc); final SubscriptionsOutputMessage som = (SubscriptionsOutputMessage) parser.unmarshal(response, SubscriptionsOutputMessage.class); return som.getSubscriptions(); }
@Override public void updateSensors(final CatalogInputMessage message) { LOGGER.debug("Updating sensors"); final RequestContext rc = RequestUtils.buildContext(message, converter.marshal(message)); getRestClient().put(rc); LOGGER.debug("Sensors updated"); }
private BatchProcessResponse callBulkApi(final List<EventMessage> eventsToProcess) { numRetries++; LOGGER.debug("Num of attempt: {}", numRetries); BatchProcessResponse response = null; try { final RequestContext rc = new RequestContext("/_bulk", buildBody(eventsToProcess)); final String jsonResponse = restClient.post(rc); response = (BatchProcessResponse) converter.unmarshal(jsonResponse, BatchProcessResponse.class); } catch (final Exception e) { LOGGER.warn("Error executing bulk request to elasticsearch: {}", e.getMessage(), e); response = new BatchProcessResponse(true); } return response; }
@Override public void deleteProvider(final CatalogDeleteInputMessage message) { LOGGER.debug("Deleting provider components/sensors"); final RequestContext rc = RequestUtils.buildContext(message, converter.marshal(message)); getRestClient().delete(rc); LOGGER.debug("Provider components/sensors deleted"); }
@Override public OrdersOutputMessage getLastOrders(final OrderInputMessage message) { LOGGER.debug("Retrieving last orders {}", message); final RequestContext rc = RequestUtils.buildContext(message, RequestUtils.buildParameters(message)); final String response = getRestClient().get(rc); LOGGER.debug("Retrieved last orders"); return (OrdersOutputMessage) converter.unmarshal(response, OrdersOutputMessage.class); } }
@Override public void sendObservations(final DataInputMessage message) { LOGGER.debug("Sending observations {}", message); final RequestContext rc = RequestUtils.buildContext(message, converter.marshal(message)); getRestClient().put(rc); LOGGER.debug("Observations has been sent"); }
@Override public ObservationsOutputMessage getLastObservations(final DataInputMessage message) { LOGGER.debug("Retrieving last observations {}", message); final RequestContext rc = RequestUtils.buildContext(message, RequestUtils.buildParameters(message)); final String response = getRestClient().get(rc); LOGGER.debug("Retrieved last observations"); return (ObservationsOutputMessage) converter.unmarshal(response, ObservationsOutputMessage.class); }
@Override public void updateComponents(final CatalogInputMessage message) { LOGGER.debug("Updating components"); final RequestContext rc = RequestUtils.buildContext(message, converter.marshal(message)); getRestClient().put(rc); LOGGER.debug("Components updated"); }