Skip to content

Commit 3fad385

Browse files
committed
RANGER-5515: addressed review suggestion
1 parent fe04479 commit 3fad385

1 file changed

Lines changed: 36 additions & 41 deletions

File tree

agents-common/src/main/java/org/apache/ranger/admin/client/RangerAdminRESTClient.java

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.sun.jersey.api.client.ClientResponse;
2424
import org.apache.hadoop.conf.Configuration;
2525
import org.apache.hadoop.security.AccessControlException;
26+
import org.apache.http.HttpStatus;
2627
import org.apache.ranger.admin.client.datatype.RESTResponse;
2728
import org.apache.ranger.audit.provider.MiscUtil;
2829
import org.apache.ranger.authorization.hadoop.config.RangerPluginConfig;
@@ -55,12 +56,6 @@
5556
import java.util.List;
5657
import java.util.Map;
5758

58-
import static org.apache.http.HttpStatus.SC_NOT_FOUND;
59-
import static org.apache.http.HttpStatus.SC_NOT_MODIFIED;
60-
import static org.apache.http.HttpStatus.SC_NO_CONTENT;
61-
import static org.apache.http.HttpStatus.SC_OK;
62-
import static org.apache.http.HttpStatus.SC_UNAUTHORIZED;
63-
6459
public class RangerAdminRESTClient extends AbstractRangerAdminClient {
6560
private static final Logger LOG = LoggerFactory.getLogger(RangerAdminRESTClient.class);
6661

@@ -172,7 +167,7 @@ public ServicePolicies getServicePoliciesIfUpdated(final long lastKnownVersion,
172167

173168
checkAndResetSessionCookie(response);
174169

175-
if (response == null || response.getStatus() == SC_NOT_MODIFIED || response.getStatus() == SC_NO_CONTENT) {
170+
if (response == null || response.getStatus() == HttpStatus.SC_NOT_MODIFIED || response.getStatus() == HttpStatus.SC_NO_CONTENT) {
176171
if (response == null) {
177172
LOG.error("Error getting policies; Received NULL response!!. secureMode={}, serviceName={}", isSecureMode, serviceName);
178173
} else {
@@ -183,9 +178,9 @@ public ServicePolicies getServicePoliciesIfUpdated(final long lastKnownVersion,
183178
}
184179

185180
ret = null;
186-
} else if (response.getStatus() == SC_OK) {
181+
} else if (response.getStatus() == HttpStatus.SC_OK) {
187182
ret = JsonUtilsV2.readResponse(response, ServicePolicies.class);
188-
} else if (response.getStatus() == SC_NOT_FOUND) {
183+
} else if (response.getStatus() == HttpStatus.SC_NOT_FOUND) {
189184
ret = null;
190185

191186
LOG.error("Error getting policies; service not found. secureMode={}, response={}, serviceName={}, lastKnownVersion={}, lastActivationTimeInMillis={}",
@@ -250,7 +245,7 @@ public RangerRoles getRolesIfUpdated(final long lastKnownRoleVersion, final long
250245

251246
checkAndResetSessionCookie(response);
252247

253-
if (response == null || response.getStatus() == SC_NOT_MODIFIED || response.getStatus() == SC_NO_CONTENT) {
248+
if (response == null || response.getStatus() == HttpStatus.SC_NOT_MODIFIED || response.getStatus() == HttpStatus.SC_NO_CONTENT) {
254249
if (response == null) {
255250
LOG.error("Error getting Roles; Received NULL response!!. secureMode={}, serviceName={}", isSecureMode, serviceName);
256251
} else {
@@ -261,9 +256,9 @@ public RangerRoles getRolesIfUpdated(final long lastKnownRoleVersion, final long
261256
}
262257

263258
ret = null;
264-
} else if (response.getStatus() == SC_OK) {
259+
} else if (response.getStatus() == HttpStatus.SC_OK) {
265260
ret = JsonUtilsV2.readResponse(response, RangerRoles.class);
266-
} else if (response.getStatus() == SC_NOT_FOUND) {
261+
} else if (response.getStatus() == HttpStatus.SC_NOT_FOUND) {
267262
ret = null;
268263

269264
LOG.error("Error getting Roles; service not found. secureMode={}, response={}, serviceName={}, lastKnownRoleVersion={}, lastActivationTimeInMillis={}",
@@ -319,12 +314,12 @@ public RangerRole createRole(final RangerRole request) throws Exception {
319314

320315
checkAndResetSessionCookie(response);
321316

322-
if (response != null && response.getStatus() != SC_OK) {
317+
if (response != null && response.getStatus() != HttpStatus.SC_OK) {
323318
RESTResponse resp = RESTResponse.fromClientResponse(response);
324319

325320
LOG.error("createRole() failed: HTTP status={}, message={}, isSecure={}{}", response.getStatus(), resp.getMessage(), isSecureMode);
326321

327-
if (response.getStatus() == SC_UNAUTHORIZED) {
322+
if (response.getStatus() == HttpStatus.SC_UNAUTHORIZED) {
328323
throw new AccessControlException();
329324
}
330325

@@ -374,12 +369,12 @@ public void dropRole(final String execUser, final String roleName) throws Except
374369

375370
if (response == null) {
376371
throw new Exception("unknown error during deleteRole. roleName=" + roleName);
377-
} else if (response.getStatus() != SC_OK && response.getStatus() != SC_NO_CONTENT) {
372+
} else if (response.getStatus() != HttpStatus.SC_OK && response.getStatus() != HttpStatus.SC_NO_CONTENT) {
378373
RESTResponse resp = RESTResponse.fromClientResponse(response);
379374

380375
LOG.error("createRole() failed: HTTP status={}, message={}, isSecure={}", response.getStatus(), resp.getMessage(), isSecureMode);
381376

382-
if (response.getStatus() == SC_UNAUTHORIZED) {
377+
if (response.getStatus() == HttpStatus.SC_UNAUTHORIZED) {
383378
throw new AccessControlException();
384379
}
385380

@@ -424,12 +419,12 @@ public List<String> getAllRoles(final String execUser) throws Exception {
424419
List<String> ret;
425420

426421
if (response != null) {
427-
if (response.getStatus() != SC_OK) {
422+
if (response.getStatus() != HttpStatus.SC_OK) {
428423
RESTResponse resp = RESTResponse.fromClientResponse(response);
429424

430425
LOG.error("getAllRoles() failed: HTTP status={}, message={}, isSecure={}", response.getStatus(), resp.getMessage(), isSecureMode);
431426

432-
if (response.getStatus() == SC_UNAUTHORIZED) {
427+
if (response.getStatus() == HttpStatus.SC_UNAUTHORIZED) {
433428
throw new AccessControlException();
434429
}
435430

@@ -476,12 +471,12 @@ public List<String> getUserRoles(final String execUser) throws Exception {
476471
List<String> ret;
477472

478473
if (response != null) {
479-
if (response.getStatus() != SC_OK) {
474+
if (response.getStatus() != HttpStatus.SC_OK) {
480475
RESTResponse resp = RESTResponse.fromClientResponse(response);
481476

482477
LOG.error("getUserRoles() failed: HTTP status={}, message={}, isSecure={}", response.getStatus(), resp.getMessage(), isSecureMode);
483478

484-
if (response.getStatus() == SC_UNAUTHORIZED) {
479+
if (response.getStatus() == HttpStatus.SC_UNAUTHORIZED) {
485480
throw new AccessControlException();
486481
}
487482

@@ -532,12 +527,12 @@ public RangerRole getRole(final String execUser, final String roleName) throws E
532527
RangerRole ret;
533528

534529
if (response != null) {
535-
if (response.getStatus() != SC_OK) {
530+
if (response.getStatus() != HttpStatus.SC_OK) {
536531
RESTResponse resp = RESTResponse.fromClientResponse(response);
537532

538533
LOG.error("getRole() failed: HTTP status={}, message={}, isSecure={}", response.getStatus(), resp.getMessage(), isSecureMode);
539534

540-
if (response.getStatus() == SC_UNAUTHORIZED) {
535+
if (response.getStatus() == HttpStatus.SC_UNAUTHORIZED) {
541536
throw new AccessControlException();
542537
}
543538

@@ -581,12 +576,12 @@ public void grantRole(final GrantRevokeRoleRequest request) throws Exception {
581576

582577
checkAndResetSessionCookie(response);
583578

584-
if (response != null && response.getStatus() != SC_OK) {
579+
if (response != null && response.getStatus() != HttpStatus.SC_OK) {
585580
RESTResponse resp = RESTResponse.fromClientResponse(response);
586581

587582
LOG.error("grantRole() failed: HTTP status={}, message={}, isSecure={}", response.getStatus(), resp.getMessage(), isSecureMode);
588583

589-
if (response.getStatus() == SC_UNAUTHORIZED) {
584+
if (response.getStatus() == HttpStatus.SC_UNAUTHORIZED) {
590585
throw new AccessControlException();
591586
}
592587

@@ -625,12 +620,12 @@ public void revokeRole(final GrantRevokeRoleRequest request) throws Exception {
625620

626621
checkAndResetSessionCookie(response);
627622

628-
if (response != null && response.getStatus() != SC_OK) {
623+
if (response != null && response.getStatus() != HttpStatus.SC_OK) {
629624
RESTResponse resp = RESTResponse.fromClientResponse(response);
630625

631626
LOG.error("revokeRole() failed: HTTP status={}, message={}, isSecure={}", response.getStatus(), resp.getMessage(), isSecureMode);
632627

633-
if (response.getStatus() == SC_UNAUTHORIZED) {
628+
if (response.getStatus() == HttpStatus.SC_UNAUTHORIZED) {
634629
throw new AccessControlException();
635630
}
636631

@@ -676,12 +671,12 @@ public void grantAccess(final GrantRevokeRequest request) throws Exception {
676671

677672
checkAndResetSessionCookie(response);
678673

679-
if (response != null && response.getStatus() != SC_OK) {
674+
if (response != null && response.getStatus() != HttpStatus.SC_OK) {
680675
RESTResponse resp = RESTResponse.fromClientResponse(response);
681676

682677
LOG.error("grantAccess() failed: HTTP status={}, message={}, isSecure={}", response.getStatus(), resp.getMessage(), isSecureMode);
683678

684-
if (response.getStatus() == SC_UNAUTHORIZED) {
679+
if (response.getStatus() == HttpStatus.SC_UNAUTHORIZED) {
685680
throw new AccessControlException();
686681
}
687682

@@ -727,12 +722,12 @@ public void revokeAccess(final GrantRevokeRequest request) throws Exception {
727722

728723
checkAndResetSessionCookie(response);
729724

730-
if (response != null && response.getStatus() != SC_OK) {
725+
if (response != null && response.getStatus() != HttpStatus.SC_OK) {
731726
RESTResponse resp = RESTResponse.fromClientResponse(response);
732727

733728
LOG.error("revokeAccess() failed: HTTP status={}, message={}, isSecure={}", response.getStatus(), resp.getMessage(), isSecureMode);
734729

735-
if (response.getStatus() == SC_UNAUTHORIZED) {
730+
if (response.getStatus() == HttpStatus.SC_UNAUTHORIZED) {
736731
throw new AccessControlException();
737732
}
738733

@@ -784,7 +779,7 @@ public ServiceTags getServiceTagsIfUpdated(final long lastKnownVersion, final lo
784779

785780
final ServiceTags ret;
786781

787-
if (response == null || response.getStatus() == SC_NOT_MODIFIED) {
782+
if (response == null || response.getStatus() == HttpStatus.SC_NOT_MODIFIED) {
788783
if (response == null) {
789784
LOG.error("Error getting tags; Received NULL response!!. secureMode={}, serviceName={}", isSecureMode, serviceName);
790785
} else {
@@ -795,9 +790,9 @@ public ServiceTags getServiceTagsIfUpdated(final long lastKnownVersion, final lo
795790
}
796791

797792
ret = null;
798-
} else if (response.getStatus() == SC_OK) {
793+
} else if (response.getStatus() == HttpStatus.SC_OK) {
799794
ret = JsonUtilsV2.readResponse(response, ServiceTags.class);
800-
} else if (response.getStatus() == SC_NOT_FOUND) {
795+
} else if (response.getStatus() == HttpStatus.SC_NOT_FOUND) {
801796
ret = null;
802797

803798
LOG.error("Error getting tags; service not found. secureMode={}, response={}, serviceName={}, lastKnownVersion={}, lastActivationTimeInMillis={}",
@@ -855,7 +850,7 @@ public List<String> getTagTypes(String pattern) throws Exception {
855850

856851
List<String> ret;
857852

858-
if (response != null && response.getStatus() == SC_OK) {
853+
if (response != null && response.getStatus() == HttpStatus.SC_OK) {
859854
ret = JsonUtilsV2.readResponse(response, TYPE_LIST_STRING);
860855
} else {
861856
RESTResponse resp = RESTResponse.fromClientResponse(response);
@@ -912,7 +907,7 @@ public RangerUserStore getUserStoreIfUpdated(long lastKnownUserStoreVersion, lon
912907

913908
final RangerUserStore ret;
914909

915-
if (response == null || response.getStatus() == SC_NOT_MODIFIED) {
910+
if (response == null || response.getStatus() == HttpStatus.SC_NOT_MODIFIED) {
916911
if (response == null) {
917912
LOG.error("Error getting UserStore; Received NULL response!!. secureMode={}, serviceName={}", isSecureMode, serviceName);
918913
} else {
@@ -923,9 +918,9 @@ public RangerUserStore getUserStoreIfUpdated(long lastKnownUserStoreVersion, lon
923918
}
924919

925920
ret = null;
926-
} else if (response.getStatus() == SC_OK) {
921+
} else if (response.getStatus() == HttpStatus.SC_OK) {
927922
ret = JsonUtilsV2.readResponse(response, RangerUserStore.class);
928-
} else if (response.getStatus() == SC_NOT_FOUND) {
923+
} else if (response.getStatus() == HttpStatus.SC_NOT_FOUND) {
929924
ret = null;
930925

931926
LOG.error("Error getting UserStore; service not found. secureMode={}, response={}, serviceName={}, lastKnownUserStoreVersion={}, lastActivationTimeInMillis={}",
@@ -993,16 +988,16 @@ public ServiceGdsInfo getGdsInfoIfUpdated(long lastKnownVersion, long lastActiva
993988
ret = null;
994989

995990
LOG.error("Error getting GdsInfo - received NULL response: secureMode={}, serviceName={}", isSecureMode, serviceName);
996-
} else if (response.getStatus() == SC_NOT_MODIFIED) {
991+
} else if (response.getStatus() == HttpStatus.SC_NOT_MODIFIED) {
997992
ret = null;
998993

999994
RESTResponse resp = RESTResponse.fromClientResponse(response);
1000995

1001996
LOG.debug("No change in GdsInfo: secureMode={}, response={}, serviceName={}, lastKnownGdsVersion={}, lastActivationTimeInMillis={}",
1002997
isSecureMode, resp, serviceName, lastKnownVersion, lastActivationTimeInMillis);
1003-
} else if (response.getStatus() == SC_OK) {
998+
} else if (response.getStatus() == HttpStatus.SC_OK) {
1004999
ret = JsonUtilsV2.readResponse(response, ServiceGdsInfo.class);
1005-
} else if (response.getStatus() == SC_NOT_FOUND) {
1000+
} else if (response.getStatus() == HttpStatus.SC_NOT_FOUND) {
10061001
ret = null;
10071002

10081003
LOG.error("Error getting GdsInfo - service not found: secureMode={}, response={}, serviceName={}, lastKnownGdsVersion={},lastActivationTimeInMillis={}",
@@ -1060,7 +1055,7 @@ private void checkAndResetSessionCookie(ClientResponse response) {
10601055
} else {
10611056
int status = response.getStatus();
10621057

1063-
if (status == SC_OK || status == SC_NO_CONTENT || status == SC_NOT_MODIFIED) {
1058+
if (status == HttpStatus.SC_OK || status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_NOT_MODIFIED) {
10641059
Cookie newCookie = null;
10651060

10661061
for (NewCookie cookie : response.getCookies()) {

0 commit comments

Comments
 (0)