List of usage examples for com.amazonaws.services.ecs.model Service getServiceName
public String getServiceName()
The name of your service.
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 a va2 s . 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
@Override public DeploymentResult operate(List priorOutputs) { updateTaskStatus("Initializing Create Amazon ECS Server Group Operation..."); AmazonCredentials credentials = getCredentials(); AmazonECS ecs = getAmazonEcsClient(); String serverGroupVersion = inferNextServerGroupVersion(ecs); updateTaskStatus("Creating Amazon ECS Task Definition..."); TaskDefinition taskDefinition = registerTaskDefinition(ecs, serverGroupVersion); updateTaskStatus("Done creating Amazon ECS Task Definition..."); String ecsServiceRole = inferAssumedRoleArn(credentials); Service service = createService(ecs, taskDefinition, ecsServiceRole, serverGroupVersion); String resourceId = registerAutoScalingGroup(credentials, service); if (!description.getAutoscalingPolicies().isEmpty()) { List<String> alarmNames = description.getAutoscalingPolicies().stream().map(MetricAlarm::getAlarmName) .collect(Collectors.toList()); ecsCloudMetricService.associateAsgWithMetrics(description.getCredentialAccount(), getRegion(), alarmNames, service.getServiceName(), resourceId); }/* w w w. j a va 2 s. c o m*/ return makeDeploymentResult(service); }
From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.ops.CreateServerGroupAtomicOperation.java
License:Apache License
private String registerAutoScalingGroup(AmazonCredentials credentials, Service service) { AWSApplicationAutoScaling autoScalingClient = getAmazonApplicationAutoScalingClient(); String assumedRoleArn = inferAssumedRoleArn(credentials); RegisterScalableTargetRequest request = new RegisterScalableTargetRequest() .withServiceNamespace(ServiceNamespace.Ecs) .withScalableDimension(ScalableDimension.EcsServiceDesiredCount) .withResourceId(/*from ww w.j a va 2 s.c om*/ String.format("service/%s/%s", description.getEcsClusterName(), service.getServiceName())) .withRoleARN(assumedRoleArn).withMinCapacity(description.getCapacity().getMin()) .withMaxCapacity(description.getCapacity().getMax()); updateTaskStatus("Creating Amazon Application Auto Scaling Scalable Target Definition..."); autoScalingClient.registerScalableTarget(request); updateTaskStatus("Done creating Amazon Application Auto Scaling Scalable Target Definition."); return request.getResourceId(); }
From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.ops.CreateServerGroupAtomicOperation.java
License:Apache License
private DeploymentResult makeDeploymentResult(Service service) { Map<String, String> namesByRegion = new HashMap<>(); namesByRegion.put(getRegion(), service.getServiceName()); DeploymentResult result = new DeploymentResult(); result.setServerGroupNames(Arrays.asList(getServerGroupName(service))); result.setServerGroupNameByRegion(namesByRegion); return result; }
From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.ops.CreateServerGroupAtomicOperation.java
License:Apache License
private String getServerGroupName(Service service) { // See in Orca MonitorKatoTask#getServerGroupNames for a reason for this return getRegion() + ":" + service.getServiceName(); }
From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.ops.ResizeServiceAtomicOperation.java
License:Apache License
private void resizeAutoScalingGroup(Service service) { AWSApplicationAutoScaling autoScalingClient = getAmazonApplicationAutoScalingClient(); Integer desiredCount = description.getCapacity().getDesired(); String ecsClusterName = containerInformationService.getClusterName(service.getServiceName(), description.getAccount(), description.getRegion()); RegisterScalableTargetRequest request = new RegisterScalableTargetRequest() .withServiceNamespace(ServiceNamespace.Ecs) .withScalableDimension(ScalableDimension.EcsServiceDesiredCount) .withResourceId(String.format("service/%s/%s", ecsClusterName, service.getServiceName())) .withRoleARN(service.getRoleArn()).withMinCapacity(description.getCapacity().getMin()) .withMaxCapacity(description.getCapacity().getMax()); updateTaskStatus(String.format("Resizing Scalable Target of %s to %s instances", service.getServiceName(), desiredCount));// w ww .j a v a 2s . co m autoScalingClient.registerScalableTarget(request); updateTaskStatus(String.format("Done resizing Scalable Target of %s to %s instances", service.getServiceName(), desiredCount)); }
From source file:com.netflix.spinnaker.clouddriver.ecs.provider.agent.ServiceCachingAgent.java
License:Apache License
public static Map<String, Object> convertServiceToAttributes(String accountName, String region, Service service) { Map<String, Object> attributes = new HashMap<>(); String applicationName = service.getServiceName().contains("-") ? StringUtils.substringBefore(service.getServiceName(), "-") : service.getServiceName();/*w ww . j a v a2 s .c om*/ String clusterName = StringUtils.substringAfterLast(service.getClusterArn(), "/"); attributes.put("account", accountName); attributes.put("region", region); attributes.put("applicationName", applicationName); attributes.put("serviceName", service.getServiceName()); attributes.put("serviceArn", service.getServiceArn()); attributes.put("clusterName", clusterName); attributes.put("clusterArn", service.getClusterArn()); attributes.put("roleArn", service.getRoleArn()); attributes.put("taskDefinition", service.getTaskDefinition()); attributes.put("desiredCount", service.getDesiredCount()); attributes.put("maximumPercent", service.getDeploymentConfiguration().getMaximumPercent()); attributes.put("minimumHealthyPercent", service.getDeploymentConfiguration().getMinimumHealthyPercent()); attributes.put("loadBalancers", service.getLoadBalancers()); attributes.put("createdAt", service.getCreatedAt().getTime()); return attributes; }
From source file:com.netflix.spinnaker.clouddriver.ecs.provider.agent.ServiceCachingAgent.java
License:Apache License
@Override protected Map<String, Collection<CacheData>> generateFreshData(Collection<Service> services) { Collection<CacheData> dataPoints = new LinkedList<>(); Map<String, CacheData> clusterDataPoints = new HashMap<>(); for (Service service : services) { Map<String, Object> attributes = convertServiceToAttributes(accountName, region, service); String key = Keys.getServiceKey(accountName, region, service.getServiceName()); dataPoints.add(new DefaultCacheData(key, attributes, Collections.emptyMap())); Map<String, Object> clusterAttributes = EcsClusterCachingAgent .convertClusterArnToAttributes(accountName, region, service.getClusterArn()); String clusterName = StringUtils.substringAfterLast(service.getClusterArn(), "/"); key = Keys.getClusterKey(accountName, region, clusterName); clusterDataPoints.put(key, new DefaultCacheData(key, clusterAttributes, Collections.emptyMap())); }//from w w w . j ava 2 s . c o m log.info("Caching " + dataPoints.size() + " services in " + getAgentType()); Map<String, Collection<CacheData>> dataMap = new HashMap<>(); dataMap.put(SERVICES.toString(), dataPoints); log.info("Caching " + clusterDataPoints.size() + " ECS clusters in " + getAgentType()); dataMap.put(ECS_CLUSTERS.toString(), clusterDataPoints.values()); return dataMap; }