Search in sources :

Example 16 with Operation

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

the class UserSyncAcceptorTest method testUserSyncAcceptedWithDifferentEnvironment.

@Test
void testUserSyncAcceptedWithDifferentEnvironment() {
    Operation syncOperation = mock(Operation.class);
    when(syncOperation.getUserList()).thenReturn(List.of("userA", "userB"));
    when(syncOperation.getEnvironmentList()).thenReturn(List.of("envA"));
    Operation runningSyncOperation = mock(Operation.class);
    when(runningSyncOperation.getUserList()).thenReturn(List.of("userA"));
    when(runningSyncOperation.getEnvironmentList()).thenReturn(List.of("envB"));
    assertFalse(userSyncAcceptor.doOperationsConflict(syncOperation, runningSyncOperation));
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 17 with Operation

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

the class FreeIpaScalingService method triggerDownscale.

private DownscaleResponse triggerDownscale(DownscaleRequest request, Stack stack, AvailabilityType originalAvailabilityType) {
    Operation operation = startScalingOperation(stack.getAccountId(), request.getEnvironmentCrn(), OperationType.DOWNSCALE);
    ArrayList<String> instanceIdList = getDownscaleCandidates(stack, originalAvailabilityType, request.getTargetAvailabilityType());
    DownscaleEvent downscaleEvent = new DownscaleEvent(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), stack.getId(), instanceIdList, request.getTargetAvailabilityType().getInstanceCount(), false, false, false, operation.getOperationId());
    try {
        LOGGER.info("Trigger downscale flow with event: {}", downscaleEvent);
        FlowIdentifier flowIdentifier = flowManager.notify(DownscaleFlowEvent.DOWNSCALE_EVENT.event(), downscaleEvent);
        DownscaleResponse response = new DownscaleResponse();
        response.setOperationId(operation.getOperationId());
        response.setOriginalAvailabilityType(originalAvailabilityType);
        response.setTargetAvailabilityType(request.getTargetAvailabilityType());
        response.setFlowIdentifier(flowIdentifier);
        return response;
    } catch (Exception e) {
        String exception = handleFlowException(operation, e, stack);
        throw new BadRequestException(exception);
    }
}
Also used : DownscaleEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent) DownscaleResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.DownscaleResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 18 with Operation

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

the class FreeIpaScalingService method triggerUpscale.

private UpscaleResponse triggerUpscale(UpscaleRequest request, Stack stack, AvailabilityType originalAvailabilityType) {
    Operation operation = startScalingOperation(stack.getAccountId(), request.getEnvironmentCrn(), OperationType.UPSCALE);
    UpscaleEvent upscaleEvent = new UpscaleEvent(UpscaleFlowEvent.UPSCALE_EVENT.event(), stack.getId(), request.getTargetAvailabilityType().getInstanceCount(), false, false, false, operation.getOperationId());
    try {
        LOGGER.info("Trigger upscale flow with event: {}", upscaleEvent);
        FlowIdentifier flowIdentifier = flowManager.notify(UpscaleFlowEvent.UPSCALE_EVENT.event(), upscaleEvent);
        UpscaleResponse response = new UpscaleResponse();
        response.setOperationId(operation.getOperationId());
        response.setOriginalAvailabilityType(originalAvailabilityType);
        response.setTargetAvailabilityType(request.getTargetAvailabilityType());
        response.setFlowIdentifier(flowIdentifier);
        return response;
    } catch (Exception e) {
        String exception = handleFlowException(operation, e, stack);
        throw new BadRequestException(exception);
    }
}
Also used : UpscaleEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleEvent) UpscaleResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.scale.UpscaleResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Operation(com.sequenceiq.freeipa.entity.Operation) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 19 with Operation

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

the class OperationService method failOperation.

public Operation failOperation(String accountId, String operationId, String failureMessage, Collection<SuccessDetails> success, Collection<FailureDetails> failure) {
    Operation operation = getOperationForAccountIdAndOperationId(accountId, operationId);
    operation.setStatus(OperationState.FAILED);
    operation.setError(failureMessage);
    operation.setEndTime(System.currentTimeMillis());
    operation.setSuccessList(List.copyOf(success));
    operation.setFailureList(List.copyOf(failure));
    LOGGER.warn("Operation failed: {}. Operation duration was {} ms.", operation, operation.getEndTime() - operation.getStartTime());
    return operationRepository.save(operation);
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation)

Example 20 with Operation

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

the class OperationService method timeout.

public Operation timeout(String operationId, String accountId) {
    Operation operation = getOperationForAccountIdAndOperationId(accountId, operationId);
    operation.setStatus(OperationState.TIMEDOUT);
    operation.setEndTime(System.currentTimeMillis());
    LOGGER.info("Operation timed out: {}", operation);
    return operationRepository.save(operation);
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation)

Aggregations

Operation (com.sequenceiq.freeipa.entity.Operation)88 Test (org.junit.jupiter.api.Test)55 Stack (com.sequenceiq.freeipa.entity.Stack)23 UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)18 SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)15 OperationToSyncOperationStatus (com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus)12 AcceptResult (com.sequenceiq.freeipa.service.freeipa.user.AcceptResult)11 UserSyncRequestFilter (com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter)10 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)9 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)8 EnvironmentUserSyncState (com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState)7 OperationType (com.sequenceiq.freeipa.api.v1.operation.model.OperationType)7 OperationStatus (com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)6 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)5 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)5 FreeIpaUpgradeResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse)4 SynchronizeAllUsersRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest)4 CustomPermissionCheck (com.sequenceiq.authorization.annotation.CustomPermissionCheck)3