Skip to content

Commit ed92537

Browse files
committed
continue cleanup
1 parent ad62a1f commit ed92537

File tree

8 files changed

+81
-157
lines changed

8 files changed

+81
-157
lines changed

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/WMQContext.java renamed to ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/WmqContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
* authorization.<br>
1717
* It also validates the arguments passed for various scenarios.
1818
*/
19-
public class WMQContext {
19+
public class WmqContext {
2020
private static final String TRANSPORT_TYPE_CLIENT = "Client";
2121
private static final String TRANSPORT_TYPE_BINDINGS = "Bindings";
2222

23-
public static final Logger logger = LoggerFactory.getLogger(WMQContext.class);
23+
public static final Logger logger = LoggerFactory.getLogger(WmqContext.class);
2424
private final QueueManager queueManager;
2525

26-
public WMQContext(QueueManager queueManager) {
26+
public WmqContext(QueueManager queueManager) {
2727
this.queueManager = queueManager;
2828
validateArgs();
2929
}

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/WMQMonitor.java renamed to ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/WmqMonitor.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import io.opentelemetry.api.metrics.Meter;
1515
import io.opentelemetry.ibm.mq.config.QueueManager;
1616
import io.opentelemetry.ibm.mq.metrics.MetricsConfig;
17-
import io.opentelemetry.ibm.mq.metricscollector.*;
1817
import io.opentelemetry.ibm.mq.metricscollector.ChannelMetricsCollector;
1918
import io.opentelemetry.ibm.mq.metricscollector.InquireChannelCmdCollector;
2019
import io.opentelemetry.ibm.mq.metricscollector.InquireQueueManagerCmdCollector;
@@ -27,28 +26,29 @@
2726
import io.opentelemetry.ibm.mq.metricscollector.ReadConfigurationEventQueueCollector;
2827
import io.opentelemetry.ibm.mq.metricscollector.TopicMetricsCollector;
2928
import io.opentelemetry.ibm.mq.opentelemetry.ConfigWrapper;
30-
import io.opentelemetry.ibm.mq.util.WMQUtil;
29+
import io.opentelemetry.ibm.mq.util.WmqUtil;
3130
import java.util.ArrayList;
3231
import java.util.List;
3332
import java.util.Map;
3433
import java.util.concurrent.Callable;
3534
import java.util.concurrent.ExecutorService;
3635
import java.util.function.Consumer;
3736
import org.jetbrains.annotations.NotNull;
37+
import org.jetbrains.annotations.Nullable;
3838
import org.slf4j.Logger;
3939
import org.slf4j.LoggerFactory;
4040

41-
public class WMQMonitor {
41+
public class WmqMonitor {
4242

43-
private static final Logger logger = LoggerFactory.getLogger(WMQMonitor.class);
43+
private static final Logger logger = LoggerFactory.getLogger(WmqMonitor.class);
4444

4545
private final List<QueueManager> queueManagers;
4646
private final List<Consumer<MetricsCollectorContext>> jobs = new ArrayList<>();
4747
private final LongGauge heartbeatGauge;
4848
private final ExecutorService threadPool;
4949
private final MetricsConfig metricsConfig;
5050

51-
public WMQMonitor(ConfigWrapper config, ExecutorService threadPool, Meter meter) {
51+
public WmqMonitor(ConfigWrapper config, ExecutorService threadPool, Meter meter) {
5252
List<Map<String, ?>> queueManagers = getQueueManagers(config);
5353
ObjectMapper mapper = new ObjectMapper();
5454

@@ -86,16 +86,6 @@ public void run() {
8686
}
8787
}
8888

89-
@NotNull
90-
private static List<Map<String, ?>> getQueueManagers(ConfigWrapper config) {
91-
List<Map<String, ?>> queueManagers = config.getQueueManagers();
92-
if (queueManagers.isEmpty()) {
93-
throw new IllegalStateException(
94-
"The 'queueManagers' section in config.yml is empty or otherwise incorrect.");
95-
}
96-
return queueManagers;
97-
}
98-
9989
public void run(QueueManager queueManager) {
10090
String queueManagerName = queueManager.getName();
10191
logger.debug("WMQMonitor thread for queueManager {} started.", queueManagerName);
@@ -104,11 +94,11 @@ public void run(QueueManager queueManager) {
10494
PCFMessageAgent agent = null;
10595
int heartBeatMetricValue = 0;
10696
try {
107-
ibmQueueManager = WMQUtil.connectToQueueManager(queueManager);
97+
ibmQueueManager = WmqUtil.connectToQueueManager(queueManager);
10898
heartBeatMetricValue = 1;
109-
agent = WMQUtil.initPCFMessageAgent(queueManager, ibmQueueManager);
99+
agent = WmqUtil.initPCFMessageAgent(queueManager, ibmQueueManager);
110100
extractAndReportMetrics(ibmQueueManager, queueManager, agent);
111-
} catch (Exception e) {
101+
} catch (RuntimeException e) {
112102
logger.error(
113103
"Error connecting to QueueManager {} by thread {}: {}",
114104
queueManagerName,
@@ -130,6 +120,16 @@ public void run(QueueManager queueManager) {
130120
}
131121
}
132122

123+
@NotNull
124+
private static List<Map<String, ?>> getQueueManagers(ConfigWrapper config) {
125+
List<Map<String, ?>> queueManagers = config.getQueueManagers();
126+
if (queueManagers.isEmpty()) {
127+
throw new IllegalStateException(
128+
"The 'queueManagers' section in config.yml is empty or otherwise incorrect.");
129+
}
130+
return queueManagers;
131+
}
132+
133133
private void extractAndReportMetrics(
134134
MQQueueManager mqQueueManager, QueueManager queueManager, PCFMessageAgent agent) {
135135
logger.debug("Queueing {} jobs", jobs.size());
@@ -154,9 +154,9 @@ private void extractAndReportMetrics(
154154
collector.getClass().getSimpleName(),
155155
diffTime);
156156
}
157-
} catch (Exception e) {
157+
} catch (RuntimeException e) {
158158
logger.error(
159-
"Error while running task name = " + collector.getClass().getSimpleName(), e);
159+
"Error while running task name = {}", collector.getClass().getSimpleName(), e);
160160
}
161161
return null;
162162
});
@@ -170,7 +170,8 @@ private void extractAndReportMetrics(
170170
}
171171

172172
/** Destroy the agent and disconnect from queue manager */
173-
private static void cleanUp(MQQueueManager ibmQueueManager, PCFMessageAgent agent) {
173+
private static void cleanUp(
174+
@Nullable MQQueueManager ibmQueueManager, @Nullable PCFMessageAgent agent) {
174175
// Disconnect the agent.
175176

176177
if (agent != null) {

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/config/ExcludeFilters.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
import io.opentelemetry.ibm.mq.metricscollector.FilterType;
99
import java.util.Collection;
10+
import java.util.Collections;
1011
import java.util.HashSet;
1112
import java.util.Set;
1213

14+
/**
15+
* A jackson databind class used for config.
16+
*/
1317
public class ExcludeFilters {
1418

15-
private String type;
19+
private String type = "UNKNOWN";
1620
private Set<String> values = new HashSet<>();
1721

1822
public String getType() {
@@ -24,11 +28,11 @@ public void setType(String type) {
2428
}
2529

2630
public Set<String> getValues() {
27-
return values;
31+
return Collections.unmodifiableSet(values);
2832
}
2933

3034
public void setValues(Set<String> values) {
31-
this.values = values;
35+
this.values = new HashSet<>(values);
3236
}
3337

3438
public static boolean isExcluded(String resourceName, Collection<ExcludeFilters> excludeFilters) {

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/config/QueueManager.java

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
package io.opentelemetry.ibm.mq.config;
77

88
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
9-
import java.util.List;
9+
import org.jetbrains.annotations.Nullable;
1010

11+
/** This is a jackson databind class used purely for config. */
1112
@JsonIgnoreProperties(ignoreUnknown = true)
1213
public class QueueManager {
1314

14-
private String host;
15+
@Nullable private String host;
1516
private int port = -1;
16-
private String name;
17-
private String channelName;
18-
private String transportType;
19-
private String username;
20-
private String password;
21-
private String sslKeyRepository;
17+
private String name = "UNKNOWN";
18+
@Nullable private String channelName;
19+
@Nullable private String transportType;
20+
@Nullable private String username;
21+
@Nullable private String password;
22+
@Nullable private String sslKeyRepository;
2223
private int ccsid = Integer.MIN_VALUE;
2324
private int encoding = Integer.MIN_VALUE;
24-
private String cipherSuite;
25-
private String cipherSpec;
26-
private String replyQueuePrefix;
27-
private String modelQueueName;
25+
@Nullable private String cipherSuite;
26+
@Nullable private String cipherSpec;
27+
@Nullable private String replyQueuePrefix;
28+
@Nullable private String modelQueueName;
2829
private String configurationQueueName = "SYSTEM.ADMIN.CONFIG.EVENT";
2930
private String performanceEventsQueueName = "SYSTEM.ADMIN.PERFM.EVENT";
3031
private String queueManagerEventsQueueName = "SYSTEM.ADMIN.QMGR.EVENT";
@@ -34,14 +35,12 @@ public class QueueManager {
3435
// https://www.ibm.com/docs/en/ibm-mq/9.3.x?topic=qmini-channels-stanza-file
3536
private int maxActiveChannels = 100;
3637

37-
private ResourceFilters queueFilters;
38-
private ResourceFilters channelFilters;
39-
private ResourceFilters listenerFilters;
40-
private ResourceFilters topicFilters;
38+
@Nullable private ResourceFilters queueFilters;
39+
@Nullable private ResourceFilters channelFilters;
40+
@Nullable private ResourceFilters listenerFilters;
41+
@Nullable private ResourceFilters topicFilters;
4142

42-
List<String> writeStatsDirectory;
43-
44-
public String getHost() {
43+
public @Nullable String getHost() {
4544
return host;
4645
}
4746

@@ -65,35 +64,35 @@ public void setName(String name) {
6564
this.name = name;
6665
}
6766

68-
public String getChannelName() {
67+
public @Nullable String getChannelName() {
6968
return channelName;
7069
}
7170

72-
public void setChannelName(String channelName) {
71+
public void setChannelName(@Nullable String channelName) {
7372
this.channelName = channelName;
7473
}
7574

76-
public String getTransportType() {
75+
public @Nullable String getTransportType() {
7776
return transportType;
7877
}
7978

80-
public void setTransportType(String transportType) {
79+
public void setTransportType(@Nullable String transportType) {
8180
this.transportType = transportType;
8281
}
8382

84-
public String getUsername() {
83+
public @Nullable String getUsername() {
8584
return username;
8685
}
8786

88-
public void setUsername(String username) {
87+
public void setUsername(@Nullable String username) {
8988
this.username = username;
9089
}
9190

92-
public String getPassword() {
91+
public @Nullable String getPassword() {
9392
return password;
9493
}
9594

96-
public void setPassword(String password) {
95+
public void setPassword(@Nullable String password) {
9796
this.password = password;
9897
}
9998

@@ -104,31 +103,31 @@ public ResourceFilters getQueueFilters() {
104103
return queueFilters;
105104
}
106105

107-
public void setQueueFilters(ResourceFilters queueFilters) {
106+
public void setQueueFilters(@Nullable ResourceFilters queueFilters) {
108107
this.queueFilters = queueFilters;
109108
}
110109

111-
public String getSslKeyRepository() {
110+
public @Nullable String getSslKeyRepository() {
112111
return sslKeyRepository;
113112
}
114113

115-
public void setSslKeyRepository(String sslKeyRepository) {
114+
public void setSslKeyRepository(@Nullable String sslKeyRepository) {
116115
this.sslKeyRepository = sslKeyRepository;
117116
}
118117

119-
public String getCipherSuite() {
118+
public @Nullable String getCipherSuite() {
120119
return cipherSuite;
121120
}
122121

123122
public void setCipherSuite(String cipherSuite) {
124123
this.cipherSuite = cipherSuite;
125124
}
126125

127-
public String getCipherSpec() {
126+
public @Nullable String getCipherSpec() {
128127
return cipherSpec;
129128
}
130129

131-
public void setCipherSpec(String cipherSpec) {
130+
public void setCipherSpec(@Nullable String cipherSpec) {
132131
this.cipherSpec = cipherSpec;
133132
}
134133

@@ -139,23 +138,23 @@ public ResourceFilters getChannelFilters() {
139138
return channelFilters;
140139
}
141140

142-
public void setChannelFilters(ResourceFilters channelFilters) {
141+
public void setChannelFilters(@Nullable ResourceFilters channelFilters) {
143142
this.channelFilters = channelFilters;
144143
}
145144

146-
public String getReplyQueuePrefix() {
145+
public @Nullable String getReplyQueuePrefix() {
147146
return replyQueuePrefix;
148147
}
149148

150-
public void setReplyQueuePrefix(String replyQueuePrefix) {
149+
public void setReplyQueuePrefix(@Nullable String replyQueuePrefix) {
151150
this.replyQueuePrefix = replyQueuePrefix;
152151
}
153152

154-
public String getModelQueueName() {
153+
public @Nullable String getModelQueueName() {
155154
return modelQueueName;
156155
}
157156

158-
public void setModelQueueName(String modelQueueName) {
157+
public void setModelQueueName(@Nullable String modelQueueName) {
159158
this.modelQueueName = modelQueueName;
160159
}
161160

@@ -166,7 +165,7 @@ public ResourceFilters getListenerFilters() {
166165
return listenerFilters;
167166
}
168167

169-
public void setListenerFilters(ResourceFilters listenerFilters) {
168+
public void setListenerFilters(@Nullable ResourceFilters listenerFilters) {
170169
this.listenerFilters = listenerFilters;
171170
}
172171

@@ -193,7 +192,7 @@ public ResourceFilters getTopicFilters() {
193192
return topicFilters;
194193
}
195194

196-
public void setTopicFilters(ResourceFilters topicFilters) {
195+
public void setTopicFilters(@Nullable ResourceFilters topicFilters) {
197196
this.topicFilters = topicFilters;
198197
}
199198

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/metricscollector/MetricsCollectorContext.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
import io.opentelemetry.ibm.mq.config.QueueManager;
1616
import io.opentelemetry.ibm.mq.metrics.MetricsConfig;
1717
import java.io.IOException;
18-
import java.util.*;
18+
import java.util.Arrays;
19+
import java.util.List;
20+
import java.util.Set;
1921
import javax.annotation.concurrent.Immutable;
2022
import org.jetbrains.annotations.NotNull;
21-
import org.slf4j.Logger;
22-
import org.slf4j.LoggerFactory;
2323

2424
/**
2525
* A temporary bundle to contain the collaborators of the original MetricsCollector base class until
@@ -29,8 +29,6 @@
2929
@Immutable
3030
public final class MetricsCollectorContext {
3131

32-
private static final Logger logger = LoggerFactory.getLogger(MetricsCollectorContext.class);
33-
3432
private final QueueManager queueManager;
3533
private final PCFMessageAgent agent;
3634
private final MQQueueManager mqQueueManager;

ibm-mq-metrics/src/main/java/io/opentelemetry/ibm/mq/opentelemetry/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import io.opentelemetry.api.OpenTelemetry;
99
import io.opentelemetry.api.metrics.MeterProvider;
10-
import io.opentelemetry.ibm.mq.WMQMonitor;
10+
import io.opentelemetry.ibm.mq.WmqMonitor;
1111
import io.opentelemetry.sdk.OpenTelemetrySdk;
1212
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
1313
import io.opentelemetry.sdk.resources.Resource;
@@ -76,7 +76,7 @@ public static void run(
7676
MeterProvider meterProvider = otel.getMeterProvider();
7777

7878
Runtime.getRuntime().addShutdownHook(new Thread(service::shutdown));
79-
WMQMonitor monitor = new WMQMonitor(config, service, meterProvider.get("websphere/mq"));
79+
WmqMonitor monitor = new WmqMonitor(config, service, meterProvider.get("websphere/mq"));
8080
service.scheduleAtFixedRate(
8181
monitor::run,
8282
config.getTaskInitialDelaySeconds(),

0 commit comments

Comments
 (0)