use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupTableResource method createAdapter.
@POST
@Path("adapters")
@AuditEvent(type = AuditEventTypes.LOOKUP_ADAPTER_CREATE)
@ApiOperation(value = "Create a new data adapter")
@RequiresPermissions(RestPermissions.LOOKUP_TABLES_CREATE)
public DataAdapterApi createAdapter(@Valid @ApiParam DataAdapterApi newAdapter) {
try {
DataAdapterDto dto = newAdapter.toDto();
DataAdapterDto saved = dbDataAdapterService.save(dto);
return DataAdapterApi.fromDto(saved);
} catch (DuplicateKeyException e) {
throw new BadRequestException(e.getMessage());
}
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupTableService method handleAdapterUpdate.
@Subscribe
public void handleAdapterUpdate(DataAdaptersUpdated updated) {
scheduler.schedule(() -> {
// first we create the new adapter instance and start it
// then we retrieve the old one so we can safely stop it later
// then we build a new lookup table instance with the new adapter instance
// last we can remove the old lookup table instance and stop the original adapter
// collect old adapter instances
final ImmutableSet.Builder<LookupDataAdapter> existingAdapters = ImmutableSet.builder();
// create new adapter and lookup table instances
final Map<DataAdapterDto, LookupDataAdapter> newAdapters = createAdapters(configService.findDataAdaptersForIds(updated.ids()));
final CountDownLatch runningLatch = new CountDownLatch(newAdapters.size());
newAdapters.forEach((dto, adapter) -> {
adapter.addListener(new DataAdapterListener(dto, adapter, runningLatch, existingAdapters::add), scheduler);
adapter.startAsync();
});
// wait until everything is either running or failed before starting the
awaitUninterruptibly(runningLatch);
// when a data adapter is updated, the lookup tables that use it need to be updated as well
final Collection<LookupTableDto> tablesToUpdate = configService.findTablesForDataAdapterIds(updated.ids());
tablesToUpdate.forEach(this::createLookupTable);
// stop old adapters
existingAdapters.build().forEach(AbstractIdleService::stopAsync);
}, 0, TimeUnit.SECONDS);
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupTableService method createAndStartAdapters.
protected CountDownLatch createAndStartAdapters() {
final Map<DataAdapterDto, LookupDataAdapter> adapters = createAdapters(configService.loadAllDataAdapters());
final CountDownLatch latch = new CountDownLatch(toIntExact(adapters.size()));
adapters.forEach((dto, adapter) -> {
adapter.addListener(new DataAdapterListener(dto, adapter, latch), scheduler);
adapter.startAsync();
});
return latch;
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupTableFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_TABLE_V1).data(objectMapper.convertValue(LookupTableEntity.create(ValueReference.of("http-dsv-no-cache"), ValueReference.of("HTTP DSV without Cache"), ValueReference.of("HTTP DSV without Cache"), ValueReference.of("no-op-cache"), ValueReference.of("http-dsv"), ValueReference.of("Default single value"), ValueReference.of(LookupDefaultValue.Type.STRING), ValueReference.of("Default multi value"), ValueReference.of(LookupDefaultValue.Type.OBJECT)), JsonNode.class)).build();
final EntityDescriptor cacheDescriptor = EntityDescriptor.create("no-op-cache", ModelTypes.LOOKUP_CACHE_V1);
final CacheDto cacheDto = CacheDto.builder().id("5adf24b24b900a0fdb4e0001").name("no-op-cache").title("No-op cache").description("No-op cache").config(new FallbackCacheConfig()).build();
final EntityDescriptor dataAdapterDescriptor = EntityDescriptor.create("http-dsv", ModelTypes.LOOKUP_ADAPTER_V1);
final DataAdapterDto dataAdapterDto = DataAdapterDto.builder().id("5adf24a04b900a0fdb4e0002").name("http-dsv").title("HTTP DSV").description("HTTP DSV").config(new FallbackAdapterConfig()).build();
final Map<EntityDescriptor, Object> nativeEntities = ImmutableMap.of(cacheDescriptor, cacheDto, dataAdapterDescriptor, dataAdapterDto);
assertThat(lookupTableService.findAll()).isEmpty();
final NativeEntity<LookupTableDto> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), nativeEntities, "username");
assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.LOOKUP_TABLE_V1);
assertThat(nativeEntity.entity().name()).isEqualTo("http-dsv-no-cache");
assertThat(nativeEntity.entity().title()).isEqualTo("HTTP DSV without Cache");
assertThat(nativeEntity.entity().description()).isEqualTo("HTTP DSV without Cache");
assertThat(nativeEntity.entity().cacheId()).isEqualTo("5adf24b24b900a0fdb4e0001");
assertThat(nativeEntity.entity().dataAdapterId()).isEqualTo("5adf24a04b900a0fdb4e0002");
assertThat(nativeEntity.entity().defaultSingleValue()).isEqualTo("Default single value");
assertThat(nativeEntity.entity().defaultSingleValueType()).isEqualTo(LookupDefaultValue.Type.STRING);
assertThat(nativeEntity.entity().defaultMultiValue()).isEqualTo("Default multi value");
assertThat(nativeEntity.entity().defaultMultiValueType()).isEqualTo(LookupDefaultValue.Type.OBJECT);
assertThat(lookupTableService.findAll()).hasSize(1);
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupDataAdapterFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
final Entity entity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.LOOKUP_ADAPTER_V1).data(objectMapper.convertValue(LookupDataAdapterEntity.create(ValueReference.of("http-dsv"), ValueReference.of("HTTP DSV"), ValueReference.of("HTTP DSV"), ReferenceMapUtils.toReferenceMap(Collections.emptyMap())), JsonNode.class)).build();
assertThat(dataAdapterService.findAll()).isEmpty();
final NativeEntity<DataAdapterDto> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
assertThat(nativeEntity.descriptor().id()).isNotNull();
assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.LOOKUP_ADAPTER_V1);
assertThat(nativeEntity.entity().name()).isEqualTo("http-dsv");
assertThat(nativeEntity.entity().title()).isEqualTo("HTTP DSV");
assertThat(nativeEntity.entity().description()).isEqualTo("HTTP DSV");
assertThat(dataAdapterService.findAll()).hasSize(1);
}
Aggregations