Search in sources :

Example 51 with TypeToken

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();
}
Also used : SystemServiceMeta(co.cask.cdap.proto.SystemServiceMeta) TypeToken(com.google.common.reflect.TypeToken) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL)

Example 52 with TypeToken

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();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL)

Example 53 with TypeToken

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();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL)

Example 54 with TypeToken

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;
}
Also used : Type(java.lang.reflect.Type) TypeToken(com.google.common.reflect.TypeToken)

Example 55 with TypeToken

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();
    }
}
Also used : HandleNotFoundException(co.cask.cdap.explore.service.HandleNotFoundException) QueryResult(co.cask.cdap.proto.QueryResult) TypeToken(com.google.common.reflect.TypeToken) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) IOException(java.io.IOException) File(java.io.File) Lock(java.util.concurrent.locks.Lock) ExploreException(co.cask.cdap.explore.service.ExploreException)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)135 Test (org.junit.Test)60 HttpResponse (co.cask.common.http.HttpResponse)26 URL (java.net.URL)24 ServiceResponse (com.microsoft.rest.ServiceResponse)22 Response (retrofit2.Response)22 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)18 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)17 PipedInputStream (java.io.PipedInputStream)17 PipedOutputStream (java.io.PipedOutputStream)17 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)16 List (java.util.List)16 Map (java.util.Map)11 ImmutableList (com.google.common.collect.ImmutableList)9 Type (java.lang.reflect.Type)9 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)9 NotFoundException (co.cask.cdap.common.NotFoundException)8 VirtualMachineScaleSetVMInstanceIDs (com.microsoft.azure.management.compute.VirtualMachineScaleSetVMInstanceIDs)8 Gson (com.google.gson.Gson)7 JsonObject (com.google.gson.JsonObject)7