Skip to content

Commit

Permalink
Provider push implementation (#141)
Browse files Browse the repository at this point in the history
* Provider push implementation

* Complete Provider instances can be pushed
* Notifications are now handled via EMF Change Adapters

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* bumped http to 5.0.0 and moved servlet api to parent - helps resolver

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* fixed tests
Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Moved Metdataupdate to Change Adapters

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* satisfy EditorConfig check

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* fixed test and editor config

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* excluded ecore and genmodel from editorconfig check

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Removed debug printout

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Wait for the result before we query
Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Hopefully fixed test

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Added some Tests and fixed bugs

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* removed some loose ends

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* removed some loose ends

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* added missing Capability

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Handling of unset resources

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Split models into provider and internal metadata

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* fixed extended model
Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* reworked model push to work without emfcompare

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Fixed Metadata access

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Adds Metadata annotation support

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* fixed Version bump issue

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* revert license tool version change

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* fixed tests and the definition of eIsSet for Services

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* fixed the isSert determination

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Returns observations only if the resource has been set

* Added comments on row count in ObservationHistoryTest

* Added a location in tests to have circular links for all resources

* downgraded to geckoEMF 4.6.0-SNAPSHOT

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Added back the test for timescale-history-provider

* Updated bndrun files

* Fixed test for Windows

* fixed wrong parent version

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* fixed feature

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* satisfying EditorConfig

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* modified xml config

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* Bumped geckoemf to 4.6.2

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* updated bndruns

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

* reverted editor config

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>

---------

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>
Co-authored-by: Thomas Calmant <thomas.calmant@gmail.com>
  • Loading branch information
juergen-albert and tcalmant committed May 10, 2023
1 parent 58eaad9 commit 5e27485
Show file tree
Hide file tree
Showing 202 changed files with 3,405 additions and 10,907 deletions.
9 changes: 9 additions & 0 deletions prototype/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ indent_size = 1
[*.bndrun]
indent_style = tab
insert_final_newline = false
trim_trailing_whitespace = false

# Custom rules for unit tests with oddly named resource files
[distribution/launcher/src/test/resources/**.feature]
Expand All @@ -37,3 +38,11 @@ insert_final_newline = unset
trim_trailing_whitespace = unset
indent_style = unset
indent_size = unset

[**/*.{ecore,genmodel}]
charset = unset
end_of_line = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
indent_style = unset
indent_size = unset
4 changes: 2 additions & 2 deletions prototype/core/annotation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.eclipse.sensinact.gateway.core</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
</parent>
<artifactId>annotation</artifactId>
<name>SensiNact core Annotations</name>
Expand Down Expand Up @@ -44,4 +44,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
12 changes: 11 additions & 1 deletion prototype/core/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.eclipse.sensinact.gateway.core</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
</parent>
<artifactId>api</artifactId>
<name>SensiNact core API</name>
Expand Down Expand Up @@ -45,6 +45,16 @@
<artifactId>geo-json</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}.models</groupId>
<artifactId>provider</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.sensinact.gateway.core.models</groupId>
<artifactId>provider</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
public abstract class BaseValueDto {

/**
* The model to which this value belongs. If null then a model name
* will be created if necessary
* The model to which this value belongs. If null then a model name will be
* created if necessary
*/
@Model
public String model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.InputStream;
import java.util.Map;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.sensinact.prototype.command.CommandScoped;

/**
Expand All @@ -34,4 +35,8 @@ public interface SensinactModelManager extends CommandScoped {

Map<String, Model> getModels();

Model getModel(EClass eClass);

ModelBuilder createModel(EClass eClass);

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*********************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: Kentyou - initial implementation
**********************************************************************/
* Copyright (c) 2022 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: Kentyou - initial implementation
**********************************************************************/
@org.osgi.annotation.bundle.Export
@org.osgi.annotation.versioning.Version("0.2.0")
package org.eclipse.sensinact.prototype;
package org.eclipse.sensinact.prototype;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public interface ResourceSnapshot extends Snapshot {

ServiceSnapshot getService();

boolean isSet();

TimedValue<?> getValue();

Map<String, Object> getMetadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;
import java.util.function.Predicate;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.sensinact.gateway.geojson.GeoJsonObject;
import org.eclipse.sensinact.prototype.command.CommandScoped;
import org.eclipse.sensinact.prototype.snapshot.ProviderSnapshot;
Expand Down Expand Up @@ -54,6 +55,15 @@ public interface SensinactDigitalTwin extends CommandScoped {
*/
SensinactProvider getProvider(String providerName);

/**
* Get a provider by name and its concrete model class
*
* @param model
* @param providerName
* @return
*/
SensinactProvider getProvider(EClass model, String id);

/**
* Get a provider by name and model
*
Expand Down Expand Up @@ -134,4 +144,5 @@ public interface SensinactDigitalTwin extends CommandScoped {
List<ProviderSnapshot> filteredSnapshot(Predicate<GeoJsonObject> geoFilter,
Predicate<ProviderSnapshot> providerFilter, Predicate<ServiceSnapshot> svcFilter,
Predicate<ResourceSnapshot> rcFilter);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import java.util.List;
import java.util.Map;

import org.eclipse.sensinact.model.core.provider.Provider;
import org.eclipse.sensinact.prototype.command.CommandScoped;
import org.osgi.util.promise.Promise;

/**
* This is the digital twin of a single provider instance
Expand Down Expand Up @@ -68,4 +70,11 @@ public interface SensinactProvider extends CommandScoped {
* Delete this provider from the Digital Twin
*/
void delete();

/**
* Updates a complete Provider
*
* @return
*/
Promise<Void> update(Provider newVersion);
}
2 changes: 1 addition & 1 deletion prototype/core/geo-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.eclipse.sensinact.gateway.core</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
</parent>
<artifactId>geo-json</artifactId>
<name>SensiNact GeoJSON mapping types</name>
Expand Down
39 changes: 30 additions & 9 deletions prototype/core/impl/integration-test.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,36 @@
org.apache.felix.scr;version='[2.2.2,2.2.3)',\
org.eclipse.emf.common;version='[2.28.0,2.28.1)',\
org.eclipse.emf.ecore;version='[2.33.0,2.33.1)',\
org.eclipse.emf.ecore.xmi;version='[2.17.0,2.17.1)',\
org.eclipse.sensinact.gateway.core.annotation;version='[0.0.1,0.0.2)',\
org.eclipse.sensinact.gateway.core.api;version='[0.0.1,0.0.2)',\
org.eclipse.sensinact.gateway.core.geo-json;version='[0.0.1,0.0.2)',\
org.eclipse.sensinact.gateway.core.impl;version='[0.0.1,0.0.2)',\
org.eclipse.sensinact.gateway.core.impl-tests;version='[0.0.1,0.0.2)',\
org.eclipse.sensinact.gateway.core.models;version='[0.0.1,0.0.2)',\
org.gecko.emf.osgi.api;version='[4.5.0,4.5.1)',\
org.gecko.emf.osgi.component;version='[4.5.0,4.5.1)',\
org.eclipse.emf.ecore.xmi;version='[2.18.0,2.18.1)',\
org.eclipse.sensinact.gateway.core.annotation;version='[0.0.2,0.0.3)',\
org.eclipse.sensinact.gateway.core.api;version='[0.0.2,0.0.3)',\
org.eclipse.sensinact.gateway.core.geo-json;version='[0.0.2,0.0.3)',\
org.eclipse.sensinact.gateway.core.impl;version='[0.0.2,0.0.3)',\
org.eclipse.sensinact.gateway.core.impl-tests;version='[0.0.2,0.0.3)',\
org.eclipse.sensinact.gateway.core.models.metadata;version='[0.0.2,0.0.3)',\
org.eclipse.sensinact.gateway.core.models.provider;version='[0.0.2,0.0.3)',\
org.gecko.emf.osgi.api;version='[4.6.2,4.6.3)',\
org.gecko.emf.osgi.component;version='[4.6.2,4.6.3)',\
org.mockito.junit-jupiter;version='[4.7.0,4.7.1)',\
org.mockito.mockito-core;version='[4.7.0,4.7.1)',\
org.objenesis;version='[3.2.0,3.2.1)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
org.osgi.service.cm;version='[1.6.1,1.6.2)',\
org.osgi.service.component;version='[1.5.0,1.5.1)',\
org.osgi.service.typedevent;version='[1.0.0,1.0.1)',\
org.osgi.test.common;version='[1.2.1,1.2.2)',\
org.osgi.test.junit5;version='[1.2.1,1.2.2)',\
org.osgi.util.converter;version='[1.0.9,1.0.10)',\
org.osgi.util.function;version='[1.1.0,1.1.1)',\
org.osgi.util.promise;version='[1.3.0,1.3.1)',\
org.osgi.util.pushstream;version='[1.0.2,1.0.3)',\
slf4j.api;version='[1.7.36,1.7.37)',\
slf4j.simple;version='[1.7.36,1.7.37)'
org.gecko.emf.osgi.api;version='[4.6.0,4.6.1)',\
org.gecko.emf.osgi.component;version='[4.6.0,4.6.1)',\
=======
org.gecko.emf.osgi.component;version='[5.0.0,5.0.1)',\
>>>>>>> branch 'model_push' of git@github.com:eclipse/org.eclipse.sensinact.gateway.git
org.mockito.junit-jupiter;version='[4.7.0,4.7.1)',\
org.mockito.mockito-core;version='[4.7.0,4.7.1)',\
org.objenesis;version='[3.2.0,3.2.1)',\
Expand Down
16 changes: 13 additions & 3 deletions prototype/core/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.eclipse.sensinact.gateway.core</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
</parent>
<artifactId>impl</artifactId>
<name>SensiNact core implementation</name>
Expand All @@ -33,8 +33,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>models</artifactId>
<groupId>${project.groupId}.models</groupId>
<artifactId>metadata</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -73,6 +73,16 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.sensinact.gateway.core.models</groupId>
<artifactId>metadata</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.sensinact.model.core.SensiNactPackage;
import org.eclipse.sensinact.model.core.provider.ProviderPackage;
import org.eclipse.sensinact.prototype.command.AbstractSensinactCommand;
import org.eclipse.sensinact.prototype.command.GatewayThread;
import org.eclipse.sensinact.prototype.model.impl.SensinactModelManagerImpl;
import org.eclipse.sensinact.prototype.model.nexus.impl.ModelNexus;
import org.eclipse.sensinact.prototype.model.nexus.ModelNexus;
import org.eclipse.sensinact.prototype.notification.NotificationAccumulator;
import org.eclipse.sensinact.prototype.notification.impl.ImmediateNotificationAccumulator;
import org.eclipse.sensinact.prototype.notification.impl.NotificationAccumulatorImpl;
Expand Down Expand Up @@ -71,10 +71,10 @@ public class GatewayThreadImpl extends Thread implements GatewayThread {

@Activate
public GatewayThreadImpl(@Reference TypedEventBus typedEventBus, @Reference ResourceSet resourceSet,
@Reference SensiNactPackage sensinactPackage) {
@Reference ProviderPackage ProviderPackage) {
this.typedEventBus = typedEventBus;
this.whiteboard = new SensinactWhiteboard(this);
nexusImpl = new ModelNexus(resourceSet, sensinactPackage, this::getCurrentAccumulator, this::performAction);
nexusImpl = new ModelNexus(resourceSet, ProviderPackage, this::getCurrentAccumulator, this::performAction);
start();
}

Expand Down Expand Up @@ -198,9 +198,9 @@ public WorkItem(Deferred<T> d, AbstractSensinactCommand<T> command, ModelNexus n

void doWork() {
try {
SensinactDigitalTwinImpl twinImpl = new SensinactDigitalTwinImpl(command.getAccumulator(), nexusImpl,
SensinactDigitalTwinImpl twinImpl = new SensinactDigitalTwinImpl(nexusImpl,
getGatewayThread().getPromiseFactory());
SensinactModelManagerImpl mgrImpl = new SensinactModelManagerImpl(command.getAccumulator(), nexusImpl);
SensinactModelManagerImpl mgrImpl = new SensinactModelManagerImpl(nexusImpl);
Promise<T> promise;
try {
promise = command.call(twinImpl, mgrImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Kentyou - initial implementation
* Kentyou - initial implementation
* Data In Motion - Addeds Provider Push
**********************************************************************/
package org.eclipse.sensinact.prototype.impl;

Expand All @@ -18,6 +19,7 @@
import java.util.Map;
import java.util.WeakHashMap;

import org.eclipse.sensinact.model.core.provider.Provider;
import org.eclipse.sensinact.prototype.PrototypePush;
import org.eclipse.sensinact.prototype.command.AbstractSensinactCommand;
import org.eclipse.sensinact.prototype.command.GatewayThread;
Expand Down Expand Up @@ -49,6 +51,10 @@ public class PrototypePushImpl implements PrototypePush {
@Override
public Promise<?> pushUpdate(Object o) {

if (o instanceof Provider) {
return thread.execute(new SaveProviderCommand((Provider) o));
}

DataExtractor extractor;

Class<?> updateClazz = o.getClass();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*********************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Kentyou - initial implementation
**********************************************************************/
package org.eclipse.sensinact.prototype.impl;

import java.time.Instant;

import org.eclipse.sensinact.model.core.provider.Provider;
import org.eclipse.sensinact.prototype.command.AbstractSensinactCommand;
import org.eclipse.sensinact.prototype.model.Model;
import org.eclipse.sensinact.prototype.model.SensinactModelManager;
import org.eclipse.sensinact.prototype.twin.SensinactDigitalTwin;
import org.eclipse.sensinact.prototype.twin.SensinactProvider;
import org.osgi.util.promise.Promise;
import org.osgi.util.promise.PromiseFactory;

public class SaveProviderCommand extends AbstractSensinactCommand<Void> {

private Provider provider;

public SaveProviderCommand(Provider provider) {
this.provider = provider;
}

@Override
protected Promise<Void> call(SensinactDigitalTwin twin, SensinactModelManager modelMgr,
PromiseFactory promiseFactory) {

Model model = modelMgr.getModel(provider.eClass());
if (model == null) {
model = modelMgr.createModel(provider.eClass()).withCreationTime(Instant.now()).build();
}
SensinactProvider sp = twin.getProvider(model.getName(), provider.getId());
if (sp == null) {
sp = twin.createProvider(model.getName(), provider.getId(), Instant.now());
}

return sp.update(provider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.sensinact.model.core.Provider;
import org.eclipse.sensinact.model.core.provider.Provider;
import org.eclipse.sensinact.prototype.snapshot.ProviderSnapshot;

public class ProviderSnapshotImpl extends AbstractSnapshot implements ProviderSnapshot {
Expand Down
Loading

0 comments on commit 5e27485

Please sign in to comment.