use of org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException in project nifi by apache.
the class PGChangeVersion method getLatestVersion.
private int getLatestVersion(final NiFiClient client, final VersionControlInformationDTO existingVersionControlDTO) throws NiFiClientException, IOException {
final FlowClient flowClient = client.getFlowClient();
final String registryId = existingVersionControlDTO.getRegistryId();
final String bucketId = existingVersionControlDTO.getBucketId();
final String flowId = existingVersionControlDTO.getFlowId();
final VersionedFlowSnapshotMetadataSetEntity versions = flowClient.getVersions(registryId, bucketId, flowId);
if (versions.getVersionedFlowSnapshotMetadataSet() == null || versions.getVersionedFlowSnapshotMetadataSet().isEmpty()) {
throw new NiFiClientException("No versions available");
}
int latestVersion = 1;
for (VersionedFlowSnapshotMetadataEntity version : versions.getVersionedFlowSnapshotMetadataSet()) {
if (version.getVersionedFlowSnapshotMetadata().getVersion() > latestVersion) {
latestVersion = version.getVersionedFlowSnapshotMetadata().getVersion();
}
}
return latestVersion;
}
use of org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException in project nifi by apache.
the class PGGetAllVersions method doExecute.
@Override
public VersionedFlowSnapshotMetadataSetResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException {
final String pgId = getRequiredArg(properties, CommandOption.PG_ID);
final VersionsClient versionsClient = client.getVersionsClient();
final VersionControlInformationEntity existingVersionControlInfo = versionsClient.getVersionControlInfo(pgId);
final VersionControlInformationDTO existingVersionControlDTO = existingVersionControlInfo.getVersionControlInformation();
if (existingVersionControlDTO == null) {
throw new NiFiClientException("Process group is not under version control");
}
final String registryId = existingVersionControlDTO.getRegistryId();
final String bucketId = existingVersionControlDTO.getBucketId();
final String flowId = existingVersionControlDTO.getFlowId();
final FlowClient flowClient = client.getFlowClient();
final VersionedFlowSnapshotMetadataSetEntity versions = flowClient.getVersions(registryId, bucketId, flowId);
if (versions.getVersionedFlowSnapshotMetadataSet() == null || versions.getVersionedFlowSnapshotMetadataSet().isEmpty()) {
throw new NiFiClientException("No versions available");
}
return new VersionedFlowSnapshotMetadataSetResult(getResultType(properties), versions);
}
use of org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException in project nifi by apache.
the class PGGetVersion method doExecute.
@Override
public VersionControlInfoResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException, CommandException {
final String pgId = getRequiredArg(properties, CommandOption.PG_ID);
final VersionControlInformationEntity entity = client.getVersionsClient().getVersionControlInfo(pgId);
if (entity.getVersionControlInformation() == null) {
throw new NiFiClientException("Process group is not under version control");
}
return new VersionControlInfoResult(getResultType(properties), entity);
}
use of org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException in project nifi by apache.
the class GetRegistryClientId method doExecute.
@Override
public RegistryClientIDResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, CommandException {
final String regClientName = getArg(properties, CommandOption.REGISTRY_CLIENT_NAME);
final String regClientUrl = getArg(properties, CommandOption.REGISTRY_CLIENT_URL);
if (!StringUtils.isBlank(regClientName) && !StringUtils.isBlank(regClientUrl)) {
throw new CommandException("Name and URL cannot be specified at the same time");
}
if (StringUtils.isBlank(regClientName) && StringUtils.isBlank(regClientUrl)) {
throw new CommandException("Name or URL must be specified");
}
final RegistryClientsEntity registries = client.getControllerClient().getRegistryClients();
RegistryDTO registry;
if (!StringUtils.isBlank(regClientName)) {
registry = registries.getRegistries().stream().map(r -> r.getComponent()).filter(r -> r.getName().equalsIgnoreCase(regClientName.trim())).findFirst().orElse(null);
} else {
registry = registries.getRegistries().stream().map(r -> r.getComponent()).filter(r -> r.getUri().equalsIgnoreCase(regClientUrl.trim())).findFirst().orElse(null);
}
if (registry == null) {
throw new NiFiClientException("No registry client exists with the name '" + regClientName + "'");
} else {
return new RegistryClientIDResult(getResultType(properties), registry);
}
}
use of org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException in project nifi by apache.
the class JerseyFlowClient method getSuggestedProcessGroupCoordinates.
@Override
public ProcessGroupBox getSuggestedProcessGroupCoordinates(final String parentId) throws NiFiClientException, IOException {
if (StringUtils.isBlank(parentId)) {
throw new IllegalArgumentException("Process group id cannot be null");
}
final ProcessGroupFlowEntity processGroup = getProcessGroup(parentId);
final ProcessGroupFlowDTO processGroupFlowDTO = processGroup.getProcessGroupFlow();
final FlowDTO flowDTO = processGroupFlowDTO.getFlow();
final List<ComponentEntity> pgComponents = new ArrayList<>();
pgComponents.addAll(flowDTO.getProcessGroups());
pgComponents.addAll(flowDTO.getProcessors());
pgComponents.addAll(flowDTO.getRemoteProcessGroups());
pgComponents.addAll(flowDTO.getConnections());
pgComponents.addAll(flowDTO.getFunnels());
pgComponents.addAll(flowDTO.getInputPorts());
pgComponents.addAll(flowDTO.getOutputPorts());
pgComponents.addAll(flowDTO.getLabels());
final Set<PositionDTO> positions = pgComponents.stream().map(ComponentEntity::getPosition).collect(Collectors.toSet());
if (positions.isEmpty()) {
return ProcessGroupBox.CANVAS_CENTER;
}
final List<ProcessGroupBox> coords = positions.stream().filter(Objects::nonNull).map(p -> new ProcessGroupBox(p.getX().intValue(), p.getY().intValue())).collect(Collectors.toList());
final ProcessGroupBox freeSpot = coords.get(0).findFreeSpace(coords);
return freeSpot;
}
Aggregations