Search in sources :

Example 6 with InvalidElementException

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

the class Validator method validateInstanceTypes.

private void validateInstanceTypes(InstanceTypesType instances) throws InvalidElementException {
    List<String> instanceNames = new ArrayList<String>();
    List<InstanceTypeType> instances_list = instances.getInstanceType();
    if (instances_list != null) {
        for (InstanceTypeType i : instances.getInstanceType()) {
            if (instanceNames.contains(i.getName())) {
                throw new InvalidElementException("Instances", "Attribute Instance " + i.getName(), "Name already used");
            } else {
                instanceNames.add(i.getName());
                validateInstance(i);
            }
        }
    } else {
        // Empty inner elements
        throw new InvalidElementException("InstanceTypes", "", "Content is empty");
    }
}
Also used : ArrayList(java.util.ArrayList) InvalidElementException(es.bsc.compss.types.resources.exceptions.InvalidElementException) InstanceTypeType(es.bsc.compss.types.resources.jaxb.InstanceTypeType)

Example 7 with InvalidElementException

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

the class Validator method validateSubmissionSystem.

private void validateSubmissionSystem(SubmissionSystemType subSys) throws InvalidElementException {
    List<Object> innerElements = subSys.getBatchOrInteractive();
    if (innerElements != null) {
        boolean batchTagFound = false;
        boolean interactiveTagFound = false;
        for (Object obj : innerElements) {
            if (obj instanceof BatchType) {
                if (batchTagFound) {
                    throw new InvalidElementException("SubmissionSystem", "Attribute Batch", "Appears more than once");
                } else {
                    batchTagFound = true;
                    validateBatch(((BatchType) obj));
                }
            } else if (obj instanceof InteractiveType) {
                if (interactiveTagFound) {
                    throw new InvalidElementException("SubmissionSystem", "Attribute Interactive", "Appears more than once");
                } else {
                    interactiveTagFound = true;
                    validateInteractive(((InteractiveType) obj));
                }
            } else {
                throw new InvalidElementException("SubmissionSystem", "Attribute " + obj.getClass(), "Invalid type");
            }
        }
        // Check minimum
        if (!batchTagFound && !interactiveTagFound) {
            throw new InvalidElementException("SubmissionSystem", "Interactive/Batch", "At least 1 submission system must be defined");
        }
    } else {
        // Empty inner elements
        throw new InvalidElementException("SubmissionSystem", "", "Content is empty");
    }
}
Also used : InteractiveType(es.bsc.compss.types.resources.jaxb.InteractiveType) InvalidElementException(es.bsc.compss.types.resources.exceptions.InvalidElementException) BatchType(es.bsc.compss.types.resources.jaxb.BatchType)

Example 8 with InvalidElementException

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

the class Validator method validateImage.

