Search in sources :

Example 21 with JSONArray

use of net.sf.json.JSONArray in project promoted-builds-plugin by jenkinsci.

the class ManualCondition method doApprove.

/**
     * Web method to handle the approval action submitted by the user.
     */
public void doApprove(StaplerRequest req, StaplerResponse rsp, @AncestorInPath PromotionProcess promotionProcess, @AncestorInPath AbstractBuild<?, ?> build) throws IOException, ServletException {
    JSONObject formData = req.getSubmittedForm();
    if (canApprove(promotionProcess, build)) {
        List<ParameterValue> paramValues = new ArrayList<ParameterValue>();
        if (parameterDefinitions != null && !parameterDefinitions.isEmpty()) {
            JSONArray a = JSONArray.fromObject(formData.get("parameter"));
            for (Object o : a) {
                JSONObject jo = (JSONObject) o;
                String name = jo.getString("name");
                ParameterDefinition d = getParameterDefinition(name);
                if (d == null)
                    throw new IllegalArgumentException("No such parameter definition: " + name);
                paramValues.add(d.createValue(req, jo));
            }
        }
        approve(build, promotionProcess, paramValues);
    }
    rsp.sendRedirect2("../../../..");
}
Also used : JSONObject(net.sf.json.JSONObject) ParameterValue(hudson.model.ParameterValue) ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) JSONObject(net.sf.json.JSONObject) SimpleParameterDefinition(hudson.model.SimpleParameterDefinition) ParameterDefinition(hudson.model.ParameterDefinition)

Example 22 with JSONArray

use of net.sf.json.JSONArray in project cobar by alibaba.

the class CobarNodeInstantPerfValueAjax method handleRequest.

@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    AjaxParams params = new AjaxParams(request);
    CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(params.getCobarNodeId());
    JSONArray array = null;
    String jsonRst = null;
    String st = params.getValueType();
    if (null == st || st.equals("")) {
        throw new IllegalArgumentException("parameter 'cobarControlValueType' is unknown: " + st);
    }
    int type = typeMap.get(st);
    switch(type) {
        case TYPE_SERVER_STATUS:
            jsonRst = JSONObject.fromObject(getServerStatus(params)).toString(2);
            break;
        case TYPE_PROCESSOR_STATUS:
            List<Map<String, Object>> listProcessor = listProcessorStatus(params);
            array = JSONArray.fromObject(listProcessor);
            jsonRst = array.toString(2);
            break;
        case TYPE_THREAD_POOL:
            List<Map<String, Object>> listThreadpool = listThreadPool(params);
            array = JSONArray.fromObject(listThreadpool);
            jsonRst = array.toString(2);
            break;
        case TYPE_COMMAND:
            List<Map<String, Object>> listCommand = listCommand(params);
            array = JSONArray.fromObject(listCommand);
            jsonRst = array.toString(2);
            break;
        case TYPE_DATANODES:
            List<Map<String, Object>> listDatanode = listDatanode(params);
            array = JSONArray.fromObject(listDatanode);
            jsonRst = array.toString(2);
            break;
        case TYPE_DATABASES:
            List<String> listDatabase = null;
            if (perfAccesser.checkConnection()) {
                listDatabase = perfAccesser.listDataBases();
            }
            array = JSONArray.fromObject(listDatabase);
            jsonRst = array.toString(2);
            break;
        case TYPE_DATASOURCES:
            List<DataSources> listDatasource = null;
            if (perfAccesser.checkConnection()) {
                listDatasource = perfAccesser.listDataSources();
            }
            array = JSONArray.fromObject(listDatasource);
            jsonRst = array.toString(2);
            break;
        case TYPE_CONNECTION:
            List<Map<String, Object>> listConnection = listConnection(params);
            array = JSONArray.fromObject(listConnection);
            jsonRst = array.toString(2);
            break;
        default:
            throw new IllegalArgumentException("parameter 'cobarNodeInstantPerfValueType' is known: " + params.getValueType());
    }
    perfAccesser = null;
    response.setHeader("Content-Type", "text/json; charset=utf-8");
    OutputStream out = response.getOutputStream();
    out.write(jsonRst.getBytes("utf-8"));
    out.flush();
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) DataSources(com.alibaba.cobar.manager.dataobject.cobarnode.DataSources) OutputStream(java.io.OutputStream) JSONArray(net.sf.json.JSONArray) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with JSONArray

use of net.sf.json.JSONArray in project cobar by alibaba.

the class ClusterInstantPerfValueAjax method handleRequest.

