Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sonar cloud 2020 03 06 #2897

Merged
merged 15 commits into from
Aug 27, 2020
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ public Set<Actions> getActions() {
public boolean getGroupable() {
return false;
}

@Override
public boolean equals(Object o) {
return super.equals(o);
}

@Override
public int hashCode() {
return super.hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* <BR>
* <BR>
* <p>
*
*
* <pre>
* &lt;plugins&gt;
* &lt;bean xmlns="http://www.springframework.org/schema/beans" id="applicationFilter" class="org.eclipse.kapua.broker.core.KapuaApplicationBrokerFilter"/&gt;
Expand All @@ -41,9 +41,9 @@ public Broker installPlugin(Broker broker) throws Exception {
logger.info("Installing Kapua application broker plugin...");
try {
return new KapuaApplicationBrokerFilter(broker);
} catch (Throwable t) {
logger.error("Error in plugin installation.", t);
throw new SecurityException(t);
} catch (Exception e) {
logger.error("Error in plugin installation.", e);
throw new SecurityException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public class KapuaBrokerJAXBContextLoader {
BROKER_JAXB_CONTEXT_CLASS_NAME = config.getString(BrokerSettingKey.BROKER_JAXB_CONTEXT_CLASS_NAME);
}

public KapuaBrokerJAXBContextLoader() throws KapuaException {
}

public void init() throws KapuaException {
logger.info(">>> Broker jaxb context loader... load context");
JAXBContextProvider jaxbContextProvider = ClassUtil.newInstance(BROKER_JAXB_CONTEXT_CLASS_NAME, BrokerJAXBContextProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public Broker installPlugin(final Broker broker) throws Exception {

// install the filters
return new KapuaSecurityBrokerFilter(broker);
} catch (Throwable t) {
logger.error("Error in plugin installation.", t);
throw new SecurityException(t);
} catch (Exception e) {
logger.error("Error in plugin installation.", e);
throw new SecurityException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ public abstract class AbstractKapuaConverter {

public static final Logger logger = LoggerFactory.getLogger(AbstractKapuaConverter.class);

// metrics
protected static final String METRIC_MODULE_NAME = "converter";
protected static final String METRIC_COMPONENT_NAME = "kapua";
protected static final MetricsService METRICS_SERVICE = MetricServiceFactory.getInstance();

private final Counter metricConverterJmsMessage;
Expand All @@ -60,9 +57,30 @@ public abstract class AbstractKapuaConverter {
* Constructor
*/
protected AbstractKapuaConverter() {
metricConverterJmsMessage = METRICS_SERVICE.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "jms", "message", "count");
metricConverterJmsErrorMessage = METRICS_SERVICE.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "jms", "message", "error", "count");
metricConverterErrorMessage = METRICS_SERVICE.getCounter(METRIC_MODULE_NAME, METRIC_COMPONENT_NAME, "kapua_message", "message", "error", "count");
metricConverterJmsMessage = METRICS_SERVICE.getCounter(
ConverterMetrics.METRIC_MODULE_NAME,
ConverterMetrics.METRIC_COMPONENT_NAME,
ConverterMetrics.METRIC_JMS,
ConverterMetrics.METRIC_MESSAGE,
ConverterMetrics.METRIC_COUNT
);

metricConverterJmsErrorMessage = METRICS_SERVICE.getCounter(
ConverterMetrics.METRIC_MODULE_NAME,
ConverterMetrics.METRIC_COMPONENT_NAME,
ConverterMetrics.METRIC_JMS,
ConverterMetrics.METRIC_MESSAGE,
ConverterMetrics.METRIC_ERROR,
ConverterMetrics.METRIC_COUNT
);

metricConverterErrorMessage = METRICS_SERVICE.getCounter(
ConverterMetrics.METRIC_MODULE_NAME,
ConverterMetrics.METRIC_COMPONENT_NAME,
ConverterMetrics.METRIC_KAPUA_MESSAGE,
ConverterMetrics.METRIC_MESSAGE,
ConverterMetrics.METRIC_ERROR,
ConverterMetrics.METRIC_COUNT);
}

/**
Expand All @@ -82,9 +100,9 @@ protected CamelKapuaMessage<?> convertTo(Exchange exchange, Object value, Messag
try {
// FIX #164
Date queuedOn = new Date(message.getHeader(CamelConstants.JMS_HEADER_TIMESTAMP, Long.class));
KapuaId connectionId = (KapuaId) SerializationUtils.deserialize(Base64.getDecoder().decode(message.getHeader(MessageConstants.HEADER_KAPUA_CONNECTION_ID, String.class)));
KapuaId connectionId = SerializationUtils.deserialize(Base64.getDecoder().decode(message.getHeader(MessageConstants.HEADER_KAPUA_CONNECTION_ID, String.class)));
String clientId = message.getHeader(MessageConstants.HEADER_KAPUA_CLIENT_ID, String.class);
ConnectorDescriptor connectorDescriptor = (ConnectorDescriptor) SerializationUtils
ConnectorDescriptor connectorDescriptor = SerializationUtils
.deserialize(Base64.getDecoder().decode(message.getHeader(MessageConstants.HEADER_KAPUA_CONNECTOR_DEVICE_PROTOCOL, String.class)));
return JmsUtil.convertToCamelKapuaMessage(connectorDescriptor, messageType, messageContent, CamelUtil.getTopic(message), queuedOn, connectionId, clientId);
} catch (JMSException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.broker.core.converter;

public class ConverterMetrics {

private ConverterMetrics() { }

public static final String METRIC_MODULE_NAME = "converter";

public static final String METRIC_COMPONENT_NAME = "kapua";

public static final String METRIC_JMS = "jms";
public static final String METRIC_MESSAGE = "message";
public static final String METRIC_MESSAGES = "messages";
public static final String METRIC_ERROR = "error";
public static final String METRIC_COUNT = "count";
public static final String METRIC_KAPUA_MESSAGE = "kapua_message";
public static final String METRIC_DATA = "data";

public static final String METRIC_APP = "app";
public static final String METRIC_BIRTH = "birth";
public static final String METRIC_DC = "dc";
public static final String METRIC_MISSING = "missing";
public static final String METRIC_NOTIFY = "notify";

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class DeviceManagementNotificationConverter extends AbstractKapuaConverte

public DeviceManagementNotificationConverter() {
super();
metricConverterDeviceManagementNotificationMessage = METRICS_SERVICE.getCounter(METRIC_COMPONENT_NAME, "kapua", "kapua_message", "messages", "notify", "count");
metricConverterDeviceManagementNotificationMessage = METRICS_SERVICE.getCounter(ConverterMetrics.METRIC_MODULE_NAME, ConverterMetrics.METRIC_COMPONENT_NAME, ConverterMetrics.METRIC_KAPUA_MESSAGE, ConverterMetrics.METRIC_MESSAGES, ConverterMetrics.METRIC_NOTIFY, ConverterMetrics.METRIC_COUNT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public KapuaCamelFilter() {
*/
public void bindSession(Exchange exchange, Object value) throws KapuaException {
ThreadContext.unbindSubject();
if (!exchange.getIn().getHeader(MessageConstants.HEADER_KAPUA_BROKER_CONTEXT, boolean.class)) {
if (Boolean.FALSE.equals(exchange.getIn().getHeader(MessageConstants.HEADER_KAPUA_BROKER_CONTEXT, boolean.class))) {
try {
// FIX #164
KapuaSecurityUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/**
* Kapua message converter used to convert data messages.
*
*
* @since 1.0
*/
public class KapuaDataConverter extends AbstractKapuaConverter {
Expand All @@ -37,12 +37,12 @@ public class KapuaDataConverter extends AbstractKapuaConverter {

public KapuaDataConverter() {
super();
metricConverterDataMessage = METRICS_SERVICE.getCounter(METRIC_COMPONENT_NAME, "kapua", "kapua_message", "messages", "data", "count");
metricConverterDataMessage = METRICS_SERVICE.getCounter(ConverterMetrics.METRIC_MODULE_NAME, ConverterMetrics.METRIC_COMPONENT_NAME, ConverterMetrics.METRIC_KAPUA_MESSAGE, ConverterMetrics.METRIC_MESSAGES, ConverterMetrics.METRIC_DATA, ConverterMetrics.METRIC_COUNT);
}

/**
* Convert incoming message to a Kapua data message
*
*
* @param exchange
* @param value
* @return Message container that contains data message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.broker.core.message.CamelKapuaMessage;
import org.eclipse.kapua.broker.core.plugin.ConnectorDescriptor.MessageType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.codahale.metrics.Counter;

/**
* Kapua message converter used to convert life cycle messages.
*
*
* @since 1.0
*/
public class KapuaLifeCycleConverter extends AbstractKapuaConverter {
Expand All @@ -38,16 +39,16 @@ public class KapuaLifeCycleConverter extends AbstractKapuaConverter {

public KapuaLifeCycleConverter() {
super();
metricConverterAppMessage = METRICS_SERVICE.getCounter(METRIC_COMPONENT_NAME, "kapua", "kapua_message", "messages", "app", "count");
metricConverterBirthMessage = METRICS_SERVICE.getCounter(METRIC_COMPONENT_NAME, "kapua", "kapua_message", "messages", "birth", "count");
metricConverterDcMessage = METRICS_SERVICE.getCounter(METRIC_COMPONENT_NAME, "kapua", "kapua_message", "messages", "dc", "count");
metricConverterMissingMessage = METRICS_SERVICE.getCounter(METRIC_COMPONENT_NAME, "kapua", "kapua_message", "messages", "missing", "count");
metricConverterNotifyMessage = METRICS_SERVICE.getCounter(METRIC_COMPONENT_NAME, "kapua", "kapua_message", "messages", "notify", "count");
metricConverterAppMessage = METRICS_SERVICE.getCounter(ConverterMetrics.METRIC_MODULE_NAME, ConverterMetrics.METRIC_COMPONENT_NAME, ConverterMetrics.METRIC_KAPUA_MESSAGE, ConverterMetrics.METRIC_MESSAGES, ConverterMetrics.METRIC_APP, ConverterMetrics.METRIC_COUNT);
metricConverterBirthMessage = METRICS_SERVICE.getCounter(ConverterMetrics.METRIC_MODULE_NAME, ConverterMetrics.METRIC_COMPONENT_NAME, ConverterMetrics.METRIC_KAPUA_MESSAGE, ConverterMetrics.METRIC_MESSAGES, ConverterMetrics.METRIC_BIRTH, ConverterMetrics.METRIC_COUNT);
metricConverterDcMessage = METRICS_SERVICE.getCounter(ConverterMetrics.METRIC_MODULE_NAME, ConverterMetrics.METRIC_COMPONENT_NAME, ConverterMetrics.METRIC_KAPUA_MESSAGE, ConverterMetrics.METRIC_MESSAGES, ConverterMetrics.METRIC_DC, ConverterMetrics.METRIC_COUNT);
metricConverterMissingMessage = METRICS_SERVICE.getCounter(ConverterMetrics.METRIC_MODULE_NAME, ConverterMetrics.METRIC_COMPONENT_NAME, ConverterMetrics.METRIC_KAPUA_MESSAGE, ConverterMetrics.METRIC_MESSAGES, ConverterMetrics.METRIC_MISSING, ConverterMetrics.METRIC_COUNT);
metricConverterNotifyMessage = METRICS_SERVICE.getCounter(ConverterMetrics.METRIC_MODULE_NAME, ConverterMetrics.METRIC_COMPONENT_NAME, ConverterMetrics.METRIC_KAPUA_MESSAGE, ConverterMetrics.METRIC_MESSAGES, ConverterMetrics.METRIC_NOTIFY, ConverterMetrics.METRIC_COUNT);
}

/**
* Convert incoming message to a Kapua application (life cycle) message
*
*
* @param exchange
* @param value
* @return Message container that contains application message
Expand All @@ -62,7 +63,7 @@ public CamelKapuaMessage<?> convertToApps(Exchange exchange, Object value) throw

/**
* Convert incoming message to a Kapua birth (life cycle) message
*
*
* @param exchange
* @param value
* @return Message container that contains birth message
Expand All @@ -77,7 +78,7 @@ public CamelKapuaMessage<?> convertToBirth(Exchange exchange, Object value) thro

/**
* Convert incoming message to a Kapua disconnect (life cycle) message
*
*
* @param exchange
* @param value
* @return Message container that contains disconnect message
Expand All @@ -92,7 +93,7 @@ public CamelKapuaMessage<?> convertToDisconnect(Exchange exchange, Object value)

/**
* Convert incoming message to a Kapua missing (life cycle) message
*
*
* @param exchange
* @param value
* @return Message container that contains missing message
Expand All @@ -107,7 +108,7 @@ public CamelKapuaMessage<?> convertToMissing(Exchange exchange, Object value) th

/**
* Convert incoming message to a Kapua notify (life cycle) message
*
*
* @param exchange
* @param value
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@

/**
* Camel Header constants
*
*
* @since 1.0
*/
public interface CamelConstants {
public class CamelConstants {

private CamelConstants() { }

public String JMS_EXCHANGE_FAILURE_ENDPOINT = "CamelFailureEndpoint";
public String JMS_EXCHANGE_FAILURE_EXCEPTION = "CamelExceptionCaught";
public String JMS_EXCHANGE_REDELIVERED = "JMSRedelivered";
public static final String JMS_EXCHANGE_FAILURE_ENDPOINT = "CamelFailureEndpoint";
public static final String JMS_EXCHANGE_FAILURE_EXCEPTION = "CamelExceptionCaught";
public static final String JMS_EXCHANGE_REDELIVERED = "JMSRedelivered";

public String JMS_HEADER_TIMESTAMP = "JMSTimestamp";
public String JMS_HEADER_DESTINATION = "JMSDestination";
public static final String JMS_HEADER_TIMESTAMP = "JMSTimestamp";
public static final String JMS_HEADER_DESTINATION = "JMSDestination";

public String JMS_CORRELATION_ID = "JMSCorrelationID";
public static final String JMS_CORRELATION_ID = "JMSCorrelationID";

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
public class DataStorageMessageProcessor extends AbstractProcessor<CamelKapuaMessage<?>> {

private static final Logger LOG = LoggerFactory.getLogger(DataStorageMessageProcessor.class);
private static final String METRIC_COMPONENT_NAME = "datastore";

private final MessageStoreService messageStoreService = KapuaLocator.getInstance().getService(MessageStoreService.class);

Expand All @@ -47,9 +46,9 @@ public DataStorageMessageProcessor() {
super("DataStorage");
MetricsService metricService = MetricServiceFactory.getInstance();

metricQueueCommunicationErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "queue", "communication", "error", "count");
metricQueueConfigurationErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "queue", "configuration", "error", "count");
metricQueueGenericErrorCount = metricService.getCounter(METRIC_COMPONENT_NAME, "datastore", "store", "queue", "generic", "error", "count");
metricQueueCommunicationErrorCount = metricService.getCounter(DataStoreMetrics.METRIC_MODULE_NAME, DataStoreMetrics.METRIC_COMPONENT_NAME, DataStoreMetrics.METRIC_STORE, DataStoreMetrics.METRIC_QUEUE, DataStoreMetrics.METRIC_COMMUNICATION, DataStoreMetrics.METRIC_ERROR, DataStoreMetrics.METRIC_COUNT);
metricQueueConfigurationErrorCount = metricService.getCounter(DataStoreMetrics.METRIC_MODULE_NAME, DataStoreMetrics.METRIC_COMPONENT_NAME, DataStoreMetrics.METRIC_STORE, DataStoreMetrics.METRIC_QUEUE, DataStoreMetrics.METRIC_CONFIGURATION, DataStoreMetrics.METRIC_ERROR, DataStoreMetrics.METRIC_COUNT);
metricQueueGenericErrorCount = metricService.getCounter(DataStoreMetrics.METRIC_MODULE_NAME, DataStoreMetrics.METRIC_COMPONENT_NAME, DataStoreMetrics.METRIC_STORE, DataStoreMetrics.METRIC_QUEUE, DataStoreMetrics.METRIC_GENERIC, DataStoreMetrics.METRIC_ERROR, DataStoreMetrics.METRIC_COUNT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.broker.core.listener;

public class DataStoreMetrics {

private DataStoreMetrics() { }

public static final String METRIC_MODULE_NAME = "datastore";

public static final String METRIC_COMPONENT_NAME = "datastore";

public static final String METRIC_STORE = "store";
public static final String METRIC_QUEUE = "queue";
public static final String METRIC_COMMUNICATION = "communication";
public static final String METRIC_CONFIGURATION = "configuration";
public static final String METRIC_GENERIC = "generic";

public static final String METRIC_ERROR = "error";
public static final String METRIC_COUNT = "count";

}
Loading