Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] MongoDB persistence update #859

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.http.provider.config.HttpOperationProviderConfig;
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.http.util.HttpHelper;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.StorageException;
import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure;
import de.fraunhofer.iosb.ilt.faaast.service.util.ReferenceHelper;
import java.io.IOException;
Expand Down Expand Up @@ -67,7 +68,7 @@ protected OperationVariable[] getOutputParameters() {
try {
return serviceContext.getOperationOutputVariables(reference);
}
catch (ResourceNotFoundException e) {
catch (ResourceNotFoundException | StorageException e) {
throw new IllegalStateException(
String.format(
"operation not defined in AAS model (reference: %s)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.http.provider.config.HttpSubscriptionProviderConfig;
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.http.util.HttpHelper;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.StorageException;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue;
import de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo;
import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure;
Expand Down Expand Up @@ -153,9 +154,9 @@ protected TypeInfo getTypeInfo() {
try {
return serviceContext.getTypeInfo(reference);
}
catch (ResourceNotFoundException e) {
catch (ResourceNotFoundException | StorageException e) {
throw new IllegalStateException(String.format(
"HTTP subscription provider could not get typ info as resource does not exist - this should not be able to occur (reference: %s)",
"HTTP subscription provider could not get type info as resource does not exist or storage failed - this should not be able to occur (reference: %s)",
ReferenceHelper.toString(reference)),
e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.http.provider.config.HttpValueProviderConfig;
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.http.util.HttpHelper;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.StorageException;
import de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo;
import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure;
import de.fraunhofer.iosb.ilt.faaast.service.util.ReferenceHelper;
Expand Down Expand Up @@ -148,9 +149,9 @@ protected TypeInfo getTypeInfo() {
try {
return serviceContext.getTypeInfo(reference);
}
catch (ResourceNotFoundException e) {
catch (ResourceNotFoundException | StorageException e) {
throw new IllegalStateException(String.format(
"HTTP value provider could not get typ info as resource does not exist - this should not be able to occur (reference: %s)",
"HTTP value provider could not get type info as resource does not exist or storage failed - this should not be able to occur (reference: %s)",
ReferenceHelper.toString(reference)),
e);
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.common.provider.MultiFormatSubscriptionProvider;
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.mqtt.provider.config.MqttSubscriptionProviderConfig;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.StorageException;
import de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo;
import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure;
import de.fraunhofer.iosb.ilt.faaast.service.util.ReferenceHelper;
Expand Down Expand Up @@ -51,9 +52,9 @@ protected TypeInfo getTypeInfo() {
try {
return serviceContext.getTypeInfo(reference);
}
catch (ResourceNotFoundException e) {
catch (ResourceNotFoundException | StorageException e) {
throw new IllegalStateException(String.format(
"MQTT subscription provider could not get typ info as resource does not exist - this should not be able to occur (reference: %s)",
"MQTT subscription provider could not get type info as resource does not exist or storage failed - this should not be able to occur (reference: %s)",
ReferenceHelper.toString(reference)),
e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.common.provider.MultiFormatValueProvider;
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.mqtt.provider.config.MqttValueProviderConfig;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.StorageException;
import de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo;
import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure;
import de.fraunhofer.iosb.ilt.faaast.service.util.ReferenceHelper;
Expand Down Expand Up @@ -71,9 +72,9 @@ protected TypeInfo getTypeInfo() {
try {
return serviceContext.getTypeInfo(reference);
}
catch (ResourceNotFoundException e) {
catch (ResourceNotFoundException | StorageException e) {
throw new IllegalStateException(String.format(
"MQTT value provider could not get typ info as resource does not exist - this should not be able to occur (reference: %s)",
"MQTT value provider could not get type info as resource does not exist or storage failed - this should not be able to occur (reference: %s)",
ReferenceHelper.toString(reference)),
e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationException;
import de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationInitializationException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.StorageException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueFormatException;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.Datatype;
Expand Down Expand Up @@ -125,15 +126,16 @@ public void testSubscriptionProviderConnectionLost()

@Test
public void testSubscriptionProviderJsonProperty()
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, ResourceNotFoundException {
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, ResourceNotFoundException, StorageException {
assertSubscriptionProvider(FORMAT_JSON, "7", PropertyValue.of(Datatype.INT, "7"));
assertSubscriptionProvider(FORMAT_JSON, "\"hello world\"", PropertyValue.of(Datatype.STRING, "hello world"));
}


@Test
public void testReconnect()
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, IOException, ResourceNotFoundException {
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, IOException, ResourceNotFoundException,
StorageException {
int assetMqttPort = PortHelper.findFreePort();
Server localMqttServer = startMqttServer(assetMqttPort);
String localMqttServerUri = "tcp://" + LOCALHOST + ":" + assetMqttPort;
Expand Down Expand Up @@ -180,7 +182,8 @@ public void testReconnect()

@Test
public void testSubscriptionProviderJsonPropertyInvalidMessage()
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, IOException, ResourceNotFoundException {
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, IOException, ResourceNotFoundException,
StorageException {
TestLogger logger = TestLoggerFactory.getTestLogger(MultiFormatSubscriptionProvider.class);
String message = "7";
PropertyValue expected = PropertyValue.of(Datatype.INT, message);
Expand All @@ -202,7 +205,8 @@ public void testSubscriptionProviderJsonPropertyInvalidMessage()

@Test
public void testSubscriptionProviderJsonPropertyWithInvalidQuery()
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, IOException, ResourceNotFoundException {
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, IOException, ResourceNotFoundException,
StorageException {
TestLogger logger = TestLoggerFactory.getTestLogger(MultiFormatSubscriptionProvider.class);
assertSubscriptionProvider(
MqttSubscriptionProviderConfig.builder()
Expand All @@ -216,7 +220,7 @@ public void testSubscriptionProviderJsonPropertyWithInvalidQuery()

@Test
public void testSubscriptionProviderJsonPropertyWithQuery()
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, ResourceNotFoundException {
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, ResourceNotFoundException, StorageException {
assertSubscriptionProvider(FORMAT_JSON, "{\"foo\": 123, \"bar\": 7}", "$.bar", PropertyValue.of(Datatype.INT, "7"));
assertSubscriptionProvider(FORMAT_JSON, "{\"foo\": \"hello\", \"bar\": \"world\"}", "$.bar", PropertyValue.of(Datatype.STRING, "world"));
}
Expand All @@ -225,7 +229,7 @@ public void testSubscriptionProviderJsonPropertyWithQuery()
@Test
public void testValueProviderProperty()
throws AssetConnectionException, InterruptedException, ValueFormatException, MqttException, JSONException, ConfigurationInitializationException,
ResourceNotFoundException {
ResourceNotFoundException, StorageException {
String expected = "\"hello world\"";
String actual = invokeValueProvider(FORMAT_JSON, PropertyValue.of(Datatype.STRING, "hello world"), null);
JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
Expand All @@ -235,7 +239,7 @@ public void testValueProviderProperty()
@Test
public void testValueProviderPropertyWithTemplate()
throws AssetConnectionException, InterruptedException, ValueFormatException, MqttException, JSONException, ConfigurationInitializationException,
ResourceNotFoundException {
ResourceNotFoundException, StorageException {
String expected = "{\"foo\": \"hello world\"}";
String template = "{\"foo\": ${value}}";
String actual = invokeValueProvider(FORMAT_JSON, PropertyValue.of(Datatype.STRING, "hello world"), template);
Expand Down Expand Up @@ -275,7 +279,7 @@ private static IConfig getMqttServerConfig(int port) {


private String invokeValueProvider(String format, DataElementValue newValue, String template)
throws AssetConnectionException, InterruptedException, MqttException, ConfigurationInitializationException, ResourceNotFoundException {
throws AssetConnectionException, InterruptedException, MqttException, ConfigurationInitializationException, ResourceNotFoundException, StorageException {
MqttAssetConnection assetConnection = newConnection(MqttValueProviderConfig.builder()
.format(format)
.template(template)
Expand Down Expand Up @@ -310,13 +314,13 @@ public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {


private void assertSubscriptionProvider(String format, String message, PropertyValue expected)
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, ResourceNotFoundException {
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, ResourceNotFoundException, StorageException {
assertSubscriptionProvider(format, message, null, expected);
}


private void assertSubscriptionProvider(String format, String message, String query, PropertyValue expected)
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, ResourceNotFoundException {
throws AssetConnectionException, InterruptedException, ValueFormatException, ConfigurationInitializationException, ResourceNotFoundException, StorageException {
assertSubscriptionProvider(
MqttSubscriptionProviderConfig.builder()
.format(format)
Expand All @@ -329,7 +333,7 @@ private void assertSubscriptionProvider(String format, String message, String qu


private void assertSubscriptionProvider(MqttSubscriptionProviderConfig config, Runnable publisher, Callable<Boolean> waitCondition, PropertyValue... expected)
throws AssetConnectionException, ValueFormatException, ConfigurationInitializationException, InterruptedException, ResourceNotFoundException {
throws AssetConnectionException, ValueFormatException, ConfigurationInitializationException, InterruptedException, ResourceNotFoundException, StorageException {
MqttAssetConnection assetConnection = newConnection(
ArrayUtils.isEmpty(expected)
? null
Expand Down Expand Up @@ -388,13 +392,13 @@ private void awaitConnection(AssetConnection connection) {


private MqttAssetConnection newConnection(MqttValueProviderConfig valueProvider)
throws ConfigurationInitializationException, AssetConnectionException, ResourceNotFoundException {
throws ConfigurationInitializationException, AssetConnectionException, ResourceNotFoundException, StorageException {
return newConnection(DEFAULT_REFERENCE, null, valueProvider, null, null);
}


private MqttAssetConnection newConnection(TypeInfo expectedTypeInfo, MqttSubscriptionProviderConfig subscriptionProvider)
throws ConfigurationInitializationException, AssetConnectionException, ResourceNotFoundException {
throws ConfigurationInitializationException, AssetConnectionException, ResourceNotFoundException, StorageException {
return newConnection(DEFAULT_REFERENCE, expectedTypeInfo, null, null, subscriptionProvider);
}

Expand All @@ -404,7 +408,7 @@ private MqttAssetConnection newConnection(Reference reference,
MqttValueProviderConfig valueProvider,
MqttOperationProviderConfig operationProvider,
MqttSubscriptionProviderConfig subscriptionProvider)
throws ConfigurationInitializationException, AssetConnectionException, ResourceNotFoundException {
throws ConfigurationInitializationException, AssetConnectionException, ResourceNotFoundException, StorageException {
return newConnection(mqttServerUri, reference, expectedTypeInfo, valueProvider, operationProvider, subscriptionProvider);
}

Expand All @@ -415,7 +419,7 @@ private MqttAssetConnection newConnection(String url,
MqttValueProviderConfig valueProvider,
MqttOperationProviderConfig operationProvider,
MqttSubscriptionProviderConfig subscriptionProvider)
throws ConfigurationInitializationException, AssetConnectionException, ResourceNotFoundException {
throws ConfigurationInitializationException, AssetConnectionException, ResourceNotFoundException, StorageException {
MqttAssetConnectionConfig config = MqttAssetConnectionConfig.builder()
.serverUri(url)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.util.OpcUaHelper;
import de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.StorageException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.Datatype;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue;
Expand Down Expand Up @@ -181,7 +182,7 @@ private void init() throws AssetConnectionException {
try {
outputVariables = serviceContext.getOperationOutputVariables(reference);
}
catch (ResourceNotFoundException e) {
catch (ResourceNotFoundException | StorageException e) {
throw new AssetConnectionException(
String.format(
"Operation could not be found in AAS model (reference: %s)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.util.OpcUaHelper;
import de.fraunhofer.iosb.ilt.faaast.service.exception.InvalidConfigurationException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.StorageException;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.Datatype;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue;
Expand Down Expand Up @@ -63,7 +64,7 @@ private void init() throws AssetConnectionException {
try {
typeInfo = serviceContext.getTypeInfo(reference);
}
catch (ResourceNotFoundException ex) {
catch (ResourceNotFoundException | StorageException ex) {
throw new AssetConnectionException(
String.format("%s - could not resolve type information (reference: %s)",
baseErrorMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.util.ArrayHelper;
import de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.util.OpcUaHelper;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException;
import de.fraunhofer.iosb.ilt.faaast.service.model.exception.StorageException;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.Datatype;
import de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue;
Expand Down Expand Up @@ -88,7 +89,7 @@ private void init() throws AssetConnectionException {
try {
typeInfo = serviceContext.getTypeInfo(reference);
}
catch (ResourceNotFoundException ex) {
catch (ResourceNotFoundException | StorageException ex) {
throw new AssetConnectionException(
String.format("Could not resolve type information (reference: %s)",
ReferenceHelper.toString(reference)));
Expand Down
Loading