@@ -91,9 +91,11 @@ private static OzoneConfiguration createConf() {
9191 ClassLoader contextClassLoader =
9292 Thread .currentThread ().getContextClassLoader ();
9393 Thread .currentThread ().setContextClassLoader (null );
94- OzoneConfiguration conf = new OzoneConfiguration ();
95- Thread .currentThread ().setContextClassLoader (contextClassLoader );
96- return conf ;
94+ try {
95+ return new OzoneConfiguration ();
96+ } finally {
97+ Thread .currentThread ().setContextClassLoader (contextClassLoader );
98+ }
9799 }
98100
99101 public BasicOzoneClientAdapterImpl (OzoneConfiguration conf , String volumeStr ,
@@ -109,38 +111,39 @@ public BasicOzoneClientAdapterImpl(String omHost, int omPort,
109111 ClassLoader contextClassLoader =
110112 Thread .currentThread ().getContextClassLoader ();
111113 Thread .currentThread ().setContextClassLoader (null );
112- OzoneConfiguration conf = OzoneConfiguration .of (hadoopConf );
113114
114- if (omHost == null && OmUtils .isServiceIdsDefined (conf )) {
115- // When the host name or service id isn't given
116- // but ozone.om.service.ids is defined, declare failure.
115+ try {
116+ OzoneConfiguration conf = OzoneConfiguration .of (hadoopConf );
117117
118- // This is a safety precaution that prevents the client from
119- // accidentally failing over to an unintended OM.
120- throw new IllegalArgumentException ("Service ID or host name must not"
121- + " be omitted when ozone.om.service.ids is defined." );
122- }
118+ if (omHost == null && OmUtils .isServiceIdsDefined (conf )) {
119+ // When the host name or service id isn't given
120+ // but ozone.om.service.ids is defined, declare failure.
123121
124- if (omPort != -1 ) {
125- // When the port number is specified, perform the following check
126- if (OmUtils .isOmHAServiceId (conf , omHost )) {
127- // If omHost is a service id, it shouldn't use a port
128- throw new IllegalArgumentException ("Port " + omPort +
129- " specified in URI but host '" + omHost + "' is "
130- + "a logical (HA) OzoneManager and does not use port information." );
122+ // This is a safety precaution that prevents the client from
123+ // accidentally failing over to an unintended OM.
124+ throw new IllegalArgumentException ("Service ID or host name must not"
125+ + " be omitted when ozone.om.service.ids is defined." );
131126 }
132- } else {
133- // When port number is not specified, read it from config
134- omPort = OmUtils .getOmRpcPort (conf );
135- }
136127
137- SecurityConfig secConfig = new SecurityConfig (conf );
128+ if (omPort != -1 ) {
129+ // When the port number is specified, perform the following check
130+ if (OmUtils .isOmHAServiceId (conf , omHost )) {
131+ // If omHost is a service id, it shouldn't use a port
132+ throw new IllegalArgumentException ("Port " + omPort +
133+ " specified in URI but host '" + omHost + "' is a "
134+ + "logical (HA) OzoneManager and does not use port information." );
135+ }
136+ } else {
137+ // When port number is not specified, read it from config
138+ omPort = OmUtils .getOmRpcPort (conf );
139+ }
138140
139- if (secConfig .isSecurityEnabled ()) {
140- this .securityEnabled = true ;
141- }
141+ SecurityConfig secConfig = new SecurityConfig (conf );
142+
143+ if (secConfig .isSecurityEnabled ()) {
144+ this .securityEnabled = true ;
145+ }
142146
143- try {
144147 String replicationTypeConf =
145148 conf .get (OzoneConfigKeys .OZONE_REPLICATION_TYPE ,
146149 OzoneConfigKeys .OZONE_REPLICATION_TYPE_DEFAULT );
0 commit comments