use of org.apache.archiva.configuration.provider.IndeterminateConfigurationException in project archiva by apache.
the class DefaultRedbackRuntimeConfigurationAdmin method updateRedbackRuntimeConfiguration.
@Override
public void updateRedbackRuntimeConfiguration(RedbackRuntimeConfiguration redbackRuntimeConfiguration) throws RepositoryAdminException {
org.apache.archiva.configuration.model.RedbackRuntimeConfiguration runtimeConfiguration = build(redbackRuntimeConfiguration);
Configuration configuration = archivaConfiguration.getConfiguration();
configuration.setRedbackRuntimeConfiguration(runtimeConfiguration);
try {
archivaConfiguration.save(configuration);
} catch (RegistryException e) {
throw new RepositoryAdminException(e.getMessage(), e);
} catch (IndeterminateConfigurationException e) {
throw new RepositoryAdminException(e.getMessage(), e);
}
}
use of org.apache.archiva.configuration.provider.IndeterminateConfigurationException in project archiva by apache.
the class ManagedRepositoryHandler method put.
@Override
public ManagedRepository put(ManagedRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
final String id = repositoryConfiguration.getId();
final RepositoryType repositoryType = RepositoryType.valueOf(repositoryConfiguration.getType());
final RepositoryProvider provider = getProvider(repositoryType);
ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
configLock.lock();
ManagedRepository repo = null;
ManagedRepository oldRepository = null;
Configuration configuration = null;
try {
boolean updated = false;
configuration = getConfigurationHandler().getBaseConfiguration();
repo = getRepositories().get(id);
oldRepository = repo == null ? null : clone(repo, id);
if (repo == null) {
repo = put(repositoryConfiguration, configuration);
} else {
setRepositoryDefaults(repositoryConfiguration);
provider.updateManagedInstance((EditableManagedRepository) repo, repositoryConfiguration);
updated = true;
pushEvent(LifecycleEvent.UPDATED, repo);
}
registerNewRepository(repositoryConfiguration, repo, configuration, updated);
} catch (IndeterminateConfigurationException | RegistryException e) {
if (oldRepository != null) {
ManagedRepositoryConfiguration oldCfg = provider.getManagedConfiguration(oldRepository);
provider.updateManagedInstance((EditableManagedRepository) repo, oldCfg);
rollback(configuration, oldRepository, e, oldCfg);
} else {
getRepositories().remove(id);
}
log.error("Could not save the configuration for repository {}: {}", id, e.getMessage(), e);
throw new RepositoryException("Could not save the configuration for repository " + id + ": " + e.getMessage());
} finally {
configLock.unlock();
}
return repo;
}
use of org.apache.archiva.configuration.provider.IndeterminateConfigurationException in project archiva by apache.
the class AbstractRepositoryHandler method remove.
/**
* Removes a repository group from the registry and configuration, if it exists.
* The change is saved to the configuration immediately.
*
* @param id the id of the repository group to remove
* @throws RepositoryException if an error occurs during configuration save
*/
@Override
public void remove(String id) throws RepositoryException {
R repo = get(id);
if (repo != null) {
try {
repo = getRepositories().remove(id);
if (repo != null) {
deactivateRepository(repo);
Configuration configuration = this.configurationHandler.getBaseConfiguration();
C cfg = findRepositoryConfiguration(configuration, id);
if (cfg != null) {
removeRepositoryConfiguration(configuration, cfg);
}
this.configurationHandler.save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
setLastState(repo, RepositoryState.UNREGISTERED);
}
} catch (RegistryException | IndeterminateConfigurationException e) {
// Rollback
log.error("Could not save config after repository removal: {}", e.getMessage(), e);
getRepositories().put(repo.getId(), repo);
throw new RepositoryException("Could not save configuration after repository removal: " + e.getMessage());
}
}
}
use of org.apache.archiva.configuration.provider.IndeterminateConfigurationException in project archiva by apache.
the class DefaultArchivaRuntimeConfigurationAdmin method updateArchivaRuntimeConfiguration.
@Override
public void updateArchivaRuntimeConfiguration(ArchivaRuntimeConfiguration archivaRuntimeConfiguration) throws RepositoryAdminException {
Configuration configuration = archivaConfiguration.getConfiguration();
configuration.setArchivaRuntimeConfiguration(build(archivaRuntimeConfiguration));
try {
archivaConfiguration.save(configuration);
} catch (RegistryException e) {
throw new RepositoryAdminException(e.getMessage(), e);
} catch (IndeterminateConfigurationException e) {
throw new RepositoryAdminException(e.getMessage(), e);
}
}
use of org.apache.archiva.configuration.provider.IndeterminateConfigurationException in project archiva by apache.
the class RepositoryGroupHandler method put.
/**
* Adds a new repository group or updates the repository with the same id, if it exists already.
* The configuration is saved immediately.
*
* @param repositoryGroupConfiguration the repository configuration
* @return the updated or created repository
* @throws RepositoryException if an error occurs, or the configuration is not valid.
*/
@Override
public RepositoryGroup put(RepositoryGroupConfiguration repositoryGroupConfiguration) throws RepositoryException {
final String id = repositoryGroupConfiguration.getId();
final RepositoryType repositoryType = RepositoryType.valueOf(repositoryGroupConfiguration.getType());
final RepositoryProvider provider = getProvider(repositoryType);
RepositoryGroup currentRepository;
ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
configLock.lock();
try {
Configuration configuration = this.getConfigurationHandler().getBaseConfiguration();
currentRepository = getRepositories().get(id);
RepositoryGroup oldRepository = currentRepository == null ? null : clone(currentRepository, id);
try {
boolean updated = false;
if (currentRepository == null) {
currentRepository = put(repositoryGroupConfiguration, configuration);
} else {
setRepositoryGroupDefaults(repositoryGroupConfiguration);
provider.updateRepositoryGroupInstance((EditableRepositoryGroup) currentRepository, repositoryGroupConfiguration);
updated = true;
pushEvent(LifecycleEvent.UPDATED, currentRepository);
}
registerNewRepository(repositoryGroupConfiguration, currentRepository, configuration, updated);
} catch (IndeterminateConfigurationException | RegistryException | RepositoryException e) {
// Trying a rollback
if (oldRepository != null) {
RepositoryGroupConfiguration oldCfg = provider.getRepositoryGroupConfiguration(oldRepository);
provider.updateRepositoryGroupInstance((EditableRepositoryGroup) currentRepository, oldCfg);
rollback(configuration, oldRepository, e, oldCfg);
} else {
getRepositories().remove(id);
}
log.error("Could not save the configuration for repository group {}: {}", id, e.getMessage(), e);
if (e instanceof RepositoryException) {
throw (RepositoryException) e;
} else {
throw new RepositoryException("Could not save the configuration for repository group " + id + ": " + e.getMessage());
}
}
} finally {
configLock.unlock();
}
return currentRepository;
}
Aggregations