当前位置: 首页>>代码示例>>Java>>正文


Java RegisterInstancesWithLoadBalancerRequest类代码示例

本文整理汇总了Java中com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest的典型用法代码示例。如果您正苦于以下问题:Java RegisterInstancesWithLoadBalancerRequest类的具体用法?Java RegisterInstancesWithLoadBalancerRequest怎么用?Java RegisterInstancesWithLoadBalancerRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RegisterInstancesWithLoadBalancerRequest类属于com.amazonaws.services.elasticloadbalancing.model包,在下文中一共展示了RegisterInstancesWithLoadBalancerRequest类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerInstance

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
/**
 * Requests registration of the ec2 instance with the ELB.
 * <p/>
 * After calling here, you need to call DescribeLoadBalancers or DescribeInstanceHealth to see if registration is
 * complete.
 */
public void registerInstance(String elbName, String ec2InstanceId)
{
  LOGGER.debug("registerInstancesWithLoadBalancer(elbName: " + elbName + ", ec2InstanceId: " + ec2InstanceId + ")");
  assertNonBlankArgs(elbName, ec2InstanceId);
  StopWatch stopWatch = new StopWatch();
  try
  {
    stopWatch.start();
    RegisterInstancesWithLoadBalancerRequest request = new RegisterInstancesWithLoadBalancerRequest();
    request.setLoadBalancerName(elbName);
    request.setInstances(Arrays.asList(new Instance(ec2InstanceId)));
    awsElbClient.registerInstancesWithLoadBalancer(request);
    //Currently not doing anything with the RegisterInstancesWithLoadBalancerResult
  }
  finally
  {
    stopWatch.stop();
    LOGGER.debug("registerInstancesWithLoadBalancer time elapsed " + stopWatch);
  }
}
 
开发者ID:Nike-Inc,项目名称:bluegreen-manager,代码行数:27,代码来源:ElbClient.java

