use of org.apache.archiva.configuration.model.Configuration 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.configuration.model.Configuration 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;
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class RemoteRepositoryHandler method put.
@Override
public RemoteRepository put(RemoteRepository repository) throws RepositoryException {
final String id = repository.getId();
RemoteRepository originRepo = getRepositories().remove(id);
if (originRepo == null && repositoryHandlerManager.isRegisteredId(id)) {
throw new RepositoryException("There exists a repository with id " + id + ". Could not update with managed repository.");
}
try {
if (originRepo != null && repository != originRepo) {
deactivateRepository(originRepo);
pushEvent(LifecycleEvent.UNREGISTERED, originRepo);
}
RepositoryProvider provider = getProvider(repository.getType());
RemoteRepositoryConfiguration newCfg = provider.getRemoteConfiguration(repository);
getConfigurationHandler().getLock().writeLock().lock();
try {
Configuration configuration = getConfigurationHandler().getBaseConfiguration();
updateReferences(repository, newCfg);
RemoteRepositoryConfiguration oldCfg = configuration.findRemoteRepositoryById(id);
if (oldCfg != null) {
configuration.removeRemoteRepository(oldCfg);
}
configuration.addRemoteRepository(newCfg);
getConfigurationHandler().save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
setLastState(repository, RepositoryState.SAVED);
activateRepository(repository);
} finally {
getConfigurationHandler().getLock().writeLock().unlock();
}
getRepositories().put(id, repository);
setLastState(repository, RepositoryState.REGISTERED);
return repository;
} catch (Exception e) {
// Rollback only partly, because repository is closed already
if (originRepo != null) {
getRepositories().put(id, originRepo);
} else {
getRepositories().remove(id);
}
log.error("Exception during configuration update {}", e.getMessage(), e);
throw new RepositoryException("Could not save the configuration" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
}
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class ArchivaRepositoryRegistryTest method removeRemoteRepositoryWithoutSave.
@Test
public void removeRemoteRepositoryWithoutSave() throws Exception {
Configuration configuration = archivaConfiguration.getConfiguration();
assertEquals(1, repositoryRegistry.getRemoteRepositories().size());
RemoteRepository repo = repositoryRegistry.getRemoteRepository("central");
repositoryRegistry.removeRepository(repo, configuration);
assertEquals(0, repositoryRegistry.getRemoteRepositories().size());
assertTrue(repositoryRegistry.getRemoteRepositories().stream().noneMatch(rep -> rep.getId().equals("central")));
archivaConfiguration.reload();
repositoryRegistry.reload();
assertEquals(1, repositoryRegistry.getRemoteRepositories().size());
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class ArchivaRepositoryRegistryTest method putRemoteRepositoryFromConfigWithoutSave.
@Test
public void putRemoteRepositoryFromConfigWithoutSave() throws Exception {
Configuration configuration = archivaConfiguration.getConfiguration();
RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
Configuration newConfiguration = new Configuration();
cfg.setId("test002");
cfg.setName("This is test 002");
RemoteRepository repo = repositoryRegistry.putRepository(cfg, newConfiguration);
assertNotNull(repo);
assertEquals("test002", repo.getId());
assertEquals("This is test 002", repo.getName());
assertNotNull(repo.getContent());
archivaConfiguration.reload();
assertEquals(1, archivaConfiguration.getConfiguration().getRemoteRepositories().size());
Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories();
assertEquals(1, repos.size());
assertEquals(1, newConfiguration.getRemoteRepositories().size());
RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository("central");
cfg = new RemoteRepositoryConfiguration();
cfg.setId("central");
cfg.setName("This is central test 002");
repo = repositoryRegistry.putRepository(cfg, newConfiguration);
assertEquals("This is central test 002", repo.getName());
assertEquals(2, newConfiguration.getRemoteRepositories().size());
repositoryRegistry.reload();
assertEquals(1, repositoryRegistry.getRemoteRepositories().size());
}
Aggregations