Skip to content

Commit dd2fe1b

Browse files
committed
Compilation fixed
1 parent daf70d2 commit dd2fe1b

File tree

3 files changed

+60
-44
lines changed

3 files changed

+60
-44
lines changed

modules/aws/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/elb/TcpDiscoveryElbIpFinder.java

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
import com.amazonaws.services.ec2.AmazonEC2;
2121
import com.amazonaws.services.ec2.AmazonEC2ClientBuilder;
2222
import com.amazonaws.services.ec2.model.DescribeInstancesRequest;
23+
import com.amazonaws.services.ec2.model.Reservation;
2324
import com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancing;
2425
import com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingClientBuilder;
2526
import com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest;
2627
import com.amazonaws.services.elasticloadbalancing.model.Instance;
2728
import com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription;
29+
import java.util.ArrayList;
2830
import org.apache.ignite.spi.IgniteSpiConfiguration;
2931
import org.apache.ignite.spi.IgniteSpiException;
3032
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter;
@@ -34,7 +36,6 @@
3436
import java.util.List;
3537

3638
import static com.amazonaws.util.StringUtils.isNullOrEmpty;
37-
import static java.util.stream.Collectors.toList;
3839

3940
/**
4041
* AWS ELB-based IP finder.
@@ -67,7 +68,7 @@ public class TcpDiscoveryElbIpFinder extends TcpDiscoveryIpFinderAdapter {
6768
private AmazonEC2 amazonEC2Client;
6869

6970
/** */
70-
private AWSCredentialsProvider credentialsProvider;
71+
private AWSCredentialsProvider credsProvider;
7172

7273
/** */
7374
private String region;
@@ -82,47 +83,53 @@ public TcpDiscoveryElbIpFinder() {
8283
setShared(true);
8384
}
8485

85-
/**
86-
* {@inheritDoc}
87-
*/
88-
@Override
89-
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
86+
/** {@inheritDoc} */
87+
@Override public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
9088
initClients();
9189

90+
List<String> instanceIds = new ArrayList<>();
91+
9292
DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest().withLoadBalancerNames(loadBalancerName);
9393

94-
List<String> instanceIds = amazonELBClient.describeLoadBalancers(req)
95-
.getLoadBalancerDescriptions()
96-
.stream()
97-
.map(LoadBalancerDescription::getInstances)
98-
.flatMap(instances -> instances.stream())
99-
.map(Instance::getInstanceId)
100-
.collect(toList());
101-
102-
return amazonEC2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIds))
103-
.getReservations()
104-
.stream()
105-
.flatMap(reservation -> reservation.getInstances().stream())
106-
.map(instance -> new InetSocketAddress(instance.getPrivateIpAddress(), 0))
107-
.collect(toList());
94+
List<LoadBalancerDescription> descs = amazonELBClient.describeLoadBalancers(req).getLoadBalancerDescriptions();
95+
96+
for (LoadBalancerDescription desc : descs) {
97+
for (Instance instance : desc.getInstances())
98+
instanceIds.add(instance.getInstanceId());
99+
}
100+
101+
DescribeInstancesRequest instReq = new DescribeInstancesRequest().withInstanceIds(instanceIds);
102+
103+
List<Reservation> reservations = amazonEC2Client.describeInstances(instReq).getReservations();
104+
105+
List<InetSocketAddress> addrs = new ArrayList<>();
106+
107+
for (Reservation reservation : reservations) {
108+
List<com.amazonaws.services.ec2.model.Instance> instances = reservation.getInstances();
109+
110+
for (com.amazonaws.services.ec2.model.Instance instance : instances)
111+
addrs.add(new InetSocketAddress(instance.getPrivateIpAddress(), 0));
112+
}
113+
114+
return addrs;
108115
}
109116

