diff --git a/cloud-reactor/src/main/java/com/sequenceiq/cloudbreak/cloud/handler/GetRegionsV2Handler.java b/cloud-reactor/src/main/java/com/sequenceiq/cloudbreak/cloud/handler/GetRegionsV2Handler.java index 922861dc209..1d51950744c 100644 --- a/cloud-reactor/src/main/java/com/sequenceiq/cloudbreak/cloud/handler/GetRegionsV2Handler.java +++ b/cloud-reactor/src/main/java/com/sequenceiq/cloudbreak/cloud/handler/GetRegionsV2Handler.java @@ -38,17 +38,14 @@ public void accept(Event getRegionsRequestEvent) { CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant( Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant())); - CloudRegions cloudRegions = null; - try { - cloudRegions = cloudPlatformConnectors.get(cloudPlatformVariant) - .platformResources().regions(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters()); - } catch (Exception e) { - cloudRegions = new CloudRegions(); - } + + CloudRegions cloudRegions = cloudPlatformConnectors.get(cloudPlatformVariant) + .platformResources().regions(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters()); GetPlatformRegionsResultV2 getPlatformRegionsResultV2 = new GetPlatformRegionsResultV2(request, cloudRegions); request.getResult().onNext(getPlatformRegionsResultV2); LOGGER.info("Query platform regions types finished."); - } catch (RuntimeException e) { + } catch (Exception e) { + LOGGER.warn("Could not get regions from the cloud provider due to:", e); request.getResult().onNext(new GetPlatformRegionsResultV2(e.getMessage(), e, request)); } } diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/controller/EndpointConfig.java b/core/src/main/java/com/sequenceiq/cloudbreak/controller/EndpointConfig.java index 1791ad868fd..7b2cee9e8da 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/controller/EndpointConfig.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/controller/EndpointConfig.java @@ -21,6 +21,7 @@ import com.sequenceiq.cloudbreak.controller.mapper.DefaultExceptionMapper; import com.sequenceiq.cloudbreak.controller.mapper.DuplicatedKeyValueExceptionMapper; import com.sequenceiq.cloudbreak.controller.mapper.EntityNotFoundExceptionMapper; +import com.sequenceiq.cloudbreak.controller.mapper.GetCloudParameterExceptionMapper; import com.sequenceiq.cloudbreak.controller.mapper.HibernateConstraintViolationExceptionMapper; import com.sequenceiq.cloudbreak.controller.mapper.HttpMediaTypeNotSupportedExceptionMapper; import com.sequenceiq.cloudbreak.controller.mapper.HttpMessageNotReadableExceptionMapper; @@ -114,6 +115,7 @@ private void registerExceptionMappers() { register(DataIntegrityViolationExceptionMapper.class); register(TerminationFailedExceptionMapper.class); register(WebApplicaitonExceptionMapper.class); + register(GetCloudParameterExceptionMapper.class); register(RuntimeExceptionMapper.class); register(DefaultExceptionMapper.class); diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/controller/mapper/GetCloudParameterExceptionMapper.java b/core/src/main/java/com/sequenceiq/cloudbreak/controller/mapper/GetCloudParameterExceptionMapper.java new file mode 100644 index 00000000000..2d929e35f71 --- /dev/null +++ b/core/src/main/java/com/sequenceiq/cloudbreak/controller/mapper/GetCloudParameterExceptionMapper.java @@ -0,0 +1,20 @@ +package com.sequenceiq.cloudbreak.controller.mapper; + +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; + +import javax.ws.rs.core.Response; + +import com.sequenceiq.cloudbreak.service.stack.GetCloudParameterException; + +public class GetCloudParameterExceptionMapper extends BaseExceptionMapper { + + @Override + Response.Status getResponseStatus() { + return BAD_REQUEST; + } + + @Override + protected boolean logException() { + return false; + } +} diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/service/stack/CloudParameterService.java b/core/src/main/java/com/sequenceiq/cloudbreak/service/stack/CloudParameterService.java index 93098f21c73..b4563b4c5f3 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/service/stack/CloudParameterService.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/service/stack/CloudParameterService.java @@ -198,7 +198,7 @@ public CloudNetworks getCloudNetworks(Credential credential, String region, Stri LOGGER.info("Platform networks types result: {}", res); if (res.getStatus().equals(EventStatus.FAILED)) { LOGGER.error("Failed to get platform networks", res.getErrorDetails()); - throw new OperationException(res.getErrorDetails()); + throw new GetCloudParameterException("Failed to get networks for the cloud provider", res.getErrorDetails()); } return res.getCloudNetworks(); } catch (InterruptedException e) { @@ -218,7 +218,7 @@ public CloudSshKeys getCloudSshKeys(Credential credential, String region, String LOGGER.info("Platform sshkeys types result: {}", res); if (res.getStatus().equals(EventStatus.FAILED)) { LOGGER.error("Failed to get platform sshkeys", res.getErrorDetails()); - throw new OperationException(res.getErrorDetails()); + throw new GetCloudParameterException("Failed to get SSH keys for the cloud provider", res.getErrorDetails()); } return res.getCloudSshKeys(); } catch (InterruptedException e) { @@ -239,7 +239,7 @@ public CloudSecurityGroups getSecurityGroups(Credential credential, String regio LOGGER.info("Platform securitygroups types result: {}", res); if (res.getStatus().equals(EventStatus.FAILED)) { LOGGER.error("Failed to get platform securitygroups", res.getErrorDetails()); - throw new OperationException(res.getErrorDetails()); + throw new GetCloudParameterException("Failed to get security groups for the cloud provider", res.getErrorDetails()); } return res.getCloudSecurityGroups(); } catch (InterruptedException e) { @@ -283,7 +283,7 @@ public CloudVmTypes getVmTypesV2(Credential credential, String region, String va LOGGER.info("Platform vmtypes result: {}", res); if (res.getStatus().equals(EventStatus.FAILED)) { LOGGER.error("Failed to get platform vmtypes", res.getErrorDetails()); - throw new OperationException(res.getErrorDetails()); + throw new GetCloudParameterException("Failed to VM types for the cloud provider", res.getErrorDetails()); } return res.getCloudVmTypes(); } catch (InterruptedException e) { @@ -302,8 +302,8 @@ public CloudRegions getRegionsV2(Credential credential, String region, String va GetPlatformRegionsResultV2 res = getPlatformRegionsRequest.await(); LOGGER.info("Platform regions result: {}", res); if (res.getStatus().equals(EventStatus.FAILED)) { - LOGGER.error("Failed to get platform regions", res.getErrorDetails()); - throw new OperationException(res.getErrorDetails()); + throw new GetCloudParameterException("Failed to get regions from the cloud provider due to network issues or invalid credential", + res.getErrorDetails()); } return res.getCloudRegions(); } catch (InterruptedException e) { @@ -323,7 +323,7 @@ public CloudGateWays getGateways(Credential credential, String region, String va LOGGER.info("Platform gateways result: {}", res); if (res.getStatus().equals(EventStatus.FAILED)) { LOGGER.error("Failed to get platform gateways", res.getErrorDetails()); - throw new OperationException(res.getErrorDetails()); + throw new GetCloudParameterException("Failed to get gateways for the cloud provider", res.getErrorDetails()); } return res.getCloudGateWays(); } catch (InterruptedException e) { @@ -343,7 +343,7 @@ public CloudIpPools getPublicIpPools(Credential credential, String region, Strin LOGGER.info("Platform publicIpPools result: {}", res); if (res.getStatus().equals(EventStatus.FAILED)) { LOGGER.error("Failed to get platform publicIpPools", res.getErrorDetails()); - throw new OperationException(res.getErrorDetails()); + throw new GetCloudParameterException("Failed to get public IP pools for the cloud provider", res.getErrorDetails()); } return res.getCloudIpPools(); } catch (InterruptedException e) { @@ -363,7 +363,7 @@ public CloudAccessConfigs getCloudAccessConfigs(Credential credential, String re LOGGER.info("Platform accessConfigs result: {}", res); if (res.getStatus().equals(EventStatus.FAILED)) { LOGGER.error("Failed to get platform accessConfigs", res.getErrorDetails()); - throw new OperationException(res.getErrorDetails()); + throw new GetCloudParameterException("Failed to get access configs for the cloud provider", res.getErrorDetails()); } return res.getCloudAccessConfigs(); } catch (InterruptedException e) { @@ -384,7 +384,7 @@ public Map getInstanceGroupParameters(Cr LOGGER.info("Platform instanceGroupParameterResult result: {}", res); if (res.getStatus().equals(EventStatus.FAILED)) { LOGGER.error("Failed to get platform instanceGroupParameterResult", res.getErrorDetails()); - throw new OperationException(res.getErrorDetails()); + throw new GetCloudParameterException("Failed to instance group parameters for the cloud provider", res.getErrorDetails()); } return res.getInstanceGroupParameterResponses(); } catch (InterruptedException e) { diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/service/stack/GetCloudParameterException.java b/core/src/main/java/com/sequenceiq/cloudbreak/service/stack/GetCloudParameterException.java new file mode 100644 index 00000000000..0f325a5d443 --- /dev/null +++ b/core/src/main/java/com/sequenceiq/cloudbreak/service/stack/GetCloudParameterException.java @@ -0,0 +1,16 @@ +package com.sequenceiq.cloudbreak.service.stack; + +public class GetCloudParameterException extends RuntimeException { + + public GetCloudParameterException(String message) { + super(message); + } + + public GetCloudParameterException(String message, Throwable cause) { + super(message, cause); + } + + public GetCloudParameterException(Throwable cause) { + super(cause); + } +}