Search in sources :

Example 1 with ContentPackService

use of org.graylog2.contentpacks.ContentPackService in project graylog2-server by Graylog2.

the class V20191219090834_AddSourcesPageTest method upgradeFailsBecauseSourcePageContentPackExists.

@Test
public void upgradeFailsBecauseSourcePageContentPackExists() throws IOException {
    final URL contentPackURL = V20191219090834_AddSourcesPage.class.getResource("V20191219090834_AddSourcesPage_Content_Pack.json");
    final ContentPack contentPack = ContentPackV1.builder().id(ModelId.of("04fcf179-49e0-4e8f-9c02-0ff13062efbe")).summary("summary").revision(1).name("Sources Page").description("description").vendor("").url(URI.create("http://graylog.com")).entities(ImmutableSet.of()).build();
    final ContentPackInstallation contentPackInstallation = ContentPackInstallation.builder().contentPackId(contentPack.id()).contentPackRevision(1).parameters(ImmutableMap.of()).entities(ImmutableSet.of()).comment("Comment").createdAt(Instant.now()).createdBy("admin").build();
    when(configService.get(V20191219090834_AddSourcesPage.MigrationCompleted.class)).thenReturn(null);
    when(objectMapper.readValue(contentPackURL, ContentPack.class)).thenReturn(contentPack);
    when(contentPackPersistenceService.insert(contentPack)).thenReturn(Optional.empty());
    assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> migration.upgrade()).withMessage("Could not install Source Page Content Pack.");
    verify(configService).write(V20191219090834_AddSourcesPage.MigrationCompleted.create("04fcf179-49e0-4e8f-9c02-0ff13062efbe"));
    verifyZeroInteractions(contentPackService);
}
Also used : ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) ContentPack(org.graylog2.contentpacks.model.ContentPack) URL(java.net.URL) Test(org.junit.Test)

Example 2 with ContentPackService

use of org.graylog2.contentpacks.ContentPackService in project graylog2-server by Graylog2.

the class ContentPackServiceTest method setUp.

@Before
public void setUp() throws Exception {
    final ContentPackInstallationPersistenceService contentPackInstallationPersistenceService = contentPackInstallService;
    final Set<ConstraintChecker> constraintCheckers = Collections.emptySet();
    pluginMetaData = new HashSet<>();
    outputFactories = new HashMap<>();
    outputFactories2 = new HashMap<>();
    final Map<ModelType, EntityWithExcerptFacade<?, ?>> entityFacades = ImmutableMap.of(ModelTypes.GROK_PATTERN_V1, new GrokPatternFacade(objectMapper, patternService), ModelTypes.STREAM_V1, new StreamFacade(objectMapper, streamService, streamRuleService, alertService, alarmCallbackConfigurationService, legacyAlertConditionMigration, indexSetService, userService), ModelTypes.OUTPUT_V1, new OutputFacade(objectMapper, outputService, pluginMetaData, outputFactories, outputFactories2));
    contentPackService = new ContentPackService(contentPackInstallationPersistenceService, constraintCheckers, entityFacades);
    Map<String, String> entityData = new HashMap<>(2);
    entityData.put("name", "NAME");
    entityData.put("pattern", "\\w");
    grokPattern = GrokPattern.builder().pattern("\\w").name("NAME").build();
    JsonNode jsonData = objectMapper.convertValue(entityData, JsonNode.class);
    EntityV1 entityV1 = EntityV1.builder().id(ModelId.of("12345")).type(ModelTypes.GROK_PATTERN_V1).data(jsonData).build();
    ImmutableSet<Entity> entities = ImmutableSet.of(entityV1);
    NativeEntityDescriptor nativeEntityDescriptor = NativeEntityDescriptor.create(ModelId.of("12345"), "dead-beef1", ModelTypes.GROK_PATTERN_V1, "NAME");
    nativeEntityDescriptors = ImmutableSet.of(nativeEntityDescriptor);
    contentPack = ContentPackV1.builder().description("test").entities(entities).name("test").revision(1).summary("").vendor("").url(URI.create("http://graylog.com")).id(ModelId.of("dead-beef")).build();
    contentPackInstallation = ContentPackInstallation.builder().contentPackId(ModelId.of("dead-beef")).contentPackRevision(1).entities(nativeEntityDescriptors).comment("Installed").parameters(ImmutableMap.copyOf(Collections.emptyMap())).createdAt(Instant.now()).createdBy("me").build();
}
Also used : Entity(org.graylog2.contentpacks.model.entities.Entity) StreamFacade(org.graylog2.contentpacks.facades.StreamFacade) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityWithExcerptFacade(org.graylog2.contentpacks.facades.EntityWithExcerptFacade) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) ModelType(org.graylog2.contentpacks.model.ModelType) ConstraintChecker(org.graylog2.contentpacks.constraints.ConstraintChecker) GrokPatternFacade(org.graylog2.contentpacks.facades.GrokPatternFacade) OutputFacade(org.graylog2.contentpacks.facades.OutputFacade) Before(org.junit.Before)

