use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class RepositoryServletTest method testGetRepositoryAfterAdd.
@Test
public void testGetRepositoryAfterAdd() throws Exception {
RepositoryServlet servlet = RepositoryServlet.class.cast(findServlet("repository"));
assertNotNull(servlet);
ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
Configuration c = archivaConfiguration.getConfiguration();
ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
repo.setId(NEW_REPOSITORY_ID);
repo.setName(NEW_REPOSITORY_NAME);
Path repoRoot = Paths.get("target/test-repository-root");
if (!Files.exists(repoRoot)) {
Files.createDirectories(repoRoot);
}
repo.setLocation(repoRoot.toAbsolutePath().toString());
c.addManagedRepository(repo);
saveConfiguration(archivaConfiguration);
ManagedRepository repository = servlet.getRepository(NEW_REPOSITORY_ID);
assertNotNull(repository);
assertEquals(NEW_REPOSITORY_NAME, repository.getName());
// check other is still intact
assertRepositoryValid(servlet, REPOID_INTERNAL);
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class RepositoryGroupHandler method put.
/**
* Adds a new repository group to the current list, or replaces the repository group definition with
* the same id, if it exists already.
* The change is saved to the configuration immediately.
*
* @param repositoryGroup the new repository group.
* @throws RepositoryException if the new repository group could not be saved to the configuration.
*/
@Override
public RepositoryGroup put(final RepositoryGroup repositoryGroup) throws RepositoryException {
final String id = repositoryGroup.getId();
RepositoryGroup originRepoGroup = getRepositories().remove(id);
try {
if (originRepoGroup != null && originRepoGroup != repositoryGroup) {
deactivateRepository(originRepoGroup);
pushEvent(new LifecycleEvent(LifecycleEvent.UNREGISTERED, this, originRepoGroup));
}
RepositoryProvider provider = getProvider(repositoryGroup.getType());
RepositoryGroupConfiguration newCfg = provider.getRepositoryGroupConfiguration(repositoryGroup);
ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
configLock.lock();
try {
Configuration configuration = this.getConfigurationHandler().getBaseConfiguration();
updateReferences(repositoryGroup, newCfg);
RepositoryGroupConfiguration oldCfg = configuration.findRepositoryGroupById(id);
if (oldCfg != null) {
configuration.removeRepositoryGroup(oldCfg);
}
configuration.addRepositoryGroup(newCfg);
getConfigurationHandler().save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
setLastState(repositoryGroup, RepositoryState.SAVED);
activateRepository(repositoryGroup);
} finally {
configLock.unlock();
}
getRepositories().put(id, repositoryGroup);
setLastState(repositoryGroup, RepositoryState.REGISTERED);
return repositoryGroup;
} catch (Exception e) {
// Rollback
if (originRepoGroup != null) {
getRepositories().put(id, originRepoGroup);
} 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()), e);
}
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class ManagedRepositoryHandler method put.
@Override
public ManagedRepository put(ManagedRepository repository) throws RepositoryException {
final String id = repository.getId();
ManagedRepository 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());
ManagedRepositoryConfiguration newCfg = provider.getManagedConfiguration(repository);
getConfigurationHandler().getLock().writeLock().lock();
try {
Configuration configuration = getConfigurationHandler().getBaseConfiguration();
updateReferences(repository, newCfg);
ManagedRepositoryConfiguration oldCfg = configuration.findManagedRepositoryById(id);
if (oldCfg != null) {
configuration.removeManagedRepository(oldCfg);
}
configuration.addManagedRepository(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 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.model.Configuration in project archiva by apache.
the class ManagedRepositoryHandler method updateReferences.
@Override
public void updateReferences(ManagedRepository repo, ManagedRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
log.debug("Updating references of repo {}", repo.getId());
if (repo.supportsFeature(StagingRepositoryFeature.class)) {
Configuration configuration = getConfigurationHandler().getBaseConfiguration();
RepositoryProvider provider = getProvider(repo.getType());
StagingRepositoryFeature feature = repo.getFeature(StagingRepositoryFeature.class);
if (feature.isStageRepoNeeded() && feature.getStagingRepository() == null) {
ManagedRepository stageRepo = get(getStagingId(repo.getId()));
if (stageRepo == null) {
stageRepo = getStagingRepository(repo);
getRepositories().put(stageRepo.getId(), stageRepo);
if (configuration != null) {
replaceOrAddRepositoryConfig(provider.getManagedConfiguration(stageRepo), configuration);
}
pushEvent(new LifecycleEvent(LifecycleEvent.REGISTERED, this, stageRepo));
}
feature.setStagingRepository(stageRepo);
}
}
if (repo instanceof EditableManagedRepository) {
EditableManagedRepository editableRepo = (EditableManagedRepository) repo;
if (repo.getContent() == null) {
editableRepo.setContent(repositoryContentFactory.getManagedRepositoryContent(repo));
editableRepo.getContent().setRepository(editableRepo);
}
log.debug("Index repo: " + repo.hasIndex());
if (repo.hasIndex() && (repo.getIndexingContext() == null || !repo.getIndexingContext().isOpen())) {
log.debug("Creating indexing context for {}", repo.getId());
createIndexingContext(editableRepo);
}
}
repo.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
}
Aggregations