Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3003 from Netflix/exception_refactoring
Browse files Browse the repository at this point in the history
ApplicationException.Code is replaced with exception classes for each of the codes.
  • Loading branch information
aravindanr authored Jul 7, 2022
2 parents ddc1bed + 9e1364b commit 35fea12
Show file tree
Hide file tree
Showing 51 changed files with 540 additions and 812 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

import com.netflix.conductor.common.run.ExternalStorageLocation;
import com.netflix.conductor.common.utils.ExternalPayloadStorage;
import com.netflix.conductor.core.exception.ApplicationException;
import com.netflix.conductor.core.exception.NonTransientException;
import com.netflix.conductor.core.exception.TransientException;
import com.netflix.conductor.core.utils.IDGenerator;
import com.netflix.conductor.s3.config.S3Properties;

Expand Down Expand Up @@ -104,11 +105,11 @@ public ExternalStorageLocation getLocation(
"Error communicating with S3 - operation:%s, payloadType: %s, path: %s",
operation, payloadType, path);
LOGGER.error(msg, e);
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e);
throw new TransientException(msg, e);
} catch (URISyntaxException e) {
String msg = "Invalid URI Syntax";
LOGGER.error(msg, e);
throw new ApplicationException(ApplicationException.Code.INTERNAL_ERROR, msg, e);
throw new NonTransientException(msg, e);
}
}

Expand All @@ -135,7 +136,7 @@ public void upload(String path, InputStream payload, long payloadSize) {
String.format(
"Error uploading to S3 - path:%s, payloadSize: %d", path, payloadSize);
LOGGER.error(msg, e);
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e);
throw new TransientException(msg, e);
}
}

Expand All @@ -154,7 +155,7 @@ public InputStream download(String path) {
} catch (SdkClientException e) {
String msg = String.format("Error downloading from S3 - path:%s", path);
LOGGER.error(msg, e);
throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e);
throw new TransientException(msg, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
package com.netflix.conductor.cassandra.dao;

import java.io.IOException;
import java.util.UUID;

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

import com.netflix.conductor.cassandra.config.CassandraProperties;
import com.netflix.conductor.core.exception.NonTransientException;
import com.netflix.conductor.metrics.Monitors;

import com.datastax.driver.core.DataType;
Expand Down Expand Up @@ -110,6 +112,14 @@ public CassandraBaseDAO(
init();
}

protected static UUID toUUID(String uuidString, String message) {
try {
return UUID.fromString(uuidString);
} catch (IllegalArgumentException iae) {
throw new IllegalArgumentException(message + " " + uuidString, iae);
}
}

private void init() {
try {
if (!initialized) {
Expand Down Expand Up @@ -226,15 +236,15 @@ String toJson(Object value) {
try {
return objectMapper.writeValueAsString(value);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
throw new NonTransientException("Error serializing to json", e);
}
}

<T> T readValue(String json, Class<T> clazz) {
try {
return objectMapper.readValue(json, clazz);
} catch (IOException e) {
throw new RuntimeException(e);
throw new NonTransientException("Error de-serializing json", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
import com.netflix.conductor.cassandra.config.CassandraProperties;
import com.netflix.conductor.cassandra.util.Statements;
import com.netflix.conductor.common.metadata.events.EventHandler;
import com.netflix.conductor.core.exception.ApplicationException;
import com.netflix.conductor.core.exception.ApplicationException.Code;
import com.netflix.conductor.core.exception.TransientException;
import com.netflix.conductor.dao.EventHandlerDAO;
import com.netflix.conductor.metrics.Monitors;

import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.exceptions.DriverException;
import com.fasterxml.jackson.databind.ObjectMapper;

import static com.netflix.conductor.cassandra.util.Constants.EVENT_HANDLER_KEY;
Expand Down Expand Up @@ -96,7 +96,7 @@ public void removeEventHandler(String name) {
Monitors.error(CLASS_NAME, "removeEventHandler");
String errorMsg = String.format("Failed to remove event handler: %s", name);
LOGGER.error(errorMsg, e);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
throw new TransientException(errorMsg, e);
}
refreshEventHandlersCache();
}
Expand Down Expand Up @@ -154,11 +154,11 @@ private List<EventHandler> getAllEventHandlersFromDB() {
.map(row -> readValue(row.getString(EVENT_HANDLER_KEY), EventHandler.class))
.collect(Collectors.toList());

} catch (Exception e) {
} catch (DriverException e) {
Monitors.error(CLASS_NAME, "getAllEventHandlersFromDB");
String errorMsg = "Failed to get all event handlers";
LOGGER.error(errorMsg, e);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
throw new TransientException(errorMsg, e);
}
}

Expand All @@ -168,14 +168,14 @@ private void insertOrUpdateEventHandler(EventHandler eventHandler) {
session.execute(insertEventHandlerStatement.bind(eventHandler.getName(), handler));
recordCassandraDaoRequests("storeEventHandler");
recordCassandraDaoPayloadSize("storeEventHandler", handler.length(), "n/a", "n/a");
} catch (Exception e) {
} catch (DriverException e) {
Monitors.error(CLASS_NAME, "insertOrUpdateEventHandler");
String errorMsg =
String.format(
"Error creating/updating event handler: %s/%s",
eventHandler.getName(), eventHandler.getEvent());
LOGGER.error(errorMsg, e);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
throw new TransientException(errorMsg, e);
}
refreshEventHandlersCache();
}
Expand Down
Loading

0 comments on commit 35fea12

Please sign in to comment.