Search in sources :

Example 1 with RegistryClientIDResult

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

the class QuickImport method getRegistryClientId.

private String getRegistryClientId(final NiFiClient nifiClient, final String registryClientBaseUrl, final boolean isInteractive) throws NiFiClientException, IOException, MissingOptionException {
    final Properties getRegClientProps = new Properties();
    getRegClientProps.setProperty(CommandOption.REGISTRY_CLIENT_URL.getLongName(), registryClientBaseUrl);
    String registryClientId;
    try {
        final RegistryClientIDResult registryClientResult = getRegistryClientId.doExecute(nifiClient, getRegClientProps);
        registryClientId = registryClientResult.getResult().getId();
        if (isInteractive) {
            println();
            println("Found existing registry client '" + registryClientResult.getResult().getName() + "'...");
        }
    } catch (Exception e) {
        registryClientId = null;
    }
    if (registryClientId == null) {
        final Properties createRegClientProps = new Properties();
        createRegClientProps.setProperty(CommandOption.REGISTRY_CLIENT_NAME.getLongName(), REG_CLIENT_NAME);
        createRegClientProps.setProperty(CommandOption.REGISTRY_CLIENT_DESC.getLongName(), REG_CLIENT_DESC + new Date().toString());
        createRegClientProps.setProperty(CommandOption.REGISTRY_CLIENT_URL.getLongName(), registryClientBaseUrl);
        final StringResult createdRegClient = createRegistryClient.doExecute(nifiClient, createRegClientProps);
        registryClientId = createdRegClient.getResult();
        if (isInteractive) {
            println();
            println("Created new registry client '" + REG_CLIENT_NAME + "'...");
        }
    }
    return registryClientId;
}
Also used : RegistryClientIDResult(org.apache.nifi.toolkit.cli.impl.result.RegistryClientIDResult) StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) Properties(java.util.Properties) NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) IOException(java.io.IOException) MissingOptionException(org.apache.commons.cli.MissingOptionException) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) ParseException(org.apache.commons.cli.ParseException) Date(java.util.Date)

Example 2 with RegistryClientIDResult

use of org.apache.nifi.toolkit.cli.impl.result.RegistryClientIDResult 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)

Aggregations

IOException (java.io.IOException)2 Properties (java.util.Properties)2 NiFiClientException (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException)2 RegistryClientIDResult (org.apache.nifi.toolkit.cli.impl.result.RegistryClientIDResult)2 Date (java.util.Date)1 MissingOptionException (org.apache.commons.cli.MissingOptionException)1 ParseException (org.apache.commons.cli.ParseException)1 StringUtils (org.apache.commons.lang3.StringUtils)1 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)1 CommandException (org.apache.nifi.toolkit.cli.api.CommandException)1 Context (org.apache.nifi.toolkit.cli.api.Context)1 NiFiClient (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient)1 CommandOption (org.apache.nifi.toolkit.cli.impl.command.CommandOption)1 AbstractNiFiCommand (org.apache.nifi.toolkit.cli.impl.command.nifi.AbstractNiFiCommand)1 StringResult (org.apache.nifi.toolkit.cli.impl.result.StringResult)1 RegistryDTO (org.apache.nifi.web.api.dto.RegistryDTO)1 RegistryClientsEntity (org.apache.nifi.web.api.entity.RegistryClientsEntity)1