diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/FlowClient.java b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/FlowClient.java index bc56eceeea..17492c99cc 100644 --- a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/FlowClient.java +++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/FlowClient.java @@ -17,6 +17,7 @@ package org.apache.nifi.toolkit.cli.impl.client.nifi; import org.apache.nifi.web.api.entity.ActivateControllerServicesEntity; +import org.apache.nifi.web.api.entity.ClusteSummaryEntity; import org.apache.nifi.web.api.entity.ControllerServicesEntity; import org.apache.nifi.web.api.entity.CurrentUserEntity; import org.apache.nifi.web.api.entity.ProcessGroupFlowEntity; @@ -97,4 +98,10 @@ public interface FlowClient { */ ActivateControllerServicesEntity activateControllerServices(ActivateControllerServicesEntity activateControllerServicesEntity) throws NiFiClientException, IOException; + /** + * + * @return cluster summary response + */ + ClusteSummaryEntity getClusterSummary() throws NiFiClientException, IOException; + } diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyFlowClient.java b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyFlowClient.java index 4489998c00..bfc2660086 100644 --- a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyFlowClient.java +++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyFlowClient.java @@ -24,6 +24,7 @@ import org.apache.nifi.web.api.dto.PositionDTO; import org.apache.nifi.web.api.dto.flow.FlowDTO; import org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO; import org.apache.nifi.web.api.entity.ActivateControllerServicesEntity; +import org.apache.nifi.web.api.entity.ClusteSummaryEntity; import org.apache.nifi.web.api.entity.ComponentEntity; import org.apache.nifi.web.api.entity.ControllerServicesEntity; import org.apache.nifi.web.api.entity.CurrentUserEntity; @@ -217,4 +218,12 @@ public class JerseyFlowClient extends AbstractJerseyClient implements FlowClient ActivateControllerServicesEntity.class); }); } + + @Override + public ClusteSummaryEntity getClusterSummary() throws NiFiClientException, IOException { + return executeAction("Error retrieving cluster summary", () -> { + final WebTarget target = flowTarget.path("cluster/summary"); + return getRequestBuilder(target).get(ClusteSummaryEntity.class); + }); + } } diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java index ac5ec62e1d..00a38a222c 100644 --- a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java +++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java @@ -18,6 +18,7 @@ package org.apache.nifi.toolkit.cli.impl.command.nifi; import org.apache.nifi.toolkit.cli.api.Command; import org.apache.nifi.toolkit.cli.impl.command.AbstractCommandGroup; +import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.ClusterSummary; import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.CurrentUser; import org.apache.nifi.toolkit.cli.impl.command.nifi.flow.GetRootId; import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGChangeVersion; @@ -56,6 +57,7 @@ public class NiFiCommandGroup extends AbstractCommandGroup { protected List createCommands() { final List commands = new ArrayList<>(); commands.add(new CurrentUser()); + commands.add(new ClusterSummary()); commands.add(new GetRootId()); commands.add(new ListRegistryClients()); commands.add(new CreateRegistryClient()); diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/flow/ClusterSummary.java b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/flow/ClusterSummary.java new file mode 100644 index 0000000000..dfe3898eb2 --- /dev/null +++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/flow/ClusterSummary.java @@ -0,0 +1,47 @@ +/* + * 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.nifi.toolkit.cli.impl.command.nifi.flow; + +import org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient; +import org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient; +import org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException; +import org.apache.nifi.toolkit.cli.impl.command.nifi.AbstractNiFiCommand; +import org.apache.nifi.toolkit.cli.impl.result.ClusterSummaryEntityResult; +import org.apache.nifi.web.api.entity.ClusteSummaryEntity; + +import java.io.IOException; +import java.util.Properties; + +public class ClusterSummary extends AbstractNiFiCommand { + public ClusterSummary() { + super("cluster-summary", ClusterSummaryEntityResult.class); + } + + @Override + public String getDescription() { + return "Returns information about the node's cluster summary. " + + "This provides a way to test if the node is in the expected state."; + } + + @Override + public ClusterSummaryEntityResult doExecute(NiFiClient client, Properties properties) + throws NiFiClientException, IOException { + final FlowClient flowClient = client.getFlowClient(); + final ClusteSummaryEntity clusterSummary = flowClient.getClusterSummary(); + return new ClusterSummaryEntityResult(getResultType(properties), clusterSummary); + } +} diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/result/ClusterSummaryEntityResult.java b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/result/ClusterSummaryEntityResult.java new file mode 100644 index 0000000000..53d9601522 --- /dev/null +++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/result/ClusterSummaryEntityResult.java @@ -0,0 +1,54 @@ +/* + * 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.nifi.toolkit.cli.impl.result; + +import org.apache.commons.lang3.Validate; +import org.apache.nifi.toolkit.cli.api.ResultType; +import org.apache.nifi.web.api.entity.ClusteSummaryEntity; + +import java.io.PrintStream; + +/** + * Result for CurrentUserEntity from NiFi. + */ +public class ClusterSummaryEntityResult extends AbstractWritableResult { + + private final ClusteSummaryEntity clusteSummaryEntity; + + public ClusterSummaryEntityResult(final ResultType resultType, final ClusteSummaryEntity clusteSummaryEntity) { + super(resultType); + this.clusteSummaryEntity = clusteSummaryEntity; + Validate.notNull(this.clusteSummaryEntity); + } + + @Override + public ClusteSummaryEntity getResult() { + return clusteSummaryEntity; + } + + @Override + protected void writeSimpleResult(final PrintStream output) { + output.printf( + "Total node count: %d\nConnected node count: %d\nClustered: %s\nConnected to cluster: %s\n", + clusteSummaryEntity.getClusterSummary().getTotalNodeCount(), + clusteSummaryEntity.getClusterSummary().getConnectedNodeCount(), + clusteSummaryEntity.getClusterSummary().getClustered(), + clusteSummaryEntity.getClusterSummary().getConnectedToCluster() + ); + } + +}