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);
}
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;
}
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;
}
}
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);
}
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;
}
Aggregations