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

The following examples show how to use com.amazonaws.services.elasticloadbalancingv2.model.DeregisterTargetsRequest. 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: ELBDeregisterInstanceStep.java    From pipeline-aws-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected String run() throws Exception {
	TaskListener listener = this.getContext().get(TaskListener.class);
	listener.getLogger().println("elbDeregisterInstance instanceID: " + this.step.instanceID + " port: " + this.step.port + " from targetGroupARN: " + this.step.targetGroupARN);
	ArrayList<TargetDescription> arr = new ArrayList<TargetDescription>();
	arr.add(new TargetDescription().withId(this.step.instanceID).withPort(this.step.port));
	DeregisterTargetsRequest request = new DeregisterTargetsRequest().withTargetGroupArn(this.step.targetGroupARN).withTargets( arr );
	AmazonElasticLoadBalancing client = AWSClientFactory.create(AmazonElasticLoadBalancingClientBuilder.standard(), this.getEnvVars());
	client.deregisterTargets(request);
	
	DescribeTargetHealthRequest req = new DescribeTargetHealthRequest().withTargetGroupArn(this.step.targetGroupARN);
	DescribeTargetHealthResult res = client.describeTargetHealth(req);
	listener.getLogger().println(res.toString());
	
	return null;
}
 
Example #2
Source File: AwsLoadBalancerConnector.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public Completable deregisterAll(String loadBalancerId, Set<String> ipAddresses) {
    if (CollectionsExt.isNullOrEmpty(ipAddresses)) {
        return Completable.complete();
    }

    // TODO: retry logic
    // TODO: handle partial failures in the batch
    // TODO: timeouts

    final DeregisterTargetsRequest request = new DeregisterTargetsRequest()
            .withTargetGroupArn(loadBalancerId)
            .withTargets(ipAddresses.stream().map(
                    ipAddress -> new TargetDescription().withId(ipAddress)
            ).collect(Collectors.toSet()));

    long startTime = registry.clock().wallTime();
    // force observeOn(scheduler) since the callback will be called from the AWS SDK threadpool
    return AwsObservableExt.asyncActionCompletable(supplier -> getClient(loadBalancerId).deregisterTargetsAsync(request, supplier.handler(
            (req, resp) -> {
                logger.debug("Deregistered targets {}", resp);
                connectorMetrics.success(AwsLoadBalancerConnectorMetrics.AwsLoadBalancerMethods.DeregisterTargets, startTime);
            },
            (t) -> {
                logger.error("Error deregistering targets on " + loadBalancerId, t);
                connectorMetrics.failure(AwsLoadBalancerConnectorMetrics.AwsLoadBalancerMethods.DeregisterTargets, t, startTime);
            }
    ))).observeOn(scheduler);
}
 
Example #3
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
public AgentCheckInResponse removeInstance(String id, String trafficSourceName) {

    Optional<TargetGroup> maybeTargetGroup = getTargetGroup(trafficSourceName);
    if (maybeTargetGroup.isPresent()) {
      TargetGroup targetGroup = maybeTargetGroup.get();
      TargetDescription targetDescription = new TargetDescription()
          .withId(id);
      if (targetsOn(targetGroup).contains(targetDescription.getId())) {
        DeregisterTargetsRequest deregisterTargetsRequest = new DeregisterTargetsRequest()
            .withTargets(targetDescription)
            .withTargetGroupArn(targetGroup.getTargetGroupArn());
        try {
          elbClient.deregisterTargets(deregisterTargetsRequest);
          LOG.info("De-registered instance {} from target group {}", id, targetGroup);
          return getShutdownResponse(targetGroup.getTargetGroupArn(), targetDescription, true);
        } catch (AmazonServiceException exn) {
          LOG.warn("Failed to de-register instance {} from target group {}", id, targetGroup);
        }
      } else {
        LOG.debug("Instance {} not found at target group {}", id, targetGroup);
      }
    } else {
      LOG.debug("No target group found with name {}", trafficSourceName);
    }

    return new AgentCheckInResponse(TrafficSourceState.DONE, Optional.absent(), 0L);
  }
 
Example #4
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
/**
 * De-register any targets representing agents that are not known to the BaragonService,
 * or which otherwise need to be removed.
 *
 * @param targetGroup TargetGroup to check for old agents
 * @param agents Known agents, to be used as a reference sheet
 */
private void deregisterRemovableTargets(TrafficSource trafficSource,
                                        BaragonGroup baragonGroup,
                                        TargetGroup targetGroup,
                                        Collection<BaragonAgentMetadata> agents,
                                        Collection<TargetDescription> targets) {
  Collection<TargetDescription> removableTargets = listRemovableTargets(trafficSource, baragonGroup, targets, agents);

  for (TargetDescription removableTarget : removableTargets) {
    try {
      if (configuration.isPresent()
          && !configuration.get().isRemoveLastHealthyEnabled()
          && isLastHealthyInstance(removableTarget, targetGroup)) {
        LOG.info("Will not de-register target {} because it is last healthy instance in {}", removableTarget, targetGroup);
      } else {
        elbClient.deregisterTargets(new DeregisterTargetsRequest()
            .withTargetGroupArn(targetGroup.getTargetGroupArn())
            .withTargets(removableTarget));
        LOG.info("De-registered target {} from target group {}", removableTarget, targetGroup);
      }
    } catch (AmazonClientException acexn) {
      LOG.error("Could not de-register target {} from target group {} due to error",
          removableTarget, targetGroup, acexn);
      exceptionNotifier.notify(acexn, ImmutableMap
          .of("targetGroup", targetGroup.getTargetGroupName()));
    }
  }
}