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

    https://github.com/apache/nifi/pull/2335#discussion_r156979528
  
    --- Diff: 
nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/main/java/org/apache/nifi/atlas/NiFiAtlasClient.java
 ---
    @@ -0,0 +1,537 @@
    +/*
    + * 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.atlas;
    +
    +import com.sun.jersey.api.client.UniformInterfaceException;
    +import com.sun.jersey.core.util.MultivaluedMapImpl;
    +import org.apache.atlas.ApplicationProperties;
    +import org.apache.atlas.AtlasClientV2;
    +import org.apache.atlas.AtlasServiceException;
    +import org.apache.atlas.model.SearchFilter;
    +import org.apache.atlas.model.instance.AtlasEntity;
    +import org.apache.atlas.model.instance.AtlasObjectId;
    +import org.apache.atlas.model.instance.EntityMutationResponse;
    +import org.apache.atlas.model.typedef.AtlasEntityDef;
    +import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
    +import org.apache.atlas.model.typedef.AtlasTypesDef;
    +import org.apache.nifi.atlas.security.AtlasAuthN;
    +import org.apache.nifi.util.StringUtils;
    +import org.apache.nifi.util.Tuple;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import javax.ws.rs.core.MultivaluedMap;
    +import java.io.File;
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Objects;
    +import java.util.Properties;
    +import java.util.Set;
    +import java.util.concurrent.atomic.AtomicBoolean;
    +import java.util.function.Function;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +import java.util.stream.Collectors;
    +
    +import static org.apache.nifi.atlas.AtlasUtils.findIdByQualifiedName;
    +import static 
org.apache.nifi.atlas.AtlasUtils.getComponentIdFromQualifiedName;
    +import static org.apache.nifi.atlas.AtlasUtils.toStr;
    +import static org.apache.nifi.atlas.NiFiFlow.EntityChangeType.AS_IS;
    +import static org.apache.nifi.atlas.NiFiFlow.EntityChangeType.CREATED;
    +import static org.apache.nifi.atlas.NiFiFlow.EntityChangeType.DELETED;
    +import static org.apache.nifi.atlas.NiFiFlow.EntityChangeType.UPDATED;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_DESCRIPTION;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_FLOW_PATHS;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_GUID;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_INPUTS;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_INPUT_PORTS;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_OUTPUTS;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_OUTPUT_PORTS;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUEUES;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_TYPENAME;
    +import static org.apache.nifi.atlas.NiFiTypes.ATTR_URL;
    +import static org.apache.nifi.atlas.NiFiTypes.ENTITIES;
    +import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_FLOW;
    +import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_FLOW_PATH;
    +import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_INPUT_PORT;
    +import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_OUTPUT_PORT;
    +import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_QUEUE;
    +
    +public class NiFiAtlasClient {
    +
    +    private static final Logger logger = 
LoggerFactory.getLogger(NiFiAtlasClient.class);
    +
    +    private static NiFiAtlasClient nifiClient;
    +    private AtlasClientV2 atlasClient;
    +
    +    private NiFiAtlasClient() {
    +        super();
    +    }
    +
    +    public static NiFiAtlasClient getInstance() {
    +        if (nifiClient == null) {
    +            synchronized (NiFiAtlasClient.class) {
    +                if (nifiClient == null) {
    +                    nifiClient = new NiFiAtlasClient();
    +                }
    +            }
    +        }
    +        return nifiClient;
    +    }
    +
    +    public void initialize(final String[] baseUrls, final AtlasAuthN 
authN, final File atlasConfDir) {
    +
    +        synchronized (NiFiAtlasClient.class) {
    +
    +            if (atlasClient != null) {
    +                logger.info("{} had been setup but replacing it with new 
one.", atlasClient);
    +                ApplicationProperties.forceReload();
    +            }
    +
    +            if (atlasConfDir != null) {
    +                // If atlasConfDir is not set, 
atlas-application.properties will be searched under classpath.
    +                Properties props = System.getProperties();
    +                final String atlasConfProp = "atlas.conf";
    +                props.setProperty(atlasConfProp, 
atlasConfDir.getAbsolutePath());
    +                logger.debug("{} has been set to: {}", atlasConfProp, 
props.getProperty(atlasConfProp));
    +            }
    +
    +            atlasClient = authN.createClient(baseUrls);
    +
    +        }
    +    }
    +
    +    /**
    +     * This is an utility method to delete unused types.
    +     * Should be used during development or testing only.
    +     * @param typeNames to delete
    +     */
    +    void deleteTypeDefs(String ... typeNames) throws AtlasServiceException 
{
    +        final AtlasTypesDef existingTypeDef = getTypeDefs(typeNames);
    +        try {
    +            atlasClient.deleteAtlasTypeDefs(existingTypeDef);
    +        } catch (UniformInterfaceException e) {
    +            if (e.getResponse().getStatus() == 204) {
    +                // 204 is a successful response.
    +                // NOTE: However after executing this, Atlas should be 
restarted to work properly.
    --- End diff --
    
    Is this a bug in Atlas? If so, has a JIRA been filed for the Atlas team? 
Should we be logging a warning here?


---

Reply via email to