use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class DBDataAdapterService method save.
public DataAdapterDto save(DataAdapterDto table) {
WriteResult<DataAdapterDto, ObjectId> save = db.save(table);
final DataAdapterDto savedDataAdapter = save.getSavedObject();
clusterEventBus.post(DataAdaptersUpdated.create(savedDataAdapter.id()));
return savedDataAdapter;
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupTableService method createAdapter.
protected LookupDataAdapter createAdapter(DataAdapterDto dto) {
try {
final LookupDataAdapter.Factory2 factory2 = adapterFactories2.get(dto.config().type());
final LookupDataAdapter.Factory factory = adapterFactories.get(dto.config().type());
final LookupDataAdapter adapter;
if (factory2 != null) {
adapter = factory2.create(dto);
} else if (factory != null) {
adapter = factory.create(dto.id(), dto.name(), dto.config());
} else {
LOG.warn("Unable to load data adapter {} of type {}, missing a factory. Is a required plugin missing?", dto.name(), dto.config().type());
// TODO system notification
return null;
}
addListeners(adapter, dto);
return adapter;
} catch (Exception e) {
LOG.error("Couldn't create adapter <{}/{}>", dto.name(), dto.id(), e);
return null;
}
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupTableService method addListeners.
protected void addListeners(LookupDataAdapter adapter, DataAdapterDto dto) {
adapter.addListener(new LoggingServiceListener("Data Adapter", String.format(Locale.ENGLISH, "%s/%s [@%s]", dto.name(), dto.id(), objectId(adapter)), LOG), scheduler);
// Each adapter needs to be added to the refresh scheduler
adapter.addListener(adapterRefreshService.newServiceListener(adapter), scheduler);
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupTableResource method deleteAdapter.
@DELETE
@Path("adapters/{idOrName}")
@AuditEvent(type = AuditEventTypes.LOOKUP_ADAPTER_DELETE)
@ApiOperation(value = "Delete the given data adapter", notes = "The data adapter cannot be in use by any lookup table, otherwise the request will fail.")
public DataAdapterApi deleteAdapter(@ApiParam(name = "idOrName") @PathParam("idOrName") @NotEmpty String idOrName) {
Optional<DataAdapterDto> dataAdapterDto = dbDataAdapterService.get(idOrName);
if (!dataAdapterDto.isPresent()) {
throw new NotFoundException();
}
DataAdapterDto dto = dataAdapterDto.get();
checkPermission(RestPermissions.LOOKUP_TABLES_DELETE, dto.id());
boolean unused = dbTableService.findByDataAdapterIds(singleton(dto.id())).isEmpty();
if (!unused) {
throw new BadRequestException("The adapter is still in use, cannot delete.");
}
dbDataAdapterService.delete(idOrName);
return DataAdapterApi.fromDto(dto);
}
use of org.graylog2.lookup.dto.DataAdapterDto in project graylog2-server by Graylog2.
the class LookupTableResource method updateAdapter.
@PUT
@Path("adapters/{idOrName}")
@AuditEvent(type = AuditEventTypes.LOOKUP_ADAPTER_UPDATE)
@ApiOperation(value = "Update the given data adapter settings")
public DataAdapterApi updateAdapter(@ApiParam(name = "idOrName") @PathParam("idOrName") @NotEmpty String idOrName, @Valid @ApiParam DataAdapterApi toUpdate) {
checkLookupAdapterId(idOrName, toUpdate);
checkPermission(RestPermissions.LOOKUP_TABLES_EDIT, toUpdate.id());
DataAdapterDto saved = dbDataAdapterService.save(toUpdate.toDto());
return DataAdapterApi.fromDto(saved);
}
Aggregations