Skip to content

Commit

Permalink
fix for bug #253
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Sep 9, 2024
1 parent 29a38db commit 63817a2
Showing 1 changed file with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public ResponseEntity<HttpStatus> createConnectorConfiguration(
}
// Remove sensitive data before printing to log
ConnectorSpecification connectorSpecification = connectorRegistry
.getConnectorSpecification(configuration.connectorType);
.getConnectorSpecification(configuration.connectorType);
ConnectorConfiguration clonedConfig = configuration.getCleanedConfig(connectorSpecification);
log.info("Tenant {} - Post Connector configuration: {}", tenant, clonedConfig.toString());
try {
Expand All @@ -186,7 +186,7 @@ public ResponseEntity<List<ConnectorConfiguration>> getConnectionConfigurations(
// Remove sensitive data before sending to UI
for (ConnectorConfiguration config : configurations) {
ConnectorSpecification connectorSpecification = connectorRegistry
.getConnectorSpecification(config.connectorType);
.getConnectorSpecification(config.connectorType);
ConnectorConfiguration cleanedConfig = config.getCleanedConfig(connectorSpecification);
modifiedConfigs.add(cleanedConfig);
}
Expand All @@ -210,14 +210,24 @@ public ResponseEntity<String> deleteConnectionConfiguration(@PathVariable String
try {
ConnectorConfiguration configuration = connectorConfigurationComponent.getConnectorConfiguration(ident,
tenant);
AConnectorClient client = connectorRegistry.getClientForTenant(tenant,
configuration.getIdent());
if (client == null)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Client with ident " + ident + " not found");
client.disconnect();
bootstrapService.shutdownAndRemoveConnector(tenant, client.getConnectorIdent());
if (configuration.enabled)
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body("Can't delete an enabled connector! Disable connector first.");
connectorConfigurationComponent.deleteConnectorConfiguration(ident);
mappingComponent.removeConnectorFromDeploymentMap(tenant, ident);
// NOTE this block was disabled since a disabled connector is not registered in
// connectorRegistry

// AConnectorClient client = connectorRegistry.getClientForTenant(tenant,
// configuration.getIdent());
// if (client == null)
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Client with ident
// " + ident + " not found");
// client.disconnect();
// bootstrapService.shutdownAndRemoveConnector(tenant,
// client.getConnectorIdent());
// connectorConfigurationComponent.deleteConnectorConfiguration(ident);
// mappingComponent.removeConnectorFromDeploymentMap(tenant, ident);
} catch (Exception ex) {
log.error("Tenant {} - Error getting mqtt broker configuration {}", tenant, ex);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, ex.getLocalizedMessage());
Expand All @@ -241,7 +251,7 @@ public ResponseEntity<ConnectorConfiguration> updateConnectionConfiguration(@Pat
}
// Remove sensitive data before printing to log
ConnectorSpecification connectorSpecification = connectorRegistry
.getConnectorSpecification(configuration.connectorType);
.getConnectorSpecification(configuration.connectorType);
ConnectorConfiguration clonedConfig = configuration.getCleanedConfig(connectorSpecification);
log.info("Tenant {} - Post Connector configuration: {}", tenant, clonedConfig.toString());
try {
Expand Down Expand Up @@ -420,8 +430,9 @@ public ResponseEntity<HttpStatus> runOperation(@Valid @RequestBody ServiceOperat
configuration.setEnabled(true);
connectorConfigurationComponent.saveConnectorConfiguration(configuration);

//Initialize Connector only when enabled.
ServiceConfiguration serviceConfiguration = serviceConfigurationComponent.getServiceConfiguration(tenant);
// Initialize Connector only when enabled.
ServiceConfiguration serviceConfiguration = serviceConfigurationComponent
.getServiceConfiguration(tenant);
bootstrapService.initializeConnectorByConfiguration(configuration, serviceConfiguration, tenant);
configurationRegistry.getNotificationSubscriber().notificationSubscriberReconnect(tenant);

Expand All @@ -438,9 +449,9 @@ public ResponseEntity<HttpStatus> runOperation(@Valid @RequestBody ServiceOperat

AConnectorClient client = connectorRegistry.getClientForTenant(tenant,
connectorIdent);
//client.submitDisconnect();
// client.submitDisconnect();
bootstrapService.disableConnector(tenant, client.getConnectorIdent());
//We might need to Reconnect other Notification Clients for other connectors
// We might need to Reconnect other Notification Clients for other connectors
configurationRegistry.getNotificationSubscriber().notificationSubscriberReconnect(tenant);
} else if (operation.getOperation().equals(Operation.REFRESH_STATUS_MAPPING)) {
mappingComponent.sendMappingStatus(tenant);
Expand Down

0 comments on commit 63817a2

Please sign in to comment.