Search in sources :

Example 1 with ConfigServiceException

use of eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException 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 2 with ConfigServiceException

use of eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException 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 3 with ConfigServiceException

use of eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException 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)

Aggregations

SettingType (eu.europa.ec.fisheries.schema.exchange.service.v1.SettingType)3 ConfigServiceException (eu.europa.ec.fisheries.uvms.config.exception.ConfigServiceException)3 ExchangeServiceException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)2 ServiceResponseType (eu.europa.ec.fisheries.schema.exchange.service.v1.ServiceResponseType)1 SettingListType (eu.europa.ec.fisheries.schema.exchange.service.v1.SettingListType)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