use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class LoadBalancerRecreatorService method collectLoadBalancerMetadata.
private List<CloudLoadBalancerMetadata> collectLoadBalancerMetadata(AuthenticatedContext authenticatedContext, Long stackId) {
List<LoadBalancerType> loadBalancerTypes = loadBalancerPersistenceService.findByStackId(stackId).stream().map(LoadBalancer::getType).collect(Collectors.toList());
List<CloudResource> cloudResources = resourceService.findByStackIdAndType(stackId, ResourceType.ELASTIC_LOAD_BALANCER).stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
CollectLoadBalancerMetadataRequest request = new CollectLoadBalancerMetadataRequest(authenticatedContext.getCloudContext(), authenticatedContext.getCloudCredential(), loadBalancerTypes, cloudResources);
eventBus.notify(request.selector(), Event.wrap(request));
try {
CollectLoadBalancerMetadataResult res = request.await();
LOGGER.debug("Collect load balancer metadata result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
String msg = "Failed to collect the load balancer metadata. " + res.getErrorDetails().getMessage();
LOGGER.debug(msg);
throw new CloudbreakServiceException(msg, res.getErrorDetails());
}
return res.getResults();
} catch (InterruptedException e) {
LOGGER.error("Error while collect load balancer metadata", e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class StackCreationActions method prepareImageAction.
@Bean(name = "IMAGESETUP_STATE")
public Action<?, ?> prepareImageAction() {
return new AbstractStackCreationAction<>(SetupResult.class) {
@Override
protected void doExecute(StackCreationContext context, SetupResult payload, Map<Object, Object> variables) {
stackCreationService.prepareImage(context.getStack(), variables);
sendEvent(context);
}
@Override
protected Selectable createRequest(StackCreationContext context) {
try {
CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
Image image = imageService.getImage(context.getCloudContext().getId());
return new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image);
} catch (CloudbreakImageNotFoundException e) {
throw new CloudbreakServiceException(e);
}
}
};
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class StackUpscaleActions method finishExtendMetadata.
@Bean(name = "EXTEND_METADATA_FINISHED_STATE")
public Action<?, ?> finishExtendMetadata() {
return new AbstractStackUpscaleAction<>(CollectMetadataResult.class) {
@Override
protected void doExecute(StackScalingFlowContext context, CollectMetadataResult payload, Map<Object, Object> variables) throws TransactionExecutionException {
Integer adjustment = context.getHostGroupWithAdjustment().values().stream().reduce(0, Integer::sum);
Set<String> upscaleCandidateAddresses = stackUpscaleService.finishExtendMetadata(context.getStack(), adjustment, payload);
variables.put(UPSCALE_CANDIDATE_ADDRESSES, upscaleCandidateAddresses);
Set<String> hostGroups = context.getHostGroupWithAdjustment().keySet();
List<InstanceGroup> scaledInstanceGroups = instanceGroupService.findByStackIdAndInstanceGroupNames(payload.getResourceId(), hostGroups);
boolean gatewayWasUpscaled = scaledInstanceGroups.stream().anyMatch(instanceGroup -> InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType()));
if (gatewayWasUpscaled) {
LOGGER.info("Gateway type instance group");
Stack stack = stackService.getByIdWithListsInTransaction(context.getStack().getId());
InstanceMetaData gatewayMetaData = stack.getPrimaryGatewayInstance();
if (null == gatewayMetaData) {
throw new CloudbreakServiceException("Could not get gateway instance metadata from the cloud provider.");
}
DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(stack.getEnvironmentCrn());
CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData, environment, stack.getStackAuthentication());
LOGGER.info("Send GetSSHFingerprintsRequest because we need to collect SSH fingerprints");
Selectable sshFingerPrintReq = new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
sendEvent(context, sshFingerPrintReq);
} else {
StackEvent bootstrapPayload = new StackEvent(context.getStack().getId());
sendEvent(context, StackUpscaleEvent.BOOTSTRAP_NEW_NODES_EVENT.event(), bootstrapPayload);
}
}
};
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class NodeStatusService method saltPing.
public RPCResponse<NodeStatusProto.SaltHealthReport> saltPing(Long stackId) {
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
MDCBuilder.buildMdcContext(stack);
LOGGER.debug("Retrieving salt ping report from the hosts of stack: {}", stack.getResourceCrn());
try (CdpNodeStatusMonitorClient client = factory.getClient(stack, stack.getPrimaryGatewayInstance())) {
return client.saltPing(false, false);
} catch (CdpNodeStatusMonitorClientException e) {
throw new CloudbreakServiceException("Could not get salt ping report from stack.");
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class NodeStatusService method getSystemMetrics.
public RPCResponse<NodeStatusProto.NodeStatusReport> getSystemMetrics(Stack stack) {
MDCBuilder.buildMdcContext(stack);
LOGGER.debug("Retrieving system metrics report from the hosts of stack: {}", stack.getResourceCrn());
try (CdpNodeStatusMonitorClient client = factory.getClient(stack, stack.getPrimaryGatewayInstance())) {
return client.systemMetricsReport();
} catch (CdpNodeStatusMonitorClientException e) {
throw new CloudbreakServiceException("Could not get system metrics report from stack.");
}
}
Aggregations