Search in sources :

Example 6 with NiFiClientException

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;
}
Also used : NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) VersionedFlowSnapshotMetadataEntity(org.apache.nifi.web.api.entity.VersionedFlowSnapshotMetadataEntity) FlowClient(org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient) VersionedFlowSnapshotMetadataSetEntity(org.apache.nifi.web.api.entity.VersionedFlowSnapshotMetadataSetEntity)

Example 7 with NiFiClientException

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);
}
Also used : NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) VersionControlInformationEntity(org.apache.nifi.web.api.entity.VersionControlInformationEntity) VersionedFlowSnapshotMetadataSetResult(org.apache.nifi.toolkit.cli.impl.result.VersionedFlowSnapshotMetadataSetResult) VersionsClient(org.apache.nifi.toolkit.cli.impl.client.nifi.VersionsClient) FlowClient(org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient) VersionedFlowSnapshotMetadataSetEntity(org.apache.nifi.web.api.entity.VersionedFlowSnapshotMetadataSetEntity) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO)

Example 8 with NiFiClientException

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);
}
Also used : NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) VersionControlInformationEntity(org.apache.nifi.web.api.entity.VersionControlInformationEntity) VersionControlInfoResult(org.apache.nifi.toolkit.cli.impl.result.VersionControlInfoResult)

Example 9 with NiFiClientException

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);
    }
}
Also used : NiFiClient(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient) Properties(java.util.Properties) RegistryClientsEntity(org.apache.nifi.web.api.entity.RegistryClientsEntity) NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) RegistryClientIDResult(org.apache.nifi.toolkit.cli.impl.result.RegistryClientIDResult) CommandOption(org.apache.nifi.toolkit.cli.impl.command.CommandOption) AbstractNiFiCommand(org.apache.nifi.toolkit.cli.impl.command.nifi.AbstractNiFiCommand) IOException(java.io.IOException) CommandException(org.apache.nifi.toolkit.cli.api.CommandException) StringUtils(org.apache.commons.lang3.StringUtils) Context(org.apache.nifi.toolkit.cli.api.Context) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO) NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) RegistryClientsEntity(org.apache.nifi.web.api.entity.RegistryClientsEntity) RegistryClientIDResult(org.apache.nifi.toolkit.cli.impl.result.RegistryClientIDResult) CommandException(org.apache.nifi.toolkit.cli.api.CommandException) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO)

Example 10 with NiFiClientException

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;
}
Also used : ProcessGroupBox(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupBox) NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) Set(java.util.Set) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) Entity(javax.ws.rs.client.Entity) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Objects(java.util.Objects) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) MediaType(javax.ws.rs.core.MediaType) List(java.util.List) VersionedFlowSnapshotMetadataSetEntity(org.apache.nifi.web.api.entity.VersionedFlowSnapshotMetadataSetEntity) Map(java.util.Map) FlowClient(org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient) CurrentUserEntity(org.apache.nifi.web.api.entity.CurrentUserEntity) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) WebTarget(javax.ws.rs.client.WebTarget) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) Collections(java.util.Collections) ScheduleComponentsEntity(org.apache.nifi.web.api.entity.ScheduleComponentsEntity) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) ArrayList(java.util.ArrayList) ProcessGroupBox(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupBox) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Objects(java.util.Objects)

Aggregations

NiFiClientException (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException)10 FlowClient (org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient)5 IOException (java.io.IOException)4 Properties (java.util.Properties)3 StringUtils (org.apache.commons.lang3.StringUtils)3 VersionControlInformationDTO (org.apache.nifi.web.api.dto.VersionControlInformationDTO)3 VersionControlInformationEntity (org.apache.nifi.web.api.entity.VersionControlInformationEntity)3 VersionedFlowSnapshotMetadataSetEntity (org.apache.nifi.web.api.entity.VersionedFlowSnapshotMetadataSetEntity)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MissingOptionException (org.apache.commons.cli.MissingOptionException)2 Context (org.apache.nifi.toolkit.cli.api.Context)2 NiFiClient (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient)2 ProcessGroupBox (org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupBox)2 ProcessGroupClient (org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupClient)2 VersionsClient (org.apache.nifi.toolkit.cli.impl.client.nifi.VersionsClient)2 CommandOption (org.apache.nifi.toolkit.cli.impl.command.CommandOption)2 AbstractNiFiCommand (org.apache.nifi.toolkit.cli.impl.command.nifi.AbstractNiFiCommand)2 RegistryClientIDResult (org.apache.nifi.toolkit.cli.impl.result.RegistryClientIDResult)2 StringResult (org.apache.nifi.toolkit.cli.impl.result.StringResult)2