Skip to content

Commit

Permalink
fix(core.configuration): delete Configuration from ConfigurationAdmin
Browse files Browse the repository at this point in the history
Signed-off-by: Marcello Martina <[email protected]>
  • Loading branch information
marcellorinaldo authored and salvatore-coppola committed Apr 15, 2024
1 parent 2bc2cc3 commit e996ec1
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ protected void removeConfigurableComponent(final ServiceReference<ConfigurableCo

final String kuraPid = makeString(reference.getProperty(ConfigurationService.KURA_SERVICE_PID));

deleteConfigurationFromConfigAdminInternal(kuraPid);
unregisterComponentConfiguration(kuraPid);
}

Expand All @@ -285,8 +286,8 @@ protected void removeSelfConfiguringComponent(final ServiceReference<SelfConfigu

final String kuraPid = makeString(reference.getProperty(ConfigurationService.KURA_SERVICE_PID));

deleteConfigurationFromConfigAdminInternal(kuraPid);
unregisterComponentConfiguration(kuraPid);

}

protected void deactivate(ComponentContext componentContext) {
Expand Down Expand Up @@ -422,7 +423,7 @@ public synchronized void createFactoryConfiguration(String factoryPid, String pi
boolean takeSnapshot) throws KuraException {
if (pid == null) {
throw new KuraException(KuraErrorCode.INVALID_PARAMETER, "pid cannot be null");
} else if (this.servicePidByPid.containsKey(pid)) {
} else if (this.servicePidByPid.containsKey(pid) || this.allActivatedPids.contains(pid)) {
throw new KuraException(KuraErrorCode.INVALID_PARAMETER, "pid " + pid + " already exists");
}

Expand Down Expand Up @@ -856,6 +857,27 @@ private synchronized void updateConfigurationsInternal(List<ComponentConfigurati
}
}

private synchronized void deleteConfigurationFromConfigAdminInternal(String kuraServicePid) {
try {
final Configuration[] configurations = this.configurationAdmin.listConfigurations(null);

final Optional<Configuration> configuration = Arrays.stream(configurations).filter(c -> {
final String pid = (String) c.getProperties().get(KURA_SERVICE_PID);
return pid.equals(kuraServicePid);
}).findAny();

if (!configuration.isPresent()) {
logger.warn("The component with kura.service.pid '{}' does not exist", kuraServicePid);
} else {
logger.info("Deleting factory configuration for component with kura.service.pid '{}'",
kuraServicePid);
configuration.get().delete();
}
} catch (Exception e) {
logger.error("Error deleting configuration for component with kura.service.pid '{}'", kuraServicePid, e);
}
}

// returns configurations with encrypted passwords
private List<ComponentConfiguration> getComponentConfigurationsInternal() throws KuraException {
List<ComponentConfiguration> configs = new ArrayList<>();
Expand Down

0 comments on commit e996ec1

Please sign in to comment.