use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class TopologyService method delete.
private void delete(Topology topology) {
authorizationService.hasWritePermission(topology);
if (0L != credentialRepository.countByTopology(topology) + templateRepository.countByTopology(topology) + networkRepository.countByTopology(topology)) {
throw new BadRequestException(String.format("Topology '%d' is in use, cannot be deleted.", topology.getId()));
}
LOGGER.debug("Deleting topology. {} - {}", new Object[] { topology.getId(), topology.getName() });
Date now = new Date();
String terminatedName = topology.getName() + DELIMITER + now.getTime();
topology.setName(terminatedName);
topology.setDeleted(true);
topologyRepository.save(topology);
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackServiceTest method testRemoveInstanceWhenTheHostIsGatewayTypeThenWeShoulNotAllowTerminationWithException.
@Test
public void testRemoveInstanceWhenTheHostIsGatewayTypeThenWeShoulNotAllowTerminationWithException() {
String exceptionMessage = String.format("Downscale for node [public IP: %s] is prohibited because it maintains the Ambari server", INSTANCE_PUBLIC_IP);
when(stackRepository.findOne(STACK_ID)).thenReturn(stack);
when(instanceMetaDataRepository.findByInstanceId(STACK_ID, INSTANCE_ID)).thenReturn(instanceMetaData);
when(instanceMetaData.getInstanceMetadataType()).thenReturn(GATEWAY);
when(instanceMetaData.getPublicIp()).thenReturn(INSTANCE_PUBLIC_IP);
doThrow(new BadRequestException(exceptionMessage)).when(downscaleValidatorService).checkInstanceIsTheAmbariServerOrNot(INSTANCE_PUBLIC_IP, GATEWAY);
expectedException.expect(BadRequestException.class);
expectedException.expectMessage(exceptionMessage);
underTest.removeInstance(user, STACK_ID, INSTANCE_ID);
verify(instanceMetaDataRepository, times(1)).findByInstanceId(STACK_ID, INSTANCE_ID);
verify(downscaleValidatorService, times(1)).checkInstanceIsTheAmbariServerOrNot(INSTANCE_PUBLIC_IP, GATEWAY);
verify(downscaleValidatorService, times(0)).checkUserHasRightToTerminateInstance(anyBoolean(), anyString(), anyString(), anyLong());
verify(flowManager, times(0)).triggerStackRemoveInstance(anyLong(), anyString(), anyString());
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class UpdateStackRequestV2ToUpdateStackRequestConverter method convert.
@Override
public UpdateStackJson convert(StackScaleRequestV2 source) {
UpdateStackJson updateStackJson = new UpdateStackJson();
updateStackJson.setWithClusterEvent(true);
InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(source.getStackId(), source.getGroup());
if (instanceGroup != null) {
InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
instanceGroupAdjustmentJson.setInstanceGroup(source.getGroup());
int scaleNumber = source.getDesiredCount() - instanceGroup.getNodeCount();
instanceGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
} else {
throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
}
return updateStackJson;
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackValidationRequestToStackValidationConverter method convertHostGroupsFromJson.
private Set<HostGroup> convertHostGroupsFromJson(Collection<InstanceGroup> instanceGroups, Iterable<HostGroupRequest> hostGroupsJsons) {
Set<HostGroup> hostGroups = new HashSet<>();
for (HostGroupRequest json : hostGroupsJsons) {
HostGroup hostGroup = new HostGroup();
hostGroup.setName(json.getName());
Constraint constraint = getConversionService().convert(json.getConstraint(), Constraint.class);
String instanceGroupName = json.getConstraint().getInstanceGroupName();
if (instanceGroupName != null) {
InstanceGroup instanceGroup = instanceGroups.stream().filter(instanceGroup1 -> instanceGroup1.getGroupName().equals(instanceGroupName)).findFirst().get();
if (instanceGroup == null) {
throw new BadRequestException(String.format("Cannot find instance group named '%s' in instance group list", instanceGroupName));
}
constraint.setInstanceGroup(instanceGroup);
}
hostGroup.setConstraint(constraint);
hostGroups.add(hostGroup);
}
return hostGroups;
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackService method validateScalingAdjustment.
private void validateScalingAdjustment(InstanceGroupAdjustmentJson instanceGroupAdjustmentJson, Stack stack) {
if (0 == instanceGroupAdjustmentJson.getScalingAdjustment()) {
throw new BadRequestException(String.format("Requested scaling adjustment on stack '%s' is 0. Nothing to do.", stack.getName()));
}
if (0 > instanceGroupAdjustmentJson.getScalingAdjustment()) {
InstanceGroup instanceGroup = stack.getInstanceGroupByInstanceGroupName(instanceGroupAdjustmentJson.getInstanceGroup());
if (-1 * instanceGroupAdjustmentJson.getScalingAdjustment() > instanceGroup.getNodeCount()) {
throw new BadRequestException(String.format("There are %s instances in instance group '%s'. Cannot remove %s instances.", instanceGroup.getNodeCount(), instanceGroup.getGroupName(), -1 * instanceGroupAdjustmentJson.getScalingAdjustment()));
}
int removableHosts = instanceMetaDataRepository.findRemovableInstances(stack.getId(), instanceGroupAdjustmentJson.getInstanceGroup()).size();
if (removableHosts < -1 * instanceGroupAdjustmentJson.getScalingAdjustment()) {
throw new BadRequestException(String.format("There are %s unregistered instances in instance group '%s' but %s were requested. Decommission nodes from the cluster!", removableHosts, instanceGroup.getGroupName(), instanceGroupAdjustmentJson.getScalingAdjustment() * -1));
}
}
}
Aggregations