Commit 8afda64a authored by Luís Nogueira's avatar Luís Nogueira

Initial version of the integration with COMPSs via dataClay

parent 95252ed1
### Java ###
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Linux ###
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
NFRTool - Time and Energy
\ No newline at end of file
Go to /dataclay directory and initialize dataclay
(Start dataClay)
$ ./start_dataclay.sh
(Register model located in `model` folder into started dataClay instance)
$ ./register_model.sh
(Get stubs of your registered model)
$ ./get_stubs.sh
Go to /app directory
(To be able to compile the app outside a container, install the stubs in the local maven repository)
$ ./install_mvn_stubs.sh
Finnaly, run the demo which includes Time and Energy requirements
$ ./run_nfrtool.sh
\ No newline at end of file
<factorypath>
<factorypathentry kind="VARJAR" id="M2_REPO/es/bsc/compss/nfrtool-dataclay-stubs/2.0/nfrtool-dataclay-stubs-2.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/es/bsc/dataclay/dataclay/2.1/dataclay-2.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/grpc/grpc-netty-shaded/1.25.0/grpc-netty-shaded-1.25.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/grpc/grpc-core/1.25.0/grpc-core-1.25.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/gson/gson/2.8.5/gson-2.8.5.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/android/annotations/4.1.1.4/annotations-4.1.1.4.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/perfmark/perfmark-api/0.19.0/perfmark-api-0.19.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/opencensus/opencensus-api/0.21.0/opencensus-api-0.21.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/opencensus/opencensus-contrib-grpc-metrics/0.21.0/opencensus-contrib-grpc-metrics-0.21.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/grpc/grpc-protobuf/1.25.0/grpc-protobuf-1.25.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/grpc/grpc-api/1.25.0/grpc-api-1.25.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/grpc/grpc-context/1.25.0/grpc-context-1.25.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/errorprone/error_prone_annotations/2.3.3/error_prone_annotations-2.3.3.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/codehaus/mojo/animal-sniffer-annotations/1.17/animal-sniffer-annotations-1.17.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/protobuf/protobuf-java/3.10.0/protobuf-java-3.10.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/guava/28.1-android/guava-28.1-android.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/api/grpc/proto-google-common-protos/1.12.0/proto-google-common-protos-1.12.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/grpc/grpc-protobuf-lite/1.25.0/grpc-protobuf-lite-1.25.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/grpc/grpc-stub/1.25.0/grpc-stub-1.25.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/postgresql/postgresql/9.4.1212/postgresql-9.4.1212.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/ow2/asm/asm/7.2/asm-7.2.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/ow2/asm/asm-commons/7.2/asm-commons-7.2.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/ow2/asm/asm-analysis/7.2/asm-analysis-7.2.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/ow2/asm/asm-tree/7.2/asm-tree-7.2.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/ow2/asm/asm-util/7.2/asm-util-7.2.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/logging/log4j/log4j-api/2.11.0/log4j-api-2.11.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/logging/log4j/log4j-core/2.11.0/log4j-core-2.11.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/fasterxml/jackson/core/jackson-databind/2.10.0/jackson-databind-2.10.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/fasterxml/jackson/core/jackson-annotations/2.10.0/jackson-annotations-2.10.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/fasterxml/jackson/core/jackson-core/2.10.0/jackson-core-2.10.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/commons-io/commons-io/2.5/commons-io-2.5.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/yaml/snakeyaml/1.25/snakeyaml-1.25.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/commons/commons-dbcp2/2.1.1/commons-dbcp2-2.1.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/commons-logging/commons-logging/1.2/commons-logging-1.2.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/xerial/sqlite-jdbc/3.21.0.1/sqlite-jdbc-3.21.0.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/javax/persistence/javax.persistence-api/2.2/javax.persistence-api-2.2.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/aspectj/aspectjrt/1.9.4/aspectjrt-1.9.4.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/aspectj/aspectjtools/1.9.4/aspectjtools-1.9.4.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/es/bsc/dataclay/extrae/3.6.1/extrae-3.6.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/reflections/reflections/0.9.11/reflections-0.9.11.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/ibm/wala/com.ibm.wala.shrike/1.5.0/com.ibm.wala.shrike-1.5.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/ibm/wala/com.ibm.wala.core/1.5.0/com.ibm.wala.core-1.5.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/ibm/wala/com.ibm.wala.cast/1.5.0/com.ibm.wala.cast-1.5.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/ibm/wala/com.ibm.wala.cast.java/1.5.0/com.ibm.wala.cast.java-1.5.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/ibm/wala/com.ibm.wala.util/1.5.0/com.ibm.wala.util-1.5.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/ibm/wala/com.ibm.wala.cast.java.ecj/1.5.0/com.ibm.wala.cast.java.ecj-1.5.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/eclipse/jdt/org.eclipse.jdt.core/3.10.0/org.eclipse.jdt.core-3.10.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/json/json/20190722/json-20190722.jar" enabled="true" runInBatchMode="false"/>
</factorypath>
/bin/
/target/
/.classpath
/.project
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations
org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
{
"java.configuration.updateBuildConfiguration": "automatic"
}
\ No newline at end of file
Go to /dataclay directory and initialize dataclay
(Start dataClay)
$ ./start_dataclay.sh
(Register model located in `model` folder into started dataClay instance)
$ ./register_model.sh
(Get stubs of your registered model)
$ ./get_stubs.sh
Go to /app directory
Change the StubsClasspath in cfgfiles/session.propeties to the correct path were the stubs generated by ./get_stubs.sh were created
To be able to compile the app outside a container, install the stubs in the local maven repository
$ ./install_mvn_stubs.sh
Finnaly, run the demo which includes Time and Energy requirements
$ ./run_nfrtool.sh
\ No newline at end of file
HOST=localhost
TCPPORT=11034
CHECK_LOG4J_DEBUG=true
<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="60" status="off">
<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601} %p [%c] [%t] [%C{1}:%L] %m%n"></PatternLayout>
</Console>
</Appenders>
<Loggers>
<Logger name="DataClay.api" level="off" />
<!-- Runtime -->
<Logger name="ClientRuntime" level="off" />
<Logger name="ClientManagementLib" level="off"/>
<Logger name="DataClayRuntime" level="off"/>
<Logger name="DataServiceRuntime" level="off"/>
<Logger name="DataClayObjectLoader" level="off"/>
<Logger name="DataClayObject" level="off" /> <!-- This is very verbose! -->
<!-- Data service -->
<Logger name="DataService" level="off"/>
<Logger name="ExecutionEnvironmentSrv" level="off"/>
<!-- Lockers -->
<Logger name="dataclay.util.classloaders.SyncClass" level="off"/>
<Logger name="dataclay.heap.LockerPool" level="off"/>
<Logger name="LockerPool" level="off"/>
<Logger name="dataclay.util.classloaders.ClassLockers" level="off"/>
<!-- Garbage collection -->
<Logger name="GlobalGC" level="off"/>
<Logger name="heap.HeapManager" level="off"/>
<Logger name="ReferenceCounting" level="off"/>
<Logger name="StorageLocation" level="off"/>
<!-- Logic module -->
<Logger name="LogicModule" level="off"/>
<Logger name="LMDB" level="off"/>
<Logger name="managers" level="off" />
<Logger name="MetaDataService.db" level="off" />
<Logger name="MetaDataService" level="off" />
<!-- Communication -->
<Logger name="io.grpc" level="off"/>
<Logger name="io.netty" level="off"/>
<Logger name="NettyClientHandler" level="off"/>
<Logger name="grpc.client" level="off"/>
<Logger name="communication.LogicModule.service" level="off"/>
<Logger name="grpc.client.logicmodule" level="off"/>
<Logger name="grpc.client.dataservice.DS1" level="off"/>
<!-- Databases -->
<Logger name="dataclay.dbhandler" level="off"/>
<Logger name="dbhandler.PostgresConnection" level="off" />
<Logger name="org.apache.commons.dbcp2" level="off"/>
<Logger name="PostgresHandler" level="off"/>
<Logger name="SQLHandler" level="off"/>
<!-- Misc -->
<Logger name="util" level="off" />
<Logger name="exceptions" level="debug"/>
<Logger name="Paraver" level="off"/>
<Logger name="DataClaySerializationLib" level="off"/>
<Logger name="DataClayDeserializationLib" level="off"/>
<!-- ROOT LOGGER -->
<Root level="debug">
<AppenderRef ref="ConsoleAppender" />
</Root>
</Loggers>
</Configuration>
Account=ElasticUser
Password=ElasticPass
DataSets=ElasticDS
DataSetForStore=ElasticDS
StubsClasspath=/home/luis/Documents/elastic/new_nfrtool/dataclay/stubs/
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main(){
for(;;){
printf("Worker %d is running...\n", getpid());
sleep(1);
}
}
#!/bin/bash
cd ../dataclay/stubs
jar cvf ../stubs.jar .
mvn install:install-file -Dfile=../stubs.jar -DgroupId=es.bsc.compss -DartifactId=nfrtool-dataclay-stubs -Dversion=2.0 -Dpackaging=jar -DcreateChecksum=true
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>es.bsc.dataclay</groupId>
<artifactId>nfrtool-demo</artifactId>
<version>2.1</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.release>8</maven.compiler.release>
</properties>
<dependencies>
<dependency>
<groupId>es.bsc.compss</groupId>
<artifactId>nfrtool-dataclay-stubs</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>es.bsc.dataclay</groupId>
<artifactId>dataclay</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>
app.NFRTool
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
#!/bin/bash
loadavg=`cat /proc/loadavg`
pastminute=`echo $loadavg|awk '{printf $1 * 100}'`
past5minutes=`echo $loadavg|awk '{printf $2 * 100}'`
past15minutes=`echo $loadavg|awk '{printf $3 * 100}'`
echo "{cpuload:"$pastminute"}"
#!/bin/bash
ps -o pcpu= -p $1 | awk '{printf("%d",$1 * 100)}'
#!/bin/bash
ps -eo pcpu,pid,cmd | sort -k1 -r -n | head -10|awk '{printf("{pcpu:%.2f,pid:%d,cmd:%s}\n",$1,$2,$3)}'
#!/bin/bash
energy_now=`cat /sys/class/power_supply/BAT0/energy_now`
energy_full=`cat /sys/class/power_supply/BAT0/energy_full`
power_now=`cat /sys/class/power_supply/BAT0/power_now`
charge=`echo $energy_now $energy_full | awk '{ printf("%d\n", $1/$2 * 100) }'`
#echo "Charge: "$charge"%"
consumption=`echo $power_now | awk '{ printf("%d\n", $1*10^-6) }'`
#echo "Power consumption: "$consumption"W"
echo "{charge:"$charge",consumption:"$consumption}
#!/bin/bash
mvn clean package
java -jar target/nfrtool-demo-2.1.jar elastic --node elasticnode 192.168.1.1 100 80 --master elasticnode 111 --worker elasticnode 222 127.0.0.1
/*
* Copyright 2020 Instituto Superior de Engenharia do Porto
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package app;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.json.JSONObject;
import es.bsc.compss.nfr.model.Worker;
import java.util.List;
public class EnergyMonitor implements Runnable {
private NFRViolationQueue queue;
private List<Worker> workerList;
private int energyCapacity;
EnergyMonitor(NFRViolationQueue queue, List<Worker> workerList) {
this.queue = queue;
this.workerList = workerList;
energyCapacity = 0;
}
private int getCharge(){
int charge = 0;
try {
Process p = Runtime.getRuntime().exec("probes/energy/energyprobe.sh");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String output = stdInput.readLine();
JSONObject jsonObject = new JSONObject(output);
charge = jsonObject.getInt("charge");
} catch (Exception e) {
e.printStackTrace();
}
return charge;
}
private void getNodeEnergyCapacity(){
if(workerList.size() > 0){
Worker worker = workerList.get(0);
energyCapacity = worker.getNode().getEnergyCapacity();
}
}
public void run() {
getNodeEnergyCapacity();
int charge = 0;
while (!Thread.interrupted()) {
charge = getCharge();
if(charge < energyCapacity){
NFRViolation violation = new NFRViolation("energy", "charge", charge);
queue.addNFRViolation(violation);
System.out.println(Thread.currentThread().getName() + " added energy violation to queue: " + charge);
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
System.out.println(Thread.currentThread().getName() + " was interrupted. Aborting...");
break;
}
}
}
}
\ No newline at end of file
/*
* Copyright 2020 Instituto Superior de Engenharia do Porto
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package app;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import es.bsc.dataclay.api.DataClay;
import es.bsc.compss.nfr.model.*;
import es.bsc.dataclay.exceptions.metadataservice.ObjectNotRegisteredException;
import java.util.ArrayList;
import java.util.List;
/**
* NFRTool for time and energy dimensions.
*/
public class NFRTool {
public static ElasticSystem createNewElasticSystem(String localIP) throws Exception{
ElasticSystem system = new ElasticSystem();
system.makePersistent("system");
String applicationName = "testApp";
// Create application
COMPSsApplication app = new COMPSsApplication(applicationName,"1.0");
system.addApplication(app);
// Create node1 and persist it
String nodeName = localIP;
Node localhost = new Node(nodeName, 100, 80, 30);
localhost.makePersistent(nodeName);
system.addNode(localhost);
// Get node by alias
Node node = Node.getByAlias(nodeName);
// Create master
Master master = new Master(node, 111);
master.setApplication(app);
master.makePersistent();
// Set master of application
app.setMaster(master);
int pid1 = 0, pid2 = 0;
// Execute fake workers to monitor
try {
Process p1 = Runtime.getRuntime().exec("fake_worker/fakeworker");
pid1 = (int) p1.pid();
Process p2 = Runtime.getRuntime().exec("fake_worker/fakeworker");
pid2 = (int) p2.pid();
} catch (Exception e) {
e.printStackTrace();
}
// Create workers
Worker worker1 = new Worker(node, pid1 ,true, app);
Worker worker2 = new Worker(node, pid2 ,true, app);
// Add worker to application
app.addWorker(worker1);
app.addWorker(worker2);
// Print application information
System.out.println("=== Application information ===");
System.out.println(app.toString());
return system;
}
public static void getCurrentElasticSystem(ElasticSystem system){
System.out.println();
System.out.println("Deployed ELASTIC system:");
system.getApplications().forEach(app -> {
System.out.println(String.format("App: %s", app.getName()));
System.out.println(String.format("\tMaster: %s with PID %d", app.getMaster().getNode().getName(), app.getMaster().getPid()));
System.out.println("\tWorkers:");
app.getWorkers().forEach(w -> System.out.println(String.format("\t\t- %s (PID: %d), active = %b", w.getAddress(), w.getPid(), w.isActive())));
System.out.println();
});
/*COMPSsApplication app = system.getApplications().get(system.getApplications().size() - 1);
List<Worker> workers = app.getWorkers();
workers.get(workers.size() - 1).setActive(!workers.get(workers.size() - 1).isActive());*/
}
public static List<Worker> getWorkersToMonitor(ElasticSystem system, String localIP){
List<Worker> workerList = new ArrayList<Worker>();
system.getApplications().forEach(app -> {
app.getWorkers().forEach(worker -> {
if(worker.getAddress().equals(localIP)){
workerList.add(worker);
}
});
});
return workerList;
}
public static void main(String[] args) throws Exception {
String localIP;
try {
localIP = InetAddress.getLocalHost().getHostAddress();
System.out.println("NFRTool current local IP address: " + localIP);
} catch (UnknownHostException e) {
e.printStackTrace();
localIP = "localhost";
}
Socket socket = new Socket();
socket.connect(new InetSocketAddress("google.com", 80));
String publicIP = socket.getLocalAddress().getHostAddress();
System.out.println("NFRTool current public IP address: " + publicIP);
socket.close();
// Init dataClay session
DataClay.init();
ElasticSystem system;
try {
system = ElasticSystem.getByAlias("system");
System.out.println("ELASTIC system exists!");
getCurrentElasticSystem(system);
} catch (ObjectNotRegisteredException e) {
System.out.println("ELASTIC system has not been deployed. Creating a new one for demo purposes...");
system = createNewElasticSystem(localIP);
}
List<Worker> workerList = getWorkersToMonitor(system,localIP);
System.out.println("Workers running locally:");
workerList.forEach(worker -> System.out.println("Worker: " + worker.getPid()));
NFRViolationQueue queue = new NFRViolationQueue();
ResourceManager resourceManager = new ResourceManager(queue, workerList);
Thread rmThread = new Thread(resourceManager,"Resource Manager");
TimeMonitor timeMonitor = new TimeMonitor(queue, workerList);
Thread tmThread = new Thread(timeMonitor,"Time Monitor");
EnergyMonitor energyMonitor = new EnergyMonitor(queue, workerList);
Thread emThread = new Thread(energyMonitor,"Energy Monitor");
rmThread.start();
tmThread.start();