예제 #1
0
 /**
  * Sends the IPMI message to the remote host.
  *
  * @param connectionHandle - {@link ConnectionHandle} associated with the remote host.
  * @param request - {@link IpmiCommandCoder} containing the request to be sent
  * @return ID of the message that will be also attached to the response to pair request with
  *     response if queue was not full and message was sent, -1 if sending of the message failed.
  * @throws ConnectionException when connection is in the state that does not allow to perform this
  *     operation.
  * @throws Exception when sending message to the managed system or initializing one of the
  *     cipherSuite's algorithms fails
  */
 public int sendMessage(ConnectionHandle connectionHandle, IpmiCommandCoder request)
     throws Exception {
   int tries = 0;
   int tag = -1;
   while (tries <= retries && tag < 0) {
     try {
       ++tries;
       while (tag < 0) {
         tag =
             connectionManager
                 .getConnection(connectionHandle.getHandle())
                 .sendIpmiCommand(request);
         if (tag < 0) {
           Thread.sleep(10); // tag < 0 means that MessageQueue is
           // full so we need to wait and retry
         }
       }
       logger.debug("Sending message with tag " + tag + ", try " + tries);
     } catch (IllegalArgumentException e) {
       throw e;
     } catch (Exception e) {
       logger.warn("Failed to send message, cause:", e);
       if (tries > retries) {
         throw e;
       }
     }
   }
   return tag;
 }
예제 #2
0
 /**
  * Establishes the session with the remote host.
  *
  * @param connectionHandle - {@link ConnectionHandle} associated with the remote host.
  * @param username - the username
  * @param password - password matching the username
  * @param bmcKey - the key that should be provided if the two-key authentication is enabled, null
  *     otherwise.
  * @throws ConnectionException when connection is in the state that does not allow to perform this
  *     operation.
  * @throws Exception when sending message to the managed system or initializing one of the
  *     cipherSuite's algorithms fails
  */
 public void openSession(
     ConnectionHandle connectionHandle, String username, String password, byte[] bmcKey)
     throws Exception {
   int tries = 0;
   boolean succeded = false;
   while (tries <= retries && !succeded) {
     try {
       ++tries;
       connectionManager.startSession(
           connectionHandle.getHandle(),
           connectionHandle.getCipherSuite(),
           connectionHandle.getPrivilegeLevel(),
           username,
           password,
           bmcKey);
       succeded = true;
     } catch (Exception e) {
       logger.warn("Failed to receive answer, cause:", e);
       if (tries > retries) {
         throw e;
       }
     }
   }
   return;
 }
예제 #3
0
 /**
  * Closes the session with the remote host if it is currently in open state.
  *
  * @param connectionHandle - {@link ConnectionHandle} associated with the remote host.
  * @throws ConnectionException when connection is in the state that does not allow to perform this
  *     operation.
  * @throws Exception when sending message to the managed system or initializing one of the
  *     cipherSuite's algorithms fails
  */
 public void closeSession(ConnectionHandle connectionHandle) throws Exception {
   if (!connectionManager.getConnection(connectionHandle.getHandle()).isSessionValid()) {
     return;
   }
   int tries = 0;
   boolean succeded = false;
   while (tries <= retries && !succeded) {
     try {
       ++tries;
       connectionManager.getConnection(connectionHandle.getHandle()).closeSession();
       succeded = true;
     } catch (Exception e) {
       logger.warn("Failed to receive answer, cause:", e);
       if (tries > retries) {
         throw e;
       }
     }
   }
   return;
 }
예제 #4
0
 /**
  * Gets {@link CipherSuite}s available for the connection with the remote host.
  *
  * @param connectionHandle {@link ConnectionHandle} to the connection created before
  * @see #createConnection(InetAddress)
  * @return list of the {@link CipherSuite}s that are allowed during the connection
  * @throws Exception when sending message to the managed system fails
  */
 public List<CipherSuite> getAvailableCipherSuites(ConnectionHandle connectionHandle)
     throws Exception {
   int tries = 0;
   List<CipherSuite> result = null;
   while (tries <= retries && result == null) {
     try {
       ++tries;
       result = connectionManager.getAvailableCipherSuites(connectionHandle.getHandle());
     } catch (Exception e) {
       logger.warn("Failed to receive answer, cause:", e);
       if (tries > retries) {
         throw e;
       }
     }
   }
   return result;
 }
예제 #5
0
 /**
  * Gets the authentication capabilities for the connection with the remote host.
  *
  * @param connectionHandle - {@link ConnectionHandle} associated with the host
  * @param cipherSuite - {@link CipherSuite} that will be used during the connection
  * @param requestedPrivilegeLevel - {@link PrivilegeLevel} that is requested for the session
  * @return - {@link GetChannelAuthenticationCapabilitiesResponseData}
  * @throws ConnectionException when connection is in the state that does not allow to perform this
  *     operation.
  * @throws Exception when sending message to the managed system fails
  */
 public GetChannelAuthenticationCapabilitiesResponseData getChannelAuthenticationCapabilities(
     ConnectionHandle connectionHandle,
     CipherSuite cipherSuite,
     PrivilegeLevel requestedPrivilegeLevel)
     throws Exception {
   int tries = 0;
   GetChannelAuthenticationCapabilitiesResponseData result = null;
   while (tries <= retries && result == null) {
     try {
       ++tries;
       result =
           connectionManager.getChannelAuthenticationCapabilities(
               connectionHandle.getHandle(), cipherSuite, requestedPrivilegeLevel);
       connectionHandle.setCipherSuite(cipherSuite);
       connectionHandle.setPrivilegeLevel(requestedPrivilegeLevel);
     } catch (Exception e) {
       logger.warn("Failed to receive answer, cause:", e);
       if (tries > retries) {
         throw e;
       }
     }
   }
   return result;
 }
예제 #6
0
 /**
  * Changes the timeout value for connection with the given handle.
  *
  * @param handle - {@link ConnectionHandle} associated with the remote host.
  * @param timeout - new timeout value in ms
  */
 public void setTimeout(ConnectionHandle handle, int timeout) {
   connectionManager.getConnection(handle.getHandle()).setTimeout(timeout);
 }
예제 #7
0
 /** Finalizes the connector and closes all connections. */
 public void tearDown() {
   connectionManager.close();
 }
예제 #8
0
 /** Closes the connection with the given handle */
 public void closeConnection(ConnectionHandle handle) {
   connectionManager.getConnection(handle.getHandle()).unregisterListener(this);
   connectionManager.closeConnection(handle.getHandle());
 }
예제 #9
0
 /**
  * Creates connection to the remote host.
  *
  * @param address - {@link InetAddress} of the remote host
  * @return handle to the connection to the remote host
  * @throws IOException when properties file was not found
  * @throws FileNotFoundException when properties file was not found
  */
 public ConnectionHandle createConnection(InetAddress address)
     throws FileNotFoundException, IOException {
   int handle = connectionManager.createConnection(address);
   connectionManager.getConnection(handle).registerListener(this);
   return new ConnectionHandle(handle);
 }