use of com.clicklogs.model.ClickLogRequest in project aws-ingesting-click-logs-using-terraform by aws-samples.
the class ClickLoggerStreamHandler method handleRequest.
@Override
public KinesisAnalyticsInputPreprocessingResponse handleRequest(final KinesisFirehoseEvent event, final Context context) {
final LambdaLogger logger = context.getLogger();
final String success_response = new String("200 OK");
logger.log("EVENT: " + gson.toJson(event));
String env_table = System.getenv("DB_TABLE");
if (!StringUtils.isBlank(env_table)) {
dynamo_table_name = env_table;
}
// System.getenv("REGION");
String env_region = System.getenv("AWS_REGION");
logger.log("Environment region name - " + env_region);
if (!StringUtils.isBlank(env_region)) {
region = env_region;
}
List<Record> records = new ArrayList<>();
event.getRecords().forEach(kinesisRecord -> {
String clickJson = new String(kinesisRecord.getData().array());
logger.log("Individual record: " + kinesisRecord.getData());
Gson gson = new Gson();
try {
ClickLogRequest clickLogRequest = gson.fromJson(clickJson, ClickLogRequest.class);
String req = clickLogRequest.getRequestid() + " - " + clickLogRequest.getCallerid() + " - " + clickLogRequest.getComponent() + " - " + clickLogRequest.getType() + " - " + clickLogRequest.getAction() + " - " + clickLogRequest.getUser() + " - " + clickLogRequest.getClientip() + " - " + clickLogRequest.getCreatedtime();
Boolean valid_input = true;
logger.log("Incoming request variables - " + req);
if (clickLogRequest != null) {
logger.log("Validating inputs");
if (StringUtils.isBlank(clickLogRequest.getRequestid())) {
logger.log("error occurred - requestid missing");
valid_input = false;
}
if (StringUtils.isBlank(clickLogRequest.getContextid())) {
logger.log("error occurred - contextid missing");
valid_input = false;
}
if (StringUtils.isBlank(clickLogRequest.getCallerid())) {
logger.log("error occurred - caller missing");
valid_input = false;
}
if (StringUtils.isBlank(clickLogRequest.getType())) {
logger.log("error occurred - type missing");
valid_input = false;
}
if (StringUtils.isBlank(clickLogRequest.getAction())) {
logger.log("error occurred - action missing");
valid_input = false;
}
if (StringUtils.isBlank(clickLogRequest.getComponent())) {
logger.log("error occurred - component missing");
valid_input = false;
}
String user = "GUEST";
if (StringUtils.isBlank(clickLogRequest.getUser())) {
logger.log("setting default user");
clickLogRequest.setUser(user);
}
String clientip = "APIGWY";
if (StringUtils.isBlank(clickLogRequest.getClientip())) {
logger.log("setting default clientip");
clickLogRequest.setClientip(clientip);
}
String datetime = "";
if (StringUtils.isBlank(clickLogRequest.getCreatedtime())) {
logger.log("setting default createdtime");
Format f = new SimpleDateFormat("mm-dd-yyyy hh:mm:ss");
datetime = f.format(new Date());
clickLogRequest.setCreatedtime(datetime);
}
logger.log("Validated inputs");
}
req = clickLogRequest.getRequestid() + " - " + clickLogRequest.getCallerid() + " - " + clickLogRequest.getComponent() + " - " + clickLogRequest.getType() + " - " + clickLogRequest.getAction() + " - " + clickLogRequest.getUser() + " - " + clickLogRequest.getClientip() + " - " + clickLogRequest.getCreatedtime();
logger.log("Modified request variables - " + req);
logger.log("Valid Input - " + String.valueOf(valid_input));
System.out.println("Calling updateclicklogs method for the received clicklogrequest");
if (valid_input) {
updateClickLogs(clickLogRequest);
}
Record record = new Record();
record.setRecordId(kinesisRecord.getRecordId());
record.setData(kinesisRecord.getData());
Result result = KinesisAnalyticsInputPreprocessingResponse.Result.Ok;
record.setResult(result);
records.add(record);
} catch (JsonSyntaxException jsEx) {
System.out.println(jsEx);
}
});
KinesisAnalyticsInputPreprocessingResponse response = new KinesisAnalyticsInputPreprocessingResponse(records);
logger.log(success_response);
return response;
}
use of com.clicklogs.model.ClickLogRequest in project aws-ingesting-click-logs-using-terraform by aws-samples.
the class ClickLoggerHandlerTest method setup.
@Before
public void setup() {
clickLogRequest = new ClickLogRequest();
clickLogRequest.setAction("ACTION");
clickLogRequest.setCallerid("CALLERID");
clickLogRequest.setClientip("CLIENTIP");
clickLogRequest.setComponent("COMPONENT");
clickLogRequest.setContextid("CONTEXTID");
clickLogRequest.setCreatedtime("CREATEDTIME");
clickLogRequest.setRequestid("REQUESTID");
clickLogRequest.setType("TYPE");
clickLogRequest.setUser("USER");
when(clickLogRequest).thenReturn(this.clickLogRequest);
amazonKinesisFirehoseClient = Mockito.mock(AmazonKinesisFirehose.class);
when(amazonKinesisFirehoseClient).thenReturn(amazonKinesisFirehoseClient);
putRecordResult = new PutRecordResult();
putRecordResult.setRecordId("SUCCESS_RECORD_ID");
when(any(PutRecordResult.class)).thenReturn(putRecordResult);
}
use of com.clicklogs.model.ClickLogRequest in project aws-ingesting-click-logs-using-terraform by aws-samples.
the class ClickLoggerStreamHanderTest method setup.
@Before
public void setup() {
List<Record> records = new ArrayList<>();
Record record = new Record();
clickLogRequest = new ClickLogRequest();
clickLogRequest.setAction("ACTION");
clickLogRequest.setCallerid("CALLERID");
clickLogRequest.setClientip("CLIENTIP");
clickLogRequest.setComponent("COMPONENT");
clickLogRequest.setContextid("CONTEXTID");
clickLogRequest.setCreatedtime("CREATEDTIME");
clickLogRequest.setRequestid("REQUESTID");
clickLogRequest.setType("TYPE");
clickLogRequest.setUser("USER");
when(clickLogRequest).thenReturn(this.clickLogRequest);
record = new Record();
record.setData(ByteBuffer.wrap(clickLogRequest.toString().getBytes()));
records.add(record);
event.setRecords(records);
when(event).thenReturn(this.event);
}
Aggregations