NIFI-5430 CLI tool extension for cluster summary

This closes #2894.

Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
pepov 2018-07-16 09:34:41 +02:00 committed by Bryan Bende
parent b10220439c
commit b191f6a62a
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39
5 changed files with 119 additions and 0 deletions

View File

@ -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;
}

View File

@ -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);
});
}
}

View File

@ -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());

View File

@ -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);
}
}

View File

@ -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()
);
}
}