Search in sources :

Example 6 with StringResult

use of org.apache.nifi.toolkit.cli.impl.result.StringResult in project nifi by apache.

the class PGImport method doExecute.

@Override
public StringResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException {
    final String bucketId = getRequiredArg(properties, CommandOption.BUCKET_ID);
    final String flowId = getRequiredArg(properties, CommandOption.FLOW_ID);
    final Integer flowVersion = getRequiredIntArg(properties, CommandOption.FLOW_VERSION);
    // if a registry client is specified use it, otherwise see if there is only one available and use that,
    // if more than one is available then throw an exception because we don't know which one to use
    String registryId = getArg(properties, CommandOption.REGISTRY_CLIENT_ID);
    if (StringUtils.isBlank(registryId)) {
        final RegistryClientsEntity registries = client.getControllerClient().getRegistryClients();
        final Set<RegistryClientEntity> entities = registries.getRegistries();
        if (entities == null || entities.isEmpty()) {
            throw new NiFiClientException("No registry clients available");
        }
        if (entities.size() == 1) {
            registryId = entities.stream().findFirst().get().getId();
        } else {
            throw new MissingOptionException(CommandOption.REGISTRY_CLIENT_ID.getLongName() + " must be provided when there is more than one available");
        }
    }
    // get the optional id of the parent PG, otherwise fallback to the root group
    String parentPgId = getArg(properties, CommandOption.PG_ID);
    if (StringUtils.isBlank(parentPgId)) {
        final FlowClient flowClient = client.getFlowClient();
        parentPgId = flowClient.getRootGroupId();
    }
    final VersionControlInformationDTO versionControlInfo = new VersionControlInformationDTO();
    versionControlInfo.setRegistryId(registryId);
    versionControlInfo.setBucketId(bucketId);
    versionControlInfo.setFlowId(flowId);
    versionControlInfo.setVersion(flowVersion);
    final ProcessGroupBox pgBox = client.getFlowClient().getSuggestedProcessGroupCoordinates(parentPgId);
    final PositionDTO posDto = new PositionDTO();
    posDto.setX(Integer.valueOf(pgBox.getX()).doubleValue());
    posDto.setY(Integer.valueOf(pgBox.getY()).doubleValue());
    final ProcessGroupDTO pgDto = new ProcessGroupDTO();
    pgDto.setVersionControlInformation(versionControlInfo);
    pgDto.setPosition(posDto);
    final ProcessGroupEntity pgEntity = new ProcessGroupEntity();
    pgEntity.setComponent(pgDto);
    pgEntity.setRevision(getInitialRevisionDTO());
    final ProcessGroupClient pgClient = client.getProcessGroupClient();
    final ProcessGroupEntity createdEntity = pgClient.createProcessGroup(parentPgId, pgEntity);
    return new StringResult(createdEntity.getId(), getContext().isInteractive());
}
Also used : NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) RegistryClientsEntity(org.apache.nifi.web.api.entity.RegistryClientsEntity) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) FlowClient(org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient) ProcessGroupBox(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupBox) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) ProcessGroupClient(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupClient) MissingOptionException(org.apache.commons.cli.MissingOptionException)

Example 7 with StringResult

use of org.apache.nifi.toolkit.cli.impl.result.StringResult in project nifi by apache.

the class CreateRegistryClient method doExecute.

@Override
public StringResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException {
    final String name = getRequiredArg(properties, CommandOption.REGISTRY_CLIENT_NAME);
    final String url = getRequiredArg(properties, CommandOption.REGISTRY_CLIENT_URL);
    final String desc = getArg(properties, CommandOption.REGISTRY_CLIENT_DESC);
    final RegistryDTO registryDTO = new RegistryDTO();
    registryDTO.setName(name);
    registryDTO.setUri(url);
    registryDTO.setDescription(desc);
    final RegistryClientEntity clientEntity = new RegistryClientEntity();
    clientEntity.setComponent(registryDTO);
    clientEntity.setRevision(getInitialRevisionDTO());
    final RegistryClientEntity createdEntity = client.getControllerClient().createRegistryClient(clientEntity);
    return new StringResult(createdEntity.getId(), getContext().isInteractive());
}
Also used : RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO)

