Search in sources :

Example 6 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project elasticsearch by elastic.

the class SmileXContentTests method testBigInteger.

public void testBigInteger() throws Exception {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    JsonGenerator generator = new SmileFactory().createGenerator(os);
    doTestBigInteger(generator, os);
}
Also used : SmileFactory(com.fasterxml.jackson.dataformat.smile.SmileFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project hadoop by apache.

the class Anonymizer method anonymizeTrace.

// anonymize the job trace file
private void anonymizeTrace() throws Exception {
    if (anonymizeTrace) {
        System.out.println("Anonymizing trace file: " + inputTracePath);
        JobTraceReader reader = null;
        JsonGenerator outGen = null;
        Configuration conf = getConf();
        try {
            // create a generator
            outGen = createJsonGenerator(conf, outputTracePath);
            // define the input trace reader
            reader = new JobTraceReader(inputTracePath, conf);
            // read the plain unanonymized logged job
            LoggedJob job = reader.getNext();
            while (job != null) {
                // write it via an anonymizing channel
                outGen.writeObject(job);
                // read the next job
                job = reader.getNext();
            }
            System.out.println("Anonymized trace file: " + outputTracePath);
        } finally {
            if (outGen != null) {
                outGen.close();
            }
            if (reader != null) {
                reader.close();
            }
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 8 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project hadoop by apache.

the class JMXJsonServlet method doGet.

/**
   * Process a GET request for the specified resource.
   * 
   * @param request
   *          The servlet request we are processing
   * @param response
   *          The servlet response we are creating
   */
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
    try {
        // If user is a static user and auth Type is null, that means
        // there is a non-security environment and no need authorization,
        // otherwise, do the authorization.
        final ServletContext servletContext = getServletContext();
        if (!HttpServer2.isStaticUserAndNoneAuthType(servletContext, request) && !isInstrumentationAccessAllowed(request, response)) {
            return;
        }
        JsonGenerator jg = null;
        PrintWriter writer = null;
        try {
            writer = response.getWriter();
            response.setContentType("application/json; charset=utf8");
            response.setHeader(ACCESS_CONTROL_ALLOW_METHODS, "GET");
            response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
            jg = jsonFactory.createGenerator(writer);
            jg.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
            jg.useDefaultPrettyPrinter();
            jg.writeStartObject();
            // query per mbean attribute
            String getmethod = request.getParameter("get");
            if (getmethod != null) {
                String[] splitStrings = getmethod.split("\\:\\:");
                if (splitStrings.length != 2) {
                    jg.writeStringField("result", "ERROR");
                    jg.writeStringField("message", "query format is not as expected.");
                    jg.flush();
                    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                    return;
                }
                listBeans(jg, new ObjectName(splitStrings[0]), splitStrings[1], response);
                return;
            }
            // query per mbean
            String qry = request.getParameter("qry");
            if (qry == null) {
                qry = "*:*";
            }
            listBeans(jg, new ObjectName(qry), null, response);
        } finally {
            if (jg != null) {
                jg.close();
            }
            if (writer != null) {
                writer.close();
            }
        }
    } catch (IOException e) {
        LOG.error("Caught an exception while processing JMX request", e);
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (MalformedObjectNameException e) {
        LOG.error("Caught an exception while processing JMX request", e);
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ServletContext(javax.servlet.ServletContext) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) ObjectName(javax.management.ObjectName)

Example 9 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project flink by apache.

the class AbstractMetricsHandler method getMetricsValues.

private String getMetricsValues(Map<String, String> pathParams, String requestedMetricsList) throws IOException {
    if (requestedMetricsList.isEmpty()) {
        /**
			 * The WebInterface doesn't check whether the list of available metrics was empty. This can lead to a 
			 * request for which the "get" parameter is an empty string.
			 */
        return "";
    }
    MetricStore metricStore = fetcher.getMetricStore();
    synchronized (metricStore) {
        Map<String, String> metrics = getMapFor(pathParams, metricStore);
        if (metrics == null) {
            return "";
        }
        String[] requestedMetrics = requestedMetricsList.split(",");
        StringWriter writer = new StringWriter();
        JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
        gen.writeStartArray();
        for (String requestedMetric : requestedMetrics) {
            Object metricValue = metrics.get(requestedMetric);
            if (metricValue != null) {
                gen.writeStartObject();
                gen.writeStringField("id", requestedMetric);
                gen.writeStringField("value", metricValue.toString());
                gen.writeEndObject();
            }
        }
        gen.writeEndArray();
        gen.close();
        return writer.toString();
    }
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 10 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project flink by apache.

the class JarListHandler method handleJsonRequest.

@Override
public String handleJsonRequest(Map<String, String> pathParams, Map<String, String> queryParams, ActorGateway jobManager) throws Exception {
    try {
        StringWriter writer = new StringWriter();
        JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
        gen.writeStartObject();
        gen.writeStringField("address", queryParams.get(RuntimeMonitorHandler.WEB_MONITOR_ADDRESS_KEY));
        gen.writeArrayFieldStart("files");
        File[] list = jarDir.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".jar");
            }
        });
        for (File f : list) {
            // separate the uuid and the name parts.
            String id = f.getName();
            int startIndex = id.indexOf("_");
            if (startIndex < 0) {
                continue;
            }
            String name = id.substring(startIndex + 1);
            if (name.length() < 5 || !name.endsWith(".jar")) {
                continue;
            }
            gen.writeStartObject();
            gen.writeStringField("id", id);
            gen.writeStringField("name", name);
            gen.writeNumberField("uploaded", f.lastModified());
            gen.writeArrayFieldStart("entry");
            String[] classes = new String[0];
            try {
                JarFile jar = new JarFile(f);
                Manifest manifest = jar.getManifest();
                String assemblerClass = null;
                if (manifest != null) {
                    assemblerClass = manifest.getMainAttributes().getValue(PackagedProgram.MANIFEST_ATTRIBUTE_ASSEMBLER_CLASS);
                    if (assemblerClass == null) {
                        assemblerClass = manifest.getMainAttributes().getValue(PackagedProgram.MANIFEST_ATTRIBUTE_MAIN_CLASS);
                    }
                }
                if (assemblerClass != null) {
                    classes = assemblerClass.split(",");
                }
            } catch (IOException ignored) {
            // we simply show no entries here
            }
            // show every entry class that can be loaded later on.
            for (String clazz : classes) {
                clazz = clazz.trim();
                PackagedProgram program = null;
                try {
                    program = new PackagedProgram(f, clazz, new String[0]);
                } catch (Exception ignored) {
                // ignore jar files which throw an error upon creating a PackagedProgram
                }
                if (program != null) {
                    gen.writeStartObject();
                    gen.writeStringField("name", clazz);
                    String desc = program.getDescription();
                    gen.writeStringField("description", desc == null ? "No description provided" : desc);
                    gen.writeEndObject();
                }
            }
            gen.writeEndArray();
            gen.writeEndObject();
        }
        gen.writeEndArray();
        gen.writeEndObject();
        gen.close();
        return writer.toString();
    } catch (Exception e) {
        throw new RuntimeException("Failed to fetch jar list: " + e.getMessage(), e);
    }
}
Also used : IOException(java.io.IOException) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) IOException(java.io.IOException) FilenameFilter(java.io.FilenameFilter) PackagedProgram(org.apache.flink.client.program.PackagedProgram) StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)711 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 KriptonByteArrayOutputStream (com.abubusoft.kripton.common.KriptonByteArrayOutputStream)257 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)257 JacksonWrapperSerializer (com.abubusoft.kripton.persistence.JacksonWrapperSerializer)257 IOException (java.io.IOException)170 StringWriter (java.io.StringWriter)145 JsonFactory (com.fasterxml.jackson.core.JsonFactory)101 ByteArrayOutputStream (java.io.ByteArrayOutputStream)66 Map (java.util.Map)57 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 HashMap (java.util.HashMap)41 Test (org.junit.Test)30 File (java.io.File)27 ArrayList (java.util.ArrayList)26 OutputStream (java.io.OutputStream)25 Writer (java.io.Writer)22 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)21 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)20 FileOutputStream (java.io.FileOutputStream)19