Skip to content

Commit

Permalink
Merge pull request #4330 from atlanhq/APP-5713
Browse files Browse the repository at this point in the history
APP-5713 Added new Error code for service unavailable
  • Loading branch information
pavanmanishd authored Mar 4, 2025
2 parents 89e4587 + 57618f7 commit 7c40f76
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -180,6 +182,9 @@ private DirectIndexQueryResult runQueryWithLowLevelClient(SearchParams searchPar
}
} catch (IOException e) {
LOG.error("Failed to execute direct query on ES {}", e.getMessage());

handleNetworkErrors(e);

throw new AtlasBaseException(AtlasErrorCode.INDEX_SEARCH_FAILED, e.getMessage());
}
}
Expand Down Expand Up @@ -207,6 +212,9 @@ private Map<String, Object> runQueryWithLowLevelClient(String query) throws Atla

} catch (IOException e) {
LOG.error("Failed to execute direct query on ES {}", e.getMessage());

handleNetworkErrors(e);

throw new AtlasBaseException(AtlasErrorCode.INDEX_SEARCH_FAILED, e.getMessage());
}
}
Expand All @@ -220,6 +228,9 @@ private Map<String, LinkedHashMap> runUpdateByQueryWithLowLevelClient(String que

} catch (IOException e) {
LOG.error("Failed to execute direct query on ES {}", e.getMessage());

handleNetworkErrors(e);

throw new AtlasBaseException(AtlasErrorCode.INDEX_SEARCH_FAILED, e.getMessage());
}
}
Expand Down Expand Up @@ -271,6 +282,11 @@ private DirectIndexQueryResult performAsyncDirectIndexQuery(SearchParams searchP
}
}catch (Exception e) {
LOG.error("Failed to execute direct query on ES {}", e.getMessage());

if (e instanceof IOException) {
handleNetworkErrors((IOException) e);
}

throw new AtlasBaseException(AtlasErrorCode.INDEX_SEARCH_FAILED, e.getMessage());
} finally {
if (contextIdExists) {
Expand All @@ -286,6 +302,20 @@ private DirectIndexQueryResult performAsyncDirectIndexQuery(SearchParams searchP
return result;
}

/*
* Checks if the exception is a network-related issue and throws a SERVICE_UNAVAILABLE error.
*/
private void handleNetworkErrors(Exception e) throws AtlasBaseException {
if (e instanceof SocketTimeoutException || e instanceof UnknownHostException ||
(e.getMessage() != null &&
(e.getMessage().contains("Connection reset by peer") ||
e.getMessage().contains("Network error") ||
e.getMessage().contains("Connection refused")))) {
throw new AtlasBaseException(AtlasErrorCode.SERVICE_UNAVAILABLE,
"Service is unavailable or a network error occurred: Elasticsearch - " + e.getMessage());
}
}

/*
* Process the request with the same search context ID and sequence number
* @param searchParams
Expand Down
1 change: 1 addition & 0 deletions intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public enum AtlasErrorCode {
KEYCLOAK_INIT_FAILED(500, "ATLAS-500-00-022", "Failed to initialize keycloak client: {0}"),

MAINTENANCE_MODE_ENABLED(503, "ATLAS-503-00-001", "Atlas is in maintenance mode for this specific operation. Please try again later."),
SERVICE_UNAVAILABLE(503, "ATLAS-503-00-002", "Service is unavailable or a network error occurred: {0}"),

BATCH_SIZE_TOO_LARGE(406, "ATLAS-406-00-001", "Batch size is too large, please use a smaller batch size"),

Expand Down

0 comments on commit 7c40f76

Please sign in to comment.