private void validateImage(ImageType image) throws InvalidElementException {
    // Validate inner elements
    List<Object> innerElements = image.getAdaptorsOrOperatingSystemOrSoftware();
    if (innerElements != null) {
        boolean adaptorsTagFound = false;
        boolean OSTagFound = false;
        boolean softwareTagFound = false;
        boolean sdTagFound = false;
        boolean priceTagFound = false;
        boolean creationTimeTagFound = false;
        for (Object obj : innerElements) {
            if (obj instanceof AdaptorsListType) {
                if (adaptorsTagFound) {
                    throw new InvalidElementException("Image", "Attribute Adaptors", "Appears more than once");
                } else {
                    adaptorsTagFound = true;
                    validateAdaptors(((AdaptorsListType) obj));
                }
            } else if (obj instanceof OSType) {
                if (OSTagFound) {
                    throw new InvalidElementException("Image", "Attribute OperatingSystem", "Appears more than once");
                } else {
                    OSTagFound = true;
                    validateOS(((OSType) obj));
                }
            } else if (obj instanceof SoftwareListType) {
                if (softwareTagFound) {
                    throw new InvalidElementException("Image", "Attribute Software", "Appears more than once");
                } else {
                    softwareTagFound = true;
                    validateSoftwareList(((SoftwareListType) obj));
                }
            } else if (obj instanceof AttachedDisksListType) {
                if (sdTagFound) {
                    throw new InvalidElementException("Image", "Attribute AttachedDisks", "Appears more than once");
                } else {
                    sdTagFound = true;
                    this.validateAttachedDisksList(((AttachedDisksListType) obj));
                }
            } else if (obj instanceof PriceType) {
                if (priceTagFound) {
                    throw new InvalidElementException("Image", "Attribute Price", "Appears more than once");
                } else {
                    priceTagFound = true;
                    validatePrice(((PriceType) obj));
                }
            } else if (obj instanceof java.lang.Integer) {
                // Creation time (int)
                if (creationTimeTagFound) {
                    throw new InvalidElementException("Image", "Attribute CreationTime", "Appears more than once");
                } else {
                    creationTimeTagFound = true;
                // Nothing to validate since it is an integer
                }
            } else {
                throw new InvalidElementException("Image", "Attribute " + obj.getClass(), "Incorrect attribute");
            }
        }
        // Check minimum appearences
        if (!adaptorsTagFound) {
            throw new InvalidElementException("Image ", "Attribute Adaptors", "Doesn't appear");
        }
    } else {
        // Empty inner elements
        throw new InvalidElementException("Image", "", "Content is empty");
    }
}
Also used : AdaptorsListType(es.bsc.compss.types.resources.jaxb.AdaptorsListType) SoftwareListType(es.bsc.compss.types.resources.jaxb.SoftwareListType) OSType(es.bsc.compss.types.resources.jaxb.OSType) AttachedDisksListType(es.bsc.compss.types.resources.jaxb.AttachedDisksListType) InvalidElementException(es.bsc.compss.types.resources.exceptions.InvalidElementException) PriceType(es.bsc.compss.types.resources.jaxb.PriceType)

Example 9 with InvalidElementException

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

the class Validator method validateDataNode.

/**
 * Validates the given DataNodeType @dn with the current ResourcesFileType The content is correct if no exception is
 * raised
 *
 * @param dn
 * @throws InvalidElementException
 */
public void validateDataNode(DataNodeType dn) throws InvalidElementException {
    // Check that name isn't used
    int num = 0;
    for (String d : rf.getDataNodes_names()) {
        if (d.equals(dn.getName())) {
            num = num + 1;
        }
    }
    if (num > 1) {
        // DataNode already exists
        throw new InvalidElementException("DataNode", dn.getName(), "Name already in use");
    }
    // Check inner elements
    List<JAXBElement<?>> innerElements = dn.getHostOrPathOrAdaptors();
    if (innerElements != null) {
        boolean hostTagFound = false;
        boolean pathTagFound = false;
        boolean adaptorsTagFound = false;
        boolean storageTagFound = false;
        boolean sharedDisksTagFound = false;
        for (JAXBElement<?> obj : innerElements) {
            if (obj.getName().equals(new QName("Host"))) {
                if (hostTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("DataNode " + dn.getName(), "Attribute " + obj.getName(), "Appears more than once");
                } else {
                    hostTagFound = true;
                }
            } else if (obj.getName().equals(new QName("Path"))) {
                if (pathTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("DataNode " + dn.getName(), "Attribute " + obj.getName(), "Appears more than once");
                } else {
                    pathTagFound = true;
                }
            } else if (obj.getName().equals(new QName("Adaptors"))) {
                if (adaptorsTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("DataNode " + dn.getName(), "Attribute " + obj.getName(), "Appears more than once");
                } else {
                    adaptorsTagFound = true;
                    validateAdaptors(((AdaptorsListType) obj.getValue()));
                }
            } else if (obj.getName().equals(new QName("Storage"))) {
                if (storageTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("DataNode " + dn.getName(), "Attribute " + obj.getName(), "Appears more than once");
                } else {
                    storageTagFound = true;
                    validateStorage(((StorageType) obj.getValue()));
                }
            } else if (obj.getName().equals(new QName("SharedDisks"))) {
                if (sharedDisksTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("DataNode " + dn.getName(), "Attribute " + obj.getName(), "Appears more than once");
                } else {
                    sharedDisksTagFound = true;
                    validateAttachedDisksList(((AttachedDisksListType) obj.getValue()));
                }
            } else {
                throw new InvalidElementException("DataNode " + dn.getName(), "Attribute " + obj.getName(), "Incorrect attribute");
            }
        }
        // Check minimum appearences
        if (!hostTagFound) {
            throw new InvalidElementException("DataNode " + dn.getName(), "Attribute Host", "Doesn't appear");
        }
        if (!pathTagFound) {
            throw new InvalidElementException("DataNode " + dn.getName(), "Attribute Path", "Doesn't appear");
        }
        if (!adaptorsTagFound) {
            throw new InvalidElementException("DataNode " + dn.getName(), "Attribute Adaptors", "Doesn't appear");
        }
    } else {
        // Empty inner elements
        throw new InvalidElementException("DataNode " + dn.getName(), "", "Content is empty");
    }
}
Also used : AdaptorsListType(es.bsc.compss.types.resources.jaxb.AdaptorsListType) QName(javax.xml.namespace.QName) AttachedDisksListType(es.bsc.compss.types.resources.jaxb.AttachedDisksListType) InvalidElementException(es.bsc.compss.types.resources.exceptions.InvalidElementException) JAXBElement(javax.xml.bind.JAXBElement)

