Search in sources :

Example 1 with DynamicPropertyService

use of io.gravitee.definition.model.services.dynamicproperty.DynamicPropertyService in project gravitee-management-rest-api by gravitee-io.

the class DynamicPropertiesService method startDynamicProperties.

private void startDynamicProperties(ApiEntity api) {
    if (api.getState() == Lifecycle.State.STARTED) {
        DynamicPropertyService dynamicPropertyService = api.getServices().get(DynamicPropertyService.class);
        if (dynamicPropertyService != null && dynamicPropertyService.isEnabled()) {
            DynamicPropertyUpdater updater = new DynamicPropertyUpdater(api);
            if (dynamicPropertyService.getProvider() == DynamicPropertyProvider.HTTP) {
                HttpProvider provider = new HttpProvider(dynamicPropertyService);
                provider.setVertx(vertx);
                updater.setProvider(provider);
                updater.setApiService(apiService);
                logger.info("Add a scheduled task to poll dynamic properties each {} {} ", dynamicPropertyService.getTrigger().getRate(), dynamicPropertyService.getTrigger().getUnit());
                // Force the first refresh, and then run it periodically
                updater.handle(null);
                long periodicTimer = vertx.setPeriodic(getDelayMillis(dynamicPropertyService.getTrigger()), updater);
                timers.put(api, periodicTimer);
            }
        } else {
            logger.info("Dynamic properties service is disabled for: {} [{}]", api.getName(), api.getVersion());
        }
    }
}
Also used : DynamicPropertyService(io.gravitee.definition.model.services.dynamicproperty.DynamicPropertyService) HttpProvider(io.gravitee.management.services.dynamicproperties.provider.http.HttpProvider)

Example 2 with DynamicPropertyService

use of io.gravitee.definition.model.services.dynamicproperty.DynamicPropertyService in project gravitee-management-rest-api by gravitee-io.

the class DynamicPropertiesService method startDynamicProperties.

private void startDynamicProperties(ApiEntity api) {
    if (api.getState() == Lifecycle.State.STARTED) {
        DynamicPropertyService dynamicPropertyService = api.getServices().get(DynamicPropertyService.class);
        if (dynamicPropertyService != null && dynamicPropertyService.isEnabled()) {
            DynamicPropertyUpdater updater = new DynamicPropertyUpdater(api);
            if (dynamicPropertyService.getProvider() == DynamicPropertyProvider.HTTP) {
                HttpProvider provider = new HttpProvider(dynamicPropertyService);
                provider.setVertx(vertx);
                provider.setNode(node);
                updater.setProvider(provider);
                updater.setApiService(apiService);
                logger.info("Add a scheduled task to poll dynamic properties each {}", dynamicPropertyService.getSchedule());
                // Force the first refresh, and then run it periodically
                updater.handle(null);
                CronHandler cronHandler = new CronHandler(vertx, dynamicPropertyService.getSchedule());
                cronHandler.schedule(updater);
                handlers.put(api, cronHandler);
            }
        } else {
            logger.info("Dynamic properties service is disabled for: {} [{}]", api.getName(), api.getVersion());
        }
    }
}
Also used : DynamicPropertyService(io.gravitee.definition.model.services.dynamicproperty.DynamicPropertyService) HttpProvider(io.gravitee.rest.api.services.dynamicproperties.provider.http.HttpProvider)

Example 3 with DynamicPropertyService

use of io.gravitee.definition.model.services.dynamicproperty.DynamicPropertyService in project gravitee-management-rest-api by gravitee-io.

the class ApiService_hasHealthCheckEnabledTest method shouldNotBeEnabledWithAnotherService.

@Test
public void shouldNotBeEnabledWithAnotherService() {
    ApiEntity api = mock(ApiEntity.class);
    DynamicPropertyService dpSrv = mock(DynamicPropertyService.class);
    when(dpSrv.isEnabled()).thenReturn(Boolean.TRUE);
    Services services = new Services();
    services.set(Collections.singletonList(dpSrv));
    when(api.getServices()).thenReturn(services);
    mockProxy(api, false);
    boolean valid = apiService.hasHealthCheckEnabled(api, true);
    assertFalse(valid);
}
Also used : Services(io.gravitee.definition.model.services.Services) DynamicPropertyService(io.gravitee.definition.model.services.dynamicproperty.DynamicPropertyService) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Aggregations

DynamicPropertyService (io.gravitee.definition.model.services.dynamicproperty.DynamicPropertyService)3 Services (io.gravitee.definition.model.services.Services)1 HttpProvider (io.gravitee.management.services.dynamicproperties.provider.http.HttpProvider)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 HttpProvider (io.gravitee.rest.api.services.dynamicproperties.provider.http.HttpProvider)1 Test (org.junit.Test)1