use of com.sequenceiq.cloudbreak.controller.CloudbreakApiException in project cloudbreak by hortonworks.
the class ClusterToClusterResponseConverter method convertContainerConfig.
private void convertContainerConfig(Cluster source, ClusterResponse clusterResponse) {
Json customContainerDefinition = source.getCustomContainerDefinition();
if (customContainerDefinition != null && StringUtils.isNoneEmpty(customContainerDefinition.getValue())) {
try {
Map<String, String> map = customContainerDefinition.get(Map.class);
Map<String, String> result = new HashMap<>();
for (Entry<String, String> stringStringEntry : map.entrySet()) {
result.put(stringStringEntry.getKey(), stringStringEntry.getValue());
}
clusterResponse.setCustomContainers(new CustomContainerResponse(result));
} catch (IOException e) {
LOGGER.error("Failed to add customContainerDefinition to response", e);
throw new CloudbreakApiException("Failed to add customContainerDefinition to response", e);
}
}
}
use of com.sequenceiq.cloudbreak.controller.CloudbreakApiException in project cloudbreak by hortonworks.
the class ReactorFlowManager method notify.
private void notify(String selector, Acceptable acceptable) {
Event<Acceptable> event = eventFactory.createEventWithErrHandler(acceptable);
reactor.notify(selector, event);
try {
Boolean accepted = true;
if (event.getData().accepted() != null) {
accepted = event.getData().accepted().await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS);
}
if (accepted == null || !accepted) {
Stack stack = stackService.get(event.getData().getStackId());
throw new FlowsAlreadyRunningException(String.format("Stack %s has flows under operation, request not allowed.", stack.getName()));
}
} catch (InterruptedException e) {
throw new CloudbreakApiException(e.getMessage());
}
}
use of com.sequenceiq.cloudbreak.controller.CloudbreakApiException 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.CloudbreakApiException in project cloudbreak by hortonworks.
the class ClusterToClusterResponseConverter method convertKnox.
private void convertKnox(Cluster source, ClusterResponse clusterResponse) {
Gateway gateway = source.getGateway();
GatewayJson cloudGatewayJson = new GatewayJson();
cloudGatewayJson.setEnableGateway(gateway.getEnableGateway());
cloudGatewayJson.setTopologyName(gateway.getTopologyName());
Json exposedJson = gateway.getExposedServices();
if (exposedJson != null && StringUtils.isNoneEmpty(exposedJson.getValue())) {
try {
cloudGatewayJson.setExposedServices(exposedJson.get(ExposedServices.class).getServices());
} catch (IOException e) {
LOGGER.error("Failed to add exposedServices to response", e);
throw new CloudbreakApiException("Failed to add exposedServices to response", e);
}
}
cloudGatewayJson.setPath(gateway.getPath());
cloudGatewayJson.setTokenCert(gateway.getTokenCert());
cloudGatewayJson.setSsoProvider(gateway.getSsoProvider());
cloudGatewayJson.setSsoType(gateway.getSsoType());
cloudGatewayJson.setGatewayType(gateway.getGatewayType());
clusterResponse.setGateway(cloudGatewayJson);
}
Aggregations