use of org.apache.nifi.web.api.dto.ProcessorConfigDTO in project kylo by Teradata.
the class AbstractNiFiProcessorsRestClient method createConfig.
private ProcessorConfigDTO createConfig(String schedStrategy, String schedPeriod) {
ProcessorConfigDTO config = new ProcessorConfigDTO();
config.setSchedulingStrategy(schedStrategy);
config.setSchedulingPeriod(schedPeriod);
return config;
}
use of org.apache.nifi.web.api.dto.ProcessorConfigDTO in project kylo by Teradata.
the class NifiConnectionOrderVisitor method getRemoteProcessGroupAsVisitableProcessor.
private NifiVisitableProcessor getRemoteProcessGroupAsVisitableProcessor(String processGroupId, String parentGroupId) {
NifiVisitableProcessor processor = visitedProcessors.get(processGroupId);
if (processor == null) {
ProcessorDTO processorDTO = processorsMap.get(processGroupId);
if (processorDTO == null) {
RemoteProcessGroupDTO remoteProcessGroupDTO = getRemoteGroup(processGroupId);
if (remoteProcessGroupDTO != null) {
processorDTO = new ProcessorDTO();
processorDTO.setType("NiFi.RemoteProcessGroup");
processorDTO.setId(processGroupId);
processorDTO.setParentGroupId(parentGroupId);
processorDTO.setName(remoteProcessGroupDTO.getName());
processorDTO.setConfig(new ProcessorConfigDTO());
processorsMap.put(processGroupId, processorDTO);
}
}
if (processorDTO != null) {
processor = new NifiVisitableProcessor(processorDTO);
}
}
return processor;
}
use of org.apache.nifi.web.api.dto.ProcessorConfigDTO in project kylo by Teradata.
the class TemplateCreationHelperTest method updateControllerServiceReferencesWithRecursive.
/**
* Verify recursively enabling controller services when updating processor properties.
*/
@Test
public void updateControllerServiceReferencesWithRecursive() {
final List<ControllerServiceDTO> updatedControllerServices = new ArrayList<>();
final List<NifiProperty> updatedProperties = new ArrayList<>();
// Mock NiFi client
final NiFiControllerServicesRestClient controllerServicesRestClient = Mockito.mock(NiFiControllerServicesRestClient.class);
Mockito.when(controllerServicesRestClient.update(Mockito.any())).thenAnswer(answer -> {
final ControllerServiceDTO controllerService = answer.getArgumentAt(0, ControllerServiceDTO.class);
updatedControllerServices.add(controllerService);
return controllerService;
});
final NiFiRestClient restClient = Mockito.mock(NiFiRestClient.class);
Mockito.when(restClient.controllerServices()).thenReturn(controllerServicesRestClient);
// Mock Legacy NiFi client
final LegacyNifiRestClient legacyRestClient = Mockito.mock(LegacyNifiRestClient.class);
Mockito.when(legacyRestClient.enableControllerServiceAndSetProperties(Mockito.any(), Mockito.any())).thenReturn(new ControllerServiceDTO());
Mockito.when(legacyRestClient.getNiFiRestClient()).thenReturn(restClient);
Mockito.when(legacyRestClient.getPropertyDescriptorTransform()).thenReturn(new MockNiFiPropertyDescriptorTransform());
Mockito.doAnswer(invocation -> {
updatedProperties.add(invocation.getArgumentAt(2, NifiProperty.class));
return null;
}).when(legacyRestClient).updateProcessorProperty(Mockito.isNull(String.class), Mockito.eq("P1"), Mockito.any());
final ControllerServiceDTO service1 = new ControllerServiceDTO();
service1.setDescriptors(Collections.singletonMap("service", newPropertyDescriptor("service", "com.example.Service2", "S2")));
service1.setId("S1");
service1.setName("Service1");
service1.setProperties(newHashMap("service", "invalid"));
service1.setState("DISABLED");
final ControllerServiceDTO service2 = new ControllerServiceDTO();
service2.setId("S2");
service2.setName("Service2");
service2.setProperties(new HashMap<>());
service2.setState("ENABLED");
Mockito.when(legacyRestClient.getControllerServices()).thenReturn(ImmutableSet.of(service1, service2));
// Mock processors
final ProcessorConfigDTO config = new ProcessorConfigDTO();
config.setDescriptors(Collections.singletonMap("service", newPropertyDescriptor("service", "com.example.Service1", "S1")));
config.setProperties(Collections.singletonMap("service", "invalid"));
final ProcessorDTO processor = new ProcessorDTO();
processor.setId("P1");
processor.setName("Processor1");
processor.setConfig(config);
// Update processors
final TemplateCreationHelper helper = new TemplateCreationHelper(legacyRestClient);
helper.snapshotControllerServiceReferences();
helper.identifyNewlyCreatedControllerServiceReferences();
helper.updateControllerServiceReferences(Collections.singletonList(processor));
// Verify updated properties
Assert.assertEquals("Property 'Service' not set on controller service 'Server1'.", 1, updatedControllerServices.size());
Assert.assertEquals("S2", updatedControllerServices.get(0).getProperties().get("service"));
Assert.assertEquals("Property 'Service' not set on processor 'Processor1'.", 1, updatedProperties.size());
Assert.assertEquals("S1", updatedProperties.get(0).getValue());
}
use of org.apache.nifi.web.api.dto.ProcessorConfigDTO in project nifi by apache.
the class ProcessGroupResource method createProcessor.
// ----------
// processors
// ----------
/**
* Creates a new processor.
*
* @param httpServletRequest request
* @param groupId The group id
* @param requestProcessorEntity A processorEntity.
* @return A processorEntity.
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/processors")
@ApiOperation(value = "Creates a new processor", response = ProcessorEntity.class, authorizations = { @Authorization(value = "Write - /process-groups/{uuid}"), @Authorization(value = "Read - any referenced Controller Services - /controller-services/{uuid}"), @Authorization(value = "Write - if the Processor is restricted - /restricted-components") })
@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 createProcessor(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId, @ApiParam(value = "The processor configuration details.", required = true) final ProcessorEntity requestProcessorEntity) {
if (requestProcessorEntity == null || requestProcessorEntity.getComponent() == null) {
throw new IllegalArgumentException("Processor details must be specified.");
}
if (requestProcessorEntity.getRevision() == null || (requestProcessorEntity.getRevision().getVersion() == null || requestProcessorEntity.getRevision().getVersion() != 0)) {
throw new IllegalArgumentException("A revision of 0 must be specified when creating a new Processor.");
}
final ProcessorDTO requestProcessor = requestProcessorEntity.getComponent();
if (requestProcessor.getId() != null) {
throw new IllegalArgumentException("Processor ID cannot be specified.");
}
if (StringUtils.isBlank(requestProcessor.getType())) {
throw new IllegalArgumentException("The type of processor to create must be specified.");
}
final PositionDTO proposedPosition = requestProcessor.getPosition();
if (proposedPosition != null) {
if (proposedPosition.getX() == null || proposedPosition.getY() == null) {
throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified.");
}
}
if (requestProcessor.getParentGroupId() != null && !groupId.equals(requestProcessor.getParentGroupId())) {
throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestProcessor.getParentGroupId(), groupId));
}
requestProcessor.setParentGroupId(groupId);
if (isReplicateRequest()) {
return replicate(HttpMethod.POST, requestProcessorEntity);
}
return withWriteLock(serviceFacade, requestProcessorEntity, lookup -> {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
final Authorizable processGroup = lookup.getProcessGroup(groupId).getAuthorizable();
processGroup.authorize(authorizer, RequestAction.WRITE, user);
ComponentAuthorizable authorizable = null;
try {
authorizable = lookup.getConfigurableComponent(requestProcessor.getType(), requestProcessor.getBundle());
if (authorizable.isRestricted()) {
authorizeRestrictions(authorizer, authorizable);
}
final ProcessorConfigDTO config = requestProcessor.getConfig();
if (config != null && config.getProperties() != null) {
AuthorizeControllerServiceReference.authorizeControllerServiceReferences(config.getProperties(), authorizable, authorizer, lookup);
}
} finally {
if (authorizable != null) {
authorizable.cleanUpResources();
}
}
}, () -> serviceFacade.verifyCreateProcessor(requestProcessor), processorEntity -> {
final ProcessorDTO processor = processorEntity.getComponent();
// set the processor id as appropriate
processor.setId(generateUuid());
// create the new processor
final Revision revision = getRevision(processorEntity, processor.getId());
final ProcessorEntity entity = serviceFacade.createProcessor(revision, groupId, processor);
processorResource.populateRemainingProcessorEntityContent(entity);
// generate a 201 created response
String uri = entity.getUri();
return generateCreatedResponse(URI.create(uri), entity).build();
});
}
use of org.apache.nifi.web.api.dto.ProcessorConfigDTO in project nifi by apache.
the class ProcessorResource method populateRemainingProcessorContent.
/**
* Populate the uri's for the specified processor and its relationships.
*/
public ProcessorDTO populateRemainingProcessorContent(ProcessorDTO processor) {
// get the config details and see if there is a custom ui for this processor type
ProcessorConfigDTO config = processor.getConfig();
if (config != null) {
// consider legacy custom ui fist
String customUiUrl = servletContext.getInitParameter(processor.getType());
if (StringUtils.isNotBlank(customUiUrl)) {
config.setCustomUiUrl(customUiUrl);
} else {
final BundleDTO bundle = processor.getBundle();
// see if this processor has any ui extensions
final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions");
if (uiExtensionMapping.hasUiExtension(processor.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion())) {
final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(processor.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion());
for (final UiExtension uiExtension : uiExtensions) {
if (UiExtensionType.ProcessorConfiguration.equals(uiExtension.getExtensionType())) {
config.setCustomUiUrl(uiExtension.getContextPath() + "/configure");
}
}
}
}
}
return processor;
}
Aggregations