Search in sources :

Example 36 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class SidecarCollectorFacade method decode.

private NativeEntity<Collector> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entity.data(), SidecarCollectorEntity.class);
    final Collector collector = Collector.builder().name(collectorEntity.name().asString(parameters)).serviceType(collectorEntity.serviceType().asString(parameters)).nodeOperatingSystem(collectorEntity.nodeOperatingSystem().asString(parameters)).executablePath(collectorEntity.executablePath().asString(parameters)).executeParameters(collectorEntity.executeParameters().asString(parameters)).validationParameters(collectorEntity.validationParameters().asString(parameters)).defaultTemplate(collectorEntity.defaultTemplate().asString(parameters)).build();
    final Collector savedCollector = collectorService.save(collector);
    return NativeEntity.create(entity.id(), savedCollector.id(), TYPE_V1, collector.name(), savedCollector);
}
Also used : SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector)

Example 37 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class SidecarCollectorFacade method findExisting.

private Optional<NativeEntity<Collector>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entity.data(), SidecarCollectorEntity.class);
    final String name = collectorEntity.name().asString(parameters);
    final String os = collectorEntity.nodeOperatingSystem().asString(parameters);
    final Optional<Collector> existingCollector = Optional.ofNullable(collectorService.findByNameAndOs(name, os));
    return existingCollector.map(collector -> NativeEntity.create(entity.id(), collector.id(), TYPE_V1, collector.name(), collector));
}
Also used : SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector)

Example 38 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class ViewFacade method createNativeEntity.

@Override
public NativeEntity<ViewDTO> createNativeEntity(Entity entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, String username) {
    ensureV1(entity);
    final User user = Optional.ofNullable(userService.load(username)).orElseThrow(() -> new IllegalStateException("Cannot load user <" + username + "> from db"));
    return decode((EntityV1) entity, parameters, nativeEntities, user);
}
Also used : User(org.graylog2.plugin.database.users.User)

Example 39 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class InputFacade method createExtractors.

private List<Extractor> createExtractors(final Input input, final List<ExtractorEntity> extractorEntities, final String username, final Map<String, ValueReference> parameters) throws Extractor.ReservedFieldException, org.graylog2.ConfigurationException, ExtractorFactory.NoSuchExtractorException, ValidationException {
    final ImmutableList.Builder<Extractor> result = ImmutableList.builder();
    for (ExtractorEntity extractorEntity : extractorEntities) {
        final List<Converter> converters = createConverters(extractorEntity.converters(), parameters);
        final Extractor extractor = addExtractor(input, extractorEntity.title().asString(parameters), extractorEntity.order().asInteger(parameters), extractorEntity.cursorStrategy().asEnum(parameters, Extractor.CursorStrategy.class), extractorEntity.type().asEnum(parameters, Extractor.Type.class), extractorEntity.sourceField().asString(parameters), extractorEntity.targetField().asString(parameters), toValueMap(extractorEntity.configuration(), parameters), converters, extractorEntity.conditionType().asEnum(parameters, Extractor.ConditionType.class), extractorEntity.conditionValue().asString(parameters), username);
        result.add(extractor);
    }
    return result.build();
}
Also used : ModelType(org.graylog2.contentpacks.model.ModelType) ImmutableList(com.google.common.collect.ImmutableList) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) Converter(org.graylog2.plugin.inputs.Converter) Extractor(org.graylog2.plugin.inputs.Extractor) GrokExtractor(org.graylog2.inputs.extractors.GrokExtractor) LookupTableExtractor(org.graylog2.inputs.extractors.LookupTableExtractor)

Example 40 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class SidecarCollectorConfigurationFacade method resolveEntityV1.

private Graph<Entity> resolveEntityV1(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
    final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build();
    mutableGraph.addNode(entity);
    final SidecarCollectorConfigurationEntity configurationEntity = objectMapper.convertValue(entity.data(), SidecarCollectorConfigurationEntity.class);
    final EntityDescriptor collectorDescriptor = EntityDescriptor.create(configurationEntity.collectorId().asString(parameters), ModelTypes.SIDECAR_COLLECTOR_V1);
    final Entity collectorEntity = entities.get(collectorDescriptor);
    if (collectorEntity != null) {
        mutableGraph.putEdge(entity, collectorEntity);
    }
    return ImmutableGraph.copyOf(mutableGraph);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity)

Aggregations

ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)18 Entity (org.graylog2.contentpacks.model.entities.Entity)16 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)16 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)16 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 Map (java.util.Map)10 ContentPackException (org.graylog2.contentpacks.exceptions.ContentPackException)10 ModelType (org.graylog2.contentpacks.model.ModelType)10 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)10 Set (java.util.Set)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 Graph (com.google.common.graph.Graph)8 GraphBuilder (com.google.common.graph.GraphBuilder)8 ImmutableGraph (com.google.common.graph.ImmutableGraph)8 MutableGraph (com.google.common.graph.MutableGraph)8 HashMap (java.util.HashMap)8 Optional (java.util.Optional)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 Collection (java.util.Collection)7