Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.openbase.jul.pattern.trigger.Trigger;
import org.openbase.jul.pattern.trigger.TriggerPool;
import org.openbase.jul.pattern.trigger.TriggerPool.TriggerAggregation;
import org.openbase.jul.pattern.trigger.TriggerPriority;
import org.openbase.jul.schedule.GlobalCachedExecutorService;
import org.openbase.jul.schedule.RecurrenceEventFilter;
import org.openbase.jul.schedule.SyncObject;
Expand Down Expand Up @@ -164,6 +165,11 @@ protected void postInit() throws InitializationException, InterruptedException {
*/
public void registerActivationTrigger(Trigger trigger, TriggerAggregation aggregation) throws CouldNotPerformException {
try {
/*
* We need to take care that agents that schedule new actions are prioritized
* in contrast to the one which cancel their actions.
*/
trigger.setPriority(TriggerPriority.HIGH);
activationTriggerPool.addTrigger(trigger, aggregation);
} catch (CouldNotPerformException ex) {
throw new InitializationException("Could not add agent to agent pool", ex);
Expand All @@ -172,6 +178,11 @@ public void registerActivationTrigger(Trigger trigger, TriggerAggregation aggreg

public void registerDeactivationTrigger(Trigger trigger, TriggerAggregation aggregation) throws CouldNotPerformException {
try {
/*
* We need to take care that agents that cancel their actions are handled with low priority
* to avoid termination actions to get accidentally activated.
*/
trigger.setPriority(TriggerPriority.LOW);
deactivationTriggerPool.addTrigger(trigger, aggregation);
} catch (CouldNotPerformException ex) {
throw new InitializationException("Could not add agent to agent pool", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@ import java.util.concurrent.TimeoutException
*/
class MasterSlavePowerCycleAgent : AbstractTriggerableAgent() {
private var master: PowerConsumptionSensorRemote? = null
private var slave: PowerStateServiceRemote? = null
private var slave: PowerStateServiceRemote = PowerStateServiceRemote()

@Throws(InitializationException::class, InterruptedException::class)
override fun init(config: UnitConfig) {
super.init(config)
try {
val variableProvider = MetaConfigVariableProvider("AgentConfig", config.metaConfig)
if (master != null) {
master!!.shutdown()
}
if (slave != null) {
slave!!.shutdown()
}

master?.shutdown()
slave.shutdown()

slave = PowerStateServiceRemote()

// resolve master
Expand All @@ -74,23 +73,25 @@ class MasterSlavePowerCycleAgent : AbstractTriggerableAgent() {

// resolve master
try {
slave!!.init(Registries.getUnitRegistry(true).getUnitConfigById(variableProvider.getValue("SLAVE_ID")))
slave.init(Registries.getUnitRegistry(true).getUnitConfigById(variableProvider.getValue("SLAVE_ID")))
} catch (ex: NotAvailableException) {
slave!!.init(
slave.init(
Registries.getUnitRegistry(true).getUnitConfigByAlias(variableProvider.getValue("SLAVE_ALIAS"))
)
}

// activation trigger
registerActivationTrigger(
GenericBoundedDoubleValueTrigger(
master,
variableProvider.getValue("HIGH_ACTIVE_POWER_THRESHOLD", "1.0").toDouble(),
HIGH_ACTIVE,
POWER_CONSUMPTION_STATE_SERVICE,
"getConsumption"
), OR
)
master?.let { master ->
registerActivationTrigger(
GenericBoundedDoubleValueTrigger(
master,
variableProvider.getValue("HIGH_ACTIVE_POWER_THRESHOLD", "1.0").toDouble(),
HIGH_ACTIVE,
POWER_CONSUMPTION_STATE_SERVICE,
"getConsumption"
), OR
)
}
} catch (ex: CouldNotPerformException) {
throw InitializationException(this, ex)
}
Expand All @@ -107,7 +108,7 @@ class MasterSlavePowerCycleAgent : AbstractTriggerableAgent() {
// sync slave
activationState.value?.let { value ->
when (value) {
ACTIVE -> observe(slave!!.setPowerState(ON, getDefaultActionParameter(Timeout.INFINITY_TIMEOUT)))
ACTIVE -> observe(slave.setPowerState(ON, getDefaultActionParameter(Timeout.INFINITY_TIMEOUT)))
INACTIVE, UNKNOWN -> cancelAllObservedActions()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.openbase.app.test.agent.AbstractBCOAgentManagerTest;
import org.openbase.bco.dal.control.layer.unit.MotionDetectorController;
import org.openbase.bco.dal.lib.state.States;
import org.openbase.bco.dal.lib.state.States.Motion;
import org.openbase.bco.dal.remote.layer.unit.ColorableLightRemote;
import org.openbase.bco.dal.remote.layer.unit.MotionDetectorRemote;
import org.openbase.bco.dal.remote.layer.unit.Units;
Expand Down Expand Up @@ -61,18 +62,12 @@
*
* @author <a href="mailto:tmichalski@techfak.uni-bielefeld.de">Timo Michalski</a>
*/
@Disabled
public class AbsenceEnergySavingAgentTest extends AbstractBCOAgentManagerTest {

private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(AbsenceEnergySavingAgentTest.class);

public static final String ABSENCE_ENERGY_SAVING_AGENT_LABEL = "Absence_Energy_Saving_Agent_Unit_Test";

private static final PowerState ON = PowerState.newBuilder().setValue(PowerState.State.ON).build();

private static final MotionState MOTION = MotionState.newBuilder().setValue(MotionState.State.MOTION).build();
private static final MotionState NO_MOTION = MotionState.newBuilder().setValue(MotionState.State.NO_MOTION).build();

/**
* Test of activate method, of class PowerStateSynchroniserAgent.
*
Expand Down Expand Up @@ -102,7 +97,7 @@ public void testAbsenceEnergySavingAgent() throws Exception {
motionDetectorRemote.waitForData();

// create initial values with motion and lights on
motionDetectorController.applyServiceState(MOTION, ServiceType.MOTION_STATE_SERVICE);
motionDetectorController.applyServiceState(Motion.MOTION, ServiceType.MOTION_STATE_SERVICE);
motionDetectorStateAwaiter.waitForState((MotionDetectorData data) -> data.getMotionState().getValue() == MotionState.State.MOTION);
locationStateAwaiter.waitForState((LocationData data) -> data.getPresenceState().getValue() == PresenceState.State.PRESENT);

Expand All @@ -112,7 +107,7 @@ public void testAbsenceEnergySavingAgent() throws Exception {
.setExecutionTimePeriod(1000000)
.build();

waitForExecution(locationRemote.setPowerState(ON, lowPriorityActionParameter));
waitForExecution(locationRemote.setPowerState(States.Power.ON, lowPriorityActionParameter));
locationStateAwaiter.waitForState((LocationData data) -> data.getPowerState().getValue() == PowerState.State.ON);
colorableLightStateAwaiter.waitForState((ColorableLightData data) -> data.getPowerState().getValue() == PowerState.State.ON);

Expand All @@ -122,7 +117,7 @@ public void testAbsenceEnergySavingAgent() throws Exception {
assertEquals(PowerState.State.ON, colorableLightRemote.getPowerState().getValue(), "PowerState of ColorableLight[" + colorableLightRemote.getLabel() + "] has not switched to OFF");

// test if on no motion the lights are turned off
motionDetectorController.applyServiceState(NO_MOTION, ServiceType.MOTION_STATE_SERVICE);
motionDetectorController.applyServiceState(Motion.NO_MOTION, ServiceType.MOTION_STATE_SERVICE);
motionDetectorStateAwaiter.waitForState((MotionDetectorData data) -> data.getMotionState().getValue() == MotionState.State.NO_MOTION);
locationStateAwaiter.waitForState((LocationData data) -> data.getPresenceState().getValue() == PresenceState.State.ABSENT);
colorableLightStateAwaiter.waitForState((ColorableLightData data) -> data.getPowerState().getValue() == PowerState.State.OFF);
Expand All @@ -134,7 +129,7 @@ public void testAbsenceEnergySavingAgent() throws Exception {
//assertEquals("PowerState of Location[" + locationRemote.getLabel() + "] has not switched to OFF", PowerState.State.OFF, locationRemote.getPowerState().getValue());

// test if the lights stay off on new motion
motionDetectorController.applyServiceState(MOTION, ServiceType.MOTION_STATE_SERVICE);
motionDetectorController.applyServiceState(Motion.MOTION, ServiceType.MOTION_STATE_SERVICE);
motionDetectorStateAwaiter.waitForState((MotionDetectorData data) -> data.getMotionState().getValue() == MotionState.State.MOTION);
locationStateAwaiter.waitForState((LocationData data) -> data.getPresenceState().getValue() == PresenceState.State.PRESENT);
colorableLightStateAwaiter.waitForState((ColorableLightData data) -> data.getPowerState().getValue() == PowerState.State.OFF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.openbase.type.domotic.unit.location.LocationDataType.LocationData;


@Disabled
public class FireAlarmAgentTest extends AbstractBCOAgentManagerTest {

private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(FireAlarmAgentTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
* * @author <a href="mailto:tmichalski@techfak.uni-bielefeld.de">Timo
* Michalski</a>
*/
@Disabled
public class HeaterEnergySavingAgentTest extends AbstractBCOAgentManagerTest {

public static final String HEATER_ENERGY_SAVING_AGENT_LABEL = "Heater_Energy_Saving_Agent_Unit_Test";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

Expand Down Expand Up @@ -61,16 +60,12 @@
* * @author <a href="mailto:tmichalski@techfak.uni-bielefeld.de">Timo
* Michalski</a>
*/
@Disabled
public class IlluminationLightSavingAgentTest extends AbstractBCOAgentManagerTest {

private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(IlluminationLightSavingAgentTest.class);

public static final String ILLUMINATION_LIGHT_SAVING_AGENT_LABEL = "Illumination_Light_Saving_Agent_Unit_Test";

public IlluminationLightSavingAgentTest() throws Exception {
}

/**
* Test of activate method, of class PowerStateSynchroniserAgent.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,12 @@
/**
* * @author <a href="mailto:pleminoq@openbase.org">Tamino Huxohl</a>
*/
@Disabled
public class PowerStateSynchroniserAgentTest extends AbstractBCOAgentManagerTest {

private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(PowerStateSynchroniserAgentTest.class);

private static final String AGENT_ALIAS = "Power_State_Sync_Agent_Unit_Test";
private static final long STATE_AWAIT_TIMEOUT = 1000;

public PowerStateSynchroniserAgentTest() {
}

private String sourceId;
private String targetId1;
private String targetId2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,9 @@
import org.openbase.type.domotic.unit.dal.MotionDetectorDataType.MotionDetectorData;
import org.openbase.type.domotic.unit.location.LocationDataType.LocationData;



/**
* * @author <a href="mailto:tmichalski@techfak.uni-bielefeld.de">Timo Michalski</a>
*/
@Disabled
public class PresenceLightAgentTest extends AbstractBCOAgentManagerTest {

private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(PresenceLightAgentTest.class);
Expand All @@ -88,14 +85,6 @@ public class PresenceLightAgentTest extends AbstractBCOAgentManagerTest {
private UnitStateAwaiter<LightSensorData, LightSensorRemote> lightSensorStateAwaiter;
private UnitStateAwaiter<LocationData, LocationRemote> locationStateAwaiter;

public PresenceLightAgentTest() throws CouldNotPerformException, InterruptedException {
locationRemote = Units.getUnitByAlias(MockRegistry.ALIAS_LOCATION_STAIRWAY_TO_HEAVEN, true, Units.LOCATION);
colorableLightRemote = locationRemote.getUnits(UnitType.COLORABLE_LIGHT, true, Units.COLORABLE_LIGHT).get(0);
motionDetectorRemote = locationRemote.getUnits(UnitType.MOTION_DETECTOR, true, Units.MOTION_DETECTOR).get(0);
lightSensorRemote = locationRemote.getUnits(UnitType.LIGHT_SENSOR, true, Units.LIGHT_SENSOR).get(0);

}

//@BeforeAll //uncomment to enable debug mode
public static void showActionInspector() throws Throwable {

Expand All @@ -110,6 +99,11 @@ public static void showActionInspector() throws Throwable {
@Override
public void prepareEnvironment() throws CouldNotPerformException, InterruptedException {

locationRemote = Units.getUnitByAlias(MockRegistry.ALIAS_LOCATION_STAIRWAY_TO_HEAVEN, true, Units.LOCATION);
colorableLightRemote = locationRemote.getUnits(UnitType.COLORABLE_LIGHT, true, Units.COLORABLE_LIGHT).get(0);
motionDetectorRemote = locationRemote.getUnits(UnitType.MOTION_DETECTOR, true, Units.MOTION_DETECTOR).get(0);
lightSensorRemote = locationRemote.getUnits(UnitType.LIGHT_SENSOR, true, Units.LIGHT_SENSOR).get(0);

// set location emphasis to economy to make the agent more responsive on presence changes
waitForExecution(locationRemote.setEconomyEmphasis(1));

Expand Down Expand Up @@ -147,7 +141,6 @@ public void prepareEnvironment() throws CouldNotPerformException, InterruptedExc
*/
@Test
@Timeout(30)
@Disabled
public void testPresenceLightAgent() throws Exception {

// test if on motion the lights are turned on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ open class MqttIntegrationTest {
synchronized(configLock) {
mosquittoConfig = Files.createTempFile("mosquitto_", ".conf")
Files.write(
mosquittoConfig, Arrays.asList(
mosquittoConfig, listOf(
"allow_anonymous true",
"listener " + port
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public List<LocationRemote> getChildLocationList(final boolean waitForData) thro
try {
childList.add(Units.getUnit(Registries.getUnitRegistry().getUnitConfigById(childId), waitForData, LOCATION));
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new CouldNotPerformException("Could not get all child locations!", ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ private RequiredActionObserver(final List<ActionReference> requiredActionImpact,
for (Entry<UnitRemote<?>, RequiredServiceDescription> unitActionReferenceEntry : unitAndRequiredServiceStateMap.entrySet()) {
try {
unitActionReferenceEntry.getKey().addServiceStateObserver(ServiceTempus.CURRENT, unitActionReferenceEntry.getValue().getServiceType(), this);
unitActionReferenceEntry.getKey().addServiceStateObserver(ServiceTempus.REQUESTED, unitActionReferenceEntry.getValue().getServiceType(), this);
} catch (CouldNotPerformException ex) {
ExceptionPrinter.printHistory("Could not observe service state of action impact!", ex, LOGGER, LogLevel.WARN);
}
Expand All @@ -416,7 +417,7 @@ private RequiredActionObserver(final List<ActionReference> requiredActionImpact,
} catch (CouldNotPerformException e) {
// ignore if this action can not be checks since the validation will at least check its state.
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}

Expand All @@ -428,7 +429,7 @@ private void verifyAllStates() {
try {
for (Entry<UnitRemote<? extends Message>, RequiredServiceDescription> unitActionReferenceEntry : unitAndRequiredServiceStateMap.entrySet()) {
try {
// skip unit in case its offline, since than the verification is automatically
// skip unit in case its offline, since then the verification is automatically
// performed when its back online but those unnecessary timeouts are avoided.
if (unitActionReferenceEntry.getKey().isConnected()) {
continue;
Expand Down Expand Up @@ -479,6 +480,7 @@ public void shutdown() {
// deregister observation
for (Entry<UnitRemote<?>, RequiredServiceDescription> unitActionReferenceEntry : unitAndRequiredServiceStateMap.entrySet()) {
unitActionReferenceEntry.getKey().removeServiceStateObserver(ServiceTempus.CURRENT, unitActionReferenceEntry.getValue().getServiceType(), this);
unitActionReferenceEntry.getKey().removeServiceStateObserver(ServiceTempus.REQUESTED, unitActionReferenceEntry.getValue().getServiceType(), this);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,8 @@ public void waitForRegistration(final long timeout, final TimeUnit timeUnit) thr
} else {
futureObservationTask.get(timeSplit.getTime(), timeSplit.getTimeUnit());
}
} catch (CancellationException ex) {
throw new CouldNotPerformException(ex.getCause());
} catch (java.util.concurrent.TimeoutException ex) {
throw new org.openbase.jul.exception.TimeoutException();
}
Expand Down Expand Up @@ -1232,4 +1234,3 @@ public String toString() {
return Action.toString(this);
}
}

Loading