-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-5430 CLI tool extension for cluster summary
This closes #2894. Signed-off-by: Bryan Bende <bbende@apache.org>
- Loading branch information
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/flow/ClusterSummary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...cli/src/main/java/org/apache/nifi/toolkit/cli/impl/result/ClusterSummaryEntityResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
|
||
} |