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());
}
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());
}
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());
}
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);
}
}
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());
}
Aggregations