use of org.apache.archiva.components.registry.RegistryException in project archiva by apache.
the class DefaultArchivaConfiguration method handleUpgradeConfiguration.
/**
* Handle upgrade to newer version
*/
private void handleUpgradeConfiguration() throws RegistryException, IndeterminateConfigurationException {
List<String> dbConsumers = Arrays.asList("update-db-artifact", "update-db-repository-metadata");
// remove database consumers if here
List<String> intersec = ListUtils.intersection(dbConsumers, configuration.getRepositoryScanning().getKnownContentConsumers());
if (!intersec.isEmpty()) {
List<String> knowContentConsumers = new ArrayList<>(configuration.getRepositoryScanning().getKnownContentConsumers().size());
for (String knowContentConsumer : configuration.getRepositoryScanning().getKnownContentConsumers()) {
if (!dbConsumers.contains(knowContentConsumer)) {
knowContentConsumers.add(knowContentConsumer);
}
}
configuration.getRepositoryScanning().setKnownContentConsumers(knowContentConsumers);
}
// ensure create-archiva-metadata is here
if (!configuration.getRepositoryScanning().getKnownContentConsumers().contains("create-archiva-metadata")) {
List<String> knowContentConsumers = new ArrayList<>(configuration.getRepositoryScanning().getKnownContentConsumers());
knowContentConsumers.add("create-archiva-metadata");
configuration.getRepositoryScanning().setKnownContentConsumers(knowContentConsumers);
}
// ensure duplicate-artifacts is here
if (!configuration.getRepositoryScanning().getKnownContentConsumers().contains("duplicate-artifacts")) {
List<String> knowContentConsumers = new ArrayList<>(configuration.getRepositoryScanning().getKnownContentConsumers());
knowContentConsumers.add("duplicate-artifacts");
configuration.getRepositoryScanning().setKnownContentConsumers(knowContentConsumers);
}
Registry defaultOnlyConfiguration = readDefaultOnlyConfiguration();
// Currently we check only for configuration version change, not certain version numbers.
if (hasConfigVersionChanged(configuration, defaultOnlyConfiguration)) {
updateCheckPathDefaults(configuration, defaultOnlyConfiguration);
String newVersion = defaultOnlyConfiguration.getString("version");
if (newVersion == null) {
throw new IndeterminateConfigurationException("The default configuration has no version information!");
}
configuration.setVersion(newVersion);
try {
save(configuration);
} catch (IndeterminateConfigurationException e) {
log.error("Error occured during configuration update to new version: {}", e.getMessage());
} catch (RegistryException e) {
log.error("Error occured during configuration update to new version: {}", e.getMessage());
}
}
}
use of org.apache.archiva.components.registry.RegistryException 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.components.registry.RegistryException 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.components.registry.RegistryException 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;
}
use of org.apache.archiva.components.registry.RegistryException in project archiva by apache.
the class RemoteRepositoryHandler method put.
@Override
public RemoteRepository put(RemoteRepositoryConfiguration 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();
RemoteRepository repo = null;
RemoteRepository 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.updateRemoteInstance((EditableRemoteRepository) repo, repositoryConfiguration);
updated = true;
pushEvent(LifecycleEvent.UPDATED, repo);
}
registerNewRepository(repositoryConfiguration, repo, configuration, updated);
} catch (IndeterminateConfigurationException | RegistryException e) {
if (oldRepository != null) {
RemoteRepositoryConfiguration oldCfg = provider.getRemoteConfiguration(oldRepository);
provider.updateRemoteInstance((EditableRemoteRepository) 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;
}
Aggregations