use of es.bsc.compss.types.implementations.ServiceImplementation 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);
}
}
use of es.bsc.compss.types.implementations.ServiceImplementation in project compss by bsc-wdc.
the class TestCompatible method checkResourcesAssignedToImpl.
private static String checkResourcesAssignedToImpl(Implementation impl, Worker<?> resource) {
if ((impl.getTaskType().equals(TaskType.METHOD) && resource.getType().equals(Resource.Type.SERVICE)) || (impl.getTaskType().equals(TaskType.SERVICE) && resource.getType().equals(Resource.Type.WORKER))) {
return "types";
}
if (resource.getType() == Worker.Type.WORKER) {
MethodImplementation mImpl = (MethodImplementation) impl;
MethodResourceDescription iDescription = mImpl.getRequirements();
MethodWorker worker = (MethodWorker) resource;
MethodResourceDescription wDescription = (MethodResourceDescription) worker.getDescription();
/*
* *********************************************************************************************************
* COMPUTING UNITS
**********************************************************************************************************/
if ((iDescription.getTotalCPUComputingUnits() >= MethodResourceDescription.ONE_INT) && (wDescription.getTotalCPUComputingUnits() >= MethodResourceDescription.ONE_INT) && (wDescription.getTotalCPUComputingUnits() < iDescription.getTotalCPUComputingUnits())) {
return "computingUnits";
}
/*
* *********************************************************************************************************
* PROCESSOR
***********************************************************************************************************/
for (Processor ip : iDescription.getProcessors()) {
// Check if processor can be executed in worker
boolean canBeHosted = false;
for (Processor wp : wDescription.getProcessors()) {
// Static checks
if (!ip.getName().equals(MethodResourceDescription.UNASSIGNED_STR) && !wp.getName().equals(MethodResourceDescription.UNASSIGNED_STR) && !wp.getName().equals(ip.getName())) {
// System.out.println("DUE TO: " + ip.getName() + " != " + wp.getName());
continue;
}
if (ip.getSpeed() != MethodResourceDescription.UNASSIGNED_FLOAT && wp.getSpeed() != MethodResourceDescription.UNASSIGNED_FLOAT && wp.getSpeed() < ip.getSpeed()) {
// System.out.println("DUE TO: " + ip.getSpeed() + " != " + wp.getSpeed());
continue;
}
if (!ip.getArchitecture().equals(MethodResourceDescription.UNASSIGNED_STR) && !wp.getArchitecture().equals(MethodResourceDescription.UNASSIGNED_STR) && !wp.getArchitecture().equals(ip.getArchitecture())) {
// System.out.println("DUE TO: " + ip.getArchitecture() + " != " + wp.getArchitecture());
continue;
}
if ((!ip.getPropName().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wp.getPropName().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!ip.getPropName().equals(wp.getPropName()))) {
// System.out.println("DUE TO: " + ip.getPropName() + " != " + wp.getPropName());
continue;
}
if ((!ip.getPropValue().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wp.getPropValue().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!ip.getPropValue().equals(wp.getPropValue()))) {
// System.out.println("DUE TO: " + ip.getPropValue() + " != " + wp.getPropValue());
continue;
}
// Dynamic checks
if (wp.getComputingUnits() >= ip.getComputingUnits()) {
canBeHosted = true;
break;
} else {
// System.out.println("DUE TO: " + ip.getComputingUnits() + " != " + wp.getComputingUnits());
}
}
if (!canBeHosted) {
return "processor";
}
}
/*
* *********************************************************************************************************
* MEMORY
***********************************************************************************************************/
if ((iDescription.getMemorySize() != MethodResourceDescription.UNASSIGNED_FLOAT) && (wDescription.getMemorySize() != MethodResourceDescription.UNASSIGNED_FLOAT) && (wDescription.getMemorySize() < iDescription.getMemorySize())) {
return "memorySize";
}
if ((!iDescription.getMemoryType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!iDescription.getMemoryType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wDescription.getMemoryType().equals(iDescription.getMemoryType()))) {
return "memoryType";
}
/*
* *********************************************************************************************************
* STORAGE
***********************************************************************************************************/
if ((iDescription.getStorageSize() != MethodResourceDescription.UNASSIGNED_FLOAT) && (wDescription.getStorageSize() != MethodResourceDescription.UNASSIGNED_FLOAT) && (wDescription.getStorageSize() < iDescription.getStorageSize())) {
return "storageSize";
}
if ((!iDescription.getStorageType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!iDescription.getStorageType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wDescription.getStorageType().equals(iDescription.getStorageType()))) {
return "storageType";
}
/*
* *********************************************************************************************************
* OPERATING SYSTEM
***********************************************************************************************************/
if ((!iDescription.getOperatingSystemType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!iDescription.getOperatingSystemType().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wDescription.getOperatingSystemType().equals(iDescription.getOperatingSystemType()))) {
return "operatingSystemType";
}
if ((!iDescription.getOperatingSystemDistribution().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!iDescription.getOperatingSystemDistribution().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wDescription.getOperatingSystemDistribution().equals(iDescription.getOperatingSystemDistribution()))) {
return "operatingSystemDistribution";
}
if ((!iDescription.getOperatingSystemVersion().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!iDescription.getOperatingSystemVersion().equals(MethodResourceDescription.UNASSIGNED_STR)) && (!wDescription.getOperatingSystemVersion().equals(iDescription.getOperatingSystemVersion()))) {
return "operatingSystemVersion";
}
/*
* *********************************************************************************************************
* APPLICATION SOFTWARE
***********************************************************************************************************/
if (!(iDescription.getAppSoftware().isEmpty()) && !(wDescription.getAppSoftware().containsAll(iDescription.getAppSoftware()))) {
return "appSoftware";
}
/*
* *********************************************************************************************************
* HOST QUEUE
***********************************************************************************************************/
if (!(iDescription.getHostQueues().isEmpty()) && !(wDescription.getHostQueues().containsAll(iDescription.getHostQueues()))) {
return "hostQueues";
}
} else if (resource.getType() == Worker.Type.SERVICE) {
ServiceImplementation sImpl = (ServiceImplementation) impl;
ServiceResourceDescription iDescription = sImpl.getRequirements();
ServiceWorker worker = (ServiceWorker) resource;
ServiceResourceDescription wDescription = (ServiceResourceDescription) worker.getDescription();
if (!wDescription.getServiceName().equals(iDescription.getServiceName())) {
return "ServiceName";
}
if (!wDescription.getNamespace().equals(iDescription.getNamespace())) {
return "Namespace";
}
if (!wDescription.getPort().equals(iDescription.getPort())) {
return "Port";
}
} else {
return "Unknown resource type";
}
/*
* ************************************************************************************************************
* ALL CONSTAINT VALUES OK
*************************************************************************************************************/
return null;
}
Aggregations