Java Code Examples for org.apache.nifi.web.api.dto.ProcessorDTO#setType()
The following examples show how to use
org.apache.nifi.web.api.dto.ProcessorDTO#setType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NiFiClientUtil.java From nifi with Apache License 2.0 | 6 votes |
public ProcessorEntity createProcessor(final String type, final String processGroupId, final String bundleGroupId, final String artifactId, final String version) throws NiFiClientException, IOException { final ProcessorDTO dto = new ProcessorDTO(); dto.setType(type); final BundleDTO bundle = new BundleDTO(); bundle.setGroup(bundleGroupId); bundle.setArtifact(artifactId); bundle.setVersion(version); dto.setBundle(bundle); final ProcessorEntity entity = new ProcessorEntity(); entity.setComponent(dto); entity.setRevision(createNewRevision()); return nifiClient.getProcessorClient().createProcessor(processGroupId, entity); }
Example 2
Source File: AbstractAnonymousUserTest.java From nifi with Apache License 2.0 | 6 votes |
/** * Attempt to create a processor anonymously. * * @throws Exception ex */ protected Response testCreateProcessor(final String baseUrl, final NiFiTestUser niFiTestUser) throws Exception { final String url = baseUrl + "/process-groups/root/processors"; // create the processor final ProcessorDTO processor = new ProcessorDTO(); processor.setName("Copy"); processor.setType(SourceTestProcessor.class.getName()); // create the revision final RevisionDTO revision = new RevisionDTO(); revision.setClientId(CLIENT_ID); revision.setVersion(0l); // create the entity body final ProcessorEntity entity = new ProcessorEntity(); entity.setRevision(revision); entity.setComponent(processor); // perform the request return niFiTestUser.testPost(url, entity); }
Example 3
Source File: ITProcessorAccessControl.java From nifi with Apache License 2.0 | 5 votes |
private void createExecuteCodeRestrictedProcessor(final NiFiTestUser user) throws Exception { String url = helper.getBaseUrl() + "/process-groups/root/processors"; // create the processor ProcessorDTO processor = new ProcessorDTO(); processor.setName("execute code restricted"); processor.setType(ExecuteCodeRestrictedProcessor.class.getName()); // create the revision final RevisionDTO revision = new RevisionDTO(); revision.setClientId(READ_WRITE_CLIENT_ID); revision.setVersion(0L); // create the entity body ProcessorEntity entity = new ProcessorEntity(); entity.setRevision(revision); entity.setComponent(processor); // perform the request as a user with read/write but no restricted access Response response = helper.getReadWriteUser().testPost(url, entity); // ensure the request is successful assertEquals(403, response.getStatus()); // perform the request as a user with read/write and restricted access response = user.testPost(url, entity); // ensure the request is successful assertEquals(201, response.getStatus()); final ProcessorEntity responseEntity = response.readEntity(ProcessorEntity.class); // remove the restricted component deleteRestrictedComponent(responseEntity, user); }
Example 4
Source File: ITAccessTokenEndpoint.java From nifi with Apache License 2.0 | 5 votes |
private ProcessorDTO createProcessor(final String token) throws Exception { String url = helper.getBaseUrl() + "/process-groups/root/processors"; // authorization header Map<String, String> headers = new HashMap<>(); headers.put("Authorization", "Bearer " + token); // create the processor ProcessorDTO processor = new ProcessorDTO(); processor.setName("Copy"); processor.setType(SourceTestProcessor.class.getName()); // create the revision final RevisionDTO revision = new RevisionDTO(); revision.setClientId(CLIENT_ID); revision.setVersion(0l); // create the entity body ProcessorEntity entity = new ProcessorEntity(); entity.setRevision(revision); entity.setComponent(processor); // perform the request Response response = helper.getUser().testPostWithHeaders(url, entity, headers); // ensure the request is successful Assert.assertEquals(201, response.getStatus()); // get the entity body entity = response.readEntity(ProcessorEntity.class); // verify creation processor = entity.getComponent(); Assert.assertEquals("Copy", processor.getName()); Assert.assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType()); return processor; }
Example 5
Source File: ITProcessorAccessControl.java From nifi with Apache License 2.0 | 5 votes |
public static ProcessorEntity createProcessor(final AccessControlHelper ach, final String name) throws Exception { String url = ach.getBaseUrl() + "/process-groups/root/processors"; // create the processor ProcessorDTO processor = new ProcessorDTO(); processor.setName(name); processor.setType(SourceTestProcessor.class.getName()); // create the revision final RevisionDTO revision = new RevisionDTO(); revision.setClientId(READ_WRITE_CLIENT_ID); revision.setVersion(0L); // create the entity body ProcessorEntity entity = new ProcessorEntity(); entity.setRevision(revision); entity.setComponent(processor); // perform the request Response response = ach.getReadWriteUser().testPost(url, entity); // ensure the request is successful assertEquals(201, response.getStatus()); // get the entity body entity = response.readEntity(ProcessorEntity.class); // verify creation processor = entity.getComponent(); assertEquals(name, processor.getName()); assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType()); // get the processor return entity; }
Example 6
Source File: ITProcessorAccessControl.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Tests attempt to create a restricted processor. * * @throws Exception if there is an error creating this processor */ @Test public void testCreateRestrictedProcessor() throws Exception { String url = helper.getBaseUrl() + "/process-groups/root/processors"; // create the processor ProcessorDTO processor = new ProcessorDTO(); processor.setName("restricted"); processor.setType(RestrictedProcessor.class.getName()); // create the revision final RevisionDTO revision = new RevisionDTO(); revision.setClientId(READ_WRITE_CLIENT_ID); revision.setVersion(0L); // create the entity body ProcessorEntity entity = new ProcessorEntity(); entity.setRevision(revision); entity.setComponent(processor); // perform the request as a user with read/write but no restricted access ClientResponse response = helper.getReadWriteUser().testPost(url, entity); // ensure the request is successful assertEquals(403, response.getStatus()); // perform the request as a user with read/write and restricted access response = helper.getPrivilegedUser().testPost(url, entity); // ensure the request is successful assertEquals(201, response.getStatus()); final ProcessorEntity responseEntity = response.getEntity(ProcessorEntity.class); // remove the restricted component deleteRestrictedComponent(responseEntity); }
Example 7
Source File: ProcessorSchemaTest.java From nifi-minifi with Apache License 2.0 | 5 votes |
@Before public void setup() { config = new ProcessorConfigDTO(); RelationshipDTO relationshipDTO = new RelationshipDTO(); relationshipDTO.setName(testRelationship); relationshipDTO.setAutoTerminate(true); dto = new ProcessorDTO(); dto.setConfig(config); dto.setName(testName); dto.setId(testId); dto.setType(testProcessorClass); config.setSchedulingStrategy(testSchedulingStrategy); config.setSchedulingPeriod(testSchedulingPeriod); config.setConcurrentlySchedulableTaskCount(testMaxConcurrentTasks); config.setPenaltyDuration(testPenalizationPeriod); config.setYieldDuration(testYieldDuration); config.setRunDurationMillis(testRunDurationNanos / 1000); config.setAnnotationData(testAnnotationData); dto.setRelationships(Arrays.asList(relationshipDTO)); Map<String, String> properties = new HashMap<>(); properties.put(testKey, testValue); config.setProperties(properties); map = new HashMap<>(); map.put(CommonPropertyKeys.NAME_KEY, testName); map.put(CommonPropertyKeys.ID_KEY, testId); map.put(CLASS_KEY, testProcessorClass); map.put(CommonPropertyKeys.SCHEDULING_STRATEGY_KEY, testSchedulingStrategy); map.put(CommonPropertyKeys.SCHEDULING_PERIOD_KEY, testSchedulingPeriod); map.put(CommonPropertyKeys.MAX_CONCURRENT_TASKS_KEY, testMaxConcurrentTasks); map.put(ProcessorSchema.PENALIZATION_PERIOD_KEY, testPenalizationPeriod); map.put(CommonPropertyKeys.YIELD_PERIOD_KEY, testYieldDuration); map.put(ProcessorSchema.RUN_DURATION_NANOS_KEY, testRunDurationNanos); map.put(ProcessorSchema.AUTO_TERMINATED_RELATIONSHIPS_LIST_KEY, Arrays.asList(testRelationship)); map.put(PROPERTIES_KEY, new HashMap<>(properties)); map.put(ANNOTATION_DATA_KEY, testAnnotationData); }
Example 8
Source File: ITAccessTokenEndpoint.java From localization_nifi with Apache License 2.0 | 5 votes |
private ProcessorDTO createProcessor(final String token) throws Exception { String url = BASE_URL + "/process-groups/root/processors"; // authorization header Map<String, String> headers = new HashMap<>(); headers.put("Authorization", "Bearer " + token); // create the processor ProcessorDTO processor = new ProcessorDTO(); processor.setName("Copy"); processor.setType(SourceTestProcessor.class.getName()); // create the revision final RevisionDTO revision = new RevisionDTO(); revision.setClientId(CLIENT_ID); revision.setVersion(0l); // create the entity body ProcessorEntity entity = new ProcessorEntity(); entity.setRevision(revision); entity.setComponent(processor); // perform the request ClientResponse response = TOKEN_USER.testPostWithHeaders(url, entity, headers); // ensure the request is successful Assert.assertEquals(201, response.getStatus()); // get the entity body entity = response.getEntity(ProcessorEntity.class); // verify creation processor = entity.getComponent(); Assert.assertEquals("Copy", processor.getName()); Assert.assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType()); return processor; }
Example 9
Source File: ITProcessorAccessControl.java From localization_nifi with Apache License 2.0 | 5 votes |
public static ProcessorEntity createProcessor(final AccessControlHelper ach, final String name) throws Exception { String url = ach.getBaseUrl() + "/process-groups/root/processors"; // create the processor ProcessorDTO processor = new ProcessorDTO(); processor.setName(name); processor.setType(SourceTestProcessor.class.getName()); // create the revision final RevisionDTO revision = new RevisionDTO(); revision.setClientId(READ_WRITE_CLIENT_ID); revision.setVersion(0L); // create the entity body ProcessorEntity entity = new ProcessorEntity(); entity.setRevision(revision); entity.setComponent(processor); // perform the request ClientResponse response = ach.getReadWriteUser().testPost(url, entity); // ensure the request is successful assertEquals(201, response.getStatus()); // get the entity body entity = response.getEntity(ProcessorEntity.class); // verify creation processor = entity.getComponent(); assertEquals(name, processor.getName()); assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType()); // get the processor return entity; }
Example 10
Source File: ITProcessorAccessControl.java From nifi with Apache License 2.0 | 4 votes |
/** * Tests attempt to create a restricted processor. * * @throws Exception if there is an error creating this processor */ @Test public void testCreateRestrictedProcessor() throws Exception { String url = helper.getBaseUrl() + "/process-groups/root/processors"; // create the processor ProcessorDTO processor = new ProcessorDTO(); processor.setName("restricted"); processor.setType(RestrictedProcessor.class.getName()); // create the revision final RevisionDTO revision = new RevisionDTO(); revision.setClientId(READ_WRITE_CLIENT_ID); revision.setVersion(0L); // create the entity body ProcessorEntity entity = new ProcessorEntity(); entity.setRevision(revision); entity.setComponent(processor); // perform the request as a user with read/write but no restricted access Response response = helper.getReadWriteUser().testPost(url, entity); // ensure the request is successful assertEquals(403, response.getStatus()); // perform the request as a user with read/write and only execute code restricted access response = helper.getExecuteCodeUser().testPost(url, entity); // ensure the request is successful assertEquals(403, response.getStatus()); // perform the request as a user with read/write and restricted access response = helper.getPrivilegedUser().testPost(url, entity); // ensure the request is successful assertEquals(201, response.getStatus()); final ProcessorEntity responseEntity = response.readEntity(ProcessorEntity.class); // remove the restricted component deleteRestrictedComponent(responseEntity, helper.getPrivilegedUser()); }
Example 11
Source File: FlowFromDOMFactory.java From localization_nifi with Apache License 2.0 | 4 votes |
public static ProcessorDTO getProcessor(final Element element, final StringEncryptor encryptor) { final ProcessorDTO dto = new ProcessorDTO(); dto.setId(getString(element, "id")); dto.setName(getString(element, "name")); dto.setType(getString(element, "class")); dto.setPosition(getPosition(DomUtils.getChild(element, "position"))); dto.setStyle(getStyle(DomUtils.getChild(element, "styles"))); final ProcessorConfigDTO configDto = new ProcessorConfigDTO(); dto.setConfig(configDto); configDto.setComments(getString(element, "comment")); configDto.setConcurrentlySchedulableTaskCount(getInt(element, "maxConcurrentTasks")); final String schedulingPeriod = getString(element, "schedulingPeriod"); configDto.setSchedulingPeriod(schedulingPeriod); configDto.setPenaltyDuration(getString(element, "penalizationPeriod")); configDto.setYieldDuration(getString(element, "yieldPeriod")); configDto.setBulletinLevel(getString(element, "bulletinLevel")); configDto.setLossTolerant(getBoolean(element, "lossTolerant")); final ScheduledState scheduledState = getScheduledState(element); dto.setState(scheduledState.toString()); // handle scheduling strategy final String schedulingStrategyName = getString(element, "schedulingStrategy"); if (schedulingStrategyName == null || schedulingStrategyName.trim().isEmpty()) { configDto.setSchedulingStrategy(SchedulingStrategy.TIMER_DRIVEN.name()); } else { configDto.setSchedulingStrategy(schedulingStrategyName.trim()); } // handle execution node final String executionNode = getString(element, "executionNode"); if (executionNode == null || executionNode.trim().isEmpty()) { configDto.setExecutionNode(ExecutionNode.ALL.name()); } else { configDto.setExecutionNode(executionNode.trim()); } final Long runDurationNanos = getOptionalLong(element, "runDurationNanos"); if (runDurationNanos != null) { configDto.setRunDurationMillis(TimeUnit.NANOSECONDS.toMillis(runDurationNanos)); } configDto.setProperties(getProperties(element, encryptor)); configDto.setAnnotationData(getString(element, "annotationData")); final Set<String> autoTerminatedRelationships = new HashSet<>(); final List<Element> autoTerminateList = getChildrenByTagName(element, "autoTerminatedRelationship"); for (final Element autoTerminateElement : autoTerminateList) { autoTerminatedRelationships.add(autoTerminateElement.getTextContent()); } configDto.setAutoTerminatedRelationships(autoTerminatedRelationships); return dto; }
Example 12
Source File: ITProcessorAccessControl.java From nifi with Apache License 2.0 | 4 votes |
private Tuple<ProcessorEntity, SnippetEntity> createSnippetWithRestrictedComponent(final String restrictedClassName, final NiFiTestUser user) throws Exception { final String processorUrl = helper.getBaseUrl() + "/process-groups/root/processors"; final String snippetUrl = helper.getBaseUrl() + "/snippets"; // create the processor ProcessorDTO processor = new ProcessorDTO(); processor.setName("restricted"); processor.setType(restrictedClassName); // create the revision final RevisionDTO revision = new RevisionDTO(); revision.setClientId(READ_WRITE_CLIENT_ID); revision.setVersion(0L); // create the entity body ProcessorEntity entity = new ProcessorEntity(); entity.setRevision(revision); entity.setComponent(processor); // perform the request as a user with read/write and restricted access Response response = user.testPost(processorUrl, entity); // ensure the request is successful assertEquals(201, response.getStatus()); // get the response final ProcessorEntity responseProcessorEntity = response.readEntity(ProcessorEntity.class); // build the snippet for the copy/paste final SnippetDTO snippet = new SnippetDTO(); snippet.setParentGroupId(responseProcessorEntity.getComponent().getParentGroupId()); snippet.getProcessors().put(responseProcessorEntity.getId(), responseProcessorEntity.getRevision()); // create the entity body final SnippetEntity snippetEntity = new SnippetEntity(); snippetEntity.setSnippet(snippet); // create the snippet response = helper.getNoneUser().testPost(snippetUrl, snippetEntity); // ensure the request failed... need either read or write to create snippet (not sure what snippet will be used for) assertEquals(403, response.getStatus()); // create the snippet response = helper.getReadWriteUser().testPost(snippetUrl, snippetEntity); // ensure the request is successful assertEquals(201, response.getStatus()); // get the response return new Tuple<>(responseProcessorEntity, response.readEntity(SnippetEntity.class)); }
Example 13
Source File: FlowFromDOMFactory.java From nifi with Apache License 2.0 | 4 votes |
public static ProcessorDTO getProcessor(final Element element, final StringEncryptor encryptor, final FlowEncodingVersion flowEncodingVersion) { final ProcessorDTO dto = new ProcessorDTO(); dto.setId(getString(element, "id")); dto.setVersionedComponentId(getString(element, "versionedComponentId")); dto.setName(getString(element, "name")); dto.setType(getString(element, "class")); dto.setBundle(getBundle(DomUtils.getChild(element, "bundle"))); dto.setPosition(getPosition(DomUtils.getChild(element, "position"))); dto.setStyle(getStyle(DomUtils.getChild(element, "styles"))); final ProcessorConfigDTO configDto = new ProcessorConfigDTO(); dto.setConfig(configDto); configDto.setComments(getString(element, "comment")); configDto.setConcurrentlySchedulableTaskCount(getInt(element, "maxConcurrentTasks")); final String schedulingPeriod = getString(element, "schedulingPeriod"); configDto.setSchedulingPeriod(schedulingPeriod); configDto.setPenaltyDuration(getString(element, "penalizationPeriod")); configDto.setYieldDuration(getString(element, "yieldPeriod")); configDto.setBulletinLevel(getString(element, "bulletinLevel")); configDto.setLossTolerant(getBoolean(element, "lossTolerant")); final ScheduledState scheduledState = getScheduledState(element); dto.setState(scheduledState.toString()); // handle scheduling strategy final String schedulingStrategyName = getString(element, "schedulingStrategy"); if (schedulingStrategyName == null || schedulingStrategyName.trim().isEmpty()) { configDto.setSchedulingStrategy(SchedulingStrategy.TIMER_DRIVEN.name()); } else { configDto.setSchedulingStrategy(schedulingStrategyName.trim()); } // handle execution node final String executionNode = getString(element, "executionNode"); if (executionNode == null || executionNode.trim().isEmpty()) { configDto.setExecutionNode(ExecutionNode.ALL.name()); } else { configDto.setExecutionNode(executionNode.trim()); } final Long runDurationNanos = getOptionalLong(element, "runDurationNanos"); if (runDurationNanos != null) { configDto.setRunDurationMillis(TimeUnit.NANOSECONDS.toMillis(runDurationNanos)); } configDto.setProperties(getProperties(element, encryptor, flowEncodingVersion)); configDto.setAnnotationData(getString(element, "annotationData")); final Set<String> autoTerminatedRelationships = new HashSet<>(); final List<Element> autoTerminateList = getChildrenByTagName(element, "autoTerminatedRelationship"); for (final Element autoTerminateElement : autoTerminateList) { autoTerminatedRelationships.add(autoTerminateElement.getTextContent()); } configDto.setAutoTerminatedRelationships(autoTerminatedRelationships); return dto; }
Example 14
Source File: TestFlowController.java From nifi with Apache License 2.0 | 4 votes |
@Test(expected = IllegalArgumentException.class) public void testInstantiateSnippetWhenProcessorMissingBundle() throws Exception { final String id = UUID.randomUUID().toString(); final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate(); final ProcessorNode processorNode = controller.getFlowManager().createProcessor(DummyProcessor.class.getName(), id, coordinate); // create a processor dto final ProcessorDTO processorDTO = new ProcessorDTO(); processorDTO.setId(UUID.randomUUID().toString()); // use a different id here processorDTO.setPosition(new PositionDTO(new Double(0), new Double(0))); processorDTO.setStyle(processorNode.getStyle()); processorDTO.setParentGroupId("1234"); processorDTO.setInputRequirement(processorNode.getInputRequirement().name()); processorDTO.setPersistsState(processorNode.getProcessor().getClass().isAnnotationPresent(Stateful.class)); processorDTO.setRestricted(processorNode.isRestricted()); processorDTO.setExecutionNodeRestricted(processorNode.isExecutionNodeRestricted()); processorDTO.setExtensionMissing(processorNode.isExtensionMissing()); processorDTO.setType(processorNode.getCanonicalClassName()); processorDTO.setBundle(null); // missing bundle processorDTO.setName(processorNode.getName()); processorDTO.setState(processorNode.getScheduledState().toString()); processorDTO.setRelationships(new ArrayList<>()); processorDTO.setDescription("description"); processorDTO.setSupportsParallelProcessing(!processorNode.isTriggeredSerially()); processorDTO.setSupportsEventDriven(processorNode.isEventDrivenSupported()); processorDTO.setSupportsBatching(processorNode.isSessionBatchingSupported()); ProcessorConfigDTO configDTO = new ProcessorConfigDTO(); configDTO.setSchedulingPeriod(processorNode.getSchedulingPeriod()); configDTO.setPenaltyDuration(processorNode.getPenalizationPeriod()); configDTO.setYieldDuration(processorNode.getYieldPeriod()); configDTO.setRunDurationMillis(processorNode.getRunDuration(TimeUnit.MILLISECONDS)); configDTO.setConcurrentlySchedulableTaskCount(processorNode.getMaxConcurrentTasks()); configDTO.setLossTolerant(processorNode.isLossTolerant()); configDTO.setComments(processorNode.getComments()); configDTO.setBulletinLevel(processorNode.getBulletinLevel().name()); configDTO.setSchedulingStrategy(processorNode.getSchedulingStrategy().name()); configDTO.setExecutionNode(processorNode.getExecutionNode().name()); configDTO.setAnnotationData(processorNode.getAnnotationData()); processorDTO.setConfig(configDTO); // create the snippet with the processor final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO(); flowSnippetDTO.setProcessors(Collections.singleton(processorDTO)); // instantiate the snippet assertEquals(0, controller.getFlowManager().getRootGroup().getProcessors().size()); controller.getFlowManager().instantiateSnippet(controller.getFlowManager().getRootGroup(), flowSnippetDTO); }
Example 15
Source File: TestFlowController.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testInstantiateSnippetWithProcessor() throws ProcessorInstantiationException { final String id = UUID.randomUUID().toString(); final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate(); final ProcessorNode processorNode = controller.getFlowManager().createProcessor(DummyProcessor.class.getName(), id, coordinate); // create a processor dto final ProcessorDTO processorDTO = new ProcessorDTO(); processorDTO.setId(UUID.randomUUID().toString()); // use a different id here processorDTO.setPosition(new PositionDTO(new Double(0), new Double(0))); processorDTO.setStyle(processorNode.getStyle()); processorDTO.setParentGroupId("1234"); processorDTO.setInputRequirement(processorNode.getInputRequirement().name()); processorDTO.setPersistsState(processorNode.getProcessor().getClass().isAnnotationPresent(Stateful.class)); processorDTO.setRestricted(processorNode.isRestricted()); processorDTO.setExecutionNodeRestricted(processorNode.isExecutionNodeRestricted()); processorDTO.setExtensionMissing(processorNode.isExtensionMissing()); processorDTO.setType(processorNode.getCanonicalClassName()); processorDTO.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion())); processorDTO.setName(processorNode.getName()); processorDTO.setState(processorNode.getScheduledState().toString()); processorDTO.setRelationships(new ArrayList<>()); processorDTO.setDescription("description"); processorDTO.setSupportsParallelProcessing(!processorNode.isTriggeredSerially()); processorDTO.setSupportsEventDriven(processorNode.isEventDrivenSupported()); processorDTO.setSupportsBatching(processorNode.isSessionBatchingSupported()); ProcessorConfigDTO configDTO = new ProcessorConfigDTO(); configDTO.setSchedulingPeriod(processorNode.getSchedulingPeriod()); configDTO.setPenaltyDuration(processorNode.getPenalizationPeriod()); configDTO.setYieldDuration(processorNode.getYieldPeriod()); configDTO.setRunDurationMillis(processorNode.getRunDuration(TimeUnit.MILLISECONDS)); configDTO.setConcurrentlySchedulableTaskCount(processorNode.getMaxConcurrentTasks()); configDTO.setLossTolerant(processorNode.isLossTolerant()); configDTO.setComments(processorNode.getComments()); configDTO.setBulletinLevel(processorNode.getBulletinLevel().name()); configDTO.setSchedulingStrategy(processorNode.getSchedulingStrategy().name()); configDTO.setExecutionNode(processorNode.getExecutionNode().name()); configDTO.setAnnotationData(processorNode.getAnnotationData()); processorDTO.setConfig(configDTO); // create the snippet with the processor final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO(); flowSnippetDTO.setProcessors(Collections.singleton(processorDTO)); // instantiate the snippet assertEquals(0, controller.getFlowManager().getRootGroup().getProcessors().size()); controller.getFlowManager().instantiateSnippet(controller.getFlowManager().getRootGroup(), flowSnippetDTO); assertEquals(1, controller.getFlowManager().getRootGroup().getProcessors().size()); }
Example 16
Source File: TestFlowController.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testInstantiateSnippetWithDisabledProcessor() throws ProcessorInstantiationException { final String id = UUID.randomUUID().toString(); final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate(); final ProcessorNode processorNode = controller.getFlowManager().createProcessor(DummyProcessor.class.getName(), id, coordinate); processorNode.disable(); // create a processor dto final ProcessorDTO processorDTO = new ProcessorDTO(); processorDTO.setId(UUID.randomUUID().toString()); // use a different id here processorDTO.setPosition(new PositionDTO(new Double(0), new Double(0))); processorDTO.setStyle(processorNode.getStyle()); processorDTO.setParentGroupId("1234"); processorDTO.setInputRequirement(processorNode.getInputRequirement().name()); processorDTO.setPersistsState(processorNode.getProcessor().getClass().isAnnotationPresent(Stateful.class)); processorDTO.setRestricted(processorNode.isRestricted()); processorDTO.setExecutionNodeRestricted(processorNode.isExecutionNodeRestricted()); processorDTO.setExtensionMissing(processorNode.isExtensionMissing()); processorDTO.setType(processorNode.getCanonicalClassName()); processorDTO.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion())); processorDTO.setName(processorNode.getName()); processorDTO.setState(processorNode.getScheduledState().toString()); processorDTO.setRelationships(new ArrayList<>()); processorDTO.setDescription("description"); processorDTO.setSupportsParallelProcessing(!processorNode.isTriggeredSerially()); processorDTO.setSupportsEventDriven(processorNode.isEventDrivenSupported()); processorDTO.setSupportsBatching(processorNode.isSessionBatchingSupported()); ProcessorConfigDTO configDTO = new ProcessorConfigDTO(); configDTO.setSchedulingPeriod(processorNode.getSchedulingPeriod()); configDTO.setPenaltyDuration(processorNode.getPenalizationPeriod()); configDTO.setYieldDuration(processorNode.getYieldPeriod()); configDTO.setRunDurationMillis(processorNode.getRunDuration(TimeUnit.MILLISECONDS)); configDTO.setConcurrentlySchedulableTaskCount(processorNode.getMaxConcurrentTasks()); configDTO.setLossTolerant(processorNode.isLossTolerant()); configDTO.setComments(processorNode.getComments()); configDTO.setBulletinLevel(processorNode.getBulletinLevel().name()); configDTO.setSchedulingStrategy(processorNode.getSchedulingStrategy().name()); configDTO.setExecutionNode(processorNode.getExecutionNode().name()); configDTO.setAnnotationData(processorNode.getAnnotationData()); processorDTO.setConfig(configDTO); // create the snippet with the processor final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO(); flowSnippetDTO.setProcessors(Collections.singleton(processorDTO)); // instantiate the snippet assertEquals(0, controller.getFlowManager().getRootGroup().getProcessors().size()); controller.getFlowManager().instantiateSnippet(controller.getFlowManager().getRootGroup(), flowSnippetDTO); assertEquals(1, controller.getFlowManager().getRootGroup().getProcessors().size()); assertTrue(controller.getFlowManager().getRootGroup().getProcessors().iterator().next().getScheduledState().equals(ScheduledState.DISABLED)); }
Example 17
Source File: ITProcessorAccessControl.java From localization_nifi with Apache License 2.0 | 4 votes |
private Tuple<ProcessorEntity, SnippetEntity> createSnippetWithRestrictedComponent() throws Exception { final String processorUrl = helper.getBaseUrl() + "/process-groups/root/processors"; final String snippetUrl = helper.getBaseUrl() + "/snippets"; // create the processor ProcessorDTO processor = new ProcessorDTO(); processor.setName("restricted"); processor.setType(RestrictedProcessor.class.getName()); // create the revision final RevisionDTO revision = new RevisionDTO(); revision.setClientId(READ_WRITE_CLIENT_ID); revision.setVersion(0L); // create the entity body ProcessorEntity entity = new ProcessorEntity(); entity.setRevision(revision); entity.setComponent(processor); // perform the request as a user with read/write and restricted access ClientResponse response = helper.getPrivilegedUser().testPost(processorUrl, entity); // ensure the request is successful assertEquals(201, response.getStatus()); // get the response final ProcessorEntity responseProcessorEntity = response.getEntity(ProcessorEntity.class); // build the snippet for the copy/paste final SnippetDTO snippet = new SnippetDTO(); snippet.setParentGroupId(responseProcessorEntity.getComponent().getParentGroupId()); snippet.getProcessors().put(responseProcessorEntity.getId(), responseProcessorEntity.getRevision()); // create the entity body final SnippetEntity snippetEntity = new SnippetEntity(); snippetEntity.setSnippet(snippet); // create the snippet response = helper.getNoneUser().testPost(snippetUrl, snippetEntity); // ensure the request failed... need either read or write to create snippet (not sure what snippet will be used for) assertEquals(403, response.getStatus()); // create the snippet response = helper.getReadWriteUser().testPost(snippetUrl, snippetEntity); // ensure the request is successful assertEquals(201, response.getStatus()); // get the response return new Tuple<>(responseProcessorEntity, response.getEntity(SnippetEntity.class)); }