Search in sources :

Example 11 with FlowIdentifier

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

the class DistroXUpgradeService method initUpgrade.

private UpgradeV4Response initUpgrade(UpgradeV4Request request, UpgradeV4Response upgradeV4Response, NameOrCrn cluster, Long workspaceId, String userCrn) {
    ImageInfoV4Response image = imageSelector.determineImageId(request, upgradeV4Response.getUpgradeCandidates());
    ImageChangeDto imageChangeDto = createImageChangeDto(cluster, workspaceId, image);
    Stack stack = stackService.getByNameOrCrnInWorkspace(cluster, workspaceId);
    boolean lockComponents = request.getLockComponents() != null ? request.getLockComponents() : isComponentsLocked(stack, image);
    validateOsUpgradeEntitled(lockComponents, request);
    boolean replaceVms = determineReplaceVmsParam(upgradeV4Response, lockComponents, stack);
    String upgradeVariant = calculateUpgradeVariant(stack, userCrn);
    FlowIdentifier flowIdentifier = reactorFlowManager.triggerDistroXUpgrade(stack.getId(), imageChangeDto, replaceVms, lockComponents, upgradeVariant);
    UpgradeV4Response response = new UpgradeV4Response("Upgrade started with Image: " + image.getImageId(), flowIdentifier);
    response.setReplaceVms(replaceVms);
    return response;
}
Also used : ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 12 with FlowIdentifier

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

the class SdxCcmUpgradeServiceTest method testInitAndWaitForStackUpgrade.

@Test
void testInitAndWaitForStackUpgrade() {
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:altus:iam:us-west-1:altus:user:__internal__actor__");
    FlowIdentifier flowId = new FlowIdentifier(FlowType.FLOW, "pollableId");
    StackCcmUpgradeV4Response upgradeResponse = new StackCcmUpgradeV4Response(flowId);
    when(stackV4Endpoint.upgradeCcmByCrnInternal(eq(0L), eq(STACK_CRN), any())).thenReturn(upgradeResponse);
    PollingConfig pc = new PollingConfig(1L, TimeUnit.HOURS, 1L, TimeUnit.HOURS);
    SdxCluster sdx = getSdxCluster();
    underTest.initAndWaitForStackUpgrade(sdx, pc);
    verify(stackV4Endpoint).upgradeCcmByCrnInternal(any(), eq(STACK_CRN), any());
    verify(cloudbreakPoller).pollCcmUpgradeUntilAvailable(sdx, pc);
}
Also used : StackCcmUpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.StackCcmUpgradeV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with FlowIdentifier

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

the class Flow2Handler method retryLastFailedFlowFromStart.

/**
 * Retry the failed flow completely
 *
 * @param resourceId Datalake ID
 * @return Identifier of flow or a flow chain
 */
public FlowIdentifier retryLastFailedFlowFromStart(Long resourceId) {
    FlowLog firstSuccessfulStateLog = getFirstRetryableStateLogfromLatestFlow(resourceId);
    LOGGER.info("Trying to restart flow {}", firstSuccessfulStateLog.getFlowType().getName());
    restartFlow(firstSuccessfulStateLog);
    LOGGER.info("Restarted flow : {}", firstSuccessfulStateLog.getFlowType().getName());
    if (firstSuccessfulStateLog.getFlowChainId() != null) {
        return new FlowIdentifier(FlowType.FLOW_CHAIN, firstSuccessfulStateLog.getFlowChainId());
    } else {
        return new FlowIdentifier(FlowType.FLOW, firstSuccessfulStateLog.getFlowId());
    }
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 14 with FlowIdentifier

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

the class EventSender method doSend.

private FlowIdentifier doSend(BaseFlowEvent event, Event.Headers headers, String resourceName) {
    Event<BaseFlowEvent> eventWithErrHandler = eventFactory.createEventWithErrHandler(new HashMap<>(headers.asMap()), event);
    reactor.notify(event.selector(), eventWithErrHandler);
    Promise<AcceptResult> accepted = eventWithErrHandler.getData().accepted();
    String resourceCrn = event.getResourceCrn();
    if (accepted != null) {
        try {
            FlowAcceptResult acceptResult = (FlowAcceptResult) accepted.await(TIMEOUT, TimeUnit.SECONDS);
            return createFlowIdentifier(acceptResult, resourceCrn);
        } catch (InterruptedException e) {
            throw new IllegalStateException(e.getMessage());
        }
    }
    if (headers.contains(FLOW_ID)) {
        return new FlowIdentifier(FlowType.FLOW, headers.get(FLOW_ID));
    } else if (headers.contains(FLOW_CHAIN_ID)) {
        return new FlowIdentifier(FlowType.FLOW_CHAIN, headers.get(FLOW_CHAIN_ID));
    }
    LOGGER.error("Accepted is null, header does not contains flow or flow chain id, event: {}, header: {}", event, headers);
    reactorReporter.logErrorReport();
    throw new FlowNotAcceptedException(String.format("Timeout happened when trying to start the flow for stack %s.", resourceCrn));
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) AcceptResult(com.sequenceiq.cloudbreak.common.event.AcceptResult) FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

Example 15 with FlowIdentifier

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

the class DistroXRemoveInstancesAction method action.

@Override
public DistroXTestDto action(TestContext testContext, DistroXTestDto testDto, CloudbreakClient client) throws Exception {
    List<String> removableInstanceIds = testDto.getInstanceIdsForAction();
    if (!removableInstanceIds.isEmpty()) {
        MultipleInstanceDeleteRequest instanceDeleteRequest = new MultipleInstanceDeleteRequest();
        instanceDeleteRequest.setInstances(removableInstanceIds);
        Log.when(LOGGER, String.format(" Removing instances [%s] from distrox '%s'... ", instanceDeleteRequest.getInstances(), testDto.getName()));
        FlowIdentifier flowIdentifier = client.getDefaultClient().distroXV1Endpoint().deleteInstancesByCrn(testDto.getCrn(), removableInstanceIds, instanceDeleteRequest, false);
        testDto.setFlow("Instance deletion", flowIdentifier);
        StackV4Response stackV4Response = client.getDefaultClient().distroXV1Endpoint().getByName(testDto.getName(), new HashSet<>(Arrays.asList("hardware_info", "events")));
        testDto.setResponse(stackV4Response);
        Log.whenJson(LOGGER, " Distrox remove instances response: ", stackV4Response);
        LOGGER.info(String.format("Hardware info for distrox '%s' after remove instances [%s].", testDto.getName(), stackV4Response.getHardwareInfoGroups()));
        return testDto;
    } else {
        throw new TestFailException(String.format("Cannot find any instance to remove from distrox '%s'!", testDto.getName()));
    }
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) MultipleInstanceDeleteRequest(com.sequenceiq.distrox.api.v1.distrox.model.MultipleInstanceDeleteRequest) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

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