use of com.sequenceiq.freeipa.flow.stack.StackEvent 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.flow.stack.StackEvent 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;
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method recordHostnamesAction.
@Bean(name = "UPSCALE_RECORD_HOSTNAMES_STATE")
public Action<?, ?> recordHostnamesAction() {
return new AbstractUpscaleAction<>(HostMetadataSetupSuccess.class) {
@Override
protected void doExecute(StackContext context, HostMetadataSetupSuccess payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Recording hostnames");
List<String> instanceIds = getInstanceIds(variables);
List<String> hosts = stack.getNotDeletedInstanceMetaDataList().stream().filter(instanceMetaData -> instanceIds.contains(instanceMetaData.getInstanceId())).map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toList());
setUpscaleHosts(variables, hosts);
sendEvent(context, UPSCALE_RECORD_HOSTNAMES_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method revokeCertsAction.
@Bean(name = "DOWNSCALE_REVOKE_CERTS_STATE")
public Action<?, ?> revokeCertsAction() {
return new AbstractDownscaleAction<>(StackEvent.class) {
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
stackUpdater.updateStackStatus(context.getStack().getId(), getInProgressStatus(variables), "Revoking certificates");
CleanupEvent cleanupEvent = buildCleanupEvent(context, getDownscaleHosts(variables));
RevokeCertsRequest request = new RevokeCertsRequest(cleanupEvent, context.getStack());
sendEvent(context, request);
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method updateMetadataForDeletionRequestAction.
@Bean(name = "DOWNSCALE_UPDATE_METADATA_FOR_DELETION_REQUEST_STATE")
public Action<?, ?> updateMetadataForDeletionRequestAction() {
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), "Updating metadata for deletion request");
List<String> repairInstanceIds = getInstanceIds(variables);
terminationService.requestDeletion(stack.getId(), repairInstanceIds);
sendEvent(context, UPDATE_METADATA_FOR_DELETION_REQUEST_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
}
};
}
Aggregations