Search in sources :

Example 16 with DataAdapterDto

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;
}
Also used : DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) ObjectId(org.bson.types.ObjectId)

Example 17 with DataAdapterDto

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;
    }
}
Also used : LookupDataAdapter(org.graylog2.plugin.lookup.LookupDataAdapter)

Example 18 with DataAdapterDto

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);
}
Also used : LoggingServiceListener(org.graylog2.utilities.LoggingServiceListener)

Example 19 with DataAdapterDto

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);
}
Also used : DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 20 with DataAdapterDto

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);
}
Also used : DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Aggregations

DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)17 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)8 Test (org.junit.Test)7 ApiOperation (io.swagger.annotations.ApiOperation)6 Path (javax.ws.rs.Path)6 Entity (org.graylog2.contentpacks.model.entities.Entity)5 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)5 BadRequestException (javax.ws.rs.BadRequestException)4 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)4 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)4 LookupTableDto (org.graylog2.lookup.dto.LookupTableDto)4 AuditEvent (org.graylog2.audit.jersey.AuditEvent)3 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)3 FallbackAdapterConfig (org.graylog2.plugin.lookup.FallbackAdapterConfig)3 LookupDataAdapter (org.graylog2.plugin.lookup.LookupDataAdapter)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)2