org.apache.commons.cli.MissingOptionException Java Examples

The following examples show how to use org.apache.commons.cli.MissingOptionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PGCreate.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException {

    final String processGroupName = getRequiredArg(properties, CommandOption.PG_NAME);

    final FlowClient flowClient = client.getFlowClient();
    final ProcessGroupClient pgClient = client.getProcessGroupClient();
    final String rootPgId = flowClient.getRootGroupId();

    final ProcessGroupDTO processGroupDTO = new ProcessGroupDTO();
    processGroupDTO.setParentGroupId(rootPgId);
    processGroupDTO.setName(processGroupName);

    final ProcessGroupEntity pgEntity = new ProcessGroupEntity();
    pgEntity.setComponent(processGroupDTO);
    pgEntity.setRevision(getInitialRevisionDTO());

    final ProcessGroupEntity createdEntity = pgClient.createProcessGroup(
            rootPgId, pgEntity);

    return new StringResult(createdEntity.getId(), getContext().isInteractive());
}
 
Example #2
Source File: CreateRegistryClient.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #3
Source File: ParseExceptionProcessor.java    From rug-cli with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static String process(ParseException e) {
    if (e instanceof MissingOptionException) {
        StringBuilder sb = new StringBuilder();
        Iterator<String> options = ((MissingOptionException) e).getMissingOptions().iterator();
        while (options.hasNext()) {
            sb.append(options.next());
            if (options.hasNext()) {
                sb.append(", ");
            }
        }
        return String.format("Missing required option(s) %s.", sb.toString());
    }
    else if (e instanceof MissingArgumentException) {
        return String.format("%s is missing a required argument.",
                ((MissingArgumentException) e).getOption());
    }
    else if (e instanceof UnrecognizedOptionException) {
        return String.format("%s is not a valid option.",
                ((UnrecognizedOptionException) e).getOption());
    }
    else {
        return String.format("%s.", e.getMessage());
    }
}
 
Example #4
Source File: CreateReportingTask.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String inputFile = getRequiredArg(properties, CommandOption.INPUT_SOURCE);
    final URI uri = Paths.get(inputFile).toAbsolutePath().toUri();
    final String contents = IOUtils.toString(uri, StandardCharsets.UTF_8);

    final ObjectMapper objectMapper = JacksonUtils.getObjectMapper();
    final ReportingTaskEntity deserializedTask = objectMapper.readValue(contents, ReportingTaskEntity.class);
    if (deserializedTask == null) {
        throw new IOException("Unable to deserialize reporting task from " + inputFile);
    }

    deserializedTask.setRevision(getInitialRevisionDTO());

    final ControllerClient controllerClient = client.getControllerClient();
    final ReportingTaskEntity createdEntity = controllerClient.createReportingTask(deserializedTask);

    return new StringResult(String.valueOf(createdEntity.getId()), getContext().isInteractive());
}
 
Example #5
Source File: StopReportingTasks.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public VoidResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String rtId = getArg(properties, CommandOption.RT_ID);
    final Set<ReportingTaskEntity> reportingTaskEntities = new HashSet<>();

    if (StringUtils.isBlank(rtId)) {
        final ReportingTasksEntity reportingTasksEntity = client.getFlowClient().getReportingTasks();
        reportingTaskEntities.addAll(reportingTasksEntity.getReportingTasks());
    } else {
        reportingTaskEntities.add(client.getReportingTasksClient().getReportingTask(rtId));
    }

    activate(client, properties, reportingTaskEntities, "STOPPED");

    return VoidResult.getInstance();
}
 
Example #6
Source File: PGSetParamContext.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public VoidResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {

    final String pgId = getRequiredArg(properties, CommandOption.PG_ID);
    final String paramContextId = getRequiredArg(properties, CommandOption.PARAM_CONTEXT_ID);

    final ProcessGroupClient pgClient = client.getProcessGroupClient();
    final ProcessGroupEntity pgEntity = pgClient.getProcessGroup(pgId);

    final ParameterContextReferenceEntity parameterContextReference = new ParameterContextReferenceEntity();
    parameterContextReference.setId(paramContextId);

    final ProcessGroupDTO updatedDTO = new ProcessGroupDTO();
    updatedDTO.setId(pgId);
    updatedDTO.setParameterContext(parameterContextReference);

    final ProcessGroupEntity updatedEntity = new ProcessGroupEntity();
    updatedEntity.setId(pgId);
    updatedEntity.setComponent(updatedDTO);
    updatedEntity.setRevision(pgEntity.getRevision());

    pgClient.updateProcessGroup(updatedEntity);
    return VoidResult.getInstance();
}
 
