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");
}
}
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");
}
}
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");
}
}
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");
}
}
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");
}
}
Aggregations