use of org.checkerframework.checker.nullness.qual.Nullable in project ExoPlayer by google.
the class DemoUtil method getHttpDataSourceFactory.
public static synchronized HttpDataSource.Factory getHttpDataSourceFactory(Context context) {
if (httpDataSourceFactory == null) {
if (USE_CRONET_FOR_NETWORKING) {
context = context.getApplicationContext();
@Nullable CronetEngine cronetEngine = CronetUtil.buildCronetEngine(context);
if (cronetEngine != null) {
httpDataSourceFactory = new CronetDataSource.Factory(cronetEngine, Executors.newSingleThreadExecutor());
}
}
if (httpDataSourceFactory == null) {
// We don't want to use Cronet, or we failed to instantiate a CronetEngine.
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
CookieHandler.setDefault(cookieManager);
httpDataSourceFactory = new DefaultHttpDataSource.Factory();
}
}
return httpDataSourceFactory;
}
use of org.checkerframework.checker.nullness.qual.Nullable in project aws-xray-sdk-java by aws.
the class ContainerInsightsUtil method getClusterName.
/**
* Return the cluster name from ContainerInsights configMap via the K8S API and the pod's system account.
*
* @return the name
*/
@Nullable
public static String getClusterName() {
if (isK8s()) {
CloseableHttpClient client = getHttpClient();
HttpGet getRequest = new HttpGet(K8S_URL + CI_CONFIGMAP_PATH);
String k8sCredentialHeader = getK8sCredentialHeader();
if (k8sCredentialHeader != null) {
getRequest.setHeader(AUTH_HEADER_NAME, k8sCredentialHeader);
}
try {
CloseableHttpResponse response = client.execute(getRequest);
try {
HttpEntity entity = response.getEntity();
String json = EntityUtils.toString(entity);
ObjectMapper mapper = new ObjectMapper();
String clusterName = mapper.readTree(json).at("/data/cluster.name").asText();
if (logger.isDebugEnabled()) {
logger.debug("Container Insights Cluster Name: " + clusterName);
}
return clusterName;
} catch (IOException e) {
logger.error("Error parsing response from Kubernetes", e);
} finally {
response.close();
}
client.close();
} catch (IOException e) {
logger.error("Error querying for Container Insights ConfigMap", e);
}
}
return null;
}
use of org.checkerframework.checker.nullness.qual.Nullable in project aws-xray-sdk-java by aws.
the class ContainerInsightsUtil method getK8sKeystore.
@Nullable
private static KeyStore getK8sKeystore() {
InputStream certificateFile = null;
try {
KeyStore k8sTrustStore = null;
File caFile = Paths.get(K8S_CRED_FOLDER, K8S_CRED_CERT_SUFFIX).toFile();
if (caFile.exists()) {
k8sTrustStore = KeyStore.getInstance(KeyStore.getDefaultType());
k8sTrustStore.load(null, null);
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
certificateFile = new FileInputStream(caFile);
Collection<? extends Certificate> certificates = certificateFactory.generateCertificates(certificateFile);
if (certificates.isEmpty()) {
throw new IllegalArgumentException("K8s cert file contained no certificates.");
}
for (Certificate certificate : certificates) {
k8sTrustStore.setCertificateEntry("k8sca", certificate);
}
} else {
logger.debug("K8s CA Cert file does not exists.");
}
return k8sTrustStore;
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | IOException e) {
logger.warn("Unable to load K8s CA certificate.", e);
return null;
} finally {
if (certificateFile != null) {
try {
certificateFile.close();
} catch (IOException e) {
logger.error("Can't close K8s CA certificate file.", e);
}
}
}
}
use of org.checkerframework.checker.nullness.qual.Nullable in project aws-xray-sdk-java by aws.
the class ContainerInsightsUtil method getK8sCredentialHeader.
@Nullable
private static String getK8sCredentialHeader() {
BufferedReader tokenReader = null;
try {
File tokenFile = Paths.get(K8S_CRED_FOLDER, K8S_CRED_TOKEN_SUFFIX).toFile();
tokenReader = new BufferedReader(new InputStreamReader(new FileInputStream(tokenFile), StandardCharsets.UTF_8));
return String.format("Bearer %s", tokenReader.readLine());
} catch (IOException e) {
logger.warn("Unable to read K8s credential file.", e);
} finally {
if (tokenReader != null) {
try {
tokenReader.close();
} catch (IOException e) {
logger.error("Can't close K8s credential file.", e);
}
}
}
return null;
}
use of org.checkerframework.checker.nullness.qual.Nullable in project aws-xray-sdk-java by aws.
the class AWSXRayRecorder method currentTraceId.
/**
* @throws SegmentNotFoundException
* if {@code contextMissingStrategy} throws exceptions and no segment or subsegment is currently in progress
* @return the trace ID of the {@code Segment} currently in progress, or {@code null} if {@code contextMissingStrategy}
* suppresses exceptions and no segment or subsegment is currently in progress
*/
@Nullable
public TraceID currentTraceId() {
SegmentContext context = getSegmentContext();
if (context == null) {
return null;
}
Entity current = context.getTraceEntity();
if (current != null) {
return current.getParentSegment().getTraceId();
} else {
contextMissingStrategy.contextMissing("Failed to get current trace ID: segment cannot be found.", SegmentNotFoundException.class);
return null;
}
}
Aggregations