Search in sources :

Example 1 with InvalidElementException

use of es.bsc.compss.types.resources.exceptions.InvalidElementException in project compss by bsc-wdc.

the class Validator method validateProcessor.

private void validateProcessor(ProcessorType processor) throws InvalidElementException {
    // Names are validated in the parent node
    // Validate inner elements
    List<JAXBElement<?>> innerElements = processor.getComputingUnitsOrArchitectureOrSpeed();
    if (innerElements != null) {
        boolean cuTagFound = false;
        boolean ArchitectureTagFound = false;
        boolean speedTagFound = false;
        boolean typeTagFound = false;
        boolean memTagFound = false;
        boolean processorPropertyTagFound = false;
        for (JAXBElement<?> obj : innerElements) {
            if (obj.getName().equals(new QName("ComputingUnits"))) {
                if (cuTagFound) {
                    throw new InvalidElementException("Processor", "Attribute ComputingUnits", "Appears more than once");
                } else {
                    cuTagFound = true;
                    int val = (Integer) obj.getValue();
                    if (val <= 0) {
                        throw new InvalidElementException("Processor", "Attribute ComputingUnits", "Must be greater than 0");
                    }
                }
            } else if (obj.getName().equals(new QName("Architecture"))) {
                if (ArchitectureTagFound) {
                    throw new InvalidElementException("Processor", "Attribute Architecture", "Appears more than once");
                } else {
                    ArchitectureTagFound = true;
                }
            } else if (obj.getName().equals(new QName("Speed"))) {
                if (speedTagFound) {
                    throw new InvalidElementException("Processor", "Attribute Speed", "Appears more than once");
                } else {
                    speedTagFound = true;
                    float val = (Float) obj.getValue();
                    if (val <= 0.0) {
                        throw new InvalidElementException("Processor", "Attribute Speed", "Must be greater than 0");
                    }
                }
            } else if (obj.getName().equals(new QName("Type"))) {
                if (typeTagFound) {
                    throw new InvalidElementException("Processor", "Attribute Type", "Appears more than once");
                } else {
                    typeTagFound = true;
                }
            } else if (obj.getName().equals(new QName("InternalMemorySize"))) {
                if (memTagFound) {
                    throw new InvalidElementException("Processor", "Attribute InternalMemorySize", "Appears more than once");
                } else {
                    memTagFound = true;
                    float val = (Float) obj.getValue();
                    if (val <= 0.0) {
                        throw new InvalidElementException("Processor", "Attribute InternalMemorySize", "Must be greater than 0");
                    }
                }
            } else if (obj.getName().equals(new QName("ProcessorProperty"))) {
                if (processorPropertyTagFound) {
                    throw new InvalidElementException("Processor", "Attribute ProcessorProperty", "Appears more than once");
                } else {
                    processorPropertyTagFound = true;
                }
            } else {
                throw new InvalidElementException("Processor", "Attribute " + obj.getClass(), "Incorrect attribute");
            }
        }
        // Check minimum appearences
        if (!cuTagFound) {
            throw new InvalidElementException("Processor", "Attribute ComputingUnits", "Doesn't appear");
        }
    } else {
        // Empty inner elements
        throw new InvalidElementException("Processor", "", "Content is empty");
    }
}
Also used : QName(javax.xml.namespace.QName) InvalidElementException(es.bsc.compss.types.resources.exceptions.InvalidElementException) JAXBElement(javax.xml.bind.JAXBElement)

Example 2 with InvalidElementException

use of es.bsc.compss.types.resources.exceptions.InvalidElementException in project compss by bsc-wdc.

the class Validator method validateAdaptor.

