Java 类com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest 实例源码

项目:aem-orchestrator    文件:AwsHelperServiceTest.java   
@Test
public void testGetElbDnsName() {
    final LoadBalancerDescription description = new LoadBalancerDescription();
    description.setDNSName("testDnsName");

    final List<LoadBalancerDescription> descriptions = new ArrayList<>();
    descriptions.add(description);

    final DescribeLoadBalancersResult result = mock(DescribeLoadBalancersResult.class);
    when(result.getLoadBalancerDescriptions()).thenReturn(descriptions);

    when(amazonElbClient.describeLoadBalancers(any(DescribeLoadBalancersRequest.class))).thenReturn(result);

    final String elbName = "testElbName";
    assertThat(awsHelperService.getElbDnsName(elbName), equalTo(description.getDNSName()));

    final ArgumentCaptor<DescribeLoadBalancersRequest> argumentCaptor = ArgumentCaptor.forClass(DescribeLoadBalancersRequest.class);
    verify(amazonElbClient).describeLoadBalancers(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue().getLoadBalancerNames().get(0), equalTo(elbName));
}
项目:photon-model    文件:AWSLoadBalancerServiceTest.java   
private LoadBalancerDescription getAwsLoadBalancer(String name) {
    DescribeLoadBalancersRequest describeRequest = new DescribeLoadBalancersRequest()
            .withLoadBalancerNames(name);

    DescribeLoadBalancersResult describeResult = null;

    try {
        describeResult = this.client.describeLoadBalancers(describeRequest);
    } catch (Exception e) {
        this.host.log("Exception describing load balancers with name '%s': %s", name,
                e.toString());
    }

    Collection<LoadBalancerDescription> lbs =
            describeResult != null ? describeResult.getLoadBalancerDescriptions() : null;
    if (lbs == null || lbs.isEmpty()) {
        return null;
    }
    if (lbs.size() > 1) {
        throw new IllegalStateException(
                "More than one load balancers found with name '" + name + "'.");
    }
    return lbs.iterator().next();
}
项目:cloud-runner    文件:ElasticLoadBalancing.java   
public static String getLoadBalancerDNS(String name) {
    if (name == null || name.trim().length() == 0)
        throw new RuntimeException(
                "The name of the load balancer cannot be empty!");

    connect();

    ArrayList<String> names = new ArrayList<String>();
    names.add(name);

    DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest(
            names);
    DescribeLoadBalancersResult res = client.describeLoadBalancers(req);
    List<LoadBalancerDescription> descs = res.getLoadBalancerDescriptions();
    if (descs.size() == 0 || descs.get(0) == null)
        return null;

    return descs.get(0).getDNSName();
}
项目:primecloud-controller    文件:AwsCommonProcess.java   
public LoadBalancerDescription describeLoadBalancer(AwsProcessClient awsProcessClient, String loadBalancerName) {
    // 単一ロードバランサの参照
    DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest();
    request.withLoadBalancerNames(loadBalancerName);
    DescribeLoadBalancersResult result = awsProcessClient.getElbClient().describeLoadBalancers(request);
    List<LoadBalancerDescription> descriptions = result.getLoadBalancerDescriptions();

    // API実行結果チェック
    if (descriptions.size() == 0) {
        // アドレスが存在しない場合
        throw new AutoException("EPROCESS-000131", loadBalancerName);

    } else if (descriptions.size() > 1) {
        // アドレスを複数参照できた場合
        AutoException exception = new AutoException("EPROCESS-000132", loadBalancerName);
        exception.addDetailInfo("result=" + descriptions);
        throw exception;
    }

    return descriptions.get(0);
}
项目:Baragon    文件:ElbResource.java   
@GET
@NoAuth
@Path("/{elbName}")
public LoadBalancerDescription getElb(@PathParam("elbName") String elbName) {
  if (config.isPresent()) {
    try {
      DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest(Arrays.asList(elbName));
      DescribeLoadBalancersResult result = elbClient.describeLoadBalancers(request);
      for (LoadBalancerDescription elb : result.getLoadBalancerDescriptions()) {
        if (elb.getLoadBalancerName().equals(elbName)) {
          return elb;
        }
      }
    } catch (AmazonClientException e) {
      throw new BaragonWebException(String.format("AWS Client Error: %s", e));
    }
    throw new BaragonNotFoundException(String.format("ELB with name %s not found", elbName));
  } else {
    throw new BaragonWebException("ElbSync and related actions are not currently enabled");
  }
}
项目:bluegreen-manager    文件:ElbClient.java   
/**
 * Returns a description of the named ELB.
 */
