Skip to content

Commit 7738585

Browse files
authored
Add get description for member and service (#72)
* Add get description for member and service * Minor code update
1 parent a52ff39 commit 7738585

File tree

6 files changed

+162
-9
lines changed

6 files changed

+162
-9
lines changed

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/HttpRequestSender.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,22 @@ public String getScheduledDistributions(String sService, String sDomainPartition
580580
return rootNode.get("scheduledDistributions").asText();
581581
}
582582

583+
@Override
584+
public String getServiceDescription(String sService, String sDomainPartition)
585+
throws Exception
586+
{
587+
URLBuilder urlBuilder = getBasePath().addPathSegment(SERVICES)
588+
.addPathSegment(encodeServiceName(sService)).addPathSegment("description")
589+
.addQueryParameter(LINKS, "");
590+
if (sDomainPartition != null)
591+
{
592+
urlBuilder.addQueryParameter("domainPartition", sDomainPartition);
593+
}
594+
595+
JsonNode rootNode = getResponseJson(sendGetRequest(urlBuilder));
596+
return rootNode.get("description").asText();
597+
}
598+
583599
@Override
584600
public Set<Object[]> getPartitionAssignmentAttributes(String sService, String sDomainPartition)
585601
throws Exception
@@ -679,6 +695,18 @@ public String reportEnvironment(Integer nNodeId)
679695
return rootNode.get("environment").asText();
680696
}
681697

