use of org.apache.nifi.web.api.entity.RegistryClientsEntity 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.web.api.entity.RegistryClientsEntity 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);
}
}
use of org.apache.nifi.web.api.entity.RegistryClientsEntity in project nifi by apache.
the class TestRegistryClientResult method testWriteSimpleRegistryClientsResult.
@Test
public void testWriteSimpleRegistryClientsResult() throws IOException {
final RegistryDTO r1 = new RegistryDTO();
r1.setName("Registry 1");
r1.setUri("http://thisisalonglonglonglonglonglonglonglonglonguri.com:18080");
r1.setId(UUID.fromString("ea752054-22c6-4fc0-b851-967d9a3837cb").toString());
final RegistryDTO r2 = new RegistryDTO();
r2.setName("Registry 2 with a longer than usual name");
r2.setUri("http://localhost:18080");
r2.setId(UUID.fromString("ddf5f289-7502-46df-9798-4b0457c1816b").toString());
final RegistryClientEntity clientEntity1 = new RegistryClientEntity();
clientEntity1.setId(r1.getId());
clientEntity1.setComponent(r1);
final RegistryClientEntity clientEntity2 = new RegistryClientEntity();
clientEntity2.setId(r2.getId());
clientEntity2.setComponent(r2);
final Set<RegistryClientEntity> clientEntities = new HashSet<>();
clientEntities.add(clientEntity1);
clientEntities.add(clientEntity2);
final RegistryClientsEntity registryClientsEntity = new RegistryClientsEntity();
registryClientsEntity.setRegistries(clientEntities);
final RegistryClientsResult result = new RegistryClientsResult(ResultType.SIMPLE, registryClientsEntity);
result.write(printStream);
final String resultOut = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
// System.out.println(resultOut);
final String expected = "\n" + "# Name Id Uri \n" + "- ------------------------------------ ------------------------------------ --------------------------------------------------------------- \n" + "1 Registry 1 ea752054-22c6-4fc0-b851-967d9a3837cb http://thisisalonglonglonglonglonglonglonglonglonguri.com:18080 \n" + "2 Registry 2 with a longer than usu... ddf5f289-7502-46df-9798-4b0457c1816b http://localhost:18080 \n" + "\n";
Assert.assertEquals(expected, resultOut);
}
use of org.apache.nifi.web.api.entity.RegistryClientsEntity in project nifi by apache.
the class ControllerResource method getRegistryClients.
// ----------
// registries
// ----------
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("registry-clients")
@ApiOperation(value = "Gets the listing of available registry clients", response = RegistryClientsEntity.class, authorizations = { @Authorization(value = "Read - /flow") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response getRegistryClients() {
authorizeController(RequestAction.READ);
if (isReplicateRequest()) {
return replicate(HttpMethod.GET);
}
final Set<RegistryClientEntity> registries = serviceFacade.getRegistryClients();
registries.forEach(registry -> populateRemainingRegistryEntityContent(registry));
final RegistryClientsEntity registryEntities = new RegistryClientsEntity();
registryEntities.setRegistries(registries);
return generateOkResponse(registryEntities).build();
}
Aggregations