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

The following examples show how to use com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest. 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: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
public Optional<TargetGroup> getTargetGroup(String trafficSourceName) {
  DescribeTargetGroupsRequest targetGroupsRequest = new DescribeTargetGroupsRequest()
      .withNames(trafficSourceName);

  try {
    List<TargetGroup> maybeTargetGroup = elbClient
        .describeTargetGroups(targetGroupsRequest)
        .getTargetGroups();

    if (maybeTargetGroup.size() > 0) {
      return Optional.of(maybeTargetGroup.get(0));
    } else {
      return Optional.absent();
    }
  } catch (TargetGroupNotFoundException exn) {
    LOG.warn("Could not find target group with name {}", trafficSourceName);
    return Optional.absent();
  }
}
 
Example #4
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;
}