Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
CLOUD-97300 responds with BadRequest when regions could not be querie…
Browse files Browse the repository at this point in the history
…d from the provider
  • Loading branch information
biharitomi authored and mhmxs committed Feb 28, 2018
1 parent 82a8ccc commit fed1663
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,14 @@ public void accept(Event<GetPlatformRegionsRequestV2> 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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<GetCloudParameterException> {

@Override
Response.Status getResponseStatus() {
return BAD_REQUEST;
}

@Override
protected boolean logException() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -384,7 +384,7 @@ public Map<String, InstanceGroupParameterResponse> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit fed1663

Please sign in to comment.