use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class ChangePrimaryGatewayActions method finsihedAction.
@Bean(name = "CHANGE_PRIMARY_GATEWAY_FINISHED_STATE")
public Action<?, ?> finsihedAction() {
return new AbstractChangePrimaryGatewayAction<>(StackEvent.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(ChangePrimaryGatewayContext context, StackEvent payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
if (isFinalChain(variables)) {
successDetails.getAdditionalDetails().put("DownscaleHosts", getDownscaleHosts(variables));
successDetails.getAdditionalDetails().put("UpscaleHosts", getUpscaleHosts(variables));
operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
} else {
stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_IN_PROGRESS, "Finished changing the primary gateway");
}
sendEvent(context, CHANGE_PRIMARY_GATEWAY_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class ValidateInstancesHealthHandlerTest method testHealthy.
@Test
public void testHealthy() throws FreeIpaClientException {
Stack stack = new Stack();
stack.setId(1L);
when(stackService.getStackById(1L)).thenReturn(stack);
List<String> instanceIds = List.of("im1", "im2");
InstanceMetaData im1 = new InstanceMetaData();
im1.setInstanceId("im1");
im1.setDiscoveryFQDN("im1Fqdn");
InstanceMetaData im2 = new InstanceMetaData();
im2.setInstanceId("im2");
im2.setDiscoveryFQDN("im2Fqdn");
when(instanceMetaDataService.getNotTerminatedByInstanceIds(1L, instanceIds)).thenReturn(Set.of(im1, im2));
when(healthService.getInstanceHealthDetails(stack, im1)).thenReturn(createHealthyNodeDetail(im1));
when(healthService.getInstanceHealthDetails(stack, im2)).thenReturn(createHealthyNodeDetail(im2));
StackEvent result = (StackEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(new ValidateInstancesHealthEvent(1L, instanceIds))));
assertEquals(UPSCALE_VALIDATE_NEW_INSTANCES_HEALTH_FINISHED_EVENT.event(), result.selector());
assertEquals(1L, result.getResourceId());
}
use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method updateMetadataAction.
@Bean(name = "DOWNSCALE_UPDATE_METADATA_STATE")
public Action<?, ?> updateMetadataAction() {
return new AbstractDownscaleAction<>(RemoveHostsFromOrchestrationSuccess.class) {
@Inject
private InstanceGroupService instanceGroupService;
@Override
protected void doExecute(StackContext context, RemoveHostsFromOrchestrationSuccess payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating metadata");
List<String> repairInstanceIds = getInstanceIds(variables);
terminationService.finalizeTermination(stack.getId(), repairInstanceIds);
terminationService.finalizeTerminationForInstancesWithoutInstanceIds(stack.getId());
if (!isRepair(variables)) {
int nodeCount = getInstanceCountByGroup(variables);
instanceGroupService.findByStackId(stack.getId()).forEach(instanceGroup -> {
instanceGroup.setNodeCount(nodeCount);
instanceGroupService.save(instanceGroup);
});
}
sendEvent(context, UPDATE_METADATA_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method updateEnvironmentStackConfigAction.
@Bean(name = "DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_STATE")
public Action<?, ?> updateEnvironmentStackConfigAction() {
return new AbstractDownscaleAction<>(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 {
if (!isRepair(variables) || !isChainedAction(variables) || isFinalChain(variables)) {
ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> environmentEndpoint.updateConfigsInEnvironmentByCrn(stack.getEnvironmentCrn()));
}
sendEvent(context, DOWNSCALE_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, DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT.selector(), new DownscaleFailureEvent(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, DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT.selector(), new DownscaleFailureEvent(stack.getId(), "Updating environment stack config", Set.of(), Map.of(), e));
}
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method updateKerberosNameserversConfigAction.
@Bean(name = "DOWNSCALE_UPDATE_KERBEROS_NAMESERVERS_CONFIG_STATE")
public Action<?, ?> updateKerberosNameserversConfigAction() {
return new AbstractDownscaleAction<>(StackEvent.class) {
@Inject
private KerberosConfigUpdateService kerberosConfigUpdateService;
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating kerberos nameserver config");
try {
kerberosConfigUpdateService.updateNameservers(stack.getId());
sendEvent(context, DOWNSCALE_UPDATE_KERBEROS_NAMESERVERS_CONFIG_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
} catch (Exception e) {
LOGGER.error("Failed to update the kerberos nameserver config", e);
sendEvent(context, DOWNSCALE_UPDATE_KERBEROS_NAMESERVERS_CONFIG_FAILED_EVENT.selector(), new DownscaleFailureEvent(stack.getId(), "Updating kerberos nameserver config", Set.of(), Map.of(), e));
}
}
};
}
Aggregations