Java Code Examples for com.netflix.hystrix.HystrixCommand#execute()

The following examples show how to use com.netflix.hystrix.HystrixCommand#execute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreparationAPI.java    From data-prep with Apache License 2.0 6 votes vote down vote up
/**
 * Moves the step of specified id <i>stepId</i> after step of specified id <i>parentId</i> within the specified
 * preparation.
 *
 * @param preparationId the Id of the specified preparation
 * @param stepId the Id of the specified step to move
 * @param parentStepId the Id of the specified step which will become the parent of the step to move
 */
// formatter:off
@RequestMapping(value = "/api/preparations/{preparationId}/steps/{stepId}/order", method = POST,
        consumes = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Moves a step within a preparation just after the specified <i>parentStepId</i>",
        notes = "Moves a step within a preparation.")
@Timed
public void moveStep(@PathVariable("preparationId") final String preparationId,
        @ApiParam(value = "The current index of the action we want to move.") @PathVariable("stepId") String stepId,
        @ApiParam(value = "The current index of the action we want to move.") @RequestParam String parentStepId) {
    //@formatter:on

    LOG.info("Moving step {} after step {}, within preparation {}", stepId, parentStepId, preparationId);

    final HystrixCommand<String> command =
            getCommand(PreparationReorderStep.class, preparationId, stepId, parentStepId);
    command.execute();

    LOG.debug("Step {} moved after step {}, within preparation {}", stepId, parentStepId, preparationId);

}
 
Example 2
Source File: DataSetAPI.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/api/datasets/favorite/{id}", method = POST, produces = TEXT_PLAIN_VALUE)
@ApiOperation(value = "Set or Unset the dataset as favorite for the current user.", produces = TEXT_PLAIN_VALUE, //
        notes = "Specify if a dataset is or is not a favorite for the current user.")
@Timed
public Callable<String> favorite(
        @ApiParam(value = "Id of the favorite data set ") @PathVariable(value = "id") String id,
        @RequestParam(defaultValue = "false") @ApiParam(name = "unset",
                value = "When true, will remove the dataset from favorites, if false (default) this will set the dataset as favorite.") boolean unset) {
    return () -> {
        if (LOG.isDebugEnabled()) {
            LOG.debug((unset ? "Unset" : "Set") + " favorite dataset #{} (pool: {})...", id, getConnectionStats());
        }
        HystrixCommand<String> creation = getCommand(SetFavorite.class, id, unset);
        String result = creation.execute();
        LOG.debug("Set Favorite for user (can'tget user now) #{} done.", id);
        return result;
    };
}
 
Example 3
Source File: DataSetAPI.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/api/datasets/{id}", method = DELETE)
@ApiOperation(value = "Delete a data set by id",
        notes = "Delete a data set content based on provided id. Id should be a UUID returned by the list operation. Not valid or non existing data set id returns empty content.")
@Timed
public ResponseEntity<String> delete(@PathVariable(value = "id") @ApiParam(name = "id",
        value = "Id of the data set to delete") String dataSetId) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Delete dataset #{} (pool: {})...", dataSetId, getConnectionStats());
    }
    HystrixCommand<ResponseEntity<String>> deleteCommand = getCommand(DataSetDelete.class, dataSetId);
    try {
        return deleteCommand.execute();
    } finally {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Listing datasets (pool: {}) done.", getConnectionStats());
        }
    }
}
 
Example 4
Source File: DataSetAPI.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/api/datasets/{id}/copy", method = POST, produces = TEXT_PLAIN_VALUE)
@ApiOperation(value = "Copy the dataset.", produces = TEXT_PLAIN_VALUE,
        notes = "Copy the dataset, returns the id of the copied created data set.")
@Timed
public Callable<String> copy(@ApiParam(value = "Name of the copy") @RequestParam(required = false) String name,
        @ApiParam(value = "Id of the data set to update / create") @PathVariable(value = "id") String id) {
    return () -> {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Copying {} (pool: {})...", id, getConnectionStats());
        }

        HystrixCommand<String> creation = getCommand(CopyDataSet.class, id, name);
        String result = creation.execute();
        LOG.info("Dataset {} copied --> {} named '{}'", id, result, name);
        return result;
    };
}
 
Example 5
Source File: DataSetAPI.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/api/datasets/{id}", method = PUT, produces = TEXT_PLAIN_VALUE)
@ApiOperation(value = "Update a data set by id.", produces = TEXT_PLAIN_VALUE, //
        notes = "Create or update a data set based on content provided in PUT body with given id. For documentation purposes, body is typed as 'text/plain' but operation accepts binary content too. Returns the id of the newly created data set.")
@Timed
public Callable<String> createOrUpdateById(
        @ApiParam(
                value = "User readable name of the data set (e.g. 'Finance Report 2015', 'Test Data Set').") @RequestParam(
                        defaultValue = "", required = false) String name,
        @ApiParam(value = "Id of the data set to update / create") @PathVariable(value = "id") String id,
        @ApiParam(value = "Size of the data set, in bytes.") @RequestParam(defaultValue = "0") long size,
        @ApiParam(value = "content") InputStream dataSetContent) {
    return () -> {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating or updating dataset #{} (pool: {})...", id, getConnectionStats());
        }
        HystrixCommand<String> creation = getCommand(CreateOrUpdateDataSet.class, id, name, size, dataSetContent);
        String result = creation.execute();
        LOG.debug("Dataset creation or update for #{} done.", id);
        return result;
    };
}
 