Example #7
Source File: CreateParamContext.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {

    final String paramContextName = getRequiredArg(properties, CommandOption.PARAM_CONTEXT_NAME);
    final String paramContextDesc = getArg(properties, CommandOption.PARAM_CONTEXT_DESC);

    final ParameterContextDTO paramContextDTO = new ParameterContextDTO();
    paramContextDTO.setName(paramContextName);
    paramContextDTO.setParameters(Collections.emptySet());

    if (!StringUtils.isBlank(paramContextDesc)) {
        paramContextDTO.setDescription(paramContextDesc);
    }

    final ParameterContextEntity paramContextEntity = new ParameterContextEntity();
    paramContextEntity.setComponent(paramContextDTO);
    paramContextEntity.setRevision(getInitialRevisionDTO());

    final ParamContextClient paramContextClient = client.getParamContextClient();
    final ParameterContextEntity createdParamContext = paramContextClient.createParamContext(paramContextEntity);
    return new StringResult(createdParamContext.getId(), isInteractive());
}
 
Example #8
Source File: CreateControllerService.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String inputFile = getRequiredArg(properties, CommandOption.INPUT_SOURCE);
    final URI uri = Paths.get(inputFile).toAbsolutePath().toUri();
    final String contents = IOUtils.toString(uri, StandardCharsets.UTF_8);

    final ObjectMapper objectMapper = JacksonUtils.getObjectMapper();
    final ControllerServiceEntity deserializedService = objectMapper.readValue(contents, ControllerServiceEntity.class);
    if (deserializedService == null) {
        throw new IOException("Unable to deserialize controller service version from " + inputFile);
    }

    deserializedService.setRevision(getInitialRevisionDTO());

    final ControllerClient controllerClient = client.getControllerClient();
    final ControllerServiceEntity createdEntity = controllerClient.createControllerService(deserializedService);

    return new StringResult(String.valueOf(createdEntity.getId()), getContext().isInteractive());
}
 
Example #9
Source File: EnableControllerServices.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public VoidResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String csId = getArg(properties, CommandOption.CS_ID);
    final Set<ControllerServiceEntity> serviceEntities = new HashSet<>();

    if (StringUtils.isBlank(csId)) {
        final ControllerServicesEntity servicesEntity = client.getFlowClient().getControllerServices();
        serviceEntities.addAll(servicesEntity.getControllerServices());
    } else {
        serviceEntities.add(client.getControllerServicesClient().getControllerService(csId));
    }

    activate(client, properties, serviceEntities, "ENABLED");

    return VoidResult.getInstance();
}
 
Example #10
Source File: PGCreateControllerService.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String processorGroupId = getRequiredArg(properties, CommandOption.PG_ID);
    final String inputFile = getRequiredArg(properties, CommandOption.INPUT_SOURCE);
    final URI uri = Paths.get(inputFile).toAbsolutePath().toUri();
    final String contents = IOUtils.toString(uri, StandardCharsets.UTF_8);

    final ObjectMapper objectMapper = JacksonUtils.getObjectMapper();
    final ControllerServiceEntity deserializedService = objectMapper.readValue(contents, ControllerServiceEntity.class);
    if (deserializedService == null) {
        throw new IOException("Unable to deserialize controller service version from " + inputFile);
    }

    deserializedService.setRevision(getInitialRevisionDTO());

    final ProcessGroupClient pgClient = client.getProcessGroupClient();
    final ControllerServiceEntity createdEntity = pgClient.createControllerService(
            processorGroupId, deserializedService);

    return new StringResult(String.valueOf(createdEntity.getId()), getContext().isInteractive());
}
 