Example 10 with InvalidElementException

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

the class Validator method validateInstance.

private void validateInstance(InstanceTypeType instance) throws InvalidElementException {
    // Validate inner elements
    List<Object> innerElements = instance.getProcessorOrMemoryOrStorage();
    if (innerElements != null) {
        List<String> processorNames = new ArrayList<String>();
        boolean processorTagFound = false;
        boolean memoryTagFound = false;
        boolean storageTagFound = false;
        boolean priceTagFound = false;
        for (Object obj : innerElements) {
            if (obj instanceof ProcessorType) {
                processorTagFound = true;
                ProcessorType p = (ProcessorType) obj;
                if (processorNames.contains(p.getName())) {
                    throw new InvalidElementException("Instance", "Attribute Processor " + p.getName(), "Appears more than once");
                } else {
                    processorNames.add(p.getName());
                    validateProcessor(((ProcessorType) obj));
                }
            } else if (obj instanceof MemoryType) {
                if (memoryTagFound) {
                    throw new InvalidElementException("Instance", "Attribute Memory", "Appears more than once");
                } else {
                    memoryTagFound = true;
                    validateMemory(((MemoryType) obj));
                }
            } else if (obj instanceof StorageType) {
                if (storageTagFound) {
                    throw new InvalidElementException("Instance", "Attribute Storage", "Appears more than once");
                } else {
                    storageTagFound = true;
                    validateStorage(((StorageType) obj));
                }
            } else if (obj instanceof PriceType) {
                if (priceTagFound) {
                    throw new InvalidElementException("Instance", "Attribute Price", "Appears more than once");
                } else {
                    priceTagFound = true;
                    validatePrice(((PriceType) obj));
                }
            } else {
                throw new InvalidElementException("Instance", "Attribute " + obj.getClass(), "Incorrect attribute");
            }
        }
        // Check minimum appearences
        if (!processorTagFound) {
            throw new InvalidElementException("Insntace", "Attribute Processor", "Doesn't appear");
        }
    } else {
        // Empty inner elements
        throw new InvalidElementException("InstanceType", "", "Content is empty");
    }
}
Also used : StorageType(es.bsc.compss.types.resources.jaxb.StorageType) ProcessorType(es.bsc.compss.types.resources.jaxb.ProcessorType) ArrayList(java.util.ArrayList) InvalidElementException(es.bsc.compss.types.resources.exceptions.InvalidElementException) PriceType(es.bsc.compss.types.resources.jaxb.PriceType) MemoryType(es.bsc.compss.types.resources.jaxb.MemoryType)

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