private SecondaryCommand(int id) {
   super(
       Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("SystemX"))
           .andCommandKey(HystrixCommandKey.Factory.asKey("SecondaryCommand"))
           .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey("SecondaryCommand"))
           .andCommandPropertiesDefaults(
               // we default to a 100ms timeout for secondary
               HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(100)));
   this.id = id;
 }
 /**
  * A failsafe GET request which takes the client, request and response handler to use to send the
  * request and send a response
  *
  * @param client the http client
  * @param request the request to make using the client
  * @param responseHandler the response handler
  */
 public FailSafeGetRequest(
     HttpClient client, HttpGet request, ResponseHandler<Address> responseHandler) {
   super(
       Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(PERSON_GROUP))
           .andCommandKey(HystrixCommandKey.Factory.asKey(ADDRESS_GET_COMMAND))
           .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(ADDRESS_CLIENT_POOL)));
   this.client = client;
   this.responseHandler = responseHandler;
   this.request = request;
 }
  public GetLogsCommand(String key) {
    super(
        Setter.withGroupKey(
                HystrixCommandGroupKey.Factory.asKey(FluxConstants.MIDDLETIER_HYSTRIX_GROUP))
            .andCommandKey(
                HystrixCommandKey.Factory.asKey(
                    FluxConstants.MIDDLETIER_HYSTRIX_GET_LOGS_COMMAND_KEY))
            .andThreadPoolKey(
                HystrixThreadPoolKey.Factory.asKey(FluxConstants.MIDDLETIER_HYSTRIX_THREAD_POOL)));

    this.key = key;
  }
 public CommandFacadeWithPrimarySecondary(int id) {
   super(
       Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("SystemX"))
           .andCommandKey(HystrixCommandKey.Factory.asKey("PrimarySecondaryCommand"))
           .andCommandPropertiesDefaults(
               // we want to default to semaphore-isolation since this wraps
               // 2 others commands that are already thread isolated
               HystrixCommandProperties.Setter()
                   .withExecutionIsolationStrategy(
                       HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)));
   this.id = id;
 }
  @Test
  public void should_gather_json_metrics() throws Exception {
    HystrixCommandKey hystrixCommandKey = HystrixCommandKey.Factory.asKey("commandKey");
    HystrixCommandMetrics.getInstance(
        hystrixCommandKey,
        HystrixCommandGroupKey.Factory.asKey("commandGroupKey"),
        new HystrixPropertiesCommandDefault(
            hystrixCommandKey, HystrixCommandProperties.defaultSetter()));
    given(this.discoveryClient.getLocalServiceInstance()).willReturn(this.serviceInstance);

    this.hystrixStreamTask.gatherMetrics();

    assertThat(this.hystrixStreamTask.jsonMetrics.isEmpty(), is(false));
  }
 public ShedLoadInventoryRequestCommand(
     final InventoryRequester inventoryRequester, final Store store, final Product product) {
   super(
       Setter.withGroupKey(
               HystrixCommandGroupKey.Factory.asKey(
                   ShedLoadInventoryRequestCommand.class.getSimpleName()))
           .andCommandKey(
               HystrixCommandKey.Factory.asKey(
                   ShedLoadInventoryRequestCommand.class.getSimpleName()))
           .andCommandPropertiesDefaults(
               HystrixCommandProperties.Setter()
                   .withCircuitBreakerRequestVolumeThreshold(10)
                   .withCircuitBreakerForceClosed(true)
                   .withExecutionTimeoutInMilliseconds(200)),
       inventoryRequester,
       store,
       product);
 }
  /**
   * Constructor for REST WebService HystrixCommand class, passing in all the parameters to execute
   * the call.
   *
   * @param commandName String the web service call name used to create the Hystrix Command Key
   * @param groupKeyName The group key under which this web service call falls
   * @param httpRequest Request method to be executed
   * @param httpClient HttpClient that executes the request
   * @param httpContext Http request execution context
   */
  public CommandRestResourceCall(
      final String groupKeyName,
      final String commandName,
      final HttpRequestBase httpRequest,
      final HttpClient httpClient,
      final HttpContext httpContext) {

    super(
        Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKeyName))
            .andCommandKey(HystrixCommandKey.Factory.asKey(commandName)));

    checkNullArguments(groupKeyName, commandName, httpRequest, httpClient, httpContext);

    this.commandName = commandName;
    this.httpRequest = httpRequest;
    this.httpClient = httpClient;
    this.httpContext = httpContext;
  }
