Skip to content
Snippets Groups Projects
Commit 438f3df1 authored by Manuel Krombholz's avatar Manuel Krombholz
Browse files

ExternalHost computed in InfluxRoot and MQTTRoot

parent 1f928f99
No related branches found
No related tags found
1 merge request!19dev to master
Pipeline #9939 passed
Showing
with 34 additions and 56 deletions
aspect ExternalHost {
syn boolean ExternalHost.exists() = getHostName()!=null && !getHostName().isEmpty();
public ExternalHost ExternalHost.copyFrom(ExternalHost host) {
return setHostName(host.getHostName()).setPort(host.getPort()).setUserName(host.getUserName()).setPassword(host.getPassword());
}
}
\ No newline at end of file
aspect InfluxRoot {
syn ExternalHost InfluxRoot.getHost() = new ExternalHost();
}
\ No newline at end of file
...@@ -8,10 +8,7 @@ aspect ItemHistory { ...@@ -8,10 +8,7 @@ aspect ItemHistory {
public static final InfluxRoot InfluxRoot.createDefault() { public static final InfluxRoot InfluxRoot.createDefault() {
InfluxRoot result = new InfluxRoot(); InfluxRoot result = new InfluxRoot();
ExternalHost eh = new ExternalHost(); result.getHost().setUserName(DEFAULT_USER).setPassword(DEFAULT_PASSWORD);
eh.setUserName(DEFAULT_USER);
eh.setPassword(DEFAULT_PASSWORD);
result.setHost(eh);
result.setDbName(DEFAULT_DB_NAME); result.setDbName(DEFAULT_DB_NAME);
...@@ -22,7 +19,7 @@ aspect ItemHistory { ...@@ -22,7 +19,7 @@ aspect ItemHistory {
cache InfluxRoot.influxAdapter(); cache InfluxRoot.influxAdapter();
syn InfluxAdapter InfluxRoot.influxAdapter() { syn InfluxAdapter InfluxRoot.influxAdapter() {
InfluxAdapter result; InfluxAdapter result;
if (hasHost()) { if (getHost().exists()) {
result = new InfluxAdapterImpl(); result = new InfluxAdapterImpl();
} else { } else {
result = new InfluxAdapterStub(); result = new InfluxAdapterStub();
...@@ -106,6 +103,8 @@ aspect ItemHistory { ...@@ -106,6 +103,8 @@ aspect ItemHistory {
getRoot().getInfluxRoot().influxAdapter().write(pointFromState()); getRoot().getInfluxRoot().influxAdapter().write(pointFromState());
} }
//--- pointFromState --- //--- pointFromState ---
protected abstract AbstractItemPoint Item.pointFromState(); protected abstract AbstractItemPoint Item.pointFromState();
protected AbstractItemPoint ItemWithBooleanState.pointFromState() { protected AbstractItemPoint ItemWithBooleanState.pointFromState() {
......
...@@ -195,7 +195,7 @@ aspect Printing { ...@@ -195,7 +195,7 @@ aspect Printing {
return new MemberPrinter("Mqtt") return new MemberPrinter("Mqtt")
.addNonDefault("incoming", getIncomingPrefix()) .addNonDefault("incoming", getIncomingPrefix())
.addNonDefault("outgoing", getOutgoingPrefix()) .addNonDefault("outgoing", getOutgoingPrefix())
.addOptional("host", hasHost() && !host.getHostName().isEmpty(), () -> host.prettyPrint()) .addOptional("host", host.exists(), () -> host.prettyPrint())
.build(); .build();
} }
...@@ -206,7 +206,7 @@ aspect Printing { ...@@ -206,7 +206,7 @@ aspect Printing {
.addNonDefault("user", host.getUserName(), DEFAULT_USER) .addNonDefault("user", host.getUserName(), DEFAULT_USER)
.addNonDefault("password", host.getPassword(), DEFAULT_PASSWORD) .addNonDefault("password", host.getPassword(), DEFAULT_PASSWORD)
.addNonDefault("dbName", getDbName(), DEFAULT_DB_NAME) .addNonDefault("dbName", getDbName(), DEFAULT_DB_NAME)
.addOptional("host", hasHost() && !host.getHostName().isEmpty(), () -> host.prettyPrint()) .addOptional("host", host.exists(), () -> host.prettyPrint())
.build(); .build();
} }
......
...@@ -4,40 +4,6 @@ aspect Util { ...@@ -4,40 +4,6 @@ aspect Util {
// public static ExternalHost ExternalHost.createByName(String hostName) { // public static ExternalHost ExternalHost.createByName(String hostName) {
// return new ExternalHost(hostName, 1883); // return new ExternalHost(hostName, 1883);
// } // }
public void MqttRoot.updateHost(String hostName, int port, String username, String password) {
if (getHost()==null) {
setHost(new ExternalHost());
}
if (hostName!=null) {
getHost().setHostName(hostName);
}
if (port>0) {
getHost().setPort(port);
}
if (username!=null) {
getHost().setUserName(username);
}
if (password!=null) {
getHost().setPassword(password);
}
flushCache();
}
public void InfluxRoot.updateHost(String hostName, String username, String password) {
if (getHost()==null) {
setHost(new ExternalHost());
}
if (hostName!=null) {
getHost().setHostName(hostName);
}
if (username!=null) {
getHost().setUserName(username);
}
if (password!=null) {
getHost().setPassword(password);
}
}
public static ExternalHost ExternalHost.of(String hostName, int defaultPort) { public static ExternalHost ExternalHost.of(String hostName, int defaultPort) {
return ExternalHost.of(hostName,defaultPort,null,null); return ExternalHost.of(hostName,defaultPort,null,null);
......
...@@ -331,9 +331,9 @@ MqttRoot mqtt_root = ...@@ -331,9 +331,9 @@ MqttRoot mqtt_root =
MqttRoot mqtt_root_body = MqttRoot mqtt_root_body =
INCOMING EQUALS TEXT.n mqtt_root_body.mrb {: mrb.setIncomingPrefix(ensureTrailingSlash(n)); return mrb; :} INCOMING EQUALS TEXT.n mqtt_root_body.mrb {: mrb.setIncomingPrefix(ensureTrailingSlash(n)); return mrb; :}
| OUTGOING EQUALS TEXT.n mqtt_root_body.mrb {: mrb.setOutgoingPrefix(ensureTrailingSlash(n)); return mrb; :} | OUTGOING EQUALS TEXT.n mqtt_root_body.mrb {: mrb.setOutgoingPrefix(ensureTrailingSlash(n)); return mrb; :}
| HOST EQUALS TEXT.n mqtt_root_body.mrb {: mrb.updateHost(n,0,null,null); return mrb; :} | HOST EQUALS TEXT.n mqtt_root_body.mrb {: mrb.getHost().setHostName(n); return mrb; :}
| USER EQUALS TEXT.n mqtt_root_body.mrb {: mrb.updateHost(null,0,n,null); return mrb; :} | USER EQUALS TEXT.n mqtt_root_body.mrb {: mrb.getHost().setUserName(n); return mrb; :}
| PASSWORD EQUALS TEXT.n mqtt_root_body.mrb {: mrb.updateHost(null,0,null,n); return mrb; :} | PASSWORD EQUALS TEXT.n mqtt_root_body.mrb {: mrb.getHost().setPassword(n); return mrb; :}
| {: return new MqttRoot(); :} | {: return new MqttRoot(); :}
; ;
...@@ -345,10 +345,10 @@ InfluxRoot influx_root = ...@@ -345,10 +345,10 @@ InfluxRoot influx_root =
// Influx: user="" password="" dbName="" host="" ; // Influx: user="" password="" dbName="" host="" ;
InfluxRoot influx_root_body = InfluxRoot influx_root_body =
USER EQUALS TEXT.n influx_root_body.irb {: irb.updateHost(null,n,null); return irb; :} USER EQUALS TEXT.n influx_root_body.irb {: irb.getHost().setUserName(n); return irb; :}
| PASSWORD EQUALS TEXT.n influx_root_body.irb {: irb.updateHost(null,null,n); return irb; :} | PASSWORD EQUALS TEXT.n influx_root_body.irb {: irb.getHost().setPassword(n); return irb; :}
| DB_NAME EQUALS TEXT.n influx_root_body.irb {: irb.setDbName(n); return irb; :} | DB_NAME EQUALS TEXT.n influx_root_body.irb {: irb.setDbName(n); return irb; :}
| HOST EQUALS TEXT.n influx_root_body.irb {: irb.updateHost(n,null,null); return irb; :} | HOST EQUALS TEXT.n influx_root_body.irb {: irb.getHost().setHostName(n);; return irb; :}
| {: return InfluxRoot.createDefault(); :} | {: return InfluxRoot.createDefault(); :}
; ;
......
...@@ -9,4 +9,4 @@ rel Root.CurrentUser? -> User ; ...@@ -9,4 +9,4 @@ rel Root.CurrentUser? -> User ;
ExternalHost ::= <HostName:String> <Port:int> <UserName:String> <Password:String>; ExternalHost ::= <HostName:String> <Port:int> <UserName:String> <Password:String>;
// ---------------- InfluxDB ------------------------------ // ---------------- InfluxDB ------------------------------
InfluxRoot ::= <DbName:String> [Host:ExternalHost] ; InfluxRoot ::= <DbName:String> /Host:ExternalHost/ ;
...@@ -33,6 +33,7 @@ aspect MQTT { ...@@ -33,6 +33,7 @@ aspect MQTT {
} }
} }
//--- getIncomingTopic --- //--- getIncomingTopic ---
syn String MqttTopic.getIncomingTopic() = getMqttRoot().getIncomingPrefix() + getTopicString(); syn String MqttTopic.getIncomingTopic() = getMqttRoot().getIncomingPrefix() + getTopicString();
...@@ -43,7 +44,7 @@ aspect MQTT { ...@@ -43,7 +44,7 @@ aspect MQTT {
cache MqttRoot.getMqttSender(); cache MqttRoot.getMqttSender();
syn MQTTSender MqttRoot.getMqttSender() { syn MQTTSender MqttRoot.getMqttSender() {
MQTTSender result; MQTTSender result;
if (hasHost()) { if (getHost().exists()) {
result = new MQTTSenderImpl(); result = new MQTTSenderImpl();
} else { } else {
result = new MQTTSenderStub(); result = new MQTTSenderStub();
...@@ -80,6 +81,8 @@ aspect MQTT { ...@@ -80,6 +81,8 @@ aspect MQTT {
item.setTopic(getRoot().getMqttRoot().getOrCreateMqttTopic(item.getTopic().getTopicString())); item.setTopic(getRoot().getMqttRoot().getOrCreateMqttTopic(item.getTopic().getTopicString()));
} }
public MqttTopic MqttRoot.getOrCreateMqttTopic(String topicString) { public MqttTopic MqttRoot.getOrCreateMqttTopic(String topicString) {
return resolveTopicSuffix(topicString).orElseGet(() -> { return resolveTopicSuffix(topicString).orElseGet(() -> {
MqttTopic result = new MqttTopic(); MqttTopic result = new MqttTopic();
...@@ -89,4 +92,6 @@ aspect MQTT { ...@@ -89,4 +92,6 @@ aspect MQTT {
}); });
} }
syn ExternalHost MqttRoot.getHost() = new ExternalHost();
} }
// ---------------- MQTT ------------------------------ // ---------------- MQTT ------------------------------
MqttRoot ::= Topic:MqttTopic* <IncomingPrefix:String> <OutgoingPrefix:String> [Host:ExternalHost] ; MqttRoot ::= Topic:MqttTopic* <IncomingPrefix:String> <OutgoingPrefix:String> /Host:ExternalHost/ ;
MqttTopic ::= <TopicString:String> ; MqttTopic ::= <TopicString:String> ;
rel Item.Topic? <-> MqttTopic.Item* ; rel Item.Topic? <-> MqttTopic.Item* ;
...@@ -162,7 +162,6 @@ public class InfluxTest { ...@@ -162,7 +162,6 @@ public class InfluxTest {
InfluxRoot influxRoot; InfluxRoot influxRoot;
if (useStub) { if (useStub) {
influxRoot = InfluxRoot.createDefault(); influxRoot = InfluxRoot.createDefault();
influxRoot.setHostOpt(new Opt<>());
// now a SenderStub is being used // now a SenderStub is being used
((InfluxAdapterStub) influxRoot.influxAdapter()).setCallback( ((InfluxAdapterStub) influxRoot.influxAdapter()).setCallback(
point -> points.add((DoubleStatePoint) point)); point -> points.add((DoubleStatePoint) point));
...@@ -170,7 +169,7 @@ public class InfluxTest { ...@@ -170,7 +169,7 @@ public class InfluxTest {
influxRoot = InfluxRoot.createDefault(); influxRoot = InfluxRoot.createDefault();
// use container running influx // use container running influx
influxRoot.setDbName(InfluxTest.class.getSimpleName()); influxRoot.setDbName(InfluxTest.class.getSimpleName());
influxRoot.setHost(new ExternalHost().setHostName(getInfluxHost())); influxRoot.getHost().setHostName(getInfluxHost());
} }
mai.model.getRoot().setInfluxRoot(influxRoot); mai.model.getRoot().setInfluxRoot(influxRoot);
assumeTrue(influxRoot.influxAdapter().isConnected()); assumeTrue(influxRoot.influxAdapter().isConnected());
......
...@@ -175,11 +175,11 @@ public class MqttTests { ...@@ -175,11 +175,11 @@ public class MqttTests {
mqttRoot.setIncomingPrefix("inc"); mqttRoot.setIncomingPrefix("inc");
mqttRoot.setOutgoingPrefix(outgoingPrefix); mqttRoot.setOutgoingPrefix(outgoingPrefix);
if (useStub) { if (useStub) {
mqttRoot.setHostOpt(new Opt<>());
// now a SenderStub is being used // now a SenderStub is being used
((MQTTSenderStub) mqttRoot.getMqttSender()).setCallback(((topic, message, qos) -> messages.add(message))); ((MQTTSenderStub) mqttRoot.getMqttSender()).setCallback(((topic, message, qos) -> messages.add(message)));
} else { } else {
mqttRoot.setHost(ExternalHost.of(getMqttHost(), 1883)); mqttRoot.getHost().setHostName(getMqttHost()).setPort(1883);
} }
MqttTopic a = createAndAddMqttTopic(mqttRoot, firstPart); MqttTopic a = createAndAddMqttTopic(mqttRoot, firstPart);
MqttTopic ab = createAndAddMqttTopic(mqttRoot, firstPart + "/" + secondPart); MqttTopic ab = createAndAddMqttTopic(mqttRoot, firstPart + "/" + secondPart);
......
...@@ -47,7 +47,7 @@ public class IntegrationMain { ...@@ -47,7 +47,7 @@ public class IntegrationMain {
InputStream inputStream = IntegrationMain.class.getResourceAsStream(filename); InputStream inputStream = IntegrationMain.class.getResourceAsStream(filename);
String host = "localhost"; String host = "localhost";
MqttRoot mqttRoot = new MqttRoot(); MqttRoot mqttRoot = new MqttRoot();
mqttRoot.setHost(new ExternalHost().setHostName(host)); mqttRoot.getHost().setHostName(host);
// columns: time,topic,qos,message // columns: time,topic,qos,message
try (InputStreamReader inputStreamReader = new InputStreamReader(inputStream); try (InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
CSVReader reader = new CSVReaderBuilder(inputStreamReader) CSVReader reader = new CSVReaderBuilder(inputStreamReader)
...@@ -90,7 +90,7 @@ public class IntegrationMain { ...@@ -90,7 +90,7 @@ public class IntegrationMain {
// Root model = importFromLocalFile(); // Root model = importFromLocalFile();
logger.debug("Got model: {}", model.getSmartHomeEntityModel().description()); logger.debug("Got model: {}", model.getSmartHomeEntityModel().description());
MqttRoot mqttRoot = new MqttRoot(); MqttRoot mqttRoot = new MqttRoot();
mqttRoot.updateHost("localhost",-1,null,null); mqttRoot.getHost().setHostName("localhost");
mqttRoot.setIncomingPrefix("oh2/out/"); mqttRoot.setIncomingPrefix("oh2/out/");
MqttTopic irisStateTopic = new MqttTopic(); MqttTopic irisStateTopic = new MqttTopic();
irisStateTopic.setTopicString("iris1_item/state"); irisStateTopic.setTopicString("iris1_item/state");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment