public void Execute(IAquilesCommand command) { if (command != null) { this.ExecuteCommand(command); } else { throw new ArgumentNullException("command"); } }
private void ExecuteCommand(IAquilesCommand command) { long startedTicks = DateTime.Now.Ticks; command.ValidateInput(cluster.KeySpaces); bool isClientStillHealthy = false; bool openedInScope = false; bool shouldRetry = false; do { openedInScope = this.OpenCassandraClientConnection(openedInScope); try { this.logger.Debug("executing command."); command.Execute(this.cassandraClient.InnerClient); isClientStillHealthy = true; shouldRetry = false; } catch (NotFoundException ex) { //WTF?? "not found" should be trapped. string error = BuildExceptionMessage(ex); logger.Error(error, ex); // despite this command failed, the connection is still usable. isClientStillHealthy = true; throw new AquilesException(error, ex); } catch (InvalidRequestException ex) { //WTF?? "invalid request" should checked on the command method "ValidateRequest" string error = BuildExceptionMessage(ex, ex.Why); logger.Error(error, ex); // despite this command failed, the connection is still usable. isClientStillHealthy = true; throw new AquilesException(error, ex); } catch (UnavailableException ex) { //WTF?? Cassandra cannot ensure object replication state? string error = BuildExceptionMessage(ex); logger.Error(error, ex); throw new AquilesException(error, ex); } catch (TimedOutException ex) { //WTF?? Cassandra timeout? string error = BuildExceptionMessage(ex); logger.Error(error, ex); throw new AquilesException(error, ex); } catch (TApplicationException ex) { // client thrift version does not match server version? string error = BuildExceptionMessage(ex); logger.Error(error, ex); throw new AquilesException(error, ex); } catch (AuthenticationException ex) { // invalid credentials string error = BuildExceptionMessage(ex, ex.Why); logger.Error(error, ex); // despite this command failed, the connection is still usable. isClientStillHealthy = true; throw new AquilesException(error, ex); } catch (AuthorizationException ex) { // user does not have access to keyspace string error = BuildExceptionMessage(ex, ex.Why); logger.Error(error, ex); // despite this command failed, the connection is still usable. isClientStillHealthy = true; throw new AquilesException(error, ex); } catch (IOException ex) { // i got the client, it was opened but the node crashed or something if (openedInScope) { logger.Warn(logger.StringFormatInvariantCulture("Exception '{0}', retrying on a different connection.", ex), ex); shouldRetry = true; } else { string error = BuildExceptionMessage(ex); logger.Error(error, ex); // despite this command failed, the connection is still usable. throw new AquilesException(error, ex); } } finally { this.isClientHealthy = isClientStillHealthy; if (openedInScope) { this.logger.Debug("connection opened in scope, closing."); this.Close(); } } } while (shouldRetry); TimeSpan duration = new TimeSpan(DateTime.Now.Ticks - startedTicks); logger.Info(logger.StringFormatInvariantCulture("Command '{0}' took {1} ms.", command, duration.Milliseconds)); }