use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.
the class ValidationExceptionMapperTest method testToResponse.
@Test
public void testToResponse() throws Exception {
final ExceptionMapper<ValidationException> mapper = new ValidationExceptionMapper();
final Map<String, List<ValidationResult>> validationErrors = ImmutableMap.of("foo", ImmutableList.of(new ValidationResult.ValidationFailed("foo failed")), "bar", ImmutableList.of(new ValidationResult.ValidationFailed("bar failed"), new ValidationResult.ValidationFailed("baz failed")));
@SuppressWarnings("ThrowableInstanceNeverThrown") final ValidationException exception = new ValidationException(validationErrors);
final Response response = mapper.toResponse(exception);
assertThat(response.getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
assertThat(response.getMediaType()).isEqualTo(MediaType.APPLICATION_JSON_TYPE);
assertThat(response.hasEntity()).isTrue();
assertThat(response.getEntity()).isInstanceOf(ValidationApiError.class);
final ValidationApiError responseEntity = (ValidationApiError) response.getEntity();
assertThat(responseEntity.getMessage()).startsWith("Validation failed!");
assertThat(responseEntity.getValidationErrors()).containsKeys("foo", "bar");
assertThat(responseEntity.getValidationErrors().get("foo")).hasSize(1);
assertThat(responseEntity.getValidationErrors().get("bar")).hasSize(2);
}
use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.
the class BundleImporter method createInputs.
private void createInputs(final String bundleId, final Set<Input> inputs, final String userName) throws org.graylog2.plugin.inputs.Extractor.ReservedFieldException, org.graylog2.ConfigurationException, NoSuchInputTypeException, ValidationException, ExtractorFactory.NoSuchExtractorException, NotFoundException, ConfigurationException {
for (final Input input : inputs) {
final MessageInput messageInput = createMessageInput(bundleId, input, userName);
createdInputs.put(messageInput.getId(), messageInput);
// Launch input. (this will run async and clean up itself in case of an error.)
inputLauncher.launch(messageInput);
}
}
use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.
the class BundleImporter method createMessageInput.
private MessageInput createMessageInput(final String bundleId, final Input inputDescription, final String userName) throws NoSuchInputTypeException, ConfigurationException, ValidationException, NotFoundException, org.graylog2.ConfigurationException, ExtractorFactory.NoSuchExtractorException, org.graylog2.plugin.inputs.Extractor.ReservedFieldException {
final Configuration inputConfig = new Configuration(inputDescription.getConfiguration());
final DateTime createdAt = Tools.nowUTC();
final MessageInput messageInput = messageInputFactory.create(inputDescription.getType(), inputConfig);
messageInput.setTitle(inputDescription.getTitle());
messageInput.setGlobal(inputDescription.isGlobal());
messageInput.setCreatorUserId(userName);
messageInput.setCreatedAt(createdAt);
messageInput.setContentPack(bundleId);
messageInput.checkConfiguration();
// Don't run if exclusive and another instance is already running.
if (messageInput.isExclusive() && inputRegistry.hasTypeRunning(messageInput.getClass())) {
LOG.error("Input type <{}> of input <{}> is exclusive and already has input running.", messageInput.getClass(), messageInput.getTitle());
}
final String id = inputDescription.getId();
final org.graylog2.inputs.Input mongoInput;
if (id == null) {
mongoInput = inputService.create(buildMongoDbInput(inputDescription, userName, createdAt, bundleId));
} else {
mongoInput = inputService.create(id, buildMongoDbInput(inputDescription, userName, createdAt, bundleId));
}
// Persist input.
final String persistId = inputService.save(mongoInput);
messageInput.setPersistId(persistId);
messageInput.initialize();
addStaticFields(messageInput, inputDescription.getStaticFields());
addExtractors(messageInput, inputDescription.getExtractors(), userName);
return messageInput;
}
use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.
the class Configuration method validateNetworkInterfaces.
@ValidatorMethod
@SuppressWarnings("unused")
public void validateNetworkInterfaces() throws ValidationException {
final URI restListenUri = getRestListenUri();
final URI webListenUri = getWebListenUri();
if (restListenUri.getPort() == webListenUri.getPort() && !restListenUri.getHost().equals(webListenUri.getHost()) && (WILDCARD_IP_ADDRESS.equals(restListenUri.getHost()) || WILDCARD_IP_ADDRESS.equals(webListenUri.getHost()))) {
throw new ValidationException("Wildcard IP addresses cannot be used if the Graylog REST API and web interface listen on the same port.");
}
}
use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.
the class EsNodeProviderTest method zenUnicastHostsAreTrimmed.
@Test
public void zenUnicastHostsAreTrimmed() throws IOException, ValidationException, RepositoryException {
Map<String, String> settings = ImmutableMap.of("password_secret", "thisisatest", "retention_strategy", "delete", "root_password_sha2", "thisisatest", "elasticsearch_discovery_zen_ping_unicast_hosts", " example.com, example.net ");
final ElasticsearchConfiguration config = new ElasticsearchConfiguration();
new JadConfig(new InMemoryRepository(settings), config).process();
final Settings nodeSettings = EsNodeProvider.readNodeSettings(config, nodeId);
assertThat(nodeSettings.getAsArray("discovery.zen.ping.unicast.hosts")).contains("example.com", "example.net");
}
Aggregations