@@ -446,18 +446,14 @@ protected synchronized byte[] createPassword(TokenIdent identifier) {
446446 byte [] password = createPassword (identifier .getBytes (), currentKey .getKey ());
447447 DelegationTokenInformation tokenInfo = new DelegationTokenInformation (now
448448 + tokenRenewInterval , password , getTrackingIdIfEnabled (identifier ));
449- long start = Time .monotonicNow ();
450- boolean success = false ;
451449 try {
450+ long start = Time .monotonicNow ();
452451 storeToken (identifier , tokenInfo );
453- success = true ;
452+ metrics . addStoreToken ( Time . monotonicNow () - start ) ;
454453 } catch (IOException ioe ) {
455454 LOG .error ("Could not store token " + formatTokenId (identifier ) + "!!" ,
456455 ioe );
457- } finally {
458- if (metrics != null ) {
459- metrics .addStoreToken (success , Time .monotonicNow () - start );
460- }
456+ metrics .addTokenFailure ();
461457 }
462458 return password ;
463459 }
@@ -579,15 +575,13 @@ public synchronized long renewToken(Token<TokenIdent> token,
579575 throw new InvalidToken ("Renewal request for unknown token "
580576 + formatTokenId (id ));
581577 }
582- long start = Time .monotonicNow ();
583- boolean success = false ;
584578 try {
579+ long start = Time .monotonicNow ();
585580 updateToken (id , info );
586- success = true ;
587- } finally {
588- if (metrics != null ) {
589- metrics .addUpdateToken (success , Time .monotonicNow () - start );
590- }
581+ metrics .addUpdateToken (Time .monotonicNow () - start );
582+ } catch (IOException ioe ) {
583+ metrics .addTokenFailure ();
584+ throw ioe ;
591585 }
592586 return renewTime ;
593587 }
@@ -624,16 +618,14 @@ public synchronized TokenIdent cancelToken(Token<TokenIdent> token,
624618 if (info == null ) {
625619 throw new InvalidToken ("Token not found " + formatTokenId (id ));
626620 }
627- long start = Time .monotonicNow ();
628- boolean success = false ;
629621 try {
622+ long start = Time .monotonicNow ();
630623 removeTokenForOwnerStats (id );
631624 removeStoredToken (id );
632- success = true ;
633- } finally {
634- if (metrics != null ) {
635- metrics .addRemoveToken (success , Time .monotonicNow () - start );
636- }
625+ metrics .addRemoveToken (Time .monotonicNow () - start );
626+ } catch (IOException ioe ) {
627+ metrics .addTokenFailure ();
628+ throw ioe ;
637629 }
638630 return id ;
639631 }
@@ -906,34 +898,24 @@ public DelegationTokenSecretManagerMetrics() {
906898 LOG .debug ("Initialized {}" , registry );
907899 }
908900
909- public void addStoreToken (boolean success , long value ) {
910- if (success ) {
911- storeToken .add (value );
912- ioStatistics .addTimedOperation (STORE_TOKEN_STAT , value );
913- } else {
914- tokenFailure .incr ();
915- ioStatistics .incrementCounter (TOKEN_FAILURE_STAT );
916- }
901+ public void addStoreToken (long value ) {
902+ storeToken .add (value );
903+ ioStatistics .addTimedOperation (STORE_TOKEN_STAT , value );
917904 }
918905
919- public void addUpdateToken (boolean success , long value ) {
920- if (success ) {
921- updateToken .add (value );
922- ioStatistics .addTimedOperation (UPDATE_TOKEN_STAT , value );
923- } else {
924- tokenFailure .incr ();
925- ioStatistics .incrementCounter (TOKEN_FAILURE_STAT );
926- }
906+ public void addUpdateToken (long value ) {
907+ updateToken .add (value );
908+ ioStatistics .addTimedOperation (UPDATE_TOKEN_STAT , value );
927909 }
928910
929- public void addRemoveToken (boolean success , long value ) {
930- if ( success ) {
931- removeToken . add ( value );
932- ioStatistics . addTimedOperation ( REMOVE_TOKEN_STAT , value );
933- } else {
934- tokenFailure . incr ();
935- ioStatistics . incrementCounter ( TOKEN_FAILURE_STAT );
936- }
911+ public void addRemoveToken (long value ) {
912+ removeToken . add ( value );
913+ ioStatistics . addTimedOperation ( REMOVE_TOKEN_STAT , value );
914+ }
915+
916+ public void addTokenFailure () {
917+ tokenFailure . incr ( );
918+ ioStatistics . incrementCounter ( TOKEN_FAILURE_STAT );
937919 }
938920
939921 @ Override
0 commit comments