test_class.declarator: agentClassRepository
test_class.modifier: private
test_class.original_string: private AgentClassRepository agentClassRepository;
test_class.type: AgentClassRepository
test_class.var_name: agentClassRepository
test_class.declarator: flowMapper
test_class.modifier: private
test_class.original_string: private FlowMapper flowMapper;
test_class.type: FlowMapper
test_class.var_name: flowMapper
test_class.declarator: flowRetrievalService
test_class.modifier: private
test_class.original_string: private FlowRetrievalService flowRetrievalService;
test_class.type: FlowRetrievalService
test_class.var_name: flowRetrievalService
test_class.declarator: flowTransformService
test_class.modifier: private
test_class.original_string: private FlowTransformService<ConfigSchema> flowTransformService;
test_class.type: FlowTransformService<ConfigSchema>
test_class.var_name: flowTransformService
test_class.declarator: configSchemaSerializer
test_class.modifier: private
test_class.original_string: private Serializer<ConfigSchema> configSchemaSerializer;
test_class.type: Serializer<ConfigSchema>
test_class.var_name: configSchemaSerializer
test_class.declarator: flowRepository
test_class.modifier: private
test_class.original_string: private FlowRepository flowRepository;
test_class.type: FlowRepository
test_class.var_name: flowRepository
test_class.declarator: flowMappingRepository
test_class.modifier: private
test_class.original_string: private FlowMappingRepository flowMappingRepository;
test_class.type: FlowMappingRepository
test_class.var_name: flowMappingRepository
test_class.declarator: transactionTemplate
test_class.modifier: private
test_class.original_string: private TransactionTemplate transactionTemplate;
test_class.type: TransactionTemplate
test_class.var_name: transactionTemplate
test_class.declarator: flowRefresherTask
test_class.modifier: private
test_class.original_string: private FlowRefresherTask flowRefresherTask;
test_class.type: FlowRefresherTask
test_class.var_name: flowRefresherTask
test_class.file: efm/efm-c2-protocol/efm-c2-protocol-framework/src/test/java/com/cloudera/cem/efm/service/flow/refresh/TestFlowRefresherTask.java
test_class.identifier: TestFlowRefresherTask
test_case.body: @Test
      public void testRefreshWhenRegistryInfoChanged() throws FlowRetrievalException, FlowMapperException, SerializerException, FlowTransformException, IOException {
          final String className = "Test Class";
          final AtomicInteger refreshedCounter = new AtomicInteger(0);
  
          final FlowUri flowUri = new FlowUri("http://localhost:18080", "1234", "5678");
          when(flowMapper.getFlowMapping(className)).thenReturn(Optional.of(flowUri));
  
          final Integer flowVersion = new Integer(1);
          final VersionedFlowSnapshot flowSnapshot = FlowTestUtils.createSnapshot(flowUri.getBucketId(), flowUri.getFlowId(), flowVersion);
          when(flowRetrievalService.getLatestFlow(flowUri)).thenReturn(flowSnapshot);
  
          final FlowMappingEntity flowMappingEntity = FlowTestUtils.createFlowMappingEntity(className, flowUri, flowVersion, "YAML");
          flowMappingEntity.getFlowEntity().setRegistryUrl("http://changed-host:18080"); // change the hostname to trigger an updated
          when(flowMappingRepository.findById(className)).thenReturn(Optional.of(flowMappingEntity));
  
          // test the refresher
          flowRefresherTask.refreshAgentClass(className, refreshedCounter);
  
          // refresh should happen because registry url changed
          assertEquals(1, refreshedCounter.get());
      }
