use of com.sequenceiq.freeipa.flow.stack.StackEvent 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.StackEvent 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.StackEvent 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.StackEvent in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method updateKerberosNameserversConfigAction.
@Bean(name = "UPSCALE_UPDATE_KERBEROS_NAMESERVERS_CONFIG_STATE")
public Action<?, ?> updateKerberosNameserversConfigAction() {
return new AbstractUpscaleAction<>(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, UPSCALE_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, UPSCALE_UPDATE_KERBEROS_NAMESERVERS_CONFIG_FAILED_EVENT.selector(), new UpscaleFailureEvent(stack.getId(), "Updating kerberos nameserver config", Set.of(), Map.of(), e));
}
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method addInstancesAction.
@Bean(name = "UPSCALE_ADD_INSTANCES_STATE")
public Action<?, ?> addInstancesAction() {
return new AbstractUpscaleAction<>(StackEvent.class) {
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Adding instances");
List<CloudInstance> newInstances = buildNewInstances(context.getStack(), getInstanceCountByGroup(variables));
if (newInstances.isEmpty()) {
skipAddingNewInstances(context, stack);
} else {
addNewInstances(context, stack, newInstances);
}
}
private void skipAddingNewInstances(StackContext context, Stack stack) {
List<CloudResourceStatus> list = resourceService.getAllAsCloudResourceStatus(stack.getId());
UpscaleStackRequest<UpscaleStackResult> request = new UpscaleStackRequest<>(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), ResourceLists.transform(list), new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L));
UpscaleStackResult result = new UpscaleStackResult(request.getResourceId(), ResourceStatus.CREATED, list);
sendEvent(context, result.selector(), result);
}
private void addNewInstances(StackContext context, Stack stack, List<CloudInstance> newInstances) {
Stack updatedStack = instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, newInstances);
List<CloudResource> cloudResources = resourceService.findAllByStackId(stack.getId()).stream().map(resource -> resourceConverter.convert(resource)).collect(Collectors.toList());
CloudStack updatedCloudStack = cloudStackConverter.convert(updatedStack);
UpscaleStackRequest<UpscaleStackResult> request = new UpscaleStackRequest<>(context.getCloudContext(), context.getCloudCredential(), updatedCloudStack, cloudResources, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, (long) newInstances.size()));
sendEvent(context, request.selector(), request);
}
private List<CloudInstance> buildNewInstances(Stack stack, int instanceCountByGroup) {
long privateId = privateIdProvider.getFirstValidPrivateId(stack.getInstanceGroups());
List<CloudInstance> newInstances = new ArrayList<>();
for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
int remainingInstances = instanceCountByGroup - instanceGroup.getNotDeletedInstanceMetaDataSet().size();
for (long i = 0; i < remainingInstances; ++i) {
newInstances.add(cloudStackConverter.buildInstance(stack, null, instanceGroup, stack.getStackAuthentication(), privateId++, InstanceStatus.CREATE_REQUESTED));
}
}
return newInstances;
}
};
}
Aggregations