Search in sources :

Example 56 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class FreeIpaClientFactoryTest method setup.

@BeforeAll
static void setup() {
    InstanceMetaData metaData = new InstanceMetaData();
    METADATAS.add(metaData);
    metaData.setPrivateIp("127.0.0.1");
    metaData.setDiscoveryFQDN(FREEIPP_FQDN);
    metaData.setInstanceStatus(InstanceStatus.CREATED);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 57 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData 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 58 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class OneFreeIpaReachableAttemptTest method setup.

@BeforeEach
public void setup() {
    stack = new Stack();
    stack.setId(ID);
    InMemoryStateStore.putStack(ID, PollGroup.POLLABLE);
    InstanceMetaData instance1 = new InstanceMetaData();
    InstanceMetaData instance2 = new InstanceMetaData();
    instanceSet = Set.of(instance1, instance2);
    oneFreeIpaReachableAttemptUnderTest = new OneFreeIpaReachableAttempt(freeIpaInstanceHealthDetailsService, stack, instanceSet);
    response = new RPCResponse<>();
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 59 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class TerminationServiceTest method testRequestDeletionForInstances.

@Test
void testRequestDeletionForInstances() {
    Stack stack = mock(Stack.class);
    InstanceMetaData im1 = mock(InstanceMetaData.class);
    InstanceMetaData im2 = mock(InstanceMetaData.class);
    InstanceMetaData im3 = mock(InstanceMetaData.class);
    InstanceMetaData im4 = mock(InstanceMetaData.class);
    when(stack.getAllInstanceMetaDataList()).thenReturn(List.of(im1, im2, im3, im4));
    when(im1.isTerminated()).thenReturn(true);
    when(im2.isTerminated()).thenReturn(false);
    when(im3.isTerminated()).thenReturn(false);
    when(im4.isTerminated()).thenReturn(false);
    when(im2.getInstanceId()).thenReturn("i-2");
    when(im3.getInstanceId()).thenReturn("i-3");
    when(im4.getInstanceId()).thenReturn("i-4");
    underTest.requestDeletionForInstances(stack, List.of("i-3"));
    verify(im1, never()).setInstanceStatus(any());
    verify(im2, never()).setInstanceStatus(any());
    verify(im3).setInstanceStatus(eq(InstanceStatus.DELETE_REQUESTED));
    verify(im4, never()).setInstanceStatus(any());
    verify(instanceMetaDataService).saveAll(any());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 60 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class TerminationServiceTest method testFinalizeTerminationFroInstancesWithoutInstanceIds.

@Test
void testFinalizeTerminationFroInstancesWithoutInstanceIds() {
    Stack stack = mock(Stack.class);
    InstanceMetaData im1 = mock(InstanceMetaData.class);
    InstanceMetaData im2 = mock(InstanceMetaData.class);
    InstanceMetaData im3 = mock(InstanceMetaData.class);
    InstanceMetaData im4 = mock(InstanceMetaData.class);
    when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
    when(stack.getAllInstanceMetaDataList()).thenReturn(List.of(im1, im2, im3, im4));
    when(im1.isTerminated()).thenReturn(true);
    when(im2.isTerminated()).thenReturn(false);
    when(im3.isTerminated()).thenReturn(false);
    when(im4.isTerminated()).thenReturn(false);
    when(im2.getInstanceId()).thenReturn(null);
    when(im3.getInstanceId()).thenReturn("i-3");
    when(im4.getInstanceId()).thenReturn(null);
    when(clock.getCurrentTimeMillis()).thenReturn(1L);
    underTest.finalizeTerminationForInstancesWithoutInstanceIds(1L);
    verify(im2).setTerminationDate(any());
    verify(im2).setInstanceStatus(eq(InstanceStatus.TERMINATED));
    verify(im4).setTerminationDate(any());
    verify(im4).setInstanceStatus(eq(InstanceStatus.TERMINATED));
    verify(instanceMetaDataService).saveAll(any());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)163 Stack (com.sequenceiq.freeipa.entity.Stack)104 Test (org.junit.jupiter.api.Test)77 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)30 List (java.util.List)19 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)18 Inject (javax.inject.Inject)18 Set (java.util.Set)16 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)13 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)13 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)12 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)11 StackService (com.sequenceiq.freeipa.service.stack.StackService)10 ArrayList (java.util.ArrayList)10 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)9 HealthDetailsFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse)9 Operation (com.sequenceiq.freeipa.entity.Operation)9