|
33 | 33 | import transwarp.org.elasticsearch.action.bulk.BulkProcessor; |
34 | 34 | import transwarp.org.elasticsearch.client.transport.TransportClient; |
35 | 35 | import transwarp.org.elasticsearch.common.network.NetworkModule; |
| 36 | +import transwarp.org.elasticsearch.common.settings.Setting; |
36 | 37 | import transwarp.org.elasticsearch.common.settings.Settings; |
37 | 38 | import transwarp.org.elasticsearch.common.transport.TransportAddress; |
38 | 39 | import transwarp.org.elasticsearch.common.unit.TimeValue; |
@@ -65,33 +66,47 @@ public ExtendES5ApiCallBridge(List<InetSocketAddress> transportAddresses, Elasti |
65 | 66 | Preconditions.checkArgument(transportAddresses != null && !transportAddresses.isEmpty()); |
66 | 67 | this.transportAddresses = transportAddresses; |
67 | 68 | this.esTableInfo = esTableInfo; |
| 69 | + this.esTableInfo.judgeKrbEnable(); |
68 | 70 | } |
69 | 71 |
|
70 | 72 | @Override |
71 | 73 | public TransportClient createClient(Map<String, String> clientConfig) throws IOException{ |
72 | 74 |
|
73 | | - //1. login kdc with keytab and krb5 conf |
74 | | - UserGroupInformation ugi = KrbUtils.loginAndReturnUgi( |
75 | | - esTableInfo.getPrincipal(), |
76 | | - esTableInfo.getKeytab(), |
77 | | - esTableInfo.getKrb5conf()); |
78 | | - |
79 | | - //2. set transwarp attributes |
80 | | - Settings settings = Settings.builder().put(clientConfig) |
81 | | - .put("client.transport.sniff", true) |
82 | | - .put("security.enable", true) |
83 | | - .put(NetworkModule.TRANSPORT_TYPE_KEY, "security-netty3") |
84 | | - .build(); |
85 | | - |
86 | | - //3. build transport client with transwarp plugins |
87 | | - TransportClient transportClient = ugi.doAs((PrivilegedAction<TransportClient>) () -> { |
88 | | - TransportClient tmpClient = new PreBuiltTransportClient(settings, |
89 | | - Collections.singletonList(DoorKeeperClientPlugin.class)); |
| 75 | + TransportClient transportClient; |
| 76 | + |
| 77 | + if (esTableInfo.isEnableKrb()) { |
| 78 | + //1. login kdc with keytab and krb5 conf |
| 79 | + UserGroupInformation ugi = KrbUtils.loginAndReturnUgi( |
| 80 | + esTableInfo.getPrincipal(), |
| 81 | + esTableInfo.getKeytab(), |
| 82 | + esTableInfo.getKrb5conf()); |
| 83 | + |
| 84 | + //2. set transwarp attributes |
| 85 | + Settings settings = Settings.builder().put(clientConfig) |
| 86 | + .put("client.transport.sniff", true) |
| 87 | + .put("security.enable", true) |
| 88 | + .put(NetworkModule.TRANSPORT_TYPE_KEY, "security-netty3") |
| 89 | + .build(); |
| 90 | + |
| 91 | + //3. build transport client with transwarp plugins |
| 92 | + transportClient = ugi.doAs((PrivilegedAction<TransportClient>) () -> { |
| 93 | + TransportClient tmpClient = new PreBuiltTransportClient(settings, |
| 94 | + Collections.singletonList(DoorKeeperClientPlugin.class)); |
| 95 | + for (TransportAddress transport : ElasticsearchUtils.convertInetSocketAddresses(transportAddresses)) { |
| 96 | + tmpClient.addTransportAddress(transport); |
| 97 | + } |
| 98 | + return tmpClient; |
| 99 | + }); |
| 100 | + } else { |
| 101 | + Settings settings = Settings.builder().put(clientConfig) |
| 102 | + .put("client.transport.sniff", true) |
| 103 | + .build(); |
| 104 | + |
| 105 | + transportClient = new PreBuiltTransportClient(settings); |
90 | 106 | for (TransportAddress transport : ElasticsearchUtils.convertInetSocketAddresses(transportAddresses)) { |
91 | | - tmpClient.addTransportAddress(transport); |
| 107 | + transportClient.addTransportAddress(transport); |
92 | 108 | } |
93 | | - return tmpClient; |
94 | | - }); |
| 109 | + } |
95 | 110 |
|
96 | 111 | return transportClient; |
97 | 112 | } |
@@ -140,18 +155,27 @@ public void configureBulkProcessorBackoff( |
140 | 155 | @Override |
141 | 156 | public boolean verifyClientConnection(TransportClient client) throws IOException { |
142 | 157 |
|
143 | | - //1. login kdc with keytab and krb5 conf |
144 | | - UserGroupInformation ugi = KrbUtils.loginAndReturnUgi( |
145 | | - esTableInfo.getPrincipal(), |
146 | | - esTableInfo.getKeytab(), |
147 | | - esTableInfo.getKrb5conf()); |
148 | 158 |
|
149 | | - //2. refresh availableNodes. |
150 | | - boolean verifyResult = ugi.doAs((PrivilegedAction<Boolean>) () -> { |
151 | | - LOG.info("Refresh client available nodes."); |
| 159 | + boolean verifyResult = false; |
| 160 | + |
| 161 | + if (esTableInfo.isEnableKrb()) { |
| 162 | + //1. login kdc with keytab and krb5 conf |
| 163 | + UserGroupInformation ugi = KrbUtils.loginAndReturnUgi( |
| 164 | + esTableInfo.getPrincipal(), |
| 165 | + esTableInfo.getKeytab(), |
| 166 | + esTableInfo.getKrb5conf()); |
| 167 | + |
| 168 | + //2. refresh availableNodes. |
| 169 | + verifyResult = ugi.doAs((PrivilegedAction<Boolean>) () -> { |
| 170 | + LOG.info("Refresh client available nodes."); |
| 171 | + client.refreshAvailableNodes(); |
| 172 | + return client.connectedNodes().isEmpty(); |
| 173 | + }); |
| 174 | + } else { |
152 | 175 | client.refreshAvailableNodes(); |
153 | | - return client.connectedNodes().isEmpty(); |
154 | | - }); |
| 176 | + verifyResult = client.connectedNodes().isEmpty(); |
| 177 | + } |
| 178 | + |
155 | 179 |
|
156 | 180 | if (!verifyResult) { |
157 | 181 | return true; |
|
0 commit comments