use of es.bsc.compss.types.resources.MethodResourceDescription in project compss by bsc-wdc.
the class CloudProviderTest method testRefusedOneTurnOn.
@Test
public void testRefusedOneTurnOn() {
Map<String, String> properties = new HashMap<>();
CloudProvider cp = null;
try {
cp = new CloudProvider(PROVIDER_NAME, 0, RUNTIME_CONNECTOR, null, null, properties);
} catch (Exception e) {
fail("Could not create the Cloud Provider");
return;
}
if (cp.getCurrentVMCount() != 0) {
fail("Cloud Provider is not properly intialized the number of requested VMs should be 0");
}
String imageName = "IMAGE" + (int) (Math.random() * 10000);
CloudImageDescription cid = new CloudImageDescription(imageName, new HashMap<>());
cp.addCloudImage(cid);
String typeName = "TYPE" + (int) (Math.random() * 10000);
float type1Memory = (float) Math.random() * 5;
MethodResourceDescription mrd1 = new MethodResourceDescription();
mrd1.setMemorySize(type1Memory);
CloudInstanceTypeDescription citd = new CloudInstanceTypeDescription(typeName, mrd1);
cp.addInstanceType(citd);
CloudMethodResourceDescription cmrd = new CloudMethodResourceDescription(citd, cid);
ResourceCreationRequest crc = cp.requestResourceCreation(cmrd);
if (!FakeConnector.getProcessedRequests().contains(crc)) {
fail("Turn on has not reached the connector");
}
if (cp.getCurrentVMCount() != 1) {
fail("Cloud Provider is not properly accounting the number of requested VMs");
}
List<ResourceCreationRequest> pendingRequests = cp.getPendingRequests();
if (!pendingRequests.contains(crc)) {
fail("Cloud Provider is not properly registering the pending creations requests");
}
if (pendingRequests.size() != 1) {
fail("Cloud Provider is not properly registering the pending creations requests");
}
cp.refusedCreation(crc);
if (cp.getCurrentVMCount() != 0) {
fail("Cloud Provider is not properly accounting the number of requested VMs");
}
pendingRequests = cp.getPendingRequests();
if (!pendingRequests.isEmpty()) {
fail("Cloud Provider is not properly registering the pending creations requests");
}
}
use of es.bsc.compss.types.resources.MethodResourceDescription in project compss by bsc-wdc.
the class CloudProviderTest method testCreateOneVMOneResourceSameDescription.
@Test
public void testCreateOneVMOneResourceSameDescription() {
Map<String, String> properties = new HashMap<>();
CloudProvider cp = null;
try {
cp = new CloudProvider(PROVIDER_NAME, 0, RUNTIME_CONNECTOR, null, null, properties);
} catch (Exception e) {
fail("Could not create the Cloud Provider");
return;
}
String imageName = "IMAGE" + (int) (Math.random() * 10000);
CloudImageDescription cid = new CloudImageDescription(imageName, new HashMap<>());
cp.addCloudImage(cid);
String typeName = "TYPE" + (int) (Math.random() * 10000);
float type1Memory = (float) Math.random() * 5;
MethodResourceDescription mrd1 = new MethodResourceDescription();
mrd1.setMemorySize(type1Memory);
CloudInstanceTypeDescription citd = new CloudInstanceTypeDescription(typeName, mrd1);
cp.addInstanceType(citd);
CloudMethodResourceDescription cmrd = new CloudMethodResourceDescription(citd, cid);
ResourceCreationRequest crc = cp.requestResourceCreation(cmrd);
if (cp.getCurrentVMCount() != 1) {
fail("Cloud Provider is not properly accounting the number of requested VMs");
}
List<ResourceCreationRequest> pendingRequests = cp.getPendingRequests();
Set<CloudMethodWorker> workers = cp.getHostedWorkers();
if (!pendingRequests.contains(crc)) {
fail("Cloud Provider is not properly registering the pending creations requests");
}
if (pendingRequests.size() != 1) {
fail("Cloud Provider is not properly registering the pending creations requests");
}
if (!workers.isEmpty()) {
fail("Cloud Provider is not properly registering the hosted workers");
}
String vmName = "VM" + (int) (Math.random() * 1000);
CloudMethodWorker cmw = new CloudMethodWorker(vmName, cp, cmrd, new FakeNode(vmName), 0, 0, 0, 0, new HashMap<>());
CloudMethodResourceDescription granted = new CloudMethodResourceDescription(citd, cid);
cp.confirmedCreation(crc, cmw, granted);
if (cp.getCurrentVMCount() != 1) {
fail("Cloud Provider is not properly accounting the number of requested VMs");
}
pendingRequests = cp.getPendingRequests();
workers = cp.getHostedWorkers();
if (!pendingRequests.isEmpty()) {
fail("Cloud Provider is not properly registering the pending creations requests");
}
if (workers.size() != 1) {
fail("Cloud Provider is not properly registering the hosted workers");
}
if (!workers.contains(cmw)) {
fail("Cloud Provider is not properly registering the hosted workers");
}
}
use of es.bsc.compss.types.resources.MethodResourceDescription in project compss by bsc-wdc.
the class IDLParser method loadCConstraints.
private static MethodResourceDescription loadCConstraints(String line) {
line = line.substring(CONSTRAINT_IDL.length() + 1);
String proc = new String();
if (line.matches(".*" + PROCESSOR_IDL + ".*")) {
int procStart = line.indexOf("{");
int procEnd = line.indexOf("}");
proc = line.substring(procStart, procEnd + 1);
line = line.replace(proc, "");
line = line.replace("processors=", "");
proc = proc.replaceAll("[{}]", "");
LOGGER.debug("[IDL Parser] Loading processors: " + proc);
line = line.replaceFirst(",", "");
}
line = line.replaceAll("[() ;\n\t]", "");
String[] constraints = line.split(",");
MethodResourceDescription mrd = new MethodResourceDescription(constraints, proc);
// logger.debug("New Constraints detected: " + mrd);
return mrd;
}
use of es.bsc.compss.types.resources.MethodResourceDescription in project compss by bsc-wdc.
the class IDLParser method parseIDLMethods.
public static void parseIDLMethods(String constraintsFile) {
LOGGER.debug("Loading file " + constraintsFile);
try (BufferedReader br = new BufferedReader(new FileReader(constraintsFile))) {
MethodResourceDescription defaultCtr = MethodResourceDescription.EMPTY_FOR_CONSTRAINTS.copy();
boolean isReadingCodeRegion = false;
StringBuilder structureString = new StringBuilder();
CodeRegion type = null;
CImplementation implementation = null;
MethodResourceDescription currConstraints = new MethodResourceDescription(defaultCtr);
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
// System.out.println("Read line: "+ line);
if (isReadingCodeRegion && type != null) {
if (line.startsWith("//")) {
// Line is a comment inside the core region ignoring it
continue;
} else if (type.equals(CodeRegion.COMMENT)) {
if (line.endsWith("*/")) {
isReadingCodeRegion = false;
} else {
continue;
}
} else {
if (line.matches(".*[)];")) {
isReadingCodeRegion = false;
structureString.append(line);
if (type.equals(CodeRegion.CONSTRAINT)) {
LOGGER.debug("[IDL Parser] Loading constraint: " + structureString.toString());
currConstraints = loadCConstraints(structureString.toString());
} else if (type.equals(CodeRegion.IMPLEMENTATION)) {
LOGGER.debug("[IDL Parser] Loading implementation: " + structureString.toString());
implementation = loadCImplementation(structureString.toString());
} else if (type.equals(CodeRegion.FUNCTION)) {
LOGGER.debug("[IDL Parser] Loading function: " + structureString.toString() + " constraint:" + currConstraints);
parseCFunction(structureString.toString(), currConstraints, implementation);
currConstraints = new MethodResourceDescription(defaultCtr);
implementation = null;
}
} else {
structureString.append(line);
}
}
} else {
if (line.startsWith("//") || line.startsWith("#") || (line.startsWith("/*") && line.endsWith("*/"))) {
// Line is a comment of pre-processor pragma ignoring it
continue;
} else if (line.startsWith("/*")) {
// Line starts comment region
isReadingCodeRegion = true;
type = CodeRegion.COMMENT;
} else if (line.matches(CONSTRAINT_IDL + "[(].*[)];")) {
// Line contains
LOGGER.debug("[IDL Parser] Loading constraint: " + line);
currConstraints = loadCConstraints(line);
continue;
} else if (line.matches(CONSTRAINT_IDL + "[(].*")) {
// Line starts a constraints region
isReadingCodeRegion = true;
structureString = new StringBuilder(line);
type = CodeRegion.CONSTRAINT;
} else if (line.matches(IMPLEMENTS_IDL + "[(].*[)];")) {
// Line implements
LOGGER.debug("[IDL Parser] Loading implementation: " + line);
implementation = loadCImplementation(line);
continue;
} else if (line.matches(IMPLEMENTS_IDL + "[(].*")) {
// Line starts a constraints region
isReadingCodeRegion = true;
structureString = new StringBuilder(line);
type = CodeRegion.IMPLEMENTATION;
} else if (line.matches(".*[(].*[)];")) {
// Line contains a function
LOGGER.debug("[IDL Parser] Loading function: " + line + " constraint:" + currConstraints);
parseCFunction(line, currConstraints, implementation);
currConstraints = new MethodResourceDescription(defaultCtr);
implementation = null;
} else if (line.matches(".*[(].*")) {
// Line starts a function region
isReadingCodeRegion = true;
structureString = new StringBuilder(line);
type = CodeRegion.FUNCTION;
}
}
}
} catch (IOException ioe) {
LOGGER.fatal(CONSTR_LOAD_ERR, ioe);
}
}
use of es.bsc.compss.types.resources.MethodResourceDescription in project compss by bsc-wdc.
the class ITFParser method checkDefinedImplementations.
/**
* Check all the defined implementations of the same method
*
* @param m
* @param methodId
* @param calleeMethodSignature
* @param hasStreams
* @param implementations
* @param signatures
*/
private static void checkDefinedImplementations(java.lang.reflect.Method m, Integer methodId, StringBuilder calleeMethodSignature, boolean hasStreams, boolean hasPrefixes, List<Implementation> implementations, List<String> signatures) {
/*
* Global constraints of the method
*/
MethodResourceDescription defaultConstraints = MethodResourceDescription.EMPTY_FOR_CONSTRAINTS.copy();
if (m.isAnnotationPresent(Constraints.class)) {
defaultConstraints = new MethodResourceDescription(m.getAnnotation(Constraints.class));
}
/*
* Check all annotations present at the method for versioning
*/
String methodName = m.getName();
int implId = 0;
/*
* METHOD
*/
for (Method methodAnnot : m.getAnnotationsByType(Method.class)) {
LOGGER.debug(" * Processing @Method annotation");
// Warning for ignoring streams
if (hasStreams) {
ErrorManager.warn("Java method " + methodName + " does not support stream annotations. SKIPPING stream annotation");
}
// Warning for ignoring prefixes
if (hasPrefixes) {
ErrorManager.warn("Java method " + methodName + " does not support prefix annotations. SKIPPING prefix annotation");
}
String declaringClass = methodAnnot.declaringClass();
String methodSignature = calleeMethodSignature.toString() + declaringClass;
signatures.add(methodSignature);
// Load specific method constraints if present
MethodResourceDescription implConstraints = defaultConstraints;
if (methodAnnot.constraints() != null) {
implConstraints = new MethodResourceDescription(methodAnnot.constraints());
implConstraints.mergeMultiConstraints(defaultConstraints);
}
// Register method implementation
Implementation impl = new MethodImplementation(declaringClass, methodName, methodId, implId, implConstraints);
++implId;
implementations.add(impl);
}
/*
* SERVICE
*/
for (Service serviceAnnot : m.getAnnotationsByType(Service.class)) {
// Services don't have constraints
LOGGER.debug(" * Processing @Service annotation");
// Warning for ignoring streams
if (hasStreams) {
ErrorManager.warn("Java service " + methodName + " does not support stream annotations. SKIPPING stream annotation");
}
calleeMethodSignature.append(serviceAnnot.namespace()).append(',');
calleeMethodSignature.append(serviceAnnot.name()).append(',');
calleeMethodSignature.append(serviceAnnot.port());
String serviceSignature = calleeMethodSignature.toString();
signatures.add(serviceSignature);
// Register service implementation
Implementation impl = new ServiceImplementation(methodId, serviceAnnot.namespace(), serviceAnnot.name(), serviceAnnot.port(), serviceAnnot.operation());
++implId;
implementations.add(impl);
}
/*
* MPI
*/
for (MPI mpiAnnot : m.getAnnotationsByType(MPI.class)) {
LOGGER.debug(" * Processing @MPI annotation");
String binary = EnvironmentLoader.loadFromEnvironment(mpiAnnot.binary());
String workingDir = EnvironmentLoader.loadFromEnvironment(mpiAnnot.workingDir());
String mpiRunner = EnvironmentLoader.loadFromEnvironment(mpiAnnot.mpiRunner());
if (mpiRunner == null || mpiRunner.isEmpty()) {
ErrorManager.error("Empty mpiRunner annotation for method " + m.getName());
}
if (binary == null || binary.isEmpty()) {
ErrorManager.error("Empty binary annotation for method " + m.getName());
}
LOGGER.debug("Binary: " + binary);
LOGGER.debug("mpiRunner: " + mpiRunner);
String mpiSignature = calleeMethodSignature.toString() + LoaderUtils.MPI_SIGNATURE;
signatures.add(mpiSignature);
// Load specific method constraints if present
MethodResourceDescription implConstraints = defaultConstraints;
if (mpiAnnot.constraints() != null) {
implConstraints = new MethodResourceDescription(mpiAnnot.constraints());
implConstraints.mergeMultiConstraints(defaultConstraints);
}
// Register method implementation
Implementation impl = new MPIImplementation(binary, workingDir, mpiRunner, methodId, implId, implConstraints);
++implId;
implementations.add(impl);
}
/*
* Decaf
*/
for (Decaf decafAnnot : m.getAnnotationsByType(Decaf.class)) {
LOGGER.debug(" * Processing @DECAF annotation");
String dfScript = EnvironmentLoader.loadFromEnvironment(decafAnnot.dfScript());
String dfExecutor = EnvironmentLoader.loadFromEnvironment(decafAnnot.dfExecutor());
String dfLib = EnvironmentLoader.loadFromEnvironment(decafAnnot.dfLib());
String workingDir = EnvironmentLoader.loadFromEnvironment(decafAnnot.workingDir());
String mpiRunner = EnvironmentLoader.loadFromEnvironment(decafAnnot.mpiRunner());
if (mpiRunner == null || mpiRunner.isEmpty()) {
ErrorManager.error("Empty mpiRunner annotation for method " + m.getName());
}
if (dfScript == null || dfScript.isEmpty()) {
ErrorManager.error("Empty binary annotation for method " + m.getName());
}
LOGGER.debug("DF Script: " + dfScript);
LOGGER.debug("DF Executor: " + dfExecutor);
LOGGER.debug("DF Lib: " + dfLib);
LOGGER.debug("mpiRunner: " + mpiRunner);
String mpiSignature = calleeMethodSignature.toString() + LoaderUtils.DECAF_SIGNATURE;
signatures.add(mpiSignature);
// Load specific method constraints if present
MethodResourceDescription implConstraints = defaultConstraints;
if (decafAnnot.constraints() != null) {
implConstraints = new MethodResourceDescription(decafAnnot.constraints());
implConstraints.mergeMultiConstraints(defaultConstraints);
}
// Register method implementation
Implementation impl = new DecafImplementation(dfScript, dfExecutor, dfLib, workingDir, mpiRunner, methodId, implId, implConstraints);
++implId;
implementations.add(impl);
}
/*
* OMPSS
*/
for (OmpSs ompssAnnot : m.getAnnotationsByType(OmpSs.class)) {
LOGGER.debug(" * Processing @OmpSs annotation");
String binary = EnvironmentLoader.loadFromEnvironment(ompssAnnot.binary());
String workingDir = EnvironmentLoader.loadFromEnvironment(ompssAnnot.workingDir());
if (binary == null || binary.isEmpty()) {
ErrorManager.error("Empty binary annotation for method " + m.getName());
}
String ompssSignature = calleeMethodSignature.toString() + LoaderUtils.OMPSS_SIGNATURE;
signatures.add(ompssSignature);
// Load specific method constraints if present
MethodResourceDescription implConstraints = defaultConstraints;
if (ompssAnnot.constraints() != null) {
implConstraints = new MethodResourceDescription(ompssAnnot.constraints());
implConstraints.mergeMultiConstraints(defaultConstraints);
}
// Register method implementation
Implementation impl = new OmpSsImplementation(binary, workingDir, methodId, implId, implConstraints);
++implId;
implementations.add(impl);
}
/*
* OPENCL
*/
for (OpenCL openclAnnot : m.getAnnotationsByType(OpenCL.class)) {
LOGGER.debug(" * Processing @OpenCL annotation");
String kernel = EnvironmentLoader.loadFromEnvironment(openclAnnot.kernel());
String workingDir = EnvironmentLoader.loadFromEnvironment(openclAnnot.workingDir());
if (kernel == null || kernel.isEmpty()) {
ErrorManager.error("Empty kernel annotation for method " + m.getName());
}
String openclSignature = calleeMethodSignature.toString() + LoaderUtils.OPENCL_SIGNATURE;
signatures.add(openclSignature);
// Load specific method constraints if present
MethodResourceDescription implConstraints = defaultConstraints;
if (openclAnnot.constraints() != null) {
implConstraints = new MethodResourceDescription(openclAnnot.constraints());
implConstraints.mergeMultiConstraints(defaultConstraints);
}
// Register method implementation
Implementation impl = new OpenCLImplementation(kernel, workingDir, methodId, implId, implConstraints);
++implId;
implementations.add(impl);
}
/*
* BINARY
*/
for (Binary binaryAnnot : m.getAnnotationsByType(Binary.class)) {
LOGGER.debug(" * Processing @Binary annotation");
String binary = EnvironmentLoader.loadFromEnvironment(binaryAnnot.binary());
String workingDir = EnvironmentLoader.loadFromEnvironment(binaryAnnot.workingDir());
if (binary == null || binary.isEmpty()) {
ErrorManager.error("Empty binary annotation for method " + m.getName());
}
String binarySignature = calleeMethodSignature.toString() + LoaderUtils.BINARY_SIGNATURE;
signatures.add(binarySignature);
// Load specific method constraints if present
MethodResourceDescription implConstraints = defaultConstraints;
if (binaryAnnot.constraints() != null) {
implConstraints = new MethodResourceDescription(binaryAnnot.constraints());
implConstraints.mergeMultiConstraints(defaultConstraints);
}
// Register method implementation
Implementation impl = new BinaryImplementation(binary, workingDir, methodId, implId, implConstraints);
++implId;
implementations.add(impl);
}
}
Aggregations