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