use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class FreeIpaOperationCheckerTask method checkStatus.
@Override
public boolean checkStatus(T operationPollerObject) {
OperationStatus operationStatus = ThreadBasedUserCrnProvider.doAsInternalActor(operationPollerObject.getRegionalAwareInternalCrnGeneratorFactory().iam().getInternalCrnForServiceAsString(), () -> operationPollerObject.getOperationV1Endpoint().getOperationStatus(operationPollerObject.getOperationId(), operationPollerObject.getAccountId()));
LOGGER.debug("OperationStatus for operationId[{}]: {}", operationPollerObject.getOperationId(), operationStatus);
if (OperationState.COMPLETED.equals(operationStatus.getStatus())) {
return true;
} else if (OperationState.RUNNING.equals(operationStatus.getStatus())) {
return false;
} else {
String failureDetails = extractFailureDetails(operationStatus);
throw new FreeIpaOperationFailedException(String.format("FreeIPA [%s] operation [%s] failed with state [%s] and error message [%s]. " + "Failure details: [%s]", operationStatus.getOperationType(), operationPollerObject.getOperationId(), operationStatus.getStatus(), operationStatus.getError(), failureDetails));
}
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method upscaleFailureAction.
@Bean(name = "UPSCALE_FAIL_STATE")
public Action<?, ?> upscaleFailureAction() {
return new AbstractUpscaleAction<>(UpscaleFailureEvent.class) {
@Inject
private OperationService operationService;
@Override
protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<UpscaleState, UpscaleFlowEvent> stateContext, UpscaleFailureEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return super.createFlowContext(flowParameters, stateContext, payload);
}
@Override
protected void doExecute(StackContext context, UpscaleFailureEvent payload, Map<Object, Object> variables) {
LOGGER.error("Upscale failed with payload: " + payload);
Stack stack = context.getStack();
String environmentCrn = stack.getEnvironmentCrn();
SuccessDetails successDetails = new SuccessDetails(environmentCrn);
successDetails.getAdditionalDetails().put(payload.getFailedPhase(), payload.getSuccess() == null ? List.of() : new ArrayList<>(payload.getSuccess()));
String message = "Upscale failed during " + payload.getFailedPhase();
FailureDetails failureDetails = new FailureDetails(environmentCrn, message);
if (payload.getFailureDetails() != null) {
failureDetails.getAdditionalDetails().putAll(payload.getFailureDetails());
}
String errorReason = getErrorReason(payload.getException());
stackUpdater.updateStackStatus(context.getStack().getId(), getFailedStatus(variables), errorReason);
operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
enableStatusChecker(stack, "Failed upscaling FreeIPA");
enableNodeStatusChecker(stack, "Failed upscaling FreeIPA");
sendEvent(context, FAIL_HANDLED_EVENT.event(), payload);
}
@Override
protected void initPayloadConverterMap(List<PayloadConverter<UpscaleFailureEvent>> payloadConverters) {
payloadConverters.add(new UpscaleStackResultToUpscaleFailureEventConverter());
payloadConverters.add(new CollectMetadataResultToUpscaleFailureEventConverter());
payloadConverters.add(new BootstrapMachinesFailedToUpscaleFailureEventConverter());
payloadConverters.add(new HostMetadataSetupFailedToUpscaleFailureEventConverter());
payloadConverters.add(new InstallFreeIpaServicesFailedToUpscaleFailureEventConverter());
payloadConverters.add(new ClusterProxyUpdateRegistrationFailedToUpscaleFailureEventConverter());
payloadConverters.add(new PostInstallFreeIpaFailedToUpscaleFailureEventConverter());
}
};
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method downscaleFailureAction.
@Bean(name = "DOWNSCALE_FAIL_STATE")
public Action<?, ?> downscaleFailureAction() {
return new AbstractDownscaleAction<>(DownscaleFailureEvent.class) {
@Inject
private OperationService operationService;
@Override
protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<DownscaleState, DownscaleFlowEvent> stateContext, DownscaleFailureEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return super.createFlowContext(flowParameters, stateContext, payload);
}
@Override
protected void doExecute(StackContext context, DownscaleFailureEvent payload, Map<Object, Object> variables) {
LOGGER.error("Downscale failed with payload: " + payload);
Stack stack = context.getStack();
String environmentCrn = stack.getEnvironmentCrn();
SuccessDetails successDetails = new SuccessDetails(environmentCrn);
successDetails.getAdditionalDetails().put(payload.getFailedPhase(), payload.getSuccess() == null ? List.of() : new ArrayList<>(payload.getSuccess()));
String message = "Downscale failed during " + payload.getFailedPhase();
FailureDetails failureDetails = new FailureDetails(environmentCrn, message);
if (payload.getFailureDetails() != null) {
failureDetails.getAdditionalDetails().putAll(payload.getFailureDetails());
}
String errorReason = getErrorReason(payload.getException());
stackUpdater.updateStackStatus(context.getStack().getId(), getFailedStatus(variables), errorReason);
operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
enableStatusChecker(stack, "Failed downscaling FreeIPA");
enableNodeStatusChecker(stack, "Failed downscaling FreeIPA");
sendEvent(context, FAIL_HANDLED_EVENT.event(), payload);
}
@Override
protected void initPayloadConverterMap(List<PayloadConverter<DownscaleFailureEvent>> payloadConverters) {
payloadConverters.add(new ClusterProxyUpdateRegistrationFailedToDownscaleFailureEventConverter());
payloadConverters.add(new DownscaleStackCollectResourcesResultToDownscaleFailureEventConverter());
payloadConverters.add(new DownscaleStackResultToDownscaleFailureEventConverter());
payloadConverters.add(new RemoveServersResponseToDownscaleFailureEventConverter());
payloadConverters.add(new RemoveDnsResponseToDownscaleFailureEventConverter());
payloadConverters.add(new RemoveHostsResponseToDownscaleFailureEventConverter());
payloadConverters.add(new RevokeCertsResponseToDownscaleFailureEventConverter());
}
};
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncCompletedFailure.
@Test
void internalCalculateEnvironmentUserSyncStateLastSyncCompletedFailure() {
UserSyncStatus userSyncStatus = new UserSyncStatus();
Operation lastSync = new Operation();
lastSync.setOperationId(UUID.randomUUID().toString());
lastSync.setStatus(OperationState.COMPLETED);
lastSync.setFailureList(List.of(new FailureDetails(ENVIRONMENT_CRN, "failure message")));
userSyncStatus.setLastStartedFullSync(lastSync);
EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus));
assertEquals(UserSyncState.SYNC_FAILED, result.getState());
assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails in project cloudbreak by hortonworks.
the class UserSyncForEnvServiceTest method testSyncUsersTimesOut.
@Test
public void testSyncUsersTimesOut() {
ReflectionTestUtils.setField(underTest, "operationTimeout", 0L);
Stack stack1 = mock(Stack.class);
when(stack1.getEnvironmentCrn()).thenReturn(ENV_CRN);
UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(Set.of(), Set.of(), Optional.empty());
UserSyncOptions options = new UserSyncOptions(true, true, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
doAnswer(inv -> {
inv.getArgument(2, Runnable.class).run();
return null;
}).when(operationService).tryWithOperationCleanup(eq(OPERATION_ID), eq(ACCOUNT_ID), any(Runnable.class));
UmsUsersState umsUsersState1 = mock(UmsUsersState.class);
when(umsUsersStateProviderDispatcher.getEnvToUmsUsersStateMap(eq(ACCOUNT_ID), eq(Set.of(ENV_CRN)), eq(Set.of()), eq(Set.of()), any())).thenReturn(Map.of(ENV_CRN, umsUsersState1));
Future<?> future = mock(Future.class);
when(asyncTaskExecutor.submit(any(Callable.class))).thenAnswer(inv -> {
when(future.get(0L, TimeUnit.MILLISECONDS)).thenThrow(new TimeoutException("timeout"));
return future;
});
when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any(Optional.class))).thenReturn(new UmsEventGenerationIds());
when(entitlementService.isUserSyncThreadTimeoutEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
underTest.synchronizeUsers(OPERATION_ID, ACCOUNT_ID, List.of(stack1), userSyncFilter, options, System.currentTimeMillis());
verifyNoInteractions(userSyncStatusService);
ArgumentCaptor<Collection> successCaptor = ArgumentCaptor.forClass(Collection.class);
ArgumentCaptor<Collection> failureCaptor = ArgumentCaptor.forClass(Collection.class);
verify(operationService).completeOperation(eq(ACCOUNT_ID), eq(OPERATION_ID), successCaptor.capture(), failureCaptor.capture());
assertTrue(successCaptor.getValue().isEmpty());
verify(future).cancel(true);
List<FailureDetails> failures = (List<FailureDetails>) failureCaptor.getValue();
assertThat(failures, allOf(hasItem(allOf(hasProperty("environment", is(ENV_CRN)), hasProperty("message", is("Timed out")), hasProperty("additionalDetails", anEmptyMap())))));
}
Aggregations