com.netflix.hystrix.HystrixInvokableInfo Java Examples

The following examples show how to use com.netflix.hystrix.HystrixInvokableInfo. 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: ConnectionActionHandlerTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSetInoutOutputShapesToAnyIfMetadataCallFails() {
    @SuppressWarnings({"unchecked", "rawtypes"})
    final Class<Entity<Map<String, Object>>> entityType = (Class) Entity.class;
    ArgumentCaptor.forClass(entityType);

    // simulates fallback return
    final DynamicActionMetadata fallback = new DynamicActionMetadata.Builder().build();
    when(metadataCommand.execute()).thenReturn(fallback);
    when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(false);

    final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, Collections.emptyMap());

    @SuppressWarnings("unchecked")
    final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity();

    final ConnectorDescriptor descriptor = meta.getValue();
    assertThat(descriptor.getInputDataShape()).contains(ConnectionActionHandler.ANY_SHAPE);
    assertThat(descriptor.getOutputDataShape()).contains(salesforceOutputShape);
}
 
Example #2
Source File: ConnectionActionHandlerTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldConvertParameterFromIterableWithStringsToCommaDelimitedString() {
    final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder()
        .putProperty("sObjectName", Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Account", "Account"),
            DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Contact", "Contact")))
        .build();
    when(metadataCommand.execute()).thenReturn(suggestions);
    when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(true);


    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("sObjectName", Arrays.asList("Contact", "Account"));

    final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, parameters);

    assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode());
    assertThat(metadataCommandParameters).containsEntry("sObjectName", "Contact,Account");
}
 
Example #3
Source File: ConnectionActionHandlerTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldConvertParameterFromArrayOfStringsToCommaDelimitedString() {
    final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder()
        .putProperty("sObjectName", Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Account", "Account"),
            DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Contact", "Contact")))
        .build();
    when(metadataCommand.execute()).thenReturn(suggestions);
    when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(true);


    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("sObjectName", new String[] { "Contact", "Account" });

    final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, parameters);

    assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode());
    assertThat(metadataCommandParameters).containsEntry("sObjectName", "Contact,Account");
}
 
Example #4
Source File: ConnectionActionHandlerTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSupportOtherParameterTypes() {
    final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder()
        .putProperty("sObjectName", Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("1", "1"),
            DynamicActionMetadata.ActionPropertySuggestion.Builder.of("2", "2")))
        .build();
    when(metadataCommand.execute()).thenReturn(suggestions);
    when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(true);


    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("sObjectName", 1);

    handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, parameters);
    assertThat(metadataCommandParameters).containsEntry("sObjectName", "1");
}
 
Example #5
Source File: CommandWithFallbackViaNetwork.java    From tools-journey with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    HystrixRequestContext context = HystrixRequestContext.initializeContext();
    try {
        assertEquals(null, new CommandWithFallbackViaNetwork(1).execute());

        HystrixInvokableInfo<?> command1 = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixInvokableInfo<?>[2])[0];
        assertEquals("GetValueCommand", command1.getCommandKey().name());
        assertTrue(command1.getExecutionEvents().contains(HystrixEventType.FAILURE));

        HystrixInvokableInfo<?> command2 = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixInvokableInfo<?>[2])[1];
        assertEquals("GetValueFallbackCommand", command2.getCommandKey().name());
        assertTrue(command2.getExecutionEvents().contains(HystrixEventType.FAILURE));
    } finally {
        context.shutdown();
    }
}
 
Example #6
Source File: QuickStart.java    From javabase with Apache License 2.0 6 votes vote down vote up
private static void commandWithFallbackViaNetworkTest() {
    HystrixRequestContext context = HystrixRequestContext.initializeContext();
    try {
         log.info(new CommandWithFallbackViaNetwork(1).execute());

        HystrixInvokableInfo<?> command1 = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixInvokableInfo<?>[2])[0];
        log.info(command1.getCommandKey().name());
        log.info(""+command1.getExecutionEvents().contains(HystrixEventType.FAILURE));

        HystrixInvokableInfo<?> command2 = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixInvokableInfo<?>[2])[1];
        log.info(command2.getCommandKey().name());
        log.info(""+command2.getExecutionEvents().contains(HystrixEventType.FAILURE));
    } finally {
        context.shutdown();
    }
}
 
Example #7
Source File: DBIExceptionLogger.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Override
protected <T> void logException(DBIException exception, HystrixInvokableInfo<T> command) {
    DBI_ERRORS.mark();
    final Throwable cause = Throwables.getRootCause(exception);
    if (cause instanceof SQLException) {
        sqlExceptionLogger.logSQLException((SQLException) cause, command);
    } else {
        logger.error("DBI problem running command: {}:{}", command.getCommandKey(), command.getClass().getSimpleName(), exception);
    }
}
 
