Skip to content

Commit

Permalink
Merge branch 'release/2024.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeilmeier committed May 2, 2024
2 parents 52502bf + 5d1a04f commit 15bed86
Show file tree
Hide file tree
Showing 738 changed files with 30,933 additions and 23,112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '20'

- name: Setup Cache for Node.js
uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '20'

- name: Setup Cache for Node.js
uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion cnf/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<message key="name.invalidPattern" value="Method type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="InterfaceTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]$)"/>
<message key="name.invalidPattern" value="Interface type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="NoFinalizer"/>
Expand Down
12 changes: 6 additions & 6 deletions cnf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,25 @@
<!-- Used by com.influxdb: influxdb-client -->
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-gson</artifactId>
<version>2.10.0</version>
<version>2.11.0</version>
</dependency>
<dependency>
<!-- Used by com.influxdb: influxdb-client -->
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.10.0</version>
<version>2.11.0</version>
</dependency>
<dependency>
<!-- Used by com.influxdb: influxdb-client -->
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-scalars</artifactId>
<version>2.10.0</version>
<version>2.11.0</version>
</dependency>
<dependency>
<!-- Used by com.influxdb: influxdb -->
<groupId>com.squareup.retrofit2</groupId>
<artifactId>adapter-rxjava3</artifactId>
<version>2.10.0</version>
<version>2.11.0</version>
</dependency>
<dependency>
<!-- JavaBeans Activation Framework -->
Expand Down Expand Up @@ -237,7 +237,7 @@
<!-- Changelog: https://github.com/apache/felix-dev/blob/master/webconsole/README.md#releases -->
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.webconsole</artifactId>
<version>5.0.0</version>
<version>5.0.2</version>
</dependency>
<dependency>
<!-- Apache Felix Web Console Service Component Runtime/Declarative Services Plugin -->
Expand All @@ -260,7 +260,7 @@
<dependency>
<groupId>org.dhatim</groupId>
<artifactId>fastexcel</artifactId>
<version>0.17.0</version>
<version>0.18.0</version>
</dependency>
<dependency>
<!-- Eclipse Paho MQTTv5 Client -->
Expand Down
8 changes: 8 additions & 0 deletions doc/modules/ROOT/pages/edge/implement.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,11 @@ This functionality can also be used in production environments albeit dynamic co

[NOTE]
Same applies to the OpenEMS Backend for dynamically loading devices.

=== Check the Tests of Your Module

Before continuing with the development and implementation, it's important to ensure that your module's tests are passing. This helps in maintaining the quality and functionality of the module. To check the tests of your module, execute the following Gradle command in the root directory of OpenEMS:

