use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class CmTemplateValidator method validateRole.
private void validateRole(String accountId, EntitledForServiceScale role, Versioned blueprintVersion, CmTemplateProcessor templateProcessor) {
boolean versionEnablesScaling = isVersionEnablesScaling(blueprintVersion, role);
boolean entitledFor = entitlementService.isEntitledFor(accountId, role.getEntitledFor());
if (role.getBlockedUntilCDPVersion().isPresent() && !versionEnablesScaling && !entitledFor) {
throw new BadRequestException(String.format("'%s' service is not enabled to scale until CDP %s", role.name(), role.getBlockedUntilCDPVersion().get()));
} else if (role.getBlockedUntilCDPVersion().isEmpty() && !entitledFor) {
throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name()));
} else if (role.getRequiredService().isPresent() && !isRequiredServicePresent(role.getRequiredService(), templateProcessor) && versionEnablesScaling) {
throw new BadRequestException(String.format("'%s' service is not presented on the cluster, and that is required", role.getRequiredService().get()));
} else {
LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor());
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class NetworkV4RequestToNetworkConverter method convert.
public Network convert(NetworkV4Request source) {
Network network = new Network();
network.setName(missingResourceNameGenerator.generateName(APIResourceType.NETWORK));
network.setSubnetCIDR(source.getSubnetCIDR());
network.setOutboundInternetTraffic(OutboundInternetTraffic.ENABLED);
Map<String, Object> parameters = providerParameterCalculator.get(source).asMap();
if (parameters != null) {
try {
network.setAttributes(new Json(parameters));
} catch (IllegalArgumentException ignored) {
throw new BadRequestException("Invalid parameters");
}
}
return network;
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class GatewayTopologyV4RequestToGatewayTopologyConverter method convertExposedServices.
private void convertExposedServices(GatewayTopology gatewayTopology, GatewayTopologyV4Request source) {
try {
if (!CollectionUtils.isEmpty(source.getExposedServices())) {
ExposedServices exposedServices = gatewayTopologyV4RequestToExposedServicesConverter.convert(source);
gatewayTopology.setExposedServices(new Json(exposedServices));
}
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid exposedServices in request. Could not be parsed to JSON.", e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class StopStartDownscaleFlowEventChainFactory method createFlowTriggerEventQueue.
@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(ClusterAndStackDownscaleTriggerEvent event) {
StackView stackView = stackService.getViewByIdWithoutAuth(event.getResourceId());
Map<String, Set<Long>> hostGroupsWithPrivateIds = event.getHostGroupsWithPrivateIds();
Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
// TODO CB-14929: Is a stack sync really required here. What does it do ? (As of now it also serves to accept the event)
addStackSyncTriggerEvent(event, flowEventChain);
if (hostGroupsWithPrivateIds.keySet().size() > 1) {
throw new BadRequestException("Start stop downscale flow was intended to handle only 1 hostgroup.");
}
for (Map.Entry<String, Set<Long>> hostGroupWithPrivateIds : hostGroupsWithPrivateIds.entrySet()) {
StopStartDownscaleTriggerEvent te = new StopStartDownscaleTriggerEvent(StopStartDownscaleEvent.STOPSTART_DOWNSCALE_TRIGGER_EVENT.event(), stackView.getId(), hostGroupWithPrivateIds.getKey(), hostGroupWithPrivateIds.getValue());
flowEventChain.add(te);
}
return new FlowTriggerEventQueue(getName(), event, flowEventChain);
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class ClouderaManagerClusterCreationSetupService method determineCmRepoConfig.
private ClusterComponent determineCmRepoConfig(Optional<Component> stackClouderaManagerRepoConfig, String osType, Cluster cluster, String cdhStackVersion) throws CloudbreakImageCatalogException {
Json json;
if (Objects.isNull(stackClouderaManagerRepoConfig) || stackClouderaManagerRepoConfig.isEmpty()) {
ImageCatalogPlatform platform = platformStringTransformer.getPlatformStringForImageCatalog(cluster.getStack().getCloudPlatform(), cluster.getStack().getPlatformVariant());
ClouderaManagerRepo clouderaManagerRepo = defaultClouderaManagerRepoService.getDefault(osType, StackType.CDH.name(), cdhStackVersion, platform);
if (clouderaManagerRepo == null) {
throw new BadRequestException(String.format("Couldn't determine Cloudera Manager repo for the stack: %s", cluster.getStack().getName()));
}
json = new Json(clouderaManagerRepo);
} else {
json = stackClouderaManagerRepoConfig.get().getAttributes();
}
return new ClusterComponent(ComponentType.CM_REPO_DETAILS, json, cluster);
}
Aggregations