use of com.google.api.services.notebooks.v1.model.Instance 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.google.api.services.notebooks.v1.model.Instance 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.google.api.services.notebooks.v1.model.Instance 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.google.api.services.notebooks.v1.model.Instance in project openvidu-loadtest by OpenVidu.
the class Ec2Client method launchInstance.
private List<Instance> launchInstance(int number, List<Tag> tags) {
TagSpecification tagSpecification = new TagSpecification().withResourceType(ResourceType.Instance).withTags(tags);
RunInstancesRequest ec2request = new RunInstancesRequest().withImageId(AMI_ID).withInstanceType(INSTANCE_TYPE).withTagSpecifications(tagSpecification).withMaxCount(number).withMinCount(1).withBlockDeviceMappings(new BlockDeviceMapping().withDeviceName("/dev/sda1").withEbs(new EbsBlockDevice().withVolumeSize(50).withDeleteOnTermination(true)));
if (!this.loadTestConfig.getWorkerInstanceKeyPair().isBlank()) {
ec2request.withKeyName(this.loadTestConfig.getWorkerInstanceKeyPair());
}
if (!SECURITY_GROUP_ID.isEmpty()) {
ec2request.withSecurityGroupIds(SECURITY_GROUP_ID);
}
RunInstancesResult ec2response = ec2.runInstances(ec2request);
List<Instance> ec2InstanceList = new ArrayList<Instance>();
for (Instance instance : ec2response.getReservation().getInstances()) {
// Need to get the instance periodically to obtain all properties updated
ec2InstanceList.add(waitUntilInstanceState(instance.getInstanceId(), InstanceStateName.Running));
log.info("Successfully started EC2 instance");
}
return ec2InstanceList;
}
use of com.google.api.services.notebooks.v1.model.Instance in project openvidu-loadtest by OpenVidu.
the class LoadTestController method disconnectAllSessions.
private void disconnectAllSessions() {
List<String> workersUrl = devWorkersList;
for (WebSocketClient ws : wsSessions) {
ws.close();
}
wsSessions.clear();
if (PROD_MODE) {
// Add all ec2 instances
for (Instance ec2 : awsWorkersList) {
workersUrl.add(ec2.getPublicDnsName());
}
for (Instance recordingEc2 : recordingWorkersList) {
workersUrl.add(recordingEc2.getPublicDnsName());
}
browserEmulatorClient.disconnectAll(workersUrl);
ec2Client.stopInstance(recordingWorkersList);
ec2Client.stopInstance(awsWorkersList);
Date stopDate = new Date();
workerTimes = workerStartTimes.stream().map(startTime -> TimeUnit.MINUTES.convert(stopDate.getTime() - startTime.getTime(), TimeUnit.MILLISECONDS)).collect(Collectors.toList());
recordingWorkerTimes = recordingWorkerStartTimes.stream().map(startTime -> TimeUnit.MINUTES.convert(stopDate.getTime() - startTime.getTime(), TimeUnit.MILLISECONDS)).collect(Collectors.toList());
awsWorkersList = new ArrayList<Instance>();
recordingWorkersList = new ArrayList<Instance>();
} else {
browserEmulatorClient.disconnectAll(workersUrl);
}
}
Aggregations