Skip to content

Commit

Permalink
Merge pull request #112 from maciej-cz/bugfix/startup-crashloop
Browse files Browse the repository at this point in the history
Avoid crashloop in case of invalid connector
  • Loading branch information
cpoder authored Jul 4, 2024
2 parents 35102aa + d04143f commit 7302caa
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7302caa

Please sign in to comment.