From d04143f56e701984ad37f477d2ca24ca07c359f5 Mon Sep 17 00:00:00 2001 From: Maciej Czarnecki Date: Thu, 4 Jul 2024 09:06:09 +0200 Subject: [PATCH] Avoid crashloop in case of invalid connector --- .../ns/integration/LNSIntegrationService.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/java/lora-ns-ms/src/main/java/lora/ns/integration/LNSIntegrationService.java b/java/lora-ns-ms/src/main/java/lora/ns/integration/LNSIntegrationService.java index 5cbd298d7..fe15d0309 100644 --- a/java/lora-ns-ms/src/main/java/lora/ns/integration/LNSIntegrationService.java +++ b/java/lora-ns-ms/src/main/java/lora/ns/integration/LNSIntegrationService.java @@ -191,15 +191,24 @@ private void init(MicroserviceSubscriptionAddedEvent event) { QueryParam queryParam = new QueryParam(() -> "query", URLEncoder.encode( LNS_TYPE + " eq " + this.getType() + " and type eq '" + LNS_CONNECTOR_TYPE + "'", StandardCharsets.UTF_8)); for (ManagedObjectRepresentation mor : col.get(queryParam).allPages()) { - log.info("Retrieved connector: {} of type {}", mor.getName(), mor.getProperty(LNS_TYPE)); - LNSConnector instance = getInstance(mor); - lnsConnectorManager.addConnector(instance); - lnsGatewayManager.upsertGateways(instance); - configureRoutings(instance.getId(), event.getCredentials()); + try { + initializeConnector(mor, event.getCredentials()); + } catch (Exception e) { + log.warn("Could not initialize connector {}", mor.getName(), e); + } } agentService.registerAgent(this); } + private void initializeConnector(ManagedObjectRepresentation mor, + MicroserviceCredentials credentials) { + log.info("Retrieved connector: {} of type {}", mor.getName(), mor.getProperty(LNS_TYPE)); + LNSConnector instance = getInstance(mor); + lnsConnectorManager.addConnector(instance); + lnsGatewayManager.upsertGateways(instance); + configureRoutings(instance.getId(), credentials); + } + public void mapEventToC8Y(String eventString, String lnsInstanceId) { loraContextService.log("Following message was received from the LNS: {}", eventString); EventRepresentation event = new EventRepresentation();