Search in sources :

Example 6 with SettingType

use of eu.europa.ec.fisheries.schema.config.types.v1.SettingType in project UVMS-ExchangeModule-APP by UnionVMS.

the class PluginServiceBean method registerService.

private void registerService(RegisterServiceRequest register, String messageId) throws ExchangeModelMarshallException, ExchangeMessageException {
    try {
        overrideSettingsFromConfig(register);
        ServiceResponseType service = exchangeService.registerService(register.getService(), register.getCapabilityList(), register.getSettingList(), register.getService().getName());
        // push to config module
        try {
            String serviceClassName = register.getService().getServiceClassName();
            SettingListType settings = register.getSettingList();
            for (SettingType setting : settings.getSetting()) {
                String description = "Plugin " + serviceClassName + " " + setting.getKey() + " setting";
                configService.pushSettingToConfig(SettingTypeMapper.map(setting.getKey(), setting.getValue(), description), false);
            }
        } catch (ConfigServiceException e) {
            LOG.error("Couldn't register plugin settings in config parameter table");
        }
        // TODO log to exchange log
        String response = ExchangePluginResponseMapper.mapToRegisterServiceResponseOK(messageId, service);
        producer.sendEventBusMessage(response, register.getService().getServiceResponseMessageName());
        setServiceStatusOnRegister(register.getService().getServiceClassName());
    } catch (ExchangeServiceException | ExchangeModelMapperException e) {
        String response = ExchangePluginResponseMapper.mapToRegisterServiceResponseNOK(messageId, "Exchange service exception when registering plugin [ " + e.getMessage() + " ]");
        producer.sendEventBusMessage(response, register.getService().getServiceResponseMessageName());
    }
}
Also used : ExchangeModelMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMapperException) ServiceResponseType(eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType) ConfigServiceException(eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException) SettingType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType) SettingListType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Example 7 with SettingType

use of eu.europa.ec.fisheries.schema.config.types.v1.SettingType in project UVMS-ExchangeModule-APP by UnionVMS.

the class PluginServiceBean method setConfig.

@Override
public void setConfig(@Observes @ConfigSettingUpdatedEvent ConfigSettingEvent settingEvent) {
    switch(settingEvent.getType()) {
        case STORE:
            // ConfigModule and/or Exchange module deployed
            break;
        case UPDATE:
            LOG.info("ConfigModule updated parameter table with settings of plugins");
            try {
                String key = settingEvent.getKey();
                String value = parameterService.getStringValue(key);
                String settingKey;
                String[] splittedKey = key.split(PARAMETER_DELIMETER);
                if (splittedKey.length > 2) {
                    settingKey = key;
                    String serviceClassName = "";
                    for (int i = 0; i < splittedKey.length - 2; i++) {
                        serviceClassName += splittedKey[i] + ".";
                    }
                    serviceClassName += splittedKey[splittedKey.length - 2];
                    SettingType settingType = new SettingType();
                    settingType.setKey(key);
                    settingType.setValue(value);
                    updatePluginSetting(serviceClassName, settingType, "UVMS");
                } else {
                    LOG.error("No key or malformed key sent in settingEvent: key: {}, value: {}", key, value);
                }
            } catch (ConfigServiceException e) {
                LOG.error("Couldn't get updated parameter table value");
            } catch (ExchangeServiceException e) {
                LOG.error("Couldn't upsert settings in exchange");
            } catch (ExchangeModelMarshallException e) {
                LOG.error("Couldn't create plugin set config request");
            } catch (ExchangeMessageException e) {
                LOG.error("Couldn't send message to plugin");
            }
            break;
        case DELETE:
            LOG.info("ConfigModule removed parameter setting");
            break;
    }
}
Also used : ExchangeModelMarshallException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException) ConfigServiceException(eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) SettingType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Example 8 with SettingType

use of eu.europa.ec.fisheries.schema.config.types.v1.SettingType in project UVMS-ExchangeModule-APP by UnionVMS.

the class PluginServiceBean method overrideSettingsFromConfig.

