Search in sources :

Example 11 with InvalidElementException

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

the class Validator method validateComputeNode.

/**
 * Validates the given ComputeNodeType @cn with the current ResourcesFileType The content is correct if no exception
 * is raised
 *
 * @param cn
 * @throws InvalidElementException
 */
public void validateComputeNode(ComputeNodeType cn) throws InvalidElementException {
    // Check that name isn't used
    int num = 0;
    for (String c : rf.getComputeNodes_names()) {
        if (c.equals(cn.getName())) {
            num = num + 1;
        }
    }
    if (num > 1) {
        // ComputeNode already exists
        throw new InvalidElementException("ComputeNode", cn.getName(), "Name already in use");
    }
    // Check inner elements
    List<Object> innerElements = cn.getProcessorOrAdaptorsOrMemory();
    if (innerElements != null) {
        List<String> processorNames = new ArrayList<String>();
        boolean processorTagFound = false;
        boolean adaptorsTagFound = false;
        boolean memoryTagFound = false;
        boolean storageTagFound = false;
        boolean osTagFound = false;
        boolean softwareTagFound = false;
        boolean sharedDisksTagFound = false;
        boolean priceTagFound = false;
        for (Object obj : innerElements) {
            if (obj instanceof ProcessorType) {
                ProcessorType p = (ProcessorType) obj;
                if (processorNames.contains(p.getName())) {
                    throw new InvalidElementException("ComputeNode " + cn.getName(), "Attribute Processor" + p.getName(), "Appears more than once");
                } else {
                    processorTagFound = true;
                    processorNames.add(p.getName());
                    validateProcessor(p);
                }
            } else if (obj instanceof AdaptorsListType) {
                if (adaptorsTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("ComputeNode " + cn.getName(), "Attribute " + obj.getClass(), "Appears more than once");
                } else {
                    adaptorsTagFound = true;
                    validateAdaptors(((AdaptorsListType) obj));
                }
            } else if (obj instanceof MemoryType) {
                if (memoryTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("ComputeNode " + cn.getName(), "Attribute " + obj.getClass(), "Appears more than once");
                } else {
                    memoryTagFound = true;
                    validateMemory(((MemoryType) obj));
                }
            } else if (obj instanceof StorageType) {
                if (storageTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("ComputeNode " + cn.getName(), "Attribute " + obj.getClass(), "Appears more than once");
                } else {
                    storageTagFound = true;
                    validateStorage(((StorageType) obj));
                }
            } else if (obj instanceof OSType) {
                if (osTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("ComputeNode " + cn.getName(), "Attribute " + obj.getClass(), "Appears more than once");
                } else {
                    osTagFound = true;
                    validateOS(((OSType) obj));
                }
            } else if (obj instanceof SoftwareListType) {
                if (softwareTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("ComputeNode " + cn.getName(), "Attribute " + obj.getClass(), "Appears more than once");
                } else {
                    softwareTagFound = true;
                    validateSoftwareList(((SoftwareListType) obj));
                }
            } else if (obj instanceof AttachedDisksListType) {
                if (sharedDisksTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("ComputeNode " + cn.getName(), "Attribute " + obj.getClass(), "Appears more than once");
                } else {
                    sharedDisksTagFound = true;
                    validateAttachedDisksList(((AttachedDisksListType) obj));
                }
            } else if (obj instanceof PriceType) {
                if (priceTagFound) {
                    // Second occurency, throw exception
                    throw new InvalidElementException("ComputeNode " + cn.getName(), "Attribute " + obj.getClass(), "Appears more than once");
                } else {
                    priceTagFound = true;
                    validatePrice(((PriceType) obj));
                }
            } else {
                throw new InvalidElementException("ComputeNode " + cn.getName(), "Attribute " + obj.getClass(), "Incorrect attribute");
            }
        }
        // Check minimum appearences
        if (!processorTagFound) {
            throw new InvalidElementException("ComputeNode " + cn.getName(), "Attribute Processor", "Doesn't appear");
        }
        if (!adaptorsTagFound) {
            throw new InvalidElementException("ComputeNode " + cn.getName(), "Attribute Adaptors", "Doesn't appear");
        }
    } else {
        // Empty inner elements
        throw new InvalidElementException("ComputeNode " + cn.getName(), "", "Content is empty");
    }
}
Also used : AdaptorsListType(es.bsc.compss.types.resources.jaxb.AdaptorsListType) StorageType(es.bsc.compss.types.resources.jaxb.StorageType) ProcessorType(es.bsc.compss.types.resources.jaxb.ProcessorType) ArrayList(java.util.ArrayList) 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) 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