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);
}
}
Aggregations