Search in sources :

Example 61 with InstanceMetaData

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

the class RemoveHostsHandlerTest method testSendsSuccessMessageWhenRemovingHostAndIPAddressIsReusedAfterRepair.

@Test
void testSendsSuccessMessageWhenRemovingHostAndIPAddressIsReusedAfterRepair() throws Exception {
    CleanupEvent cleanupEvent = new CleanupEvent(STACK_ID, USERS, Set.of("example1.com"), ROLES, IPS, STATES_TO_SKIP, ACCOUNT_ID, OPERATION_ID, CLUSTER_NAME, ENVIRONMENT_CRN);
    RemoveHostsFromOrchestrationRequest request = new RemoveHostsFromOrchestrationRequest(cleanupEvent);
    Stack stack = new Stack();
    when(stackService.getByIdWithListsInTransaction(any())).thenReturn(stack);
    InstanceGroup ig = new InstanceGroup();
    ig.setGroupName("group");
    Template t = new Template();
    t.setInstanceType("GATEWAY");
    ig.setTemplate(t);
    InstanceMetaData im1 = new InstanceMetaData();
    im1.setDiscoveryFQDN("example1.com");
    im1.setPrivateIp("192.168.0.1");
    im1.setInstanceId("i-1");
    im1.setInstanceGroup(ig);
    InstanceMetaData im2 = new InstanceMetaData();
    im2.setDiscoveryFQDN("example2.com");
    im2.setPrivateIp("192.168.0.2");
    im2.setInstanceId("i-2");
    im2.setInstanceGroup(ig);
    InstanceMetaData im3 = new InstanceMetaData();
    im3.setDiscoveryFQDN("example3.com");
    im3.setPrivateIp("192.168.0.1");
    im3.setInstanceId("i-3");
    im3.setInstanceGroup(ig);
    ig.setInstanceMetaData(Set.of(im1, im2, im3));
    stack.setInstanceGroups(Set.of(ig));
    underTest.accept(new Event<>(request));
    verify(eventBus, times(1)).notify(eq("REMOVEHOSTSFROMORCHESTRATIONSUCCESS"), ArgumentMatchers.<Event>any());
    verify(bootstrapService).bootstrap(any(), any());
    verify(hostOrchestrator).tearDown(any(), any(), eq(Map.of("example1.com", "192.168.0.1")), any(), any());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) RemoveHostsFromOrchestrationRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removehosts.RemoveHostsFromOrchestrationRequest) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Template(com.sequenceiq.freeipa.entity.Template) Test(org.junit.jupiter.api.Test)

Example 62 with InstanceMetaData

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

the class ChangePrimaryGatewayServiceTest method testChangePrimaryGatewayMetadataWhenFormerPgwExiststThenItSavesMetadata.