Example #11
Source File: DisableControllerServices.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public VoidResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String csId = getArg(properties, CommandOption.CS_ID);
    final Set<ControllerServiceEntity> serviceEntities = new HashSet<>();

    if (StringUtils.isBlank(csId)) {
        final ControllerServicesEntity servicesEntity = client.getFlowClient().getControllerServices();
        serviceEntities.addAll(servicesEntity.getControllerServices());
    } else {
        serviceEntities.add(client.getControllerServicesClient().getControllerService(csId));
    }

    activate(client, properties, serviceEntities, "DISABLED");

    return VoidResult.getInstance();
}
 
Example #12
Source File: DeleteParamContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public StringResult doExecute(NiFiClient client, Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String paramContextId = getRequiredArg(properties, CommandOption.PARAM_CONTEXT_ID);

    final ParamContextClient paramContextClient = client.getParamContextClient();
    final ParameterContextEntity existingParamContext = paramContextClient.getParamContext(paramContextId);

    final String version = String.valueOf(existingParamContext.getRevision().getVersion());
    paramContextClient.deleteParamContext(paramContextId, version);
    return new StringResult(paramContextId, isInteractive());
}
 
Example #13
Source File: ImportParamContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    // optional params
    final String paramContextName = getArg(properties, CommandOption.PARAM_CONTEXT_NAME);
    final String paramContextDesc = getArg(properties, CommandOption.PARAM_CONTEXT_DESC);

    // read the content of the input source into memory
    final String inputSource = getRequiredArg(properties, CommandOption.INPUT_SOURCE);
    final String paramContextJson = getInputSourceContent(inputSource);

    // unmarshall the content into the DTO object
    final ObjectMapper objectMapper = JacksonUtils.getObjectMapper();
    final ParameterContextDTO paramContext = objectMapper.readValue(paramContextJson, ParameterContextDTO.class);

    // override context name if specified
    if (!StringUtils.isBlank(paramContextName)) {
        paramContext.setName(paramContextName);
    }

    // override context description if specified
    if (!StringUtils.isBlank(paramContextDesc)) {
        paramContext.setDescription(paramContextDesc);
    }

    // create the entity to wrap the context
    final ParameterContextEntity paramContextEntity = new ParameterContextEntity();
    paramContextEntity.setComponent(paramContext);
    paramContextEntity.setRevision(getInitialRevisionDTO());

    // create the context and return the id
    final ParamContextClient paramContextClient = client.getParamContextClient();
    final ParameterContextEntity createdParamContext = paramContextClient.createParamContext(paramContextEntity);
    return new StringResult(createdParamContext.getId(), isInteractive());
}
 
Example #14
Source File: GetControllerServices.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ControllerServicesResult doExecute(NiFiClient client, Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final FlowClient flowClient = client.getFlowClient();
    final ControllerServicesEntity servicesEntity = flowClient.getControllerServices();
    return new ControllerServicesResult(getResultType(properties), servicesEntity);
}
 
Example #15
Source File: PGStart.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public VoidResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {

    final String pgId = getRequiredArg(properties, CommandOption.PG_ID);

    final ScheduleComponentsEntity entity = new ScheduleComponentsEntity();
    entity.setId(pgId);
    entity.setState(ScheduleComponentsEntity.STATE_RUNNING);

    final FlowClient flowClient = client.getFlowClient();
    final ScheduleComponentsEntity resultEntity = flowClient.scheduleProcessGroupComponents(pgId, entity);
    return VoidResult.getInstance();
}
 
Example #16
Source File: GetReportingTask.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ReportingTaskResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String rtId = getRequiredArg(properties, CommandOption.RT_ID);
    final ReportingTasksClient rtClient = client.getReportingTasksClient();

    final ReportingTaskEntity rtEntity = rtClient.getReportingTask(rtId);
    return new ReportingTaskResult(getResultType(properties), rtEntity);
}
 
Example #17
Source File: GetReportingTasks.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ReportingTasksResult doExecute(NiFiClient client, Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final FlowClient flowClient = client.getFlowClient();
    final ReportingTasksEntity tasksEntity = flowClient.getReportingTasks();
    return new ReportingTasksResult(getResultType(properties), tasksEntity);
}
 
Example #18
Source File: GetParamContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ParamContextResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String paramContextId = getRequiredArg(properties, CommandOption.PARAM_CONTEXT_ID);
    final ParamContextClient paramContextClient = client.getParamContextClient();
    final ParameterContextEntity parameterContext = paramContextClient.getParamContext(paramContextId);
    return new ParamContextResult(getResultType(properties), parameterContext);
}
 