private void validateAdaptor(AdaptorType adaptor) throws InvalidElementException {
    // Validate inner elements
    List<JAXBElement<?>> innerElements = adaptor.getSubmissionSystemOrPortsOrBrokerAdaptor();
    if (innerElements != null) {
        boolean subsysTagFound = false;
        boolean portsTagFound = false;
        boolean brokerAdaptorTagFound = false;
        boolean propertiesTagFound = false;
        boolean userTagFound = false;
        for (JAXBElement<?> obj : innerElements) {
            if (obj.getName().equals(new QName("SubmissionSystem"))) {
                if (subsysTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("Adaptor", "Attribute " + obj.getName(), "Appears more than once");
                } else {
                    subsysTagFound = true;
                    validateSubmissionSystem(((SubmissionSystemType) obj.getValue()));
                }
            } else if (obj.getName().equals(new QName("Ports"))) {
                if (portsTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("Adaptor", "Attribute " + obj.getName(), "Appears more than once");
                } else if (brokerAdaptorTagFound || propertiesTagFound) {
                    // Cannot define multiple adaptor properties
                    throw new InvalidElementException("Adaptor", "Attribute " + obj.getName(), "An adaptor property (GAT or External) was already defined");
                } else {
                    portsTagFound = true;
                    validateNIOAdaptorProperties(((NIOAdaptorProperties) obj.getValue()));
                }
            } else if (obj.getName().equals(new QName("BrokerAdaptor"))) {
                if (brokerAdaptorTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("Adaptor", "Attribute " + obj.getName(), "Appears more than once");
                } else if (portsTagFound || propertiesTagFound) {
                    // Cannot define multiple adaptor properties
                    throw new InvalidElementException("Adaptor", "Attribute " + obj.getName(), "An adaptor property (NIO or External) was already defined");
                } else {
                    brokerAdaptorTagFound = true;
                    validateGATAdaptorProperties(((String) obj.getValue()));
                }
            } else if (obj.getName().equals(new QName("Properties"))) {
                if (propertiesTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("Adaptor", "Attribute " + obj.getName(), "Appears more than once");
                } else if (portsTagFound || brokerAdaptorTagFound) {
                    // Cannot define multiple adaptor properties
                    throw new InvalidElementException("Adaptor", "Attribute " + obj.getName(), "An adaptor property (NIO or GAT) was already defined");
                } else {
                    propertiesTagFound = true;
                    validateExternalAdaptorProperties(((ExternalAdaptorProperties) obj.getValue()));
                }
            } else if (obj.getName().equals(new QName("User"))) {
                if (userTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("Adaptor", "Attribute " + obj.getName(), "Appears more than once");
                } else {
                    userTagFound = true;
                }
            } else {
                throw new InvalidElementException("Adaptor " + adaptor.getName(), "Attribute" + obj.getName(), "Incorrect attribute");
            }
        }
        // Check minimum appearences
        if (!subsysTagFound) {
            throw new InvalidElementException("Adaptor " + adaptor.getName(), "Attribute SubmissionSystem", "Doesn't appear");
        }
        if (!portsTagFound && !brokerAdaptorTagFound && !propertiesTagFound) {
            throw new InvalidElementException("Adaptor " + adaptor.getName(), "Attribute Adaptor properties (NIO, GAT or External)", "Doesn't appear");
        }
    } else {
        // Empty inner elements
        throw new InvalidElementException("Adaptor", "", "Content is empty");
    }
}
Also used : SubmissionSystemType(es.bsc.compss.types.resources.jaxb.SubmissionSystemType) QName(javax.xml.namespace.QName) InvalidElementException(es.bsc.compss.types.resources.exceptions.InvalidElementException) NIOAdaptorProperties(es.bsc.compss.types.resources.jaxb.NIOAdaptorProperties) JAXBElement(javax.xml.bind.JAXBElement) ExternalAdaptorProperties(es.bsc.compss.types.resources.jaxb.ExternalAdaptorProperties)

Example 3 with InvalidElementException

use of es.bsc.compss.types.resources.exceptions.InvalidElementException in project compss by bsc-wdc.

the class Validator method validateMemory.

private void validateMemory(MemoryType memory) throws InvalidElementException {
    // Validate inner elements
    List<Serializable> innerElements = memory.getSizeOrType();
    if (innerElements != null) {
        boolean sizeTagFound = false;
        boolean typeTagFound = false;
        for (Object obj : innerElements) {
            if (obj instanceof Float) {
                if (sizeTagFound) {
                    throw new InvalidElementException("Memory", "Attribute Size", "Appears more than once");
                } else {
                    sizeTagFound = true;
                    Float val = (Float) obj;
                    if (val <= 0.0) {
                        throw new InvalidElementException("Memory", "Attribute Size", "Must be greater than 0");
                    }
                }
            } else if (obj instanceof String) {
                if (typeTagFound) {
                    throw new InvalidElementException("Memory", "Attribute Type", "Appears more than once");
                } else {
                    typeTagFound = true;
                }
            } else {
                throw new InvalidElementException("Memory", "Attribute " + obj.getClass(), "Incorrect attribute");
            }
        }
        // Check minimum appearences
        if (!sizeTagFound) {
            throw new InvalidElementException("Memory ", "Attribute Size", "Doesn't appear");
        }
    } else {
        // Empty inner elements
        throw new InvalidElementException("Memory", "", "Content is empty");
    }
}
Also used : Serializable(java.io.Serializable) InvalidElementException(es.bsc.compss.types.resources.exceptions.InvalidElementException)