Example #8
Source File: RecommendationServiceFallbackHandler.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<ByteBuf> getFallback(HystrixInvokableInfo<?> hystrixInfo, Map<String, Object> requestProperties) {
    byte[] bytes = Movie.ORANGE_IS_THE_NEW_BLACK.toString().getBytes(Charset.defaultCharset());
    ByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.buffer(bytes.length);
    byteBuf.writeBytes(bytes);
    return Observable.just(byteBuf);
}
 
Example #9
Source File: ExceptionLoggingCommandHook.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> Exception onExecutionError(HystrixInvokable<T> commandInstance, Exception exception) {
    for (ExceptionLogger<? extends Exception> logger: exceptionLoggers) {
        if (logger.canHandleException(exception) && isHystrixInvokableInfo(commandInstance)) {
            logger.log(exception, (HystrixInvokableInfo<T>)commandInstance);
            return exception;
        }
    }

    return exception;
}
 
Example #10
Source File: ExceptionLogger.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
/**
 * Actually log the exception
 * @throws IllegalStateException it relieves an exception that it can't log
 */
public <T> void log(Exception exception, HystrixInvokableInfo<T> commandInstance) {
    checkState(canHandleException(exception));

    logException((E) exception, commandInstance);
}
 
Example #11
Source File: DefaultExceptionLogger.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@Override
protected <T> void logException(Exception exception, HystrixInvokableInfo<T> commandInstance) {
    logger.warn("An exception occurred while executing {}:{}",
            commandInstance.getCommandKey().name(),
            commandInstance.getClass().getSimpleName(),
            exception);
}
 
Example #12
Source File: Meta.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public static <V> Meta<V> from(final V value, final HystrixInvokableInfo<V> metaInfo) {
    if (metaInfo.isFailedExecution()) {
        final Throwable executionException = metaInfo.getFailedExecutionException();
        return Meta.withError(value, executionException);
    } else if (metaInfo.isResponseTimedOut()) {
        final double timeout = metaInfo.getProperties().executionTimeoutInMilliseconds().get() / 1000.0;
        return Meta.withWarning(value, "The query could not be completed in " + timeout + " seconds.");
    } else if (metaInfo.isSuccessfulExecution()) {
        return Meta.verbatim(value);
    } else {
        return Meta.withWarning(value, "The query did not succeed");
    }
}
 
Example #13
Source File: ConnectionActionHandlerTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldProvideActionDefinition() {
    @SuppressWarnings({"unchecked", "rawtypes"})
    final Class<Entity<Map<String, Object>>> entityType = (Class) Entity.class;
    ArgumentCaptor.forClass(entityType);

    final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder()
        .putProperty("sObjectName", Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Account", "Account"),
            DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Contact", "Contact")))
        .build();
    when(metadataCommand.execute()).thenReturn(suggestions);
    when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(true);

    final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, Collections.emptyMap());

    assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode());

    @SuppressWarnings("unchecked")
    final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity();

    final ConnectorDescriptor enrichedDefinitioin = new ConnectorDescriptor.Builder()
        .createFrom(createOrUpdateSalesforceObjectDescriptor)
        .replaceConfigurationProperty("sObjectName",
            c -> c.addAllEnum(Arrays.asList(
                    ConfigurationProperty.PropertyValue.Builder.of("Account", "Account"),
                    ConfigurationProperty.PropertyValue.Builder.of("Contact", "Contact"))))
        .inputDataShape(ConnectionActionHandler.ANY_SHAPE)//
        .build();

    assertThat(meta.getValue()).isEqualTo(enrichedDefinitioin);
}
 
Example #14
Source File: ConnectionActionHandlerTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldElicitActionPropertySuggestions() {
    final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder()
        .putProperty("sObjectName",
            Collections.singletonList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Contact", "Contact")))
        .putProperty("sObjectIdName",
            Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("ID", "Contact ID"),
                DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Email", "Email"),
                DynamicActionMetadata.ActionPropertySuggestion.Builder.of("TwitterScreenName__c", "Twitter Screen Name")))
        .inputShape(salesforceContactShape)//
        .build();
    when(metadataCommand.execute()).thenReturn(suggestions);
    when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(true);

    final ConnectorDescriptor enrichedDefinitioin = new ConnectorDescriptor.Builder()
        .createFrom(createOrUpdateSalesforceObjectDescriptor)
        .replaceConfigurationProperty("sObjectName",
            c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Contact", "Contact")).defaultValue("Contact"))
        .replaceConfigurationProperty("sObjectIdName",
            c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("ID", "Contact ID")))
        .replaceConfigurationProperty("sObjectIdName",
            c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Email", "Email")))
        .replaceConfigurationProperty("sObjectIdName",
            c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("TwitterScreenName__c", "Twitter Screen Name")))
        .inputDataShape(salesforceContactShape)//
        .build();

    final Map<String, Object> parameters = new HashMap<>();
    parameters.put("sObjectName", "Contact");

    final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, parameters);

    assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode());

    @SuppressWarnings("unchecked")
    final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity();

    assertThat(meta.getValue()).isEqualTo(enrichedDefinitioin);
}
 
