Merge branch 'fix/server-down' into 'master'
Fix: check if the server is down See merge request sheepitrenderfarm/client!142
This commit is contained in:
@@ -60,6 +60,7 @@ public class Error {
|
|||||||
ERROR_BAD_UPLOAD_RESPONSE(101),
|
ERROR_BAD_UPLOAD_RESPONSE(101),
|
||||||
PATH_INVALID(102),
|
PATH_INVALID(102),
|
||||||
NO_WRITE_PERMISSION(103),
|
NO_WRITE_PERMISSION(103),
|
||||||
|
SERVER_DOWN(104),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
@@ -162,6 +163,8 @@ public class Error {
|
|||||||
return "Corrupt response from the server when trying to upload data. The server might be overloaded or be encountering other issues. Will try again in a few minutes.";
|
return "Corrupt response from the server when trying to upload data. The server might be overloaded or be encountering other issues. Will try again in a few minutes.";
|
||||||
case NETWORK_ISSUE:
|
case NETWORK_ISSUE:
|
||||||
return "Could not connect to the server, please check your connection to the internet.";
|
return "Could not connect to the server, please check your connection to the internet.";
|
||||||
|
case SERVER_DOWN:
|
||||||
|
return "Server is down.";
|
||||||
case TOO_OLD_CLIENT:
|
case TOO_OLD_CLIENT:
|
||||||
return "This client is too old, you need to update it.";
|
return "This client is too old, you need to update it.";
|
||||||
case AUTHENTICATION_FAILED:
|
case AUTHENTICATION_FAILED:
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ public class Server extends Thread {
|
|||||||
|
|
||||||
this.log.debug("Server::getConfiguration url " + remoteURL.build().toString());
|
this.log.debug("Server::getConfiguration url " + remoteURL.build().toString());
|
||||||
|
|
||||||
Response response = this.HTTPRequest(remoteURL, formBody);
|
Response response = this.HTTPRequest(remoteURL, formBody, false);
|
||||||
int r = response.code();
|
int r = response.code();
|
||||||
String contentType = response.body().contentType().toString();
|
String contentType = response.body().contentType().toString();
|
||||||
|
|
||||||
@@ -239,6 +239,10 @@ public class Server extends Thread {
|
|||||||
this.user_config.setPassword(publickey);
|
this.user_config.setPassword(publickey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (r == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||||
|
// most likely the server instance is down but not the frontend proxy (traefik)
|
||||||
|
return Error.Type.SERVER_DOWN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (ConnectException e) {
|
catch (ConnectException e) {
|
||||||
this.log.error("Server::getConfiguration error ConnectException " + e);
|
this.log.error("Server::getConfiguration error ConnectException " + e);
|
||||||
@@ -451,6 +455,34 @@ public class Server extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Response HTTPRequest(HttpUrl.Builder httpUrlBuilder, RequestBody data_, boolean checkIsSuccessful) throws IOException {
|
||||||
|
String url = httpUrlBuilder.build().toString();
|
||||||
|
Request.Builder builder = new Request.Builder().addHeader("User-Agent", HTTP_USER_AGENT).url(url);
|
||||||
|
|
||||||
|
this.log.debug("Server::HTTPRequest url(" + url + ")");
|
||||||
|
|
||||||
|
if (data_ != null) {
|
||||||
|
builder.post(data_);
|
||||||
|
}
|
||||||
|
|
||||||
|
Request request = builder.build();
|
||||||
|
Response response = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
response = httpClient.newCall(request).execute();
|
||||||
|
|
||||||
|
if (checkIsSuccessful && !response.isSuccessful()) {
|
||||||
|
throw new IOException("Unexpected code " + response);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lastRequestTime = new Date().getTime();
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new IOException("Unexpected response from HTTP Stack" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Error.Type HTTPGetFile(String url_, String destination_, Gui gui_, String status_) throws FermeException {
|
public Error.Type HTTPGetFile(String url_, String destination_, Gui gui_, String status_) throws FermeException {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
OutputStream output = null;
|
OutputStream output = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user