Example usage for com.amazonaws.services.ecs.model ListServicesResult getServiceArns

List of usage examples for com.amazonaws.services.ecs.model ListServicesResult getServiceArns

Introduction

In this page you can find the example usage for com.amazonaws.services.ecs.model ListServicesResult getServiceArns.

Prototype


public java.util.List<String> getServiceArns() 

Source Link

Document

The list of full ARN entries for each service associated with the specified cluster.

Usage

From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.EcsServerGroupNameResolver.java

License:Open Source License

@Override
public List<TakenSlot> getTakenSlots(String familyName) {
    List<String> relevantServices = new ArrayList<>();
    String nextToken = null;/*from  w  w  w. j av  a2s . c  om*/
    do {
        ListServicesRequest request = new ListServicesRequest().withCluster(ecsClusterName);
        if (nextToken != null) {
            request.setNextToken(nextToken);
        }

        ListServicesResult result = ecs.listServices(request);
        for (String serviceArn : result.getServiceArns()) {
            if (serviceArn.contains(familyName)) {
                relevantServices.add(serviceArn);
            }
        }

        nextToken = result.getNextToken();
    } while (nextToken != null && nextToken.length() != 0);

    List<TakenSlot> slots = new ArrayList<>();
    List<List<String>> serviceBatches = Lists.partition(relevantServices, 10);
    for (List<String> serviceBatch : serviceBatches) {
        DescribeServicesRequest request = new DescribeServicesRequest().withCluster(ecsClusterName)
                .withServices(serviceBatch);
        DescribeServicesResult result = ecs.describeServices(request);
        for (Service service : result.getServices()) {
            Names names = Names.parseName(service.getServiceName());
            slots.add(new TakenSlot(service.getServiceName(), names.getSequence(), service.getCreatedAt()));
        }
    }

    return slots;
}

From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.ops.CreateServerGroupAtomicOperation.java

License:Apache License

private String inferNextServerGroupVersion(AmazonECS ecs) {
    int latestVersion = 0;
    String familyName = getFamilyName();

    String nextToken = null;/*from  w  w  w. ja v  a2  s .  c o  m*/
    do {
        ListServicesRequest request = new ListServicesRequest().withCluster(description.getEcsClusterName());
        if (nextToken != null) {
            request.setNextToken(nextToken);
        }

        ListServicesResult result = ecs.listServices(request);
        for (String serviceArn : result.getServiceArns()) {
            if (serviceArn.contains(familyName)) {
                int currentVersion;
                try {
                    String versionString = StringUtils.substringAfterLast(serviceArn, "-").replaceAll("v", "");
                    currentVersion = Integer.parseInt(versionString);
                } catch (NumberFormatException e) {
                    currentVersion = 0;
                }
                latestVersion = Math.max(currentVersion, latestVersion);
            }
        }

        nextToken = result.getNextToken();
    } while (nextToken != null && nextToken.length() != 0);

    return String.format("v%04d", (latestVersion + 1));
}

From source file:com.netflix.spinnaker.clouddriver.ecs.provider.agent.ServiceCachingAgent.java

License:Apache License

@Override
protected List<Service> getItems(AmazonECS ecs, ProviderCache providerCache) {
    List<Service> serviceList = new LinkedList<>();
    Set<String> clusters = getClusters(ecs, providerCache);

    for (String cluster : clusters) {
        String nextToken = null;//from www  .  j  a v  a  2s  . co m
        do {
            ListServicesRequest listServicesRequest = new ListServicesRequest().withCluster(cluster);
            if (nextToken != null) {
                listServicesRequest.setNextToken(nextToken);
            }
            ListServicesResult listServicesResult = ecs.listServices(listServicesRequest);
            List<String> serviceArns = listServicesResult.getServiceArns();
            if (serviceArns.size() == 0) {
                continue;
            }

            List<Service> services = ecs
                    .describeServices(
                            new DescribeServicesRequest().withCluster(cluster).withServices(serviceArns))
                    .getServices();
            serviceList.addAll(services);

            nextToken = listServicesResult.getNextToken();
        } while (nextToken != null && nextToken.length() != 0);
    }
    return serviceList;
}