SBC auto-update in case of server version bump
This commit is contained in:
parent
f1439e4141
commit
5a820a5557
|
@ -40,7 +40,12 @@ public class NetworkConnector implements Closeable {
|
||||||
private boolean isClosed;
|
private boolean isClosed;
|
||||||
|
|
||||||
public NetworkConnectorResult start(Implementation implementation, String authToken, String controllerPort, NetworkConnectorContext context) {
|
public NetworkConnectorResult start(Implementation implementation, String authToken, String controllerPort, NetworkConnectorContext context) {
|
||||||
return start(implementation, authToken, controllerPort, context, ReconnectListener.VOID);
|
return start(implementation, authToken, controllerPort, context, new ReconnectListener() {
|
||||||
|
@Override
|
||||||
|
public void onReconnect() {
|
||||||
|
log.info("onReconnect");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkConnectorResult start(Implementation implementation, String authToken, String controllerPort, NetworkConnectorContext context, ReconnectListener reconnectListener) {
|
public NetworkConnectorResult start(Implementation implementation, String authToken, String controllerPort, NetworkConnectorContext context, ReconnectListener reconnectListener) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import static com.devexperts.logging.Logging.getLogging;
|
||||||
public class NetworkConnectorContext {
|
public class NetworkConnectorContext {
|
||||||
private static final Logging log = getLogging(NetworkConnectorContext.class);
|
private static final Logging log = getLogging(NetworkConnectorContext.class);
|
||||||
private static final int UPDATE_SBC_EXIT_CODE = 15;
|
private static final int UPDATE_SBC_EXIT_CODE = 15;
|
||||||
private static final int UPDATE_FIRMWARE_EXIT_CODE = 16;
|
public static final int UPDATE_FIRMWARE_EXIT_CODE = 16;
|
||||||
|
|
||||||
public int reconnectDelay() {
|
public int reconnectDelay() {
|
||||||
return 15; // this one is seconds
|
return 15; // this one is seconds
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.rusefi.proxy.client;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class IncompatibleBackendException extends IOException {
|
||||||
|
public IncompatibleBackendException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ import com.rusefi.io.tcp.BinaryProtocolProxy;
|
||||||
import com.rusefi.io.tcp.ServerSocketReference;
|
import com.rusefi.io.tcp.ServerSocketReference;
|
||||||
import com.rusefi.io.tcp.TcpIoStream;
|
import com.rusefi.io.tcp.TcpIoStream;
|
||||||
import com.rusefi.proxy.NetworkConnector;
|
import com.rusefi.proxy.NetworkConnector;
|
||||||
|
import com.rusefi.proxy.NetworkConnectorContext;
|
||||||
import com.rusefi.server.ApplicationRequest;
|
import com.rusefi.server.ApplicationRequest;
|
||||||
import com.rusefi.server.rusEFISSLContext;
|
import com.rusefi.server.rusEFISSLContext;
|
||||||
import com.rusefi.tools.online.HttpUtil;
|
import com.rusefi.tools.online.HttpUtil;
|
||||||
|
@ -77,8 +78,15 @@ public class LocalApplicationProxy implements Closeable {
|
||||||
public static ServerSocketReference startAndRun(LocalApplicationProxyContext context, ApplicationRequest applicationRequest, int jsonHttpPort, TcpIoStream.DisconnectListener disconnectListener, ConnectionListener connectionListener) throws IOException {
|
public static ServerSocketReference startAndRun(LocalApplicationProxyContext context, ApplicationRequest applicationRequest, int jsonHttpPort, TcpIoStream.DisconnectListener disconnectListener, ConnectionListener connectionListener) throws IOException {
|
||||||
String version = context.executeGet(ProxyClient.getHttpAddress(jsonHttpPort) + ProxyClient.VERSION_PATH);
|
String version = context.executeGet(ProxyClient.getHttpAddress(jsonHttpPort) + ProxyClient.VERSION_PATH);
|
||||||
log.info("Server says version=" + version);
|
log.info("Server says version=" + version);
|
||||||
if (!version.contains(ProxyClient.BACKEND_VERSION))
|
if (!version.contains(ProxyClient.BACKEND_VERSION)) {
|
||||||
throw new IOException("Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION);
|
String message = "Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION;
|
||||||
|
log.error(message);
|
||||||
|
System.out.println(message);
|
||||||
|
/**
|
||||||
|
* let's give wrapper script a chance to update us
|
||||||
|
*/
|
||||||
|
throw new IncompatibleBackendException(message);
|
||||||
|
}
|
||||||
|
|
||||||
AbstractIoStream authenticatorToProxyStream = new TcpIoStream("authenticatorToProxyStream ", rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, context.serverPortForRemoteApplications()), disconnectListener);
|
AbstractIoStream authenticatorToProxyStream = new TcpIoStream("authenticatorToProxyStream ", rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, context.serverPortForRemoteApplications()), disconnectListener);
|
||||||
LocalApplicationProxy.sendHello(authenticatorToProxyStream, applicationRequest);
|
LocalApplicationProxy.sendHello(authenticatorToProxyStream, applicationRequest);
|
||||||
|
|
|
@ -5,10 +5,15 @@ import com.rusefi.auth.AuthTokenUtil;
|
||||||
import com.rusefi.autodetect.PortDetector;
|
import com.rusefi.autodetect.PortDetector;
|
||||||
import com.rusefi.proxy.NetworkConnector;
|
import com.rusefi.proxy.NetworkConnector;
|
||||||
import com.rusefi.proxy.NetworkConnectorContext;
|
import com.rusefi.proxy.NetworkConnectorContext;
|
||||||
|
import com.rusefi.tools.online.HttpUtil;
|
||||||
|
import com.rusefi.tools.online.ProxyClient;
|
||||||
import com.rusefi.ui.AuthTokenPanel;
|
import com.rusefi.ui.AuthTokenPanel;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class NetworkConnectorStartup {
|
public class NetworkConnectorStartup {
|
||||||
private final static Logging log = Logging.getLogging(NetworkConnectorStartup.class);
|
private final static Logging log = Logging.getLogging(NetworkConnectorStartup.class);
|
||||||
|
|
||||||
public static void start() {
|
public static void start() {
|
||||||
String authToken = AuthTokenPanel.getAuthToken();
|
String authToken = AuthTokenPanel.getAuthToken();
|
||||||
if (!AuthTokenUtil.isToken(authToken)) {
|
if (!AuthTokenUtil.isToken(authToken)) {
|
||||||
|
@ -24,8 +29,23 @@ public class NetworkConnectorStartup {
|
||||||
|
|
||||||
NetworkConnectorContext connectorContext = new NetworkConnectorContext();
|
NetworkConnectorContext connectorContext = new NetworkConnectorContext();
|
||||||
|
|
||||||
NetworkConnector.NetworkConnectorResult networkConnectorResult = new NetworkConnector().start(NetworkConnector.Implementation.SBC,
|
NetworkConnector.NetworkConnectorResult networkConnectorResult = new NetworkConnector().start(NetworkConnector.Implementation.SBC, authToken, autoDetectedPort, connectorContext, new NetworkConnector.ReconnectListener() {
|
||||||
authToken, autoDetectedPort, connectorContext);
|
@Override
|
||||||
|
public void onReconnect() {
|
||||||
|
try {
|
||||||
|
String version = HttpUtil.executeGet(ProxyClient.getHttpAddress(HttpUtil.PROXY_JSON_API_HTTP_PORT) + ProxyClient.VERSION_PATH);
|
||||||
|
if (!version.contains(ProxyClient.BACKEND_VERSION)) {
|
||||||
|
String message = "Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION;
|
||||||
|
log.error(message);
|
||||||
|
System.out.println(message);
|
||||||
|
// let's give wrapper bash script a chance to update software
|
||||||
|
System.exit(NetworkConnectorContext.UPDATE_FIRMWARE_EXIT_CODE);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Ignoring", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
log.info("Running with oneTimeToken=" + networkConnectorResult.getOneTimeToken());
|
log.info("Running with oneTimeToken=" + networkConnectorResult.getOneTimeToken());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue