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));
}
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());
}
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);
}
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());
}
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;
}
Aggregations