Support Questions
Find answers, ask questions, and share your expertise

getting NumberFormatException by a readHosts method of a ClouderaManager API Client

New Contributor

Hi!
Im trying to use Java Cloudera Manager API Client.
For now any information that I got via local API calls implementations was fine except information about Hosts.

 

This is my current method that I wanted to use to get

 

 

public static void hostsInfo(ApiClient cmClient) {
    HostsResourceApi hostsResourceApi = new HostsResourceApi(cmClient);

    try {
        ApiHostList hostList = hostsResourceApi.readHosts("", "", "full");
        ApiConfigList configList;
        for (ApiHost host : hostList.getItems()) {
            configList = host.getConfig();
            System.out.println(host.getHostname() + " " + host.getIpAddress());
        }

    } catch (ApiException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}

 

 

This is exception stacktrace that I get:

 

Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Expected an int but was 18943685304 at line 125 column 38 path $.items[0].totalPhysMemBytes
                at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:231)
                at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:221)
                at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
                at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
                at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
                at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
                at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
                at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
                at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
                at com.google.gson.Gson.fromJson(Gson.java:932)
                at com.google.gson.Gson.fromJson(Gson.java:897)
                at com.google.gson.Gson.fromJson(Gson.java:846)
                at com.cloudera.api.swagger.client.JSON.deserialize(JSON.java:102)
                at com.cloudera.api.swagger.client.ApiClient.deserialize(ApiClient.java:860)
                at com.cloudera.api.swagger.client.ApiClient.handleResponse(ApiClient.java:1063)
                at com.cloudera.api.swagger.client.ApiClient.execute(ApiClient.java:990)
                at com.cloudera.api.swagger.HostsResourceApi.readHostsWithHttpInfo(HostsResourceApi.java:1731)
                at com.cloudera.api.swagger.HostsResourceApi.readHosts(HostsResourceApi.java:1715)
                at com.info.cloudera.Main.hostsInfo(Main.java:71)
                at com.info.cloudera.Main.main(Main.java:181)
Caused by: java.lang.NumberFormatException: Expected an int but was 16656277504 at line 125 column 38 path $.items[0].totalPhysMemBytes
                at com.google.gson.stream.JsonReader.nextInt(JsonReader.java:1171)
                at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:229)
                ... 19 more

 

And this is the method causing method to fall with this exception. I thought that changing nextInt method call to nextLong can help, but I dont think that is correct way to fix the problem.

 

 

public static final TypeAdapter<Number> INTEGER = new TypeAdapter<Number>() {
  @Override
  public Number read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
      in.nextNull();
      return null;
    }
    try {
      return in.nextInt();
    } catch (NumberFormatException e) {
      throw new JsonSyntaxException(e);
    }
  }

 

 


 Could anyone help me with this question?

0 REPLIES 0
; ;