Exemplo n.º 1
0
  public CLI(URL jenkins, ExecutorService exec) throws IOException, InterruptedException {
    String url = jenkins.toExternalForm();
    if (!url.endsWith("/")) url += '/';

    ownsPool = exec == null;
    pool = exec != null ? exec : Executors.newCachedThreadPool();

    int clip = getCliTcpPort(url);
    if (clip >= 0) {
      // connect via CLI port
      String host = new URL(url).getHost();
      LOGGER.fine("Trying to connect directly via TCP/IP to port " + clip + " of " + host);
      Socket s = new Socket(host, clip);
      DataOutputStream dos = new DataOutputStream(s.getOutputStream());
      dos.writeUTF("Protocol:CLI-connect");

      channel =
          new Channel(
              "CLI connection to " + jenkins,
              pool,
              new BufferedInputStream(new SocketInputStream(s)),
              new BufferedOutputStream(new SocketOutputStream(s)));
    } else {
      // connect via HTTP
      LOGGER.fine("Trying to connect to " + url + " via HTTP");
      url += "cli";
      jenkins = new URL(url);

      FullDuplexHttpStream con = new FullDuplexHttpStream(jenkins);
      channel =
          new Channel(
              "Chunked connection to " + jenkins,
              pool,
              con.getInputStream(),
              con.getOutputStream());
      new PingThread(channel, 30 * 1000) {
        protected void onDead() {
          // noop. the point of ping is to keep the connection alive
          // as most HTTP servers have a rather short read time out
        }
      }.start();
    }

    // execute the command
    entryPoint = (CliEntryPoint) channel.waitForRemoteProperty(CliEntryPoint.class.getName());

    if (entryPoint.protocolVersion() != CliEntryPoint.VERSION)
      throw new IOException(Messages.CLI_VersionMismatch());
  }
Exemplo n.º 2
0
  /**
   * Run the SCM trigger with additional build actions. Used by SubversionRepositoryStatus to
   * trigger a build at a specific revisionn number.
   *
   * @param additionalActions
   * @since 1.375
   */
  public void run(Action[] additionalActions) {
    if (Hudson.getInstance().isQuietingDown()) return; // noop

    DescriptorImpl d = getDescriptor();

    LOGGER.fine("Scheduling a polling for " + job);
    if (d.synchronousPolling) {
      LOGGER.fine(
          "Running the trigger directly without threading, "
              + "as it's already taken care of by Trigger.Cron");
      new Runner(additionalActions).run();
    } else {
      // schedule the polling.
      // even if we end up submitting this too many times, that's OK.
      // the real exclusion control happens inside Runner.
      LOGGER.fine("scheduling the trigger to (asynchronously) run");
      d.queue.execute(new Runner(additionalActions));
      d.clogCheck();
    }
  }