use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class ReplicationController method getRemoteStores.
// FIXME: Find a better solution to the passed-in generic deserialization problem...erasure is a mother...
private List<? extends ArtifactStore> getRemoteStores(final ReplicationDTO dto) throws IndyWorkflowException {
final String apiUrl = dto.getApiUrl();
String remotesUrl = null;
String groupsUrl = null;
String hostedUrl = null;
try {
remotesUrl = buildUrl(apiUrl, "/admin/remotes");
groupsUrl = buildUrl(apiUrl, "/admin/groups");
hostedUrl = buildUrl(apiUrl, "/admin/hosted");
} catch (final MalformedURLException e) {
throw new IndyWorkflowException("Failed to construct store definition-retrieval URL from api-base: {}. Reason: {}", e, apiUrl, e.getMessage());
}
// logger.info( "\n\n\n\n\n[AutoProx] Checking URL: {} from:", new Throwable(), url );
final List<ArtifactStore> result = new ArrayList<ArtifactStore>();
addStoresFrom(result, remotesUrl, dto, RemoteRepository.class);
addStoresFrom(result, groupsUrl, dto, Group.class);
addStoresFrom(result, hostedUrl, dto, HostedRepository.class);
return result;
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class ReplicationController method replicate.
public Set<StoreKey> replicate(final ReplicationDTO dto, final String user) throws IndyWorkflowException {
final ReplicationRepositoryCreator creator = createRepoCreator();
if (creator == null) {
throw new IndyWorkflowException(500, "Cannot replicate; ReplicationRepositoryCreator could not be instantiated.");
}
try {
dto.validate();
} catch (final IndyException e) {
throw new IndyWorkflowException("Invalid replication request DTO: %s", e, e.getMessage());
}
List<? extends ArtifactStore> remoteStores = null;
List<EndpointView> remoteEndpoints = null;
final boolean overwrite = dto.isOverwrite();
final Set<StoreKey> replicated = new HashSet<StoreKey>();
for (final ReplicationAction action : dto) {
if (action == null) {
continue;
}
logger.info("Processing replication action:\n\n {}\n\nin DTO: {}\n\n", action, dto);
final String include = action.getInclude();
final String exclude = action.getExclude();
try {
if (action.getType() == ActionType.PROXY) {
if (remoteEndpoints == null) {
remoteEndpoints = getEndpoints(dto);
}
for (final EndpointView view : remoteEndpoints) {
final String key = "remote-" + view.getType() + "_" + view.getName();
if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
final StoreKey sk = new StoreKey(StoreType.remote, key);
if (overwrite || !data.hasArtifactStore(sk)) {
RemoteRepository repo = creator.createRemoteRepository(key, view);
repo.setMetadata(ArtifactStore.METADATA_ORIGIN, REPLICATION_ORIGIN);
setProxyAttributes(repo, action);
data.storeArtifactStore(repo, new ChangeSummary(user, "REPLICATION: Proxying remote indy repository: " + view.getResourceUri()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
replicated.add(repo.getKey());
}
}
}
} else if (action.getType() == ActionType.MIRROR) {
if (remoteStores == null) {
remoteStores = getRemoteStores(dto);
}
for (final ArtifactStore store : remoteStores) {
final String key = store.getKey().toString();
if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
if (overwrite || !data.hasArtifactStore(store.getKey())) {
if (store instanceof RemoteRepository) {
setProxyAttributes(((RemoteRepository) store), action);
}
data.storeArtifactStore(store, new ChangeSummary(user, "REPLICATION: Mirroring remote indy store: " + store.getKey()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
replicated.add(store.getKey());
}
}
}
}
} catch (final IndyDataException e) {
logger.error(e.getMessage(), e);
throw new IndyWorkflowException(e.getMessage(), e);
}
}
return replicated;
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class ContentController method rescanAll.
public void rescanAll(final EventMetadata eventMetadata) throws IndyWorkflowException {
try {
final List<ArtifactStore> stores = storeManager.query().concreteStores().getAll();
contentManager.rescanAll(stores, eventMetadata);
} catch (final IndyDataException e) {
throw new IndyWorkflowException(ApplicationStatus.SERVER_ERROR.code(), "Failed to retrieve list of concrete stores. Reason: {}", e, e.getMessage());
}
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class DefaultDownloadManager method store.
/*
* (non-Javadoc)
* @see org.commonjava.indy.core.rest.util.FileManager#upload(java.util.List, java.lang.String,
* java.io.InputStream)
*/
@Override
public Transfer store(final List<? extends ArtifactStore> stores, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
final ContentQuality quality = getQuality(path);
HostedRepository selected = null;
for (final ArtifactStore store : stores) {
if (storeManager.isReadonly(store)) {
logger.info("The store {} is readonly, store operation not allowed");
continue;
}
if (storeIsSuitableFor(store, quality, op)) {
selected = (HostedRepository) store;
break;
}
}
if (selected == null) {
logger.warn("Cannot deploy. No valid deploy points in group.");
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "No deployment locations available.");
}
logger.info("Storing: {} in selected: {} with event metadata: {}", path, selected, eventMetadata);
store(selected, path, stream, op, eventMetadata);
return getStorageReference(selected.getKey(), path);
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class DefaultContentManager method retrieveAll.
@Override
public List<Transfer> retrieveAll(final List<? extends ArtifactStore> stores, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
final List<Transfer> txfrs = new ArrayList<>();
for (final ArtifactStore store : stores) {
if (group == store.getKey().getType()) {
List<ArtifactStore> members;
try {
members = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
}
final List<Transfer> storeTransfers = new ArrayList<>();
for (final ContentGenerator generator : contentGenerators) {
final Transfer txfr = generator.generateGroupFileContent((Group) store, members, path, eventMetadata);
if (txfr != null) {
storeTransfers.add(txfr);
}
}
// ...if it's generated, it's merged in this case.
if (storeTransfers.isEmpty()) {
for (final ArtifactStore member : members) {
// NOTE: This is only safe to call because we're concrete ordered stores, so anything passing through here is concrete.
final Transfer txfr = doRetrieve(member, path, eventMetadata);
if (txfr != null) {
storeTransfers.add(txfr);
}
}
}
txfrs.addAll(storeTransfers);
} else {
// NOTE: This is only safe to call because we're doing the group check up front, so anything passing through here is concrete.
final Transfer txfr = doRetrieve(store, path, eventMetadata);
if (txfr != null) {
txfrs.add(txfr);
}
}
}
return txfrs;
}
Aggregations