Example 6
Source File: MailServiceAPI.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/api/mail", method = PUT)
@ApiOperation(value = "Send feedback to Talend")
@Timed
public void mailTo(@RequestBody MailDetails mailDetails) {
    if (mailDetails.isEmpty()) {
        throw new TDPException(APIErrorCodes.UNABLE_TO_GET_MAIL_DETAILS);
    }
    try {

        final HystrixCommand<Void> sendFeedback = getCommand(MailToCommand.class, mailDetails);
        sendFeedback.execute();

    } catch (Exception e) {
        throw new TDPException(APIErrorCodes.UNABLE_TO_SEND_MAIL, e);
    }

}
 
Example 7
Source File: HystrixWithoutConcurrencyStrategyTests.java    From servicecomb-pack with Apache License 2.0 6 votes vote down vote up
@Test
public void testCircuitBreakerWithoutServiceCombConcurrencyStrategy() {

  for (int i = 0; i < 5; i++) {
    try {
      omegaContext.newGlobalTxId();
      HystrixCommand<String> command = new HystrixConcurrencyStrategyTests.TestCircuitBreakerCommand(
          "testCircuitBreaker", omegaContext);
      String result = command.execute();
      //after core thread all invoked (3 times) ,globalTxId can not be inheritable
      if (i > 2) {
        Assert.assertNotEquals(result, omegaContext.globalTxId());
      } else {
        Assert.assertEquals(result, omegaContext.globalTxId());
      }
    } finally {
      omegaContext.clear();
    }
  }
}
 
Example 8
Source File: PreparationAPI.java    From data-prep with Apache License 2.0 6 votes vote down vote up
/**
 * Copy the steps from the another preparation to this one.
 * <p>
 * This is only allowed if this preparation has no steps.
 *
 * @param id the preparation id to update.
 * @param from the preparation id to copy the steps from.
 */
//@formatter:off
@RequestMapping(value = "/api/preparations/{id}/steps/copy", method = PUT)
@ApiOperation(value = "Copy the steps from another preparation", notes = "Copy the steps from another preparation if this one has no steps.")
@Timed
public void copyStepsFrom(@ApiParam(value="the preparation id to update") @PathVariable("id")String id,
                          @ApiParam(value = "the preparation to copy the steps from.") @RequestParam String from) {
//@formatter:on

    LOG.debug("copy preparations steps from {} to {}", from, id);

    final HystrixCommand<Void> command = getCommand(PreparationCopyStepsFrom.class, id, from);
    command.execute();

    LOG.info("preparation's steps copied from {} to {}", from, id);
}
 
Example 9
Source File: PreparationAPI.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/api/preparations/{preparationId}/lock", method = PUT, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Mark a preparation as locked by a user.",
        notes = "Does not return any value, client may expect successful operation based on HTTP status code.")
@Timed
public void lockPreparation(@PathVariable(value = "preparationId") @ApiParam(name = "preparationId",
        value = "Preparation id.") final String preparationId) {

    if (LOG.isDebugEnabled()) {
        LOG.debug("Locking preparation #{}...", preparationId);
    }

    final HystrixCommand<Void> command = getCommand(PreparationLock.class, preparationId);
    command.execute();

    if (LOG.isDebugEnabled()) {
        LOG.debug("Locked preparation #{}...", preparationId);
    }
}
 
Example 10
Source File: PreparationAPI.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/api/preparations/{id}/actions/{stepId}", method = DELETE,
        produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Delete an action in the preparation.",
        notes = "Does not return any value, client may expect successful operation based on HTTP status code.")
@Timed
public void deletePreparationAction(
        @PathVariable(value = "id") @ApiParam(name = "id", value = "Preparation id.") final String preparationId,
        @PathVariable(value = "stepId") @ApiParam(name = "stepId",
                value = "Step id to delete.") final String stepId) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleting preparation action at step #{} (pool: {} ) ...", stepId, //
                getConnectionStats());
    }

    final HystrixCommand<Void> command = getCommand(PreparationDeleteAction.class, preparationId, stepId);
    command.execute();

    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleted preparation action at step #{} (pool: {} ) ...", stepId, //
                getConnectionStats());
    }
}
 
Example 11
Source File: ExceptionLoggingCommandHookIntegrationTest.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Test
public void loggerLogsOnExpectedException() throws Exception {
    HystrixPlugins.getInstance().registerCommandExecutionHook(new ExceptionLoggingCommandHook(exceptionLogger));
    final HystrixCommand<String> failingCommand = new TenacityFailingCommand();

    failingCommand.execute();

    final List<RuntimeException> loggedExceptions = exceptionLogger.getLoggedExceptions();
    assertEquals(1, loggedExceptions.size());
    assertTrue(loggedExceptions.get(0).getClass().equals(RuntimeException.class));
}
 
