use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class ReplicationController method getEndpoints.
private List<EndpointView> getEndpoints(final ReplicationDTO dto) throws IndyWorkflowException {
final String apiUrl = dto.getApiUrl();
String url = null;
try {
url = buildUrl(apiUrl, "/stats/all-endpoints");
} catch (final MalformedURLException e) {
throw new IndyWorkflowException("Failed to construct endpoint-retrieval URL from api-base: {}. Reason: {}", e, apiUrl, e.getMessage());
}
final HttpGet req = newGet(url, dto);
CloseableHttpClient client = null;
try {
String siteId = new URL(url).getHost();
client = http.createClient(siteId);
CloseableHttpResponse response = client.execute(req, http.createContext(siteId));
final StatusLine statusLine = response.getStatusLine();
final int status = statusLine.getStatusCode();
if (status == HttpStatus.SC_OK) {
final String json = HttpResources.entityToString(response);
final EndpointViewListing listing = serializer.readValue(json, EndpointViewListing.class);
return listing.getItems();
}
throw new IndyWorkflowException(status, "Endpoint request failed: {}", statusLine);
} catch (final IOException | IndyHttpException e) {
throw new IndyWorkflowException("Failed to retrieve endpoints from: {}. Reason: {}", e, url, e.getMessage());
} finally {
IOUtils.closeQuietly(client);
}
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class DefaultContentManager method exists.
@Override
public // TODO: to add content generation handling here, for things like merged metadata, checksum files, etc.
boolean exists(ArtifactStore store, String path) throws IndyWorkflowException {
if (!checkMask(store, path)) {
return false;
}
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Checking existence of: {} in: {}", path, store.getKey());
if (store instanceof Group) {
try {
final List<ArtifactStore> allMembers = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
logger.debug("Trying to retrieve suitable transfer for: {} in group: {} members:\n{}", path, allMembers, store.getName());
for (ArtifactStore member : allMembers) {
if (exists(member, path)) {
return true;
}
}
return false;
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
}
} else {
return downloadManager.exists(store, path);
}
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class DefaultDirectContentAccess method retrieveAllRaw.
@Override
public List<Transfer> retrieveAllRaw(final List<? extends ArtifactStore> stores, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
Map<ArtifactStore, Future<Transfer>> futures = new HashMap<>();
for (final ArtifactStore store : stores) {
logger.debug("Requesting retrieval of {} in {}", path, store);
Future<Transfer> future = executorService.submit(() -> {
logger.trace("Retrieving {} in {}", path, store);
Transfer txfr = retrieveRaw(store, path, eventMetadata);
logger.trace("Transfer {} in {} retrieved", path, store);
return txfr;
});
futures.put(store, future);
}
final List<Transfer> txfrs = new ArrayList<>(stores.size());
for (ArtifactStore store : stores) {
Transfer txfr;
try {
logger.trace("Waiting for transfer of {} in {}", path, store);
Future<Transfer> future = futures.get(store);
txfr = future.get();
logger.debug("Transfer {} in {} retrieved", path, store);
} catch (InterruptedException ex) {
throw new IndyWorkflowException("Retrieval of %s in %s was interrupted", ex, path, store);
} catch (ExecutionException ex) {
throw new IndyWorkflowException("Error retrieving %s from %s: %s", ex, path, store, ex);
}
if (txfr != null) {
txfrs.add(txfr);
}
}
return txfrs;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class DefaultDownloadManager method list.
@Override
public List<StoreResource> list(final List<? extends ArtifactStore> stores, final String path) throws IndyWorkflowException {
final String dir = PathUtils.dirname(path);
final List<StoreResource> result = new ArrayList<>();
try {
final List<ListingResult> results = transfers.listAll(locationExpander.expand(new VirtualResource(LocationUtils.toLocations(stores), path)));
for (final ListingResult lr : results) {
if (lr != null && lr.getListing() != null) {
for (final String file : lr.getListing()) {
result.add(new StoreResource((KeyedLocation) lr.getLocation(), dir, file));
}
}
}
} catch (final BadGatewayException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Bad gateway: " + e.getMessage(), e);
} catch (final TransferTimeoutException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Timeout: " + e.getMessage(), e);
} catch (final TransferLocationException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Location Error: " + e.getMessage(), e);
} catch (final TransferException e) {
logger.error(e.getMessage(), e);
throw new IndyWorkflowException("Failed to list ALL paths: {} from: {}. Reason: {}", e, path, stores, e.getMessage());
}
return dedupeListing(result);
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class DefaultDownloadManager method getStorageReference.
@Override
public Transfer getStorageReference(final List<ArtifactStore> stores, final String path, final TransferOperation op) throws IndyWorkflowException {
// final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
final ContentQuality quality = getQuality(path);
Transfer transfer = null;
logger.debug("Checking {} stores to find one suitable for {} of: {}", stores.size(), op, path);
boolean suitableFound = false;
for (final ArtifactStore store : stores) {
if (storeIsSuitableFor(store, quality, op)) {
suitableFound = true;
logger.info("Attempting to retrieve storage reference in: {} for: {} (operation: {})", store, path, op);
transfer = getStorageReference(store, path);
logger.debug("Checking {} (exists? {}; file: {})", transfer, transfer != null && transfer.exists(), transfer == null ? "NONE" : transfer.getFullPath());
if (transfer != null && !transfer.exists() && (op == TransferOperation.DOWNLOAD || op == TransferOperation.LISTING)) {
transfer = null;
}
if (transfer != null) {
logger.info("Using transfer: {}", transfer);
break;
}
}
}
if (!stores.isEmpty() && !suitableFound) {
logger.warn("No suitable stores in list.");
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "No suitable store available.");
}
return transfer;
}
Aggregations