Search in sources :

Example 76 with Filter

use of com.amazonaws.services.s3.model.Filter in project openvidu-loadtest by OpenVidu.

the class Ec2Client method terminateAllInstances.

public void terminateAllInstances() {
    Filter workerTagFilter = getTagWorkerFilter();
    List<Instance> instancesToTerminate = getInstanceWithFilters(workerTagFilter);
    List<String> instancesToTerminateIds = getInstanceIds(instancesToTerminate);
    terminateInstance(instancesToTerminateIds);
}
Also used : Filter(com.amazonaws.services.ec2.model.Filter) Instance(com.amazonaws.services.ec2.model.Instance)

Example 77 with Filter

use of com.amazonaws.services.s3.model.Filter in project openvidu-loadtest by OpenVidu.

the class Ec2Client method launchAndCleanAux.

private List<Instance> launchAndCleanAux(WorkerType workerType, Filter tagFilter, int numberAtBeginning) {
    List<Instance> resultList = new ArrayList<Instance>();
    Filter runningFilter = getInstanceStateFilter(InstanceStateName.Running);
    Filter stoppedFilter = getInstanceStateFilter(InstanceStateName.Stopped);
    List<Instance> runningInstances = getInstanceWithFilters(tagFilter, runningFilter);
    List<Instance> stoppedInstances = getInstanceWithFilters(tagFilter, stoppedFilter);
    if (runningInstances.size() > 0) {
        resultList.addAll(runningInstances);
    }
    if (stoppedInstances.size() > 0 && resultList.size() < numberAtBeginning) {
        List<Instance> subList = new ArrayList<Instance>();
        if ((stoppedInstances.size() + resultList.size()) > numberAtBeginning) {
            for (int i = 0; i < numberAtBeginning; i++) {
                subList.add(stoppedInstances.get(i));
            }
        } else {
            subList = stoppedInstances;
        }
        startInstances(getInstanceIds(subList));
        for (int i = 0; i < subList.size(); i++) {
            resultList.add(waitUntilInstanceState(subList.get(i).getInstanceId(), InstanceStateName.Running));
        }
    }
    List<String> instanceIds = getInstanceIds(resultList);
    log.info("{} EC2 instances found ({})", resultList.size(), workerType.getValue());
    if (!instanceIds.isEmpty()) {
        // Clean launched instances
        rebootInstance(instanceIds);
        for (String id : instanceIds) {
            waitUntilInstanceState(id, InstanceStateName.Running);
        }
    }
    if (resultList.size() < numberAtBeginning) {
        log.info("Launching {} instance(s)", numberAtBeginning - resultList.size());
        resultList.addAll(launchInstance(numberAtBeginning - resultList.size(), workerType));
    }
    this.sleep(WAIT_RUNNING_STATE_MS);
    return resultList;
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) Filter(com.amazonaws.services.ec2.model.Filter) ArrayList(java.util.ArrayList)

Example 78 with Filter

use of com.amazonaws.services.s3.model.Filter in project openvidu-loadtest by OpenVidu.

the class Ec2Client method launchInstance.

public List<Instance> launchInstance(int number, WorkerType workerType) {
    Filter workerTagFilter = null;
    if (workerType == WorkerType.RECORDING_WORKER) {
        workerTagFilter = getTagRecordingFilter();
    } else {
        workerTagFilter = getTagWorkerFilter();
    }
    Filter stoppedFilter = getInstanceStateFilter(InstanceStateName.Stopped);
    List<Instance> stoppedInstances = getInstanceWithFilters(workerTagFilter, stoppedFilter);
    if (stoppedInstances.size() == number) {
        startInstances(getInstanceIds(stoppedInstances));
        return Arrays.asList(waitUntilInstanceState(stoppedInstances.get(0).getInstanceId(), InstanceStateName.Running));
    } else if (stoppedInstances.size() > number) {
        List<Instance> subList = new ArrayList<Instance>();
        List<Instance> result = new ArrayList<Instance>();
        for (int i = 0; i < number; i++) {
            subList.add(stoppedInstances.get(i));
        }
        startInstances(getInstanceIds(subList));
        for (Instance instance : subList) {
            result.add(waitUntilInstanceState(instance.getInstanceId(), InstanceStateName.Running));
        }
        return result;
    } else {
        startInstances(getInstanceIds(stoppedInstances));
        List<Tag> tags = new ArrayList<Tag>();
        if (workerType.equals(WorkerType.RECORDING_WORKER)) {
            tags.add(RECORDING_NAME_TAG);
            tags.add(RECORDING_TAG);
        } else {
            tags.add(NAME_TAG);
            tags.add(LOADTEST_WORKER_TAG);
        }
        List<Instance> result = this.launchInstance(number - stoppedInstances.size(), tags);
        result.addAll(stoppedInstances);
        return result;
    }
}
Also used : Filter(com.amazonaws.services.ec2.model.Filter) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.amazonaws.services.ec2.model.Tag)

