Search in sources :

Example 11 with UpscaleFailureEvent

use of com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent in project cloudbreak by hortonworks.

the class ValidateInstancesHealthHandlerTest method testExceptionDuringHealthCheck.

@Test
public void testExceptionDuringHealthCheck() throws FreeIpaClientException {
    Stack stack = new Stack();
    stack.setId(1L);
    when(stackService.getStackById(1L)).thenReturn(stack);
    List<String> instanceIds = List.of("im1", "im2");
    InstanceMetaData im1 = new InstanceMetaData();
    im1.setInstanceId("im1");
    im1.setDiscoveryFQDN("im1Fqdn");
    InstanceMetaData im2 = new InstanceMetaData();
    im2.setInstanceId("im2");
    im2.setDiscoveryFQDN("im2Fqdn");
    when(instanceMetaDataService.getNotTerminatedByInstanceIds(1L, instanceIds)).thenReturn(Set.of(im1, im2));
    when(healthService.getInstanceHealthDetails(stack, im1)).thenReturn(createHealthyNodeDetail(im1));
    when(healthService.getInstanceHealthDetails(stack, im2)).thenThrow(new FreeIpaClientException("nono"));
    ValidateInstancesHealthEvent validateInstancesHealthEvent = new ValidateInstancesHealthEvent(1L, instanceIds);
    UpscaleFailureEvent result = (UpscaleFailureEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(validateInstancesHealthEvent)));
    assertEquals(1L, result.getResourceId());
    assertEquals(PHASE, result.getFailedPhase());
    assertTrue(result.getSuccess().contains("im1"));
    assertEquals(1, result.getFailureDetails().size());
    assertEquals("nono", result.getFailureDetails().get("im2"));
    assertEquals("Unhealthy instances found: [im2]", result.getException().getMessage());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) ValidateInstancesHealthEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 12 with UpscaleFailureEvent

use of com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent in project cloudbreak by hortonworks.

the class FreeIpaUpscaleActions method tlsSetupAction.

@Bean(name = "UPSCALE_TLS_SETUP_STATE")
public Action<?, ?> tlsSetupAction() {
    return new AbstractUpscaleAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Setting up TLS");
            StackEvent event;
            try {
                if (!stack.getTunnel().useCcm()) {
                    Set<InstanceMetaData> newInstancesMetaData = stack.getInstanceGroups().stream().flatMap(instanceGroup -> instanceGroup.getAllInstanceMetaData().stream()).filter(this::isNewInstancesWithoutTlsCert).collect(Collectors.toSet());
                    for (InstanceMetaData gwInstance : newInstancesMetaData) {
                        tlsSetupService.setupTls(stack.getId(), gwInstance);
                    }
                }
                event = new StackEvent(UpscaleFlowEvent.UPSCALE_TLS_SETUP_FINISHED_EVENT.event(), stack.getId());
            } catch (Exception e) {
                LOGGER.error("Failed to setup TLS", e);
                event = new UpscaleFailureEvent(stack.getId(), "Setting ups TLS", Set.of(), Map.of(), e);
            }
            sendEvent(context, event.selector(), event);
        }

        private boolean isNewInstancesWithoutTlsCert(InstanceMetaData instanceMetaData) {
            return instanceMetaData.getInstanceStatus().equals(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus.CREATED) && Objects.isNull(instanceMetaData.getServerCert());
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent) Map(java.util.Map) ClientErrorException(javax.ws.rs.ClientErrorException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Bean(org.springframework.context.annotation.Bean)

Example 13 with UpscaleFailureEvent

use of com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent in project cloudbreak by hortonworks.

the class BootstrapMachinesFailedToUpscaleFailureEventConverter method convert.

@Override
public UpscaleFailureEvent convert(Object payload) {
    BootstrapMachinesFailed result = (BootstrapMachinesFailed) payload;
    UpscaleFailureEvent event = new UpscaleFailureEvent(result.getResourceId(), "Bootstrapping machines", Set.of(), Map.of(), new Exception("Payload failed: " + payload));
    return event;
}
Also used : BootstrapMachinesFailed(com.sequenceiq.freeipa.flow.freeipa.provision.event.bootstrap.BootstrapMachinesFailed) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent)

Example 14 with UpscaleFailureEvent

use of com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent in project cloudbreak by hortonworks.

the class PostInstallFreeIpaFailedToUpscaleFailureEventConverter method convert.

@Override
public UpscaleFailureEvent convert(Object payload) {
    PostInstallFreeIpaFailed result = (PostInstallFreeIpaFailed) payload;
    UpscaleFailureEvent event = new UpscaleFailureEvent(result.getResourceId(), "Post installing FreeIPA", Set.of(), Map.of(), new Exception("Payload failed: " + payload));
    return event;
}
Also used : PostInstallFreeIpaFailed(com.sequenceiq.freeipa.flow.freeipa.provision.event.postinstall.PostInstallFreeIpaFailed) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent)

Example 15 with UpscaleFailureEvent

use of com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent in project cloudbreak by hortonworks.

the class ValidateInstancesHealthHandlerTest method testUnHealthy.

@Test
public void testUnHealthy() throws FreeIpaClientException {
    Stack stack = new Stack();
    stack.setId(1L);
    when(stackService.getStackById(1L)).thenReturn(stack);
    List<String> instanceIds = List.of("im1", "im2");
    InstanceMetaData im1 = new InstanceMetaData();
    im1.setInstanceId("im1");
    im1.setDiscoveryFQDN("im1Fqdn");
    InstanceMetaData im2 = new InstanceMetaData();
    im2.setInstanceId("im2");
    im2.setDiscoveryFQDN("im2Fqdn");
    when(instanceMetaDataService.getNotTerminatedByInstanceIds(1L, instanceIds)).thenReturn(Set.of(im1, im2));
    when(healthService.getInstanceHealthDetails(stack, im1)).thenReturn(createHealthyNodeDetail(im1));
    NodeHealthDetails unhealthy = createHealthyNodeDetail(im2);
    unhealthy.setStatus(InstanceStatus.UNHEALTHY);
    unhealthy.setIssues(List.of("bad"));
    when(healthService.getInstanceHealthDetails(stack, im2)).thenReturn(unhealthy);
    ValidateInstancesHealthEvent validateInstancesHealthEvent = new ValidateInstancesHealthEvent(1L, instanceIds);
    UpscaleFailureEvent result = (UpscaleFailureEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(validateInstancesHealthEvent)));
    assertEquals(1L, result.getResourceId());
    assertEquals(PHASE, result.getFailedPhase());
    assertTrue(result.getSuccess().contains("im1"));
    assertEquals(1, result.getFailureDetails().size());
    assertEquals("bad", result.getFailureDetails().get("im2"));
    assertEquals("Unhealthy instances found: [im2]", result.getException().getMessage());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) NodeHealthDetails(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails) ValidateInstancesHealthEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

UpscaleFailureEvent (com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent)16 Stack (com.sequenceiq.freeipa.entity.Stack)7 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)5 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)5 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)5 Map (java.util.Map)5 Bean (org.springframework.context.annotation.Bean)5 OperationException (com.sequenceiq.cloudbreak.service.OperationException)4 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)4 ValidateInstancesHealthEvent (com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent)4 ClientErrorException (javax.ws.rs.ClientErrorException)4 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)3 CollectMetadataResult (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)2 WebApplicationExceptionMessageExtractor (com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor)2 EnvironmentEndpoint (com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)2 Flow (com.sequenceiq.flow.core.Flow)2 FlowParameters (com.sequenceiq.flow.core.FlowParameters)2 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)2 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)2 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)2