Skip to content

Commit 7737547

Browse files
committed
Fix JMXDataUpdater code formatting and structure
Fixed malformed code from previous commit: - Moved success-path logging to correct location - Moved failure-path logging to catch block properly - Removed corrupted text fragment - Applied spotless formatting
1 parent 6ca4bb4 commit 7737547

2 files changed

Lines changed: 28 additions & 17 deletions

File tree

geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/JMXDataUpdater.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ public JMXConnector connect(Object credentials) {
176176
long connectStartTime = System.currentTimeMillis();
177177
System.err.println("[JMX-CONNECT] Starting JMX connection at " + java.time.Instant.now());
178178
System.err.println("[JMX-CONNECT] Thread: " + Thread.currentThread().getName());
179-
System.err.println("[JMX-CONNECT] Credentials type: " + (credentials != null ? credentials.getClass().getName() : "null"));
179+
System.err.println("[JMX-CONNECT] Credentials type: "
180+
+ (credentials != null ? credentials.getClass().getName() : "null"));
180181
try {
181182

182183
String jmxSerURL = "";
@@ -224,33 +225,38 @@ public JMXConnector connect(Object credentials) {
224225
env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
225226
}
226227
logger.info("Connecting to jmxURL : {}", jmxSerURL);
227-
System.err.println("[JMX-CONNECT] Attempting JMXConnectorFactory.connect() to: " + jmxSerURL);
228+
System.err
229+
.println("[JMX-CONNECT] Attempting JMXConnectorFactory.connect() to: " + jmxSerURL);
228230
System.err.println("[JMX-CONNECT] With SSL: " + repository.isUseSSLManager());
229231
long jmxCallStart = System.currentTimeMillis();
230232
conn = JMXConnectorFactory.connect(url, env);
231233
long jmxCallEnd = System.currentTimeMillis();
232-
System.err.println("[JMX-CONNECT] JMXConnectorFactory.connect() successful in " + (jmxCallEnd - jmxCallStart) + "ms");
234+
System.err.println("[JMX-CONNECT] JMXConnectorFactory.connect() successful in "
235+
+ (jmxCallEnd - jmxCallStart) + "ms");
233236
mbs = conn.getMBeanServerConnection();
234237
cluster.setConnectedFlag(true);
238+
long totalDuration = System.currentTimeMillis() - connectStartTime;
239+
System.err.println("[JMX-CONNECT] Total connection time: " + totalDuration + "ms");
240+
} finally {
241+
System.setProperties(originalProperties);
242+
}
243+
}
244+
} catch (Exception e) {
235245
long totalDuration = System.currentTimeMillis() - connectStartTime;
236246
cluster.setConnectedFlag(false);
237247
cluster.setConnectionErrorMsg(e.getMessage());
238248
System.err.println("[JMX-CONNECT] Connection FAILED after " + totalDuration + "ms");
239249
System.err.println("[JMX-CONNECT] Exception type: " + e.getClass().getName());
240250
System.err.println("[JMX-CONNECT] Exception message: " + e.getMessage());
241251
if (e.getCause() != null) {
242-
System.err.println("[JMX-CONNECT] Caused by: " + e.getCause().getClass().getName() + ": " + e.getCause().getMessage());
252+
System.err.println("[JMX-CONNECT] Caused by: " + e.getCause().getClass().getName() + ": "
253+
+ e.getCause().getMessage());
243254
if (e.getCause().getCause() != null) {
244-
System.err.println("[JMX-CONNECT] Caused by: " + e.getCause().getCause().getClass().getName() + ": " + e.getCause().getCause().getMessage());
245-
}
246-
}nnection time: " + totalDuration + "ms");
247-
} finally {
248-
System.setProperties(originalProperties);
255+
System.err
256+
.println("[JMX-CONNECT] Caused by: " + e.getCause().getCause().getClass().getName()
257+
+ ": " + e.getCause().getCause().getMessage());
249258
}
250259
}
251-
} catch (Exception e) {
252-
cluster.setConnectedFlag(false);
253-
cluster.setConnectionErrorMsg(e.getMessage());
254260
logger.fatal(e.getMessage(), e);
255261
if (conn != null) {
256262
try {

geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/security/GemFireAuthenticationProvider.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,24 @@ public Authentication authenticate(Authentication authentication) throws Authent
6363
String password = authentication.getCredentials().toString();
6464

6565
logger.debug("Connecting to GemFire with user=" + name);
66-
System.err.println("[PULSE-AUTH] Authentication request for user: " + name + " at " + java.time.Instant.now());
66+
System.err.println(
67+
"[PULSE-AUTH] Authentication request for user: " + name + " at " + java.time.Instant.now());
6768
long authStartTime = System.currentTimeMillis();
6869
Cluster cluster = repository.getClusterWithUserNameAndPassword(name, password);
6970
long authEndTime = System.currentTimeMillis();
70-
System.err.println("[PULSE-AUTH] getClusterWithUserNameAndPassword returned in " + (authEndTime - authStartTime) + "ms");
71-
System.err.println("[PULSE-AUTH] Cluster connected flag: " + (cluster != null && cluster.isConnectedFlag()));
72-
System.err.println("[PULSE-AUTH] Cluster connection error: " + (cluster != null ? cluster.getConnectionErrorMsg() : "null"));
71+
System.err.println("[PULSE-AUTH] getClusterWithUserNameAndPassword returned in "
72+
+ (authEndTime - authStartTime) + "ms");
73+
System.err.println(
74+
"[PULSE-AUTH] Cluster connected flag: " + (cluster != null && cluster.isConnectedFlag()));
75+
System.err.println("[PULSE-AUTH] Cluster connection error: "
76+
+ (cluster != null ? cluster.getConnectionErrorMsg() : "null"));
7377
JMXConnector jmxc = cluster != null ? cluster.getJMXConnector() : null;
7478
if (jmxc == null) {
7579
System.err.println("[PULSE-AUTH] JMXConnector is NULL - authentication FAILED for " + name);
7680
throw new BadCredentialsException("Error connecting to GemFire JMX Server");
7781
}
78-
System.err.println("[PULSE-AUTH] JMXConnector obtained - authentication SUCCESSFUL for " + name);
82+
System.err
83+
.println("[PULSE-AUTH] JMXConnector obtained - authentication SUCCESSFUL for " + name);
7984

8085
Collection<GrantedAuthority> list = GemFireAuthentication.populateAuthorities(jmxc);
8186
GemFireAuthentication auth = new GemFireAuthentication(authentication.getPrincipal(),

0 commit comments

Comments
 (0)