Search in sources :

Example 6 with EventDataSubmissionTask

use of com.wavefront.agent.data.EventDataSubmissionTask in project java by wavefrontHQ.

the class QueueExporter method processTask.

@VisibleForTesting
<T extends DataSubmissionTask<T>> void processTask(T task, BufferedWriter writer) throws IOException {
    if (task instanceof LineDelimitedDataSubmissionTask) {
        for (String line : ((LineDelimitedDataSubmissionTask) task).payload()) {
            writer.write(line);
            writer.newLine();
        }
    } else if (task instanceof SourceTagSubmissionTask) {
        writer.write(((SourceTagSubmissionTask) task).payload().toString());
        writer.newLine();
    } else if (task instanceof EventDataSubmissionTask) {
        for (Event event : ((EventDataSubmissionTask) task).payload()) {
            writer.write(event.toString());
            writer.newLine();
        }
    }
}
Also used : SourceTagSubmissionTask(com.wavefront.agent.data.SourceTagSubmissionTask) EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) Event(com.wavefront.dto.Event) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with EventDataSubmissionTask

use of com.wavefront.agent.data.EventDataSubmissionTask in project java by wavefrontHQ.

the class SQSSubmissionQueueTest method scenarios.

@Parameterized.Parameters
public static Collection<Object[]> scenarios() {
    Collection<Object[]> scenarios = new ArrayList<>();
    for (TaskConverter.CompressionType type : TaskConverter.CompressionType.values()) {
        RetryTaskConverter<LineDelimitedDataSubmissionTask> converter = new RetryTaskConverter<>("2878", type);
        LineDelimitedDataSubmissionTask task = converter.fromBytes("WF\u0001\u0001{\"__CLASS\":\"com.wavefront.agent.data.LineDelimitedDataSubmissionTask\",\"enqueuedTimeMillis\":77777,\"attempts\":0,\"serverErrors\":0,\"handle\":\"2878\",\"entityType\":\"POINT\",\"format\":\"wavefront\",\"payload\":[\"java.util.ArrayList\",[\"item1\",\"item2\",\"item3\"]],\"enqueuedMillis\":77777}".getBytes());
        scenarios.add(new Object[] { type, converter, task });
    }
    for (TaskConverter.CompressionType type : TaskConverter.CompressionType.values()) {
        RetryTaskConverter<EventDataSubmissionTask> converter = new RetryTaskConverter<>("2878", type);
        EventDataSubmissionTask task = converter.fromBytes("WF\u0001\u0001{\"__CLASS\":\"com.wavefront.agent.data.EventDataSubmissionTask\",\"enqueuedTimeMillis\":77777,\"attempts\":0,\"serverErrors\":0,\"handle\":\"2878\",\"entityType\":\"EVENT\",\"events\":[\"java.util.ArrayList\",[{\"name\":\"Event name for testing\",\"startTime\":77777000,\"endTime\":77777001,\"annotations\":[\"java.util.HashMap\",{\"severity\":\"INFO\"}],\"dimensions\":[\"java.util.HashMap\",{\"multi\":[\"java.util.ArrayList\",[\"bar\",\"baz\"]]}],\"hosts\":[\"java.util.ArrayList\",[\"host1\",\"host2\"]],\"tags\":[\"java.util.ArrayList\",[\"tag1\"]]}]],\"enqueuedMillis\":77777}".getBytes());
        scenarios.add(new Object[] { type, converter, task });
    }
    return scenarios;
}
Also used : EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) ArrayList(java.util.ArrayList) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask)

Example 8 with EventDataSubmissionTask

use of com.wavefront.agent.data.EventDataSubmissionTask in project java by wavefrontHQ.

the class SQSSubmissionQueueTest method testTaskRead.

