use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method updateEnvironmentStackConfigAction.
@Bean(name = "UPSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_STATE")
public Action<?, ?> updateEnvironmentStackConfigAction() {
return new AbstractUpscaleAction<>(StackEvent.class) {
@Inject
private EnvironmentEndpoint environmentEndpoint;
@Inject
private WebApplicationExceptionMessageExtractor webApplicationExceptionMessageExtractor;
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating environment stack config");
try {
ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> {
environmentEndpoint.updateConfigsInEnvironmentByCrn(stack.getEnvironmentCrn());
});
sendEvent(context, UPSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
} catch (ClientErrorException e) {
String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
LOGGER.error("Failed to update the stack config due to {}", errorMessage, e);
sendEvent(context, UPSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT.selector(), new UpscaleFailureEvent(stack.getId(), "Updating environment stack config", Set.of(), Map.of(), e));
} catch (Exception e) {
LOGGER.error("Failed to update the stack config", e);
sendEvent(context, UPSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT.selector(), new UpscaleFailureEvent(stack.getId(), "Updating environment stack config", Set.of(), Map.of(), e));
}
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method updateMetadataAction.
@Bean(name = "UPSCALE_UPDATE_METADATA_STATE")
public Action<?, ?> updateMetadataAction() {
return new AbstractUpscaleAction<>(PostInstallFreeIpaSuccess.class) {
@Override
protected void doExecute(StackContext context, PostInstallFreeIpaSuccess payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Upscale update metadata");
if (!isRepair(variables)) {
int nodeCount = getInstanceCountByGroup(variables);
for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
instanceGroup.setNodeCount(nodeCount);
instanceGroupService.save(instanceGroup);
}
}
sendEvent(context, UPSCALE_UPDATE_METADATA_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackContext 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.flow.stack.StackContext in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method extendMetadataAction.
@Bean(name = "UPSCALE_EXTEND_METADATA_STATE")
public Action<?, ?> extendMetadataAction() {
return new AbstractUpscaleAction<>(StackEvent.class) {
private final Set<InstanceStatus> unusedInstanceStatuses = Set.of(InstanceStatus.CREATE_REQUESTED, InstanceStatus.CREATED);
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Extending metadata");
List<CloudInstance> allKnownInstances = cloudStackConverter.buildInstances(stack);
List<Resource> resources = resourceService.findAllByStackId(stack.getId());
List<CloudResource> cloudResources = resources.stream().map(r -> resourceConverter.convert(r)).collect(Collectors.toList());
List<CloudInstance> newCloudInstances = allKnownInstances.stream().filter(this::isNewInstances).collect(Collectors.toList());
CollectMetadataRequest request = new CollectMetadataRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, newCloudInstances, allKnownInstances);
sendEvent(context, request.selector(), request);
}
private boolean isNewInstances(CloudInstance cloudInstance) {
return unusedInstanceStatuses.contains(cloudInstance.getTemplate().getStatus());
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method bootstrappingMachinesAction.
@Bean(name = "UPSCALE_BOOTSTRAPPING_MACHINES_STATE")
public Action<?, ?> bootstrappingMachinesAction() {
return new AbstractUpscaleAction<>(ClusterProxyRegistrationSuccess.class) {
@Override
protected void doExecute(StackContext context, ClusterProxyRegistrationSuccess payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Bootstrapping machines");
BootstrapMachinesRequest request = new BootstrapMachinesRequest(stack.getId());
sendEvent(context, request.selector(), request);
}
};
}
Aggregations