Search in sources :

Example 1 with RetryException

use of com.sequenceiq.cloudbreak.retry.RetryException in project cloudbreak by hortonworks.

the class StartBindUserCreationHandlerTest method testRetryExceptionReceived.

@Test
public void testRetryExceptionReceived() {
    StackView stackView = new StackView();
    stackView.setId(1L);
    when(stackViewService.getById(1L)).thenReturn(stackView);
    Event<StartBindUserCreationEvent> event = new Event<>(new StartBindUserCreationEvent(1L));
    RetryException retryException = new RetryException();
    when(startBindUserCreationService.startBindUserCreation(stackView)).thenThrow(retryException);
    StackFailureEvent result = (StackFailureEvent) underTest.doAccept(new HandlerEvent<>(event));
    assertEquals(VALIDATE_KERBEROS_CONFIG_FAILED_EVENT.event(), result.selector());
    assertEquals(1L, result.getResourceId());
    assertEquals(retryException, result.getException());
}
Also used : StartBindUserCreationEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.StartBindUserCreationEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) StartBindUserCreationEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.StartBindUserCreationEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Event(reactor.bus.Event) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) RetryException(com.sequenceiq.cloudbreak.retry.RetryException) Test(org.junit.jupiter.api.Test)

Example 2 with RetryException

use of com.sequenceiq.cloudbreak.retry.RetryException in project cloudbreak by hortonworks.

the class ApplicationCreator method waitApplicationCreated.

@Retryable(value = RetryException.class, maxAttempts = 10, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000))
public void waitApplicationCreated(String accessToken, String tenantId, String objectId) {
    LOGGER.info("Checking the existence of the application: '{}'", objectId);
    Client client = ClientBuilder.newClient();
    WebTarget resource = client.target(GRAPH_WINDOWS + tenantId);
    Builder request = resource.path("/applications/" + objectId).queryParam("api-version", GRAPH_API_VERSION).request();
    request.accept(MediaType.APPLICATION_JSON);
    request.header("Authorization", "Bearer " + accessToken);
    try (Response response = request.get()) {
        if (response.getStatus() != HttpStatus.SC_OK) {
            throw new RetryException("App with objectId (" + objectId + ") hasn't been created yet");
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) RetryException(com.sequenceiq.cloudbreak.retry.RetryException) Retryable(org.springframework.retry.annotation.Retryable)

Example 3 with RetryException

use of com.sequenceiq.cloudbreak.retry.RetryException in project cloudbreak by hortonworks.

the class PrincipalCreator method checkTheExistenceOnGraph.

private void checkTheExistenceOnGraph(String accessToken, String objectId, String tenantId, Client client) {
    WebTarget resource = client.target(GRAPH_WINDOWS + tenantId);
    Builder request = resource.path("servicePrincipals/" + objectId).queryParam("api-version", GRAPH_API_VERSION).request();
    request.accept(MediaType.APPLICATION_JSON);
    request.header("Authorization", "Bearer " + accessToken);
    try (Response response = request.get()) {
        if (response.getStatus() != HttpStatus.SC_OK) {
            throw new RetryException("Principal with objectId (" + objectId + ") hasn't been created yet");
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) WebTarget(javax.ws.rs.client.WebTarget) RetryException(com.sequenceiq.cloudbreak.retry.RetryException)

Example 4 with RetryException

use of com.sequenceiq.cloudbreak.retry.RetryException in project cloudbreak by hortonworks.

the class PrincipalCreator method checkTheAvailabilityWithResourceLogin.

private void checkTheAvailabilityWithResourceLogin(String objectId, String tenantId, AzureApplication app, Client client) {
    WebTarget loginResource = client.target(LOGIN_MICROSOFTONLINE + tenantId);
    Map<String, String> formData = new HashMap<>();
    formData.put("grant_type", "client_credentials");
    formData.put("client_id", app.getAppId());
    formData.put("client_secret", app.getAzureApplicationCreationView().getAppSecret());
    formData.put("resource", app.getAzureApplicationCreationView().getAppIdentifierURI());
    try (Response loginResponse = loginResource.path("/oauth2/token").request().accept(MediaType.APPLICATION_JSON).header("Content-Type", "application/x-www-form-urlencoded").post(Entity.form(new MultivaluedHashMap<>(formData)))) {
        if (loginResponse.getStatus() != HttpStatus.SC_OK) {
            throw new RetryException("Principal with objectId (" + objectId + ") hasn't been available yet");
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) WebTarget(javax.ws.rs.client.WebTarget) RetryException(com.sequenceiq.cloudbreak.retry.RetryException)

Aggregations

RetryException (com.sequenceiq.cloudbreak.retry.RetryException)4 WebTarget (javax.ws.rs.client.WebTarget)3 Response (javax.ws.rs.core.Response)3 ClientBuilder (javax.ws.rs.client.ClientBuilder)2 Builder (javax.ws.rs.client.Invocation.Builder)2 StartBindUserCreationEvent (com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.StartBindUserCreationEvent)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)1 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)1 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)1 HashMap (java.util.HashMap)1 Client (javax.ws.rs.client.Client)1 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)1 Test (org.junit.jupiter.api.Test)1 Retryable (org.springframework.retry.annotation.Retryable)1 Event (reactor.bus.Event)1