110117
/**
111118
* Initializing the IP finder.
112119
*/
113120
private void initClients() {
114-
if (credentialsProvider == null || isNullOrEmpty(loadBalancerName) || isNullOrEmpty(region))
121+
if (credsProvider == null || isNullOrEmpty(loadBalancerName) || isNullOrEmpty(region))
115122
throw new IgniteSpiException("One or more configuration parameters are invalid [setCredentialsProvider=" +
116-
credentialsProvider + ", setRegion=" + region + ", setLoadBalancerName=" +
123+
credsProvider + ", setRegion=" + region + ", setLoadBalancerName=" +
117124
loadBalancerName + "]");
118125

119126
if (amazonEC2Client == null)
120-
amazonEC2Client = AmazonEC2ClientBuilder.standard().withRegion(region).withCredentials(credentialsProvider)
127+
amazonEC2Client = AmazonEC2ClientBuilder.standard().withRegion(region).withCredentials(credsProvider)
121128
.build();
122129

123130
if (amazonELBClient == null)
124131
amazonELBClient = AmazonElasticLoadBalancingClientBuilder.standard().withRegion(region)
125-
.withCredentials(credentialsProvider).build();
132+
.withCredentials(credsProvider).build();
126133
}
127134

128135
/**
@@ -153,27 +160,20 @@ public void setRegion(String region) {
153160
*
154161
* For details refer to Amazon API reference.
155162
*
156-
* @param credentialsProvider AWS credentials provider.
157-
* @return {@code this} for chaining.
163+
* @param credsProvider AWS credentials provider.
158164
*/
159165
@IgniteSpiConfiguration(optional = false)
160-
public void setCredentialsProvider(AWSCredentialsProvider credentialsProvider) {
161-
this.credentialsProvider = credentialsProvider;
166+
public void setCredentialsProvider(AWSCredentialsProvider credsProvider) {
167+
this.credsProvider = credsProvider;
162168
}
163169

164-
/**
165-
* {@inheritDoc}
166-
*/
167-
@Override
168-
public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
170+
/** {@inheritDoc} */
171+
@Override public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
169172
//No-op, ELB will take care of registration.
170173
}
171174

172-
/**
173-
* {@inheritDoc}
174-
*/
175-
@Override
176-
public void unregisterAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
175+
/** {@inheritDoc} */
176+
@Override public void unregisterAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
177177
// No-op, ELB will take care of this process.
178178
}
179179
}

modules/aws/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/elb/TcpDiscoveryElbIpFinderSelfTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
/**
2424
* TcpDiscoveryElbIpFinderSelfTest test.
2525
*/
26-
public class TcpDiscoveryElbIpFinderSelfTest extends
27-
TcpDiscoveryIpFinderAbstractSelfTest<TcpDiscoveryElbIpFinder> {
26+
public class TcpDiscoveryElbIpFinderSelfTest extends TcpDiscoveryIpFinderAbstractSelfTest<TcpDiscoveryElbIpFinder> {
2827
/**
2928
* Constructor.
3029
*
@@ -34,17 +33,17 @@ public TcpDiscoveryElbIpFinderSelfTest() throws Exception {
3433
// No-op.
3534
}
3635

36+
/** {@inheritDoc} */
3737
@Override protected void beforeTest() throws Exception {
3838
// No-op.
3939
}
4040

41-
/* {@inheritDoc} */
41+
/** {@inheritDoc} */
4242
@Override protected TcpDiscoveryElbIpFinder ipFinder() throws Exception {
43-
// No-op.
4443
return null;
4544
}
4645

47-
/* {@inheritDoc} */
46+
/** {@inheritDoc} */
4847
@Override public void testIpFinder() throws Exception {
4948
TcpDiscoveryElbIpFinder ipFinder = new TcpDiscoveryElbIpFinder();
5049

modules/aws/src/test/java/org/apache/ignite/testsuites/IgniteElbTestSuite.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package org.apache.ignite.testsuites;
219

320
import junit.framework.TestSuite;

0 commit comments

Comments
 (0)