use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackService method validateOrchestrator.
public void validateOrchestrator(Orchestrator orchestrator) {
try {
ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
containerOrchestrator.validateApiEndpoint(new OrchestrationCredential(orchestrator.getApiEndpoint(), orchestrator.getAttributes().getMap()));
} catch (CloudbreakException e) {
throw new BadRequestException(String.format("Invalid orchestrator type: %s", e.getMessage()));
} catch (CloudbreakOrchestratorException e) {
throw new BadRequestException(String.format("Error occurred when trying to reach orchestrator API: %s", e.getMessage()));
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackService method updateStatus.
@Transactional(TxType.NEVER)
public void updateStatus(Long stackId, StatusRequest status, boolean updateCluster) {
Stack stack = getByIdWithLists(stackId);
Cluster cluster = null;
if (stack.getCluster() != null) {
cluster = clusterRepository.findOneWithLists(stack.getCluster().getId());
}
switch(status) {
case SYNC:
sync(stack, false);
break;
case FULL_SYNC:
sync(stack, true);
break;
case REPAIR_FAILED_NODES:
repairFailedNodes(stack);
break;
case STOPPED:
stop(stack, cluster, updateCluster);
break;
case STARTED:
start(stack, cluster, updateCluster);
break;
default:
throw new BadRequestException("Cannot update the status of stack because status request not valid.");
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackService method start.
private void start(Stack stack, Cluster cluster, boolean updateCluster) {
if (stack.isAvailable()) {
String statusDesc = cloudbreakMessagesService.getMessage(Msg.STACK_START_IGNORED.code());
LOGGER.info(statusDesc);
eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), statusDesc);
} else if ((!stack.isStopped() || (cluster != null && !cluster.isStopped())) && !stack.isStartFailed()) {
throw new BadRequestException(String.format("Cannot update the status of stack '%s' to STARTED, because it isn't in STOPPED state.", stack.getName()));
} else if (stack.isStopped() || stack.isStartFailed()) {
stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.START_REQUESTED);
flowManager.triggerStackStart(stack.getId());
if (updateCluster && cluster != null) {
ambariClusterService.updateStatus(stack.getId(), StatusRequest.STARTED);
}
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackService method create.
@Transactional(TxType.NEVER)
public Stack create(IdentityUser user, Stack stack, String imageCatalog, Optional<String> imageId, Optional<Blueprint> blueprint) {
Stack savedStack;
stack.setOwner(user.getUserId());
stack.setAccount(user.getAccount());
stack.setGatewayPort(nginxPort);
setPlatformVariant(stack);
String stackName = stack.getName();
MDCBuilder.buildMdcContext(stack);
try {
if (!stack.getStackAuthentication().passwordAuthenticationRequired() && !Strings.isNullOrEmpty(stack.getStackAuthentication().getPublicKey())) {
long start = System.currentTimeMillis();
rsaPublicKeyValidator.validate(stack.getStackAuthentication().getPublicKey());
LOGGER.info("RSA key has been validated in {} ms fot stack {}", System.currentTimeMillis() - start, stackName);
}
if (stack.getOrchestrator() != null) {
orchestratorRepository.save(stack.getOrchestrator());
}
stack.getStackAuthentication().setLoginUserName(SSH_USER_CB);
long start = System.currentTimeMillis();
String template = connector.getTemplate(stack);
LOGGER.info("Get cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
savedStack = stackRepository.save(stack);
LOGGER.info("Stackrepository save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
addTemplateForStack(stack, template);
LOGGER.info("Save cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
addCloudbreakDetailsForStack(stack);
LOGGER.info("Add Cloudbreak template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
MDCBuilder.buildMdcContext(savedStack);
start = System.currentTimeMillis();
instanceGroupRepository.save(savedStack.getInstanceGroups());
LOGGER.info("Instance groups saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
SecurityConfig securityConfig = tlsSecurityService.storeSSHKeys();
LOGGER.info("Generating SSH keys took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
securityConfig.setSaltPassword(PasswordUtil.generatePassword());
securityConfig.setSaltBootPassword(PasswordUtil.generatePassword());
securityConfig.setKnoxMasterSecret(PasswordUtil.generatePassword());
LOGGER.info("Generating salt passwords took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
securityConfig.setStack(stack);
start = System.currentTimeMillis();
securityConfigRepository.save(securityConfig);
LOGGER.info("Security config save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
savedStack.setSecurityConfig(securityConfig);
start = System.currentTimeMillis();
imageService.create(savedStack, connector.getPlatformParameters(stack), imageCatalog, imageId, blueprint);
LOGGER.info("Image creation took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.STACK, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
} catch (CloudbreakImageNotFoundException e) {
LOGGER.error("Cloudbreak Image not found", e);
throw new CloudbreakApiException(e.getMessage(), e);
} catch (CloudbreakImageCatalogException e) {
LOGGER.error("Cloudbreak Image Catalog error", e);
throw new CloudbreakApiException(e.getMessage(), e);
}
return savedStack;
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class ServiceProviderCredentialAdapter method interactiveLogin.
public Map<String, String> interactiveLogin(Credential credential) {
CloudContext cloudContext = new CloudContext(credential.getId(), credential.getName(), credential.cloudPlatform(), credential.getOwner());
ExtendedCloudCredential cloudCredential = extendedCloudCredentialConverter.convert(credential);
InteractiveLoginRequest request = new InteractiveLoginRequest(cloudContext, cloudCredential);
LOGGER.info("Triggering event: {}", request);
eventBus.notify(request.selector(), eventFactory.createEvent(request));
try {
InteractiveLoginResult res = request.await();
String message = "Interactive login Failed: ";
LOGGER.info("Result: {}", res);
if (res.getStatus() != EventStatus.OK) {
LOGGER.error(message, res.getErrorDetails());
throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
}
return res.getParameters();
} catch (InterruptedException e) {
LOGGER.error("Error while executing credential verification", e);
throw new OperationException(e);
}
}
Aggregations