Search in sources :

Example 1 with ExamResources

use of org.openkilda.testing.service.traffexam.model.ExamResources in project open-kilda by telstra.

the class TraffExamServiceImpl method stopExam.

@Override
public void stopExam(Exam exam) throws NoResultsFoundException {
    ExamResources resources = retrieveExamResources(exam);
    List<HostResource> releaseQueue = new ArrayList<>(4);
    releaseQueue.add(resources.getProducer());
    releaseQueue.add(resources.getConsumer());
    UUID addressId;
    Address address;
    addressId = resources.getProducer().getBindAddressId();
    if (addressId != null) {
        address = suppliedAddresses.get(addressId);
        checkHostRelation(address, suppliedAddresses);
        releaseQueue.add(address);
    }
    addressId = resources.getConsumer().getBindAddressId();
    if (addressId != null) {
        address = suppliedAddresses.get(addressId);
        checkHostRelation(address, suppliedAddresses);
        releaseQueue.add(address);
    }
    List<HostResource> failed = releaseResources(releaseQueue);
    try {
        // release time is not time critical so we can try to retry release call for "stuck" resources here
        retryResourceRelease();
    } finally {
        extendFailedToRelease(failed);
    }
}
Also used : HostResource(org.openkilda.testing.service.traffexam.model.HostResource) ExamResources(org.openkilda.testing.service.traffexam.model.ExamResources) Address(org.openkilda.testing.service.traffexam.model.Address) Inet4Address(java.net.Inet4Address) EndpointAddress(org.openkilda.testing.service.traffexam.model.EndpointAddress) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 2 with ExamResources

use of org.openkilda.testing.service.traffexam.model.ExamResources in project open-kilda by telstra.

the class TraffExamServiceImpl method fetchReport.

@Override
public ExamReport fetchReport(Exam exam) throws NoResultsFoundException, ExamNotFinishedException {
    ExamResources resources = retrieveExamResources(exam);
    EndpointReport producerReport = fetchEndpointReport(resources.getProducer());
    EndpointReport consumerReport;
    try {
        consumerReport = fetchEndpointReport(resources.getConsumer());
    } catch (ExamNotFinishedException e) {
        if (producerReport.getError() == null) {
            throw e;
        }
        consumerReport = new EndpointReport("Don't wait for consumer report due to error on producer side");
    }
    return new ExamReport(exam, producerReport, consumerReport);
}
Also used : ExamResources(org.openkilda.testing.service.traffexam.model.ExamResources) ExamReport(org.openkilda.testing.service.traffexam.model.ExamReport) EndpointReport(org.openkilda.testing.service.traffexam.model.EndpointReport)

Example 3 with ExamResources

use of org.openkilda.testing.service.traffexam.model.ExamResources in project open-kilda by telstra.

the class TraffExamServiceImpl method retrieveExamResources.

private ExamResources retrieveExamResources(Exam exam) throws NoResultsFoundException {
    ExamResources resources = exam.getResources();
    if (resources == null) {
        throw new IllegalArgumentException("Exam resources are empty.");
    }
    checkExamRelation(resources);
    return resources;
}
Also used : ExamResources(org.openkilda.testing.service.traffexam.model.ExamResources)

Example 4 with ExamResources

use of org.openkilda.testing.service.traffexam.model.ExamResources in project open-kilda by telstra.

the class TraffExamServiceImpl method startExam.

