Skip to content

Commit

Permalink
Situations
Browse files Browse the repository at this point in the history
Adjustments to the jpf part, and small changes to the runtime model.
Also, a new ecorediag is introduced to present the architecture for
situations implementation.
  • Loading branch information
Michał Kit committed Sep 2, 2013
1 parent 21a6feb commit 00b3218
Show file tree
Hide file tree
Showing 43 changed files with 670 additions and 84 deletions.
2 changes: 2 additions & 0 deletions jdeeco-core-model/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
eclipse.preferences.version=1
encoding//model-refactoring/AdaptationArchitecture.ecore=UTF-8
encoding//model-refactoring/AdaptationArchitecture.ecorediag=UTF-8
encoding//model-refactoring/Providers.ecore=UTF-8
encoding//model-refactoring/Providers.ecorediag=UTF-8
encoding//model-refactoring/RuntimeArchitecture.ecore=UTF-8
Expand Down
3 changes: 0 additions & 3 deletions jdeeco-core-model/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: cz.cuni.mff.d3s.jdeeco.core.model.runtimemodel,
cz.cuni.mff.d3s.jdeeco.core.model.runtimemodel.impl,
cz.cuni.mff.d3s.jdeeco.core.model.runtimemodel.util
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecore;visibility:=reexport
Bundle-ActivationPolicy: lazy
58 changes: 58 additions & 0 deletions jdeeco-core-model/model-refactoring/AdaptationArchitecture.ecore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="adaptationarchitecture" nsURI="http://adaptationarchitecture/1.0"
nsPrefix="adaptationarchitecture">
<eAnnotations source="Michal you are so very cool"/>
<eClassifiers xsi:type="ecore:EClass" name="Oracle">
<eOperations name="isToBeScheduled">
<eParameters name="job" eType="#//Job"/>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EReference" name="solver" lowerBound="1"
eType="#//SATSolver"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="irms" upperBound="-1" eType="#//Invariant"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="SATSolver" abstract="true">
<eOperations name="solve"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Runtime" instanceClassName="cz.cuni.mff.d3s.deeco.runtime.Runtime">
<eOperations name="run" lowerBound="1"/>
<eOperations name="shutdown" lowerBound="1"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="oracle" lowerBound="1"
eType="#//Oracle" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Scheduler">
<eOperations name="schedule">
<eParameters name="job" eType="#//Job"/>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EReference" name="oracle" lowerBound="1"
eType="#//Oracle"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Job" instanceClassName="cz.cuni.mff.d3s.deeco.scheduling.Job"/>
<eClassifiers xsi:type="ecore:EClass" name="SAT4JSolver" eSuperTypes="#//SATSolver"/>
<eClassifiers xsi:type="ecore:EClass" name="IRMPrimitive" interface="true"/>
<eClassifiers xsi:type="ecore:EClass" name="Invariant" eSuperTypes="#//IRMPrimitive">
<eStructuralFeatures xsi:type="ecore:EReference" name="components" lowerBound="1"
upperBound="-1" eType="#//Component"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="O"/>
<eClassifiers xsi:type="ecore:EEnum" name="EEnum0"/>
<eClassifiers xsi:type="ecore:EClass" name="Operation" eSuperTypes="#//IRMPrimitive">
<eStructuralFeatures xsi:type="ecore:EReference" name="children" lowerBound="2"
upperBound="-1" eType="#//IRMPrimitive"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Assumption" eSuperTypes="#//Invariant #//Evaluable"/>
<eClassifiers xsi:type="ecore:EClass" name="ProcessInvariant" eSuperTypes="#//Invariant #//Evaluable">
<eStructuralFeatures xsi:type="ecore:EReference" name="componentProcess" lowerBound="1"
eType="#//ComponentProcess"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ExchangeInvariant" eSuperTypes="#//Invariant #//Evaluable">
<eStructuralFeatures xsi:type="ecore:EReference" name="ensemble" lowerBound="1"
eType="#//Ensemble"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ComponentProcess" instanceClassName="cz.cuni.mff.d3s.deeco.runtime.model.ComponentProcess"
eSuperTypes="#//ProcessInvariant"/>
<eClassifiers xsi:type="ecore:EClass" name="Ensemble" instanceClassName="cz.cuni.mff.d3s.deeco.runtime.model.Ensemble"
eSuperTypes="#//ExchangeInvariant"/>
<eClassifiers xsi:type="ecore:EClass" name="Evaluable" interface="true"/>
<eClassifiers xsi:type="ecore:EClass" name="Component" instanceClassName="cz.cuni.mff.d3s.deeco.runtime.model.Component"/>
</ecore:EPackage>
459 changes: 459 additions & 0 deletions jdeeco-core-model/model-refactoring/AdaptationArchitecture.ecorediag

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions jdeeco-core-model/model-refactoring/RuntimeMetadata.ecorediag
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</children>
<styles xmi:type="notation:ShapeStyle" xmi:id="_PwVowdJyEeK5vfh7vJCPkA" fontColor="4210752" fontName="Segoe UI" fontHeight="10" fillColor="13761016" lineColor="8421504"/>
<element xmi:type="ecore:EClass" href="RuntimeMetadata.ecore#//Component"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_PwVowtJyEeK5vfh7vJCPkA" x="-96" y="-25" width="127"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_PwVowtJyEeK5vfh7vJCPkA" x="-85" y="-25" width="127"/>
</children>
<children xmi:type="notation:Node" xmi:id="_Gw-2MNJ0EeK5vfh7vJCPkA" type="1001">
<children xmi:type="notation:Node" xmi:id="_GxIAINJ0EeK5vfh7vJCPkA" type="4001"/>
Expand Down Expand Up @@ -593,7 +593,7 @@
<styles xmi:type="notation:ConnectorStyle" xmi:id="_rHmm8dKVEeK5vfh7vJCPkA" routing="Rectilinear" lineColor="4210752"/>
<styles xmi:type="notation:FontStyle" xmi:id="_rHmm8tKVEeK5vfh7vJCPkA" fontName="Segoe UI"/>
<element xsi:nil="true"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_rHmm89KVEeK5vfh7vJCPkA" points="[-56, -16, 165, 45]$[-219, -37, 2, 24]"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_rHmm89KVEeK5vfh7vJCPkA" points="[1, -20, 386, 140]$[1, -155, 386, 5]$[-368, -155, 17, 5]"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_rHwX8NKVEeK5vfh7vJCPkA" id="(0.8882978723404256,0.5147058823529411)"/>
</edges>
<edges xmi:type="notation:Edge" xmi:id="_vEhIcNKVEeK5vfh7vJCPkA" type="3002" source="__pVF8NKSEeK5vfh7vJCPkA" target="_pkhqoNKVEeK5vfh7vJCPkA">
Expand Down Expand Up @@ -800,10 +800,10 @@
</edges>
<edges xmi:type="notation:Edge" xmi:id="_9zzG8PkOEeKAScggIIlt-Q" type="3002" source="_fXVqIPOgEeKGfIUqTb093w" target="_PwVowNJyEeK5vfh7vJCPkA">
<children xmi:type="notation:Node" xmi:id="_9z0VEPkOEeKAScggIIlt-Q" type="4011">
<layoutConstraint xmi:type="notation:Location" xmi:id="_9z0VEfkOEeKAScggIIlt-Q" x="-10" y="-10"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_9z0VEfkOEeKAScggIIlt-Q" x="-6" y="-25"/>
</children>
<children xmi:type="notation:Node" xmi:id="_9z08IPkOEeKAScggIIlt-Q" type="4012">
<layoutConstraint xmi:type="notation:Location" xmi:id="_9z08IfkOEeKAScggIIlt-Q" x="10" y="10"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_9z08IfkOEeKAScggIIlt-Q" x="-39" y="-20"/>
</children>
<styles xmi:type="notation:ConnectorStyle" xmi:id="_9zzG8fkOEeKAScggIIlt-Q" lineColor="4210752"/>
<styles xmi:type="notation:FontStyle" xmi:id="_9zzG8vkOEeKAScggIIlt-Q" fontColor="4210752" fontName="Segoe UI" fontHeight="10"/>
Expand Down
2 changes: 1 addition & 1 deletion jdeeco-core/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</attributes>
</classpathentry>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
22 changes: 21 additions & 1 deletion jdeeco-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<destFileName>${coreJar}</destFileName>
<outputDirectory>${dist}</outputDirectory>
</artifactItem>

