Search in sources :

Example 51 with Stack

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);
}
Also used : OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 52 with Stack

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);
}
Also used : OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Stack(com.sequenceiq.freeipa.entity.Stack) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 53 with Stack

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);
}
Also used : OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 54 with Stack

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;
}
Also used : StackStatus(com.sequenceiq.freeipa.entity.StackStatus) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 55 with 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());
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) ArrayList(java.util.ArrayList) List(java.util.List) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Stack (com.sequenceiq.freeipa.entity.Stack)468 Test (org.junit.jupiter.api.Test)237 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)107 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)63 Map (java.util.Map)63 Bean (org.springframework.context.annotation.Bean)50 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)45 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)41 List (java.util.List)37 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)34 Inject (javax.inject.Inject)30 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)29 Collectors (java.util.stream.Collectors)29 Logger (org.slf4j.Logger)29 LoggerFactory (org.slf4j.LoggerFactory)29 Set (java.util.Set)28 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)25 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)25 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)24 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)23