xtern commented on a change in pull request #8249: URL: https://github.com/apache/ignite/pull/8249#discussion_r490243355
########## 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: I advise you to separate the logic for finding a view into a separate method. In this case, code here will look something like ``` SystemView<?> targetSysView = findSysView(arg.systemViewName()); if (targetSysView == null) return null; ``` `findSysView` may look something like ``` private SystemView<?> findSysView(String name) { GridSystemViewManager sysViewMgr = ignite.context().systemView(); SystemView<?> targetSysView = sysViewMgr.view(name); if (targetSysView != null) return targetSysView; // In this case we assume that the requested system view name is in SQL format. for (SystemView<?> sysView : sysViewMgr) { if (toSqlName(sysView.name()).equals(name)) return sysView; } return null; } ``` ---------------------------------------------------------------- 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]
