Skip to content

Commit 36dc764

Browse files
Vyom Mani Tiwarimneethiraj
Vyom Mani Tiwari
authored andcommitted
RANGER-5051: checkstyle compliance updates - plugin-trino (apache#480)
Signed-off-by: Madhan Neethiraj <[email protected]>
1 parent 26e951f commit 36dc764

File tree

6 files changed

+339
-512
lines changed

6 files changed

+339
-512
lines changed

plugin-trino/pom.xml

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
<description>Ranger Security Plugin for Trino</description>
3232

3333
<properties>
34+
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
35+
<checkstyle.skip>false</checkstyle.skip>
3436
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3537
</properties>
3638

plugin-trino/src/main/java/org/apache/ranger/services/trino/RangerServiceTrino.java

+52-68
Original file line numberDiff line numberDiff line change
@@ -32,113 +32,97 @@
3232
import java.util.Map;
3333

3434
public class RangerServiceTrino
35-
extends RangerBaseService
36-
{
35+
extends RangerBaseService {
3736
private static final Logger LOG = LoggerFactory.getLogger(RangerServiceTrino.class);
37+
3838
public static final String ACCESS_TYPE_SELECT = "select";
3939

4040
@Override
41-
public List<RangerPolicy> getDefaultRangerPolicies()
42-
throws Exception
43-
{
44-
if (LOG.isDebugEnabled()) {
45-
LOG.debug("==> RangerServiceTrino.getDefaultRangerPolicies()");
46-
}
47-
48-
List<RangerPolicy> ret = super.getDefaultRangerPolicies();
49-
for (RangerPolicy defaultPolicy : ret) {
50-
if (defaultPolicy.getName().contains("all") && StringUtils.isNotBlank(lookUpUser)) {
51-
List<RangerPolicyItemAccess> accessListForLookupUser = new ArrayList<RangerPolicyItemAccess>();
52-
RangerPolicyItem policyItemForLookupUser = new RangerPolicyItem();
53-
54-
accessListForLookupUser.add(new RangerPolicyItemAccess(ACCESS_TYPE_SELECT));
55-
policyItemForLookupUser.setUsers(Collections.singletonList(lookUpUser));
56-
policyItemForLookupUser.setAccesses(accessListForLookupUser);
57-
policyItemForLookupUser.setDelegateAdmin(false);
41+
public Map<String, Object> validateConfig() {
42+
Map<String, Object> ret = new HashMap<>();
43+
String serviceName = getServiceName();
5844

59-
List<RangerPolicyItem> policyItems = defaultPolicy.getPolicyItems();
45+
LOG.debug("RangerServiceTrino.validateConfig(): Service: {}", serviceName);
6046

61-
if (policyItems == null || policyItems.isEmpty()) {
62-
policyItems = new ArrayList<>();
47+
if (configs != null) {
48+
try {
49+
if (!configs.containsKey(HadoopConfigHolder.RANGER_LOGIN_PASSWORD)) {
50+
configs.put(HadoopConfigHolder.RANGER_LOGIN_PASSWORD, null);
6351
}
6452

65-
policyItems.add(policyItemForLookupUser);
53+
ret = TrinoResourceManager.connectionTest(serviceName, configs);
54+
} catch (HadoopException he) {
55+
LOG.error("<== RangerServiceTrino.validateConfig() Error:{}", String.valueOf(he));
6656

67-
defaultPolicy.setPolicyItems(policyItems);
57+
throw he;
6858
}
6959
}
7060

71-
if (LOG.isDebugEnabled()) {
72-
LOG.debug("<== RangerServiceTrino.getDefaultRangerPolicies()");
73-
}
61+
LOG.debug("RangerServiceTrino.validateConfig(): Response: {}", ret);
7462

7563
return ret;
7664
}
7765

7866
@Override
79-
public Map<String, Object> validateConfig()
80-
throws Exception
81-
{
82-
Map<String, Object> ret = new HashMap<String, Object>();
83-
String serviceName = getServiceName();
84-
85-
if (LOG.isDebugEnabled()) {
86-
LOG.debug("RangerServiceTrino.validateConfig(): Service: " + serviceName);
87-
}
67+
public List<String> lookupResource(ResourceLookupContext context)
68+
throws Exception {
69+
List<String> ret = new ArrayList<>();
70+
String serviceName = getServiceName();
71+
String serviceType = getServiceType();
72+
Map<String, String> configs = getConfigs();
8873

89-
if (configs != null) {
74+
LOG.debug("==> RangerServiceTrino.lookupResource() Context: ({})", context);
75+
76+
if (context != null) {
9077
try {
9178
if (!configs.containsKey(HadoopConfigHolder.RANGER_LOGIN_PASSWORD)) {
9279
configs.put(HadoopConfigHolder.RANGER_LOGIN_PASSWORD, null);
9380
}
9481

95-
ret = TrinoResourceManager.connectionTest(serviceName, configs);
96-
}
97-
catch (HadoopException he) {
98-
LOG.error("<== RangerServiceTrino.validateConfig() Error:" + he);
82+
ret = TrinoResourceManager.getTrinoResources(serviceName, serviceType, configs, context);
83+
} catch (Exception e) {
84+
LOG.error("<==RangerServiceTrino.lookupResource() Error : {}", String.valueOf(e));
9985

100-
throw he;
86+
throw e;
10187
}
10288
}
10389

104-
if (LOG.isDebugEnabled()) {
105-
LOG.debug("RangerServiceTrino.validateConfig(): Response: " + ret);
106-
}
90+
LOG.debug("<== RangerServiceTrino.lookupResource() Response: ({})", ret);
10791

10892
return ret;
10993
}
11094

11195
@Override
112-
public List<String> lookupResource(ResourceLookupContext context)
113-
throws Exception
114-
{
115-
List<String> ret = new ArrayList<String>();
116-
String serviceName = getServiceName();
117-
String serviceType = getServiceType();
118-
Map<String, String> configs = getConfigs();
119-
120-
if (LOG.isDebugEnabled()) {
121-
LOG.debug("==> RangerServiceTrino.lookupResource() Context: (" + context + ")");
122-
}
96+
public List<RangerPolicy> getDefaultRangerPolicies()
97+
throws Exception {
98+
LOG.debug("==> RangerServiceTrino.getDefaultRangerPolicies()");
12399

124-
if (context != null) {
125-
try {
126-
if (!configs.containsKey(HadoopConfigHolder.RANGER_LOGIN_PASSWORD)) {
127-
configs.put(HadoopConfigHolder.RANGER_LOGIN_PASSWORD, null);
100+
List<RangerPolicy> ret = super.getDefaultRangerPolicies();
101+
102+
for (RangerPolicy defaultPolicy : ret) {
103+
if (defaultPolicy.getName().contains("all") && StringUtils.isNotBlank(lookUpUser)) {
104+
List<RangerPolicyItemAccess> accessListForLookupUser = new ArrayList<>();
105+
RangerPolicyItem policyItemForLookupUser = new RangerPolicyItem();
106+
107+
accessListForLookupUser.add(new RangerPolicyItemAccess(ACCESS_TYPE_SELECT));
108+
109+
policyItemForLookupUser.setUsers(Collections.singletonList(lookUpUser));
110+
policyItemForLookupUser.setAccesses(accessListForLookupUser);
111+
policyItemForLookupUser.setDelegateAdmin(false);
112+
113+
List<RangerPolicyItem> policyItems = defaultPolicy.getPolicyItems();
114+
115+
if (policyItems == null || policyItems.isEmpty()) {
116+
policyItems = new ArrayList<>();
128117
}
129118

130-
ret = TrinoResourceManager.getTrinoResources(serviceName, serviceType, configs, context);
131-
}
132-
catch (Exception e) {
133-
LOG.error("<==RangerServiceTrino.lookupResource() Error : " + e);
119+
policyItems.add(policyItemForLookupUser);
134120

135-
throw e;
121+
defaultPolicy.setPolicyItems(policyItems);
136122
}
137123
}
138124

139-
if (LOG.isDebugEnabled()) {
140-
LOG.debug("<== RangerServiceTrino.lookupResource() Response: (" + ret + ")");
141-
}
125+
LOG.debug("<== RangerServiceTrino.getDefaultRangerPolicies()");
142126

143127
return ret;
144128
}

0 commit comments

Comments
 (0)