<artifactItem>
<groupId>uk.com.robust-it</groupId>
<artifactId>cloning</artifactId>
Expand Down Expand Up @@ -126,6 +126,26 @@
<dependencies>
<!-- dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId>
<version>6.5.1</version> </dependency -->
<dependency>
<groupId>org.ow2.sat4j</groupId>
<artifactId>org.ow2.sat4j.core</artifactId>
<version>2.3.4</version>
</dependency>
<dependency>
<groupId>org.ow2.sat4j</groupId>
<artifactId>org.ow2.sat4j.pb</artifactId>
<version>2.3.4</version>
</dependency>
<dependency>
<groupId>org.ow2.sat4j</groupId>
<artifactId>org.ow2.sat4j.maxsat</artifactId>
<version>2.3.4</version>
</dependency>
<dependency>
<groupId>org.ow2.sat4j</groupId>
<artifactId>org.ow2.sat4j.csp</artifactId>
<version>2.3.4</version>
</dependency>
<dependency>
<groupId>uk.com.robust-it</groupId>
<artifactId>cloning</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import java.lang.annotation.Target;

/**
* Membership is used to mark the method in the ensemble definition
* Condition is used to mark the method in the ensemble definition
* class as the membership function.
*
* @author Michal Kit
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Membership {
public @interface Condition {
double value() default 0.0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cz.cuni.mff.d3s.deeco.processor;

import static cz.cuni.mff.d3s.deeco.processor.AnnotationHelper.getAnnotatedMethods;
import static cz.cuni.mff.d3s.deeco.processor.ParserHelper.getParameterList;

import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;

import cz.cuni.mff.d3s.deeco.annotations.Condition;
import cz.cuni.mff.d3s.deeco.exceptions.ComponentEnsembleParseException;
import cz.cuni.mff.d3s.deeco.path.grammar.ParseException;
import cz.cuni.mff.d3s.deeco.runtime.model.BooleanCondition;
import cz.cuni.mff.d3s.deeco.runtime.model.Parameter;

public class ConditionParser {

public static List<BooleanCondition> parseBooleanConditions(Class<?> c) {
assert (c != null);
List<BooleanCondition> result = new LinkedList<>();
List<Parameter> parameters;
for (Method m : getAnnotatedMethods(c, Condition.class)) {
if (m == null) {
continue;
}
if (!m.getReturnType().isAssignableFrom(boolean.class)) {
continue;
}
try {
parameters = getParameterList(m);
} catch (ParseException pe) {
continue;
} catch (ComponentEnsembleParseException cepe) {
continue;
}
result.add(new BooleanCondition(parameters, m));
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package cz.cuni.mff.d3s.deeco.processor;

import static cz.cuni.mff.d3s.deeco.processor.ParserHelper.getParameterList;
import static cz.cuni.mff.d3s.deeco.processor.AnnotationHelper.getAnnotatedMethod;
import static cz.cuni.mff.d3s.deeco.processor.ConditionParser.parseBooleanConditions;
import static cz.cuni.mff.d3s.deeco.processor.ParserHelper.getParameterList;
import static cz.cuni.mff.d3s.deeco.processor.ScheduleHelper.getPeriodicSchedule;
import static cz.cuni.mff.d3s.deeco.processor.ScheduleHelper.getTriggeredSchedule;

import java.lang.reflect.Method;
import java.util.List;

import cz.cuni.mff.d3s.deeco.annotations.KnowledgeExchange;
import cz.cuni.mff.d3s.deeco.annotations.Membership;
import cz.cuni.mff.d3s.deeco.annotations.PeriodicScheduling;
import cz.cuni.mff.d3s.deeco.definitions.EnsembleDefinition;
import cz.cuni.mff.d3s.deeco.exceptions.ComponentEnsembleParseException;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManager;
import cz.cuni.mff.d3s.deeco.path.grammar.ParseException;
import cz.cuni.mff.d3s.deeco.runtime.model.BooleanCondition;
import cz.cuni.mff.d3s.deeco.runtime.model.Ensemble;
import cz.cuni.mff.d3s.deeco.runtime.model.Condition;
import cz.cuni.mff.d3s.deeco.runtime.model.Exchange;
import cz.cuni.mff.d3s.deeco.runtime.model.Parameter;
import cz.cuni.mff.d3s.deeco.runtime.model.PeriodicSchedule;
Expand Down Expand Up @@ -49,25 +49,14 @@ public static Ensemble extractEnsembleProcess(Class<?> c)
throw new ParseException("The class " + c.getName()
+ " is not an ensemble definition.");
}
Method m = getAnnotatedMethod(c, Membership.class);
if (m == null) {
throw new ParseException("The ensemble " + c.getName()
+ " definition does not define a membership function");
}
if (!m.getReturnType().isAssignableFrom(boolean.class)) {
throw new ParseException(c.getName()
+ ": MembershipMethod function needs to return boolean");
List<BooleanCondition> conditions = parseBooleanConditions(c);
if (conditions.size() != 1) {
throw new ParseException("The class " + c.getName()
+ " should contain exactly one membership condition.");
}
BooleanCondition mc = conditions.get(0);
List<Parameter> parameters;
try {
parameters = getParameterList(m);
} catch (ComponentEnsembleParseException cepe) {
throw new ParseException(c.getName()
+ ": Parameters for the method " + m.getName()
+ " cannot be parsed.");
}
Condition mc = new Condition(parameters, m);
m = getAnnotatedMethod(c, KnowledgeExchange.class);
Method m = getAnnotatedMethod(c, KnowledgeExchange.class);
if (m == null) {
throw new ParseException(
"The ensemble definition does not define a knowledge exchange function");
Expand Down
24 changes: 14 additions & 10 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,24 @@
public class Runtime {

private RuntimeMetadata runtimeMetadata;
private KnowledgeManager km;
private Scheduler scheduler;
private List<TriggeredJobProducer> triggeredJobProducers;

private Runtime(boolean useMXBeans) {
if (useMXBeans)
RuntimeMX.registerMBeanForRuntime(this);
}
private final KnowledgeManager km;
private final Scheduler scheduler;
private final List<TriggeredJobProducer> triggeredJobProducers;
//private final Oracle oracle;

public Runtime(Scheduler scheduler, KnowledgeManager km) {
this(scheduler, km, false);
}

public Runtime(Scheduler scheduler, KnowledgeManager km, boolean useMXBeans) {
this(useMXBeans);
assert (km != null);
assert (scheduler != null);
if (useMXBeans)
RuntimeMX.registerMBeanForRuntime(this);
this.scheduler = scheduler;
this.km = km;
this.triggeredJobProducers = new LinkedList<>();
//this.oracle = new Oracle(new SAT4JSolver());
}

public boolean isRunning() {
Expand All @@ -69,10 +67,16 @@ public void shutdown() {
}

//TODO add hot deployment - merge metadata
public synchronized void deploy(RuntimeMetadata runtimeMetadata) {
public synchronized void deployRuntimeMetadata(RuntimeMetadata runtimeMetadata) {
assert (runtimeMetadata != null);
this.runtimeMetadata = runtimeMetadata;
}

// public synchronized void deployIRMInvariant(Invariant invariant) {
// assert (invariant != null);
// //oracle.addIRMInvariant(invariant);
// }


private void deployComponentInstances() {
for (ComponentInstance ci : runtimeMetadata.getComponentInstances()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void registerNewComponent(String className) {
}
InstanceRuntimeMetadataProvider provider = new InstanceRuntimeMetadataProvider();
provider.fromComponentInstance(extractInitialKnowledge(clazz));
rt.deploy(provider.getRuntimeMetadata());
rt.deployRuntimeMetadata(provider.getRuntimeMetadata());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import java.lang.reflect.Method;
import java.util.List;

public class Condition extends Invocable {
public class BooleanCondition extends Invocable {

public Condition(List<Parameter> parameters, Method method) {
public BooleanCondition(List<Parameter> parameters, Method method) {
super(parameters, method, LockingMode.STRONG);
}

public Condition(Method method) {
public BooleanCondition(Method method) {
super(method, LockingMode.STRONG);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

public class Ensemble {
private String id;
private Condition membership;
private BooleanCondition membership;
private Exchange knowledgeExchange;
private Schedule schedule;

public Ensemble(String id, Condition membership,
public Ensemble(String id, BooleanCondition membership,
Exchange knowledgeExchange, Schedule schedule) {
super();
this.id = id;
Expand All @@ -19,7 +19,7 @@ public String getId() {
return id;
}

public Condition getMembership() {
public BooleanCondition getMembership() {
return membership;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import cz.cuni.mff.d3s.deeco.executor.JobExecutionListener;
import cz.cuni.mff.d3s.deeco.knowledge.ISession;
import cz.cuni.mff.d3s.deeco.logging.Log;
import cz.cuni.mff.d3s.deeco.runtime.model.Condition;
import cz.cuni.mff.d3s.deeco.runtime.model.BooleanCondition;
import cz.cuni.mff.d3s.deeco.runtime.model.Ensemble;
import cz.cuni.mff.d3s.deeco.runtime.model.Exchange;
import cz.cuni.mff.d3s.deeco.runtime.model.Parameter;
Expand All @@ -14,7 +14,7 @@

public class EnsembleJob extends Job {

private Condition membership;
private BooleanCondition membership;
private Exchange knowledgeExchange;
private String coordinator;
private String member;
Expand Down
5 changes: 5 additions & 0 deletions jdeeco-core/top.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<invariant>
<description>Emergency measures are taken</description>
<operation>OR</operation>
</invariant>
Loading

0 comments on commit 00b3218

Please sign in to comment.