nizhikov commented on a change in pull request #8249: URL: https://github.com/apache/ignite/pull/8249#discussion_r492600689
########## File path: modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/systemview/SystemViewCommand.java ########## @@ -0,0 +1,221 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.commandline.systemview; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.UUID; +import java.util.logging.Logger; +import java.util.stream.Collectors; +import org.apache.ignite.internal.client.GridClient; +import org.apache.ignite.internal.client.GridClientConfiguration; +import org.apache.ignite.internal.commandline.Command; +import org.apache.ignite.internal.commandline.CommandArgIterator; +import org.apache.ignite.internal.commandline.CommandLogger; +import org.apache.ignite.internal.commandline.argument.CommandArgUtils; +import org.apache.ignite.internal.visor.systemview.VisorSystemViewTask; +import org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleAttributeType; +import org.apache.ignite.internal.visor.systemview.VisorSystemViewTaskArg; +import org.apache.ignite.internal.visor.systemview.VisorSystemViewTaskResult; +import org.apache.ignite.spi.systemview.view.SystemView; + +import static java.util.Collections.nCopies; +import static org.apache.ignite.internal.commandline.CommandList.SYSTEM_VIEW; +import static org.apache.ignite.internal.commandline.CommandLogger.optional; +import static org.apache.ignite.internal.commandline.TaskExecutor.executeTaskByNameOnNode; +import static org.apache.ignite.internal.commandline.systemview.SystemViewCommandArg.NODE_ID; +import static org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleAttributeType.DATE; +import static org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleAttributeType.NUMBER; +import static org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleAttributeType.STRING; + +/** + * Represents command for {@link SystemView} content printing. + */ +public class SystemViewCommand implements Command<Object> { + /** Column separator. */ + public static final String COLUMN_SEPARATOR = " "; + + /** + * Argument for the system view content obtainig task. + * + * @see VisorSystemViewTask + */ + private VisorSystemViewTaskArg taskArg; + + /** ID of the node to get the system view content from. */ + private UUID nodeId; + + /** {@inheritDoc} */ + @Override public Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception { + try { + VisorSystemViewTaskResult res; + + try (GridClient client = Command.startClient(clientCfg)) { + res = executeTaskByNameOnNode( + client, + VisorSystemViewTask.class.getName(), + taskArg, + nodeId, + clientCfg + ); + } + + if (res != null) + printSystemViewContent(res, log); + else + log.info("No system view with specified name was found [name=" + taskArg.systemViewName() + "]"); + + return res; + } + catch (Throwable e) { + log.severe("Failed to perform operation."); + log.severe(CommandLogger.errorMessage(e)); + + throw e; + } + } + + /** + * Prints system view content obtained via {@link VisorSystemViewTask} execution. + * + * @param taskRes Result of {@link VisorSystemViewTask} execution. + * @param log Logger. + */ + private void printSystemViewContent(VisorSystemViewTaskResult taskRes, Logger log) { + List<String> colTitles = taskRes.systemViewAttributes(); Review comment: Let's rename this to `titles` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org