Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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