Search in sources :

Example 71 with Instance

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;
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) Filter(com.amazonaws.services.ec2.model.Filter) ArrayList(java.util.ArrayList)

Example 72 with Instance

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;
    }
}
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 73 with Instance

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);
}
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 74 with Instance

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;
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) EbsBlockDevice(com.amazonaws.services.ec2.model.EbsBlockDevice) ArrayList(java.util.ArrayList) BlockDeviceMapping(com.amazonaws.services.ec2.model.BlockDeviceMapping) RunInstancesRequest(com.amazonaws.services.ec2.model.RunInstancesRequest) TagSpecification(com.amazonaws.services.ec2.model.TagSpecification)

Example 75 with Instance

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);
    }
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) WebSocketClient(io.openvidu.loadtest.services.WebSocketClient) Date(java.util.Date)

Aggregations

Instance (com.amazonaws.services.ec2.model.Instance)185 Reservation (com.amazonaws.services.ec2.model.Reservation)84 ArrayList (java.util.ArrayList)82 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)71 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)48 List (java.util.List)48 Tag (com.amazonaws.services.ec2.model.Tag)41 Test (org.junit.jupiter.api.Test)38 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)36 Map (java.util.Map)36 Collectors (java.util.stream.Collectors)32 HashMap (java.util.HashMap)26 Filter (com.amazonaws.services.ec2.model.Filter)25 Set (java.util.Set)23 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)22 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)20 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)18 InstanceState (com.amazonaws.services.ec2.model.InstanceState)18 Volume (com.amazonaws.services.ec2.model.Volume)18 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)18