use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.
the class DefaultManagedRepositoryAdmin method addManagedRepository.
@Override
public Boolean addManagedRepository(ManagedRepository managedRepository, boolean needStageRepo, AuditInformation auditInformation) throws RepositoryAdminException {
log.debug("addManagedRepository {}, {}, {}", managedRepository.getId(), needStageRepo, auditInformation);
getRepositoryCommonValidator().basicValidation(managedRepository, false);
getRepositoryCommonValidator().validateManagedRepository(managedRepository);
triggerAuditEvent(managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
ManagedRepositoryConfiguration repoConfig = getRepositoryConfiguration(managedRepository);
if (needStageRepo) {
repoConfig.setStageRepoNeeded(true);
}
Configuration configuration = getArchivaConfiguration().getConfiguration();
try {
org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository(repoConfig, configuration);
log.debug("Added new repository {}", newRepo.getId());
org.apache.archiva.repository.ManagedRepository stagingRepo = null;
addRepositoryRoles(newRepo.getId());
if (newRepo.supportsFeature(StagingRepositoryFeature.class)) {
StagingRepositoryFeature stf = newRepo.getFeature(StagingRepositoryFeature.class).get();
stagingRepo = stf.getStagingRepository();
if (stf.isStageRepoNeeded() && stagingRepo != null) {
addRepositoryRoles(stagingRepo.getId());
triggerAuditEvent(stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
}
}
saveConfiguration(configuration);
// scan repository when adding of repository is successful
try {
if (newRepo.isScanned()) {
scanRepository(newRepo.getId(), true);
}
if (stagingRepo != null && stagingRepo.isScanned()) {
scanRepository(stagingRepo.getId(), true);
}
} catch (Exception e) {
log.warn("Unable to scan repository [{}]: {}", newRepo.getId(), e.getMessage(), e);
}
} catch (RepositoryException e) {
log.error("Could not add managed repository {}" + managedRepository);
throw new RepositoryAdminException("Could not add repository " + e.getMessage());
} catch (RoleManagerException e) {
log.error("Could not add repository roles for repository [{}]: {}", managedRepository.getId(), e.getMessage(), e);
throw new RepositoryAdminException("Could not add roles to repository " + e.getMessage());
}
return Boolean.TRUE;
}
use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.
the class DefaultManagedRepositoryAdmin method updateManagedRepository.
@Override
public Boolean updateManagedRepository(ManagedRepository managedRepository, boolean needStageRepo, AuditInformation auditInformation, boolean resetStats) throws RepositoryAdminException {
log.debug("updateManagedConfiguration repo {} needStage {} resetStats {} ", managedRepository, needStageRepo, resetStats);
// Ensure that the fields are valid.
getRepositoryCommonValidator().basicValidation(managedRepository, true);
getRepositoryCommonValidator().validateManagedRepository(managedRepository);
Configuration configuration = getArchivaConfiguration().getConfiguration();
ManagedRepositoryConfiguration updatedRepoConfig = getRepositoryConfiguration(managedRepository);
updatedRepoConfig.setStageRepoNeeded(needStageRepo);
org.apache.archiva.repository.ManagedRepository oldRepo = repositoryRegistry.getManagedRepository(managedRepository.getId());
boolean stagingExists = false;
if (oldRepo.supportsFeature(StagingRepositoryFeature.class)) {
stagingExists = oldRepo.getFeature(StagingRepositoryFeature.class).get().getStagingRepository() != null;
}
boolean updateIndexContext = !StringUtils.equals(updatedRepoConfig.getIndexDir(), managedRepository.getIndexDirectory());
org.apache.archiva.repository.ManagedRepository newRepo;
// TODO remove content from old if path has changed !!!!!
try {
newRepo = repositoryRegistry.putRepository(updatedRepoConfig, configuration);
if (newRepo.supportsFeature(StagingRepositoryFeature.class)) {
org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature(StagingRepositoryFeature.class).get().getStagingRepository();
if (stagingRepo != null && !stagingExists) {
triggerAuditEvent(stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
addRepositoryRoles(stagingRepo.getId());
}
}
} catch (RepositoryException e) {
log.error("Could not update repository {}: {}", managedRepository.getId(), e.getMessage(), e);
throw new RepositoryAdminException("Could not update repository " + managedRepository.getId());
} catch (RoleManagerException e) {
log.error("Error during role update of stage repo {}", managedRepository.getId(), e);
throw new RepositoryAdminException("Could not update repository " + managedRepository.getId());
}
triggerAuditEvent(managedRepository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO, auditInformation);
try {
getArchivaConfiguration().save(configuration);
} catch (RegistryException | IndeterminateConfigurationException e) {
log.error("Could not save repository configuration: {}", e.getMessage(), e);
throw new RepositoryAdminException("Could not save repository configuration: " + e.getMessage());
}
// Save the repository configuration.
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
try {
if (resetStats) {
log.debug("call repositoryStatisticsManager.deleteStatistics");
getRepositoryStatisticsManager().deleteStatistics(repositorySession.getRepository(), managedRepository.getId());
repositorySession.save();
}
} catch (MetadataRepositoryException e) {
throw new RepositoryAdminException(e.getMessage(), e);
} finally {
repositorySession.close();
}
if (updateIndexContext) {
try {
repositoryRegistry.resetIndexingContext(newRepo);
} catch (IndexUpdateFailedException e) {
e.printStackTrace();
}
}
return true;
}
use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.
the class DefaultProxyConnectorAdmin method addProxyConnector.
@Override
public Boolean addProxyConnector(ProxyConnector proxyConnector, AuditInformation auditInformation) throws RepositoryAdminException {
if (getProxyConnector(proxyConnector.getSourceRepoId(), proxyConnector.getTargetRepoId()) != null) {
throw new RepositoryAdminException("Unable to add proxy connector, as one already exists with source repository id [" + proxyConnector.getSourceRepoId() + "] and target repository id [" + proxyConnector.getTargetRepoId() + "].");
}
validateProxyConnector(proxyConnector);
proxyConnector.setBlackListPatterns(unescapePatterns(proxyConnector.getBlackListPatterns()));
proxyConnector.setWhiteListPatterns(unescapePatterns(proxyConnector.getWhiteListPatterns()));
Configuration configuration = getArchivaConfiguration().getConfiguration();
ProxyConnectorConfiguration proxyConnectorConfiguration = getProxyConnectorConfiguration(proxyConnector);
configuration.addProxyConnector(proxyConnectorConfiguration);
saveConfiguration(configuration);
triggerAuditEvent(proxyConnector.getSourceRepoId() + "-" + proxyConnector.getTargetRepoId(), null, AuditEvent.ADD_PROXY_CONNECTOR, auditInformation);
return Boolean.TRUE;
}
use of org.apache.archiva.admin.model.RepositoryAdminException 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.admin.model.RepositoryAdminException in project archiva by apache.
the class DefaultDownloadRemoteIndexScheduler method scheduleDownloadRemote.
@Override
public void scheduleDownloadRemote(String repositoryId, boolean now, boolean fullDownload) throws DownloadRemoteIndexException {
try {
org.apache.archiva.repository.RemoteRepository remoteRepo = repositoryRegistry.getRemoteRepository(repositoryId);
if (remoteRepo == null) {
log.warn("ignore scheduleDownloadRemote for repo with id {} as not exists", repositoryId);
return;
}
if (!remoteRepo.supportsFeature(RemoteIndexFeature.class)) {
log.warn("ignore scheduleDownloadRemote for repo with id {}. Does not support remote index.", repositoryId);
return;
}
RemoteIndexFeature rif = remoteRepo.getFeature(RemoteIndexFeature.class).get();
NetworkProxy networkProxy = null;
if (StringUtils.isNotBlank(rif.getProxyId())) {
networkProxy = networkProxyAdmin.getNetworkProxy(rif.getProxyId());
if (networkProxy == null) {
log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", rif.getProxyId());
}
}
DownloadRemoteIndexTaskRequest downloadRemoteIndexTaskRequest = //
new DownloadRemoteIndexTaskRequest().setRemoteRepository(//
remoteRepo).setNetworkProxy(//
networkProxy).setFullDownload(//
fullDownload).setWagonFactory(//
wagonFactory).setIndexUpdater(//
indexUpdater).setIndexPacker(this.indexPacker);
if (now) {
log.info("schedule download remote index for repository {}", remoteRepo.getId());
// do it now
taskScheduler.schedule(new DownloadRemoteIndexTask(downloadRemoteIndexTaskRequest, this.runningRemoteDownloadIds), new Date());
} else {
log.info("schedule download remote index for repository {} with cron expression {}", remoteRepo.getId(), remoteRepo.getSchedulingDefinition());
try {
CronTrigger cronTrigger = new CronTrigger(remoteRepo.getSchedulingDefinition());
taskScheduler.schedule(new DownloadRemoteIndexTask(downloadRemoteIndexTaskRequest, this.runningRemoteDownloadIds), cronTrigger);
} catch (IllegalArgumentException e) {
log.warn("Unable to schedule remote index download: {}", e.getLocalizedMessage());
}
if (rif.isDownloadRemoteIndexOnStartup()) {
log.info("remote repository {} configured with downloadRemoteIndexOnStartup schedule now a download", remoteRepo.getId());
taskScheduler.schedule(new DownloadRemoteIndexTask(downloadRemoteIndexTaskRequest, this.runningRemoteDownloadIds), new Date());
}
}
} catch (RepositoryAdminException e) {
log.error(e.getMessage(), e);
throw new DownloadRemoteIndexException(e.getMessage(), e);
}
}
Aggregations