use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class FreeIpaUpgradeCcmServiceTest method upgradeCcmTestWhenAlreadyUpgraded.
@Test
void upgradeCcmTestWhenAlreadyUpgraded() {
Stack stack = createStack(Status.AVAILABLE);
stack.setTunnel(Tunnel.CCMV2_JUMPGATE);
when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
OperationStatus operationStatus = underTest.upgradeCcm(ENVIRONMENT_CRN, ACCOUNT_ID);
assertThat(operationStatus.getStatus()).isEqualTo(OperationState.COMPLETED);
}
use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class FreeIpaUpgradeCcmServiceTest method upgradeCcmTestWhenAvailableAndOperationNotRunning.
@ParameterizedTest(name = "{0}")
@EnumSource(value = OperationState.class, names = { "RUNNING" }, mode = EnumSource.Mode.EXCLUDE)
void upgradeCcmTestWhenAvailableAndOperationNotRunning(OperationState operationState) {
Stack stack = createStack(Status.AVAILABLE);
when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
Operation operation = createOperation(operationState);
when(operationService.startOperation(ACCOUNT_ID, OperationType.UPGRADE_CCM, List.of(ENVIRONMENT_CRN), List.of())).thenReturn(operation);
when(operationConverter.convert(operation)).thenReturn(operationStatus);
OperationStatus result = underTest.upgradeCcm(ENVIRONMENT_CRN, ACCOUNT_ID);
assertThat(result).isSameAs(operationStatus);
verifyNoInteractions(flowManager);
}
use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class FreeIpaUpgradeCcmServiceTest method upgradeCcmTestWhenAvailableAndOperationRunningButFailedToStart.
@Test
void upgradeCcmTestWhenAvailableAndOperationRunningButFailedToStart() {
Stack stack = createStack(Status.AVAILABLE);
when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
Operation operation = createOperation(OperationState.RUNNING);
when(operationService.startOperation(ACCOUNT_ID, OperationType.UPGRADE_CCM, List.of(ENVIRONMENT_CRN), List.of())).thenReturn(operation);
Operation failedOperation = createOperation(OperationState.FAILED);
when(operationService.failOperation(eq(ACCOUNT_ID), eq(OPERATION_ID), any())).thenReturn(failedOperation);
when(operationConverter.convert(any())).then(invocation -> {
Operation opArg = invocation.getArgument(0);
if (!Objects.equals(opArg.getStatus(), OperationState.FAILED)) {
return operationStatus;
}
operationStatus.setStatus(OperationState.FAILED);
return operationStatus;
});
when(flowManager.notify(nullable(String.class), any())).thenThrow(new IllegalStateException("bad state"));
OperationStatus result = underTest.upgradeCcm(ENVIRONMENT_CRN, ACCOUNT_ID);
assertThat(result.getStatus()).isEqualTo(OperationState.FAILED);
}
use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class FreeIpaUpgradeCcmServiceTest method createStack.
private Stack createStack(Status status) {
Stack stack = new Stack();
stack.setId(STACK_ID);
stack.setEnvironmentCrn(ENVIRONMENT_CRN);
stack.setName(STACK_NAME);
stack.setTunnel(Tunnel.CCM);
StackStatus stackStatus = new StackStatus();
stack.setStackStatus(stackStatus);
stackStatus.setStatus(status);
return stack;
}
use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class InstanceMetadataServiceComponentTest method saveInstanceAndGetUpdatedStack.
@Test
public void saveInstanceAndGetUpdatedStack() {
DetailedEnvironmentResponse detailedEnvResponse = DetailedEnvironmentResponse.builder().withCrn(ENV_CRN).withNetwork(EnvironmentNetworkResponse.builder().withSubnetMetas(Map.of("sub1", cloudSubnet("az", "sub1"), "sub2", cloudSubnet("az", "sub2"), "sub3", cloudSubnet("az", "sub3"), "sub4", cloudSubnet("az1", "sub4"))).build()).build();
Stack stack = new Stack();
stack.setEnvironmentCrn(ENV_CRN);
InstanceGroup workerInstanceGroup = new InstanceGroup();
workerInstanceGroup.setGroupName("worker");
InstanceGroupNetwork instanceGroupNetwork = new InstanceGroupNetwork();
instanceGroupNetwork.setCloudPlatform("AWS");
instanceGroupNetwork.setAttributes(new Json(Map.of(SUBNET_IDS, List.of("sub1", "sub2", "sub3", "sub4"))));
workerInstanceGroup.setInstanceGroupNetwork(instanceGroupNetwork);
stack.setInstanceGroups(Set.of(workerInstanceGroup));
when(cachedEnvironmentClientService.getByCrn(ENV_CRN)).thenReturn(detailedEnvResponse);
FreeIpa freeIpa = new FreeIpa();
freeIpa.setHostname("hostname");
freeIpa.setDomain("domain");
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, cloudInstances(42));
Map<String, List<InstanceMetaData>> groupBySub = workerInstanceGroup.getInstanceMetaDataSet().stream().collect(Collectors.groupingBy(InstanceMetaData::getSubnetId, Collectors.mapping(Function.identity(), Collectors.toList())));
Map<String, List<InstanceMetaData>> groupByAz = workerInstanceGroup.getInstanceMetaDataSet().stream().collect(Collectors.groupingBy(InstanceMetaData::getAvailabilityZone, Collectors.mapping(Function.identity(), Collectors.toList())));
Assertions.assertEquals(2, groupByAz.size());
Assertions.assertEquals(21, groupByAz.get("az").size());
Assertions.assertEquals(21, groupByAz.get("az1").size());
Assertions.assertEquals(4, groupBySub.size());
Assertions.assertEquals(7, groupBySub.get("sub1").size());
Assertions.assertEquals(7, groupBySub.get("sub2").size());
Assertions.assertEquals(7, groupBySub.get("sub3").size());
Assertions.assertEquals(21, groupBySub.get("sub4").size());
}
Aggregations