Example 79 with Filter

use of com.amazonaws.services.s3.model.Filter in project openvidu-loadtest by OpenVidu.

the class Ec2Client method launchRecordingInstance.

public List<Instance> launchRecordingInstance(int number) {
    Filter recordingFilter = getTagRecordingFilter();
    // Filter runningFilter = getInstanceStateFilter(InstanceStateName.Running);
    Filter stoppedFilter = getInstanceStateFilter(InstanceStateName.Stopped);
    // List<Instance> runningInstance = getInstanceWithFilters(recordingFilter, runningFilter);
    List<Instance> stoppedInstance = getInstanceWithFilters(recordingFilter, stoppedFilter);
    if (stoppedInstance.size() > 0) {
        startInstances(Arrays.asList(stoppedInstance.get(0).getInstanceId()));
        Instance instanceReady = waitUntilInstanceState(stoppedInstance.get(0).getInstanceId(), InstanceStateName.Running);
        return Arrays.asList(instanceReady);
    }
    List<Tag> tags = new ArrayList<Tag>();
    tags.add(RECORDING_NAME_TAG);
    tags.add(RECORDING_TAG);
    return this.launchInstance(number, tags);
}
Also used : Filter(com.amazonaws.services.ec2.model.Filter) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) Tag(com.amazonaws.services.ec2.model.Tag)

Example 80 with Filter

use of com.amazonaws.services.s3.model.Filter in project druid by apache.

the class EC2AutoScaler method idToIpLookup.

@Override
public List<String> idToIpLookup(List<String> nodeIds) {
    final List<String> retVal = FluentIterable.from(Lists.partition(nodeIds, MAX_AWS_FILTER_VALUES)).transformAndConcat(new Function<List<String>, Iterable<Reservation>>() {

        @Override
        public Iterable<Reservation> apply(List<String> input) {
            return amazonEC2Client.describeInstances(new DescribeInstancesRequest().withFilters(new Filter("instance-id", input))).getReservations();
        }
    }).transformAndConcat(new Function<Reservation, Iterable<Instance>>() {

        @Override
        public Iterable<Instance> apply(Reservation reservation) {
            return reservation.getInstances();
        }
    }).transform(new Function<Instance, String>() {

        @Override
        public String apply(Instance instance) {
            return instance.getPrivateIpAddress();
        }
    }).toList();
    log.debug("Performing lookup: %s --> %s", nodeIds, retVal);
    return retVal;
}
Also used : Function(com.google.common.base.Function) Reservation(com.amazonaws.services.ec2.model.Reservation) FluentIterable(com.google.common.collect.FluentIterable) Filter(com.amazonaws.services.ec2.model.Filter) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) List(java.util.List) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest)

Aggregations

Filter (com.amazonaws.services.ec2.model.Filter)96 ArrayList (java.util.ArrayList)70 List (java.util.List)52 Collectors (java.util.stream.Collectors)46 IOException (java.io.IOException)41 HashMap (java.util.HashMap)38 Map (java.util.Map)35 AmazonS3 (com.amazonaws.services.s3.AmazonS3)34 Set (java.util.Set)31 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)30 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)27 Instance (com.amazonaws.services.ec2.model.Instance)26 HashSet (java.util.HashSet)26 Reservation (com.amazonaws.services.ec2.model.Reservation)24 Collections (java.util.Collections)23 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)21 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)21 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)20 Entry (java.util.Map.Entry)20 Tag (com.amazonaws.services.ec2.model.Tag)18