Example 3 with ContentPackService

use of org.graylog2.contentpacks.ContentPackService in project graylog2-server by Graylog2.

the class CatalogResourceTest method setUp.

@Before
public void setUp() {
    final ContentPackInstallationPersistenceService contentPackInstallationPersistenceService = mock(ContentPackInstallationPersistenceService.class);
    final Set<ConstraintChecker> constraintCheckers = Collections.emptySet();
    final Map<ModelType, EntityWithExcerptFacade<?, ?>> entityFacades = Collections.singletonMap(ModelType.of("test", "1"), mockEntityFacade);
    contentPackService = new ContentPackService(contentPackInstallationPersistenceService, constraintCheckers, entityFacades);
    catalogResource = new CatalogResource(contentPackService);
}
Also used : ContentPackService(org.graylog2.contentpacks.ContentPackService) ContentPackInstallationPersistenceService(org.graylog2.contentpacks.ContentPackInstallationPersistenceService) EntityWithExcerptFacade(org.graylog2.contentpacks.facades.EntityWithExcerptFacade) ModelType(org.graylog2.contentpacks.model.ModelType) ConstraintChecker(org.graylog2.contentpacks.constraints.ConstraintChecker) Before(org.junit.Before)

Example 4 with ContentPackService

use of org.graylog2.contentpacks.ContentPackService in project graylog2-server by Graylog2.

the class ContentPackResourceTest method setUp.

@Before
public void setUp() {
    objectMapper = new ObjectMapperProvider().get();
    objectMapper.setSubtypeResolver(new AutoValueSubtypeResolver());
    contentPackResource = new PermittedTestResource(contentPackService, contentPackPersistenceService, contentPackInstallationPersistenceService);
}
Also used : AutoValueSubtypeResolver(org.graylog2.jackson.AutoValueSubtypeResolver) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Before(org.junit.Before)

Example 5 with ContentPackService

use of org.graylog2.contentpacks.ContentPackService in project graylog2-server by Graylog2.

the class V20191219090834_AddSourcesPageTest method upgradeSuccessfully.

@Test
public void upgradeSuccessfully() throws IOException {
    final URL contentPackURL = V20191219090834_AddSourcesPage.class.getResource("V20191219090834_AddSourcesPage_Content_Pack.json");
    final ContentPack contentPack = ContentPackV1.builder().id(ModelId.of("04fcf179-49e0-4e8f-9c02-0ff13062efbe")).summary("summary").revision(1).name("Sources Page").description("description").vendor("").url(URI.create("http://graylog.com")).entities(ImmutableSet.of()).build();
    final ContentPackInstallation contentPackInstallation = ContentPackInstallation.builder().contentPackId(contentPack.id()).contentPackRevision(1).parameters(ImmutableMap.of()).entities(ImmutableSet.of()).comment("Comment").createdAt(Instant.now()).createdBy("admin").build();
    when(configService.get(V20191219090834_AddSourcesPage.MigrationCompleted.class)).thenReturn(null);
    when(contentPackPersistenceService.insert(contentPack)).thenReturn(Optional.ofNullable(contentPack));
    when(contentPackService.installContentPack(contentPack, Collections.emptyMap(), "Add Sources Page", "admin")).thenReturn(contentPackInstallation);
    when(objectMapper.readValue(contentPackURL, ContentPack.class)).thenReturn(contentPack);
    migration.upgrade();
    verify(contentPackService).installContentPack(contentPack, Collections.emptyMap(), "Add Sources Page", "admin");
    verify(configService).write(V20191219090834_AddSourcesPage.MigrationCompleted.create("04fcf179-49e0-4e8f-9c02-0ff13062efbe"));
}
Also used : ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) ContentPack(org.graylog2.contentpacks.model.ContentPack) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Before (org.junit.Before)3 URL (java.net.URL)2 ConstraintChecker (org.graylog2.contentpacks.constraints.ConstraintChecker)2 EntityWithExcerptFacade (org.graylog2.contentpacks.facades.EntityWithExcerptFacade)2 ContentPack (org.graylog2.contentpacks.model.ContentPack)2 ContentPackInstallation (org.graylog2.contentpacks.model.ContentPackInstallation)2 ModelType (org.graylog2.contentpacks.model.ModelType)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 HashMap (java.util.HashMap)1 ContentPackInstallationPersistenceService (org.graylog2.contentpacks.ContentPackInstallationPersistenceService)1 ContentPackService (org.graylog2.contentpacks.ContentPackService)1 GrokPatternFacade (org.graylog2.contentpacks.facades.GrokPatternFacade)1 OutputFacade (org.graylog2.contentpacks.facades.OutputFacade)1 StreamFacade (org.graylog2.contentpacks.facades.StreamFacade)1 Entity (org.graylog2.contentpacks.model.entities.Entity)1 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)1 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)1 AutoValueSubtypeResolver (org.graylog2.jackson.AutoValueSubtypeResolver)1 ObjectMapperProvider (org.graylog2.shared.bindings.providers.ObjectMapperProvider)1