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

The following examples show how to use com.amazonaws.services.elasticloadbalancingv2.model.TargetHealthDescription. 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: ELBIsInstanceRegisteredStep.java    From pipeline-aws-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected Boolean run() throws Exception {
	TaskListener listener = this.getContext().get(TaskListener.class);
	listener.getLogger().println("elbIsInstanceRegistered instanceID: " + this.step.instanceID + " port: " + this.step.port + " from targetGroupARN: " + this.step.targetGroupARN);
	
	Boolean rval = false;
	AmazonElasticLoadBalancing client = AWSClientFactory.create(AmazonElasticLoadBalancingClientBuilder.standard(), this.getEnvVars());
	DescribeTargetHealthRequest req = new DescribeTargetHealthRequest().withTargetGroupArn(this.step.targetGroupARN);
	DescribeTargetHealthResult res = client.describeTargetHealth(req);
	List<TargetHealthDescription> targets = res.getTargetHealthDescriptions();
	for (TargetHealthDescription target : targets) {
		if (target.getTarget().getId().equals(this.step.instanceID) && target.getTargetHealth().getState().equals("healthy") ) {
			rval = true;
			break;
		}
	}
	listener.getLogger().println(res.toString());
	
	return rval;
}
 
Example #2
Source File: ELBIsInstanceDeregisteredStep.java    From pipeline-aws-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected Boolean run() throws Exception {
	TaskListener listener = this.getContext().get(TaskListener.class);
	listener.getLogger().println("elbIsInstanceDeregistered instanceID: " + this.step.instanceID + " port: " + this.step.port + " from targetGroupARN: " + this.step.targetGroupARN);
	
	Boolean rval = true;
	AmazonElasticLoadBalancing client = AWSClientFactory.create(AmazonElasticLoadBalancingClientBuilder.standard(), this.getEnvVars());
	DescribeTargetHealthRequest req = new DescribeTargetHealthRequest().withTargetGroupArn(this.step.targetGroupARN);
	DescribeTargetHealthResult res = client.describeTargetHealth(req);
	List<TargetHealthDescription> targets = res.getTargetHealthDescriptions();
	for (TargetHealthDescription target : targets) {
		if (target.getTarget().getId().equals(this.step.instanceID) ) {
			rval = false;
			break;
		}
	}
	listener.getLogger().println(res.toString());
	
	return rval;
}
 
Example #3
Source File: AlbResource.java    From Baragon with Apache License 2.0 6 votes vote down vote up
@GET
@NoAuth
@Path("/target-groups/{targetGroup}/targets")
public Collection<TargetHealthDescription> getTargets(@PathParam("targetGroup") String targetGroup) {
  if (config.isPresent()) {
    try {
      Optional<TargetGroup> maybeTargetGroup = applicationLoadBalancer.getTargetGroup(targetGroup);
      if (maybeTargetGroup.isPresent()) {
        return applicationLoadBalancer.getTargetsOn(maybeTargetGroup.get());
      } else {
        throw new WebApplicationException(String.format("TargetGroup with name %s not found", targetGroup), Status.NOT_FOUND);
      }
    } catch (AmazonClientException exn) {
      throw new BaragonWebException(String.format("AWS Client exception %s", exn));
    }
  } else {
    throw new BaragonWebException("ElbSync and related actions are not currently enabled");
  }
}
 
Example #4
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param target Target to check
 * @param targetGroup Group to check in
 * @return if the given target is the last healthy target in the given target group
 */
private boolean isLastHealthyInstance(TargetDescription target, TargetGroup targetGroup) {
  DescribeTargetHealthRequest targetHealthRequest = new DescribeTargetHealthRequest()
      .withTargetGroupArn(targetGroup.getTargetGroupArn());
  List<TargetHealthDescription> targetHealthDescriptions = elbClient
      .describeTargetHealth(targetHealthRequest)
      .getTargetHealthDescriptions();

  boolean instanceIsHealthy = false;
  int healthyCount = 0;

  for (TargetHealthDescription targetHealthDescription : targetHealthDescriptions) {
    if (targetHealthDescription.getTargetHealth().getState()
        .equals(TargetHealthStateEnum.Healthy.toString())) {
      healthyCount += 1;
      if (targetHealthDescription.getTarget().equals(target)) {
        instanceIsHealthy = true;
      }
    }
  }

  return instanceIsHealthy && healthyCount == 1;
}
 
Example #5
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isInstanceHealthy(String instanceId, String elbName) {
  DescribeTargetHealthRequest healthRequest = new DescribeTargetHealthRequest()
      .withTargets(new TargetDescription().withId(instanceId));
  DescribeTargetHealthResult result = elbClient.describeTargetHealth(healthRequest);

  for (TargetHealthDescription health: result.getTargetHealthDescriptions()) {
    if (health.getTargetHealth().getState().equals(TargetHealthStateEnum.Healthy.toString())
        && health.getTarget().getId().equals(instanceId)) {
      return true;
    }
  }

  return false;
}
 
Example #6
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
public Collection<TargetHealthDescription> getTargetsOn(TargetGroup targetGroup) {
  DescribeTargetHealthRequest targetHealthRequest = new DescribeTargetHealthRequest()
      .withTargetGroupArn(targetGroup.getTargetGroupArn());

  return elbClient
      .describeTargetHealth(targetHealthRequest)
      .getTargetHealthDescriptions();
}
 
Example #7
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
private Collection<TargetDescription> targetsInTargetGroup(TargetGroup targetGroup) {
  DescribeTargetHealthRequest targetHealthRequest = new DescribeTargetHealthRequest()
      .withTargetGroupArn(targetGroup.getTargetGroupArn());
  List<TargetHealthDescription> targetGroupsResult = elbClient
      .describeTargetHealth(targetHealthRequest)
      .getTargetHealthDescriptions();

  Collection<TargetDescription> targetDescriptions = new HashSet<>();
  for (TargetHealthDescription targetHealthDescription : targetGroupsResult) {
    targetDescriptions.add(targetHealthDescription.getTarget());
  }

  return targetDescriptions;
}
 
Example #8
Source File: TargetGroupVH.java    From pacbot with Apache License 2.0 2 votes vote down vote up
/**
 * Instantiates a new target group VH.
 *
 * @param trgtGrp the trgt grp
 * @param targets the targets
 */
public TargetGroupVH(TargetGroup trgtGrp, List<TargetHealthDescription> targets){
	this.trgtGrp = trgtGrp;
	this.targets = targets;
}
 
Example #9
Source File: TargetGroupVH.java    From pacbot with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the targets.
 *
 * @return the targets
 */
public List<TargetHealthDescription> getTargets() {
	return targets;
}