All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.eagle.service.security.hbase.HbaseSensitivityResourceService Maven / Gradle / Ivy

/*
 * 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.eagle.service.security.hbase;


import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
import org.apache.eagle.security.entity.HbaseResourceSensitivityAPIEntity;
import org.apache.eagle.service.generic.GenericEntityServiceResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HbaseSensitivityResourceService {
    private static Logger LOG = LoggerFactory.getLogger(HbaseSensitivityResourceService.class);

    public Map> getAllHbaseSensitivityMap(){
        GenericEntityServiceResource resource = new GenericEntityServiceResource();
        /* parameters are: query, startTime, endTime, pageSzie, startRowkey, treeAgg, timeSeries, intervalmin, top, filterIfMissing,
        * parallel, metricName*/
        GenericServiceAPIResponseEntity ret = resource.search("HbaseResourceSensitivityService[]{*}", null, null, Integer.MAX_VALUE, null, false, false, 0L, 0, false,
                0, null, false);
        List list = (List) ret.getObj();
        if( list == null )
            return Collections.emptyMap();
        Map> res = new HashMap>();

        for(HbaseResourceSensitivityAPIEntity entity : list){
            String site = entity.getTags().get("site");
            if(entity.getTags().containsKey("hbaseResource")) {
                if(res.get(site) == null){
                    res.put(site, new HashMap());
                }
                Map resSensitivityMap = res.get(site);
                resSensitivityMap.put(entity.getTags().get("hbaseResource"), entity.getSensitivityType());
            }
            else {
                if(LOG.isDebugEnabled()) {
                    LOG.debug("An invalid sensitivity entity is detected" + entity);
                }
            }
        }
        return res;
    }

    public Map getHbaseSensitivityMap(String site){
        GenericEntityServiceResource resource = new GenericEntityServiceResource();
        String queryFormat = "HbaseResourceSensitivityService[@site=\"%s\"]{*}";
        GenericServiceAPIResponseEntity ret = resource.search(String.format(queryFormat, site), null, null, Integer.MAX_VALUE, null, false, false, 0L, 0, false,
                0, null, false);
        List list = (List) ret.getObj();
        if( list == null )
            return Collections.emptyMap();
        Map resSensitivityMap = new HashMap();
        for(HbaseResourceSensitivityAPIEntity entity : list){
            if(entity.getTags().containsKey("hbaseResource")) {
                resSensitivityMap.put(entity.getTags().get("hbaseResource"), entity.getSensitivityType());
            }
        }
        return resSensitivityMap;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy