Search in sources :

Example 1 with EndpointViewListing

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);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) MalformedURLException(java.net.MalformedURLException) HttpGet(org.apache.http.client.methods.HttpGet) IndyHttpException(org.commonjava.indy.subsys.http.IndyHttpException) IOException(java.io.IOException) URL(java.net.URL) StatusLine(org.apache.http.StatusLine) EndpointViewListing(org.commonjava.indy.model.core.dto.EndpointViewListing) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 2 with EndpointViewListing

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);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) EndpointView(org.commonjava.indy.model.core.dto.EndpointView) EndpointViewListing(org.commonjava.indy.model.core.dto.EndpointViewListing) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 3 with EndpointViewListing

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;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) EndpointViewListing(org.commonjava.indy.model.core.dto.EndpointViewListing) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

Example 4 with EndpointViewListing

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));
    }
}
Also used : EndpointView(org.commonjava.indy.model.core.dto.EndpointView) EndpointViewListing(org.commonjava.indy.model.core.dto.EndpointViewListing) Test(org.junit.Test)

Aggregations

EndpointViewListing (org.commonjava.indy.model.core.dto.EndpointViewListing)4 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)3 EndpointView (org.commonjava.indy.model.core.dto.EndpointView)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 StatusLine (org.apache.http.StatusLine)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1