Example #19
Source File: ListUserGroups.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public UserGroupsResult doExecute(NiFiClient client, Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final TenantsClient tenantsClient = client.getTenantsClient();
    final UserGroupsEntity userGroupsEntity = tenantsClient.getUserGroups();
    return new UserGroupsResult(getResultType(properties), userGroupsEntity);
}
 
Example #20
Source File: AbstractCommand.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected Integer getRequiredIntArg(final Properties properties, final CommandOption option) throws MissingOptionException {
    final String argValue = properties.getProperty(option.getLongName());
    if (StringUtils.isBlank(argValue)) {
        throw new MissingOptionException("Missing required option --" + option.getLongName());
    }

    try {
        return Integer.valueOf(argValue);
    } catch (Exception e) {
        throw new MissingOptionException("Version must be numeric: " + argValue);
    }
}
 
Example #21
Source File: GracefulCliParser.java    From valdr-bean-validation with MIT License 5 votes vote down vote up
@Override
protected void checkRequiredOptions() {
  try {
    super.checkRequiredOptions();
  } catch (MissingOptionException e) {
    incomplete = true;
  }
}
 
Example #22
Source File: ConstructorAndPublicMethodsCliObjectFactoryTest.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
  MyFactory factory = new MyFactory();
  MyObject object;

  try {
    // Try to build object with missing constructor argument, which is required
    object = factory.buildObject(new String[]{}, 0, false, "usage");
    Assert.fail();
  } catch (IOException exc) {
    // Expected
    Assert.assertEquals(exc.getCause().getClass(), MissingOptionException.class);
  }

  object = factory.buildObject(new String[]{"-myArg", "required"}, 0, false, "usage");
  Assert.assertEquals(object.required, "required");
  Assert.assertNull(object.string1);
  Assert.assertNull(object.string2);

  object = factory.buildObject(new String[]{"-setString1", "str1", "-myArg", "required"}, 0, false, "usage");
  Assert.assertEquals(object.required, "required");
  Assert.assertEquals(object.string1, "str1");
  Assert.assertNull(object.string2);

  object = factory.buildObject(new String[]{"-foo", "bar", "-myArg", "required"}, 0, false, "usage");
  Assert.assertEquals(object.required, "required");
  Assert.assertEquals(object.string2, "bar");
  Assert.assertNull(object.string1);

  object = factory.buildObject(new String[]{"-foo", "bar", "-setString1", "str1", "-myArg", "required"}, 0, false, "usage");
  Assert.assertEquals(object.required, "required");
  Assert.assertEquals(object.string2, "bar");
  Assert.assertEquals(object.string1, "str1");
}
 
Example #23
Source File: QuickImport.java    From nifi with Apache License 2.0 5 votes vote down vote up
private String getQuickImportBucketId(final NiFiRegistryClient registryClient, final boolean isInteractive)
        throws IOException, NiFiRegistryException, MissingOptionException {

    final BucketsResult bucketsResult = listBuckets.doExecute(registryClient, new Properties());

    final Bucket quickImportBucket = bucketsResult.getResult().stream()
            .filter(b -> BUCKET_NAME.equals(b.getName()))
            .findFirst().orElse(null);

    // if it doesn't exist, then create the quick import bucket
    String quickImportBucketId = null;
    if (quickImportBucket != null) {
        quickImportBucketId = quickImportBucket.getIdentifier();
        if (isInteractive) {
            println();
            println("Found existing bucket '" + BUCKET_NAME + "'...");
        }
    } else {
        final Properties createBucketProps = new Properties();
        createBucketProps.setProperty(CommandOption.BUCKET_NAME.getLongName(), BUCKET_NAME);
        createBucketProps.setProperty(CommandOption.BUCKET_DESC.getLongName(), BUCKET_DESC);

        final StringResult createdBucketId = createBucket.doExecute(registryClient, createBucketProps);
        quickImportBucketId = createdBucketId.getResult();
        if (isInteractive) {
            println();
            println("Created new bucket '" + BUCKET_NAME + "'...");
        }
    }
    return quickImportBucketId;
}
 