@SuppressWarnings("unchecked")
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    AjaxParams params = new AjaxParams(request);
    String jsonRst = null;
    String st = params.getValueType();
    if (null == st || st.equals("")) {
        throw new IllegalArgumentException("parameter 'cobarControlValueType' is unknown: " + st);
    }
    int type = valueTypeMap.get(st);
    PropertyUtilsBean util = new PropertyUtilsBean();
    switch(type) {
        case TYPE_COBAR_MEMORY_USAGE:
            List<Pair<Long, Integer>> mList = listCobarMemoryUsage(params);
            JSONArray mArray = JSONArray.fromObject(mList);
            jsonRst = mArray.toString(2);
            break;
        case TYPE_CLUSTER_THROUGHPUT_INFO:
            List<Map<String, Object>> list1 = getClusterThroughput(params);
            JSONArray arrayMap = JSONArray.fromObject(list1);
            jsonRst = arrayMap.toString(2);
            break;
        case TYPE_CLUSTER_INFO:
            AjaxResult rs = getClusterInfo(params);
            Map<String, Object> map = null;
            try {
                map = util.describe(rs);
            } catch (Exception e) {
                logger.error(e);
                throw new RuntimeException(e);
            }
            jsonRst = JSONObject.fromObject(map).toString(2);
            break;
        case TYPE_STATUS:
            List<Pair<Long, String>> sList = getStatus(params);
            JSONArray sArray = JSONArray.fromObject(sList);
            jsonRst = sArray.toString(2);
            break;
        default:
            throw new IllegalArgumentException("parameter 'ValueType' is known: " + params.getValueType());
    }
    response.setHeader("Content-Type", "text/json; charset=utf-8");
    OutputStream out = response.getOutputStream();
    out.write(jsonRst.getBytes("utf-8"));
    out.flush();
}
Also used : PropertyUtilsBean(org.apache.commons.beanutils.PropertyUtilsBean) OutputStream(java.io.OutputStream) JSONArray(net.sf.json.JSONArray) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JSONObject(net.sf.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.alibaba.cobar.manager.util.Pair)

Example 24 with JSONArray

use of net.sf.json.JSONArray in project cobar by alibaba.

the class CobarControlAjax method handleRequest.

@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    AjaxParams params = new AjaxParams(request);
    JSONArray array = null;
    String jsonRst = null;
    String st = params.getValueType();
    if (null == st || st.equals("")) {
        throw new IllegalArgumentException("parameter 'cobarControlValueType' is unknown: " + st);
    }
    int type = typeMap.get(st);
    switch(type) {
        case COBAR_LIST:
            List<Map<String, Object>> cobarList = getCobarList(params);
            array = JSONArray.fromObject(cobarList);
            jsonRst = array.toString(2);
            break;
        case KILL_CONNECTION:
            Pair<String, Boolean> kill = new Pair<String, Boolean>("result", killConnections(params));
            jsonRst = JSONObject.fromObject(kill).toString(2);
            break;
        default:
            throw new IllegalArgumentException("parameter 'cobarControlValueType' is unknown: " + params.getValueType());
    }
    response.setHeader("Content-Type", "text/json; charset=utf-8");
    OutputStream out = response.getOutputStream();
    out.write(jsonRst.getBytes("utf-8"));
    out.flush();
}
Also used : OutputStream(java.io.OutputStream) JSONArray(net.sf.json.JSONArray) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.alibaba.cobar.manager.util.Pair)

Example 25 with JSONArray

use of net.sf.json.JSONArray in project pinpoint by naver.

the class JsonLibJSONArrayIT method arrayToJsonTest.

@Test
public void arrayToJsonTest() throws Exception {
    Method fromObject = JSONArray.class.getMethod("fromObject", Object.class);
    Method toString = JSONArray.class.getMethod("toString");
    JSONArray jsonArray = JSONArray.fromObject(new Object[] { "pinpoint", "json-lib" });
    String json = jsonArray.toString();
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    verifier.verifyTrace(event(SERVICE_TYPE, fromObject));
    verifier.verifyTrace(event(SERVICE_TYPE, toString, Expectations.annotation(ANNOTATION_KEY, json.length())));
    verifier.verifyTraceCount(0);
}
Also used : JSONArray(net.sf.json.JSONArray) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Aggregations

JSONArray (net.sf.json.JSONArray)31 JSONObject (net.sf.json.JSONObject)19 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)5 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)4 Test (org.junit.Test)4 CommandStatus (com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus)3 ProcessorStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)3 SimpleChartData (com.sohu.cache.web.chart.model.SimpleChartData)3 ParameterDefinition (hudson.model.ParameterDefinition)3 ParameterValue (hudson.model.ParameterValue)3 OutputStream (java.io.OutputStream)3 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)2 Pair (com.alibaba.cobar.manager.util.Pair)2 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)2 Method (java.lang.reflect.Method)2 ParseException (java.text.ParseException)2 Iterator (java.util.Iterator)2