Search in sources :

Example 1 with HttpRequestHeaderMap

use of org.finos.legend.engine.shared.core.operational.opentracing.HttpRequestHeaderMap in project legend-engine by finos.

the class SDLCLoader method loadMetadataFromHTTPURL.

public static PureModelContextData loadMetadataFromHTTPURL(MutableList<CommonProfile> pm, LoggingEventType startEvent, LoggingEventType stopEvent, String url) {
    Scope scope = GlobalTracer.get().scopeManager().active();
    CloseableHttpClient httpclient = (CloseableHttpClient) HttpClientBuilder.getHttpClient(new BasicCookieStore());
    long start = System.currentTimeMillis();
    LogInfo info = new LogInfo(pm, startEvent, "Requesting metadata");
    LOGGER.info(info.toString());
    Span span = GlobalTracer.get().activeSpan();
    if (span != null) {
        span.log(info.eventType + ": " + info.message);
        scope.span().setOperationName(startEvent.toString());
        span.log(url);
    }
    LOGGER.info(new LogInfo(pm, LoggingEventType.METADATA_LOAD_FROM_URL, "Loading from URL " + url).toString());
    HttpGet httpGet = new HttpGet(url);
    if (span != null) {
        GlobalTracer.get().inject(scope.span().context(), HTTP_HEADERS, new HttpRequestHeaderMap(httpGet));
    }
    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode < 200 || statusCode >= 300) {
            throw new EngineException("Error response from " + url + ", HTTP" + statusCode + "\n" + EntityUtils.toString(response.getEntity()));
        }
        HttpEntity entity1 = response.getEntity();
        PureModelContextData modelContextData = objectMapper.readValue(entity1.getContent(), PureModelContextData.class);
        Assert.assertTrue(modelContextData.getSerializer() != null, () -> "Engine was unable to load information from the Pure SDLC <a href='" + url + "'>link</a>");
        LOGGER.info(new LogInfo(pm, stopEvent, (double) System.currentTimeMillis() - start).toString());
        if (span != null) {
            scope.span().log(String.valueOf(stopEvent));
        }
        return modelContextData;
    } catch (Exception e) {
        throw new EngineException("Engine was unable to load information from the Pure SDLC using: <a href='" + url + "' target='_blank'>link</a>", e);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) HttpRequestHeaderMap(org.finos.legend.engine.shared.core.operational.opentracing.HttpRequestHeaderMap) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Span(io.opentracing.Span) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) Scope(io.opentracing.Scope) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)

Aggregations

Scope (io.opentracing.Scope)1 Span (io.opentracing.Span)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)1 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)1 LogInfo (org.finos.legend.engine.shared.core.operational.logs.LogInfo)1 HttpRequestHeaderMap (org.finos.legend.engine.shared.core.operational.opentracing.HttpRequestHeaderMap)1