Examples of SshConnection


Examples of com.sonyericsson.hudson.plugins.gerrit.gerritevents.ssh.SshConnection

      return;
    } else {

      logger.info(String.format("Sending results to gerrit for %s: %s", commit, result));

      SshConnection ssh = SshConnectionFactory.getConnection(connection);
      String command = GerritCommand.createCodeReview(commit, result);
      ssh.executeCommand(command);

      logger.info("Results sent successfully");
    }
  }
View Full Code Here

Examples of com.sonyericsson.hudson.plugins.gerrit.gerritevents.ssh.SshConnection

  public void testIfOneCanConnectToGerrit() throws IOException {

    //given
    GerritConnection connection = GerritConnectionFactory.createGerritConnection(authKey, authKeyPassword, userName, sshPort, hostName);
    GerritCommit commit = GerritCommitFactory.createGerritCommitFromSonarSettings("gerrit-integration-plugin", "1", "1");
    SshConnection ssh = SshConnectionFactory.getConnection(connection);

    //when
    //the analysis is run, the local sonar instance must be up
    final SonarAnalysisResult result = new SonarAnalysisResult("test", SonarAnalysisStatus.ERRORS);
    String codeReview = GerritCommand.createCodeReview(commit, result);
    ssh.executeCommand(codeReview);

    //then

  }
View Full Code Here

Examples of com.sonyericsson.hudson.plugins.gerrit.gerritevents.ssh.SshConnection

    settings.appendProperty(GerritCommit.GERRIT_PATCH_KEY, "2");

    GerritNotifier gerritNotifier = new GerritNotifier(settings, server, sonarResultEvaluator);

    mockStatic(SshConnectionFactory.class);
    SshConnection sshConnection = mock(SshConnection.class);

    // when
    when(sshConnection.isConnected()).thenReturn(true);
    when(sshConnection.isAuthenticated()).thenReturn(true);
    when(sshConnection.isSessionOpen()).thenReturn(true);
    when(SshConnectionFactory.getConnection((GerritConnection) any())).thenReturn(sshConnection);
    when(sshConnection.executeCommand(anyString())).thenReturn("OK");

    when(sonarResultEvaluator.getResult(context, URL)).thenReturn(
        new SonarAnalysisResult("message", SonarAnalysisStatus.NO_PROBLEMS));

    gerritNotifier.executeOn(project, context);
View Full Code Here

Examples of com.sonymobile.tools.gerrit.gerritevents.ssh.SshConnection

                password = gerritAuthKeyFilePassword;
            }
            if (SshUtil.checkPassPhrase(file, password)) {
                if (file.exists() && file.isFile()) {
                    try {
                        final SshConnection sshConnection = SshConnectionFactory.getConnection(
                                gerritHostName,
                                gerritSshPort,
                                gerritProxy,
                                new Authentication(file, gerritUserName, password));
                        ExecutorService service = Executors.newFixedThreadPool(THREADS_FOR_TEST_CONNECTION);
                        Future<Integer> future = service.submit(new Callable<Integer>() {
                            @Override
                            public Integer call() throws Exception {
                                return sshConnection.executeCommandReader(GerritConnection.CMD_STREAM_EVENTS).read();
                            }
                        });
                        int readChar;
                        try {
                            readChar = future.get(TIMEOUT_FOR_TEST_CONNECTION, TimeUnit.SECONDS);
                        } catch (TimeoutException ex) {
                            readChar = 0;
                        } finally {
                            sshConnection.disconnect();
                        }
                        if (readChar < 0) {
                            return FormValidation.error(Messages.StreamEventsCapabilityException(gerritUserName));
                        } else {
                            return FormValidation.ok(Messages.Success());
View Full Code Here

Examples of com.sonymobile.tools.gerrit.gerritevents.ssh.SshConnection

    public void run() {
        while (!shutdown) {
            try {
                if (isConnected()) {
                    IGerritHudsonTriggerConfig activeConfig = getConfig();
                    SshConnection sshConnection = SshConnectionFactory.getConnection(
                            activeConfig.getGerritHostName(),
                            activeConfig.getGerritSshPort(),
                            activeConfig.getGerritProxy(),
                            activeConfig.getGerritAuthentication()
                    );
                    setGerritProjects(readProjects(sshConnection.executeCommandReader(GERRIT_LS_PROJECTS)));
                    sshConnection.disconnect();
                }
            } catch (SshException ex) {
                 logger.warn("Could not connect to Gerrit server when updating Gerrit project list: ", ex);
            } catch (IOException ex) {
                logger.error("Could not read stream with Gerrit projects: ", ex);
View Full Code Here

Examples of org.platformlayer.ops.ssh.SshConnection

  private SshConnection getSshConnection(String host, String user, KeyPair sshKeyPair) throws OpsException {
    OpsSystem opsSystem = OpsContext.get().getOpsSystem();
    ISshContext sshContext = opsSystem.getSshContext();

    SshConnection sshConnection = sshContext.getSshConnection(user);
    try {
      sshConnection.setHost(InetAddress.getByName(host));
    } catch (UnknownHostException e) {
      throw new OpsException("Error resolving address: " + host, e);
    }

    sshConnection.setKeyPair(sshKeyPair);

    // TODO: Verify the server key once we've learned it
    IServerKeyVerifier serverKeyVerifier = new AcceptAllLearningServerKeyVerifier();
    sshConnection.setServerKeyVerifier(serverKeyVerifier);

    return sshConnection;
  }
View Full Code Here

Examples of org.platformlayer.ops.ssh.SshConnection

    try {
      String commandString = command.buildCommandString();
      TimeSpan timeout = command.getTimeout();

      if (command.getKeyPair() != null) {
        SshConnection agentConnection = sshConnection.buildAgentConnection(command.getKeyPair());
        try {
          return agentConnection.sshExecute(commandString, timeout);
        } finally {
          agentConnection.close();
        }
      } else {
        return sshConnection.sshExecute(commandString, timeout);
      }
    } catch (IOException e) {
View Full Code Here

Examples of org.platformlayer.ops.ssh.SshConnection

  @Override
  public OpsTarget getTarget(String user, KeyPair sshKeyPair) throws OpsException {
    OpsSystem opsSystem = OpsContext.get().getOpsSystem();
    ISshContext sshContext = opsSystem.getSshContext();

    SshConnection sshConnection = sshContext.getSshConnection(user);

    String address = getNetworkPoint().getBestAddress(NetworkPoint.forMe());
    try {
      sshConnection.setHost(InetAddress.getByName(address));
    } catch (UnknownHostException e) {
      throw new OpsException("Error resolving address: " + address, e);
    }

    sshConnection.setKeyPair(sshKeyPair);

    File tempDirBase = new File("/tmp/");

    // TODO: Verify the server key once we've learned it
    IServerKeyVerifier serverKeyVerifier = new AcceptAllLearningServerKeyVerifier();
    sshConnection.setServerKeyVerifier(serverKeyVerifier);
    return new SshOpsTarget(tempDirBase, this, sshConnection);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.