@@ -259,6 +259,7 @@ protected void removeConfigurableComponent(final ServiceReference<ConfigurableCo
259259
260260 final String kuraPid = makeString (reference .getProperty (ConfigurationService .KURA_SERVICE_PID ));
261261
262+ deleteConfigurationFromConfigAdminInternal (kuraPid );
262263 unregisterComponentConfiguration (kuraPid );
263264 }
264265
@@ -285,8 +286,8 @@ protected void removeSelfConfiguringComponent(final ServiceReference<SelfConfigu
285286
286287 final String kuraPid = makeString (reference .getProperty (ConfigurationService .KURA_SERVICE_PID ));
287288
289+ deleteConfigurationFromConfigAdminInternal (kuraPid );
288290 unregisterComponentConfiguration (kuraPid );
289-
290291 }
291292
292293 protected void deactivate (ComponentContext componentContext ) {
@@ -422,7 +423,7 @@ public synchronized void createFactoryConfiguration(String factoryPid, String pi
422423 boolean takeSnapshot ) throws KuraException {
423424 if (pid == null ) {
424425 throw new KuraException (KuraErrorCode .INVALID_PARAMETER , "pid cannot be null" );
425- } else if (this .servicePidByPid .containsKey (pid )) {
426+ } else if (this .servicePidByPid .containsKey (pid ) || this . allActivatedPids . contains ( pid ) ) {
426427 throw new KuraException (KuraErrorCode .INVALID_PARAMETER , "pid " + pid + " already exists" );
427428 }
428429
@@ -856,6 +857,27 @@ private synchronized void updateConfigurationsInternal(List<ComponentConfigurati
856857 }
857858 }
858859
860+ private synchronized void deleteConfigurationFromConfigAdminInternal (String kuraServicePid ) {
861+ try {
862+ final Configuration [] configurations = this .configurationAdmin .listConfigurations (null );
863+
864+ final Optional <Configuration > configuration = Arrays .stream (configurations ).filter (c -> {
865+ final String pid = (String ) c .getProperties ().get (KURA_SERVICE_PID );
866+ return pid .equals (kuraServicePid );
867+ }).findAny ();
868+
869+ if (!configuration .isPresent ()) {
870+ logger .warn ("The component with kura.service.pid '{}' does not exist" , kuraServicePid );
871+ } else {
872+ logger .info ("Deleting factory configuration for component with kura.service.pid '{}'" ,
873+ kuraServicePid );
874+ configuration .get ().delete ();
875+ }
876+ } catch (Exception e ) {
877+ logger .error ("Error deleting configuration for component with kura.service.pid '{}'" , kuraServicePid , e );
878+ }
879+ }
880+
859881 // returns configurations with encrypted passwords
860882 private List <ComponentConfiguration > getComponentConfigurationsInternal () throws KuraException {
861883 List <ComponentConfiguration > configs = new ArrayList <>();
0 commit comments