Search in sources :

Example 36 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier 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 37 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier 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 38 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class FreeIpaRetryServiceTest method testRetry.

@Test
public void testRetry() {
    Stack stack = new Stack();
    stack.setId(6L);
    when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "afda");
    when(flowRetryService.retry(stack.getId())).thenReturn(new RetryResponse("asdf", flowIdentifier));
    FlowIdentifier result = underTest.retry(ENV_CRN, ACCOUNT_ID);
    assertEquals(flowIdentifier, result);
}
Also used : RetryResponse(com.sequenceiq.flow.domain.RetryResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 39 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class UpgradeConverterTest method testConvertResult.

@Test
public void testConvertResult() {
    UpgradeV4Response source = new UpgradeV4Response();
    source.setUpgradeCandidates(List.of());
    source.setCurrent(new ImageInfoV4Response());
    source.setFlowIdentifier(new FlowIdentifier(FlowType.FLOW, "asdg"));
    source.setReason("fdas");
    DistroXUpgradeV1Response result = underTest.convert(source);
    assertEquals(source.getCurrent(), result.getCurrent());
    assertEquals(source.getFlowIdentifier(), result.getFlowIdentifier());
    assertEquals(source.getReason(), result.getReason());
    assertEquals(source.getUpgradeCandidates(), result.getUpgradeCandidates());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) DistroXUpgradeV1Response(com.sequenceiq.distrox.api.v1.distrox.model.upgrade.DistroXUpgradeV1Response) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class DistroXUpgradeV1ControllerTest method testCcmUpgrade.

@Test
public void testCcmUpgrade() {
    FlowIdentifier expected = new FlowIdentifier(FlowType.FLOW, "1");
    when(stackCcmUpgradeService.upgradeCcm(NameOrCrn.ofCrn(DATAHUB_CRN))).thenReturn(expected);
    DistroXCcmUpgradeV1Response result = underTest.upgradeCcmByCrnInternal(DATAHUB_CRN, USER_CRN);
    Assertions.assertSame(expected, result.getFlowIdentifier());
}
Also used : DistroXCcmUpgradeV1Response(com.sequenceiq.distrox.api.v1.distrox.model.upgrade.DistroXCcmUpgradeV1Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)150 Test (org.junit.jupiter.api.Test)55 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)15 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)14 SdxClusterDetailResponse (com.sequenceiq.sdx.api.model.SdxClusterDetailResponse)14 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)13 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)10 Supplier (java.util.function.Supplier)10 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)9 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)7 StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)7 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)7 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)7 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)7 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)7 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)7