@Test
public void testTaskRead() throws IOException {
    SQSSubmissionQueue queue = getTaskQueue();
    UUID proxyId = UUID.randomUUID();
    DataSubmissionTask<? extends DataSubmissionTask<?>> task;
    if (this.expectedTask instanceof LineDelimitedDataSubmissionTask) {
        task = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item1", "item2", "item3"), time::get);
    } else if (this.expectedTask instanceof EventDataSubmissionTask) {
        task = new EventDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "2878", ImmutableList.of(new Event(ReportEvent.newBuilder().setStartTime(time.get() * 1000).setEndTime(time.get() * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setDimensions(ImmutableMap.of("multi", ImmutableList.of("bar", "baz"))).setAnnotations(ImmutableMap.of("severity", "INFO")).setTags(ImmutableList.of("tag1")).build())), time::get);
    } else {
        task = null;
    }
    expect(client.sendMessage(new SendMessageRequest(queueUrl, queue.encodeMessageForDelivery(this.expectedTask)))).andReturn(null);
    replay(client);
    task.enqueue(QueueingReason.RETRY);
    reset(client);
    ReceiveMessageRequest msgRequest = new ReceiveMessageRequest().withMaxNumberOfMessages(1).withWaitTimeSeconds(1).withQueueUrl(queueUrl);
    ReceiveMessageResult msgResult = new ReceiveMessageResult().withMessages(new Message().withBody(queue.encodeMessageForDelivery(task)).withReceiptHandle("handle1"));
    expect(client.receiveMessage(msgRequest)).andReturn(msgResult);
    replay(client);
    if (this.expectedTask instanceof LineDelimitedDataSubmissionTask) {
        LineDelimitedDataSubmissionTask readTask = (LineDelimitedDataSubmissionTask) queue.peek();
        assertEquals(((LineDelimitedDataSubmissionTask) task).payload(), readTask.payload());
        assertEquals(((LineDelimitedDataSubmissionTask) this.expectedTask).payload(), readTask.payload());
        assertEquals(77777, readTask.getEnqueuedMillis());
    }
    if (this.expectedTask instanceof EventDataSubmissionTask) {
        EventDataSubmissionTask readTask = (EventDataSubmissionTask) queue.peek();
        assertEquals(((EventDataSubmissionTask) task).payload(), readTask.payload());
        assertEquals(((EventDataSubmissionTask) this.expectedTask).payload(), readTask.payload());
        assertEquals(77777, readTask.getEnqueuedMillis());
    }
}
Also used : ReceiveMessageRequest(com.amazonaws.services.sqs.model.ReceiveMessageRequest) Message(com.amazonaws.services.sqs.model.Message) EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) ReportEvent(wavefront.report.ReportEvent) Event(com.wavefront.dto.Event) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) DefaultEntityPropertiesForTesting(com.wavefront.agent.data.DefaultEntityPropertiesForTesting) UUID(java.util.UUID) SendMessageRequest(com.amazonaws.services.sqs.model.SendMessageRequest) ReceiveMessageResult(com.amazonaws.services.sqs.model.ReceiveMessageResult) Test(org.junit.Test)

Aggregations

EventDataSubmissionTask (com.wavefront.agent.data.EventDataSubmissionTask)8 LineDelimitedDataSubmissionTask (com.wavefront.agent.data.LineDelimitedDataSubmissionTask)6 Event (com.wavefront.dto.Event)5 DefaultEntityPropertiesForTesting (com.wavefront.agent.data.DefaultEntityPropertiesForTesting)4 SourceTagSubmissionTask (com.wavefront.agent.data.SourceTagSubmissionTask)4 UUID (java.util.UUID)4 Test (org.junit.Test)4 ReportEvent (wavefront.report.ReportEvent)4 SourceTag (com.wavefront.dto.SourceTag)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ReportSourceTag (wavefront.report.ReportSourceTag)2 Message (com.amazonaws.services.sqs.model.Message)1 ReceiveMessageRequest (com.amazonaws.services.sqs.model.ReceiveMessageRequest)1 ReceiveMessageResult (com.amazonaws.services.sqs.model.ReceiveMessageResult)1 SendMessageRequest (com.amazonaws.services.sqs.model.SendMessageRequest)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Charsets (com.google.common.base.Charsets)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1