Skip to content

Commit

Permalink
Merge pull request #38 from RADAR-CNS/release_0.1
Browse files Browse the repository at this point in the history
Release 0.1
  • Loading branch information
yatharthranjan committed Nov 29, 2017
2 parents 8b2a9a7 + a83d444 commit 7fff01f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 34 deletions.
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

23 changes: 1 addition & 22 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {
//---------------------------------------------------------------------------//

group = 'org.radarcns'
version = '0.1-alpha.3-SNAPSHOT'
version = '0.1'
ext.description = 'Kafka backend for processing device data.'

mainClassName = 'org.radarcns.RadarBackend'
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/radarcns/monitor/AbstractKafkaMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ public AbstractKafkaMonitor(RadarPropertyHandler radar, Collection<String> topic

properties = new Properties();
String deserializer = KafkaAvroDeserializer.class.getName();
String monitorClientId = getClass().getName() + "-" + clientId;
properties.setProperty(KEY_DESERIALIZER_CLASS_CONFIG, deserializer);
properties.setProperty(VALUE_DESERIALIZER_CLASS_CONFIG, deserializer);
properties.setProperty(GROUP_ID_CONFIG, groupId);
properties.setProperty(CLIENT_ID_CONFIG, clientId);
properties.setProperty(CLIENT_ID_CONFIG, monitorClientId);
properties.setProperty(ENABLE_AUTO_COMMIT_CONFIG, "true");
properties.setProperty(AUTO_COMMIT_INTERVAL_MS_CONFIG, "1001");
properties.setProperty(SESSION_TIMEOUT_MS_CONFIG, "15101");
Expand All @@ -105,7 +106,7 @@ public AbstractKafkaMonitor(RadarPropertyHandler radar, Collection<String> topic
this.topics = topics;
this.pollTimeout = new AtomicLong(Long.MAX_VALUE);
this.done = false;
this.clientId = clientId;
this.clientId = monitorClientId;
this.groupId = groupId;

PersistentStateStore localStateStore;
Expand All @@ -121,7 +122,7 @@ public AbstractKafkaMonitor(RadarPropertyHandler radar, Collection<String> topic
S localState = stateDefault;
if (stateStore != null && stateDefault != null) {
try {
localState = stateStore.retrieveState(groupId, clientId, stateDefault);
localState = stateStore.retrieveState(groupId, monitorClientId, stateDefault);
logger.info("Using existing {} from persistence store.",
stateDefault.getClass().getName());
} catch (IOException ex) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/radarcns/monitor/BatteryLevelMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ protected void evaluateRecord(ConsumerRecord<GenericRecord, GenericRecord> recor
key.getSourceId(), key.getUserId(), record.value());
}
} else if (previousLevel <= Status.LOW.getLevel()) {
updateStatus(key, Status.NORMAL);
// Remove the email alert for battery monitor for normal level because
// it is not crucial and to prevent spamming a user's email account.
// Uncomment the line below if needed.
// updateStatus(key, Status.NORMAL);
logger.info("Battery of sensor {} of user {} is has returned to normal: {}",
key.getSourceId(), key.getUserId(), record.value());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ public void evaluateRecord() throws Exception {
sendMessage(monitor, 1.0f, false);
sendMessage(monitor, 0.1f, true);
sendMessage(monitor, 0.1f, false);
sendMessage(monitor, 0.3f, true);
sendMessage(monitor, 0.3f, false);
sendMessage(monitor, 0.4f, false);
sendMessage(monitor, 0.01f, true);
sendMessage(monitor, 0.01f, false);
sendMessage(monitor, 0.1f, false);
sendMessage(monitor, 0.1f, false);
sendMessage(monitor, 0.01f, true);
sendMessage(monitor, 1f, true);
sendMessage(monitor, 1f, false);
}

private void sendMessage(BatteryLevelMonitor monitor, float batteryLevel, boolean sentMessage)
Expand Down Expand Up @@ -130,4 +130,4 @@ public void retrieveState() throws Exception {
Map<String, Float> values = state2.getLevels();
assertThat(values, hasEntry(measurementKeyToString(key1), 0.1f));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public void createBatteryMonitor() throws Exception {
assertEquals(BatteryLevelMonitor.class, monitor.getClass());
BatteryLevelMonitor batteryMonitor = (BatteryLevelMonitor) monitor;
batteryMonitor.evaluateRecords(new ConsumerRecords<>(Collections.emptyMap()));
assertTrue(new File(config.getPersistencePath(), "battery_monitors_1.yml").isFile());
assertTrue(new File(config.getPersistencePath(), "battery_monitors_" +
BatteryLevelMonitor.class.getName() + "-1.yml").isFile());
}

@Test(expected = IOException.class)
Expand All @@ -79,7 +80,8 @@ public void createDisconnectMonitor() throws Exception {
assertEquals(DisconnectMonitor.class, monitor.getClass());
DisconnectMonitor disconnectMonitor = (DisconnectMonitor) monitor;
disconnectMonitor.evaluateRecords(new ConsumerRecords<>(Collections.emptyMap()));
assertTrue(new File(config.getPersistencePath(), "disconnect_monitor_1.yml").isFile());
assertTrue(new File(config.getPersistencePath(), "disconnect_monitor_" +
DisconnectMonitor.class.getName() + "-1.yml").isFile());
}

@Test
Expand Down Expand Up @@ -148,4 +150,4 @@ public static ConfigRadar getBatteryMonitorConfig(int port, TemporaryFolder fold
config.setBatteryMonitor(getBatteryMonitorConfig(port));
return config;
}
}
}

0 comments on commit 7fff01f

Please sign in to comment.