use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.
the class StackImageUpdateService method getNewImageIfVersionsMatch.
public StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) {
try {
restRequestThreadLocalService.setWorkspace(stack.getWorkspace());
Image currentImage = stackImageService.getCurrentImage(stack);
StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage);
if (!isCloudPlatformMatches(stack, newImage)) {
String message = messagesService.getMessage(Msg.CLOUDPLATFORM_DIFFERENT.code(), Lists.newArrayList(String.join(",", newImage.getImage().getImageSetsByProvider().keySet()), stack.cloudPlatform()));
LOGGER.debug(message);
throw new OperationException(message);
}
if (!isOsVersionsMatch(currentImage, newImage)) {
String message = messagesService.getMessage(Msg.OSVERSION_DIFFERENT.code(), Lists.newArrayList(newImage.getImage().getOs(), newImage.getImage().getOsType(), currentImage.getOs(), currentImage.getOsType()));
LOGGER.debug(message);
throw new OperationException(message);
}
if (!isStackMatchIfPrewarmed(newImage)) {
String message = "Stack versions don't match on prewarmed image with cluster's";
LOGGER.debug(message);
throw new OperationException(message);
}
return newImage;
} catch (CloudbreakImageNotFoundException e) {
LOGGER.info("Cloudbreak Image not found", e);
throw new CloudbreakApiException(e.getMessage(), e);
} catch (CloudbreakImageCatalogException e) {
LOGGER.info("Cloudbreak Image Catalog error", e);
throw new CloudbreakApiException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.service.OperationException 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.service.OperationException in project cloudbreak by hortonworks.
the class ServiceProviderConnectorAdapter method getPlatformParameters.
public PlatformParameters getPlatformParameters(Stack stack) {
LOGGER.debug("Get platform parameters for: {}", stack);
CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).build();
Credential credential = credentialClientService.getByEnvironmentCrn(stack.getEnvironmentCrn());
CloudCredential cloudCredential = credentialConverter.convert(credential);
PlatformParameterRequest parameterRequest = new PlatformParameterRequest(cloudContext, cloudCredential);
eventBus.notify(parameterRequest.selector(), eventFactory.createEvent(parameterRequest));
try {
PlatformParameterResult res = parameterRequest.await();
LOGGER.debug("Platform parameter result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
LOGGER.error("Failed to get platform parameters", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return res.getPlatformParameters();
} catch (InterruptedException e) {
LOGGER.error("Error while getting platform parameters: " + cloudContext, e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.
the class ServiceProviderConnectorAdapter method deleteStack.
public void deleteStack(Stack stack) {
LOGGER.debug("Assembling terminate stack event for stack: {}", stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(Crn.safeFromString(stack.getResourceCrn()).getAccountId()).withTenantId(stack.getTenant().getId()).build();
Credential credential = credentialClientService.getByEnvironmentCrn(stack.getEnvironmentCrn());
CloudCredential cloudCredential = credentialConverter.convert(credential);
List<CloudResource> resources = stack.getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
CloudStack cloudStack = cloudStackConverter.convert(stack);
TerminateStackRequest<TerminateStackResult> terminateRequest = new TerminateStackRequest<>(cloudContext, cloudStack, cloudCredential, resources);
LOGGER.debug("Triggering terminate stack event: {}", terminateRequest);
eventBus.notify(terminateRequest.selector(), eventFactory.createEvent(terminateRequest));
try {
TerminateStackResult res = terminateRequest.await();
LOGGER.debug("Terminate stack result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
if (res.getErrorDetails() != null) {
LOGGER.info("Failed to terminate the stack", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
throw new OperationException(format("Failed to terminate the stack: %s due to %s", cloudContext, res.getStatusReason()));
}
} catch (InterruptedException e) {
LOGGER.error("Error while terminating the stack", e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.
the class ResourceDefinitionService method getResourceDefinition.
@Cacheable("resourceDefinitionCache")
public String getResourceDefinition(String cloudPlatform, String resource) {
LOGGER.debug("Sending request for {} {} resource property definition", cloudPlatform, resource);
CloudPlatformVariant platformVariant = new CloudPlatformVariant(Platform.platform(cloudPlatform), Variant.EMPTY);
ResourceDefinitionRequest request = new ResourceDefinitionRequest(platformVariant, resource);
eventBus.notify(request.selector(), eventFactory.createEvent(request));
try {
ResourceDefinitionResult result = request.await();
LOGGER.debug("Resource property definition: {}", result);
return result.getDefinition();
} catch (InterruptedException e) {
LOGGER.info("Error while sending resource definition request", e);
throw new OperationException(e);
}
}
Aggregations