nizhikov commented on a change in pull request #8249: URL: https://github.com/apache/ignite/pull/8249#discussion_r492589817
########## File path: modules/core/src/main/java/org/apache/ignite/internal/visor/systemview/VisorSystemViewTaskResult.java ########## @@ -0,0 +1,114 @@ +/* + * 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.visor.systemview; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.ArrayList; +import java.util.List; +import org.apache.ignite.internal.dto.IgniteDataTransferObject; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleAttributeType; + +/** + * Reperesents result of {@link VisorSystemViewTask}. + */ +public class VisorSystemViewTaskResult extends IgniteDataTransferObject { + /** */ + private static final long serialVersionUID = 0L; + + /** Attribute values for each row of the system view. */ + private List<List<?>> rows; + + /** Names of the system view attributes. */ + private List<String> attrs; + + /** Types of the systen view attributes. */ + List<SimpleAttributeType> types; + + /** + * Default constructor. + */ + public VisorSystemViewTaskResult() { + // No-op. + } + + /** + * @param attrs Names of system view attributes. + * @param rows Attribute values for each row of the system view. Review comment: nit: @param types missed in javadoc. ########## File path: modules/core/src/main/java/org/apache/ignite/internal/visor/systemview/VisorSystemViewTaskResult.java ########## @@ -0,0 +1,114 @@ +/* + * 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.visor.systemview; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.ArrayList; +import java.util.List; +import org.apache.ignite.internal.dto.IgniteDataTransferObject; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleAttributeType; + +/** + * Reperesents result of {@link VisorSystemViewTask}. + */ +public class VisorSystemViewTaskResult extends IgniteDataTransferObject { + /** */ + private static final long serialVersionUID = 0L; + + /** Attribute values for each row of the system view. */ + private List<List<?>> rows; + + /** Names of the system view attributes. */ + private List<String> attrs; + + /** Types of the systen view attributes. */ + List<SimpleAttributeType> types; + + /** + * Default constructor. + */ + public VisorSystemViewTaskResult() { + // No-op. + } + + /** + * @param attrs Names of system view attributes. + * @param rows Attribute values for each row of the system view. + */ + public VisorSystemViewTaskResult(List<String> attrs, List<SimpleAttributeType> types, List<List<?>> rows) { + this.attrs = attrs; + this.types = types; + this.rows = rows; + } + + /** + * @return Names of the system view attributes. Review comment: Let's make this and similar comment one liner. ########## File path: modules/core/src/main/java/org/apache/ignite/internal/visor/systemview/VisorSystemViewTaskResult.java ########## @@ -0,0 +1,114 @@ +/* + * 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.visor.systemview; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.ArrayList; +import java.util.List; +import org.apache.ignite.internal.dto.IgniteDataTransferObject; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleAttributeType; + +/** + * Reperesents result of {@link VisorSystemViewTask}. + */ +public class VisorSystemViewTaskResult extends IgniteDataTransferObject { + /** */ + private static final long serialVersionUID = 0L; + + /** Attribute values for each row of the system view. */ + private List<List<?>> rows; + + /** Names of the system view attributes. */ + private List<String> attrs; + + /** Types of the systen view attributes. */ + List<SimpleAttributeType> types; + + /** + * Default constructor. + */ + public VisorSystemViewTaskResult() { + // No-op. + } + + /** + * @param attrs Names of system view attributes. + * @param rows Attribute values for each row of the system view. + */ + public VisorSystemViewTaskResult(List<String> attrs, List<SimpleAttributeType> types, List<List<?>> rows) { + this.attrs = attrs; + this.types = types; + this.rows = rows; + } + + /** + * @return Names of the system view attributes. + */ + public List<String> systemViewAttributes() { + return attrs; + } + + /** + * @return Attribute values for each row of the system view. + */ + public List<List<?>> systemViewContent() { + return rows; + } + + /** + * @return Types of the system view attributes. + */ + public List<SimpleAttributeType> systemViewAttributeTypes() { + return types; + } + + /** + * {@inheritDoc} Review comment: Please, make it one line comment. ########## File path: modules/core/src/main/java/org/apache/ignite/internal/visor/systemview/VisorSystemViewTaskResult.java ########## @@ -0,0 +1,114 @@ +/* + * 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.visor.systemview; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.ArrayList; +import java.util.List; +import org.apache.ignite.internal.dto.IgniteDataTransferObject; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleAttributeType; + +/** + * Reperesents result of {@link VisorSystemViewTask}. + */ +public class VisorSystemViewTaskResult extends IgniteDataTransferObject { + /** */ + private static final long serialVersionUID = 0L; + + /** Attribute values for each row of the system view. */ + private List<List<?>> rows; + + /** Names of the system view attributes. */ + private List<String> attrs; + + /** Types of the systen view attributes. */ + List<SimpleAttributeType> types; + + /** + * Default constructor. + */ + public VisorSystemViewTaskResult() { + // No-op. + } + + /** + * @param attrs Names of system view attributes. + * @param rows Attribute values for each row of the system view. + */ + public VisorSystemViewTaskResult(List<String> attrs, List<SimpleAttributeType> types, List<List<?>> rows) { + this.attrs = attrs; + this.types = types; + this.rows = rows; + } + + /** + * @return Names of the system view attributes. + */ + public List<String> systemViewAttributes() { Review comment: Let's make method naming consistent with the variables names. attrs -> attributes rows -> rows types -> types ########## 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` ########## 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(); + List<List<?>> sysViewRows = taskRes.systemViewContent(); Review comment: Let's rename this to `rows` ########## 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(); + List<List<?>> sysViewRows = taskRes.systemViewContent(); + + List<Integer> colLenghts = colTitles.stream().map(String::length).collect(Collectors.toList()); Review comment: Let's rename this to `colSzs` ########## 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(); + List<List<?>> sysViewRows = taskRes.systemViewContent(); + + List<Integer> colLenghts = colTitles.stream().map(String::length).collect(Collectors.toList()); + + List<List<String>> rows = new ArrayList<>(sysViewRows.size()); + + sysViewRows.forEach(sysViewRow -> { + ListIterator<Integer> colLenIter = colLenghts.listIterator(); + + rows.add(sysViewRow.stream().map(attr -> { + String colVal = String.valueOf(attr); Review comment: Let's rename this to `val` ########## 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(); + List<List<?>> sysViewRows = taskRes.systemViewContent(); Review comment: Let's rename this to `viewRows` ---------------------------------------------------------------- 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: [email protected]
