Skip to content

Commit

Permalink
Merge branch 'release/v1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeilmeier committed Sep 21, 2017
2 parents 2828037 + 7b597d0 commit 740f2d4
Show file tree
Hide file tree
Showing 281 changed files with 5,410 additions and 5,038 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Dependency Status](https://www.versioneye.com/user/projects/59a3dd596725bd004562717b/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/59a3dd596725bd004562717b)

# OpenEMS
## Open Source Energy Management System

Expand Down
2 changes: 2 additions & 0 deletions backend/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
eclipse.preferences.version=1
encoding//src/io/openems/impl/scheduler/SimpleScheduler.java=UTF-8
encoding/<project>=UTF-8
encoding/src=UTF-8
2 changes: 2 additions & 0 deletions backend/OpenEMS-Backend (Dummy).launch
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<mapEntry key="OPENEMS_WEBSOCKET_PORT" value="8077"/>
<mapEntry key="TIMEDATA" value="DUMMY"/>
</mapAttribute>
<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;sourceLookupDirector&gt;&#13;&#10;&lt;sourceContainers duplicates=&quot;false&quot;&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;javaProject name=&amp;quot;common&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.javaProject&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;default/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.debug.core.containerType.default&quot;/&gt;&#13;&#10;&lt;/sourceContainers&gt;&#13;&#10;&lt;/sourceLookupDirector&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="io.openems.backend.App"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="backend"/>
Expand Down
112 changes: 61 additions & 51 deletions backend/pom.xml
Original file line number Diff line number Diff line change
@@ -1,74 +1,84 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.openems</groupId>
<artifactId>femsserver</artifactId>
<version>0.0.1-SNAPSHOT</version>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<name>OpenEMS Backend</name>
<parent>
<groupId>io.openems</groupId>
<artifactId>pom</artifactId>
<version>1.3</version>
</parent>
<artifactId>backend</artifactId>
<packaging>jar</packaging>

<name>femsserver</name>
<url>http://maven.apache.org</url>

<!-- TODO check all maven dependencies of all projects -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<openems-common.version>1.0.0</openems-common.version>
<slf4j.version>1.7.15</slf4j.version>
<logback.version>1.0.1</logback.version>
<gson.version>2.6.2</gson.version>
<guava.version>23.0</guava.version>
</properties>

<repositories>
<repository>
<id>clojars</id>
<url>http://clojars.org/repo/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>${influxdb.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.abercap</groupId>
<artifactId>odoo-java-api</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.java-websocket/java-websocket -->
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>java-websocket</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<artifactId>Java-WebSocket</artifactId>
<version>${websocket.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<finalName>openems-backend</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modelVersion>4.0.0</modelVersion>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected BrowserWebsocketSingleton(int port) throws Exception {
* Open event of websocket. Parses the Odoo "session_id" and stores it in a new Session.
*/
@Override
public void onOpen(WebSocket websocket, ClientHandshake handshake) {
protected void _onOpen(WebSocket websocket, ClientHandshake handshake) {
// Prepare session information
String error = "";
BrowserSession session = null;
Expand Down Expand Up @@ -99,19 +99,22 @@ public void onOpen(WebSocket websocket, ClientHandshake handshake) {
// send connection successful to browser
JsonObject jReply = DefaultMessages.browserConnectionSuccessfulReply(session.getToken(), Optional.empty(),
data.getDevices());
log.info("Browser connected. User [" + data.getUserId().orElse(-1) + "] Session ["
+ data.getOdooSessionId().orElse("") + "]");
// TODO write user name to log output
WebSocketUtils.send(websocket, jReply);

// add websocket to local cache
this.websockets.forcePut(websocket, session);

log.info("User [" + data.getUserName() + "] connected with Session [" + data.getOdooSessionId().orElse("")
+ "]. Total websockets [" + this.websockets.size() + "]");

} else {
// send connection failed to browser
JsonObject jReply = DefaultMessages.browserConnectionFailedReply();
WebSocketUtils.send(websocket, jReply);
log.info("Browser connection failed. User [" + data.getUserId().orElse(-1) + "] Session ["
+ data.getOdooSessionId().orElse("") + "] Error [" + error + "]");
log.warn("User [" + data.getUserName() + "] connection failed. Session ["
+ data.getOdooSessionId().orElse("") + "] Error [" + error + "]. Total websockets ["
+ this.websockets.size() + "]");

websocket.closeConnection(CloseFrame.REFUSE, error);
}
Expand All @@ -121,7 +124,7 @@ public void onOpen(WebSocket websocket, ClientHandshake handshake) {
* Message event of websocket. Handles a new message.
*/
@Override
protected void onMessage(WebSocket websocket, JsonObject jMessage, Optional<JsonArray> jMessageIdOpt,
protected void _onMessage(WebSocket websocket, JsonObject jMessage, Optional<JsonArray> jMessageIdOpt,
Optional<String> deviceNameOpt) {
/*
* With existing device name
Expand Down Expand Up @@ -155,9 +158,9 @@ protected void onMessage(WebSocket websocket, JsonObject jMessage, Optional<Json
try {
forwardMessageToOpenems(websocket, jMessage, deviceName);
} catch (OpenemsException e) {
WebSocketUtils.send(websocket, DefaultMessages.notification(Notification.EDGE_UNABLE_TO_FORWARD,
deviceName, e.getMessage()));
log.error(deviceName + ": Unable to forward message: " + e.getMessage());
WebSocketUtils.sendNotification(websocket, Notification.EDGE_UNABLE_TO_FORWARD, deviceName,
e.getMessage());
log.error("Unable to forward to Device [" + deviceName + "] : " + e.getMessage());
}
}
}
Expand Down Expand Up @@ -243,9 +246,8 @@ public void openemsConnectionClosed(String name) {
for (BrowserSession session : this.sessionManager.getSessions()) {
for (Device device : session.getData().getDevices()) {
if (name.equals(device.getName())) {
WebSocket ws = this.websockets.inverse().get(session);
JsonObject j = DefaultMessages.notification(Notification.EDGE_CONNECTION_ClOSED, name);
WebSocketUtils.send(ws, j);
WebSocket websocket = this.websockets.inverse().get(session);
WebSocketUtils.sendNotification(websocket, Notification.EDGE_CONNECTION_ClOSED, name);
}
}
}
Expand All @@ -260,9 +262,8 @@ public void openemsConnectionOpened(String name) {
for (BrowserSession session : this.sessionManager.getSessions()) {
for (Device device : session.getData().getDevices()) {
if (name.equals(device.getName())) {
WebSocket ws = this.websockets.inverse().get(session);
JsonObject j = DefaultMessages.notification(Notification.EDGE_CONNECTION_OPENED, name);
WebSocketUtils.send(ws, j);
WebSocket websocket = this.websockets.inverse().get(session);
WebSocketUtils.sendNotification(Optional.of(websocket), Notification.EDGE_CONNECTION_OPENED, name);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ protected BrowserSession(String token, BrowserSessionData data) {

@Override
public String toString() {
return "User [" + getData().getUserId() + "] Session [" + getData().getOdooSessionId() + "]";
return "User [" + getData().getUserName() + "] Session [" + getData().getOdooSessionId().orElse("") + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.openems.common.types.Device;

public class BrowserSessionData extends SessionData {
private String userName = "";
private Optional<Integer> userId = Optional.empty();
private Optional<String> odooSessionId = Optional.empty();
private List<Device> devices = new ArrayList<>();
Expand All @@ -28,10 +29,18 @@ public void setUserId(Integer userId) {
this.userId = Optional.of(userId);
}

public void setUserName(String name) {
this.userName = name;
}

public Optional<Integer> getUserId() {
return userId;
}

public String getUserName() {
return userName;
}

public List<Device> getDevices() {
return devices;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;

import io.openems.backend.browserwebsocket.session.BrowserSession;
import io.openems.backend.utilities.ManyToMany;
import io.openems.common.session.Session;

public class ConnectionManagerSingleton {

Expand All @@ -18,7 +18,7 @@ public class ConnectionManagerSingleton {
/**
* Stores active websockets to browsers
*/
private final BiMap<WebSocket, Session> browserWebsockets = Maps.synchronizedBiMap(HashBiMap.create());
private final BiMap<WebSocket, BrowserSession> browserWebsockets = Maps.synchronizedBiMap(HashBiMap.create());

/**
* Stores active websockets to openems devices (value = deviceName, e.g. 'fems5')
Expand All @@ -44,7 +44,7 @@ public void removeWebsocketInterconnection(WebSocket browserWebsocket, WebSocket
/*
* Helper methods for Browser websockets
*/
public void addBrowserWebsocket(WebSocket websocket, Session session) {
public void addBrowserWebsocket(WebSocket websocket, BrowserSession session) {
this.browserWebsockets.put(websocket, session);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.openems.backend.browserwebsocket.session.BrowserSession;
import io.openems.backend.browserwebsocket.session.BrowserSessionData;
import io.openems.backend.metadata.api.MetadataSingleton;
Expand All @@ -16,7 +13,7 @@
import io.openems.common.types.Device;

public class MetadataDummySingleton implements MetadataSingleton {
private final Logger log = LoggerFactory.getLogger(MetadataDummySingleton.class);
// private final Logger log = LoggerFactory.getLogger(MetadataDummySingleton.class);

private MetadataDummyDeviceModel deviceModel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ public void getInfoWithSession(BrowserSession session) throws OpenemsException {
if (j.has("result")) {
// parse the result
JsonObject jResult = JsonUtils.getAsJsonObject(j, "result");
data.setUserId(JsonUtils.getAsInt(jResult, "user"));
JsonObject jUser = JsonUtils.getAsJsonObject(jResult, "user");
data.setUserId(JsonUtils.getAsInt(jUser, "id"));
data.setUserName(JsonUtils.getAsString(jUser, "name"));
JsonArray jDevices = JsonUtils.getAsJsonArray(jResult, "devices");
List<Device> deviceInfos = new ArrayList<>();
for (JsonElement jDevice : jDevices) {
Expand Down
Loading

0 comments on commit 740f2d4

Please sign in to comment.