Example 4 with InvalidElementException

use of es.bsc.compss.types.resources.exceptions.InvalidElementException in project compss by bsc-wdc.

the class Validator method validateStorage.

/*
     * ********************************************** 
     * HELPERS FOR VALIDATION (PRIVATE METHODS)
     **********************************************/
private void validateStorage(StorageType s) throws InvalidElementException {
    // Validate inner elements
    List<Serializable> innerElements = s.getSizeOrType();
    if (innerElements != null) {
        boolean sizeTagFound = false;
        boolean typeTagFound = false;
        for (Object obj : innerElements) {
            if (obj instanceof Float) {
                if (sizeTagFound) {
                    throw new InvalidElementException("Storage", "Attribute Size", "Appears more than once");
                } else {
                    sizeTagFound = true;
                    Float val = (Float) obj;
                    if (val <= 0.0) {
                        throw new InvalidElementException("Storage", "Attribute Size", "Must be greater than 0");
                    }
                }
            } else if (obj instanceof String) {
                if (typeTagFound) {
                    throw new InvalidElementException("Storage", "Attribute Type", "Appears more than once");
                } else {
                    typeTagFound = true;
                }
            } else {
                throw new InvalidElementException("Storage", "Attribute " + obj.getClass(), "Incorrect attribute");
            }
        }
        // Check minimum appearences
        if (!sizeTagFound) {
            throw new InvalidElementException("Storage ", "Attribute Size", "Doesn't appear");
        }
    } else {
        // Empty inner elements
        throw new InvalidElementException("Storage", "", "Content is empty");
    }
}
Also used : Serializable(java.io.Serializable) InvalidElementException(es.bsc.compss.types.resources.exceptions.InvalidElementException)

Example 5 with InvalidElementException

use of es.bsc.compss.types.resources.exceptions.InvalidElementException in project compss by bsc-wdc.

the class Validator method validateImages.

private void validateImages(ImagesType images) throws InvalidElementException {
    List<String> imageNames = new ArrayList<String>();
    List<ImageType> images_list = images.getImage();
    if (images_list != null) {
        for (ImageType im : images_list) {
            if (imageNames.contains(im.getName())) {
                throw new InvalidElementException("Images", "Attribute Image " + im.getName(), "Name already used");
            } else {
                imageNames.add(im.getName());
                validateImage(im);
            }
        }
    } else {
        // Empty inner elements
        throw new InvalidElementException("Images", "", "Content is empty");
    }
}
Also used : ArrayList(java.util.ArrayList) InvalidElementException(es.bsc.compss.types.resources.exceptions.InvalidElementException) ImageType(es.bsc.compss.types.resources.jaxb.ImageType)

Aggregations

InvalidElementException (es.bsc.compss.types.resources.exceptions.InvalidElementException)11 ArrayList (java.util.ArrayList)4 AdaptorsListType (es.bsc.compss.types.resources.jaxb.AdaptorsListType)3 AttachedDisksListType (es.bsc.compss.types.resources.jaxb.AttachedDisksListType)3 PriceType (es.bsc.compss.types.resources.jaxb.PriceType)3 JAXBElement (javax.xml.bind.JAXBElement)3 QName (javax.xml.namespace.QName)3 MemoryType (es.bsc.compss.types.resources.jaxb.MemoryType)2 OSType (es.bsc.compss.types.resources.jaxb.OSType)2 ProcessorType (es.bsc.compss.types.resources.jaxb.ProcessorType)2 SoftwareListType (es.bsc.compss.types.resources.jaxb.SoftwareListType)2 StorageType (es.bsc.compss.types.resources.jaxb.StorageType)2 Serializable (java.io.Serializable)2 BatchType (es.bsc.compss.types.resources.jaxb.BatchType)1 ExternalAdaptorProperties (es.bsc.compss.types.resources.jaxb.ExternalAdaptorProperties)1 ImageType (es.bsc.compss.types.resources.jaxb.ImageType)1 InstanceTypeType (es.bsc.compss.types.resources.jaxb.InstanceTypeType)1 InteractiveType (es.bsc.compss.types.resources.jaxb.InteractiveType)1 NIOAdaptorProperties (es.bsc.compss.types.resources.jaxb.NIOAdaptorProperties)1 SubmissionSystemType (es.bsc.compss.types.resources.jaxb.SubmissionSystemType)1