[ 
https://issues.apache.org/jira/browse/NIFI-4707?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16303029#comment-16303029
 ] 

ASF GitHub Bot commented on NIFI-4707:
--------------------------------------

Github user ijokarumawak commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2351#discussion_r158615663
  
    --- Diff: 
nifi-nar-bundles/nifi-extension-utils/nifi-reporting-utils/src/main/java/org/apache/nifi/reporting/util/provenance/ComponentMapHolder.java
 ---
    @@ -0,0 +1,120 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.nifi.reporting.util.provenance;
    +
    +import org.apache.nifi.controller.status.ConnectionStatus;
    +import org.apache.nifi.controller.status.PortStatus;
    +import org.apache.nifi.controller.status.ProcessGroupStatus;
    +import org.apache.nifi.controller.status.ProcessorStatus;
    +import org.apache.nifi.controller.status.RemoteProcessGroupStatus;
    +
    +import java.util.HashMap;
    +import java.util.Map;
    +
    +public class ComponentMapHolder {
    +    private static final String REMOTE_INPUT_PORT = "Remote Input Port";
    +    private static final String REMOTE_OUTPUT_PORT = "Remote Output Port";
    +    private final Map<String,String> componentNameMap = new HashMap<>();
    +    private final Map<String,ParentProcessGroupSearchNode> 
componentToParentGroupMap = new HashMap<>();
    +    private final Map<String,String> sourceToConnectionParentGroupMap = 
new HashMap<>();
    +    private final Map<String,String> destinationToConnectionParentGroupMap 
= new HashMap<>();
    +
    +    private ComponentMapHolder putAll(ComponentMapHolder holder) {
    +        this.componentNameMap.putAll(holder.componentNameMap);
    +        
this.componentToParentGroupMap.putAll(holder.componentToParentGroupMap);
    +        
this.sourceToConnectionParentGroupMap.putAll(holder.sourceToConnectionParentGroupMap);
    +        
this.destinationToConnectionParentGroupMap.putAll(holder.destinationToConnectionParentGroupMap);
    +        return this;
    +    }
    +
    +    public String getComponentName(final String componentId) {
    +        return componentNameMap.get(componentId);
    +    }
    +
    +    public String getProcessGroupId(final String componentId, final String 
componentType) {
    +        // Where a Remote Input/Output Port resides is only available at 
ConnectionStatus.
    +        if (REMOTE_INPUT_PORT.equals(componentType)) {
    +            return destinationToConnectionParentGroupMap.get(componentId);
    +        } else if (REMOTE_OUTPUT_PORT.equals(componentType)) {
    +            return sourceToConnectionParentGroupMap.get(componentId);
    +        }
    +        ParentProcessGroupSearchNode parentNode = 
componentToParentGroupMap.get(componentId);
    +        return parentNode == null ? null : parentNode.getId();
    +    }
    +
    +    public ParentProcessGroupSearchNode getProcessGroupParent(final String 
componentId) {
    +        return componentToParentGroupMap.get(componentId);
    +    }
    +
    +    public static ComponentMapHolder createComponentMap(final 
ProcessGroupStatus status, final ParentProcessGroupSearchNode thisNode) {
    +        final ComponentMapHolder holder = new ComponentMapHolder();
    +        final Map<String,String> componentNameMap = 
holder.componentNameMap;
    +        final Map<String,ParentProcessGroupSearchNode> 
componentToParentGroupMap = holder.componentToParentGroupMap;
    +        final Map<String,String> sourceToConnectionParentGroupMap = 
holder.sourceToConnectionParentGroupMap;
    +        final Map<String,String> destinationToConnectionParentGroupMap = 
holder.destinationToConnectionParentGroupMap;
    +
    +        if (status != null) {
    +            ParentProcessGroupSearchNode parentNode = thisNode;
    +            componentNameMap.put(status.getId(), status.getName());
    +            // Put a root entry in if one does not yet exist
    +            if (parentNode == null) {
    +                parentNode = new 
ParentProcessGroupSearchNode(status.getId(), null);
    +                componentToParentGroupMap.put(status.getId(), parentNode);
    +            }
    +
    +            for (final ProcessorStatus procStatus : 
status.getProcessorStatus()) {
    +                componentNameMap.put(procStatus.getId(), 
procStatus.getName());
    +                componentToParentGroupMap.put(procStatus.getId(), new 
ParentProcessGroupSearchNode(status.getId(), parentNode));
    +            }
    +
    +            for (final PortStatus portStatus : 
status.getInputPortStatus()) {
    +                componentNameMap.put(portStatus.getId(), 
portStatus.getName());
    +                componentToParentGroupMap.put(portStatus.getId(), new 
ParentProcessGroupSearchNode(status.getId(), parentNode));
    +            }
    +
    +            for (final PortStatus portStatus : 
status.getOutputPortStatus()) {
    +                componentNameMap.put(portStatus.getId(), 
portStatus.getName());
    +                componentToParentGroupMap.put(portStatus.getId(), new 
ParentProcessGroupSearchNode(status.getId(), parentNode));
    +            }
    +
    +            for (final RemoteProcessGroupStatus rpgStatus : 
status.getRemoteProcessGroupStatus()) {
    +                componentNameMap.put(rpgStatus.getId(), 
rpgStatus.getName());
    +                componentToParentGroupMap.put(rpgStatus.getId(), new 
ParentProcessGroupSearchNode(status.getId(), parentNode));
    +            }
    +
    +            for (final ConnectionStatus connectionStatus : 
status.getConnectionStatus()) {
    +                componentNameMap.put(connectionStatus.getId(), 
connectionStatus.getName());
    +                componentToParentGroupMap.put(connectionStatus.getId(), 
new ParentProcessGroupSearchNode(status.getId(), parentNode));
    +                // Add source and destination for Remote Input/Output 
Ports because metadata for those are only available at ConnectionStatus.
    +                
componentNameMap.computeIfAbsent(connectionStatus.getSourceId(), k -> 
connectionStatus.getSourceName());
    +                
componentNameMap.computeIfAbsent(connectionStatus.getDestinationId(), k -> 
connectionStatus.getDestinationName());
    +                
sourceToConnectionParentGroupMap.put(connectionStatus.getSourceId(), 
connectionStatus.getGroupId());
    +                
destinationToConnectionParentGroupMap.put(connectionStatus.getDestinationId(), 
connectionStatus.getGroupId());
    +            }
    +
    +            for (final ProcessGroupStatus childGroup : 
status.getProcessGroupStatus()) {
    +                componentNameMap.put(childGroup.getId(), 
childGroup.getName());
    +                ParentProcessGroupSearchNode node = new 
ParentProcessGroupSearchNode(status.getId(), parentNode);
    +                componentToParentGroupMap.put(childGroup.getId(), node);
    --- End diff --
    
    ```
    ParentProcessGroupSearchNode node = new 
ParentProcessGroupSearchNode(status.getId(), parentNode);
    componentToParentGroupMap.put(childGroup.getId(), node);
    ```
    should be
    ```
    ParentProcessGroupSearchNode node = new 
ParentProcessGroupSearchNode(childGroup.getId(), parentNode);
    componentToParentGroupMap.put(childGroup.getId(), parentNode);
    ```


> SiteToSiteProvenanceReportingTask not returning correct metadata
> ----------------------------------------------------------------
>
>                 Key: NIFI-4707
>                 URL: https://issues.apache.org/jira/browse/NIFI-4707
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Extensions
>            Reporter: Matt Burgess
>            Assignee: Matt Burgess
>
> When the SiteToSiteProvenanceReportingTask emits flow files, some of them 
> include a "componentName" field and some do not. Investigation shows that 
> only the components (except connections) in the root process group have that 
> field populated. Having this information can be very helpful to the user, 
> even though the names might be duplicated, there would be a mapping between a 
> component's ID and its name. At the very least the behavior (i.e. component 
> name being available) should be consistent.
> Having a full map (by traversing the entire flow) also opens up the ability 
> to include Process Group information for the various components. The 
> reporting task could include the parent Process Group identifier and/or name, 
> with perhaps a special ID for the root PG's "parent", such as "@ROOT@" or 
> something unique.
> This could also allow for a PG ID in the list of filtered "component IDs", 
> where any provenance event for a processor in a particular PG could be 
> included in a filter when that PG's ID is in the filter list.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to