test_case.class_method_signature: TestFlowRefresherTask.testRefreshWhenRegistryInfoChanged()
test_case.full_signature: @Test public void testRefreshWhenRegistryInfoChanged()
test_case.identifier: testRefreshWhenRegistryInfoChanged
test_case.invocations: thenReturn when getFlowMapping of createSnapshot getBucketId getFlowId thenReturn when getLatestFlow createFlowMappingEntity setRegistryUrl getFlowEntity thenReturn when findById of refreshAgentClass assertEquals get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testRefreshWhenRegistryInfoChanged()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(FlowRefresherTask.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(FlowRefresherTask.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.declarator: agentClassRepository
focal_class.modifier: private final
focal_class.original_string: private final AgentClassRepository agentClassRepository;
focal_class.type: AgentClassRepository
focal_class.var_name: agentClassRepository
focal_class.declarator: flowMapper
focal_class.modifier: private final
focal_class.original_string: private final FlowMapper flowMapper;
focal_class.type: FlowMapper
focal_class.var_name: flowMapper
focal_class.declarator: flowRetrievalService
focal_class.modifier: private final
focal_class.original_string: private final FlowRetrievalService flowRetrievalService;
focal_class.type: FlowRetrievalService
focal_class.var_name: flowRetrievalService
focal_class.declarator: flowTransformService
focal_class.modifier: private final
focal_class.original_string: private final FlowTransformService<ConfigSchema> flowTransformService;
focal_class.type: FlowTransformService<ConfigSchema>
focal_class.var_name: flowTransformService
focal_class.declarator: configSchemaSerializer
focal_class.modifier: private final
focal_class.original_string: private final Serializer<ConfigSchema> configSchemaSerializer;
focal_class.type: Serializer<ConfigSchema>
focal_class.var_name: configSchemaSerializer
focal_class.declarator: flowRepository
focal_class.modifier: private final
focal_class.original_string: private final FlowRepository flowRepository;
focal_class.type: FlowRepository
focal_class.var_name: flowRepository
focal_class.declarator: flowMappingRepository
focal_class.modifier: private final
focal_class.original_string: private final FlowMappingRepository flowMappingRepository;
focal_class.type: FlowMappingRepository
focal_class.var_name: flowMappingRepository
focal_class.declarator: transactionTemplate
focal_class.modifier: private final
focal_class.original_string: private final TransactionTemplate transactionTemplate;
focal_class.type: TransactionTemplate
focal_class.var_name: transactionTemplate
focal_class.file: efm/efm-c2-protocol/efm-c2-protocol-framework/src/main/java/com/cloudera/cem/efm/service/flow/refresh/FlowRefresherTask.java
focal_class.identifier: FlowRefresherTask
focal_class.interfaces: implements Runnable
focal_class.class_method_signature: FlowRefresherTask.FlowRefresherTask(
              final AgentClassRepository agentClassRepository,
              final FlowMapper flowMapper,
              final FlowRetrievalService flowRetrievalService,
              final FlowTransformService<ConfigSchema> flowTransformService,
              final Serializer<ConfigSchema> configSchemaSerializer,
              final FlowRepository flowRepository,
              final FlowMappingRepository flowMappingRepository,
              final TransactionTemplate transactionTemplate)
focal_class.full_signature: @Autowired public  FlowRefresherTask(
              final AgentClassRepository agentClassRepository,
              final FlowMapper flowMapper,
              final FlowRetrievalService flowRetrievalService,
              final FlowTransformService<ConfigSchema> flowTransformService,
              final Serializer<ConfigSchema> configSchemaSerializer,
              final FlowRepository flowRepository,
              final FlowMappingRepository flowMappingRepository,
              final TransactionTemplate transactionTemplate)
focal_class.identifier: FlowRefresherTask
focal_class.modifiers: @Autowired public
focal_class.parameters: (
              final AgentClassRepository agentClassRepository,
              final FlowMapper flowMapper,
              final FlowRetrievalService flowRetrievalService,
              final FlowTransformService<ConfigSchema> flowTransformService,
              final Serializer<ConfigSchema> configSchemaSerializer,
              final FlowRepository flowRepository,
              final FlowMappingRepository flowMappingRepository,
              final TransactionTemplate transactionTemplate)
focal_class.signature:  FlowRefresherTask(
              final AgentClassRepository agentClassRepository,
              final FlowMapper flowMapper,
              final FlowRetrievalService flowRetrievalService,
              final FlowTransformService<ConfigSchema> flowTransformService,
              final Serializer<ConfigSchema> configSchemaSerializer,
              final FlowRepository flowRepository,
              final FlowMappingRepository flowMappingRepository,
              final TransactionTemplate transactionTemplate)
focal_class.class_method_signature: FlowRefresherTask.run()
focal_class.full_signature: @Override public void run()
focal_class.identifier: run
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void run()
focal_class.class_method_signature: FlowRefresherTask.refreshAgentClass(final String agentClassName, final AtomicInteger refreshedCount)
focal_class.full_signature:  void refreshAgentClass(final String agentClassName, final AtomicInteger refreshedCount)
focal_class.identifier: refreshAgentClass
focal_class.parameters: (final String agentClassName, final AtomicInteger refreshedCount)
focal_class.return: void
focal_class.signature: void refreshAgentClass(final String agentClassName, final AtomicInteger refreshedCount)
focal_class.class_method_signature: FlowRefresherTask.updateFlowMapping(final FlowMappingEntity existingFlowMapping, final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_class.full_signature: private void updateFlowMapping(final FlowMappingEntity existingFlowMapping, final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_class.identifier: updateFlowMapping
focal_class.modifiers: private
focal_class.parameters: (final FlowMappingEntity existingFlowMapping, final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_class.return: void
focal_class.signature: void updateFlowMapping(final FlowMappingEntity existingFlowMapping, final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_class.class_method_signature: FlowRefresherTask.createNewFlowMapping(final String agentClassName, final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_class.full_signature: private void createNewFlowMapping(final String agentClassName, final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_class.identifier: createNewFlowMapping
focal_class.modifiers: private
focal_class.parameters: (final String agentClassName, final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_class.return: void
focal_class.signature: void createNewFlowMapping(final String agentClassName, final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_class.class_method_signature: FlowRefresherTask.createNewFlow(final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_class.full_signature: private FlowEntity createNewFlow(final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_class.identifier: createNewFlow
focal_class.modifiers: private
focal_class.parameters: (final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_class.return: FlowEntity
focal_class.signature: FlowEntity createNewFlow(final FlowUri flowUri, final VersionedFlowSnapshot latestFlow)
focal_method.body: void refreshAgentClass(final String agentClassName, final AtomicInteger refreshedCount)
              throws FlowMapperException, IOException, FlowRetrievalException, SerializerException, FlowTransformException {
  
          // Determine the uri from NiFi Registry that maps to this class
          final Optional<FlowUri> optionalFlowUri = flowMapper.getFlowMapping(agentClassName);
          if (!optionalFlowUri.isPresent()) {
              LOGGER.debug("No flow mapping present for '{}'", new Object[] {agentClassName});
              return;
          }
  
          final FlowUri flowUri = optionalFlowUri.get();
          LOGGER.debug("Found flow {} mapped to '{}'", new Object[]{flowUri.getFlowId(), agentClassName});
  
          // Get the latest version available for the uri we got above
          final VersionedFlowSnapshot latestFlow = flowRetrievalService.getLatestFlow(flowUri);
          if (latestFlow == null) {
              LOGGER.debug("No flow versions exist for '{}'", new Object[] {agentClassName});
              return;
          }
  
          // Query the database to see if we anything currently mapped for the given agent class
          final Optional<FlowMappingEntity> optionalFlowMapping = flowMappingRepository.findById(agentClassName);
          if (optionalFlowMapping.isPresent()) {
              final FlowMappingEntity existingFlowMapping = optionalFlowMapping.get();
  
              final String existingRegistryUrl = existingFlowMapping.getFlowEntity().getRegistryUrl();
              final String existingBucketId = existingFlowMapping.getFlowEntity().getRegistryBucketId();
              final String existingFlowId = existingFlowMapping.getFlowEntity().getRegistryFlowId();
  
              if (flowUri.getRegistryUrl().equals(existingRegistryUrl)
                      && flowUri.getBucketId().equals(existingBucketId)
                      && flowUri.getFlowId().equals(existingFlowId)) {
  
                  final FlowEntity existingFlow = existingFlowMapping.getFlowEntity();
                  if (latestFlow.getSnapshotMetadata().getVersion() > existingFlow.getRegistryFlowVersion()) {
                      updateFlowMapping(existingFlowMapping, flowUri, latestFlow);
                      refreshedCount.incrementAndGet();
                  } else {
                      LOGGER.debug("'{}' already mapped to latest version, nothing to do...", new Object[]{agentClassName});
                  }
  
              } else {
                  // Existing mapping doesn't match the flow uri we have so we have to update the flow mapping to point
                  // to a new flow, this could happen if the C2 server is restarted to point at a different NiFi registry
                  updateFlowMapping(existingFlowMapping, flowUri, latestFlow);
                  refreshedCount.incrementAndGet();
              }
  
          } else {
              // No mapping present yet so we need to create a new one
              createNewFlowMapping(agentClassName, flowUri, latestFlow);
              refreshedCount.incrementAndGet();
          }
      }
focal_method.class_method_signature: FlowRefresherTask.refreshAgentClass(final String agentClassName, final AtomicInteger refreshedCount)
focal_method.full_signature:  void refreshAgentClass(final String agentClassName, final AtomicInteger refreshedCount)
focal_method.identifier: refreshAgentClass
focal_method.invocations: getFlowMapping isPresent debug get debug getFlowId getLatestFlow debug findById isPresent get getRegistryUrl getFlowEntity getRegistryBucketId getFlowEntity getRegistryFlowId getFlowEntity equals getRegistryUrl equals getBucketId equals getFlowId getFlowEntity getVersion getSnapshotMetadata getRegistryFlowVersion updateFlowMapping incrementAndGet debug updateFlowMapping incrementAndGet createNewFlowMapping incrementAndGet
focal_method.parameters: (final String agentClassName, final AtomicInteger refreshedCount)
focal_method.return: void
focal_method.signature: void refreshAgentClass(final String agentClassName, final AtomicInteger refreshedCount)