001/* 002 * Copyright (c) 2017 Chris K Wensel <chris@wensel.net>. All Rights Reserved. 003 * 004 * Project and contact information: http://www.cascading.org/ 005 * 006 * This file is part of the Cascading project. 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020 021package cascading.aws.s3.logs; 022 023import java.util.TimeZone; 024 025import cascading.tuple.Fields; 026import cascading.tuple.coerce.Coercions; 027import cascading.tuple.type.DateType; 028 029/** 030 */ 031public class S3Logs 032 { 033 public static final String REGEX = "(\\S+) ([a-z0-9][a-z0-9-.]+) \\[(.*\\+.*)] (\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b) (\\S+) (\\S+) (\\S+) (\\S+) \"(\\w+ \\S+ \\S+)\" (\\d+|-) (\\S+) (\\d+|-) (\\d+|-) (\\d+|-) (\\d+|-) \"(https?://.*/?|-)\" \"(.*)\" (\\S+)"; 034 035 public static final CleanCoercibleType<Long> CLEAN_LONG = new CleanCoercibleType<>( Coercions.LONG_OBJECT, o -> o.equals( "-" ) ? null : o ); 036 public static final CleanCoercibleType<String> CLEAN_STRING = new CleanCoercibleType<>( Coercions.STRING, o -> o.equals( "-" ) ? null : o ); 037 038 public static Fields BUCKET_OWNER = new Fields( "bucketOwner", String.class ); 039 public static Fields BUCKET = new Fields( "bucket", String.class ); 040 public static Fields TIME = new Fields( "time", new DateType( "dd/MMM/yyyy:HH:mm:ss Z", TimeZone.getTimeZone( "UTC" ) ) ); 041 public static Fields REMOTE_IP_ADDRESS = new Fields( "remoteIpAddress", String.class ); 042 public static Fields REQUESTER = new Fields( "requester", CLEAN_STRING ); 043 public static Fields REQUEST_ID = new Fields( "requestId", String.class ); 044 public static Fields OPERATION = new Fields( "operation", String.class ); 045 public static Fields KEY = new Fields( "key", CLEAN_STRING ); 046 public static Fields REQUEST_URI = new Fields( "requestUri", String.class ); 047 public static Fields HTTP_STATUS = new Fields( "httpStatus", Integer.class ); 048 public static Fields ERROR_CODE = new Fields( "errorCode", CLEAN_STRING ); 049 public static Fields BYTES_SENT = new Fields( "bytesSent", CLEAN_LONG ); 050 public static Fields OBJECT_SIZE = new Fields( "objectSize", CLEAN_LONG ); 051 public static Fields TOTAL_TIME = new Fields( "totalTime", CLEAN_LONG ); 052 public static Fields TURN_AROUND_TIME = new Fields( "turnAroundTime", CLEAN_LONG ); 053 public static Fields REFERRER = new Fields( "referrer", CLEAN_STRING ); 054 public static Fields USER_AGENT = new Fields( "userAgent", String.class ); 055 public static Fields VERSION_ID = new Fields( "versionId", CLEAN_STRING ); 056 057 public static final Fields FIELDS = Fields.NONE 058 .append( BUCKET_OWNER ) 059 .append( BUCKET ) 060 .append( TIME ) 061 .append( REMOTE_IP_ADDRESS ) 062 .append( REQUESTER ) 063 .append( REQUEST_ID ) 064 .append( OPERATION ) 065 .append( KEY ) 066 .append( REQUEST_URI ) 067 .append( HTTP_STATUS ) 068 .append( ERROR_CODE ) 069 .append( BYTES_SENT ) 070 .append( OBJECT_SIZE ) 071 .append( TOTAL_TIME ) 072 .append( TURN_AROUND_TIME ) 073 .append( REFERRER ) 074 .append( USER_AGENT ) 075 .append( VERSION_ID ); 076 }