use of org.commonjava.indy.model.core.dto.EndpointViewListing 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.model.core.dto.EndpointViewListing in project indy by Commonjava.
the class StatsController method getEndpointsListing.
public EndpointViewListing getEndpointsListing(final String baseUri, final UriFormatter uriFormatter) throws IndyWorkflowException {
final List<ArtifactStore> stores = new ArrayList<ArtifactStore>();
try {
stores.addAll(dataManager.getAllArtifactStores());
} catch (final IndyDataException e) {
throw new IndyWorkflowException(ApplicationStatus.SERVER_ERROR.code(), "Failed to retrieve all endpoints: {}", e, e.getMessage());
}
final List<EndpointView> points = new ArrayList<EndpointView>();
for (final ArtifactStore store : stores) {
final StoreKey key = store.getKey();
final String resourceUri = uriFormatter.formatAbsolutePathTo(baseUri, "content", key.getPackageType(), key.getType().singularEndpointName(), key.getName());
final EndpointView point = new EndpointView(store, resourceUri);
if (!points.contains(point)) {
points.add(point);
}
}
return new EndpointViewListing(points);
}
use of org.commonjava.indy.model.core.dto.EndpointViewListing in project indy by Commonjava.
the class StatsHandler method getAllEndpoints.
@ApiOperation("Retrieve a listing of the artifact stores available on the system. This is especially useful for setting up a network of Indy instances that reference one another")
@ApiResponse(code = 200, response = EndpointViewListing.class, message = "The artifact store listing")
@Path("/all-endpoints")
@GET
@Produces(ApplicationContent.application_json)
public Response getAllEndpoints(@Context final UriInfo uriInfo) {
Response response;
try {
final String baseUri = uriInfo.getBaseUriBuilder().path(IndyDeployment.API_PREFIX).build().toString();
final EndpointViewListing listing = statsController.getEndpointsListing(baseUri, uriFormatter);
response = formatOkResponseWithJsonEntity(listing, objectMapper);
logger.info("\n\n\n\n\n\n{} Sent all-endpoints:\n\n{}\n\n\n\n\n\n\n", new Date(), listing);
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to retrieve endpoint listing: %s", formatEntity(e)), e);
response = formatResponse(e);
}
return response;
}
use of org.commonjava.indy.model.core.dto.EndpointViewListing in project indy by Commonjava.
the class CreateHostedStoreAndVerifyUrlInAllEndpointsTest method verifyHostedStoreUrlsEndpoints.
@Test
public void verifyHostedStoreUrlsEndpoints() throws Exception {
final EndpointViewListing endpoints = client.stats().getAllEndpoints();
for (final EndpointView endpoint : endpoints) {
final String endpointUrl = client.content().contentUrl(endpoint.getStoreKey());
assertThat("Resource URI: '" + endpoint.getResourceUri() + "' for endpoint: " + endpoint.getKey() + " should be: '" + endpointUrl + "'", endpoint.getResourceUri(), equalTo(endpointUrl));
}
}
Aggregations