Search in sources :

Example 1 with DictionaryProviderEntity

use of io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity in project gravitee-management-rest-api by gravitee-io.

the class DictionaryManagerTest method shouldRestartProviderConfigChanged.

@Test
public void shouldRestartProviderConfigChanged() {
    final DictionaryProviderEntity provider = new DictionaryProviderEntity();
    provider.setConfiguration(JsonNodeFactory.instance.nullNode());
    final DictionaryTriggerEntity trigger = new DictionaryTriggerEntity();
    trigger.setRate(1);
    trigger.setUnit(TimeUnit.SECONDS);
    final DictionaryEntity dictionary = new DictionaryEntity();
    dictionary.setUpdatedAt(new Date());
    dictionary.setProvider(provider);
    dictionary.setId(DICTIONARY_ID);
    dictionary.setTrigger(trigger);
    final DictionaryProviderEntity providerUpdated = new DictionaryProviderEntity();
    providerUpdated.setConfiguration(JsonNodeFactory.instance.arrayNode());
    final DictionaryEntity dictionaryUpdated = new DictionaryEntity();
    dictionaryUpdated.setUpdatedAt(new Date(ZonedDateTime.now().plusSeconds(60).toInstant().toEpochMilli()));
    dictionaryUpdated.setProvider(providerUpdated);
    dictionaryUpdated.setId(DICTIONARY_ID);
    dictionaryUpdated.setTrigger(trigger);
    when(dictionaryService.findById(DICTIONARY_ID)).thenReturn(dictionary).thenReturn(dictionaryUpdated);
    cut.start(DICTIONARY_ID);
    cut.start(DICTIONARY_ID);
    verify(eventManager, times(1)).publishEvent(eq(DictionaryEvent.START), eq(dictionary));
    verify(eventManager, times(1)).publishEvent(eq(DictionaryEvent.RESTART), eq(dictionary));
    verifyNoMoreInteractions(eventManager);
}
Also used : DictionaryEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity) DictionaryTriggerEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryTriggerEntity) DictionaryProviderEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity) Date(java.util.Date) Test(org.junit.Test)

Example 2 with DictionaryProviderEntity

use of io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity in project gravitee-management-rest-api by gravitee-io.

the class DictionaryManagerTest method shouldRestartTriggerChanged.

@Test
public void shouldRestartTriggerChanged() {
    final DictionaryProviderEntity provider = new DictionaryProviderEntity();
    provider.setConfiguration(JsonNodeFactory.instance.nullNode());
    final DictionaryTriggerEntity trigger = new DictionaryTriggerEntity();
    trigger.setRate(1);
    trigger.setUnit(TimeUnit.SECONDS);
    final DictionaryEntity dictionary = new DictionaryEntity();
    dictionary.setUpdatedAt(new Date());
    dictionary.setProvider(provider);
    dictionary.setId(DICTIONARY_ID);
    dictionary.setTrigger(trigger);
    final DictionaryTriggerEntity triggerUpdated = new DictionaryTriggerEntity();
    triggerUpdated.setRate(1);
    triggerUpdated.setUnit(TimeUnit.MINUTES);
    final DictionaryEntity dictionaryUpdated = new DictionaryEntity();
    dictionaryUpdated.setUpdatedAt(new Date(ZonedDateTime.now().plusSeconds(60).toInstant().toEpochMilli()));
    dictionaryUpdated.setProvider(provider);
    dictionaryUpdated.setId(DICTIONARY_ID);
    dictionaryUpdated.setTrigger(triggerUpdated);
    when(dictionaryService.findById(DICTIONARY_ID)).thenReturn(dictionary).thenReturn(dictionaryUpdated);
    cut.start(DICTIONARY_ID);
    cut.start(DICTIONARY_ID);
    verify(eventManager, times(1)).publishEvent(eq(DictionaryEvent.START), eq(dictionary));
    verify(eventManager, times(1)).publishEvent(eq(DictionaryEvent.RESTART), eq(dictionary));
    verifyNoMoreInteractions(eventManager);
}
Also used : DictionaryEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity) DictionaryTriggerEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryTriggerEntity) DictionaryProviderEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity) Date(java.util.Date) Test(org.junit.Test)

Example 3 with DictionaryProviderEntity

use of io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity in project gravitee-management-rest-api by gravitee-io.

the class DictionaryManagerTest method shouldNotStartAlreadyStarted.

@Test
public void shouldNotStartAlreadyStarted() {
    final DictionaryProviderEntity provider = new DictionaryProviderEntity();
    provider.setConfiguration(JsonNodeFactory.instance.nullNode());
    final DictionaryEntity dictionary = new DictionaryEntity();
    dictionary.setUpdatedAt(new Date());
    dictionary.setProvider(provider);
    dictionary.setId(DICTIONARY_ID);
    when(dictionaryService.findById(DICTIONARY_ID)).thenReturn(dictionary);
    cut.start(DICTIONARY_ID);
    verify(eventManager, times(1)).publishEvent(eq(DictionaryEvent.START), eq(dictionary));
    cut.start(DICTIONARY_ID);
    verifyNoMoreInteractions(eventManager);
}
Also used : DictionaryEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity) DictionaryProviderEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity) Date(java.util.Date) Test(org.junit.Test)

Example 4 with DictionaryProviderEntity

use of io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity in project gravitee-management-rest-api by gravitee-io.

the class DictionaryService method startDynamicDictionary.

private void startDynamicDictionary(DictionaryEntity dictionary) {
    if (!timers.containsKey(dictionary.getId())) {
        DictionaryProviderEntity providerConf = dictionary.getProvider();
        if (DICTIONARY_HTTP_PROVIDER.equals(providerConf.getType())) {
            try {
                HttpProviderConfiguration configuration = objectMapper.treeToValue(providerConf.getConfiguration(), HttpProviderConfiguration.class);
                DictionaryRefresher refresher = new DictionaryRefresher(dictionary);
                HttpProvider provider = new HttpProvider(configuration);
                provider.setVertx(vertx);
                provider.setNode(node);
                refresher.setProvider(provider);
                refresher.setDictionaryService(dictionaryService);
                logger.info("Add a scheduled task to poll dictionary provider for dictionary [{}] each {} {} ", dictionary.getId(), dictionary.getTrigger().getRate(), dictionary.getTrigger().getUnit());
                // Force the first refresh, and then run it periodically
                refresher.handle(null);
                long periodicTimer = vertx.setPeriodic(getDelayMillis(dictionary.getTrigger()), refresher);
                timers.put(dictionary.getId(), periodicTimer);
            } catch (JsonProcessingException jpe) {
                logger.error("Dictionary provider configuration for dictionary [{}] is invalid", dictionary.getId(), jpe);
            }
        }
    }
}
Also used : HttpProvider(io.gravitee.rest.api.services.dictionary.provider.http.HttpProvider) DictionaryProviderEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity) HttpProviderConfiguration(io.gravitee.rest.api.services.dictionary.provider.http.configuration.HttpProviderConfiguration) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

DictionaryProviderEntity (io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity)4 DictionaryEntity (io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity)3 Date (java.util.Date)3 Test (org.junit.Test)3 DictionaryTriggerEntity (io.gravitee.rest.api.model.configuration.dictionary.DictionaryTriggerEntity)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HttpProvider (io.gravitee.rest.api.services.dictionary.provider.http.HttpProvider)1 HttpProviderConfiguration (io.gravitee.rest.api.services.dictionary.provider.http.configuration.HttpProviderConfiguration)1