Example 8 with StringResult

use of org.apache.nifi.toolkit.cli.impl.result.StringResult in project nifi by apache.

the class CreateFlow method doExecute.

@Override
public StringResult doExecute(final NiFiRegistryClient client, final Properties properties) throws ParseException, IOException, NiFiRegistryException {
    final String bucketId = getRequiredArg(properties, CommandOption.BUCKET_ID);
    final String flowName = getRequiredArg(properties, CommandOption.FLOW_NAME);
    final String flowDesc = getArg(properties, CommandOption.FLOW_DESC);
    final VersionedFlow flow = new VersionedFlow();
    flow.setName(flowName);
    flow.setDescription(flowDesc);
    flow.setBucketIdentifier(bucketId);
    final FlowClient flowClient = client.getFlowClient();
    final VersionedFlow createdFlow = flowClient.create(flow);
    return new StringResult(createdFlow.getIdentifier(), getContext().isInteractive());
}
Also used : VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) FlowClient(org.apache.nifi.registry.client.FlowClient) StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult)

Example 9 with StringResult

use of org.apache.nifi.toolkit.cli.impl.result.StringResult in project nifi by apache.

the class GetVariable method execute.

@Override
public StringResult execute(final CommandLine commandLine) throws CommandException {
    final String[] args = commandLine.getArgs();
    if (args == null || args.length != 1 || StringUtils.isBlank(args[0])) {
        throw new CommandException("Incorrect number of arguments, should be: <var>");
    }
    final Session session = getContext().getSession();
    try {
        final String value = session.get(args[0]);
        if (value == null) {
            return new StringResult("", getContext().isInteractive());
        } else {
            return new StringResult(value, getContext().isInteractive());
        }
    } catch (SessionException se) {
        throw new CommandException(se.getMessage(), se);
    }
}
Also used : SessionException(org.apache.nifi.toolkit.cli.api.SessionException) CommandException(org.apache.nifi.toolkit.cli.api.CommandException) StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) Session(org.apache.nifi.toolkit.cli.api.Session)

Example 10 with StringResult

use of org.apache.nifi.toolkit.cli.impl.result.StringResult in project nifi by apache.

the class CreateBucket method doExecute.

@Override
public StringResult doExecute(final NiFiRegistryClient client, final Properties properties) throws IOException, NiFiRegistryException, MissingOptionException {
    final String bucketName = getRequiredArg(properties, CommandOption.BUCKET_NAME);
    final String bucketDesc = getArg(properties, CommandOption.BUCKET_DESC);
    final Bucket bucket = new Bucket();
    bucket.setName(bucketName);
    bucket.setDescription(bucketDesc);
    final BucketClient bucketClient = client.getBucketClient();
    final Bucket createdBucket = bucketClient.create(bucket);
    return new StringResult(createdBucket.getIdentifier(), getContext().isInteractive());
}
Also used : BucketClient(org.apache.nifi.registry.client.BucketClient) Bucket(org.apache.nifi.registry.bucket.Bucket) StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult)

Aggregations

StringResult (org.apache.nifi.toolkit.cli.impl.result.StringResult)11 Properties (java.util.Properties)5 MissingOptionException (org.apache.commons.cli.MissingOptionException)3 IOException (java.io.IOException)2 Date (java.util.Date)2 Bucket (org.apache.nifi.registry.bucket.Bucket)2 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)2 NiFiClientException (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException)2 RegistryClientEntity (org.apache.nifi.web.api.entity.RegistryClientEntity)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URL (java.net.URL)1 ParseException (org.apache.commons.cli.ParseException)1 BucketClient (org.apache.nifi.registry.client.BucketClient)1 FlowClient (org.apache.nifi.registry.client.FlowClient)1 FlowSnapshotClient (org.apache.nifi.registry.client.FlowSnapshotClient)1 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)1 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)1 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)1