@@ -44,6 +44,7 @@ public class CommonParams {
44
44
private String baiduAccessId ;
45
45
private String baiduSecretKey ;
46
46
private String bucket ;
47
+ private String logFilepath ;
47
48
private Map <String , Map <String , String >> pathConfigMap ;
48
49
private List <String > antiDirectories ;
49
50
private List <String > antiPrefixes ;
@@ -164,12 +165,12 @@ public CommonParams(IEntryParam entryParam) throws Exception {
164
165
path = entryParam .getValue ("path" , "" );
165
166
setSource ();
166
167
accountInit ();
168
+ logFilepath = entryParam .getValue ("log" , null );
167
169
if (isStorageSource ) {
168
170
setAuthKey ();
169
171
setBucket ();
170
172
String prefixes = entryParam .getValue ("prefixes" , null );
171
173
setPathConfigMap (entryParam .getValue ("prefix-config" , "" ), prefixes , true , true );
172
- antiPrefixes = Arrays .asList (ParamsUtils .escapeSplit (entryParam .getValue ("anti-prefixes" , "" )));
173
174
setPrefixLeft (entryParam .getValue ("prefix-left" , "false" ).trim ());
174
175
setPrefixRight (entryParam .getValue ("prefix-right" , "false" ).trim ());
175
176
} else {
@@ -181,6 +182,7 @@ public CommonParams(IEntryParam entryParam) throws Exception {
181
182
String files = entryParam .getValue ("files" , null );
182
183
setPathConfigMap (entryParam .getValue ("file-config" , "" ), files , false , false );
183
184
}
185
+ antiPrefixes = Arrays .asList (ParamsUtils .escapeSplit (entryParam .getValue ("anti-prefixes" , "" )));
184
186
setProcess ();
185
187
setPrivateType ();
186
188
regionName = entryParam .getValue ("region" , "" ).trim ().toLowerCase ();
@@ -297,11 +299,14 @@ public CommonParams(Map<String, String> paramsMap) throws Exception {
297
299
setSaveSeparator ();
298
300
break ;
299
301
case "qupload" :
300
- if (!fromLine ) mapLine .put ("key" , entryParam .getValue ("key" , "" ));
301
- String filepath = entryParam .getValue ("filepath" , "" ).trim ();
302
+ String key = entryParam .getValue ("key" , "" );
303
+ if (!fromLine ) mapLine .put ("key" , key );
304
+ String filepath = entryParam .getValue ("filepath" , "" );
302
305
if (!"" .equals (filepath )) {
303
306
indexMap .put ("filepath" , "filepath" );
304
307
mapLine .put ("filepath" , filepath );
308
+ } else if ("" .equals (key )) {
309
+ throw new IOException ("filepath and key shouldn't all be empty, file must be found with them." );
305
310
}
306
311
break ;
307
312
case "mime" :
@@ -602,9 +607,9 @@ private void setProcess() throws Exception {
602
607
}
603
608
if ("qupload" .equals (process ) && "file" .equals (entryParam .getValue ("parse" , "file" )) && !"terminal" .equals (source )) {
604
609
isSelfUpload = true ;
605
- String prefixes = entryParam . getValue ( "directories" , null );
606
- setPathConfigMap ( entryParam .getValue ("directory-config " , "" ), prefixes , false , true );
607
- antiDirectories = Arrays . asList ( ParamsUtils . escapeSplit ( entryParam .getValue ("anti-directories " , "" )) );
610
+ parse = "file" ; // 修正 parse 的默认值
611
+ String directories = entryParam .getValue ("directories " , null );
612
+ setPathConfigMap ( entryParam .getValue ("directory-config " , "" ), directories , false , true );
608
613
}
609
614
}
610
615
@@ -671,63 +676,91 @@ private void setPrivateType() throws IOException {
671
676
}
672
677
}
673
678
674
- private Map <String , String > fromProcedureLog (String logFile ) throws IOException {
675
- File file = new File (logFile );
676
- FileReader fileReader = new FileReader (file );
677
- BufferedReader bufferedReader = new BufferedReader (fileReader );
678
- Map <String , String > map = new HashMap <>();
679
- int index ;
680
- String line ;
681
- while ((line = bufferedReader .readLine ()) != null ) {
682
- index = line .indexOf (":{" );
683
- map .put (line .substring (0 , index ), line .substring (index ));
679
+ private void fromProcedureLog (String logFile , boolean withMarker , boolean withEnd ) throws IOException {
680
+ String lastLine = FileUtils .lastLineOfFile (logFile );
681
+ if (lastLine != null && !"" .equals (lastLine )) {
682
+ try {
683
+ JsonObject jsonObject = JsonUtils .toJsonObject (lastLine );
684
+ parseConfigMapFromJson (jsonObject , withMarker , withEnd );
685
+ } catch (Exception e ) {
686
+ File file = new File (logFile );
687
+ FileReader fileReader = new FileReader (file );
688
+ BufferedReader bufferedReader = new BufferedReader (fileReader );
689
+ int index ;
690
+ String line ;
691
+ String value ;
692
+ Map <String , String > map = new HashMap <>();
693
+ while ((line = bufferedReader .readLine ()) != null ) {
694
+ index = line .indexOf ("-|-" );
695
+ map .put (line .substring (0 , index ), line .substring (index ));
696
+ }
697
+ for (String key : map .keySet ()) {
698
+ value = map .get (key );
699
+ if (!"" .equals (value )) {
700
+ pathConfigMap .put (key , JsonUtils .fromJson (value , map .getClass ()));
701
+ }
702
+ }
703
+ }
684
704
}
685
- return map ;
686
705
}
687
706
688
- private void setPathConfigMap (String jsonConfigPath , String subPaths , boolean withMarker , boolean withEnd ) throws Exception {
689
- pathConfigMap = new HashMap <>();
690
- if (jsonConfigPath != null && !"" .equals (jsonConfigPath )) {
691
- JsonFile jsonFile = new JsonFile (jsonConfigPath );
692
- JsonObject jsonCfg ;
693
- JsonElement markerElement ;
694
- JsonElement startElement ;
695
- JsonElement endElement ;
696
- for (String key : jsonFile .getKeys ()) {
697
- Map <String , String > startAndEnd = new HashMap <>();
707
+ private void parseConfigMapFromJson (JsonObject jsonObject , boolean withMarker , boolean withEnd ) throws IOException {
708
+ JsonObject jsonCfg ;
709
+ JsonElement markerElement ;
710
+ JsonElement startElement ;
711
+ JsonElement endElement ;
712
+ for (String key : jsonObject .keySet ()) {
713
+ Map <String , String > startAndEnd = new HashMap <>();
698
714
// if ("".equals(prefix)) throw new IOException("prefix (prefixes config's element key) can't be empty.");
699
- JsonElement json = jsonFile .getElement (key );
700
- if (json == null || json instanceof JsonNull ) {
701
- pathConfigMap .put (key , null );
702
- continue ;
703
- }
704
- if (withMarker || withEnd ) {
705
- if (!(json instanceof JsonObject )) throw new IOException ("the value of key: " + key + " must be json." );
706
- jsonCfg = json .getAsJsonObject ();
707
- if (withMarker ) {
708
- markerElement = jsonCfg .get ("marker" );
709
- if (markerElement != null && !(markerElement instanceof JsonNull )) {
710
- startAndEnd .put ("marker" , markerElement .getAsString ());
711
- }
712
- }
713
- startElement = jsonCfg .get ("start" );
714
- if (startElement != null && !(startElement instanceof JsonNull )) {
715
- startAndEnd .put ("start" , startElement .getAsString ());
715
+ JsonElement json = jsonObject .get (key );
716
+ if (json == null || json instanceof JsonNull ) {
717
+ pathConfigMap .put (key , null );
718
+ continue ;
719
+ }
720
+ if (withMarker || withEnd ) {
721
+ if (!(json instanceof JsonObject )) throw new IOException ("the value of key: " + key + " must be json." );
722
+ jsonCfg = json .getAsJsonObject ();
723
+ if (withMarker ) {
724
+ markerElement = jsonCfg .get ("marker" );
725
+ if (markerElement != null && !(markerElement instanceof JsonNull )) {
726
+ startAndEnd .put ("marker" , markerElement .getAsString ());
716
727
}
717
- if (withEnd ) {
718
- endElement = jsonCfg .get ("end" );
719
- if (endElement != null && !(endElement instanceof JsonNull )) {
720
- startAndEnd .put ("end" , endElement .getAsString ());
721
- }
728
+ }
729
+ startElement = jsonCfg .get ("start" );
730
+ if (startElement != null && !(startElement instanceof JsonNull )) {
731
+ startAndEnd .put ("start" , startElement .getAsString ());
732
+ }
733
+ if (withEnd ) {
734
+ endElement = jsonCfg .get ("end" );
735
+ if (endElement != null && !(endElement instanceof JsonNull )) {
736
+ startAndEnd .put ("end" , endElement .getAsString ());
722
737
}
723
- } else {
724
- startAndEnd .put ("start" , json .getAsString ());
725
738
}
726
- pathConfigMap .put (key , startAndEnd );
739
+ } else {
740
+ startAndEnd .put ("start" , json .getAsString ());
741
+ }
742
+ pathConfigMap .put (key , startAndEnd );
743
+ }
744
+ }
745
+
746
+ private void setPathConfigMap (String jsonConfigPath , String subPaths , boolean withMarker , boolean withEnd ) throws Exception {
747
+ pathConfigMap = new HashMap <>();
748
+ if (logFilepath == null || "" .equals (logFilepath )) {
749
+ if (jsonConfigPath != null && !"" .equals (jsonConfigPath )) {
750
+ JsonFile jsonFile = new JsonFile (jsonConfigPath );
751
+ parseConfigMapFromJson (jsonFile .getJsonObject (), withMarker , withEnd );
752
+ } else if (subPaths != null && !"" .equals (subPaths )) {
753
+ String [] subPathList = ParamsUtils .escapeSplit (subPaths );
754
+ for (String subPath : subPathList ) pathConfigMap .put (subPath , null );
755
+ }
756
+ } else {
757
+ if (jsonConfigPath != null && !"" .equals (jsonConfigPath )) {
758
+ throw new IOException ("log and uris can not be used together, please remove prefixes/files/directories if you want use breakpoint with log." );
759
+ } else if (subPaths != null && !"" .equals (subPaths )) {
760
+ throw new IOException ("log and json config can not be used together, please remove config path if you want use breakpoint with log." );
761
+ } else {
762
+ fromProcedureLog (logFilepath , withMarker , withEnd );
727
763
}
728
- } else if (subPaths != null && !"" .equals (subPaths )) {
729
- String [] subPathList = ParamsUtils .escapeSplit (subPaths );
730
- for (String subPath : subPathList ) pathConfigMap .put (subPath , null );
731
764
}
732
765
}
733
766
@@ -991,8 +1024,8 @@ private void setIndexMap() throws IOException {
991
1024
if (!indexMap .containsKey ("0" )) indexMap .put ("0" , "key" );
992
1025
}
993
1026
}
994
- if (ProcessUtils .needFilepath (process ) || "file" .equals (parse ) || isSelfUpload ) {
995
- setIndex (entryParam .getValue ("filepath-index" , "filepath" ).trim (), "filepath" );
1027
+ if (ProcessUtils .needFilepath (process ) || "file" .equals (parse )) {
1028
+ setIndex (entryParam .getValue ("filepath-index" , fieldIndex ? "filepath" : " " ).trim (), "filepath" );
996
1029
// setIndex("parent", "parent");
997
1030
}
998
1031
if (indexMap .size () == 0 ) {
@@ -1097,7 +1130,7 @@ private void checkFilterForProcess() throws IOException {
1097
1130
1098
1131
private void setUnitLen (String unitLen ) throws IOException {
1099
1132
if (unitLen .startsWith ("-" )) {
1100
- if (isSelfUpload ) this .unitLen = 20 ;
1133
+ if (isSelfUpload ) this .unitLen = 3 ;
1101
1134
if ("qiniu" .equals (source ) || "local" .equals (source )) this .unitLen = 10000 ;
1102
1135
else this .unitLen = 1000 ;
1103
1136
} else {
0 commit comments