Search in sources :

Example 1 with RegistryClientsEntity

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());
}
Also used : NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) RegistryClientsEntity(org.apache.nifi.web.api.entity.RegistryClientsEntity) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) FlowClient(org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient) ProcessGroupBox(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupBox) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) ProcessGroupClient(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupClient) MissingOptionException(org.apache.commons.cli.MissingOptionException)

Example 2 with RegistryClientsEntity

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

Example 3 with RegistryClientsEntity

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);
}
Also used : RegistryClientsEntity(org.apache.nifi.web.api.entity.RegistryClientsEntity) RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with RegistryClientsEntity

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();
}
Also used : RegistryClientsEntity(org.apache.nifi.web.api.entity.RegistryClientsEntity) RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

RegistryClientsEntity (org.apache.nifi.web.api.entity.RegistryClientsEntity)4 RegistryClientEntity (org.apache.nifi.web.api.entity.RegistryClientEntity)3 NiFiClientException (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException)2 RegistryDTO (org.apache.nifi.web.api.dto.RegistryDTO)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 MissingOptionException (org.apache.commons.cli.MissingOptionException)1 StringUtils (org.apache.commons.lang3.StringUtils)1 CommandException (org.apache.nifi.toolkit.cli.api.CommandException)1 Context (org.apache.nifi.toolkit.cli.api.Context)1 FlowClient (org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient)1 NiFiClient (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient)1 ProcessGroupBox (org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupBox)1