Search in sources :

Example 66 with InstanceMetaData

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

the class ChangePrimaryGatewayServiceTest method testChangePrimaryGatewayMetadataWhenFormerPgwIsEmptyThenItSavesMetadata.

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

Example 67 with InstanceMetaData

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

the class ChangePrimaryGatewayServiceTest method testGetNewPrimaryGatewayInstanceIdWhenExistingPrimaryGwIsGood.

@Test
void testGetNewPrimaryGatewayInstanceIdWhenExistingPrimaryGwIsGood() throws Exception {
    Stack stack = mock(Stack.class);
    GatewayConfig gatewayConfig = mock(GatewayConfig.class);
    InstanceMetaData im1 = mock(InstanceMetaData.class);
    InstanceMetaData im2 = mock(InstanceMetaData.class);
    when(gatewayConfigService.getPrimaryGatewayConfig(any())).thenReturn(gatewayConfig);
    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_1, underTest.selectNewPrimaryGatewayInstanceId(stack, List.of()));
    verify(gatewayConfigService).getPrimaryGatewayConfig(eq(stack));
    verify(hostOrchestrator).getFreeIpaMasterHostname(eq(gatewayConfig), any());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 68 with InstanceMetaData

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

the class DiagnosticsPreFlightCheckHandlerTest method metadataSet.

private Set<InstanceMetaData> metadataSet() {
    InstanceMetaData imd = new InstanceMetaData();
    imd.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
    return Set.of(imd);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData)

Example 69 with InstanceMetaData

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

the class CreateFullBackupHandlerTest method testBackupSuccessful.

@Test
public void testBackupSuccessful() throws CloudbreakOrchestratorFailedException {
    Stack stack = mock(Stack.class);
    when(stackService.getByIdWithListsInTransaction(2L)).thenReturn(stack);
    Set<InstanceMetaData> metaDataSet = Set.of();
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(metaDataSet);
    Node node1 = createNode("node1");
    Node node2 = createNode("node2");
    Set<Node> nodes = Set.of(node1, node2);
    when(nodeService.mapInstancesToNodes(metaDataSet)).thenReturn(nodes);
    GatewayConfig gatewayConfig = mock(GatewayConfig.class);
    when(gatewayConfigService.getPrimaryGatewayConfig(stack)).thenReturn(gatewayConfig);
    StackEvent result = (StackEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(new CreateFullBackupEvent(2L))));
    ArgumentCaptor<OrchestratorStateParams> captor = ArgumentCaptor.forClass(OrchestratorStateParams.class);
    verify(orchestrator, times(2)).runOrchestratorState(captor.capture());
    List<OrchestratorStateParams> stateParams = captor.getAllValues();
    assertThat(stateParams, everyItem(allOf(hasProperty("primaryGatewayConfig", is(gatewayConfig)), hasProperty("state", is("freeipa.backup-full")), hasProperty("allNodes", is(nodes)))));
    assertThat(stateParams, hasItem(hasProperty("targetHostNames", allOf(hasItem("node1"), iterableWithSize(1)))));
    assertThat(stateParams, hasItem(hasProperty("targetHostNames", allOf(hasItem("node2"), iterableWithSize(1)))));
    assertEquals(2L, result.getResourceId());
    assertEquals(FullBackupEvent.FULL_BACKUP_SUCCESSFUL_EVENT.event(), result.selector());
}
Also used : CreateFullBackupEvent(com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) OrchestratorStateParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 70 with InstanceMetaData

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

the class InstanceMetaDataToInstanceMetaDataResponseConverterTest method createInstanceMetaData.

private InstanceMetaData createInstanceMetaData(String publicIp, String privateIp) {
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName(INSTANCE_GROUP);
    InstanceMetaData result = new InstanceMetaData();
    result.setPrivateIp(privateIp);
    result.setPublicIp(publicIp);
    result.setSshPort(SSH_PORT);
    result.setInstanceId(INSTANCE_ID);
    result.setDiscoveryFQDN(DISCOVERY_FQDN);
    result.setInstanceGroup(instanceGroup);
    result.setSubnetId(SUBNET_ID);
    result.setAvailabilityZone(AVAILABILITY_ZONE);
    result.setInstanceStatus(INSTANCE_STATUS);
    result.setInstanceMetadataType(INSTANCE_METADATA_TYPE);
    result.setLifeCycle(LIFE_CYCLE);
    return result;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup)

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