mirror of https://github.com/apache/nifi.git
NIFI-5430 CLI tool extension for cluster summary
This closes #2894. Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
parent
b10220439c
commit
b191f6a62a
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Command> createCommands() {
|
||||
final List<AbstractNiFiCommand> commands = new ArrayList<>();
|
||||
commands.add(new CurrentUser());
|
||||
commands.add(new ClusterSummary());
|
||||
commands.add(new GetRootId());
|
||||
commands.add(new ListRegistryClients());
|
||||
commands.add(new CreateRegistryClient());
|
||||
|
|
|
@ -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<ClusterSummaryEntityResult> {
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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<ClusteSummaryEntity> {
|
||||
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue