Skip to content

Commit

Permalink
NIFI-5430 CLI tool extension for cluster summary
Browse files Browse the repository at this point in the history
This closes #2894.

Signed-off-by: Bryan Bende <bbende@apache.org>
  • Loading branch information
pepov authored and bbende committed Jul 16, 2018
1 parent b102204 commit b191f6a
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,4 +98,10 @@ VersionedFlowSnapshotMetadataSetEntity getVersions(String registryId, String buc
*/
ActivateControllerServicesEntity activateControllerServices(ActivateControllerServicesEntity activateControllerServicesEntity) throws NiFiClientException, IOException;

/**
*
* @return cluster summary response
*/
ClusteSummaryEntity getClusterSummary() throws NiFiClientException, IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -217,4 +218,12 @@ public ActivateControllerServicesEntity activateControllerServices(final Activat
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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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;
Expand Down Expand Up @@ -56,6 +57,7 @@ public NiFiCommandGroup() {
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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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()
);
}

}

0 comments on commit b191f6a

Please sign in to comment.