public LoadBalancerDescription describeLoadBalancer(String elbName)
{
  LOGGER.debug("describeLoadBalancers(elbName: " + elbName + ")");
  if (StringUtils.isBlank(elbName))
  {
    throw new IllegalArgumentException("Blank elbName");
  }
  StopWatch stopWatch = new StopWatch();
  try
  {
    stopWatch.start();
    DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest();
    request.setLoadBalancerNames(Arrays.asList(elbName));
    DescribeLoadBalancersResult result = awsElbClient.describeLoadBalancers(request);
    if (result == null || CollectionUtils.isEmpty(result.getLoadBalancerDescriptions()))
    {
      throw new RuntimeException("ELB '" + elbName + "' was not found");
    }
    else if (result.getLoadBalancerDescriptions().size() > 1)
    {
      LOGGER.warn("Expected 1 ELB description for elb name '" + elbName + "', found "
          + result.getLoadBalancerDescriptions().size());
    }
    return result.getLoadBalancerDescriptions().get(0);
  }
  finally
  {
    stopWatch.stop();
    LOGGER.debug("describeLoadBalancers time elapsed " + stopWatch);
  }
}
项目:photon-model    文件:AWSLoadBalancerService.java   
private DeferredResult<AWSLoadBalancerContext> getAWSLoadBalancer(
        AWSLoadBalancerContext context) {
    DescribeLoadBalancersRequest describeRequest = new DescribeLoadBalancersRequest()
            .withLoadBalancerNames(context.loadBalancerStateExpanded.name);

    String message =
            "Describing AWS load balancer [" + context.loadBalancerStateExpanded.name + "].";
    AWSDeferredResultAsyncHandler<DescribeLoadBalancersRequest, DescribeLoadBalancersResult> handler =
            new AWSDeferredResultAsyncHandler<>(this, message);

    context.client.describeLoadBalancersAsync(describeRequest, handler);

    return handler.toDeferredResult().thenCompose(result -> {

        List<com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription> lbs = result
                .getLoadBalancerDescriptions();

        if (lbs != null && !lbs.isEmpty() && lbs.size() == 1) {
            context.registeredInstances = lbs.iterator().next().getInstances();
            return DeferredResult.completed(context);
        }

        return DeferredResult.failed(new IllegalStateException(
                "Unable to describe load balancer with name '"
                        + context.loadBalancerStateExpanded.name + "' for update"));
    });
}
项目:photon-model    文件:AWSLoadBalancerEnumerationAdapterService.java   
@Override
protected DeferredResult<RemoteResourcesPage> getExternalResources(String nextPageLink) {
    DescribeLoadBalancersRequest describeRequest = new DescribeLoadBalancersRequest()
            .withPageSize(getQueryPageSize());

    if (nextPageLink != null) {
        describeRequest.setMarker(nextPageLink);
    }

    String msg =
            "Getting AWS Load Balancers [" + this.request.original.resourceReference + "]";

    AWSDeferredResultAsyncHandler<DescribeLoadBalancersRequest, DescribeLoadBalancersResult> asyncHandler =
            new AWSDeferredResultAsyncHandler<>(this.service, msg);

    this.amazonLoadBalancerClient.describeLoadBalancersAsync(describeRequest, asyncHandler);

    return asyncHandler.toDeferredResult().thenApply(describeLoadBalancersResult -> {
        RemoteResourcesPage page = new RemoteResourcesPage();
        page.nextPageLink = describeLoadBalancersResult.getNextMarker();

        describeLoadBalancersResult.getLoadBalancerDescriptions().forEach(
                lbDescription -> page.resourcesPage
                        .put(lbDescription.getLoadBalancerName(), lbDescription));

        return page;
    });
}
项目:vertx-deploy-tools    文件:AwsAutoScalingDeployUtils.java   
private List<ListenerDescription> describeMatchingElbListeners(String loadbalancerName, List<Integer> ports) {
    DescribeLoadBalancersResult loadbalancer = awsElbClient.describeLoadBalancers(new DescribeLoadBalancersRequest().withLoadBalancerNames(loadbalancerName));
    LoadBalancerDescription description = loadbalancer.getLoadBalancerDescriptions().get(0);
    return description.getListenerDescriptions().stream()
            .filter(d -> ports.contains(d.getListener().getLoadBalancerPort()))
            .filter(d -> d.getListener().getProtocol().startsWith("HTTP"))
            .collect(Collectors.toList());
}
项目:clouck    文件:ElbWrapperImpl.java   
@Override
public List<AbstractResource<?>> describeLoadBalancers(Account account, Region region, DateTime dt) {
    AmazonElasticLoadBalancing elb = findClient(account, region);

    DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest();

    log.debug("start describing elb for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region);
    DescribeLoadBalancersResult res = elb.describeLoadBalancers(req);
    return converter.toLoadBalancers(res.getLoadBalancerDescriptions(), account.getId(), region, dt);
}
项目:cfnassist    文件:LoadBalancerClient.java   
public List<LoadBalancerDescription> describeLoadBalancers() {
    DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest();
    DescribeLoadBalancersResult result = elbClient.describeLoadBalancers(request);
    List<LoadBalancerDescription> descriptions = result.getLoadBalancerDescriptions();
    logger.info(String.format("Found %s load balancers %s", descriptions.size(), descriptions));
    return descriptions;
}
项目:Baragon    文件:ClassicLoadBalancer.java   
private Optional<LoadBalancerDescription> getElb(String elbName) {
  DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest(Arrays.asList(elbName));
  DescribeLoadBalancersResult result = elbClient.describeLoadBalancers(request);
  if (!result.getLoadBalancerDescriptions().isEmpty()) {
    return Optional.of(result.getLoadBalancerDescriptions().get(0));
  } else {
    return Optional.absent();
  }
}
项目:aem-orchestrator    文件:AwsHelperService.java   
/**
 * Return the DNS name for a given AWS ELB group name
 * @param elbName the ELB group name
 * @return String DNS name
 */
public String getElbDnsName(String elbName) {
    DescribeLoadBalancersResult result = amazonElbClient.describeLoadBalancers(new DescribeLoadBalancersRequest()
        .withLoadBalancerNames(elbName));
    return result.getLoadBalancerDescriptions().get(0).getDNSName();
}
项目:bluegreen-manager    文件:ElbClientTest.java   
private void setupMock(DescribeLoadBalancersResult fakeResult)
{
  when(mockELBClient.describeLoadBalancers(any(DescribeLoadBalancersRequest.class))).thenReturn(fakeResult);
}
项目:fullstop    文件:FetchElasticLoadBalancersJobTest.java   
@Test
public void testCheck() throws Exception {
    when(accountIdSupplierMock.get()).thenReturn(newHashSet(ACCOUNT_ID));
    when(jobsPropertiesMock.getWhitelistedRegions()).thenReturn(regions);
    when(portsChecker.check(any(LoadBalancerDescription.class))).thenReturn(Collections.<Integer>emptyList());
    when(securityGroupsChecker.check(any(), any(), any())).thenReturn(emptyMap());
    when(mockAwsELBClient.describeLoadBalancers(any(DescribeLoadBalancersRequest.class))).thenReturn(mockDescribeELBResult);
    when(mockAwsELBClient.describeTags(any(DescribeTagsRequest.class))).thenReturn(mockDescribeTagsResult);
    when(mockAwsApplications.isPubliclyAccessible(anyString(), anyString(), anyListOf(String.class)))
            .thenReturn(Optional.of(false));

    final FetchElasticLoadBalancersJob fetchELBJob = new FetchElasticLoadBalancersJob(
            violationSinkMock,
            clientProviderMock,
            accountIdSupplierMock,
            jobsPropertiesMock,
            securityGroupsChecker,
            portsChecker,
            mockAwsApplications,
            mockViolationService,
            fetchTaupageYamlMock,
            mockAmiDetailsProvider,
            mockEC2InstanceProvider,
            mock(CloseableHttpClient.class),
            mock(JobExceptionHandler.class));

    fetchELBJob.run();

    verify(accountIdSupplierMock).get();
    verify(jobsPropertiesMock, atLeast(1)).getWhitelistedRegions();
    verify(jobsPropertiesMock).getElbAllowedPorts();
    verify(securityGroupsChecker, atLeast(1)).check(any(), any(), any());
    verify(portsChecker, atLeast(1)).check(any());
    verify(mockAwsELBClient).describeLoadBalancers(any(DescribeLoadBalancersRequest.class));
    // maximum 20 ELB names can be requested at once. So this needs to be split into two calls.
    verify(mockAwsELBClient, times(2)).describeTags(any(DescribeTagsRequest.class));
    verify(clientProviderMock).getClient(any(), any(String.class), any(Region.class));
    verify(mockAwsApplications).isPubliclyAccessible(eq(ACCOUNT_ID), eq(REGION1), eq(asList("i1", "i2")));
    verify(mockEC2InstanceProvider).getById(eq(ACCOUNT_ID), eq(getRegion(fromName(REGION1))), eq("i1"));
    verify(mockAmiDetailsProvider).getAmiDetails(eq(ACCOUNT_ID), eq(getRegion(fromName(REGION1))), eq("bar"));
}
项目:cmn-project    文件:ElasticLoadBalancing.java   
public LoadBalancerDescription describeELB(String elbName) {
    logger.info("describe elb, elbName={}", elbName);
    DescribeLoadBalancersResult result = elb.describeLoadBalancers(new DescribeLoadBalancersRequest()
        .withLoadBalancerNames(elbName));
    return result.getLoadBalancerDescriptions().get(0);
}