use of org.apache.nifi.web.api.entity.RegistryClientEntity in project nifi by apache.
the class ControllerResource method createRegistryClient.
/**
* Creates a new Registry.
*
* @param httpServletRequest request
* @param requestRegistryClientEntity A registryClientEntity.
* @return A registryClientEntity.
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("registry-clients")
@ApiOperation(value = "Creates a new registry client", response = RegistryClientEntity.class, authorizations = { @Authorization(value = "Write - /controller") })
@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 = 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 createRegistryClient(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The registry configuration details.", required = true) final RegistryClientEntity requestRegistryClientEntity) {
if (requestRegistryClientEntity == null || requestRegistryClientEntity.getComponent() == null) {
throw new IllegalArgumentException("Registry details must be specified.");
}
if (requestRegistryClientEntity.getRevision() == null || (requestRegistryClientEntity.getRevision().getVersion() == null || requestRegistryClientEntity.getRevision().getVersion() != 0)) {
throw new IllegalArgumentException("A revision of 0 must be specified when creating a new Registry.");
}
final RegistryDTO requestRegistryClient = requestRegistryClientEntity.getComponent();
if (requestRegistryClient.getId() != null) {
throw new IllegalArgumentException("Registry ID cannot be specified.");
}
if (StringUtils.isBlank(requestRegistryClient.getName())) {
throw new IllegalArgumentException("Registry name must be specified.");
}
if (StringUtils.isBlank(requestRegistryClient.getUri())) {
throw new IllegalArgumentException("Registry URL must be specified.");
}
if (isReplicateRequest()) {
return replicate(HttpMethod.POST, requestRegistryClientEntity);
}
return withWriteLock(serviceFacade, requestRegistryClientEntity, lookup -> {
authorizeController(RequestAction.WRITE);
}, null, (registryEntity) -> {
final RegistryDTO registry = registryEntity.getComponent();
// set the processor id as appropriate
registry.setId(generateUuid());
// create the reporting task and generate the json
final Revision revision = getRevision(registryEntity, registry.getId());
final RegistryClientEntity entity = serviceFacade.createRegistryClient(revision, registry);
populateRemainingRegistryEntityContent(entity);
// build the response
return generateCreatedResponse(URI.create(entity.getUri()), entity).build();
});
}
use of org.apache.nifi.web.api.entity.RegistryClientEntity in project nifi by apache.
the class ControllerResource method getRegistryClient.
/**
* Retrieves the specified registry.
*
* @param id The id of the registry to retrieve
* @return A registryClientEntity.
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("/registry-clients/{id}")
@ApiOperation(value = "Gets a registry client", response = RegistryClientEntity.class, authorizations = { @Authorization(value = "Read - /controller") })
@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 getRegistryClient(@ApiParam(value = "The registry id.", required = true) @PathParam("id") final String id) {
if (isReplicateRequest()) {
return replicate(HttpMethod.GET);
}
// authorize access
authorizeController(RequestAction.READ);
// get the registry
final RegistryClientEntity entity = serviceFacade.getRegistryClient(id);
populateRemainingRegistryEntityContent(entity);
return generateOkResponse(entity).build();
}
use of org.apache.nifi.web.api.entity.RegistryClientEntity in project nifi by apache.
the class EntityFactory method createRegistryClientEntity.
public RegistryClientEntity createRegistryClientEntity(final RegistryDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) {
final RegistryClientEntity entity = new RegistryClientEntity();
entity.setRevision(revision);
entity.setPermissions(permissions);
if (dto != null) {
entity.setId(dto.getId());
if (permissions != null && permissions.getCanRead()) {
entity.setComponent(dto);
}
}
return entity;
}
use of org.apache.nifi.web.api.entity.RegistryClientEntity 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.RegistryClientEntity in project nifi by apache.
the class CreateRegistryClient method doExecute.
@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());
}
Aggregations