42
42
import org .apache .hadoop .hdfs .DFSConfigKeys ;
43
43
import org .apache .hadoop .hdfs .DFSUtilClient ;
44
44
import org .apache .hadoop .security .SecurityUtil ;
45
+ import org .eclipse .jetty .server .Response ;
45
46
import org .slf4j .Logger ;
46
47
import org .slf4j .LoggerFactory ;
47
48
import org .apache .hadoop .classification .InterfaceAudience ;
@@ -119,7 +120,7 @@ private FSImage getAndValidateFSImage(ServletContext context,
119
120
if (nnImage == null ) {
120
121
String errorMsg = "NameNode initialization not yet complete. "
121
122
+ "FSImage has not been set in the NameNode." ;
122
- response . sendError (HttpServletResponse .SC_FORBIDDEN , errorMsg );
123
+ sendError (response , HttpServletResponse .SC_FORBIDDEN , errorMsg );
123
124
throw new IOException (errorMsg );
124
125
}
125
126
return nnImage ;
@@ -218,7 +219,7 @@ private void serveFile(File file) throws IOException {
218
219
219
220
} catch (Throwable t ) {
220
221
String errMsg = "GetImage failed. " + StringUtils .stringifyException (t );
221
- response . sendError (HttpServletResponse .SC_GONE , errMsg );
222
+ sendError (response , HttpServletResponse .SC_GONE , errMsg );
222
223
throw new IOException (errMsg );
223
224
} finally {
224
225
response .getOutputStream ().close ();
@@ -234,7 +235,7 @@ private void validateRequest(ServletContext context, Configuration conf,
234
235
conf )) {
235
236
String errorMsg = "Only Namenode, Secondary Namenode, and administrators may access "
236
237
+ "this servlet" ;
237
- response . sendError (HttpServletResponse .SC_FORBIDDEN , errorMsg );
238
+ sendError (response , HttpServletResponse .SC_FORBIDDEN , errorMsg );
238
239
LOG .warn ("Received non-NN/SNN/administrator request for image or edits from "
239
240
+ request .getUserPrincipal ().getName ()
240
241
+ " at "
@@ -247,7 +248,7 @@ private void validateRequest(ServletContext context, Configuration conf,
247
248
&& !myStorageInfoString .equals (theirStorageInfoString )) {
248
249
String errorMsg = "This namenode has storage info " + myStorageInfoString
249
250
+ " but the secondary expected " + theirStorageInfoString ;
250
- response . sendError (HttpServletResponse .SC_FORBIDDEN , errorMsg );
251
+ sendError (response , HttpServletResponse .SC_FORBIDDEN , errorMsg );
251
252
LOG .warn ("Received an invalid request file transfer request "
252
253
+ "from a secondary with storage info " + theirStorageInfoString );
253
254
throw new IOException (errorMsg );
@@ -578,7 +579,7 @@ public Void run() throws Exception {
578
579
// we need a different response type here so the client can differentiate this
579
580
// from the failure to upload due to (1) security, or (2) other checkpoints already
580
581
// present
581
- response . sendError (HttpServletResponse .SC_EXPECTATION_FAILED ,
582
+ sendError (response , HttpServletResponse .SC_EXPECTATION_FAILED ,
582
583
"Nameode " +request .getLocalAddr ()+" is currently not in a state which can "
583
584
+ "accept uploads of new fsimages. State: " +state );
584
585
return null ;
@@ -593,15 +594,15 @@ public Void run() throws Exception {
593
594
// if the node is attempting to upload an older transaction, we ignore it
594
595
SortedSet <ImageUploadRequest > larger = currentlyDownloadingCheckpoints .tailSet (imageRequest );
595
596
if (larger .size () > 0 ) {
596
- response . sendError (HttpServletResponse .SC_CONFLICT ,
597
+ sendError (response , HttpServletResponse .SC_CONFLICT ,
597
598
"Another checkpointer is already in the process of uploading a" +
598
599
" checkpoint made up to transaction ID " + larger .last ());
599
600
return null ;
600
601
}
601
602
602
603
//make sure no one else has started uploading one
603
604
if (!currentlyDownloadingCheckpoints .add (imageRequest )) {
604
- response . sendError (HttpServletResponse .SC_CONFLICT ,
605
+ sendError (response , HttpServletResponse .SC_CONFLICT ,
605
606
"Either current namenode is checkpointing or another"
606
607
+ " checkpointer is already in the process of "
607
608
+ "uploading a checkpoint made at transaction ID "
@@ -648,7 +649,7 @@ public Void run() throws Exception {
648
649
(txid - lastCheckpointTxid ) + " expecting at least "
649
650
+ checkpointTxnCount ;
650
651
LOG .info (message );
651
- response . sendError (HttpServletResponse .SC_CONFLICT , message );
652
+ sendError (response , HttpServletResponse .SC_CONFLICT , message );
652
653
return null ;
653
654
}
654
655
@@ -658,7 +659,7 @@ public Void run() throws Exception {
658
659
+ "another checkpointer already uploaded an "
659
660
+ "checkpoint for txid " + txid ;
660
661
LOG .info (message );
661
- response . sendError (HttpServletResponse .SC_CONFLICT , message );
662
+ sendError (response , HttpServletResponse .SC_CONFLICT , message );
662
663
return null ;
663
664
}
664
665
@@ -695,11 +696,20 @@ public Void run() throws Exception {
695
696
});
696
697
} catch (Throwable t ) {
697
698
String errMsg = "PutImage failed. " + StringUtils .stringifyException (t );
698
- response . sendError (HttpServletResponse .SC_GONE , errMsg );
699
+ sendError (response , HttpServletResponse .SC_GONE , errMsg );
699
700
throw new IOException (errMsg );
700
701
}
701
702
}
702
703
704
+ private void sendError (HttpServletResponse response , int code , String message )
705
+ throws IOException {
706
+ if (response instanceof Response ) {
707
+ ((Response )response ).setStatusWithReason (code , message );
708
+ }
709
+
710
+ response .sendError (code , message );
711
+ }
712
+
703
713
/*
704
714
* Params required to handle put image request
705
715
*/
0 commit comments