Search in sources :

Example 46 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class FlowProgressResponseConverter method createFlowStateTransitions.

private List<FlowStateTransitionResponse> createFlowStateTransitions(List<FlowLog> reversedFlowLogs, Long currentCreatedTime) {
    List<FlowStateTransitionResponse> transitions = new ArrayList<>();
    for (int flowLogIndex = 0; flowLogIndex < reversedFlowLogs.size(); flowLogIndex++) {
        FlowLog fl = reversedFlowLogs.get(flowLogIndex);
        Double elapsedTime = null;
        if (!fl.getFinalized() && flowLogIndex == reversedFlowLogs.size() - 1) {
            elapsedTime = getRoundedTimeInSeconds(currentCreatedTime, new Date().getTime());
        } else {
            elapsedTime = getRoundedTimeInSeconds(currentCreatedTime, fl.getCreated());
        }
        currentCreatedTime = fl.getCreated();
        transitions.add(convertToFlowTransitionResponse(fl, elapsedTime));
    }
    return transitions;
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) ArrayList(java.util.ArrayList) FlowStateTransitionResponse(com.sequenceiq.flow.api.model.FlowStateTransitionResponse) Date(java.util.Date)

Example 47 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class FlowLogsToListDiagnosticsCollectionResponseConverter method convert.

public ListDiagnosticsCollectionResponse convert(List<FlowLog> flowLogs) {
    ListDiagnosticsCollectionResponse response = new ListDiagnosticsCollectionResponse();
    if (!flowLogs.isEmpty()) {
        List<DiagnosticsCollection> collections = flowLogs.stream().map(flowLog -> {
            DiagnosticsCollection collection = new DiagnosticsCollection();
            collection.setFlowId(flowLog.getFlowId());
            collection.setCreated(flowLog.getCreated());
            collection.setProperties(flowPayloadToDiagnosticDetailsConverter.convert(flowLog.getPayload()));
            collection.setStatus(calculateStatus(flowLog));
            collection.setCurrentFlowStatus(flowLog.getCurrentState());
            collection.setProgressPercentage(calculateProgressPercentage(flowLog));
            return collection;
        }).collect(Collectors.toList());
        response.setCollections(collections);
    }
    return response;
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) DiagnosticsCollectionStatus(com.sequenceiq.common.api.diagnostics.DiagnosticsCollectionStatus) DIAGNOSTICS_COLLECTION_FINISHED_STATE(com.sequenceiq.cloudbreak.core.flow2.diagnostics.DiagnosticsCollectionsState.DIAGNOSTICS_COLLECTION_FINISHED_STATE) DiagnosticsCollectionFlowConfig(com.sequenceiq.cloudbreak.core.flow2.diagnostics.config.DiagnosticsCollectionFlowConfig) Collectors(java.util.stream.Collectors) FlowPayloadToDiagnosticDetailsConverter(com.sequenceiq.cloudbreak.telemetry.converter.FlowPayloadToDiagnosticDetailsConverter) Inject(javax.inject.Inject) ListDiagnosticsCollectionResponse(com.sequenceiq.common.api.diagnostics.ListDiagnosticsCollectionResponse) HANDLED_FAILED_DIAGNOSTICS_COLLECTION_EVENT(com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionStateSelectors.HANDLED_FAILED_DIAGNOSTICS_COLLECTION_EVENT) List(java.util.List) Component(org.springframework.stereotype.Component) FlowProgressHolder(com.sequenceiq.flow.core.config.FlowProgressHolder) DIAGNOSTICS_COLLECTION_FAILED_STATE(com.sequenceiq.cloudbreak.core.flow2.diagnostics.DiagnosticsCollectionsState.DIAGNOSTICS_COLLECTION_FAILED_STATE) DiagnosticsCollection(com.sequenceiq.common.api.diagnostics.DiagnosticsCollection) StateStatus(com.sequenceiq.flow.domain.StateStatus) ListDiagnosticsCollectionResponse(com.sequenceiq.common.api.diagnostics.ListDiagnosticsCollectionResponse) DiagnosticsCollection(com.sequenceiq.common.api.diagnostics.DiagnosticsCollection)

Example 48 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class ClusterRepairServiceTest method testRepairByNodeIds.

