use of com.google.common.reflect.TypeToken in project cdap by caskdata.
the class MonitorClient method listSystemServices.
/**
* Lists all system services.
*
* @return list of {@link SystemServiceMeta}s.
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<SystemServiceMeta> listSystemServices() throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveURL("system/services");
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
return ObjectResponse.fromJsonBody(response, new TypeToken<List<SystemServiceMeta>>() {
}).getResponseObject();
}
use of com.google.common.reflect.TypeToken in project cdap by caskdata.
the class MonitorClient method getAllSystemServiceStatus.
/**
* Gets the status of all system services.
*
* @return map from service name to service status
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public Map<String, String> getAllSystemServiceStatus() throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveURL("system/services/status");
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, String>>() {
}).getResponseObject();
}
use of com.google.common.reflect.TypeToken in project cdap by caskdata.
the class PreferencesClient method getInstancePreferences.
/**
* Returns the Preferences stored at the Instance Level.
*
* @return map of key-value pairs
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public Map<String, String> getInstancePreferences() throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveURLV3("preferences");
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, String>>() {
}).getResponseObject();
}
use of com.google.common.reflect.TypeToken in project cdap by caskdata.
the class ObjectMappedTableDataset method getReflectionRowReader.
@SuppressWarnings("unchecked")
private ReflectionRowReader<T> getReflectionRowReader() {
if (rowReader == null) {
try {
// this can throw a runtime exception from a ClassNotFoundException
Type type = typeRepresentation.toType();
rowReader = new ReflectionRowReader<>(objectSchema, (TypeToken<T>) TypeToken.of(type));
} catch (RuntimeException e) {
String missingClass = isClassNotFoundException(e);
if (missingClass != null) {
LOG.error("Cannot load dataset because class {} could not be found. This is probably because the " + "type parameter of the dataset is not present in the dataset's jar file. See the developer " + "guide for more information.", missingClass);
}
throw e;
}
}
return rowReader;
}
use of com.google.common.reflect.TypeToken in project cdap by caskdata.
the class BaseHiveExploreService method previewResults.
@Override
public List<QueryResult> previewResults(QueryHandle handle) throws ExploreException, HandleNotFoundException, SQLException {
startAndWait();
if (inactiveHandleCache.getIfPresent(handle) != null) {
throw new HandleNotFoundException("Query is inactive.", true);
}
OperationInfo operationInfo = getActiveOperationInfo(handle);
Lock previewLock = operationInfo.getPreviewLock();
previewLock.lock();
try {
File previewFile = operationInfo.getPreviewFile();
if (previewFile != null) {
try {
Reader reader = com.google.common.io.Files.newReader(previewFile, Charsets.UTF_8);
try {
return GSON.fromJson(reader, new TypeToken<List<QueryResult>>() {
}.getType());
} finally {
Closeables.closeQuietly(reader);
}
} catch (FileNotFoundException e) {
LOG.error("Could not retrieve preview result file {}", previewFile, e);
throw new ExploreException(e);
}
}
try {
// Create preview results for query
previewFile = new File(previewsDir, handle.getHandle());
try (FileWriter fileWriter = new FileWriter(previewFile)) {
List<QueryResult> results = fetchNextResults(handle, PREVIEW_COUNT);
GSON.toJson(results, fileWriter);
operationInfo.setPreviewFile(previewFile);
return results;
}
} catch (IOException e) {
LOG.error("Could not write preview results into file", e);
throw new ExploreException(e);
}
} finally {
previewLock.unlock();
}
}
Aggregations