use of com.sequenceiq.freeipa.entity.Stack 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);
}
};
}
use of com.sequenceiq.freeipa.entity.Stack 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.entity.Stack 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;
}
};
}
use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method validateFreeIpaCloudStorage.
@Bean(name = "UPSCALE_VALIDATING_CLOUD_STORAGE_STATE")
public Action<?, ?> validateFreeIpaCloudStorage() {
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), "Validating cloud storage");
ValidateCloudStorageRequest request = new ValidateCloudStorageRequest(stack.getId());
sendEvent(context, request.selector(), request);
}
};
}
use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method validateInstancesAction.
@Bean(name = "UPSCALE_VALIDATE_INSTANCES_STATE")
public Action<?, ?> validateInstancesAction() {
return new AbstractUpscaleAction<>(UpscaleStackResult.class) {
@Override
protected void doExecute(StackContext context, UpscaleStackResult payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Validating new instances");
try {
finishAddInstances(context, payload);
sendEvent(context, UPSCALE_VALIDATE_INSTANCES_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
} catch (Exception e) {
LOGGER.error("Failed to validate the instances", e);
sendEvent(context, UPSCALE_VALIDATE_INSTANCES_FAILED_EVENT.selector(), new UpscaleFailureEvent(stack.getId(), "Validating new instances", Set.of(), Map.of(), e));
}
}
private void finishAddInstances(StackContext context, UpscaleStackResult payload) {
LOGGER.debug("Upscale stack result: {}", payload);
List<CloudResourceStatus> results = payload.getResults();
validateResourceResults(context, payload.getErrorDetails(), results);
Set<Resource> resourceSet = transformResults(results, context.getStack());
if (resourceSet.isEmpty()) {
metadataSetupService.cleanupRequestedInstances(context.getStack());
throw new OperationException("Failed to upscale the cluster since all create request failed. Resource set is empty");
}
LOGGER.debug("Adding new instances to the stack is DONE");
}
private void validateResourceResults(StackContext context, Exception exception, List<CloudResourceStatus> results) {
if (exception != null) {
LOGGER.info(format("Failed to upscale stack: %s", context.getCloudContext()), exception);
throw new OperationException(exception);
}
List<CloudResourceStatus> missingResources = results.stream().filter(result -> CommonResourceType.TEMPLATE == result.getCloudResource().getType().getCommonResourceType()).filter(status -> status.isFailed() || status.isDeleted()).collect(Collectors.toList());
if (!missingResources.isEmpty()) {
StringBuilder message = new StringBuilder("Failed to upscale the stack for ").append(context.getCloudContext()).append(" due to: ");
missingResources.forEach(res -> message.append("[privateId: ").append(res.getPrivateId()).append(", statusReason: ").append(res.getStatusReason()).append("] "));
LOGGER.warn(message.toString());
throw new OperationException(message.toString());
}
}
private Set<Resource> transformResults(Iterable<CloudResourceStatus> cloudResourceStatuses, Stack stack) {
Set<Resource> retSet = new HashSet<>();
for (CloudResourceStatus cloudResourceStatus : cloudResourceStatuses) {
if (!cloudResourceStatus.isFailed()) {
CloudResource cloudResource = cloudResourceStatus.getCloudResource();
Resource resource = new Resource(cloudResource.getType(), cloudResource.getName(), cloudResource.getReference(), cloudResource.getStatus(), stack, null, cloudResource.getAvailabilityZone());
retSet.add(resource);
}
}
return retSet;
}
};
}
Aggregations