Example 12
Source File: CommonAPI.java    From data-prep with Apache License 2.0 5 votes vote down vote up
/**
 * Get the async method status
 */
@RequestMapping(value = "/api/{service}/queue/{id}", method = GET, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get async method status.")
@Timed
public AsyncExecutionMessage getQueue(
        @PathVariable(value = "service") @ApiParam(name = "service", value = "service name") String service,
        @PathVariable(value = "id") @ApiParam(name = "id", value = "queue id.") String id) {
    HystrixCommand<AsyncExecutionMessage> queueStatusCommand =
            getCommand(QueueStatusCommand.class, GenericCommand.ServiceType.valueOf(service.toUpperCase()), id);
    return queueStatusCommand.execute();
}
 
Example 13
Source File: AbstractVersionSupplier.java    From data-prep with Apache License 2.0 5 votes vote down vote up
/**
 * Call the version service on the given service: dataset, preparation or transformation.
 *
 * @param serviceName the name of the service
 * @return the version of the called service
 */
protected Version callVersionService(String serviceUrl, String serviceName, String entryPoint) {
    HystrixCommand<Version> versionCommand = context.getBean(VersionCommand.class, serviceUrl, entryPoint);
    final Version version = versionCommand.execute();
    version.setServiceName(serviceName);
    return version;
}
 
Example 14
Source File: HystrixCommandTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void execute() throws Exception {
    final String name = "Pinpoint";
    final String expectedMessage = HystrixTestHelper.sayHello(name);
    HystrixCommand<String> helloCommand = SayHelloCommand.create(commandGroup, name);
    String actualMessage = helloCommand.execute();
    Assert.assertEquals(expectedMessage, actualMessage);

    HystrixTestHelper.waitForSpanDataFlush();
}
 
Example 15
Source File: HystrixCommandTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void executeWithException(Exception expectedException) throws Exception {
    final String name = "Pinpoint";
    final String expectedFallbackMessage = HystrixTestHelper.fallbackHello(name);
    HystrixCommand<String> helloCommand = SayHelloCommand.createForException(commandGroup, name, expectedException);
    String actualMessage = helloCommand.execute();
    Assert.assertEquals(expectedFallbackMessage, actualMessage);

    HystrixTestHelper.waitForSpanDataFlush();
}
 
Example 16
Source File: HystrixCommandTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void executeWithShortCircuit() throws Exception {
    final String name = "Pinpoint";
    final String expectedFallbackMessage = HystrixTestHelper.fallbackHello(name);
    HystrixCommand<String> helloCommand = SayHelloCommand.createForShortCircuit(commandGroup, name);
    String actualMessage = helloCommand.execute();
    Assert.assertEquals(expectedFallbackMessage, actualMessage);

    HystrixTestHelper.waitForSpanDataFlush();
}
 
Example 17
Source File: DataSetAPI.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/api/datasets/{id}/metadata", method = PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Update a data set metadata by id.", consumes = MediaType.APPLICATION_JSON_VALUE,
        produces = MediaType.APPLICATION_JSON_VALUE, //
        notes = "Update a data set metadata based on content provided in PUT body with given id. For documentation purposes. Returns the id of the updated data set metadata.")
@Timed
public void updateMetadata(
        @ApiParam(value = "Id of the data set metadata to be updated") @PathVariable(value = "id") String id,
        @ApiParam(value = "content") InputStream dataSetContent) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating or updating dataset #{} (pool: {})...", id, getConnectionStats());
    }
    HystrixCommand<String> updateDataSetCommand = getCommand(UpdateDataSet.class, id, dataSetContent);
    updateDataSetCommand.execute();
    LOG.debug("Dataset creation or update for #{} done.", id);
}
 
Example 18
Source File: ExceptionLoggingCommandHookIntegrationTest.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@Test
public void loggerDoesntLogIfItsNotExpected() throws Exception {
    HystrixPlugins.getInstance().registerCommandExecutionHook(new ExceptionLoggingCommandHook(exceptionLogger));
    final HystrixCommand<String> failingCommand = new TenacityFailingWithIOException();

    failingCommand.execute();

    final List<RuntimeException> loggedExceptions = exceptionLogger.getLoggedExceptions();
    assertTrue(loggedExceptions.isEmpty());
}
 
Example 19
Source File: HystrixConcurrencyStrategyTests.java    From servicecomb-pack with Apache License 2.0 5 votes vote down vote up
@Test
public void testCircuitBreaker() {
  for (int i = 0; i < 5; i++) {
    try {
      omegaContext.newGlobalTxId();
      HystrixCommand<String> command = new TestCircuitBreakerCommand("testCircuitBreaker",
          omegaContext);
      String result = command.execute();
      //inheritable GlobalTxId
      Assert.assertEquals(result, omegaContext.globalTxId());
    } finally {
      omegaContext.clear();
    }
  }
}
 
Example 20
Source File: HystrixExamples.java    From vertx-circuit-breaker with Apache License 2.0 4 votes vote down vote up
public void exampleHystrix1() {
  HystrixCommand<String> someCommand = getSomeCommandInstance();
  String result = someCommand.execute();
}