Search in sources :

Example 26 with InstanceMetaData

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

the class FreeIpaScalingServiceTest method testUpscaleIfValidationFailsThenErrorThrown.

@Test
public void testUpscaleIfValidationFailsThenErrorThrown() {
    Stack stack = mock(Stack.class);
    Set<InstanceMetaData> allInstances = createValidImSet();
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
    UpscaleRequest request = createUpscaleRequest();
    doThrow(new BadRequestException("validation failed")).when(validationService).validateStackForUpscale(allInstances, stack, new ScalingPath(AvailabilityType.TWO_NODE_BASED, AvailabilityType.HA));
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.upscale(ACCOUNT_ID, request));
    assertEquals(exception.getMessage(), "validation failed");
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ScalingPath(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.ScalingPath) UpscaleRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 27 with InstanceMetaData

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

the class FreeIpaScalingServiceTest method testDownscaleIfValidationPassesAndOperationRunningThenSucceed.

@Test
public void testDownscaleIfValidationPassesAndOperationRunningThenSucceed() {
    Stack stack = mock(Stack.class);
    Set<InstanceMetaData> allInstances = createValidImSet();
    Operation operation = createOperation(true);
    when(stack.getAccountId()).thenReturn(ACCOUNT_ID);
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    when(operationService.startOperation(ACCOUNT_ID, OperationType.DOWNSCALE, List.of(ENV_CRN), List.of())).thenReturn(operation);
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW, POLLABLE_ID);
    when(flowManager.notify(anyString(), any())).thenReturn(flowIdentifier);
    DownscaleRequest request = createDownscaleRequest();
    DownscaleResponse response = underTest.downscale(ACCOUNT_ID, request);
    assertEquals(response.getOperationId(), OPERATION_ID);
    assertEquals(response.getOriginalAvailabilityType(), AvailabilityType.TWO_NODE_BASED);
    assertEquals(response.getTargetAvailabilityType(), AvailabilityType.NON_HA);
    assertEquals(response.getFlowIdentifier(), flowIdentifier);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) DownscaleRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.DownscaleRequest) DownscaleResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.DownscaleResponse) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 28 with InstanceMetaData

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

the class UpgradeServiceTest method testUpgradeTriggered.

@Test
public void testUpgradeTriggered() {
    FreeIpaUpgradeRequest request = new FreeIpaUpgradeRequest();
    request.setImage(new ImageSettingsRequest());
    request.setEnvironmentCrn(ENVIRONMENT_CRN);
    Stack stack = mock(Stack.class);
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
    Set<InstanceMetaData> allInstances = createValidImSet();
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
    ImageInfoResponse selectedImage = mockSelectedImage(request, stack);
    ImageInfoResponse currentImage = mockCurrentImage(stack);
    Operation operation = mockOperation(OperationState.RUNNING);
    ArgumentCaptor<Acceptable> eventCaptor = ArgumentCaptor.forClass(Acceptable.class);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "flowId");
    when(flowManager.notify(eq(FlowChainTriggers.UPGRADE_TRIGGER_EVENT), eventCaptor.capture())).thenReturn(flowIdentifier);
    when(instanceMetaDataService.getPrimaryGwInstance(allInstances)).thenReturn(createPgwIm());
    when(instanceMetaDataService.getNonPrimaryGwInstances(allInstances)).thenReturn(createGwImSet());
    FreeIpaUpgradeResponse response = underTest.upgradeFreeIpa(ACCOUNT_ID, request);
    assertEquals(flowIdentifier, response.getFlowIdentifier());
    assertEquals(operation.getOperationId(), response.getOperationId());
    assertEquals(currentImage, response.getOriginalImage());
    assertEquals(selectedImage, response.getTargetImage());
    UpgradeEvent upgradeEvent = (UpgradeEvent) eventCaptor.getValue();
    assertEquals(request.getImage(), upgradeEvent.getImageSettingsRequest());
    assertEquals(operation.getOperationId(), upgradeEvent.getOperationId());
    assertEquals("pgw", upgradeEvent.getPrimareGwInstanceId());
    assertEquals(2, upgradeEvent.getInstanceIds().size());
    assertTrue(Set.of("im2", "im3").containsAll(upgradeEvent.getInstanceIds()));
    assertFalse(upgradeEvent.isBackupSet());
    verify(validationService).validateEntitlement(ACCOUNT_ID);
    verify(validationService).validateStackForUpgrade(allInstances, stack);
    verify(validationService).validateSelectedImageDifferentFromCurrent(currentImage, selectedImage);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) FreeIpaUpgradeResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse) UpgradeEvent(com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FreeIpaUpgradeRequest(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 29 with InstanceMetaData

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

the class UpgradeServiceTest method createPgwIm.

private InstanceMetaData createPgwIm() {
    InstanceMetaData im1 = new InstanceMetaData();
    im1.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
    im1.setInstanceId("pgw");
    return im1;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData)

Example 30 with InstanceMetaData

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

the class UpgradeServiceTest method testFailureIfOperationFailedToStart.

@Test
public void testFailureIfOperationFailedToStart() {
    FreeIpaUpgradeRequest request = new FreeIpaUpgradeRequest();
    request.setImage(new ImageSettingsRequest());
    request.setEnvironmentCrn(ENVIRONMENT_CRN);
    Stack stack = mock(Stack.class);
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_CRN, ACCOUNT_ID)).thenReturn(stack);
    Set<InstanceMetaData> allInstances = createValidImSet();
    when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(allInstances);
    ImageInfoResponse selectedImage = mockSelectedImage(request, stack);
    ImageInfoResponse currentImage = mockCurrentImage(stack);
    mockOperation(OperationState.REJECTED);
    when(instanceMetaDataService.getPrimaryGwInstance(allInstances)).thenReturn(createPgwIm());
    when(instanceMetaDataService.getNonPrimaryGwInstances(allInstances)).thenReturn(createGwImSet());
    assertThrows(BadRequestException.class, () -> underTest.upgradeFreeIpa(ACCOUNT_ID, request));
    verify(validationService).validateEntitlement(ACCOUNT_ID);
    verify(validationService).validateStackForUpgrade(allInstances, stack);
    verify(validationService).validateSelectedImageDifferentFromCurrent(currentImage, selectedImage);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) FreeIpaUpgradeRequest(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest) 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