use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class AmbariClusterModificationService method installServices.
private Map<String, Integer> installServices(List<String> hosts, Stack stack, AmbariClient ambariClient, String hostGroup) {
try {
String blueprintName = stack.getCluster().getBlueprint().getAmbariName();
// In case If we changed the blueprintName field we need to query the validation name information from ambari
Map<String, String> blueprintsMap = ambariClient.getBlueprintsMap();
if (!blueprintsMap.entrySet().isEmpty()) {
blueprintName = blueprintsMap.keySet().iterator().next();
}
return singletonMap("UPSCALE_REQUEST", ambariClient.addHostsWithBlueprint(blueprintName, hostGroup, hosts));
} catch (HttpResponseException e) {
if ("Conflict".equals(e.getMessage())) {
throw new BadRequestException("Host already exists.", e);
} else {
String errorMessage = AmbariClientExceptionUtil.getErrorMessage(e);
throw new CloudbreakServiceException("Ambari could not install services. " + errorMessage, e);
}
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class CollectDownscaleCandidatesHandler method accept.
@Override
public void accept(Event<CollectDownscaleCandidatesRequest> event) {
CollectDownscaleCandidatesRequest request = event.getData();
CollectDownscaleCandidatesResult result;
try {
Stack stack = stackService.getByIdWithLists(request.getStackId());
Set<String> hostNames;
if (request.getHostNames() == null || request.getHostNames().isEmpty()) {
hostNames = ambariDecommissioner.collectDownscaleCandidates(stack, request.getHostGroupName(), request.getScalingAdjustment());
} else {
hostNames = request.getHostNames();
String hostName = hostNames.stream().findFirst().orElseThrow(() -> new BadRequestException("Unable to find host name"));
ambariDecommissioner.verifyNodeCount(stack, stack.getCluster(), hostName);
}
result = new CollectDownscaleCandidatesResult(request, hostNames);
} catch (Exception e) {
result = new CollectDownscaleCandidatesResult(e.getMessage(), e, request);
}
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class InteractiveCredentialCreationHandler method accept.
@Override
public void accept(Event<InteractiveCredentialCreationRequest> interactiveCredentialCreationRequestEvent) {
InteractiveCredentialCreationRequest interactiveCredentialCreationRequest = interactiveCredentialCreationRequestEvent.getData();
ExtendedCloudCredential extendedCloudCredential = interactiveCredentialCreationRequest.getExtendedCloudCredential();
Credential credential = extendedCloudCredentialToCredentialConverter.convert(extendedCloudCredential);
try {
credentialService.createWithRetry(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), credential);
} catch (DuplicateKeyValueException e) {
sendErrorNotification(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), extendedCloudCredential.getCloudPlatform(), DuplicatedKeyValueExceptionMapper.errorMessage(e));
} catch (BadRequestException e) {
sendErrorNotification(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), extendedCloudCredential.getCloudPlatform(), e.getMessage());
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackRequestToStackConverterTest method testConvertWithNoGateway.
@SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE")
@Test
public void testConvertWithNoGateway() throws CloudbreakException {
InstanceGroup instanceGroup = mock(InstanceGroup.class);
when(instanceGroup.getInstanceGroupType()).thenReturn(InstanceGroupType.CORE);
// GIVEN
ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-2");
given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<>(Collections.singletonList(instanceGroup)));
given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<>(Collections.singletonList(instanceGroup)));
given(conversionService.convert(any(StackAuthenticationRequest.class), eq(StackAuthentication.class))).willReturn(new StackAuthentication());
given(conversionService.convert(any(FailurePolicyRequest.class), eq(FailurePolicy.class))).willReturn(new FailurePolicy());
given(conversionService.convert(any(InstanceGroupRequest.class), eq(InstanceGroup.class))).willReturn(instanceGroup);
given(conversionService.convert(any(OrchestratorRequest.class), eq(Orchestrator.class))).willReturn(new Orchestrator());
given(orchestratorTypeResolver.resolveType(any(String.class))).willReturn(OrchestratorType.HOST);
// WHEN
try {
Stack stack = underTest.convert(getRequest("stack/stack.json"));
} catch (BadRequestException e) {
// THEN
Assert.assertEquals("Ambari server must be specified", e.getMessage());
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class TemplateService method delete.
private void delete(Template template) {
authorizationService.hasWritePermission(template);
LOGGER.debug("Deleting template. {} - {}", new Object[] { template.getId(), template.getName() });
List<Stack> allStackForTemplate = stackRepository.findAllStackForTemplate(template.getId());
if (allStackForTemplate.isEmpty()) {
template.setTopology(null);
if (ResourceStatus.USER_MANAGED.equals(template.getStatus())) {
templateRepository.delete(template);
} else {
template.setName(NameUtil.postfixWithTimestamp(template.getName()));
template.setStatus(ResourceStatus.DEFAULT_DELETED);
templateRepository.save(template);
}
} else if (isRunningStackReferToTemplate(allStackForTemplate)) {
throw new BadRequestException(String.format("There are stacks associated with template '%s'. Please remove these before deleting the template.", template.getName()));
} else {
template.setName(NameUtil.postfixWithTimestamp(template.getName()));
template.setTopology(null);
template.setDeleted(true);
if (ResourceStatus.DEFAULT.equals(template.getStatus())) {
template.setStatus(ResourceStatus.DEFAULT_DELETED);
}
templateRepository.save(template);
}
}
Aggregations