Skip to content

Commit 0237958

Browse files
Juan Pablo Diaz-VazJuan Pablo Diaz-Vaz
authored andcommitted
SUMOK-15 Concatenating records to send in batch
1 parent 4d44e79 commit 0237958

9 files changed

Lines changed: 52 additions & 96 deletions

src/com/mcplusa/kinesis/implementations/SumologicTransformer.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/com/mcplusa/sumologic/KinesisConnectorForSumologicConfiguration.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
/*
2-
* Copyright 2013-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Amazon Software License (the "License").
5-
* You may not use this file except in compliance with the License.
6-
* A copy of the License is located at
7-
*
8-
* http://aws.amazon.com/asl/
9-
*
10-
* or in the "license" file accompanying this file. This file is distributed
11-
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12-
* express or implied. See the License for the specific language governing
13-
* permissions and limitations under the License.
14-
*/
151
package com.mcplusa.sumologic;
162

173
import java.util.Properties;

src/com/mcplusa/kinesis/KinesisMessageModel.java renamed to src/com/mcplusa/sumologic/KinesisMessageModel.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
/*
2-
* Copyright 2013-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Amazon Software License (the "License").
5-
* You may not use this file except in compliance with the License.
6-
* A copy of the License is located at
7-
*
8-
* http://aws.amazon.com/asl/
9-
*
10-
* or in the "license" file accompanying this file. This file is distributed
11-
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12-
* express or implied. See the License for the specific language governing
13-
* permissions and limitations under the License.
14-
*/
15-
package com.mcplusa.kinesis;
1+
package com.mcplusa.sumologic;
162

173
import java.io.Serializable;
184

src/com/mcplusa/sumologic/KinesisMessageModelSumologicTransformer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.mcplusa.sumologic;
22

33
import com.amazonaws.services.kinesis.connectors.BasicJsonTransformer;
4-
import com.mcplusa.kinesis.KinesisMessageModel;
5-
import com.mcplusa.kinesis.implementations.SumologicTransformer;
4+
5+
import com.mcplusa.sumologic.KinesisMessageModel;
6+
import com.mcplusa.sumologic.implementations.SumologicTransformer;
67

78

89
/**

src/com/mcplusa/sumologic/SumologicExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.amazonaws.services.kinesis.connectors.KinesisConnectorRecordProcessorFactory;
44

55
import com.mcplusa.kinesis.KinesisConnectorExecutor;
6-
import com.mcplusa.kinesis.KinesisMessageModel;
6+
import com.mcplusa.sumologic.KinesisMessageModel;
77
import com.mcplusa.sumologic.SumologicMessageModelPipeline;
88

99
public class SumologicExecutor extends KinesisConnectorExecutor<KinesisMessageModel, String> {

src/com/mcplusa/sumologic/SumologicMessageModelPipeline.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.mcplusa.sumologic;
22

3-
import com.mcplusa.kinesis.KinesisMessageModel;
3+
import com.mcplusa.sumologic.KinesisMessageModel;
44
import com.mcplusa.sumologic.KinesisMessageModelSumologicTransformer;
5-
import com.mcplusa.kinesis.implementations.SumologicEmitter;
5+
import com.mcplusa.sumologic.implementations.SumologicEmitter;
66

77
import com.amazonaws.services.kinesis.connectors.interfaces.IKinesisConnectorPipeline;
88
import com.amazonaws.services.kinesis.connectors.KinesisConnectorConfiguration;

src/com/mcplusa/sumologic/SumologicSender.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,20 @@ public SumologicSender(String url) {
3636
httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(), params);
3737
}
3838

39-
public void sendToSumologic(String data) {
39+
public void sendToSumologic(String data) throws IOException{
4040
HttpPost post = null;
41-
try {
42-
post = new HttpPost(url);
43-
post.setEntity(new StringEntity(data, HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8));
44-
HttpResponse response = httpClient.execute(post);
45-
int statusCode = response.getStatusLine().getStatusCode();
46-
if (statusCode != 200) {
47-
LOG.warn(String.format("Received HTTP error from Sumo Service: %d", statusCode));
48-
}
49-
//need to consume the body if you want to re-use the connection.
50-
EntityUtils.consume(response.getEntity());
51-
} catch (IOException e) {
52-
LOG.warn("Could not send log to Sumo Logic", e);
53-
try { post.abort(); } catch (Exception ignore) {}
41+
post = new HttpPost(url);
42+
post.setEntity(new StringEntity(data, HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8));
43+
HttpResponse response = httpClient.execute(post);
44+
int statusCode = response.getStatusLine().getStatusCode();
45+
if (statusCode != 200) {
46+
LOG.warn(String.format("Received HTTP error from Sumo Service: %d", statusCode));
5447
}
48+
49+
//need to consume the body if you want to re-use the connection.
50+
EntityUtils.consume(response.getEntity());
51+
try {
52+
post.abort();
53+
} catch (Exception ignore) {}
5554
}
5655
}

src/com/mcplusa/kinesis/implementations/SumologicEmitter.java renamed to src/com/mcplusa/sumologic/implementations/SumologicEmitter.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
/**
2-
* Copyright 2013-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Amazon Software License (the "License").
5-
* You may not use this file except in compliance with the License.
6-
* A copy of the License is located at
7-
*
8-
* http://aws.amazon.com/asl/
9-
*
10-
* or in the "license" file accompanying this file. This file is distributed
11-
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12-
* express or implied. See the License for the specific language governing
13-
* permissions and limitations under the License.
14-
*/
15-
package com.mcplusa.kinesis.implementations;
1+
package com.mcplusa.sumologic.implementations;
162

173
import java.io.IOException;
184
import java.util.ArrayList;
@@ -51,12 +37,24 @@ public List<String> emit(final UnmodifiableBuffer<String> buffer)
5137
throws IOException {
5238

5339
List<String> records = buffer.getRecords();
54-
for (String record : records) {
55-
LOG.info("Got record: "+record);
56-
sender.sendToSumologic(record); // TODO send in batches
57-
}
58-
59-
return new ArrayList<String>(); // TODO return unprocessed records
40+
41+
return sendBatchConcatenating(records);
42+
}
43+
44+
public List<String> sendBatchConcatenating(List<String> records) {
45+
String message = "";
46+
for(String record: records) {
47+
message += record;
48+
message += "\n";
49+
}
50+
try {
51+
LOG.info("Sending batch of: "+records.size()+" records");
52+
sender.sendToSumologic(message);
53+
} catch (IOException e) {
54+
LOG.warn("Couldn't send record to Sumologic: "+e.getMessage());
55+
return records;
56+
}
57+
return new ArrayList<String>();
6058
}
6159

6260
@Override
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.mcplusa.sumologic.implementations;
2+
3+
import com.amazonaws.services.kinesis.connectors.interfaces.ITransformer;
4+
5+
/**
6+
* This interface defines an ITransformer that has an output type of Map of attribute name (String)
7+
* to AttributeValue so that the item can be put into Sumologic.
8+
*
9+
* @param <T>
10+
*/
11+
public interface SumologicTransformer<T> extends ITransformer<T, String> {
12+
13+
}

0 commit comments

Comments
 (0)