use of com.thinkbiganalytics.nifi.rest.client.NiFiControllerServicesRestClient 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());
}
Aggregations