Exemple #8
0
 /** [SLEUTH] TraceCommand */
 @Override
 public void bottle(Wort wort, String processId, String testCommunicationType) {
   log.info("I'm in the bottling service");
   log.info("Process ID from headers {}", processId);
   String groupKey = "bottling";
   String commandKey = "bottle";
   HystrixCommand.Setter setter =
       HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
           .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
   TestConfigurationHolder testConfigurationHolder = TestConfigurationHolder.TEST_CONFIG.get();
   new TraceCommand<Void>(tracer, setter) {
     @Override
     public Void doRun() throws Exception {
       TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder);
       log.info("Sending info to bottling service about process id [{}]", processId);
       bottlerService.bottle(wort, processId);
       return null;
     }
   }.execute();
 }
public abstract class BaseThriftPushCommand<T, K> extends HystrixCommand<T> {
  protected final TCNode tcnode;
  protected final List<K> list;

  protected BaseThriftPushCommand(TCNode tcnode, List<K> list) {
    super(setter);
    this.tcnode = tcnode;
    this.list = list;
  }

  private static final HystrixCommandGroupKey groupKey =
      HystrixCommandGroupKey.Factory.asKey("PushGroup");
  private static final HystrixCommandKey commandKey = HystrixCommandKey.Factory.asKey("node");
  private static final HystrixThreadPoolKey threadPoolKey =
      HystrixThreadPoolKey.Factory.asKey("T-ThriftPushGroup");

  private static final HystrixCommandProperties.Setter commandProperties =
      HystrixCommandProperties.Setter()
          .withExecutionTimeoutInMilliseconds(5000)
          .withFallbackEnabled(true);
  private static final HystrixThreadPoolProperties.Setter threadPoolProperties =
      HystrixThreadPoolProperties.Setter().withCoreSize(1).withMaxQueueSize(2);
  public static final HystrixCommand.Setter setter =
      HystrixCommand.Setter.withGroupKey(groupKey)
          .andCommandKey(commandKey)
          .andThreadPoolKey(threadPoolKey)
          .andCommandPropertiesDefaults(commandProperties)
          .andThreadPoolPropertiesDefaults(threadPoolProperties);

  public T push() {
    this.logPush(tcnode);
    return this.execute();
  }

  protected abstract void logPush(TCNode tcnode);
}
public class ThriftPingCommand extends HystrixCommand<Integer> {
  private static final HystrixCommandGroupKey groupKey =
      HystrixCommandGroupKey.Factory.asKey("ThriftPingGroup");
  private static final HystrixCommandKey commandKey = HystrixCommandKey.Factory.asKey("ping");
  private static final HystrixThreadPoolKey threadPoolKey =
      HystrixThreadPoolKey.Factory.asKey("T-ThriftPingGroup");

  private static final HystrixCommandProperties.Setter commandProperties =
      HystrixCommandProperties.Setter()
          .withExecutionTimeoutInMilliseconds(5000)
          .withFallbackEnabled(true);
  private static final HystrixThreadPoolProperties.Setter threadPoolProperties =
      HystrixThreadPoolProperties.Setter().withCoreSize(4).withMaxQueueSize(10);
  private static final HystrixCommand.Setter setter =
      HystrixCommand.Setter.withGroupKey(groupKey)
          .andCommandKey(commandKey)
          .andThreadPoolKey(threadPoolKey)
          .andCommandPropertiesDefaults(commandProperties)
          .andThreadPoolPropertiesDefaults(threadPoolProperties);

  private final TSNode tsnode;

  public ThriftPingCommand(TSNode tsnode) {
    super(setter);
    this.tsnode = tsnode;
  }

  @Loggable
  public int ping(TSNode tsnode) {
    return this.execute();
  }

  public int ping() {
    return this.ping(this.tsnode);
  }

  @Override
  protected Integer run() throws Exception {
    String host = this.tsnode.getHost();
    int port = this.tsnode.getPort();

    TSocket transport = new TSocket(host, port, 1000);
    TProtocol protocol = new TBinaryProtocol(transport);
    PoolAble.Client client = new PoolAble.Client(protocol);
    transport.open();
    int vNodes = -1;
    try {
      vNodes = client.ping();
    } finally {
      if (transport.isOpen()) {
        transport.close();
      }
    }
    return vNodes;
  }

  @Override
  protected Integer getFallback() {
    return this.getFallback(this.tsnode);
  }

  @Loggable(value = Loggable.WARN)
  protected Integer getFallback(TSNode tsnode) {
    return -1;
  }
}