use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.
the class InstanceMetaDataToCloudInstanceConverter method convert.
public CloudInstance convert(InstanceMetaData metaDataEntity) {
InstanceGroup group = metaDataEntity.getInstanceGroup();
Optional<StackAuthenticationView> stackAuthenticationView = instanceMetaDataService.getStackAuthenticationViewByInstanceMetaDataId(metaDataEntity.getId());
Template template = metaDataEntity.getInstanceGroup().getTemplate();
Optional<StackAuthentication> stackAuthentication = stackAuthenticationView.map(StackAuthenticationView::getStackAuthentication);
InstanceStatus status = getInstanceStatus(metaDataEntity);
String imageId = stackAuthenticationView.map(StackAuthenticationView::getStackId).map(stackId -> imageService.getByStackId(stackId)).map(ImageEntity::getImageName).orElse(null);
InstanceTemplate instanceTemplate = stackToCloudStackConverter.buildInstanceTemplate(template, group.getGroupName(), metaDataEntity.getPrivateId(), status, imageId);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication(stackAuthentication.map(StackAuthentication::getPublicKey).orElse(null), stackAuthentication.map(StackAuthentication::getPublicKeyId).orElse(null), stackAuthentication.map(StackAuthentication::getLoginUserName).orElse(null));
Map<String, Object> params = new HashMap<>();
params.put(SUBNET_ID, metaDataEntity.getSubnetId());
params.put(CloudInstance.INSTANCE_NAME, metaDataEntity.getInstanceName());
Stack stack = stackAuthenticationView.map(StackAuthenticationView::getStackId).map(stackService::getStackById).orElseThrow(NotFoundException::new);
Map<String, Object> cloudInstanceParameters = stackToCloudStackConverter.buildCloudInstanceParameters(stack.getEnvironmentCrn(), metaDataEntity);
params.putAll(cloudInstanceParameters);
return new CloudInstance(metaDataEntity.getInstanceId(), instanceTemplate, instanceAuthentication, metaDataEntity.getSubnetId(), stack.getAvailabilityZone(), params);
}
use of com.sequenceiq.freeipa.entity.Stack 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.entity.Stack 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.entity.Stack in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method upscaleFailureAction.
@Bean(name = "UPSCALE_FAIL_STATE")
public Action<?, ?> upscaleFailureAction() {
return new AbstractUpscaleAction<>(UpscaleFailureEvent.class) {
@Inject
private OperationService operationService;
@Override
protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<UpscaleState, UpscaleFlowEvent> stateContext, UpscaleFailureEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return super.createFlowContext(flowParameters, stateContext, payload);
}
@Override
protected void doExecute(StackContext context, UpscaleFailureEvent payload, Map<Object, Object> variables) {
LOGGER.error("Upscale 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 = "Upscale 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 upscaling FreeIPA");
enableNodeStatusChecker(stack, "Failed upscaling FreeIPA");
sendEvent(context, FAIL_HANDLED_EVENT.event(), payload);
}
@Override
protected void initPayloadConverterMap(List<PayloadConverter<UpscaleFailureEvent>> payloadConverters) {
payloadConverters.add(new UpscaleStackResultToUpscaleFailureEventConverter());
payloadConverters.add(new CollectMetadataResultToUpscaleFailureEventConverter());
payloadConverters.add(new BootstrapMachinesFailedToUpscaleFailureEventConverter());
payloadConverters.add(new HostMetadataSetupFailedToUpscaleFailureEventConverter());
payloadConverters.add(new InstallFreeIpaServicesFailedToUpscaleFailureEventConverter());
payloadConverters.add(new ClusterProxyUpdateRegistrationFailedToUpscaleFailureEventConverter());
payloadConverters.add(new PostInstallFreeIpaFailedToUpscaleFailureEventConverter());
}
};
}
use of com.sequenceiq.freeipa.entity.Stack 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());
}
};
}
Aggregations