Example #24
Source File: CreateUserGroup.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {

    final String userGroupId = getRequiredArg(properties, CommandOption.UG_NAME);
    final String users = getArg(properties, CommandOption.USER_NAME_LIST);
    final String userIds = getArg(properties, CommandOption.USER_ID_LIST);

    final UserGroupDTO userGroupDTO = new UserGroupDTO();
    userGroupDTO.setIdentity(userGroupId);

    final Set<TenantEntity> tenantEntities = new HashSet<>();

    if (StringUtils.isNotBlank(users)) {
        tenantEntities.addAll(
            generateTenantEntities(users, client.getTenantsClient().getUsers()));
    }

    if (StringUtils.isNotBlank(userIds)) {
        tenantEntities.addAll(generateTenantEntities(userIds));
    }

    userGroupDTO.setUsers(tenantEntities);

    final UserGroupEntity userGroupEntity = new UserGroupEntity();
    userGroupEntity.setComponent(userGroupDTO);
    userGroupEntity.setRevision(getInitialRevisionDTO());

    final UserGroupEntity createdEntity = client.getTenantsClient().createUserGroup(userGroupEntity);
    return new StringResult(createdEntity.getId(), getContext().isInteractive());
}
 
Example #25
Source File: DisconnectNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public NodeResult doExecute(NiFiClient client, Properties properties) throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String nodeId = getRequiredArg(properties, CommandOption.NIFI_NODE_ID);
    final ControllerClient controllerClient = client.getControllerClient();

    NodeDTO nodeDto = new NodeDTO();
    nodeDto.setNodeId(nodeId);
    // TODO There are no constants for the DISCONNECT node status
    nodeDto.setStatus("DISCONNECTING");
    NodeEntity nodeEntity = new NodeEntity();
    nodeEntity.setNode(nodeDto);
    NodeEntity nodeEntityResult = controllerClient.disconnectNode(nodeId, nodeEntity);
    return new NodeResult(getResultType(properties), nodeEntityResult);
}
 
Example #26
Source File: ArgumentParserTest.java    From herd with Apache License 2.0 5 votes vote down vote up
@Test(expected = MissingOptionException.class)
public void testParseArguments() throws ParseException
{
    // Create an argument parser with a required "a" option.
    ArgumentParser argParser = new ArgumentParser("");
    argParser.addArgument("a", "some_required_parameter", true, "Some argument", true);

    // Parse the arguments with a missing argument which should thrown an exception since we are using the method that WILL fail on missing arguments.
    argParser.parseArguments(new String[] {});
}
 
Example #27
Source File: ArgumentParserTest.java    From herd with Apache License 2.0 5 votes vote down vote up
@Test(expected = MissingOptionException.class)
public void testParseArgumentsFailOnMissingArgumentTrue() throws ParseException
{
    // Create an argument parser with a required "a" option.
    ArgumentParser argParser = new ArgumentParser("");
    argParser.addArgument("a", "some_optional_parameter", false, "Some argument", true);

    // Parse the arguments with a missing argument which should thrown an exception since we are passing the flag which WILL fail on missing arguments.
    argParser.parseArguments(new String[] {}, true);
}
 
Example #28
Source File: UploadTemplate.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties)
        throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String processGroupId = getRequiredArg(properties, CommandOption.PG_ID);
    final String inputFile = getRequiredArg(properties, CommandOption.INPUT_SOURCE);

    final FileInputStream file = new FileInputStream(Paths.get(inputFile).toAbsolutePath().toFile());

    final ProcessGroupClient pgClient = client.getProcessGroupClient();
    final TemplateEntity createdEntity = pgClient.uploadTemplate(
            processGroupId,
            TemplateDeserializer.deserialize(file));

    return new StringResult(String.valueOf(createdEntity.getTemplate().getId()), getContext().isInteractive());
}
 
Example #29
Source File: GetNodes.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public NodesResult doExecute(NiFiClient client, Properties properties) throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final ControllerClient controllerClient = client.getControllerClient();

    ClusterEntity clusterEntityResult = controllerClient.getNodes();
    return new NodesResult(getResultType(properties), clusterEntityResult);
}
 
Example #30
Source File: PGGetAllVersions.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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);
}