use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method removeDnsEntriesAction.
@Bean(name = "DOWNSCALE_REMOVE_DNS_ENTRIES_STATE")
public Action<?, ?> removeDnsEntriesAction() {
return new AbstractDownscaleAction<>(RevokeCertsResponse.class) {
@Override
protected void doExecute(StackContext context, RevokeCertsResponse payload, Map<Object, Object> variables) {
stackUpdater.updateStackStatus(context.getStack().getId(), getInProgressStatus(variables), "Remove DNS entries");
CleanupEvent cleanupEvent = buildCleanupEvent(context, getDownscaleHosts(variables));
RemoveDnsRequest request = new RemoveDnsRequest(cleanupEvent);
sendEvent(context, request);
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackContext 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.flow.stack.StackContext in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method stopTelemetryAction.
@Bean(name = "DOWNSCALE_STOP_TELEMETRY_STATE")
public Action<?, ?> stopTelemetryAction() {
return new AbstractDownscaleAction<>(StackEvent.class) {
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Stopping telemetry");
List<String> repairInstanceIds = getInstanceIds(variables);
StopTelemetryRequest stopTelemetryRequest = new StopTelemetryRequest(stack.getId(), repairInstanceIds);
sendEvent(context, stopTelemetryRequest.selector(), stopTelemetryRequest);
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method collectResourcesAction.
@Bean(name = "DOWNSCALE_COLLECT_RESOURCES_STATE")
public Action<?, ?> collectResourcesAction() {
return new AbstractDownscaleAction<>(StopTelemetryResponse.class) {
@Override
protected void doExecute(StackContext context, StopTelemetryResponse payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Collecting resources");
List<String> repairInstanceIds = getInstanceIds(variables);
List<CloudResource> cloudResources = getCloudResources(stack);
List<CloudInstance> cloudInstances = getCloudInstances(stack, repairInstanceIds);
DownscaleStackCollectResourcesRequest request = new DownscaleStackCollectResourcesRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), cloudResources, cloudInstances);
sendEvent(context, request.selector(), request);
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method downscaleAddAdditionalHostnamesAction.
@Bean(name = "DOWNSCALE_ADD_ADDITIONAL_HOSTNAMES_STATE")
public Action<?, ?> downscaleAddAdditionalHostnamesAction() {
return new AbstractDownscaleAction<>(CollectAdditionalHostnamesResponse.class) {
@Override
protected void doExecute(StackContext context, CollectAdditionalHostnamesResponse payload, Map<Object, Object> variables) throws Exception {
Stack stack = context.getStack();
Set<String> knownHostnamesFromStack = stack.getNotDeletedInstanceMetaDataList().stream().map(InstanceMetaData::getDiscoveryFQDN).filter(Objects::nonNull).collect(Collectors.toSet());
List<String> currentHostsToRemove = getDownscaleHosts(variables);
Set<String> newHostsToRemove = payload.getHostnames().stream().filter(hostname -> !currentHostsToRemove.contains(hostname)).filter(hostname -> !knownHostnamesFromStack.contains(hostname)).collect(Collectors.toSet());
if (isRepair(variables) && !newHostsToRemove.isEmpty()) {
LOGGER.info("Adding hostnames [{}] to the list of hostnames to remove", newHostsToRemove);
List<String> allHostnamesToRemove = new LinkedList<>(currentHostsToRemove);
allHostnamesToRemove.addAll(newHostsToRemove);
setDownscaleHosts(variables, allHostnamesToRemove);
}
sendEvent(context, DOWNSCALE_ADD_ADDITIONAL_HOSTNAMES_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
}
};
}
Aggregations