----
Run ./gradlew :io.openems.edge.io.shelly:clean in the root Directory to check the tests of your module.
----
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class OfflineEdgeHandler implements Handler<OfflineEdgeMessage> {
public static final int MAX_SIMULTANEOUS_MSGS = 500;
public static final int MAX_SIMULTANEOUS_EDGES = 1000;
public static final int EDGE_REBOOT_MINUTES = 5;

private final Logger log = LoggerFactory.getLogger(OfflineEdgeHandler.class);

private final int initialDelay; // in Minutes
Expand All @@ -42,7 +42,7 @@ public class OfflineEdgeHandler implements Handler<OfflineEdgeMessage> {

private TimedTask initMetadata;
private TimedExecutor timeService;

public OfflineEdgeHandler(MessageSchedulerService mss, TimedExecutor timeService, Mailer mailer, Metadata metadata,
int initialDelay) {
this.mailer = mailer;
Expand Down Expand Up @@ -256,7 +256,7 @@ public Consumer<EventReader> getEventHandler(String eventTopic) {
yield this::handleOnSetOnline;

case Metadata.Events.AFTER_IS_INITIALIZED:
yield this::handleMetadataAfterInitialize;
yield this::handleMetadataAfterInitialize;

default:
yield null;
Expand Down
2 changes: 1 addition & 1 deletion io.openems.backend.application/BackendApp.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
org.apache.felix.inventory;version='[2.0.0,2.0.1)',\
org.apache.felix.metatype;version='[1.2.4,1.2.5)',\
org.apache.felix.scr;version='[2.2.10,2.2.11)',\
org.apache.felix.webconsole;version='[5.0.0,5.0.1)',\
org.apache.felix.webconsole;version='[5.0.2,5.0.3)',\
org.apache.felix.webconsole.plugins.ds;version='[2.3.0,2.3.1)',\
org.jetbrains.kotlin.osgi-bundle;version='[1.9.23,1.9.24)',\
org.jsr-305;version='[3.0.2,3.0.3)',\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.openems.backend.b2brest;

import java.io.BufferedReader;
import static io.openems.common.utils.JsonUtils.parseToJsonObject;
import static java.util.stream.Collectors.joining;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Base64;
Expand All @@ -11,15 +12,13 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import io.openems.backend.common.metadata.User;
import io.openems.common.exceptions.OpenemsError;
Expand Down Expand Up @@ -145,11 +144,12 @@ private void sendErrorResponse(Request baseRequest, HttpServletResponse response
*/
private static JsonObject parseJson(Request baseRequest) throws OpenemsException {
try {
return JsonParser.parseString(//
new BufferedReader(new InputStreamReader(baseRequest.getInputStream())) //
.lines() //
.collect(Collectors.joining("\n"))) //
.getAsJsonObject();
try (var br = baseRequest.getReader()) {
return parseToJsonObject(br //
.lines() //
.collect(joining("\n")));
}

} catch (Exception e) {
throw new OpenemsException("Unable to parse: " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.openems.backend.common.jsonrpc;

import java.util.concurrent.CompletableFuture;

import io.openems.backend.common.jsonrpc.request.SimulationRequest;
import io.openems.backend.common.metadata.User;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.jsonrpc.base.JsonrpcResponseSuccess;

public interface SimulationEngine {

/**
* Handles a JSON-RPC Request.
*
* @param edgeId the Edge-ID
* @param user the authenticated {@link User}
* @param request the {@link JsonrpcRequest}
* @return the JSON-RPC Success Response Future
* @throws OpenemsNamedException on error
*/
public CompletableFuture<JsonrpcResponseSuccess> handleRequest(String edgeId, User user, SimulationRequest request)
throws OpenemsNamedException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.openems.backend.common.jsonrpc.request;

import com.google.gson.JsonObject;

import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.jsonrpc.base.GenericJsonrpcRequest;
import io.openems.common.jsonrpc.base.JsonrpcRequest;
import io.openems.common.utils.JsonUtils;

/**
* Represents a JSON-RPC Request for 'SimulationRequest'.
*
* <pre>
* {
* "jsonrpc": "2.0",
* "id": "UUID",
* "method": "simulation",
* "params": {
* "payload": {@link JsonrpcRequest},
* }
* }
* </pre>
*/
public class SimulationRequest extends JsonrpcRequest {

public static final String METHOD = "simulation";

/**
* Create {@link SimulationRequest} from a template {@link JsonrpcRequest}.
*
* @param r the template {@link JsonrpcRequest}
* @return the {@link SimulationRequest}
* @throws OpenemsNamedException on parse error
*/
public static SimulationRequest from(JsonrpcRequest r) throws OpenemsNamedException {
var p = r.getParams();
JsonrpcRequest payload = GenericJsonrpcRequest.from(JsonUtils.getAsJsonObject(p, "payload"));
return new SimulationRequest(r, payload);
}

private final JsonrpcRequest payload;

public SimulationRequest(JsonrpcRequest payload) {
super(SimulationRequest.METHOD, payload.getTimeout() /* inherit timeout from payload */);
this.payload = payload;
}

public SimulationRequest(JsonrpcRequest request, JsonrpcRequest payload) {
super(request, SimulationRequest.METHOD);
this.payload = payload;
}

/**
* Gets the Payload {@link JsonrpcRequest}.
*
* @return Payload
*/
public JsonrpcRequest getPayload() {
return this.payload;
}

@Override
public JsonObject getParams() {
return JsonUtils.buildJsonObject() //
.add("payload", this.payload.toJsonObject()) //
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import com.google.gson.JsonObject;
import java.util.NavigableMap;
import java.util.TreeMap;

import com.google.gson.JsonObject;

import io.openems.common.channel.Level;
import io.openems.common.exceptions.OpenemsError;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.slf4j.LoggerFactory;

import com.google.gson.JsonObject;

import io.openems.backend.common.metadata.User;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.jsonrpc.base.GenericJsonrpcResponseSuccess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public EdgeHandler edge() {
public Optional<String> getSerialNumberForEdge(Edge edge) {
throw new UnsupportedOperationException("DummyMetadata.getSerialNumberForEdge() is not implemented");
}

@Override
public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException {
throw new UnsupportedOperationException("DummyMetadata.getUserAlertingSettings() is not implemented");
Expand Down Expand Up @@ -369,7 +369,7 @@ public EdgeMetadata getEdgeMetadataForUser(User user, String edgeId) throws Open
public Optional<Level> getSumState(String edgeId) {
throw new UnsupportedOperationException("DummyMetadata.getSumState() is not implemented");
}

@Override
public void logGenericSystemLog(GenericSystemLog systemLog) {
this.logInfo(this.log,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public Optional<String> getSerialNumberForEdge(Edge edge) {
public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException {
throw new UnsupportedOperationException("FileMetadata.getUserAlertingSettings() is not implemented");
}

@Override
public List<UserAlertingSettings> getUserAlertingSettings(String edgeId) {
throw new UnsupportedOperationException("FileMetadata.getUserAlertingSettings() is not implemented");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import io.openems.common.jsonrpc.request.GetEdgesRequest.PaginationOptions;
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.utils.JsonUtils;
import io.openems.common.utils.ObjectUtils;
import io.openems.common.utils.PasswordUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.openems.backend.common.jsonrpc.request.RegisterUserRequest;
import io.openems.backend.common.jsonrpc.request.SetUserAlertingConfigsRequest;
import io.openems.backend.common.jsonrpc.request.SetUserInformationRequest;
import io.openems.backend.common.jsonrpc.request.SimulationRequest;
import io.openems.backend.common.jsonrpc.request.SubmitSetupProtocolRequest;
import io.openems.backend.common.jsonrpc.request.SubscribeEdgesRequest;
import io.openems.backend.common.jsonrpc.response.AddEdgeToUserResponse;
Expand Down Expand Up @@ -224,6 +225,9 @@ private CompletableFuture<EdgeRpcResponse> handleEdgeRpcRequest(WsData wsData, U
this.handleSubscribeChannelsRequest(wsData, edgeId, user, SubscribeChannelsRequest.from(request));
case SubscribeSystemLogRequest.METHOD ->
this.handleSubscribeSystemLogRequest(wsData, edgeId, user, SubscribeSystemLogRequest.from(request));
case SimulationRequest.METHOD ->
this.handleSimulationRequest(edgeId, user, SimulationRequest.from(request));

case ComponentJsonApiRequest.METHOD -> {
final var componentRequest = ComponentJsonApiRequest.from(request);
if (!"_host".equals(componentRequest.getComponentId())) {
Expand Down Expand Up @@ -280,6 +284,25 @@ private CompletableFuture<EdgeRpcResponse> handleEdgeRpcRequest(WsData wsData, U
return result;
}

/**
* Handles a {@link GetSimulationRequest}.
*
* @param edgeId the Edge-ID
* @param user the {@link User} - no specific level required
* @param request the {@link GetSimulationRequest}
* @return the JSON-RPC Success Response Future
* @throws OpenemsNamedException on error
*/
private CompletableFuture<JsonrpcResponseSuccess> handleSimulationRequest(String edgeId, User user, SimulationRequest request) throws OpenemsNamedException {

final var simulation = this.parent.simulation;
if (simulation == null) {
throw new OpenemsException("simulation unavailable");
}

return simulation.handleRequest(edgeId, user, request);
}

private record LogSystemExecuteCommend(//
String edgeId, // non-null
User user, // non-null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import org.osgi.service.event.propertytypes.EventTopics;
Expand All @@ -27,6 +29,7 @@
import io.openems.backend.common.edgewebsocket.EdgeCache;
import io.openems.backend.common.edgewebsocket.EdgeWebsocket;
import io.openems.backend.common.jsonrpc.JsonRpcRequestHandler;
import io.openems.backend.common.jsonrpc.SimulationEngine;
import io.openems.backend.common.metadata.Metadata;
import io.openems.backend.common.metadata.User;
import io.openems.backend.common.timedata.TimedataManager;
Expand Down Expand Up @@ -66,6 +69,9 @@ public class UiWebsocketImpl extends AbstractOpenemsBackendComponent

@Reference
protected volatile TimedataManager timedataManager;

@Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL)
protected volatile SimulationEngine simulation;

public UiWebsocketImpl() {
super("Ui.Websocket");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class OpenemsConstants {
* <p>
* This is the month of the release.
*/
public static final short VERSION_MINOR = 4;
public static final short VERSION_MINOR = 5;

/**
* The patch version of OpenEMS.
Expand Down
Loading

0 comments on commit 15bed86

Please sign in to comment.