use of org.eclipse.kura.KuraPartialSuccessException in project kura by eclipse.
the class ConfigurationServiceImpl method updateConfigurationsInternal.
// ----------------------------------------------------------------
//
// Private APIs
//
// ----------------------------------------------------------------
private synchronized void updateConfigurationsInternal(List<ComponentConfiguration> configsToUpdate, boolean takeSnapshot) throws KuraException {
boolean snapshotOnConfirmation = false;
List<Throwable> causes = new ArrayList<Throwable>();
List<ComponentConfiguration> configs = buildCurrentConfiguration(configsToUpdate);
for (ComponentConfiguration config : configs) {
for (ComponentConfiguration configToUpdate : configsToUpdate) {
if (config.getPid().equals(configToUpdate.getPid())) {
try {
updateConfigurationInternal(config.getPid(), config.getConfigurationProperties(), snapshotOnConfirmation);
break;
} catch (KuraException e) {
s_logger.warn("Error during updateConfigurations for component " + config.getPid(), e);
causes.add(e);
}
}
}
}
if (takeSnapshot && configs != null && !configs.isEmpty()) {
saveSnapshot(configs);
}
if (!causes.isEmpty()) {
throw new KuraPartialSuccessException("updateConfigurations", causes);
}
}
use of org.eclipse.kura.KuraPartialSuccessException in project kura by eclipse.
the class ConfigurationServiceImpl method rollback.
@Override
public synchronized void rollback(long id) throws KuraException {
// load the snapshot we need to rollback to
XmlComponentConfigurations xmlConfigs = loadEncryptedSnapshotFileContent(id);
//
// restore configuration
s_logger.info("Rolling back to snapshot {}...", id);
Set<String> snapshotPids = new HashSet<String>();
boolean snapshotOnConfirmation = false;
List<Throwable> causes = new ArrayList<Throwable>();
List<ComponentConfigurationImpl> configs = xmlConfigs.getConfigurations();
for (ComponentConfigurationImpl config : configs) {
if (config != null) {
try {
rollbackConfigurationInternal(config.getPid(), config.getConfigurationProperties(), snapshotOnConfirmation);
} catch (Throwable t) {
s_logger.warn("Error during rollback for component " + config.getPid(), t);
causes.add(t);
}
// Track the pid of the component
snapshotPids.add(config.getPid());
}
}
// rollback to the default configuration for those configurable
// components
// whose configuration is not present in the snapshot
Set<String> pids = new HashSet<String>(this.m_allActivatedPids);
pids.removeAll(this.m_activatedSelfConfigComponents);
pids.removeAll(snapshotPids);
for (String pid : pids) {
s_logger.info("Rolling back to default configuration for component pid: '{}'", pid);
try {
ServiceReference<?>[] refs = this.m_ctx.getBundleContext().getServiceReferences((String) null, null);
if (refs != null) {
for (ServiceReference<?> ref : refs) {
String ppid = (String) ref.getProperty(Constants.SERVICE_PID);
if (pid.equals(ppid)) {
Bundle bundle = ref.getBundle();
try {
OCD ocd = ComponentUtil.readObjectClassDefinition(bundle, pid);
Map<String, Object> defaults = ComponentUtil.getDefaultProperties(ocd, this.m_ctx);
rollbackConfigurationInternal(pid, defaults, snapshotOnConfirmation);
} catch (Throwable t) {
s_logger.warn("Error during rollback for component " + pid, t);
causes.add(t);
}
}
}
}
} catch (InvalidSyntaxException e) {
s_logger.warn("Error during rollback for component " + pid, e);
}
}
if (!causes.isEmpty()) {
throw new KuraPartialSuccessException("Rollback", causes);
}
// Do not call snapshot() here because it gets the configurations of
// SelfConfiguringComponents
// using SelfConfiguringComponent.getConfiguration() and the
// configuration returned
// might be the old one not the one just loaded from the snapshot and
// updated through
// the Configuration Admin. Instead just make a copy of the snapshot.
saveSnapshot(configs);
}
Aggregations