Search in sources :

Example 11 with GfJsonException

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);
}
Also used : GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException)

Example 12 with GfJsonException

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);
}
Also used : GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException)

Example 13 with GfJsonException

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;
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) ArrayList(java.util.ArrayList) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException)

Example 14 with GfJsonException

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()));
        }
    }
}
Also used : StructImpl(org.apache.geode.cache.query.internal.StructImpl) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) SelectResultRow(org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) Struct(org.apache.geode.cache.query.Struct)

Example 15 with GfJsonException

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();
        }
    }
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) ArrayList(java.util.ArrayList) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) InternalCache(org.apache.geode.internal.cache.InternalCache) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) SelectResults(org.apache.geode.cache.query.SelectResults) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) SelectResultRow(org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject)

Aggregations

GfJsonException (org.apache.geode.management.internal.cli.json.GfJsonException)34 GfJsonObject (org.apache.geode.management.internal.cli.json.GfJsonObject)27 GfJsonArray (org.apache.geode.management.internal.cli.json.GfJsonArray)14 JSONObject (org.json.JSONObject)9 ArrayList (java.util.ArrayList)6 ResultDataException (org.apache.geode.management.internal.cli.result.ResultDataException)4 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 HashMap (java.util.HashMap)3 SelectResultRow (org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow)3 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)3 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CliJsonSerializable (org.apache.geode.management.internal.cli.result.CliJsonSerializable)2 Table (org.apache.geode.management.internal.cli.result.TableBuilder.Table)2