use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException in project UVMS-ExchangeModule-APP by UnionVMS.
the class PluginServiceBean method checkPluginType.
private boolean checkPluginType(PluginType pluginType, String responseTopicMessageSelector, String messageId) throws ExchangeModelMarshallException, ExchangeMessageException {
LOG.debug("checkPluginType " + pluginType.name());
if (PluginType.EMAIL == pluginType || PluginType.NAF == pluginType) {
// Check if type already exists
List<PluginType> type = new ArrayList<>();
type.add(pluginType);
try {
List<ServiceResponseType> services = exchangeService.getServiceList(type);
if (!services.isEmpty()) {
for (ServiceResponseType service : services) {
if (service.isActive()) {
// TODO log to audit log
String response = ExchangePluginResponseMapper.mapToRegisterServiceResponseNOK(messageId, "Plugin of " + pluginType + " already registered. Only one is allowed.");
producer.sendEventBusMessage(response, responseTopicMessageSelector);
return false;
}
}
}
} catch (ExchangeServiceException e) {
String response = ExchangePluginResponseMapper.mapToRegisterServiceResponseNOK(messageId, "Exchange service exception when registering plugin [ " + e.getMessage() + " ]");
producer.sendEventBusMessage(response, responseTopicMessageSelector);
return false;
}
}
return true;
}
use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException in project UVMS-ExchangeModule-APP by UnionVMS.
the class PluginServiceBean method unregisterService.
@Override
public void unregisterService(@Observes @UnRegisterServiceEvent PluginMessageEvent event) {
LOG.info("unregister service:{}", event);
TextMessage textMessage = event.getJmsMessage();
ServiceResponseType service = null;
try {
UnregisterServiceRequest unregister = JAXBMarshaller.unmarshallTextMessage(textMessage, UnregisterServiceRequest.class);
service = exchangeService.unregisterService(unregister.getService(), unregister.getService().getName());
String serviceClassName = service.getServiceClassName();
// NO ack back to plugin
// TODO log to exchange log
} catch (ExchangeModelMarshallException | ExchangeServiceException e) {
LOG.error("Unregister service exception " + e.getMessage());
errorEvent.fire(new PluginMessageEvent(textMessage, service, ExchangePluginResponseMapper.mapToPluginFaultResponse(FaultCode.EXCHANGE_PLUGIN_EVENT.getCode(), "Exception when unregister service")));
}
}
use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException in project UVMS-ExchangeModule-APP by UnionVMS.
the class PluginServiceBean method ping.
@Override
public boolean ping(String serviceClassName) throws ExchangeServiceException {
if (serviceClassName == null) {
throw new InputArgumentException("No service to ping");
}
try {
String text = ExchangePluginRequestMapper.createPingRequest();
producer.sendEventBusMessage(text, serviceClassName);
return true;
} catch (ExchangeModelMarshallException e) {
throw new ExchangeServiceException("[ Couldn't map ping request for " + serviceClassName + " ]");
} catch (ExchangeMessageException e) {
throw new ExchangeServiceException("[ Couldn't send ping request for " + serviceClassName + " ]");
}
}
use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException 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());
}
}
use of eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException 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;
}
}
Aggregations