ololo3000 commented on a change in pull request #8249: URL: https://github.com/apache/ignite/pull/8249#discussion_r490272545
########## File path: modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/systemview/SystemViewCommand.java ########## @@ -0,0 +1,223 @@ +/* + * 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: Done. ########## File path: modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/systemview/SystemViewCommand.java ########## @@ -0,0 +1,223 @@ +/* + * 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<? extends List<?>> sysViewRows = taskRes.systemViewContent(); Review comment: Done. ########## File path: modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/systemview/SystemViewCommand.java ########## @@ -0,0 +1,223 @@ +/* + * 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<? extends 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); + + colLenIter.set(Math.max(colLenIter.next(), colVal.length())); + + return colVal; + }).collect(Collectors.toList())); + }); + + printRow(colTitles, nCopies(colTitles.size(), STRING), colLenghts, log); + + rows.forEach(row -> printRow(row, taskRes.systemViewAttributeTypes(), colLenghts, log)); + } + + /** + * Prints row content with respect to column types and lengths. + * + * @param row Row which content should be printed. + * @param types Column types in sequential order for decent row formatting. + * @param lengths Column lengths in sequential order for decent row formatting. + * @param log Logger. + */ + private void printRow( + Collection<String> row, + Collection<SimpleAttributeType> types, + Collection<Integer> lengths, + Logger log + ) { + Iterator<SimpleAttributeType> typeIter = types.iterator(); + Review comment: Done. ########## File path: modules/core/src/main/java/org/apache/ignite/internal/visor/systemview/VisorSystemViewTask.java ########## @@ -0,0 +1,190 @@ +/* + * 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.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Objects; Review comment: Done. ########## File path: modules/core/src/main/java/org/apache/ignite/internal/visor/systemview/VisorSystemViewTask.java ########## @@ -0,0 +1,190 @@ +/* + * 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.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import org.apache.ignite.IgniteException; +import org.apache.ignite.internal.managers.systemview.GridSystemViewManager; +import org.apache.ignite.internal.processors.task.GridInternal; +import org.apache.ignite.internal.processors.task.GridVisorManagementTask; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.internal.visor.VisorJob; +import org.apache.ignite.internal.visor.VisorOneNodeTask; +import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.spi.systemview.view.SystemView; +import org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker; +import org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker.AttributeWithValueVisitor; +import org.jetbrains.annotations.Nullable; + +import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.toSqlName; +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; + +/** + * Reperesents visor task for obtaining system view content. + */ +@GridInternal +@GridVisorManagementTask +public class VisorSystemViewTask extends VisorOneNodeTask<VisorSystemViewTaskArg, VisorSystemViewTaskResult> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override protected VisorJob<VisorSystemViewTaskArg, VisorSystemViewTaskResult> job(VisorSystemViewTaskArg arg) { + return new VisorSystemViewJob(arg, false); + } + + /** + * + */ + private static class VisorSystemViewJob extends VisorJob<VisorSystemViewTaskArg, VisorSystemViewTaskResult> { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Create job with specified argument. + * + * @param arg Job argument. + * @param debug Flag indicating whether debug information should be printed into node log. + */ + protected VisorSystemViewJob(@Nullable VisorSystemViewTaskArg arg, boolean debug) { + super(arg, debug); + } + + /** {@inheritDoc} */ + @Override protected VisorSystemViewTaskResult run(@Nullable VisorSystemViewTaskArg arg) throws IgniteException { + GridSystemViewManager sysViewMgr = ignite.context().systemView(); + + String targetSysViewName = arg.systemViewName(); + + SystemView<?> targetSysView = sysViewMgr.view(targetSysViewName); + + if (targetSysView == null) { // In this case we assume that the requested system view name is in SQL format. + for (SystemView<?> sysView : sysViewMgr) { + if (toSqlName(sysView.name()).equals(targetSysViewName)) { + targetSysView = sysView; + + break; + } + } + } + + if (targetSysView == null) + return null; Review comment: Done. ########## File path: modules/core/src/main/java/org/apache/ignite/internal/visor/systemview/VisorSystemViewTask.java ########## @@ -0,0 +1,190 @@ +/* + * 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.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import org.apache.ignite.IgniteException; +import org.apache.ignite.internal.managers.systemview.GridSystemViewManager; +import org.apache.ignite.internal.processors.task.GridInternal; +import org.apache.ignite.internal.processors.task.GridVisorManagementTask; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.internal.visor.VisorJob; +import org.apache.ignite.internal.visor.VisorOneNodeTask; +import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.spi.systemview.view.SystemView; +import org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker; +import org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker.AttributeWithValueVisitor; +import org.jetbrains.annotations.Nullable; + +import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.toSqlName; +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; + +/** + * Reperesents visor task for obtaining system view content. + */ +@GridInternal +@GridVisorManagementTask +public class VisorSystemViewTask extends VisorOneNodeTask<VisorSystemViewTaskArg, VisorSystemViewTaskResult> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override protected VisorJob<VisorSystemViewTaskArg, VisorSystemViewTaskResult> job(VisorSystemViewTaskArg arg) { + return new VisorSystemViewJob(arg, false); + } + + /** + * + */ + private static class VisorSystemViewJob extends VisorJob<VisorSystemViewTaskArg, VisorSystemViewTaskResult> { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Create job with specified argument. + * + * @param arg Job argument. + * @param debug Flag indicating whether debug information should be printed into node log. + */ + protected VisorSystemViewJob(@Nullable VisorSystemViewTaskArg arg, boolean debug) { + super(arg, debug); + } + + /** {@inheritDoc} */ + @Override protected VisorSystemViewTaskResult run(@Nullable VisorSystemViewTaskArg arg) throws IgniteException { + GridSystemViewManager sysViewMgr = ignite.context().systemView(); + + String targetSysViewName = arg.systemViewName(); + + SystemView<?> targetSysView = sysViewMgr.view(targetSysViewName); + + if (targetSysView == null) { // In this case we assume that the requested system view name is in SQL format. + for (SystemView<?> sysView : sysViewMgr) { + if (toSqlName(sysView.name()).equals(targetSysViewName)) { + targetSysView = sysView; + + break; + } + } + } + + if (targetSysView == null) + return null; + + List<String> attrNames = new ArrayList<>(); + Review comment: Done. ########## 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<? extends List<?>> rows; Review comment: Done. ---------------------------------------------------------------- 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]