@Test
public void testRepairByNodeIds() {
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setInstanceGroupType(InstanceGroupType.CORE);
    HostGroup hostGroup1 = new HostGroup();
    hostGroup1.setName("hostGroup1");
    hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
    hostGroup1.setInstanceGroup(instanceGroup);
    when(hostGroupService.getByCluster(eq(1L))).thenReturn(Set.of(hostGroup1));
    when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
    when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
    InstanceMetaData instance1md = new InstanceMetaData();
    instance1md.setInstanceId("instanceId1");
    instance1md.setDiscoveryFQDN("host1Name.healthy");
    instance1md.setInstanceGroup(instanceGroup);
    instanceGroup.setInstanceMetaData(Collections.singleton(instance1md));
    Resource volumeSet = new Resource();
    VolumeSetAttributes attributes = new VolumeSetAttributes("eu-west-1", Boolean.TRUE, "", List.of(), 100, "standard");
    attributes.setDeleteOnTermination(null);
    volumeSet.setAttributes(new Json(attributes));
    volumeSet.setInstanceId("instanceId1");
    volumeSet.setResourceType(ResourceType.AWS_VOLUMESET);
    FlowLog flowLog = new FlowLog();
    flowLog.setStateStatus(StateStatus.SUCCESSFUL);
    when(stackUpdater.updateStackStatus(1L, DetailedStackStatus.REPAIR_IN_PROGRESS)).thenReturn(stack);
    when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
    when(stack.getInstanceMetaDataAsList()).thenReturn(List.of(instance1md));
    when(resourceService.findByStackIdAndType(stack.getId(), volumeSet.getResourceType())).thenReturn(List.of(volumeSet));
    when(stackStopRestrictionService.isInfrastructureStoppable(stack)).thenReturn(StopRestrictionReason.NONE);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairNodes(1L, Set.of("instanceId1"), false, false));
    verify(resourceService).findByStackIdAndType(stack.getId(), volumeSet.getResourceType());
    @SuppressWarnings("unchecked") ArgumentCaptor<List<Resource>> saveCaptor = ArgumentCaptor.forClass(List.class);
    verify(resourceService).saveAll(saveCaptor.capture());
    assertFalse(resourceAttributeUtil.getTypedAttributes(saveCaptor.getValue().get(0), VolumeSetAttributes.class).get().getDeleteOnTermination());
    verify(flowManager).triggerClusterRepairFlow(eq(1L), eq(Map.of("hostGroup1", List.of("host1Name.healthy"))), eq(false), eq(false));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) FlowLog(com.sequenceiq.flow.domain.FlowLog) Resource(com.sequenceiq.cloudbreak.domain.Resource) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) List(java.util.List) ArrayList(java.util.ArrayList) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test)

Example 49 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class SdxRetryServiceTest method noRetryAndNoRestartFlowIfStateSuccessful.

@Test
public void noRetryAndNoRestartFlowIfStateSuccessful() {
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setId(1L);
    sdxCluster.setClusterName("sdxclustername");
    FlowLog successfulFlowLog = new FlowLog();
    successfulFlowLog.setFlowId("FLOW_ID_1");
    successfulFlowLog.setStateStatus(StateStatus.SUCCESSFUL);
    successfulFlowLog.setNextEvent(SDX_VALIDATION_EVENT.name());
    successfulFlowLog.setCreated(1L);
    successfulFlowLog.setCurrentState(SDX_CREATION_WAIT_RDS_STATE.name());
    successfulFlowLog.setFlowType(ClassValue.of(SdxCreateFlowConfig.class));
    doAnswer(invocation -> {
        ((Consumer<FlowLog>) invocation.getArgument(1)).accept(successfulFlowLog);
        return null;
    }).when(flow2Handler).retryLastFailedFlow(anyLong(), any());
    when(flow2Handler.getFirstRetryableStateLogfromLatestFlow(anyLong())).thenReturn(successfulFlowLog);
    sdxRetryService.retrySdx(sdxCluster);
    verify(stackV4Endpoint, times(0)).retry(any(), any(), anyString());
}
Also used : Consumer(java.util.function.Consumer) FlowLog(com.sequenceiq.flow.domain.FlowLog) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxCreateFlowConfig(com.sequenceiq.datalake.flow.create.SdxCreateFlowConfig) Test(org.junit.jupiter.api.Test)

Example 50 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class TerminationTriggerServiceTest method whenStackNotDeletedAndNotTerminationFlowLogAndKerbAndNotForcedShouldTerminate.

@Test
public void whenStackNotDeletedAndNotTerminationFlowLogAndKerbAndNotForcedShouldTerminate() {
    FlowLog flowLog = new FlowLog();
    flowLog.setFlowType(ClassValue.of(StackCreationFlowConfig.class));
    when(flowLogService.findAllByResourceIdAndFinalizedIsFalseOrderByCreatedDesc(anyLong())).thenReturn(List.of(flowLog));
    setupKerberized();
    underTest.triggerTermination(getAvailableStack(), false);
    verifyTerminationEventFired(true, false, false);
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) StackCreationFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationFlowConfig) Test(org.junit.Test)

Aggregations

FlowLog (com.sequenceiq.flow.domain.FlowLog)92 Test (org.junit.jupiter.api.Test)25 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)21 List (java.util.List)13 FlowConfiguration (com.sequenceiq.flow.core.config.FlowConfiguration)12 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)11 Mockito.times (org.mockito.Mockito.times)11 Mockito.verify (org.mockito.Mockito.verify)11 Mockito.when (org.mockito.Mockito.when)11 HelloWorldFlowConfig (com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig)10 Map (java.util.Map)10 UUID (java.util.UUID)10 Collectors (java.util.stream.Collectors)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 Clock (com.sequenceiq.cloudbreak.common.service.Clock)9 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)9 FlowRegister (com.sequenceiq.flow.core.FlowRegister)9 SecureRandom (java.security.SecureRandom)9 Random (java.util.Random)9