示例2: registerInstances

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
private DeferredResult<AWSLoadBalancerContext> registerInstances(
        AWSLoadBalancerContext context) {
    // Do not try to assign instances if there aren't any
    if (context.instanceIdsToRegister.isEmpty()) {
        return DeferredResult.completed(context);
    }

    RegisterInstancesWithLoadBalancerRequest request = buildInstanceRegistrationRequest(
            context);

    String message = "Registering instances to AWS Load Balancer with name ["
            + context.loadBalancerStateExpanded.name + "]";
    AWSDeferredResultAsyncHandler<RegisterInstancesWithLoadBalancerRequest, RegisterInstancesWithLoadBalancerResult> handler =
            new AWSDeferredResultAsyncHandler<>(this, message);

    context.client.registerInstancesWithLoadBalancerAsync(request, handler);

    return handler.toDeferredResult()
            .thenApply(ignore -> context);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:21,代码来源:AWSLoadBalancerService.java

示例3: registerAWSInstancesToLoadBalancer

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
private static void registerAWSInstancesToLoadBalancer(VerificationHost host,
        AmazonElasticLoadBalancingAsyncClient client, String name, List<String> instanceIds) {
    RegisterInstancesWithLoadBalancerRequest registerRequest = new RegisterInstancesWithLoadBalancerRequest()
            .withLoadBalancerName(name)
            .withInstances(instanceIds.stream()
                    .map(com.amazonaws.services.elasticloadbalancing.model.Instance::new)
                    .collect(Collectors.toList())
            );

    RegisterInstancesWithLoadBalancerResult result = null;
    try {
        result = client.registerInstancesWithLoadBalancer(registerRequest);
    } catch (Exception e) {
        host.log(Level.SEVERE, "Error registering instances with load balancer %s",
                Utils.toString(e));
    }

    assertNotNull(result);
    assertFalse(result.getInstances().isEmpty());
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:21,代码来源:TestAWSSetupUtils.java

示例4: addInstancesToLoadBalancer

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
public static void addInstancesToLoadBalancer(String name,
		String... instanceIds) {
	if (name == null || name.trim().length() == 0)
		throw new RuntimeException(
				"The name of the load balancer cannot be empty!");

	if (instanceIds == null || instanceIds.length == 0)
		throw new RuntimeException(
				"You need to specify at least one instance id!");

	connect();

	ArrayList<com.amazonaws.services.elasticloadbalancing.model.Instance> instances = new ArrayList<com.amazonaws.services.elasticloadbalancing.model.Instance>();
	for (String instanceId : instanceIds)
		instances
				.add(new com.amazonaws.services.elasticloadbalancing.model.Instance(
						instanceId));

	RegisterInstancesWithLoadBalancerRequest req = new RegisterInstancesWithLoadBalancerRequest(
			name, instances);
	client.registerInstancesWithLoadBalancer(req);
}
 
开发者ID:rickdesantis,项目名称:cloud-runner,代码行数:23,代码来源:ElasticLoadBalancing.java

示例5: registerInstance

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
public AgentCheckInResponse registerInstance(Instance instance, String elbName, BaragonAgentMetadata agent) {
  Optional<String> maybeException = Optional.absent();
  Optional<LoadBalancerDescription> elb = getElb(elbName);
  if (elb.isPresent()) {
    if (isVpcOk(agent, elb.get())) {
      if (!elb.get().getInstances().contains(instance)) {
        checkAZEnabled(agent, elbName, elb.get());
        RegisterInstancesWithLoadBalancerRequest request = new RegisterInstancesWithLoadBalancerRequest(elbName, Arrays.asList(instance));
        elbClient.registerInstancesWithLoadBalancer(request);
        LOG.info("Registered instances {} with ELB {}", request.getInstances(), request.getLoadBalancerName());
      } else {
        LOG.debug("Agent {} already registered with ELB {}", agent.getAgentId(), elbName);
      }
    } else {
      maybeException = Optional.of(String.format("No ELB found for vpc %s", agent.getEc2().getVpcId()));
    }
  }
  return new AgentCheckInResponse(TrafficSourceState.DONE, maybeException, 0L);
}
 
开发者ID:HubSpot,项目名称:Baragon,代码行数:20,代码来源:ClassicLoadBalancer.java

示例6: registerNewInstances

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
private void registerNewInstances(List<LoadBalancerDescription> elbs, BaragonGroup group) {
  Collection<BaragonAgentMetadata> agents = loadBalancerDatastore.getAgentMetadata(group.getName());
  List<RegisterInstancesWithLoadBalancerRequest> requests = registerRequests(group, agents, elbs);
  if (!requests.isEmpty()) {
    for (RegisterInstancesWithLoadBalancerRequest request : requests) {
      try {
        elbClient.registerInstancesWithLoadBalancer(request);
        LOG.info("Registered instances {} with ELB {}", request.getInstances(), request.getLoadBalancerName());
      } catch (AmazonClientException e) {
        LOG.error("Could not register {} with elb {} due to error", request.getInstances(), request.getLoadBalancerName(), e);
        exceptionNotifier.notify(e, ImmutableMap.of("elb", request.getLoadBalancerName(), "toAdd", request.getInstances().toString()));
      }
    }
  } else {
    LOG.debug("No new instances to register for group {}", group.getName());
  }
}
 
开发者ID:HubSpot,项目名称:Baragon,代码行数:18,代码来源:ClassicLoadBalancer.java

示例7: testRegisterInstance

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
/**
 * Proves the client method is called.
 */
@Test
public void testRegisterInstance()
{
  elbClient.registerInstance(ELB_NAME, EC2_INSTANCE_ID);
  verify(mockELBClient).registerInstancesWithLoadBalancer(any(RegisterInstancesWithLoadBalancerRequest.class));
}
 
开发者ID:Nike-Inc,项目名称:bluegreen-manager,代码行数:10,代码来源:ElbClientTest.java

示例8: buildInstanceRegistrationRequest

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
private RegisterInstancesWithLoadBalancerRequest buildInstanceRegistrationRequest(
        AWSLoadBalancerContext context) {

    return new RegisterInstancesWithLoadBalancerRequest()
            .withLoadBalancerName(context.loadBalancerStateExpanded.name)
            .withInstances(context.instanceIdsToRegister.stream()
                    .map(Instance::new)
                    .collect(Collectors.toList())
            );
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:11,代码来源:AWSLoadBalancerService.java

示例9: attachInstances

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
public void attachInstances(String elbName, List<String> instanceIds, boolean waitUntilInService) throws InterruptedException {
    logger.info("attach instances to elb, elb={}, instances={}", elbName, instanceIds);

    String expectedState = waitUntilInService ? "InService" : "Service";    // if not waitUntilInService, state can be InService or OutOfService

    List<Instance> instances = instanceIds.stream().map(Instance::new).collect(Collectors.toList());

    elb.registerInstancesWithLoadBalancer(new RegisterInstancesWithLoadBalancerRequest()
        .withLoadBalancerName(elbName)
        .withInstances(instances));

    int attempts = 0;
    while (true) {
        attempts++;
        Threads.sleepRoughly(Duration.ofSeconds(15));

        List<InstanceState> states = describeInstanceHealth(elbName, instanceIds);

        for (InstanceState state : states) {
            logger.info("instance elb state {} => {}", state.getInstanceId(), state.getState());
        }

        boolean allAttached = states.stream().allMatch(state -> state.getState().contains(expectedState));
        if (allAttached) {
            logger.info("all instances are attached to elb");
            break;
        } else if (attempts >= 30) {
            throw new Error("failed to wait all instances to be attached to elb, please check aws console for more details");
        } else {
            logger.info("continue to wait, not all new instances are attached");
        }
    }
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:34,代码来源:ElasticLoadBalancing.java

示例10: registerInstances

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
public void registerInstances(List<Instance> instances, String lbName) {
	logger.info(String.format("Registering instances %s with loadbalancer %s", instances, lbName));
	RegisterInstancesWithLoadBalancerRequest regInstances = new RegisterInstancesWithLoadBalancerRequest();
	regInstances.setInstances(instances);
	regInstances.setLoadBalancerName(lbName);
	RegisterInstancesWithLoadBalancerResult result = elbClient.registerInstancesWithLoadBalancer(regInstances);
	
	logger.info("ELB Add instance call result: " + result.toString());	
}
 
开发者ID:cartwrightian,项目名称:cfnassist,代码行数:10,代码来源:LoadBalancerClient.java

示例11: addToElb

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
@POST
@Path("/{elbName}/update")
public RegisterInstancesWithLoadBalancerResult addToElb(@PathParam("elbName") String elbName, @QueryParam("instanceId") String instanceId) {
  if (config.isPresent()) {
    RegisterInstancesWithLoadBalancerRequest request = new RegisterInstancesWithLoadBalancerRequest(elbName, Arrays.asList(new Instance(instanceId)));
    return elbClient.registerInstancesWithLoadBalancer(request);
  } else {
    throw new BaragonWebException("ElbSync and related actions are not currently enabled");
  }
}
 
开发者ID:HubSpot,项目名称:Baragon,代码行数:11,代码来源:ElbResource.java

示例12: registerRequests

import com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest; //导入依赖的package包/类
private List<RegisterInstancesWithLoadBalancerRequest> registerRequests(BaragonGroup group, Collection<BaragonAgentMetadata> agents, List<LoadBalancerDescription> elbs) {
  List<RegisterInstancesWithLoadBalancerRequest> requests = new ArrayList<>();
  for (BaragonAgentMetadata agent : agents) {
    try {
      for (TrafficSource source : group.getTrafficSources()) {
        if (source.getType() != TrafficSourceType.CLASSIC) {
          continue;
        }
        if (agent.getEc2().getInstanceId().isPresent()) {
          if (shouldRegister(agent, source.getName(), elbs)) {
            Instance instance = new Instance(agent.getEc2().getInstanceId().get());
            requests.add(new RegisterInstancesWithLoadBalancerRequest(source.getName(), Arrays.asList(instance)));
            checkAZEnabled(agent, source.getName(), elbs);
            LOG.info("Will register {}-{} with ELB {}", agent.getAgentId(), agent.getEc2().getInstanceId().get(), source.getName());
          } else {
            LOG.debug("Agent {} is already registered", agent);
          }
        } else {
          throw new IllegalArgumentException(String.format("Agent Instance Id must be present to register with an ELB (agent: %s)", agent.getAgentId()));
        }
      }
    } catch (Exception e) {
      LOG.error("Could not create request for BaragonAgent {} due to error: {}", agent, e);
    }
  }
  return requests;
}
 
开发者ID:HubSpot,项目名称:Baragon,代码行数:28,代码来源:ClassicLoadBalancer.java


注:本文中的com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。