698+
@Override
699+
public String getNodeDescription(Integer nNodeId)
700+
throws Exception
701+
{
702+
URLBuilder urlBuilder = getBasePath().addPathSegment(MEMBERS)
703+
.addPathSegment(nNodeId + "").addPathSegment("description")
704+
.addQueryParameter(LINKS, "");
705+
706+
JsonNode rootNode = getResponseJson(sendGetRequest(urlBuilder));
707+
return rootNode.get("description").asText();
708+
}
709+
682710
/**
683711
* Issue a dump cluster heap request.
684712
*

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/JMXRequestSender.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ public String getScheduledDistributions(String sService, String sDomainPartition
279279
new Object[]{true}, new String[]{boolean.class.getName()});
280280
}
281281

282+
@Override
283+
public String getServiceDescription(String sService, String sDomainPartition)
284+
throws Exception
285+
{
286+
Set<ObjectName> setResult = getServiceObjectName(sService, sDomainPartition, getLocalMemberId());
287+
288+
String sFQN = getFirstResult(setResult);
289+
290+
return (String) invoke(new ObjectName(sFQN), "getServiceDescription", new Object[0], new String[0]);
291+
}
292+
282293
@Override
283294
public Set<Object[]> getPartitionAssignmentAttributes(String sService, String sDomainPartition)
284295
throws Exception
@@ -370,6 +381,19 @@ public String reportEnvironment(Integer nNodeId)
370381
return (String) invoke(new ObjectName(sFQN), "reportEnvironment", new Object[0], new String[0]);
371382
}
372383

384+
@Override
385+
public String getNodeDescription(Integer nNodeId)
386+
throws Exception
387+
{
388+
// look up the full name of the MBean in case we are in container
389+
Set<ObjectName> setResult = getCompleteObjectName(
390+
new ObjectName("Coherence:type=Node,nodeId=" + nNodeId + ",*"));
391+
392+
String sFQN = getFirstResult(setResult);
393+
394+
return (String) invoke(new ObjectName(sFQN), "getNodeDescription", new Object[0], new String[0]);
395+
}
396+
373397
/**
374398
* Issue a dump cluster heap request.
375399
*
@@ -454,6 +478,15 @@ public Object executeSubscriberOperation(Pair<String, String> topic, long sSubsc
454478

455479
// ------ JMXRequestSender methods --------------------------------------
456480

481+
public Set<ObjectName> getServiceObjectName(String sService, String sDomainPartition, int nMemberId)
482+
throws Exception
483+
{
484+
String sQuery = "Coherence:type=Service,name="
485+
+ sService + (sDomainPartition != null ? DOMAIN_PARTITION + sDomainPartition : "")
486+
+ ",nodeId=" + nMemberId + ",*";
487+
return f_connection.queryNames(new ObjectName(sQuery), null);
488+
}
489+
457490
/**
458491
* Retrieve the Reporter MBean for the local member Id. We do a query to get the object
459492
* as it may have additional key values due to a container environment.

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/RequestSender.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,19 @@ Set<ObjectName> getPartitionAssignmentObjectName(String sService, String sDomain
322322
String getScheduledDistributions(String sService, String sDomainPartition)
323323
throws Exception;
324324

325+
/**
326+
* Get the description of a service.
327+
*
328+
* @param sService the name of the service
329+
* @param sDomainPartition the domain partition to which the service belongs
330+
*
331+
* @return the service description
332+
*
333+
* @throws Exception in case of errors
334+
*/
335+
String getServiceDescription(String sService, String sDomainPartition)
336+
throws Exception;
337+
325338
/**
326339
* Get the attributes of the SimpleAssignmentStrategyMBean.
327340
*
@@ -404,6 +417,18 @@ String getNodeState(Integer nNodeId)
404417
String reportEnvironment(Integer nNodeId)
405418
throws Exception;
406419

420+
/**
421+
* Get the description of a Cluster member.
422+
*
423+
* @param nNodeId the ID of the cluster member
424+
*
425+
* @return the description of a cluster member
426+
*
427+
* @throws Exception in case of errors
428+
*/
429+
String getNodeDescription(Integer nNodeId)
430+
throws Exception;
431+
407432
/**
408433
* Issue a dump cluster heap request.
409434
*

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceMemberPanel.java

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023 Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -184,7 +184,8 @@ public CoherenceMemberPanel(VisualVMModel model)
184184
menuDetail,
185185
new ReportEnvironmentMenuOption(model, m_requestSender, f_table),
186186
new ReportNodeStateMenuOption(model, m_requestSender, f_table),
187-
new ReportNodeStateMultiMenuOption(model, m_requestSender, f_table)});
187+
new ReportNodeStateMultiMenuOption(model, m_requestSender, f_table),
188+
new GetDescriptionMenuOption(model, m_requestSender, f_table)});
188189
}
189190
else
190191
{
@@ -320,13 +321,67 @@ public ReportEnvironmentMenuOption(VisualVMModel model, RequestSender requestSen
320321
super(model, requestSender, jtable);
321322
}
322323

323-
// ----- MenuOptions methods ----------------------------------------
324+
// ----- MenuOptions methods ----------------------------------------
325+
326+
@Override
327+
public void actionPerformed(ActionEvent e)
328+
{
329+
int nRow = getSelectedRow();
330+
Integer nNodeId = null;
331+
332+
if (nRow == -1)
333+
{
334+
DialogHelper.showInfoDialog(getLocalizedText("LBL_must_select_row"));
335+
}
336+
else
337+
{
338+
try
339+
{
340+
nNodeId = (Integer) getJTable().getModel().getValueAt(nRow, 0);
341+
String sResult = generateHeader(nNodeId) + m_requestSender.reportEnvironment(nNodeId);
342+
showMessageDialog(getLocalizedText("LBL_environment_for_node") + " " + nNodeId,
343+
sResult, JOptionPane.INFORMATION_MESSAGE, 500, 400, true);
344+
}
345+
catch (Exception ee)
346+
{
347+
showMessageDialog("Error running reportEnvironment for Node " + nNodeId, getSanitizedMessage(ee), JOptionPane.ERROR_MESSAGE);
348+
}
349+
}
350+
}
324351

325352
@Override
326353
public String getMenuItem()
327354
{
328355
return getLocalizedText("LBL_report_node_environment");
329356
}
357+
}
358+
359+
// ----- inner classes GetDescriptionMenuOption ----------------------
360+
361+
/**
362+
* A class to call the description operation on the selected ClusterNode
363+
* MBean and display the details.
364+
*/
365+
private class GetDescriptionMenuOption
366+
extends AbstractMenuOption
367+
{
368+
369+
/**
370+
* {@inheritDoc}
371+
*/
372+
public GetDescriptionMenuOption(VisualVMModel model, RequestSender requestSender,
373+
ExportableJTable jtable)
374+
{
375+
super(model, requestSender, jtable);
376+
}
377+
378+
// ----- MenuOptions methods ----------------------------------------
379+
380+
@Override
381+
public String getMenuItem()
382+
{
383+
return getLocalizedText("LBL_get_description");
384+
}
330385

331386
@Override
332387
public void actionPerformed(ActionEvent e)
@@ -343,7 +398,7 @@ public void actionPerformed(ActionEvent e)
343398
try
344399
{
345400
nNodeId = (Integer) getJTable().getModel().getValueAt(nRow, 0);
346-
String sResult = generateHeader(nNodeId) + m_requestSender.reportEnvironment(nNodeId);
401+
String sResult = generateHeader(nNodeId) + m_requestSender.getNodeDescription(nNodeId);
347402

348403
showMessageDialog(getLocalizedText("LBL_environment_for_node") + " " + nNodeId,
349404
sResult, JOptionPane.INFORMATION_MESSAGE, 500, 400, true);

coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceServicePanel.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public CoherenceServicePanel(VisualVMModel model)
9898
// only available in 12.2.1 and above
9999
table.setMenuOptions(new MenuOption[]{
100100
new RightClickMenuOption(model, m_requestSender, table, REPORT_DISTRIBUTIONS),
101-
new RightClickMenuOption(model, m_requestSender, table, SHOW_PARTITION_STATS)});
101+
new RightClickMenuOption(model, m_requestSender, table, SHOW_PARTITION_STATS),
102+
new RightClickMenuOption(model, m_requestSender, table, SHOW_SERVICE_DESCRIPTION)});
102103
}
103104
else if (model.getClusterVersionAsInt() >= 121200)
104105
{
@@ -426,8 +427,8 @@ public RightClickMenuOption(VisualVMModel model, RequestSender requestSender,
426427
public String getMenuItem()
427428
{
428429
return getLocalizedText(f_nOption == REPORT_DISTRIBUTIONS
429-
? "LBL_report_sched_dist"
430-
: "LBL_partition_stats");
430+
? "LBL_report_sched_dist" : f_nOption == SHOW_PARTITION_STATS
431+
? "LBL_partition_stats" : "LBL_show_service_description");
431432
}
432433

433434
/**
@@ -459,6 +460,10 @@ public void actionPerformed(ActionEvent e)
459460
{
460461
sResult = m_requestSender.getScheduledDistributions(sService, sDomainPartition);
461462
}
463+
else if (f_nOption == SHOW_SERVICE_DESCRIPTION)
464+
{
465+
sResult = m_requestSender.getServiceDescription(sService, sDomainPartition);
466+
}
462467
else if (f_nOption == SHOW_PARTITION_STATS)
463468
{
464469
Set<Object[]> setResults = m_requestSender.getPartitionAssignmentAttributes(sService, sDomainPartition);
@@ -513,7 +518,7 @@ else if (f_nOption == SHOW_PARTITION_STATS)
513518
*/
514519
private String getSanitizedMessage(Exception e)
515520
{
516-
String sError = e.getMessage();
521+
String sError = e != null ? e.getMessage() : "unknown";
517522
return sError.contains("name cannot be null") ? "Node no longer available or operation not valid for service type." : sError;
518523
}
519524

@@ -644,6 +649,11 @@ public void updateRowSelection()
644649
*/
645650
private final int SHOW_PARTITION_STATS = 1;
646651

652+
/**
653+
* Right click option for showing service description.
654+
*/
655+
private final int SHOW_SERVICE_DESCRIPTION = 2;
656+
647657
// ----- data members ---------------------------------------------------
648658

649659
/**

coherence-visualvm-plugin/src/main/resources/com/oracle/coherence/plugin/visualvm/Bundle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ LBL_total_cluster_memory_avail=Total Storage Heap Avail (MB)
136136
LBL_overview=Overview
137137
LBL_report_node_state=Generate Thread Dump
138138
LBL_report_node_environment=Report Environment
139+
LBL_get_description=Get Description
139140
LBL_report_node_state_multi=Generate Multiple Thread Dumps
140141
LBL_state_for_node=Thread Dump(s) for Node
141142
LBL_environment_for_node=Environment for Node
@@ -226,7 +227,8 @@ LBL_request_average_duration=Request Average Duration (ms)
226227
LBL_service_partitions=Partitions
227228
LBL_task_backlog=Task Backlog
228229
LBL_details_service=Details for Service {0}
229-
LBL_report_sched_dist=Report scheduled distributions
230+
LBL_report_sched_dist=Report Scheduled Distributions
231+
LBL_show_service_description=Show Description
230232
LBL_partition_stats=Show Partition Statistics
231233
LBL_avg_partition_size=Average partition storage size in kilobytes:
232234
LBL_max_partition_size=Max partition storage size in kilobytes:

0 commit comments

Comments
 (0)