12
12
* or implied. See the License for the specific language governing permissions and limitations under
13
13
* the License.
14
14
*/
15
+
15
16
package org .apache .geode .management .internal .cli .commands ;
16
17
17
18
import java .util .ArrayList ;
18
19
import java .util .Arrays ;
19
- import java .util .HashMap ;
20
20
import java .util .List ;
21
21
import java .util .Map ;
22
- import java .util .Map .Entry ;
23
22
import java .util .Set ;
24
23
25
24
import javax .management .ObjectName ;
38
37
import org .apache .geode .management .internal .cli .CliUtil ;
39
38
import org .apache .geode .management .internal .cli .LogWrapper ;
40
39
import org .apache .geode .management .internal .cli .functions .ContinuousQueryFunction ;
41
- import org .apache .geode .management .internal .cli .functions .ContinuousQueryFunction .ClientInfo ;
42
40
import org .apache .geode .management .internal .cli .i18n .CliStrings ;
43
41
import org .apache .geode .management .internal .cli .result .CompositeResultData ;
44
- import org .apache .geode .management .internal .cli .result .CompositeResultData .SectionResultData ;
45
42
import org .apache .geode .management .internal .cli .result .ResultBuilder ;
46
43
import org .apache .geode .management .internal .cli .result .TabularResultData ;
47
44
import org .apache .geode .management .internal .security .ResourceOperation ;
48
- import org .apache .geode .security .ResourcePermission .Operation ;
49
- import org .apache .geode .security .ResourcePermission .Resource ;
50
-
51
- /**
52
- * @since GemFire 8.0
53
- */
54
- public class ClientCommands implements GfshCommand {
55
-
56
- @ CliCommand (value = CliStrings .LIST_CLIENTS , help = CliStrings .LIST_CLIENT__HELP )
57
- @ CliMetaData (relatedTopic = {CliStrings .TOPIC_CLIENT })
58
- @ ResourceOperation (resource = Resource .CLUSTER , operation = Operation .READ )
59
- public Result listClient () {
60
- Result result ;
61
-
62
- try {
63
- CompositeResultData compositeResultData = ResultBuilder .createCompositeResultData ();
64
- SectionResultData section = compositeResultData .addSection ("section1" );
65
-
66
- TabularResultData resultTable = section .addTable ("TableForClientList" );
67
- String headerText = "ClientList" ;
68
- resultTable = resultTable .setHeader (headerText );
69
-
70
- InternalCache cache = getCache ();
71
- ManagementService service = ManagementService .getExistingManagementService (cache );
72
- ObjectName [] cacheServers = service .getDistributedSystemMXBean ().listCacheServerObjectNames ();
73
-
74
- if (cacheServers .length == 0 ) {
75
- return ResultBuilder .createGemFireErrorResult (
76
- CliStrings .format (CliStrings .LIST_CLIENT_COULD_NOT_RETRIEVE_SERVER_LIST ));
77
- }
78
-
79
- Map <String , List <String >> clientServerMap = new HashMap <>();
80
-
81
- for (ObjectName objName : cacheServers ) {
82
- CacheServerMXBean serverMbean = service .getMBeanInstance (objName , CacheServerMXBean .class );
83
- String [] listOfClient = serverMbean .getClientIds ();
84
-
85
- if (listOfClient == null || listOfClient .length == 0 ) {
86
- continue ;
87
- }
88
-
89
-
90
- for (String clientName : listOfClient ) {
91
- String serverDetails = "member=" + objName .getKeyProperty ("member" ) + ",port="
92
- + objName .getKeyProperty ("port" );
93
- if (clientServerMap .containsKey (clientName )) {
94
- List <String > listServers = clientServerMap .get (clientName );
95
- listServers .add (serverDetails );
96
- } else {
97
- List <String > listServer = new ArrayList <>();
98
- listServer .add (serverDetails );
99
- clientServerMap .put (clientName , listServer );
100
- }
101
- }
102
- }
103
-
104
- if (clientServerMap .size () == 0 ) {
105
- return ResultBuilder .createGemFireErrorResult (
106
- CliStrings .format (CliStrings .LIST_COULD_NOT_RETRIEVE_CLIENT_LIST ));
107
- }
108
-
109
- String memberSeparator = "; " ;
110
-
111
- for (Entry <String , List <String >> pairs : clientServerMap .entrySet ()) {
112
- String client = pairs .getKey ();
113
- List <String > servers = pairs .getValue ();
114
- StringBuilder serverListForClient = new StringBuilder ();
115
- int serversSize = servers .size ();
116
- int i = 0 ;
117
- for (String server : servers ) {
118
- serverListForClient .append (server );
119
- if (i < serversSize - 1 ) {
120
- serverListForClient .append (memberSeparator );
121
- }
122
- i ++;
123
- }
124
- resultTable .accumulate (CliStrings .LIST_CLIENT_COLUMN_Clients , client );
125
- resultTable .accumulate (CliStrings .LIST_CLIENT_COLUMN_SERVERS ,
126
- serverListForClient .toString ());
127
- }
128
- result = ResultBuilder .buildResult (compositeResultData );
129
-
130
- } catch (Exception e ) {
131
- LogWrapper .getInstance ()
132
- .warning ("Error in list clients. stack trace" + CliUtil .stackTraceAsString (e ));
133
- result = ResultBuilder .createGemFireErrorResult (CliStrings
134
- .format (CliStrings .LIST_CLIENT_COULD_NOT_RETRIEVE_CLIENT_LIST_0 , e .getMessage ()));
135
- }
136
-
137
- LogWrapper .getInstance ().info ("list client result " + result );
138
-
139
- return result ;
140
- }
45
+ import org .apache .geode .security .ResourcePermission ;
141
46
47
+ public class DescribeClientCommand implements GfshCommand {
142
48
@ CliCommand (value = CliStrings .DESCRIBE_CLIENT , help = CliStrings .DESCRIBE_CLIENT__HELP )
143
49
@ CliMetaData (relatedTopic = {CliStrings .TOPIC_CLIENT })
144
- @ ResourceOperation (resource = Resource .CLUSTER , operation = Operation .READ )
50
+ @ ResourceOperation (resource = ResourcePermission .Resource .CLUSTER ,
51
+ operation = ResourcePermission .Operation .READ )
145
52
public Result describeClient (@ CliOption (key = CliStrings .DESCRIBE_CLIENT__ID , mandatory = true ,
146
53
help = CliStrings .DESCRIBE_CLIENT__ID__HELP ) String clientId ) {
147
54
Result result ;
@@ -160,7 +67,8 @@ public Result describeClient(@CliOption(key = CliStrings.DESCRIBE_CLIENT__ID, ma
160
67
161
68
try {
162
69
CompositeResultData compositeResultData = ResultBuilder .createCompositeResultData ();
163
- SectionResultData sectionResult = compositeResultData .addSection ("InfoSection" );
70
+ CompositeResultData .SectionResultData sectionResult =
71
+ compositeResultData .addSection ("InfoSection" );
164
72
InternalCache cache = getCache ();
165
73
166
74
ManagementService service = ManagementService .getExistingManagementService (cache );
@@ -219,7 +127,8 @@ public Result describeClient(@CliOption(key = CliStrings.DESCRIBE_CLIENT__ID, ma
219
127
}
220
128
221
129
if (object != null ) {
222
- ClientInfo objectResult = (ClientInfo ) object ;
130
+ ContinuousQueryFunction .ClientInfo objectResult =
131
+ (ContinuousQueryFunction .ClientInfo ) object ;
223
132
isDurable = objectResult .isDurable ;
224
133
225
134
if (objectResult .primaryServer != null && objectResult .primaryServer .length () > 0 ) {
@@ -265,7 +174,7 @@ public Result describeClient(@CliOption(key = CliStrings.DESCRIBE_CLIENT__ID, ma
265
174
return result ;
266
175
}
267
176
268
- private void buildTableResult (SectionResultData sectionResult ,
177
+ private void buildTableResult (CompositeResultData . SectionResultData sectionResult ,
269
178
ClientHealthStatus clientHealthStatus , String isDurable , List <String > primaryServers ,
270
179
List <String > secondaryServers ) {
271
180
@@ -305,7 +214,7 @@ private void buildTableResult(SectionResultData sectionResult,
305
214
Map <String , String > poolStats = clientHealthStatus .getPoolStats ();
306
215
307
216
if (poolStats .size () > 0 ) {
308
- for (Entry <String , String > entry : poolStats .entrySet ()) {
217
+ for (Map . Entry <String , String > entry : poolStats .entrySet ()) {
309
218
TabularResultData poolStatsResultTable =
310
219
sectionResult .addTable ("Pool Stats For Pool Name = " + entry .getKey ());
311
220
poolStatsResultTable .setHeader ("Pool Stats For Pool Name = " + entry .getKey ());
0 commit comments