Example #15
Source File: ConnectionActionHandlerTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAddMetaAndSetStatusToBadRequestIfMetaCallFails() {
    @SuppressWarnings({"unchecked", "rawtypes"})
    final Class<Entity<Map<String, Object>>> entityType = (Class) Entity.class;
    ArgumentCaptor.forClass(entityType);

    // simulates fallback return
    final DynamicActionMetadata fallback = new DynamicActionMetadata.Builder().build();
    when(metadataCommand.execute()).thenReturn(fallback);
    when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(false);

    final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, Collections.emptyMap());

    assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode());

    @SuppressWarnings("unchecked")
    final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity();

    final ConnectorDescriptor descriptor = new ConnectorDescriptor.Builder().createFrom(createOrUpdateSalesforceObjectDescriptor)
        .inputDataShape(ConnectionActionHandler.ANY_SHAPE)//
        .outputDataShape(salesforceOutputShape)//
        .build();
    assertThat(meta.getValue()).isEqualTo(descriptor);
    final MetaData metadata = meta.getData();
    assertThat(metadata).isNotNull();
    assertThat(metadata.getType()).contains(MetaData.Type.WARNING);
    assertThat(metadata.getMessage()).contains("The query did not succeed");
}
 
Example #16
Source File: ExceptionLoggingCommandHookIntegrationTest.java    From tenacity with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> void logException(RuntimeException exception, HystrixInvokableInfo<T> commandInstance) {
    loggedExceptions.add(exception);
}
 
Example #17
Source File: ExceptionLoggingCommandHook.java    From tenacity with Apache License 2.0 4 votes vote down vote up
private <T> boolean isHystrixInvokableInfo(HystrixInvokable<T> commandInstance) {
    return commandInstance instanceof HystrixInvokableInfo;
}
 
Example #18
Source File: SQLExceptionLogger.java    From tenacity with Apache License 2.0 4 votes vote down vote up
<T> void logSQLException(SQLException exception, HystrixInvokableInfo<T> command) {
    for (Throwable throwable : exception) {
        logger.error("SQL problem running command: {}:{}", command.getCommandKey(), command.getClass().getSimpleName(), throwable);
    }
}
 
Example #19
Source File: ExceptionLoggerTest.java    From tenacity with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> void logException(RuntimeException exception, HystrixInvokableInfo<T> commandInstance) {
    loggedExceptions.add(exception);
}
 
Example #20
Source File: SQLExceptionLogger.java    From tenacity with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> void logException(SQLException exception, HystrixInvokableInfo<T> command) {
    SQL_ERROR.mark();
    logSQLException(exception, command);
}
 
Example #21
Source File: HystrixHandlers.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<Movie> getFallback(HystrixInvokableInfo<?> hystrixInfo, Map<String, Object> requestProperties) {
    return null;
}
 
Example #22
Source File: HttpMetaResponse.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Override
public HystrixInvokableInfo<?> getHystrixInfo() {
    return hystrixInfo;
}
 
Example #23
Source File: HttpMetaResponse.java    From ribbon with Apache License 2.0 4 votes vote down vote up
public HttpMetaResponse(O content, HystrixInvokableInfo<?> hystrixInfo) {
    this.content = content;
    this.hystrixInfo = hystrixInfo;
}
 
Example #24
Source File: HttpMetaRequest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Override
public HystrixInvokableInfo<?> getHystrixInfo() {
    return info;
}
 
Example #25
Source File: HttpMetaRequest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
public ResponseWithSubject(Subject<T, T> subject,
                           HystrixInvokableInfo<?> info) {
    this.subject = subject;
    this.info = info;
}
 
Example #26
Source File: ExceptionLogger.java    From tenacity with Apache License 2.0 2 votes vote down vote up
/**
 * @param exception the exception that you should log
 * @param commandInstance you get access to the command that failed, so you can specify what kind it was
 */
protected abstract <T> void logException(E exception, HystrixInvokableInfo<T> commandInstance);
 
Example #27
Source File: RibbonResponse.java    From ribbon with Apache License 2.0 votes vote down vote up
public abstract HystrixInvokableInfo<?> getHystrixInfo(); 
Example #28
Source File: FallbackHandler.java    From ribbon with Apache License 2.0 votes vote down vote up
public Observable<T> getFallback(HystrixInvokableInfo<?> hystrixInfo, Map<String, Object> requestProperties);