@Test
void testChangePrimaryGatewayMetadataWhenFormerPgwExiststThenItSavesMetadata() {
    Stack stack = mock(Stack.class);
    InstanceMetaData im1 = mock(InstanceMetaData.class);
    InstanceMetaData im2 = mock(InstanceMetaData.class);
    InstanceMetaData im3 = mock(InstanceMetaData.class);
    when(stack.getId()).thenReturn(STACK_ID);
    when(instanceMetaDataRepository.findNotTerminatedForStack(anyLong())).thenReturn(Set.of(im1, im2, im3));
    when(im1.getInstanceId()).thenReturn(INSTANCE_ID_1);
    when(im2.getInstanceId()).thenReturn(INSTANCE_ID_2);
    lenient().when(im3.getInstanceId()).thenReturn(INSTANCE_ID_3);
    underTest.changePrimaryGatewayMetadata(stack, Optional.of(INSTANCE_ID_1), INSTANCE_ID_2);
    verify(im1).setInstanceMetadataType(eq(InstanceMetadataType.GATEWAY));
    verify(im2).setInstanceMetadataType(eq(InstanceMetadataType.GATEWAY_PRIMARY));
    verify(instanceMetaDataRepository).save(eq(im1));
    verify(instanceMetaDataRepository).save(eq(im2));
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 63 with InstanceMetaData

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

the class ChangePrimaryGatewayServiceTest method testGetNewPrimaryGatewayInstanceIdWhenExistingPrimaryGwIsOnListToAvoid.

@Test
void testGetNewPrimaryGatewayInstanceIdWhenExistingPrimaryGwIsOnListToAvoid() throws Exception {
    Stack stack = mock(Stack.class);
    GatewayConfig gatewayConfig = mock(GatewayConfig.class);
    InstanceMetaData im1 = mock(InstanceMetaData.class);
    InstanceMetaData im2 = mock(InstanceMetaData.class);
    Node node = mock(Node.class);
    Set<Node> allNodes = Set.of(node);
    when(gatewayConfigService.getPrimaryGatewayConfig(any())).thenReturn(gatewayConfig);
    when(gatewayConfig.getInstanceId()).thenReturn(INSTANCE_ID_1);
    when(freeIpaNodeUtilService.mapInstancesToNodes(any())).thenReturn(allNodes);
    when(hostOrchestrator.getFreeIpaMasterHostname(any(), any())).thenReturn(Optional.of(HOSTNAME_1));
    when(stack.getNotDeletedInstanceMetaDataList()).thenReturn(List.of(im1, im2));
    when(im1.getDiscoveryFQDN()).thenReturn(HOSTNAME_1);
    lenient().when(im2.getDiscoveryFQDN()).thenReturn(HOSTNAME_2);
    when(im1.getInstanceId()).thenReturn(INSTANCE_ID_1);
    lenient().when(im2.getInstanceId()).thenReturn(INSTANCE_ID_2);
    assertEquals(INSTANCE_ID_2, underTest.selectNewPrimaryGatewayInstanceId(stack, List.of(INSTANCE_ID_1)));
    verify(gatewayConfigService).getPrimaryGatewayConfig(eq(stack));
    verify(hostOrchestrator).getFreeIpaMasterHostname(eq(gatewayConfig), eq(allNodes));
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 64 with InstanceMetaData

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

the class ChangePrimaryGatewayServiceTest method testGetNewPrimaryGatewayInstanceIdWhenExistingPrimaryGwAndMasterIsOnListToAvoid.

@Test
void testGetNewPrimaryGatewayInstanceIdWhenExistingPrimaryGwAndMasterIsOnListToAvoid() throws Exception {
    Stack stack = mock(Stack.class);
    GatewayConfig gatewayConfig = mock(GatewayConfig.class);
    InstanceMetaData im1 = mock(InstanceMetaData.class);
    InstanceMetaData im2 = mock(InstanceMetaData.class);
    InstanceMetaData im3 = mock(InstanceMetaData.class);
    Node node = mock(Node.class);
    Set<Node> allNodes = Set.of(node);
    when(gatewayConfigService.getPrimaryGatewayConfig(any())).thenReturn(gatewayConfig);
    when(gatewayConfig.getInstanceId()).thenReturn(INSTANCE_ID_2);
    when(freeIpaNodeUtilService.mapInstancesToNodes(any())).thenReturn(allNodes);
    when(hostOrchestrator.getFreeIpaMasterHostname(any(), any())).thenReturn(Optional.of(HOSTNAME_1));
    when(stack.getNotDeletedInstanceMetaDataList()).thenReturn(List.of(im1, im2, im3));
    when(im1.getDiscoveryFQDN()).thenReturn(HOSTNAME_1);
    lenient().when(im2.getDiscoveryFQDN()).thenReturn(HOSTNAME_2);
    lenient().when(im3.getDiscoveryFQDN()).thenReturn(HOSTNAME_3);
    when(im1.getInstanceId()).thenReturn(INSTANCE_ID_1);
    lenient().when(im2.getInstanceId()).thenReturn(INSTANCE_ID_2);
    when(im3.getInstanceId()).thenReturn(INSTANCE_ID_3);
    assertEquals(INSTANCE_ID_3, underTest.selectNewPrimaryGatewayInstanceId(stack, List.of(INSTANCE_ID_1, INSTANCE_ID_2)));
    verify(gatewayConfigService).getPrimaryGatewayConfig(eq(stack));
    verify(hostOrchestrator).getFreeIpaMasterHostname(eq(gatewayConfig), eq(allNodes));
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 65 with InstanceMetaData

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

the class ChangePrimaryGatewayServiceTest method testGetNewPrimaryGatewayInstanceIdWhenPrimaryGwDoesNotRespond.

@Test
void testGetNewPrimaryGatewayInstanceIdWhenPrimaryGwDoesNotRespond() throws Exception {
    Stack stack = mock(Stack.class);
    InstanceMetaData im1 = mock(InstanceMetaData.class);
    InstanceMetaData im2 = mock(InstanceMetaData.class);
    when(hostOrchestrator.getFreeIpaMasterHostname(any(), any())).thenThrow(CloudbreakOrchestratorFailedException.class);
    when(stack.getNotDeletedInstanceMetaDataList()).thenReturn(List.of(im1, im2));
    when(im1.getInstanceId()).thenReturn(INSTANCE_ID_1);
    lenient().when(im2.getInstanceId()).thenReturn(INSTANCE_ID_2);
    assertEquals(INSTANCE_ID_1, underTest.selectNewPrimaryGatewayInstanceId(stack, List.of(INSTANCE_ID_2)));
    verify(gatewayConfigService).getPrimaryGatewayConfig(eq(stack));
}
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