SBC auto-update in case of server version bump
This commit is contained in:
parent
871c1f7a63
commit
dcfbda4e5c
|
@ -40,7 +40,12 @@ public class NetworkConnector implements Closeable {
|
|||
private boolean isClosed;
|
||||
|
||||
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) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import static com.devexperts.logging.Logging.getLogging;
|
|||
public class NetworkConnectorContext {
|
||||
private static final Logging log = getLogging(NetworkConnectorContext.class);
|
||||
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() {
|
||||
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.TcpIoStream;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.proxy.NetworkConnectorContext;
|
||||
import com.rusefi.server.ApplicationRequest;
|
||||
import com.rusefi.server.rusEFISSLContext;
|
||||
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 {
|
||||
String version = context.executeGet(ProxyClient.getHttpAddress(jsonHttpPort) + ProxyClient.VERSION_PATH);
|
||||
log.info("Server says version=" + version);
|
||||
if (!version.contains(ProxyClient.BACKEND_VERSION))
|
||||
throw new IOException("Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION);
|
||||
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 script a chance to update us
|
||||
*/
|
||||
throw new IncompatibleBackendException(message);
|
||||
}
|
||||
|
||||
AbstractIoStream authenticatorToProxyStream = new TcpIoStream("authenticatorToProxyStream ", rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, context.serverPortForRemoteApplications()), disconnectListener);
|
||||
LocalApplicationProxy.sendHello(authenticatorToProxyStream, applicationRequest);
|
||||
|
|
|
@ -5,10 +5,15 @@ import com.rusefi.auth.AuthTokenUtil;
|
|||
import com.rusefi.autodetect.PortDetector;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.proxy.NetworkConnectorContext;
|
||||
import com.rusefi.tools.online.HttpUtil;
|
||||
import com.rusefi.tools.online.ProxyClient;
|
||||
import com.rusefi.ui.AuthTokenPanel;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class NetworkConnectorStartup {
|
||||
private final static Logging log = Logging.getLogging(NetworkConnectorStartup.class);
|
||||
|
||||
public static void start() {
|
||||
String authToken = AuthTokenPanel.getAuthToken();
|
||||
if (!AuthTokenUtil.isToken(authToken)) {
|
||||
|
@ -24,8 +29,23 @@ public class NetworkConnectorStartup {
|
|||
|
||||
NetworkConnectorContext connectorContext = new NetworkConnectorContext();
|
||||
|
||||
NetworkConnector.NetworkConnectorResult networkConnectorResult = new NetworkConnector().start(NetworkConnector.Implementation.SBC,
|
||||
authToken, autoDetectedPort, connectorContext);
|
||||
NetworkConnector.NetworkConnectorResult networkConnectorResult = new NetworkConnector().start(NetworkConnector.Implementation.SBC, authToken, autoDetectedPort, connectorContext, new NetworkConnector.ReconnectListener() {
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue