com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult Java Examples

The following examples show how to use com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsLoadBalancerConnector.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Override
public Completable isValid(String loadBalancerId) {
    final DescribeTargetGroupsRequest request = new DescribeTargetGroupsRequest()
            .withTargetGroupArns(loadBalancerId);

    long startTime = registry.clock().wallTime();
    Single<DescribeTargetGroupsResult> resultSingle = AwsObservableExt.asyncActionSingle(supplier -> getClient(loadBalancerId).describeTargetGroupsAsync(request, supplier.handler()));
    return resultSingle
            .observeOn(scheduler)
            .doOnError(throwable -> {
                connectorMetrics.failure(AwsLoadBalancerConnectorMetrics.AwsLoadBalancerMethods.DescribeTargetGroups, throwable, startTime);
            })
            .flatMapObservable(result -> {
                connectorMetrics.success(AwsLoadBalancerConnectorMetrics.AwsLoadBalancerMethods.DescribeTargetGroups, startTime);
                return Observable.from(result.getTargetGroups());
            })
            .flatMap(targetGroup -> {
                if (targetGroup.getTargetType().equals(AWS_IP_TARGET_TYPE)) {
                    return Observable.empty();
                }
                return Observable.error(CloudConnectorException.invalidArgument(String.format("Target group %s is NOT of required type %s", targetGroup.getTargetGroupArn(), AWS_IP_TARGET_TYPE)));
            })
            .toCompletable();
}
 
Example #2
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
public Set<TargetGroup> getAllTargetGroups() {
  Set<TargetGroup> targetGroups = new HashSet<>();
  DescribeTargetGroupsRequest request = new DescribeTargetGroupsRequest()
      .withPageSize(MAX_TARGET_GROUP_PAGE_SIZE);
  DescribeTargetGroupsResult result = elbClient.describeTargetGroups(request);
  String nextMarker = result.getNextMarker();
  targetGroups.addAll(result.getTargetGroups());


  while (!Strings.isNullOrEmpty(nextMarker)) {
    DescribeTargetGroupsRequest nextRequest = new DescribeTargetGroupsRequest()
        .withMarker(nextMarker)
        .withPageSize(MAX_TARGET_GROUP_PAGE_SIZE);
    DescribeTargetGroupsResult nextResult = elbClient.describeTargetGroups(nextRequest);
    nextMarker = nextResult.getNextMarker();
    targetGroups.addAll(nextResult.getTargetGroups());
  }

  return targetGroups;
}
 
Example #3
Source File: InventoryUtil.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch target groups.
 *
 * @param temporaryCredentials the temporary credentials
 * @param skipRegions the skip regions
 * @param accountId the accountId
 * @param accountName the account name
 * @return the map
 */
public static Map<String,List<TargetGroupVH>> fetchTargetGroups(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){
	com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing elbClient ;
	Map<String,List<TargetGroupVH>> targetGrpMap = new LinkedHashMap<>();
	String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Target Group\" , \"region\":\"" ;
	for(Region region : RegionUtils.getRegions()){
		try{
			if(!skipRegions.contains(region.getName())){
				elbClient = com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder.standard().
					 	withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
				String nextMarker = null;
				List<TargetGroupVH> targetGrpList = new ArrayList<>();
				do{
					DescribeTargetGroupsResult  trgtGrpRslt =  elbClient.describeTargetGroups(new DescribeTargetGroupsRequest().withMarker(nextMarker));
					List<TargetGroup> targetGrpListTemp = trgtGrpRslt.getTargetGroups();
					for(TargetGroup tg : targetGrpListTemp) {
						DescribeTargetHealthResult rslt =  elbClient.describeTargetHealth(new DescribeTargetHealthRequest().withTargetGroupArn(tg.getTargetGroupArn()));
						targetGrpList.add(new TargetGroupVH(tg, rslt.getTargetHealthDescriptions()));
					}
					nextMarker = trgtGrpRslt.getNextMarker();
				}while(nextMarker!=null);

				if( !targetGrpList.isEmpty() ) {
					log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Target Group " +region.getName() + "-"+targetGrpList.size());
					targetGrpMap.put(accountId+delimiter+accountName+delimiter+region.getName(), targetGrpList);
				}

			}
		}catch(Exception e){
			log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}");
			ErrorManageUtil.uploadError(accountId,region.getName(),"targetgroup",e.getMessage());
		}
	}
	return targetGrpMap;
}
 
Example #4
Source File: InventoryUtilTest.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch target groups test.
 *
 * @throws Exception the exception
 */
@SuppressWarnings("static-access")
@Test
public void fetchTargetGroupsTest() throws Exception {
    
    mockStatic(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder.class);
    com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing elbClient = PowerMockito.mock(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing.class);
    com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder amazonElasticLoadBalancingClientBuilder = PowerMockito.mock(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder.class);
    AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class);
    PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider);
    when(amazonElasticLoadBalancingClientBuilder.standard()).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.withCredentials(anyObject())).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.withRegion(anyString())).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.build()).thenReturn(elbClient);
    
    DescribeTargetGroupsResult trgtGrpRslt = new DescribeTargetGroupsResult();
    List<TargetGroup> targetGrpList = new ArrayList<>();
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setTargetGroupArn("targetGroupArn");
    targetGrpList.add(targetGroup);
    trgtGrpRslt.setTargetGroups(targetGrpList);
    when(elbClient.describeTargetGroups(anyObject())).thenReturn(trgtGrpRslt);
    
    DescribeTargetHealthResult describeTargetHealthResult = new DescribeTargetHealthResult();
    describeTargetHealthResult.setTargetHealthDescriptions(new ArrayList<>());
    when(elbClient.describeTargetHealth(anyObject())).thenReturn(describeTargetHealthResult);
    assertThat(inventoryUtil.fetchTargetGroups(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), 
            "skipRegions", "account","accountName").size(), is(1));
}