private void overrideSettingsFromConfig(RegisterServiceRequest registerServiceRequest) {
    List<SettingType> currentRequestSettings = registerServiceRequest.getSettingList().getSetting();
    try {
        List<eu.europa.ec.fisheries.schema.config.types.v1.SettingType> configServiceSettings = configService.getSettings(registerServiceRequest.getService().getServiceClassName());
        Map<String, SettingType> configServiceSettingsMap = putConfigSettingsInAMap(configServiceSettings);
        if (!configServiceSettingsMap.isEmpty()) {
            for (SettingType type : currentRequestSettings) {
                SettingType configSettingType = configServiceSettingsMap.get(type.getKey());
                if (configSettingType != null && !configSettingType.getValue().equalsIgnoreCase(type.getValue())) {
                    type.setValue(configSettingType.getValue());
                }
            }
        }
    } catch (ConfigServiceException e) {
        LOG.error("Register service exception, cannot read Exchange settings from Config {} {}", registerServiceRequest, e.getMessage());
    // Ignore when we can't get the settings from Config. It is possible there is no Config module setup.
    }
}
Also used : ConfigServiceException(eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException) SettingType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType)

Example 9 with SettingType

use of eu.europa.ec.fisheries.schema.config.types.v1.SettingType in project UVMS-ExchangeModule-APP by UnionVMS.

the class MockData method getSettingList.

public static SettingListType getSettingList() {
    SettingListType dto = new SettingListType();
    SettingType setting = new SettingType();
    setting.setKey(SETTING_KEY);
    setting.setValue("setting.value");
    dto.getSetting().add(setting);
    return dto;
}
Also used : SettingType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType) SettingListType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType)

Example 10 with SettingType

use of eu.europa.ec.fisheries.schema.config.types.v1.SettingType in project UVMS-ExchangeModule-APP by UnionVMS.

the class MapperTest method testUpsert.

@Test
public void testUpsert() {
    String newValue = "NEW_VALUE";
    Service entity = MockData.getEntity(1);
    entity.setServiceCapabilityList(MockData.getEntityCapabilities(entity));
    entity.setServiceSettingList(MockData.getEntitySettings(entity));
    SettingListType updateSettings = new SettingListType();
    SettingType updateSetting = new SettingType();
    updateSetting.setKey(MockData.SETTING_KEY);
    updateSetting.setValue(newValue);
    updateSettings.getSetting().add(updateSetting);
    List<ServiceSetting> list = mapper.mapSettingsList(entity, updateSettings, "TEST");
    assertFalse(list.isEmpty());
    for (ServiceSetting setting : list) {
        assertSame(setting.getValue(), newValue);
    }
    SettingListType newSettings = new SettingListType();
    SettingType newSetting = new SettingType();
    newSetting.setKey("NEW.KEY");
    newSetting.setValue("NEW.VALUE");
    newSettings.getSetting().add(newSetting);
    list = mapper.mapSettingsList(entity, newSettings, "TEST");
    assertTrue(list.size() == 1);
}
Also used : Service(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service) SettingType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType) SettingListType(eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType) ServiceSetting(eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting) Test(org.junit.Test)

Aggregations

SettingType (eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType)9 SettingType (eu.europa.ec.fisheries.schema.config.types.v1.SettingType)5 Test (org.junit.Test)5 AbstractRestServiceTest (eu.europa.ec.fisheries.uvms.docker.validation.common.AbstractRestServiceTest)4 HttpResponse (org.apache.http.HttpResponse)4 SettingListType (eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType)3 ConfigServiceException (eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException)3 ServiceSetting (eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.ServiceSetting)2 ExchangeServiceException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)2 HashMap (java.util.HashMap)2 SettingsCreateQuery (eu.europa.ec.fisheries.schema.config.types.v1.SettingsCreateQuery)1 ServiceResponseType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType)1 Service (eu.europa.ec.fisheries.uvms.exchange.entity.serviceregistry.Service)1 ExchangeMessageException (eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException)1 ExchangeModelMapperException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMapperException)1 ExchangeModelMarshallException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException)1 ArrayList (java.util.ArrayList)1