@Override
public synchronized ExamResources startExam(Exam exam) throws NoResultsFoundException, OperationalException {
    checkHostPresence(exam.getSource());
    checkHostPresence(exam.getDest());
    Inet4Network subnet;
    try {
        subnet = addressPool.allocate();
    } catch (Inet4ValueException e) {
        throw new OperationalException("Unable to allocate subnet for exam. There is no more addresses available.");
    }
    ExamResources resources = null;
    List<HostResource> supplied = new ArrayList<>(4);
    try {
        Address sourceAddress = new Address(subnet.address(1), subnet.getPrefix(), exam.getSourceVlans());
        sourceAddress = assignAddress(exam.getSource(), sourceAddress);
        supplied.add(sourceAddress);
        Address destAddress = new Address(subnet.address(2), subnet.getPrefix(), exam.getDestVlans());
        destAddress = assignAddress(exam.getDest(), destAddress);
        supplied.add(destAddress);
        ConsumerEndpoint consumer = assignEndpoint(exam.getDest(), new ConsumerEndpoint(destAddress.getId()));
        supplied.add(consumer);
        ProducerEndpoint producer = new ProducerEndpoint(sourceAddress.getId(), new EndpointAddress(destAddress.getAddress(), consumer.getBindPort()));
        if (exam.getBandwidthLimit() != null) {
            producer.setBandwidth(exam.getBandwidthLimit());
            producer.setBurstPkt(exam.getBurstPkt());
        }
        if (exam.getTimeLimitSeconds() != null) {
            producer.setTime(exam.getTimeLimitSeconds());
        }
        producer.setUseUdp(exam.isUdp());
        producer.setBufferLength(exam.getBufferLength());
        try {
            // give consumer some time to fully roll. Probably should be fixed on service's side, this is workaround
            TimeUnit.MILLISECONDS.sleep(300);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        producer = assignEndpoint(exam.getSource(), producer);
        supplied.add(producer);
        resources = new ExamResources(subnet, producer, consumer);
    } catch (Inet4ValueException e) {
        throw new OperationalException("Insufficient resources - not enough IP address in subnet. Check addressPool configuration.");
    } finally {
        if (resources == null) {
            extendFailedToRelease(releaseResources(supplied));
            try {
                addressPool.free(subnet);
            } catch (Inet4ValueException e) {
            // Unreachable point, free throw exception only if invalid (not allocated before) address passed
            }
        }
    }
    return resources;
}
Also used : ExamResources(org.openkilda.testing.service.traffexam.model.ExamResources) Address(org.openkilda.testing.service.traffexam.model.Address) Inet4Address(java.net.Inet4Address) EndpointAddress(org.openkilda.testing.service.traffexam.model.EndpointAddress) ArrayList(java.util.ArrayList) HostResource(org.openkilda.testing.service.traffexam.model.HostResource) Inet4Network(org.openkilda.testing.service.traffexam.networkpool.Inet4Network) Inet4ValueException(org.openkilda.testing.service.traffexam.networkpool.Inet4ValueException) ConsumerEndpoint(org.openkilda.testing.service.traffexam.model.ConsumerEndpoint) ProducerEndpoint(org.openkilda.testing.service.traffexam.model.ProducerEndpoint) EndpointAddress(org.openkilda.testing.service.traffexam.model.EndpointAddress)

Aggregations

ExamResources (org.openkilda.testing.service.traffexam.model.ExamResources)4 Inet4Address (java.net.Inet4Address)2 ArrayList (java.util.ArrayList)2 Address (org.openkilda.testing.service.traffexam.model.Address)2 EndpointAddress (org.openkilda.testing.service.traffexam.model.EndpointAddress)2 HostResource (org.openkilda.testing.service.traffexam.model.HostResource)2 UUID (java.util.UUID)1 ConsumerEndpoint (org.openkilda.testing.service.traffexam.model.ConsumerEndpoint)1 EndpointReport (org.openkilda.testing.service.traffexam.model.EndpointReport)1 ExamReport (org.openkilda.testing.service.traffexam.model.ExamReport)1 ProducerEndpoint (org.openkilda.testing.service.traffexam.model.ProducerEndpoint)1 Inet4Network (org.openkilda.testing.service.traffexam.networkpool.Inet4Network)1 Inet4ValueException (org.openkilda.testing.service.traffexam.networkpool.Inet4ValueException)1