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);
}
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);
}
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);
}
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);
}
}
}
}
Aggregations