Skip to content

Commit

Permalink
🐛 Refactor error handling in PolyglotDeployer to catch specific excep…
Browse files Browse the repository at this point in the history
…tions and improve deployment timeout management
  • Loading branch information
mkjsix committed Nov 21, 2024
1 parent b8df225 commit dd85fa7
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

import static org.fusesource.jansi.Ansi.Color.GREEN;
Expand Down Expand Up @@ -64,7 +66,9 @@

import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import com.google.gson.JsonIOException;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.mongodb.client.MongoClient;

/**
Expand Down Expand Up @@ -140,7 +144,7 @@ private void deployAll(Path pluginsDirectory) {
var nodeServices = findNodeServices(pluginPath);
var interceptors = findInterceptors(pluginPath);
deploy(services, nodeServices, interceptors);
} catch (Throwable t) {
} catch (IOException | InterruptedException t) {
LOGGER.error("Error deploying {}", pluginPath.toAbsolutePath(), t);
}
}
Expand Down Expand Up @@ -340,7 +344,7 @@ private List<Path> findDeclaredPlugins(Path path, String prop, boolean checkPlug
} else {
return Lists.newArrayList();
}
} catch (Throwable t) {
} catch (JsonIOException | JsonSyntaxException | IOException t) {
LOGGER.error("Error reading {}", packagePath, t);
return Lists.newArrayList();
}
Expand Down Expand Up @@ -401,11 +405,7 @@ private void deployNodeService(Path pluginPath) throws IOException {
try {
var srvf = NodeService.get(pluginPath, this.mclient, this.config);

while (!srvf.isDone()) {
Thread.sleep(300);
}

var srv = srvf.get();
var srv = srvf.get(30, TimeUnit.SECONDS);

var record = new PluginRecord<Service<? extends ServiceRequest<?>, ? extends ServiceResponse<?>>>(srv.name(), "description", srv.secured(), true, srv.getClass().getName(), srv, new HashMap<>());

Expand All @@ -414,7 +414,7 @@ var record = new PluginRecord<Service<? extends ServiceRequest<?>, ? extends Ser
DEPLOYEES.put(pluginPath.toAbsolutePath(), srv);

LOGGER.info(ansi().fg(GREEN).a("Service '{}' deployed at URI '{}' with description: '{}'. Secured: {}. Uri match policy: {}").reset().toString(), srv.name(), srv.uri(), srv.getDescription(), srv.secured(), srv.matchPolicy());
} catch (IOException | InterruptedException | ExecutionException ex) {
} catch (IOException | InterruptedException | ExecutionException | TimeoutException ex) {
LOGGER.error("Error deploying node service {}", pluginPath, ex);
Thread.currentThread().interrupt();
executor.shutdownNow();
Expand Down

0 comments on commit dd85fa7

Please sign in to comment.