use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails in project cloudbreak by hortonworks.
the class UserSyncForEnvService method synchronizeUsers.
public void synchronizeUsers(String operationId, String accountId, List<Stack> stacks, UserSyncRequestFilter userSyncFilter, UserSyncOptions options, long startTime) {
operationService.tryWithOperationCleanup(operationId, accountId, () -> {
Set<String> environmentCrns = stacks.stream().map(Stack::getEnvironmentCrn).collect(Collectors.toSet());
UserSyncLogEvent logUserSyncEvent = options.isFullSync() ? FULL_USER_SYNC : PARTIAL_USER_SYNC;
LOGGER.info("Starting {} for environments {} with operationId {} ...", logUserSyncEvent, environmentCrns, operationId);
if (options.isFullSync()) {
umsVirtualGroupCreateService.createVirtualGroups(accountId, stacks);
}
Map<String, Future<SyncStatusDetail>> statusFutures = startAsyncSyncsForStacks(operationId, accountId, stacks, userSyncFilter, options, environmentCrns);
List<SuccessDetails> success = new ArrayList<>();
List<FailureDetails> failure = new ArrayList<>();
statusFutures.forEach((envCrn, statusFuture) -> {
try {
SyncStatusDetail statusDetail = waitForSyncStatusDetailResult(startTime, statusFuture, accountId);
switch(statusDetail.getStatus()) {
case COMPLETED:
success.add(new SuccessDetails(envCrn));
break;
case FAILED:
failure.add(createFailureDetails(envCrn, statusDetail.getDetails(), statusDetail.getWarnings()));
break;
default:
failure.add(createFailureDetails(envCrn, "Unexpected status: " + statusDetail.getStatus(), statusDetail.getWarnings()));
break;
}
} catch (TimeoutException e) {
LOGGER.warn("Sync timed out for env: {}", envCrn, e);
statusFuture.cancel(true);
failure.add(new FailureDetails(envCrn, "Timed out"));
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("Sync is interrupted for env: {}", envCrn, e);
failure.add(new FailureDetails(envCrn, e.getLocalizedMessage()));
}
});
operationService.completeOperation(accountId, operationId, success, failure);
LOGGER.info("Finished {} for environments {} with operationId {}.", logUserSyncEvent, environmentCrns, operationId);
});
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails in project cloudbreak by hortonworks.
the class FreeIpaCleanupActions method cleanupFinishedAction.
@Bean(name = "CLEANUP_FINISHED_STATE")
public Action<?, ?> cleanupFinishedAction() {
return new AbstractFreeIpaCleanupAction<>(RemoveRolesResponse.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(FreeIpaContext context, RemoveRolesResponse payload, Map<Object, Object> variables) {
CleanupEvent cleanupEvent = new CleanupEvent(FreeIpaCleanupEvent.CLEANUP_FINISHED_EVENT.event(), payload.getResourceId(), payload.getUsers(), payload.getHosts(), payload.getRoles(), payload.getIps(), payload.getStatesToSkip(), payload.getAccountId(), payload.getOperationId(), payload.getClusterName(), payload.getEnvironmentCrn());
SuccessDetails successDetails = new SuccessDetails(payload.getEnvironmentCrn());
successDetails.getAdditionalDetails().put("Hosts", payload.getHosts() == null ? List.of() : new ArrayList<>(payload.getHosts()));
successDetails.getAdditionalDetails().put("Users", payload.getUsers() == null ? List.of() : new ArrayList<>(payload.getUsers()));
successDetails.getAdditionalDetails().put("Roles", payload.getRoles() == null ? List.of() : new ArrayList<>(payload.getRoles()));
successDetails.getAdditionalDetails().put("IPs", payload.getIps() == null ? List.of() : new ArrayList<>(payload.getIps()));
operationService.completeOperation(payload.getAccountId(), payload.getOperationId(), List.of(successDetails), Collections.emptyList());
LOGGER.info("Cleanup successfully finished with: " + successDetails);
sendEvent(context, cleanupEvent);
}
};
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails in project cloudbreak by hortonworks.
the class FullBackupActions method backupFinishedAction.
@Bean(name = "BACKUP_FINISHED_STATE")
public Action<?, ?> backupFinishedAction() {
return new AbstractBackupAction<>(StackEvent.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(BackupContext context, StackEvent payload, Map<Object, Object> variables) {
LOGGER.info("Full backup flow finished");
if (isOperationIdSet(variables) && (!isChainedAction(variables) || isFinalChain(variables))) {
LOGGER.debug("Complete operation with id: [{}]", getOperationId(variables));
Stack stack = context.getStack();
SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
operationService.completeOperation(stack.getAccountId(), getOperationId(variables), Set.of(successDetails), Set.of());
}
sendEvent(context, new StackEvent(FULL_BACKUP_FINISHED_EVENT.event(), payload.getResourceId()));
}
};
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails in project cloudbreak by hortonworks.
the class CreateBindUserActions method createBindUserFinishedAction.
@Bean("CREATE_BIND_USER_FINISHED_STATE")
public Action<?, ?> createBindUserFinishedAction() {
return new AbstractBindUserCreateAction<>(CreateBindUserEvent.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(CommonContext context, CreateBindUserEvent payload, Map<Object, Object> variables) throws Exception {
LOGGER.info("Bind user creation successfully finished with payload: {}", payload);
SuccessDetails successDetails = new SuccessDetails(payload.getEnvironmentCrn());
successDetails.getAdditionalDetails().put("suffix", List.of(payload.getSuffix()));
operationService.completeOperation(payload.getAccountId(), payload.getOperationId(), Set.of(successDetails), Set.of());
LOGGER.debug("Finalizing user creation finished");
sendEvent(context, CreateBindUserFlowEvent.CREATE_BIND_USER_FINISHED_EVENT.event(), payload);
}
};
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails in project cloudbreak by hortonworks.
the class RebootActions method rebootFailureAction.
@Bean(name = "REBOOT_FAILED_STATE")
public Action<?, ?> rebootFailureAction() {
return new AbstractRebootAction<>(InstanceFailureEvent.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(RebootContext context, InstanceFailureEvent payload, Map<Object, Object> variables) {
addMdcOperationId(variables);
rebootService.handleInstanceRebootError(context);
String message = String.format("Rebooting failed for %s.", context.getInstanceIds());
LOGGER.error(message);
Stack stack = context.getStack();
SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
FailureDetails failureDetails = new FailureDetails(stack.getEnvironmentCrn(), message);
operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
sendEvent(context, new InstanceEvent(RebootEvent.REBOOT_FAIL_HANDLED_EVENT.event(), context.getStack().getId(), context.getInstanceIdList()));
}
@Override
protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, InstanceFailureEvent payload) {
Long stackId = payload.getResourceId();
Stack stack = stackService.getStackById(stackId);
MDCBuilder.buildMdcContext(stack);
return new RebootContext(flowParameters, stack, payload.getInstanceIds().stream().map(instanceId -> {
InstanceMetaData md = new InstanceMetaData();
md.setInstanceId(instanceId);
return md;
}).collect(Collectors.toList()), null, null);
}
@Override
protected Object getFailurePayload(InstanceFailureEvent payload, Optional<RebootContext> flowContext, Exception ex) {
return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
}
@Override
protected void initPayloadConverterMap(List<PayloadConverter<InstanceFailureEvent>> payloadConverters) {
payloadConverters.add(new RebootInstancesResultToCleanupFailureEventConverter());
payloadConverters.add(new WaitUntilAvailableFailedToInstanceFailureEventConverter());
}
};
}
Aggregations