Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-13865

Jenkins /queue/api does not produce properly formatted JSON when a build in queue where the destination node/s are busy.

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • core
    • None
    • Linux

      Jenkins /queue/api does not produce properly formatted JSON when build in queue where a node/s are fully busy. The json produced is un-parsable. This can be visible on the builds.apache.org server.

      Example:
      "why":"Waiting for next available executor on

      [8mha:AAAAkB+LCAAAAAAAAABb85aBtbiIQSajNKU4P08vOT+vOD8nVc+jsiC1KCczL9svvyT1dMUiOWdZ/mImBiZPBrac1Lz0kgwfBubSopwSBiGfrMSyRP2cxLx0/eCSosy8dOuKIgYpNOOcITTIMAYIYGRiYKgoADLYShgE9JPzcwtKS1KL9HNKk1PzUgENqikilQAAAA==[0mlucene"
      

      Appears that the "why" property of the queued build isn't being formatted properly. Actually it's being gzipped...

      Looking at the source, the hudson.model.queue.CauseOfBlockage class appears to be the culprit. To wit:

      public String getShortDescription() {
                  return Messages.Queue_WaitingForNextAvailableExecutorOn(HyperlinkNote.encodeTo("/computer/"+ node.getNodeName(), node.getNodeName()));
              }
      

      The nodename is attempting to be encoded with HyperlinkNote:

      public static String encodeTo(String url, String text) {
              try {
                  return new HyperlinkNote(url,text.length()).encode()+text;
              } catch (IOException e) {
                  // impossible, but don't make this a fatal problem
                  LOGGER.log(Level.WARNING, "Failed to serialize "+HyperlinkNote.class,e);
                  return text;
              }
          }
      

      Which calls the supers encode() method:

      public String encode() throws IOException {
              return encodeToBytes().toString();
          }
      

      And finally encodeToBytes():

      private ByteArrayOutputStream encodeToBytes() throws IOException {
              ByteArrayOutputStream buf = new ByteArrayOutputStream();
              ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(buf));
              oos.writeObject(this);
              oos.close();
      
              ByteArrayOutputStream buf2 = new ByteArrayOutputStream();
      
              DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null));
              buf2.write(PREAMBLE);
              dos.writeInt(buf.size());
              buf.writeTo(dos);
              dos.close();
              buf2.write(POSTAMBLE);
              return buf2;
          }
      

      Finally in ConsoleNote

      public static final String PREAMBLE_STR = "\u001B[8mha:";
      public static final String POSTAMBLE_STR = "\u001B[0m";
      }
      

      Clearly the choice in using ansi escaping, and therefore the brackets is violating the JSON structural syntax rules and causing the JSON emitted to be un-parsable.

            Unassigned Unassigned
            flyingfish Jason Howk
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: