igiguere commented on code in PR #3955: URL: https://github.com/apache/solr/pull/3955#discussion_r2640388513
########## solr/solrj/src/java/org/apache/solr/client/solrj/response/SystemInfoResponse.java: ########## @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.client.solrj.response; + +import java.lang.invoke.MethodHandles; +import java.util.Date; +import org.apache.solr.client.api.model.NodeSystemResponse; +import org.apache.solr.client.solrj.request.json.JacksonContentWriter; +import org.apache.solr.common.util.NamedList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** This class holds the response from V1 "/admin/info/system" or V2 "/node/system" */ +public class SystemInfoResponse extends SolrResponseBase { + + private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + private static final long serialVersionUID = 1L; + + private NodeSystemResponse fullResponse; + + public SystemInfoResponse(NamedList<Object> namedList) { + if (namedList == null) throw new IllegalArgumentException("Null NamedList is not allowed."); + setResponse(namedList); + } + + @Override + public void setResponse(NamedList<Object> response) { + if (getResponse() == null) super.setResponse(response); + if (fullResponse == null) { + try { + fullResponse = + JacksonContentWriter.DEFAULT_MAPPER.convertValue( + getResponse(), NodeSystemResponse.class); + } catch (Throwable t) { + log.error("Cannot convert NamedList response to API model NodeSystemResponse", t); + } + } + } + + public String getMode() { + return getFullResponse().mode; + } + + public String getZkHost() { + return getFullResponse().zkHost; + } + + public String getSolrHome() { + return getFullResponse().solrHome; + } + + public String getCoreRoot() { + return getFullResponse().coreRoot; + } + + public String getNode() { + return getFullResponse().node; + } + + public NodeSystemResponse getFullResponse() { + return fullResponse; + } + + public String getSolrImplVersion() { + return getFullResponse() != null && getFullResponse().lucene != null + ? getFullResponse().lucene.solrImplVersion + : null; + } + + public String getSolrSpecVersion() { + return getFullResponse() != null && getFullResponse().lucene != null + ? getFullResponse().lucene.solrSpecVersion + : null; + } + + public Date getJVMStartTime() { + return getFullResponse() != null + && getFullResponse().jvm != null + && getFullResponse().jvm.jmx != null + ? getFullResponse().jvm.jmx.startTime + : null; + } + + public Long getJVMUpTime() { + return getFullResponse() != null + && getFullResponse().jvm != null + && getFullResponse().jvm.jmx != null + ? getFullResponse().jvm.jmx.upTimeMS + : null; + } + + public String getJVMMemoryUsed() { + return getFullResponse() != null + && getFullResponse().jvm != null + && getFullResponse().jvm.memory != null + ? getFullResponse().jvm.memory.used + : null; + } + + public String getJVMMemoryTtl() { Review Comment: There's 2 outputs for these values (used, total, free). One is "raw", as long values. One is human-readable. Example: "total":"512 MB". I'll change the method name fo clarity. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
