Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillard31 committed May 2, 2024
1 parent dd103b2 commit 65209ab
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions nifi-docs/src/main/asciidoc/toolkit-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ The following are available commands:
nifi pg-get-version
nifi pg-stop-version-control
nifi pg-change-version
nifi pg-change-all-versions
nifi pg-get-all-versions
nifi pg-list
nifi pg-status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ public ProcessGroupsVersionChangeResult doExecute(final NiFiClient client, final
parentPgId = flowClient.getRootGroupId();
}

PGList doPGList = new PGList();
List<ProcessGroupDTO> pgList = new ArrayList<ProcessGroupDTO>();
final PGList doPGList = new PGList();
final List<ProcessGroupDTO> pgList = new ArrayList<ProcessGroupDTO>();
recursivePGList(pgList, doPGList, client, properties, parentPgId);

PGChangeVersion doPGChangeVersion = new PGChangeVersion();
final PGChangeVersion doPGChangeVersion = new PGChangeVersion();

// new version, if specified in the arguments
Integer newVersion = getIntArg(properties, CommandOption.FLOW_VERSION);
String newVersion = getArg(properties, CommandOption.FLOW_VERSION);

// force operation, if specified in the arguments
final boolean forceOperation = properties.containsKey(CommandOption.FORCE.getLongName());

final List<ProcessGroupDTO> processGroups = new ArrayList<>();
final Map<String, ChangeVersionResult> changeVersionResults = new HashMap<String, ChangeVersionResult>();

for (ProcessGroupDTO pgDTO : pgList) {
for (final ProcessGroupDTO pgDTO : pgList) {
final VersionControlInformationEntity entity = client.getVersionsClient().getVersionControlInfo(pgDTO.getId());

if(entity.getVersionControlInformation() == null || !entity.getVersionControlInformation().getFlowId().equals(flowId)) {
Expand All @@ -105,8 +105,8 @@ public ProcessGroupsVersionChangeResult doExecute(final NiFiClient client, final

processGroups.add(pgDTO);

final Integer previousVersion = pgDTO.getVersionControlInformation().getVersion();
if(previousVersion == newVersion) {
final String previousVersion = pgDTO.getVersionControlInformation().getVersion();
if (previousVersion.equals(newVersion)) {
changeVersionResults.put(pgDTO.getId(), new ChangeVersionResult(newVersion, newVersion, "Process group already at desired version"));
continue; // Process group already at desired version
}
Expand All @@ -116,7 +116,7 @@ public ProcessGroupsVersionChangeResult doExecute(final NiFiClient client, final
changeVersionResults.put(pgDTO.getId(), new ChangeVersionResult(previousVersion, newVersion, "SUCCESS"));
} catch (Exception e) {
changeVersionResults.put(pgDTO.getId(), new ChangeVersionResult(previousVersion, null, e.getMessage()));
if(forceOperation) {
if (forceOperation) {
continue;
} else {
e.printStackTrace();
Expand All @@ -130,7 +130,7 @@ public ProcessGroupsVersionChangeResult doExecute(final NiFiClient client, final

private void recursivePGList(final List<ProcessGroupDTO> pgList, final PGList doPGList, final NiFiClient client,
final Properties properties, final String pgId) throws NiFiClientException, IOException {
ProcessGroupsResult result = doPGList.getList(client, properties, pgId);
final ProcessGroupsResult result = doPGList.getList(client, properties, pgId);
for(ProcessGroupDTO pgDTO : result.getResult()) {
pgList.add(pgDTO);
recursivePGList(pgList, doPGList, client, properties, pgDTO.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public VoidResult doExecute(final NiFiClient client, final Properties properties
}

public VoidResult changeVersion(final NiFiClient client, final VersionControlInformationEntity existingVersionControlInfo,
Integer newVersion, final String pgId, final Context context) throws NiFiClientException, IOException, MissingOptionException, CommandException {
String newVersion, final String pgId, final Context context) throws NiFiClientException, IOException, MissingOptionException, CommandException {
final VersionsClient versionsClient = client.getVersionsClient();
final VersionControlInformationDTO existingVersionControlDTO = existingVersionControlInfo.getVersionControlInformation();

Expand Down Expand Up @@ -107,7 +107,7 @@ public VoidResult changeVersion(final NiFiClient client, final VersionControlInf
final VersionedFlowUpdateRequestEntity updateRequest = versionsClient.getUpdateRequest(updateRequestId);
if (updateRequest != null && updateRequest.getRequest().isComplete()) {
completed = true;
if(updateRequest.getRequest().getFailureReason() != null) {
if (updateRequest.getRequest().getFailureReason() != null) {
throw new NiFiClientException(updateRequest.getRequest().getFailureReason());
}
break;
Expand All @@ -134,7 +134,7 @@ public VoidResult changeVersion(final NiFiClient client, final VersionControlInf
return VoidResult.getInstance();
}

private String getLatestVersion(final NiFiClient client, final VersionControlInformationDTO existingVersionControlDTO)
String getLatestVersion(final NiFiClient client, final VersionControlInformationDTO existingVersionControlDTO)
throws NiFiClientException, IOException {
final FlowClient flowClient = client.getFlowClient();

Expand All @@ -149,7 +149,7 @@ private String getLatestVersion(final NiFiClient client, final VersionControlInf
return getLatestVersion(versions);
}

private static String getLatestVersion(final VersionedFlowSnapshotMetadataSetEntity versions) {
private String getLatestVersion(final VersionedFlowSnapshotMetadataSetEntity versions) {
long latestTimestamp = 0;
String latestVersion = null;
for (VersionedFlowSnapshotMetadataEntity version : versions.getVersionedFlowSnapshotMetadataSet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ProcessGroupsResult doExecute(final NiFiClient client, final Properties p
return getList(client, properties, parentPgId);
}

public ProcessGroupsResult getList(final NiFiClient client, final Properties properties, String pgID)
public ProcessGroupsResult getList(final NiFiClient client, final Properties properties, final String pgID)
throws NiFiClientException, IOException {
final ProcessGroupFlowEntity processGroupFlowEntity = client.getFlowClient().getProcessGroup(pgID);
final ProcessGroupFlowDTO processGroupFlowDTO = processGroupFlowEntity.getProcessGroupFlow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
* Object to help with the result of a change version operation
*/
public class ChangeVersionResult {
Integer previousVersion;
Integer newVersion;
String previousVersion;
String newVersion;
String message;

public ChangeVersionResult(Integer previousVersion, Integer newVersion, String message) {
public ChangeVersionResult(final String previousVersion, final String newVersion, final String message) {
this.previousVersion = previousVersion;
this.newVersion = newVersion;
this.message = message;
}

public Integer getPreviousVersion() {
public String getPreviousVersion() {
return previousVersion;
}

public Integer getNewVersion() {
public String getNewVersion() {
return newVersion;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected void writeSimpleResult(final PrintStream output) {

@Override
public ReferenceResolver createReferenceResolver(final Context context) {
final Map<Integer,ProcessGroupDTO> backRefs = new HashMap<>();
final Map<Integer, ProcessGroupDTO> backRefs = new HashMap<>();
final AtomicInteger position = new AtomicInteger(0);
processGroups.forEach(p -> backRefs.put(position.incrementAndGet(), p));

Expand Down

0 comments on commit 65209ab

Please sign in to comment.