use of com.azure.core.http.HttpRequest in project ApplicationInsights-Java by microsoft.
the class QuickPulseDataFetcher method prepareQuickPulseDataForSend.
public void prepareQuickPulseDataForSend(String redirectedEndpoint) {
try {
QuickPulseDataCollector.FinalCounters counters = QuickPulseDataCollector.INSTANCE.getAndRestart();
Date currentDate = new Date();
String endpointPrefix = Strings.isNullOrEmpty(redirectedEndpoint) ? getQuickPulseEndpoint() : redirectedEndpoint;
HttpRequest request = networkHelper.buildRequest(currentDate, this.getEndpointUrl(endpointPrefix));
request.setBody(buildPostEntity(counters));
if (!sendQueue.offer(request)) {
logger.trace("Quick Pulse send queue is full");
}
} catch (ThreadDeath td) {
throw td;
} catch (Throwable e) {
try {
logger.error("Quick Pulse failed to prepare data for send", e);
} catch (ThreadDeath td) {
throw td;
} catch (Throwable t2) {
// chomp
}
}
}
use of com.azure.core.http.HttpRequest in project ApplicationInsights-Java by microsoft.
the class QuickPulseNetworkHelper method buildPingRequest.
public HttpRequest buildPingRequest(Date currentDate, String address, String quickPulseId, String machineName, String roleName, String instanceName) {
HttpRequest request = buildRequest(currentDate, address);
request.setHeader(QPS_ROLE_NAME_HEADER, roleName);
request.setHeader(QPS_MACHINE_NAME_HEADER, machineName);
request.setHeader(QPS_STREAM_ID_HEADER, quickPulseId);
request.setHeader(QPS_INSTANCE_NAME_HEADER, instanceName);
request.setHeader(QPS_INVARIANT_VERSION_HEADER, Integer.toString(QuickPulse.QP_INVARIANT_VERSION));
return request;
}
use of com.azure.core.http.HttpRequest in project ApplicationInsights-Java by microsoft.
the class QuickPulsePingSender method ping.
public QuickPulseHeaderInfo ping(String redirectedEndpoint) {
String instrumentationKey = getInstrumentationKey();
if (Strings.isNullOrEmpty(instrumentationKey)) {
// turn off quick pulse.
return new QuickPulseHeaderInfo(QuickPulseStatus.QP_IS_OFF);
}
Date currentDate = new Date();
String endpointPrefix = Strings.isNullOrEmpty(redirectedEndpoint) ? getQuickPulseEndpoint() : redirectedEndpoint;
HttpRequest request = networkHelper.buildPingRequest(currentDate, getQuickPulsePingUri(endpointPrefix), quickPulseId, machineName, telemetryClient.getRoleName(), instanceName);
long sendTime = System.nanoTime();
HttpResponse response = null;
try {
request.setBody(buildPingEntity(currentDate.getTime()));
response = httpPipeline.send(request).block();
if (response == null) {
// this shouldn't happen, the mono should complete with a response or a failure
throw new AssertionError("http response mono returned empty");
}
// response body is not consumed below
LazyHttpClient.consumeResponseBody(response);
if (networkHelper.isSuccess(response)) {
QuickPulseHeaderInfo quickPulseHeaderInfo = networkHelper.getQuickPulseHeaderInfo(response);
switch(quickPulseHeaderInfo.getQuickPulseStatus()) {
case QP_IS_OFF:
case QP_IS_ON:
lastValidTransmission = sendTime;
operationLogger.recordSuccess();
return quickPulseHeaderInfo;
default:
break;
}
}
} catch (Throwable t) {
if (!NetworkFriendlyExceptions.logSpecialOneTimeFriendlyException(t, getQuickPulseEndpoint(), friendlyExceptionThrown, logger)) {
operationLogger.recordFailure(t.getMessage(), t);
}
} finally {
if (response != null) {
response.close();
}
}
return onPingError(sendTime);
}
use of com.azure.core.http.HttpRequest in project ApplicationInsights-Java by microsoft.
the class AzureMetadataService method run.
@Override
public void run() {
HttpRequest request = new HttpRequest(HttpMethod.GET, ENDPOINT);
request.setHeader("Metadata", "true");
HttpResponse response;
try {
response = LazyHttpClient.getInstance().send(request).block();
} catch (RuntimeException e) {
logger.debug("Shutting down AzureMetadataService scheduler: is not running on Azure VM or VMSS");
logger.trace(e.getMessage(), e);
scheduledExecutor.shutdown();
return;
}
if (response == null) {
// this shouldn't happen, the mono should complete with a response or a failure
throw new AssertionError("http response mono returned empty");
}
String json = response.getBodyAsString().block();
if (json == null) {
// this shouldn't happen, the mono should complete with a response or a failure
throw new AssertionError("response body mono returned empty");
}
MetadataInstanceResponse metadataInstanceResponse;
try {
metadataInstanceResponse = mapper.readValue(json, MetadataInstanceResponse.class);
} catch (IOException e) {
logger.debug("Shutting down AzureMetadataService scheduler:" + " error parsing response from Azure Metadata Service: {}", json, e);
scheduledExecutor.shutdown();
return;
}
updateMetadata(metadataInstanceResponse);
}
use of com.azure.core.http.HttpRequest in project lowkey-vault by nagyesta.
the class LowkeyVaultManagementClientImpl method recover.
@Override
public VaultModel recover(@NonNull final URI baseUri) {
final Map<String, String> parameters = Map.of(BASE_URI_QUERY_PARAM, baseUri.toString());
final URI uri = UriUtil.uriBuilderForPath(vaultUrl, MANAGEMENT_VAULT_RECOVERY_PATH, parameters);
final HttpRequest request = new HttpRequest(HttpMethod.PUT, uri.toString()).setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON);
return sendAndProcess(request, r -> r.getResponseObject(VaultModel.class));
}
Aggregations