43
43
import org .apache .hadoop .security .SecurityUtil ;
44
44
import org .apache .commons .logging .Log ;
45
45
import org .apache .commons .logging .LogFactory ;
46
+ import org .eclipse .jetty .server .Response ;
46
47
import org .apache .hadoop .classification .InterfaceAudience ;
47
48
import org .apache .hadoop .conf .Configuration ;
48
49
import org .apache .hadoop .hdfs .DFSUtil ;
@@ -118,7 +119,7 @@ private FSImage getAndValidateFSImage(ServletContext context,
118
119
if (nnImage == null ) {
119
120
String errorMsg = "NameNode initialization not yet complete. "
120
121
+ "FSImage has not been set in the NameNode." ;
121
- response . sendError (HttpServletResponse .SC_FORBIDDEN , errorMsg );
122
+ sendError (response , HttpServletResponse .SC_FORBIDDEN , errorMsg );
122
123
throw new IOException (errorMsg );
123
124
}
124
125
return nnImage ;
@@ -207,7 +208,7 @@ private void serveFile(File file) throws IOException {
207
208
208
209
} catch (Throwable t ) {
209
210
String errMsg = "GetImage failed. " + StringUtils .stringifyException (t );
210
- response . sendError (HttpServletResponse .SC_GONE , errMsg );
211
+ sendError (response , HttpServletResponse .SC_GONE , errMsg );
211
212
throw new IOException (errMsg );
212
213
} finally {
213
214
response .getOutputStream ().close ();
@@ -223,7 +224,7 @@ private void validateRequest(ServletContext context, Configuration conf,
223
224
conf )) {
224
225
String errorMsg = "Only Namenode, Secondary Namenode, and administrators may access "
225
226
+ "this servlet" ;
226
- response . sendError (HttpServletResponse .SC_FORBIDDEN , errorMsg );
227
+ sendError (response , HttpServletResponse .SC_FORBIDDEN , errorMsg );
227
228
LOG .warn ("Received non-NN/SNN/administrator request for image or edits from "
228
229
+ request .getUserPrincipal ().getName ()
229
230
+ " at "
@@ -236,7 +237,7 @@ private void validateRequest(ServletContext context, Configuration conf,
236
237
&& !myStorageInfoString .equals (theirStorageInfoString )) {
237
238
String errorMsg = "This namenode has storage info " + myStorageInfoString
238
239
+ " but the secondary expected " + theirStorageInfoString ;
239
- response . sendError (HttpServletResponse .SC_FORBIDDEN , errorMsg );
240
+ sendError (response , HttpServletResponse .SC_FORBIDDEN , errorMsg );
240
241
LOG .warn ("Received an invalid request file transfer request "
241
242
+ "from a secondary with storage info " + theirStorageInfoString );
242
243
throw new IOException (errorMsg );
@@ -552,7 +553,7 @@ public Void run() throws Exception {
552
553
// we need a different response type here so the client can differentiate this
553
554
// from the failure to upload due to (1) security, or (2) other checkpoints already
554
555
// present
555
- response . sendError (HttpServletResponse .SC_EXPECTATION_FAILED ,
556
+ sendError (response , HttpServletResponse .SC_EXPECTATION_FAILED ,
556
557
"Nameode " +request .getLocalAddr ()+" is currently not in a state which can "
557
558
+ "accept uploads of new fsimages. State: " +state );
558
559
return null ;
@@ -567,15 +568,15 @@ public Void run() throws Exception {
567
568
// if the node is attempting to upload an older transaction, we ignore it
568
569
SortedSet <ImageUploadRequest > larger = currentlyDownloadingCheckpoints .tailSet (imageRequest );
569
570
if (larger .size () > 0 ) {
570
- response . sendError (HttpServletResponse .SC_CONFLICT ,
571
+ sendError (response , HttpServletResponse .SC_CONFLICT ,
571
572
"Another checkpointer is already in the process of uploading a" +
572
573
" checkpoint made up to transaction ID " + larger .last ());
573
574
return null ;
574
575
}
575
576
576
577
//make sure no one else has started uploading one
577
578
if (!currentlyDownloadingCheckpoints .add (imageRequest )) {
578
- response . sendError (HttpServletResponse .SC_CONFLICT ,
579
+ sendError (response , HttpServletResponse .SC_CONFLICT ,
579
580
"Either current namenode is checkpointing or another"
580
581
+ " checkpointer is already in the process of "
581
582
+ "uploading a checkpoint made at transaction ID "
@@ -622,7 +623,7 @@ public Void run() throws Exception {
622
623
(txid - lastCheckpointTxid ) + " expecting at least "
623
624
+ checkpointTxnCount ;
624
625
LOG .info (message );
625
- response . sendError (HttpServletResponse .SC_CONFLICT , message );
626
+ sendError (response , HttpServletResponse .SC_CONFLICT , message );
626
627
return null ;
627
628
}
628
629
@@ -632,7 +633,7 @@ public Void run() throws Exception {
632
633
+ "another checkpointer already uploaded an "
633
634
+ "checkpoint for txid " + txid ;
634
635
LOG .info (message );
635
- response . sendError (HttpServletResponse .SC_CONFLICT , message );
636
+ sendError (response , HttpServletResponse .SC_CONFLICT , message );
636
637
return null ;
637
638
}
638
639
@@ -669,11 +670,20 @@ public Void run() throws Exception {
669
670
});
670
671
} catch (Throwable t ) {
671
672
String errMsg = "PutImage failed. " + StringUtils .stringifyException (t );
672
- response . sendError (HttpServletResponse .SC_GONE , errMsg );
673
+ sendError (response , HttpServletResponse .SC_GONE , errMsg );
673
674
throw new IOException (errMsg );
674
675
}
675
676
}
676
677
678
+ private void sendError (HttpServletResponse response , int code , String message )
679
+ throws IOException {
680
+ if (response instanceof Response ) {
681
+ ((Response )response ).setStatusWithReason (code , message );
682
+ }
683
+
684
+ response .sendError (code , message );
685
+ }
686
+
677
687
/*
678
688
* Params required to handle put image request
679
689
*/
0 commit comments