use of org.apache.geode.management.internal.cli.json.GfJsonException in project geode by apache.
the class CompositeResultData method addSection.
public SectionResultData addSection(String keyToAccess) {
GfJsonObject sectionData = new GfJsonObject();
try {
contentObject.putAsJSONObject(SectionResultData.generateSectionKey(keyToAccess), sectionData);
} catch (GfJsonException e) {
throw new ResultDataException(e.getMessage());
}
subsectionCount++;
return new SectionResultData(sectionData);
}
use of org.apache.geode.management.internal.cli.json.GfJsonException in project geode by apache.
the class CompositeResultData method addSection.
public SectionResultData addSection(SectionResultData otherSection) {
String keyToAccess = String.valueOf(subsectionCount);
GfJsonObject sectionData = otherSection.getSectionGfJsonObject();
try {
contentObject.putAsJSONObject(SectionResultData.generateSectionKey(keyToAccess), sectionData);
} catch (GfJsonException e) {
throw new ResultDataException(e.getMessage());
}
subsectionCount++;
return new SectionResultData(sectionData);
}
use of org.apache.geode.management.internal.cli.json.GfJsonException in project geode by apache.
the class ObjectResultData method getAllObjects.
public List<CliJsonSerializable> getAllObjects() {
List<CliJsonSerializable> list = new ArrayList<CliJsonSerializable>();
try {
GfJsonArray rootJsonArray = contentObject.getJSONArray(OBJECTS_ACCESSOR);
int size = rootJsonArray.size();
GfJsonObject jsonObject = null;
CliJsonSerializable cliJsonSerializable = null;
for (int i = 0; i < size; i++) {
jsonObject = rootJsonArray.getJSONObject(i);
cliJsonSerializable = CliJsonSerializableFactory.getCliJsonSerializable(jsonObject.getInt(CliJsonSerializable.JSID));
cliJsonSerializable.fromJson(jsonObject);
list.add(cliJsonSerializable);
}
} catch (GfJsonException e) {
throw new ResultDataException(e.getMessage());
}
return list;
}
use of org.apache.geode.management.internal.cli.json.GfJsonException in project geode by apache.
the class DataCommandFunction method select_SelectResults.
private void select_SelectResults(SelectResults selectResults, Object principal, List<SelectResultRow> list, AtomicInteger nestedObjectCount) throws GfJsonException {
for (Object object : selectResults) {
// Post processing
object = securityService.postProcess(principal, null, null, object, false);
if (object instanceof Struct) {
StructImpl impl = (StructImpl) object;
GfJsonObject jsonStruct = getJSONForStruct(impl, nestedObjectCount);
if (logger.isDebugEnabled()) {
logger.debug("SelectResults : Adding select json string : {}", jsonStruct);
}
list.add(new SelectResultRow(DataCommandResult.ROW_TYPE_STRUCT_RESULT, jsonStruct.toString()));
} else if (JsonUtil.isPrimitiveOrWrapper(object.getClass())) {
if (logger.isDebugEnabled()) {
logger.debug("SelectResults : Adding select primitive : {}", object);
}
list.add(new SelectResultRow(DataCommandResult.ROW_TYPE_PRIMITIVE, object));
} else {
if (logger.isDebugEnabled()) {
logger.debug("SelectResults : Bean Results class is {}", object.getClass());
}
String str = toJson(object);
GfJsonObject jsonBean;
try {
jsonBean = new GfJsonObject(str);
} catch (GfJsonException e) {
logger.error(e.getMessage(), e);
jsonBean = new GfJsonObject();
try {
jsonBean.put("msg", e.getMessage());
} catch (GfJsonException e1) {
logger.warn("Ignored GfJsonException:", e1);
}
}
if (logger.isDebugEnabled()) {
logger.debug("SelectResults : Adding bean json string : {}", jsonBean);
}
list.add(new SelectResultRow(DataCommandResult.ROW_TYPE_BEAN, jsonBean.toString()));
}
}
}
use of org.apache.geode.management.internal.cli.json.GfJsonException in project geode by apache.
the class DataCommandFunction method select.
@SuppressWarnings("rawtypes")
private DataCommandResult select(Object principal, String queryString) {
InternalCache cache = getCache();
AtomicInteger nestedObjectCount = new AtomicInteger(0);
if (StringUtils.isEmpty(queryString)) {
return DataCommandResult.createSelectInfoResult(null, null, -1, null, CliStrings.QUERY__MSG__QUERY_EMPTY, false);
}
QueryService qs = cache.getQueryService();
// TODO : Find out if is this optimised use. Can you have something equivalent of parsed
// queries with names where name can be retrieved to avoid parsing every-time
Query query = qs.newQuery(queryString);
DefaultQuery tracedQuery = (DefaultQuery) query;
WrappedIndexTrackingQueryObserver queryObserver = null;
String queryVerboseMsg = null;
long startTime = -1;
if (tracedQuery.isTraced()) {
startTime = NanoTimer.getTime();
queryObserver = new WrappedIndexTrackingQueryObserver();
QueryObserverHolder.setInstance(queryObserver);
}
List<SelectResultRow> list = new ArrayList<>();
try {
Object results = query.execute();
if (tracedQuery.isTraced()) {
queryVerboseMsg = getLogMessage(queryObserver, startTime, queryString);
queryObserver.reset2();
}
if (results instanceof SelectResults) {
select_SelectResults((SelectResults) results, principal, list, nestedObjectCount);
} else {
select_NonSelectResults(results, list);
}
return DataCommandResult.createSelectResult(queryString, list, queryVerboseMsg, null, null, true);
} catch (FunctionDomainException | GfJsonException | QueryInvocationTargetException | NameResolutionException | TypeMismatchException e) {
logger.warn(e.getMessage(), e);
return DataCommandResult.createSelectResult(queryString, null, queryVerboseMsg, e, e.getMessage(), false);
} finally {
if (queryObserver != null) {
QueryObserverHolder.reset();
}
}
}
Aggregations