ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [2/3] incubator-ranger git commit: RANGER-1228: removed ServiceFileStore, ServiceRESTStore, TagFileStore
Date Wed, 23 Nov 2016 22:31:44 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ccd0badd/agents-common/src/main/java/org/apache/ranger/plugin/store/file/TagFileStore.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/store/file/TagFileStore.java b/agents-common/src/main/java/org/apache/ranger/plugin/store/file/TagFileStore.java
deleted file mode 100644
index 780d379..0000000
--- a/agents-common/src/main/java/org/apache/ranger/plugin/store/file/TagFileStore.java
+++ /dev/null
@@ -1,1485 +0,0 @@
-/*
- * 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.ranger.plugin.store.file;
-
-import java.util.*;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.fs.Path;
-import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
-import org.apache.ranger.plugin.model.*;
-import org.apache.ranger.plugin.store.AbstractTagStore;
-import org.apache.ranger.plugin.store.PList;
-import org.apache.ranger.plugin.store.RangerServiceResourceSignature;
-import org.apache.ranger.plugin.store.TagPredicateUtil;
-import org.apache.ranger.plugin.store.TagStore;
-import org.apache.ranger.plugin.util.SearchFilter;
-import org.apache.ranger.plugin.util.ServiceTags;
-
-
-public class TagFileStore extends AbstractTagStore {
-	private static final Log LOG = LogFactory.getLog(TagFileStore.class);
-
-	public static final String PROPERTY_TAG_FILE_STORE_DIR = "ranger.tag.store.file.dir";
-
-
-	protected static final String FILE_PREFIX_TAG_DEF          = "ranger-tagdef-";
-	protected static final String FILE_PREFIX_TAG              = "ranger-tag-";
-	protected static final String FILE_PREFIX_RESOURCE         = "ranger-serviceresource-";
-	protected static final String FILE_PREFIX_TAG_RESOURCE_MAP = "ranger-tagresourcemap-";
-
-	private String tagDataDir            = null;
-	private long   nextTagDefId          = 0;
-	private long   nextTagId             = 0;
-	private long   nextServiceResourceId = 0;
-	private long   nextTagResourceMapId  = 0;
-
-	private TagPredicateUtil predicateUtil = null;
-	private FileStoreUtil    fileStoreUtil = null;
-
-	private volatile static TagFileStore instance = null;
-
-	public static TagStore getInstance() {
-		if (instance == null) {
-			synchronized (TagFileStore.class) {
-				if (instance == null) {
-					instance = new TagFileStore();
-					instance.initStore();
-				}
-			}
-		}
-		return instance;
-	}
-
-	TagFileStore() {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.TagFileStore()");
-		}
-
-		tagDataDir = RangerConfiguration.getInstance().get(PROPERTY_TAG_FILE_STORE_DIR, "file:///etc/ranger/data");
-		fileStoreUtil = new FileStoreUtil();
-		predicateUtil = new TagPredicateUtil();
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.TagFileStore()");
-		}
-	}
-
-	@Override
-	public void init() throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.init()");
-		}
-
-		super.init();
-		fileStoreUtil.initStore(tagDataDir);
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.init()");
-		}
-	}
-
-	protected void initStore() {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.initStore()");
-		}
-
-		fileStoreUtil.initStore(tagDataDir);
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.initStore()");
-		}
-	}
-
-	@Override
-	public RangerTagDef createTagDef(RangerTagDef tagDef) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.createTagDef(" + tagDef + ")");
-		}
-
-		RangerTagDef ret = null;
-
-		try {
-			preCreate(tagDef);
-
-			tagDef.setId(nextTagDefId);
-
-			ret = fileStoreUtil.saveToFile(tagDef, new Path(fileStoreUtil.getDataFile(FILE_PREFIX_TAG_DEF, nextTagDefId++)), false);
-
-			postCreate(ret);
-		} catch (Exception excp) {
-			LOG.warn("TagFileStore.createTagDef(): failed to save tag-def '" + tagDef.getName() + "'", excp);
-
-			throw new Exception("failed to save tag-def '" + tagDef.getName() + "'", excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.createTagDef(" + tagDef + ")");
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerTagDef updateTagDef(RangerTagDef tagDef) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.updateTagDef(" + tagDef + ")");
-		}
-
-		RangerTagDef existing = null;
-
-		if(tagDef.getId() == null) {
-			existing = getTagDefByName(tagDef.getName());
-
-			if (existing == null) {
-				throw new Exception("tag-def does not exist: name=" + tagDef.getName());
-			}
-		} else {
-			existing = getTagDef(tagDef.getId());
-
-			if (existing == null) {
-				throw new Exception("tag-def does not exist: id=" + tagDef.getId());
-			}
-		}
-
-		RangerTagDef ret = null;
-
-		try {
-			preUpdate(existing);
-
-			existing.setSource(tagDef.getSource());
-			existing.setAttributeDefs(tagDef.getAttributeDefs());
-
-			ret = fileStoreUtil.saveToFile(existing, new Path(fileStoreUtil.getDataFile(FILE_PREFIX_TAG_DEF, existing.getId())), true);
-
-			postUpdate(existing);
-		} catch (Exception excp) {
-			LOG.warn("TagFileStore.updateTagDef(): failed to save tag-def '" + tagDef.getName() + "'", excp);
-
-			throw new Exception("failed to save tag-def '" + tagDef.getName() + "'", excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.updateTagDef(" + tagDef + ")");
-		}
-
-		return ret;
-	}
-
-	@Override
-	public void deleteTagDefByName(String name) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.deleteTagDef(" + name + ")");
-		}
-
-		RangerTagDef existing = getTagDefByName(name);
-
-		if (existing != null) {
-			try {
-				deleteTagDef(existing);
-			} catch (Exception excp) {
-				throw new Exception("failed to delete tag-def with ID=" + name, excp);
-			}
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.deleteTagDef(" + name + ")");
-		}
-	}
-
-	@Override
-	public void deleteTagDef(Long id) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.deleteTagDef(" + id + ")");
-		}
-
-		RangerTagDef existing = getTagDef(id);
-
-		if(existing != null) {
-			deleteTagDef(existing);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.deleteTagDef(" + id + ")");
-		}
-	}
-	
-	@Override
-	public RangerTagDef getTagDef(Long id) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagDef(" + id + ")");
-		}
-
-		RangerTagDef ret = null;
-
-		if (id != null) {
-			SearchFilter filter = new SearchFilter(SearchFilter.TAG_DEF_ID, id.toString());
-
-			List<RangerTagDef> tagDefs = getTagDefs(filter);
-
-			ret = CollectionUtils.isEmpty(tagDefs) ? null : tagDefs.get(0);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagDef(" + id + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerTagDef getTagDefByGuid(String guid) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagDefByGuid(" + guid + ")");
-		}
-
-		RangerTagDef ret = null;
-
-		if (StringUtils.isNotBlank(guid)) {
-			SearchFilter filter = new SearchFilter(SearchFilter.TAG_DEF_GUID, guid);
-
-			List<RangerTagDef> tagDefs = getTagDefs(filter);
-
-			if(CollectionUtils.isNotEmpty(tagDefs)) {
-				ret = tagDefs.get(0);
-			}
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagDefByGuid(" + guid + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerTagDef getTagDefByName(String name) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagDefByName(" + name + ")");
-		}
-
-		RangerTagDef ret = null;
-
-		if (StringUtils.isNotBlank(name)) {
-			SearchFilter filter = new SearchFilter(SearchFilter.TAG_TYPE, name);
-
-			List<RangerTagDef> tagDefs = getTagDefs(filter);
-
-			ret = CollectionUtils.isEmpty(tagDefs) ? null : tagDefs.get(0);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagDefByName(" + name + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerTagDef> getTagDefs(SearchFilter filter) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagDefs()");
-		}
-
-		List<RangerTagDef> ret = getAllTagDefs();
-
-		if (CollectionUtils.isNotEmpty(ret) && filter != null && !filter.isEmpty()) {
-			CollectionUtils.filter(ret, predicateUtil.getPredicate(filter));
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagDefs(): count=" + (ret == null ? 0 : ret.size()));
-		}
-
-		return ret;
-	}
-
-	@Override
-	public PList<RangerTagDef> getPaginatedTagDefs(SearchFilter filter) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getPaginatedTagDefs()");
-		}
-
-		PList<RangerTagDef> ret = null;
-
-		List<RangerTagDef> list = getTagDefs(filter);
-
-		if(list != null) {
-			ret = new PList<RangerTagDef>(list, 0, list.size(), list.size(), list.size(), filter.getSortType(), filter.getSortBy());
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getPaginatedTagDefs(): count=" + (ret == null ? 0 : ret.getPageSize()));
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<String> getTagTypes() throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagTypes()");
-		}
-
-		List<String> ret = new ArrayList<String>();
-
-		List<RangerTag> allTags = getAllTags();
-
-		for (RangerTag tag : allTags) {
-			ret.add(tag.getType());
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagTypes(): count=" + ret.size());
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerTag createTag(RangerTag tag) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.createTag(" + tag + ")");
-		}
-
-		RangerTag ret = null;
-
-		try {
-			preCreate(tag);
-
-			tag.setId(nextTagId);
-
-			ret = fileStoreUtil.saveToFile(tag, new Path(fileStoreUtil.getDataFile(FILE_PREFIX_TAG, nextTagId++)), false);
-
-			postCreate(ret);
-		} catch (Exception excp) {
-			LOG.warn("TagFileStore.createTag(): failed to save tag '" + tag.getType() + "'", excp);
-
-			throw new Exception("failed to save tag '" + tag.getType() + "'", excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.createTag(" + tag + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerTag updateTag(RangerTag tag) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.updateTag(" + tag + ")");
-		}
-
-		RangerTag ret = null;
-
-		try {
-			preUpdate(tag);
-
-			ret = fileStoreUtil.saveToFile(tag, new Path(fileStoreUtil.getDataFile(FILE_PREFIX_TAG, tag.getId())), true);
-
-			postUpdate(tag);
-		} catch (Exception excp) {
-			LOG.warn("TagFileStore.updateTag(): failed to save tag '" + tag.getType() + "'", excp);
-
-			throw new Exception("failed to save tag '" + tag.getType() + "'", excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.updateTag(" + tag + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public void deleteTag(Long id) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.deleteTag(" + id + ")");
-		}
-
-		try {
-			RangerTag tag = getTag(id);
-
-			if (tag != null) {
-				deleteTag(tag);
-			}
-		} catch (Exception excp) {
-			throw new Exception("failed to delete tag with ID=" + id, excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.deleteTag(" + id + ")");
-		}
-	}
-
-	@Override
-	public RangerTag getTag(Long id) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTag(" + id + ")");
-		}
-
-		RangerTag ret = null;
-
-		if (id != null) {
-			SearchFilter filter = new SearchFilter(SearchFilter.TAG_ID, id.toString());
-
-			List<RangerTag> tags = getTags(filter);
-
-			if (CollectionUtils.isNotEmpty(tags) && CollectionUtils.size(tags) == 1) {
-				ret = tags.get(0);
-			}
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagDef(" + id + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerTag getTagByGuid(String guid) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagByGuid(" + guid + ")");
-		}
-
-		RangerTag ret = null;
-
-		if (guid != null) {
-			SearchFilter filter = new SearchFilter(SearchFilter.TAG_GUID, guid);
-
-			List<RangerTag> tags = getTags(filter);
-
-			if (CollectionUtils.isNotEmpty(tags) && CollectionUtils.size(tags) == 1) {
-				ret = tags.get(0);
-			}
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagByGuid(" + guid + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerTag> getTagsByType(String type) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagsByType(" + type + ")");
-		}
-
-		SearchFilter filter = new SearchFilter(SearchFilter.TAG_TYPE, type);
-
-		List<RangerTag> ret = getTags(filter);
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagsByType(" + type + "): count=" + (ret == null ? 0 : ret.size()));
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<Long> getTagIdsForResourceId(Long resourceId) throws Exception {
-		List<Long> ret = new ArrayList<Long>();
-
-		List<RangerTag> tags = getTagsForResourceId(resourceId);
-
-		if(CollectionUtils.isNotEmpty(tags)) {
-			for(RangerTag tag : tags) {
-				ret.add(tag.getId());
-			}
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerTag> getTagsForResourceId(Long resourceId) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagsForResourceId(" + resourceId + ")");
-		}
-
-		SearchFilter filter = new SearchFilter(SearchFilter.TAG_RESOURCE_ID, resourceId.toString());
-
-		List<RangerTag> ret = getTags(filter);
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagsForResourceId(" + resourceId + "): count=" + (ret == null ? 0 : ret.size()));
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerTag> getTagsForResourceGuid(String resourceGuid) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagsForResourceGuid(" + resourceGuid + ")");
-		}
-
-		SearchFilter filter = new SearchFilter(SearchFilter.TAG_RESOURCE_GUID, resourceGuid);
-
-		List<RangerTag> ret = getTags(filter);
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagsForResourceGuid(" + resourceGuid + "): count=" + (ret == null ? 0 : ret.size()));
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerTag> getTags(SearchFilter filter) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTags()");
-		}
-
-		List<RangerTag> ret = getAllTags();
-
-		if (CollectionUtils.isNotEmpty(ret) && filter != null && !filter.isEmpty()) {
-			CollectionUtils.filter(ret, predicateUtil.getPredicate(filter));
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTags(): count=" + (ret == null ? 0 : ret.size()));
-		}
-
-		return ret;
-	}
-
-	@Override
-	public PList<RangerTag> getPaginatedTags(SearchFilter filter) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getPaginatedTags()");
-		}
-
-		PList<RangerTag> ret = null;
-
-		List<RangerTag> list = getTags(filter);
-
-		if(list != null) {
-			ret = new PList<RangerTag>(list, 0, list.size(), list.size(), list.size(), filter.getSortType(), filter.getSortBy());
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getPaginatedTags(): count=" + (ret == null ? 0 : ret.getPageSize()));
-		}
-
-		return ret;
-	}
-
-
-	@Override
-	public RangerServiceResource createServiceResource(RangerServiceResource resource) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.createServiceResource(" + resource + ")");
-		}
-
-		RangerServiceResource ret = null;
-
-		try {
-			preCreate(resource);
-
-			if (StringUtils.isEmpty(resource.getResourceSignature())) {
-				RangerServiceResourceSignature serializer = new RangerServiceResourceSignature(resource);
-
-				resource.setResourceSignature(serializer.getSignature());
-			}
-
-			resource.setId(nextServiceResourceId);
-
-			ret = fileStoreUtil.saveToFile(resource, new Path(fileStoreUtil.getDataFile(FILE_PREFIX_RESOURCE, nextServiceResourceId++)), false);
-
-			postCreate(ret);
-		} catch (Exception excp) {
-			LOG.warn("TagFileStore.createServiceResource(): failed to save resource '" + resource.getId() + "'", excp);
-
-			throw new Exception("failed to save service-resource '" + resource.getId() + "'", excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.createServiceResource(" + resource + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerServiceResource updateServiceResource(RangerServiceResource resource) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.updateServiceResource(" + resource + ")");
-		}
-
-		RangerServiceResource ret = null;
-
-		try {
-			preUpdate(resource);
-
-			if (StringUtils.isEmpty(resource.getResourceSignature())) {
-				RangerServiceResourceSignature serializer = new RangerServiceResourceSignature(resource);
-
-				resource.setResourceSignature(serializer.getSignature());
-			}
-
-			ret = fileStoreUtil.saveToFile(resource, new Path(fileStoreUtil.getDataFile(FILE_PREFIX_RESOURCE, resource.getId())), true);
-
-			postUpdate(resource);
-		} catch (Exception excp) {
-			LOG.warn("TagFileStore.updateServiceResource(): failed to save resource '" + resource.getId() + "'", excp);
-
-			throw new Exception("failed to save service-resource '" + resource.getId() + "'", excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.updateServiceResource(" + resource + "): " + ret);
-		}
-
-		return ret;
-
-	}
-
-	@Override
-	public void deleteServiceResource(Long id) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.deleteServiceResource(" + id + ")");
-		}
-
-		try {
-			RangerServiceResource resource = getServiceResource(id);
-
-			if (resource != null) {
-				deleteServiceResource(resource);
-			}
-		} catch (Exception excp) {
-			throw new Exception("failed to delete service-resource with ID=" + id, excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.deleteServiceResource(" + id + ")");
-		}
-	}
-
-	@Override
-	public void deleteServiceResourceByGuid(String guid) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.deleteServiceResourceByGuid(" + guid + ")");
-		}
-
-		try {
-			RangerServiceResource resource = getServiceResourceByGuid(guid);
-
-			if (resource != null) {
-				deleteServiceResource(resource);
-			}
-		} catch (Exception excp) {
-			throw new Exception("failed to delete service-resource with GUID=" + guid, excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.deleteServiceResourceByGuid(" + guid + ")");
-		}
-
-	}
-
-	@Override
-	public RangerServiceResource getServiceResource(Long id) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getServiceResource(" + id + ")");
-		}
-
-		RangerServiceResource ret = null;
-
-		SearchFilter filter = new SearchFilter(SearchFilter.TAG_RESOURCE_ID, id.toString());
-
-		List<RangerServiceResource> resources = getServiceResources(filter);
-
-		if (CollectionUtils.isNotEmpty(resources)) {
-			ret = resources.get(0);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getServiceResource(" + id + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerServiceResource getServiceResourceByGuid(String guid) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getServiceResourcesByGuid(" + guid + ")");
-		}
-
-		RangerServiceResource ret = null;
-
-		SearchFilter filter = new SearchFilter(SearchFilter.TAG_RESOURCE_GUID, guid);
-
-		List<RangerServiceResource> resources = getServiceResources(filter);
-
-		if (CollectionUtils.isNotEmpty(resources)) {
-			ret = resources.get(0);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getServiceResourcesByGuid(" + guid + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerServiceResource> getServiceResourcesByService(String serviceName) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getServiceResourcesByService(" + serviceName + ")");
-		}
-
-		List<RangerServiceResource> ret = null;
-
-		if (StringUtils.isNotBlank(serviceName)) {
-			SearchFilter filter = new SearchFilter(SearchFilter.SERVICE_NAME, serviceName);
-
-			ret = getServiceResources(filter);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getServiceResourcesByService(" + serviceName + "): count=" + (ret == null ? 0 : ret.size()));
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<String> getServiceResourceGuidsByService(String serviceName) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getServiceResourceGuidsByService(" + serviceName + ")");
-		}
-
-		List<String> ret = null;
-
-		if (StringUtils.isNotBlank(serviceName)) {
-			List<RangerServiceResource> serviceResources = this.getServiceResourcesByService(serviceName);
-
-			if(CollectionUtils.isNotEmpty(serviceResources)) {
-				ret = new ArrayList<String>(serviceResources.size());
-
-				for(RangerServiceResource serviceResource : serviceResources) {
-					ret.add(serviceResource.getGuid());
-				}
-			}
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getServiceResourceGuidsByService(" + serviceName + "): count=" + (ret == null ? 0 : ret.size()));
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerServiceResource getServiceResourceByServiceAndResourceSignature(String serviceName, String resourceSignature) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getServiceResourceByServiceAndResourceSignature(" + serviceName + ", " + resourceSignature + ")");
-		}
-
-		RangerServiceResource ret = null;
-
-		if (StringUtils.isNotBlank(resourceSignature)) {
-			SearchFilter filter = new SearchFilter();
-			filter.setParam(SearchFilter.TAG_RESOURCE_SERVICE_NAME, serviceName);
-			filter.setParam(SearchFilter.TAG_RESOURCE_SIGNATURE, resourceSignature);
-
-			List<RangerServiceResource> resources = getServiceResources(filter);
-
-			ret = CollectionUtils.isNotEmpty(resources) ? resources.get(0) : null;
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getServiceResourceByServiceAndResourceSignature(" + serviceName + ", " + resourceSignature + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerServiceResource> getServiceResources(SearchFilter filter) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getServiceResources()");
-		}
-
-		List<RangerServiceResource> ret = getAllResources();
-
-		if (CollectionUtils.isNotEmpty(ret) && filter != null && !filter.isEmpty()) {
-			CollectionUtils.filter(ret, predicateUtil.getPredicate(filter));
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getServicesResources(): count=" + (ret == null ? 0 : ret.size()));
-		}
-
-		return ret;
-	}
-
-	@Override
-	public PList<RangerServiceResource> getPaginatedServiceResources(SearchFilter filter) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getPaginatedServiceResources()");
-		}
-
-		PList<RangerServiceResource> ret = null;
-
-		List<RangerServiceResource> list = getServiceResources(filter);
-
-		if(list != null) {
-			ret = new PList<RangerServiceResource>(list, 0, list.size(), list.size(), list.size(), filter.getSortType(), filter.getSortBy());
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getPaginatedServiceResources(): count=" + (ret == null ? 0 : ret.getPageSize()));
-		}
-
-		return ret;
-	}
-
-
-	@Override
-	public RangerTagResourceMap createTagResourceMap(RangerTagResourceMap tagResourceMap) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.createTagResourceMap(" + tagResourceMap + ")");
-		}
-
-		preCreate(tagResourceMap);
-
-		tagResourceMap.setId(nextTagResourceMapId);
-
-		RangerTagResourceMap ret = fileStoreUtil.saveToFile(tagResourceMap, new Path(fileStoreUtil.getDataFile(FILE_PREFIX_TAG_RESOURCE_MAP, nextTagResourceMapId++)), false);
-
-		postCreate(ret);
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.createTagResourceMap(" + tagResourceMap + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public void deleteTagResourceMap(Long id) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.deleteTagResourceMap(" + id + ")");
-		}
-
-		try {
-			RangerTagResourceMap tagResourceMap = getTagResourceMap(id);
-			if (tagResourceMap != null) {
-				Long tagId = tagResourceMap.getTagId();
-				RangerTag tag = getTag(tagId);
-
-				deleteTagResourceMap(tagResourceMap);
-				if (tag != null && tag.getOwner() == RangerTag.OWNER_SERVICERESOURCE) {
-					deleteTag(tagId);
-				}
-			}
-		} catch (Exception excp) {
-			throw new Exception("failed to delete tagResourceMap with ID=" + id, excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.deleteTagResourceMap(" + id + ")");
-		}
-	}
-
-	@Override
-	public RangerTagResourceMap getTagResourceMap(Long id) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagResourceMap(" + id + ")");
-		}
-
-		RangerTagResourceMap ret = null;
-
-		SearchFilter filter = new SearchFilter();
-
-		filter.setParam(SearchFilter.TAG_MAP_ID, id.toString());
-
-		List<RangerTagResourceMap> list = getTagResourceMaps(filter);
-
-		if (CollectionUtils.isNotEmpty(list))  {
-			ret = list.get(0);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagResourceMap(" + id + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerTagResourceMap getTagResourceMapByGuid(String guid) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagResourceMapByGuid(" + guid + ")");
-		}
-
-		RangerTagResourceMap ret = null;
-
-		SearchFilter filter = new SearchFilter();
-
-		filter.setParam(SearchFilter.TAG_MAP_GUID, guid.toString());
-
-		List<RangerTagResourceMap> list = getTagResourceMaps(filter);
-
-		if (CollectionUtils.isNotEmpty(list))  {
-			ret = list.get(0);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagResourceMapByGuid(" + guid + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerTagResourceMap> getTagResourceMapsForTagId(Long tagId) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagResourceMapsForTagId(" + tagId + ")");
-		}
-
-		SearchFilter filter = new SearchFilter();
-
-		filter.setParam(SearchFilter.TAG_ID, tagId.toString());
-
-		List<RangerTagResourceMap> ret = getTagResourceMaps(filter);
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagResourceMapsForTagId(" + tagId + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerTagResourceMap> getTagResourceMapsForTagGuid(String tagGuid) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagResourceMapsForTagGuid(" + tagGuid + ")");
-		}
-
-		List<RangerTagResourceMap> ret = null;
-
-		RangerTag tag = getTagByGuid(tagGuid);
-
-		if(tag != null) {
-			SearchFilter filter = new SearchFilter();
-			filter.setParam(SearchFilter.TAG_ID, tag.getId().toString());
-
-			ret = getTagResourceMaps(filter);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagResourceMapsForTagGuid(" + tagGuid + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerTagResourceMap> getTagResourceMapsForResourceId(Long resourceId) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagResourceMap(" + resourceId + ")");
-		}
-
-		SearchFilter filter = new SearchFilter();
-
-		filter.setParam(SearchFilter.TAG_RESOURCE_ID, resourceId.toString());
-
-		List<RangerTagResourceMap> ret = getTagResourceMaps(filter);
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagResourceMap(" + resourceId + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerTagResourceMap> getTagResourceMapsForResourceGuid(String resourceGuid) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagResourceMapsForResourceGuid(" + resourceGuid + ")");
-		}
-
-		List<RangerTagResourceMap> ret = null;
-
-		RangerServiceResource resource = getServiceResourceByGuid(resourceGuid);
-
-		if (resource != null) {
-			SearchFilter filter = new SearchFilter();
-			filter.setParam(SearchFilter.TAG_RESOURCE_ID, resource.getId().toString());
-			ret = getTagResourceMaps(filter);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagResourceMapsForResourceGuid(" + resourceGuid + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerTagResourceMap getTagResourceMapForTagAndResourceId(Long tagId, Long resourceId) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagResourceMapForTagAndResourceId(" + tagId + ", " + resourceId + ")");
-		}
-
-		RangerTagResourceMap ret = null;
-
-		SearchFilter filter = new SearchFilter();
-
-		filter.setParam(SearchFilter.TAG_ID, tagId.toString());
-		filter.setParam(SearchFilter.TAG_RESOURCE_ID, resourceId.toString());
-
-		List<RangerTagResourceMap> tagResourceMaps = getTagResourceMaps(filter);
-
-		if(CollectionUtils.isNotEmpty(tagResourceMaps)) {
-			ret = tagResourceMaps.get(0);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagResourceMapForTagAndResourceId(" + tagId + ", " + resourceId + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerTagResourceMap getTagResourceMapForTagAndResourceGuid(String tagGuid, String resrouceGuid) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagResourceMapForTagAndResourceGuid(" + tagGuid + ", " + resrouceGuid + ")");
-		}
-
-		RangerTagResourceMap ret = null;
-
-		SearchFilter filter = new SearchFilter();
-		
-		RangerTag             tag      = getTagByGuid(tagGuid);
-		RangerServiceResource resource = getServiceResourceByGuid(resrouceGuid);
-		
-		if(tag != null && resource != null) {
-			filter.setParam(SearchFilter.TAG_ID, tag.getId().toString());
-			filter.setParam(SearchFilter.TAG_RESOURCE_ID, resource.getId().toString());
-
-			List<RangerTagResourceMap> tagResourceMaps = getTagResourceMaps(filter);
-
-			if(CollectionUtils.isNotEmpty(tagResourceMaps)) {
-				ret = tagResourceMaps.get(0);
-			}
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagResourceMapForTagAndResourceGuid(" + tagGuid + ", " + resrouceGuid + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerTagResourceMap> getTagResourceMaps(SearchFilter filter) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getTagResourceMaps()");
-		}
-
-		List<RangerTagResourceMap> ret = getAllTaggedResources();
-
-		if (CollectionUtils.isNotEmpty(ret) && filter != null && !filter.isEmpty()) {
-			CollectionUtils.filter(ret, predicateUtil.getPredicate(filter));
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getTagResourceMaps(): count=" + (ret == null ? 0 : ret.size()));
-		}
-
-		return ret;
-
-	}
-
-	@Override
-	public PList<RangerTagResourceMap> getPaginatedTagResourceMaps(SearchFilter filter) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getPaginatedTagResourceMaps()");
-		}
-
-		PList<RangerTagResourceMap> ret = null;
-
-		List<RangerTagResourceMap> list = getTagResourceMaps(filter);
-		
-		if(CollectionUtils.isNotEmpty(list)) {
-			ret = new PList<RangerTagResourceMap>(list, 0, list.size(), list.size(), list.size(), filter.getSortType(), filter.getSortBy());
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getPaginatedTagResourceMaps(): count=" + (ret == null ? 0 : ret.getPageSize()));
-		}
-
-		return ret;
-	}
-
-
-	@Override
-	public ServiceTags getServiceTagsIfUpdated(String serviceName, Long lastKnownVersion) throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getServiceTagsIfUpdated(" + serviceName + ", " + lastKnownVersion + ")");
-		}
-
-		ServiceTags ret = null;
-
-		boolean tagsChanged = true;
-
-		RangerService service = null;
-
-		try {
-			service = svcStore.getServiceByName(serviceName);
-		} catch (Exception exception) {
-			LOG.error("Cannot find service for serviceName=" + serviceName);
-			tagsChanged = false;
-		}
-
-		if (lastKnownVersion != null
-				&& service != null && service.getTagVersion() != null
-				&& lastKnownVersion.equals(service.getTagVersion())) {
-			tagsChanged = false;
-		}
-
-		if (tagsChanged) {
-			if (LOG.isDebugEnabled()) {
-				LOG.debug("Changes to tagVersion detected, tagVersion in service=" + (service == null ? null : service.getTagVersion())
-						+ ", Plugin-provided lastKnownVersion=" + lastKnownVersion);
-			}
-			ret = getServiceTags(serviceName);
-		} else {
-			if (LOG.isDebugEnabled()) {
-				LOG.debug("No changes to tagVersion detected, tagVersion in service=" + (service == null ? null : service.getTagVersion())
-						+ ", Plugin-provided lastKnownVersion=" + lastKnownVersion);
-			}
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getServiceTagsIfUpdated(" + serviceName + ", " + lastKnownVersion + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public ServiceTags getServiceTags(String serviceName) throws Exception {
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getServiceTags(" + serviceName  + ")");
-		}
-
-		ServiceTags ret = new ServiceTags();
-
-		RangerService service = null;
-
-		try {
-			service = svcStore.getServiceByName(serviceName);
-		} catch (Exception exception) {
-			LOG.error("Cannot find service for serviceName=" + serviceName);
-		}
-
-		SearchFilter filter = new SearchFilter();
-
-		filter.setParam(SearchFilter.TAG_RESOURCE_SERVICE_NAME, serviceName);
-
-		List<RangerServiceResource> serviceResources = getServiceResources(filter);
-		List<RangerServiceResource> filteredServiceResources = new ArrayList<RangerServiceResource>();
-
-		Map<Long, RangerTag> tagsMap = new HashMap<Long, RangerTag>();
-		Map<Long, List<Long>> resourceToTagIdsMap = new HashMap<Long, List<Long>>();
-
-		for (RangerServiceResource serviceResource : serviceResources) {
-			List<RangerTag> tagList = getTagsForServiceResourceObject(serviceResource);
-
-			if (CollectionUtils.isNotEmpty(tagList)) {
-				List<Long> tagIdList = new ArrayList<Long>();
-				for (RangerTag tag : tagList) {
-					tagsMap.put(tag.getId(), tag);
-					tagIdList.add(tag.getId());
-				}
-				resourceToTagIdsMap.put(serviceResource.getId(), tagIdList);
-				filteredServiceResources.add(serviceResource);
-			}
-		}
-
-		ret.setServiceName(serviceName);
-		ret.setServiceResources(filteredServiceResources);
-		ret.setResourceToTagIds(resourceToTagIdsMap);
-		ret.setTags(tagsMap);
-
-		if (service != null && service.getTagVersion() != null) {
-			ret.setTagVersion(service.getTagVersion());
-		}
-		if (service != null && service.getTagUpdateTime() != null) {
-			ret.setTagUpdateTime(service.getTagUpdateTime());
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getServiceTags(" + serviceName  + "): " + ret);
-		}
-
-		return ret;
-
-	}
-
-	@Override
-	public Long getTagVersion(String serviceName) {
-
-		RangerService service = null;
-
-		try {
-			service = svcStore.getServiceByName(serviceName);
-		} catch (Exception exception) {
-			LOG.error("Cannot find service for serviceName=" + serviceName);
-		}
-
-		return service != null ? service.getTagVersion() : null;
-	}
-
-	private List<RangerTag> getTagsForServiceResourceObject(RangerServiceResource serviceResource) throws Exception {
-
-		List<RangerTag> tagList = new ArrayList<RangerTag>();
-
-		if (serviceResource != null) {
-			SearchFilter mapFilter = new SearchFilter();
-			mapFilter.setParam(SearchFilter.TAG_RESOURCE_ID, serviceResource.getId().toString());
-
-			List<RangerTagResourceMap> associations = getTagResourceMaps(mapFilter);
-			if (CollectionUtils.isNotEmpty(associations)) {
-
-				for (RangerTagResourceMap association : associations) {
-					RangerTag tag = getTag(association.getTagId());
-					if (tag != null) {
-						tagList.add(tag);
-					}
-				}
-			}
-		}
-		return tagList;
-	}
-
-	private List<RangerTagDef> getAllTagDefs() throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getAllTagDefs()");
-		}
-
-		List<RangerTagDef> ret = new ArrayList<RangerTagDef>();
-
-		try {
-			// load Tag definitions from file system
-			List<RangerTagDef> sds = fileStoreUtil.loadFromDir(new Path(fileStoreUtil.getDataDir()), FILE_PREFIX_TAG_DEF, RangerTagDef.class);
-
-			if (CollectionUtils.isNotEmpty(sds)) {
-				for (RangerTagDef sd : sds) {
-					if (sd != null) {
-						// if the TagDef is already found, remove the earlier definition
-						for (int i = 0; i < ret.size(); i++) {
-							RangerTagDef currSd = ret.get(i);
-
-							if (StringUtils.equals(currSd.getName(), sd.getName()) ||
-									ObjectUtils.equals(currSd.getId(), sd.getId())) {
-								ret.remove(i);
-							}
-						}
-
-						ret.add(sd);
-					}
-				}
-			}
-			nextTagDefId = getMaxId(ret) + 1;
-		} catch (Exception excp) {
-			LOG.error("TagFileStore.getAllTagDefs(): failed to read Tag-defs", excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getAllTagDefs(): count=" + ret.size());
-		}
-
-		return ret;
-	}
-
-	private List<RangerTag> getAllTags() throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getAllTags()");
-		}
-
-		List<RangerTag> ret = new ArrayList<RangerTag>();
-
-		try {
-			List<RangerTag> sds = fileStoreUtil.loadFromDir(new Path(fileStoreUtil.getDataDir()), FILE_PREFIX_TAG, RangerTag.class);
-
-			if (CollectionUtils.isNotEmpty(sds)) {
-				for (RangerTag sd : sds) {
-					if (sd != null) {
-						// if the Tag is already found, remove the earlier one
-						for (int i = 0; i < ret.size(); i++) {
-							RangerTag currSd = ret.get(i);
-
-							if (StringUtils.equals(currSd.getType(), sd.getType()) ||
-									ObjectUtils.equals(currSd.getId(), sd.getId())) {
-								ret.remove(i);
-							}
-						}
-
-						ret.add(sd);
-					}
-				}
-			}
-			nextTagId = getMaxId(ret) + 1;
-		} catch (Exception excp) {
-			LOG.error("TagFileStore.getAllTags(): failed to read Tags", excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getAllTags(): count=" + ret.size());
-		}
-
-		return ret;
-	}
-
-	private List<RangerServiceResource> getAllResources() throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getAllResources()");
-		}
-
-		List<RangerServiceResource> ret = new ArrayList<RangerServiceResource>();
-
-		try {
-			List<RangerServiceResource> sds = fileStoreUtil.loadFromDir(new Path(fileStoreUtil.getDataDir()), FILE_PREFIX_RESOURCE, RangerServiceResource.class);
-
-			if (CollectionUtils.isNotEmpty(sds)) {
-				for (RangerServiceResource sd : sds) {
-					if (sd != null) {
-						// if the resource is already found, remove the earlier one
-						for (int i = 0; i < ret.size(); i++) {
-							RangerServiceResource currSd = ret.get(i);
-
-							if (ObjectUtils.equals(currSd.getId(), sd.getId())) {
-								ret.remove(i);
-							}
-						}
-
-						ret.add(sd);
-					}
-				}
-			}
-			nextServiceResourceId = getMaxId(ret) + 1;
-		} catch (Exception excp) {
-			LOG.error("TagFileStore.getAllResources(): failed to read Resources", excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getAllResourcess(): count=" + ret.size());
-		}
-
-		return ret;
-	}
-
-	private List<RangerTagResourceMap> getAllTaggedResources() throws Exception {
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("==> TagFileStore.getAllTaggedResources()");
-		}
-
-		List<RangerTagResourceMap> ret = new ArrayList<RangerTagResourceMap>();
-
-		try {
-			// load resource definitions from file system
-			List<RangerTagResourceMap> resources = fileStoreUtil.loadFromDir(new Path(fileStoreUtil.getDataDir()), FILE_PREFIX_TAG_RESOURCE_MAP, RangerTagResourceMap.class);
-
-			if (CollectionUtils.isNotEmpty(resources)) {
-				for (RangerTagResourceMap resource : resources) {
-					if (resource != null) {
-						// if the RangerTagResourceMap is already found, remove the earlier definition
-						for (int i = 0; i < ret.size(); i++) {
-							RangerTagResourceMap currResource = ret.get(i);
-
-							if (ObjectUtils.equals(currResource.getId(), resource.getId())) {
-								ret.remove(i);
-							}
-						}
-
-						ret.add(resource);
-					}
-				}
-			}
-			nextTagResourceMapId = getMaxId(ret) + 1;
-		} catch (Exception excp) {
-			LOG.error("TagFileStore.getAllTaggedResources(): failed to read tagged resources", excp);
-		}
-
-		if (LOG.isDebugEnabled()) {
-			LOG.debug("<== TagFileStore.getAllTaggedResources(): count=" + ret.size());
-		}
-
-		return ret;
-	}
-
-	private void deleteTagDef(RangerTagDef tagDef) throws Exception {
-		Path filePath = new Path(fileStoreUtil.getDataFile(FILE_PREFIX_TAG_DEF, tagDef.getId()));
-
-		preDelete(tagDef);
-
-		fileStoreUtil.deleteFile(filePath);
-
-		postDelete(tagDef);
-	}
-
-	private void deleteTag(RangerTag tag) throws Exception {
-		Path filePath = new Path(fileStoreUtil.getDataFile(FILE_PREFIX_TAG, tag.getId()));
-
-		preDelete(tag);
-
-		fileStoreUtil.deleteFile(filePath);
-
-		postDelete(tag);
-	}
-
-	private void deleteServiceResource(RangerServiceResource resource) throws Exception {
-		Path filePath = new Path(fileStoreUtil.getDataFile(FILE_PREFIX_RESOURCE, resource.getId()));
-
-		preDelete(resource);
-
-		fileStoreUtil.deleteFile(filePath);
-
-		postDelete(resource);
-	}
-
-	private void deleteTagResourceMap(RangerTagResourceMap tagResourceMap) throws Exception {
-		Path filePath = new Path(fileStoreUtil.getDataFile(FILE_PREFIX_TAG_RESOURCE_MAP, tagResourceMap.getId()));
-
-		preDelete(tagResourceMap);
-
-		fileStoreUtil.deleteFile(filePath);
-
-		postDelete(tagResourceMap);
-	}
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ccd0badd/agents-common/src/main/java/org/apache/ranger/plugin/store/rest/ServiceRESTStore.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/store/rest/ServiceRESTStore.java b/agents-common/src/main/java/org/apache/ranger/plugin/store/rest/ServiceRESTStore.java
deleted file mode 100644
index 8f01934..0000000
--- a/agents-common/src/main/java/org/apache/ranger/plugin/store/rest/ServiceRESTStore.java
+++ /dev/null
@@ -1,653 +0,0 @@
-/*
- * 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.ranger.plugin.store.rest;
-
-import java.security.PrivilegedAction;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.ranger.admin.client.datatype.RESTResponse;
-import org.apache.ranger.audit.provider.MiscUtil;
-import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
-import org.apache.ranger.plugin.model.RangerPolicy;
-import org.apache.ranger.plugin.model.RangerService;
-import org.apache.ranger.plugin.model.RangerServiceDef;
-import org.apache.ranger.plugin.store.AbstractServiceStore;
-import org.apache.ranger.plugin.util.RangerRESTClient;
-import org.apache.ranger.plugin.util.SearchFilter;
-import org.apache.ranger.plugin.util.ServicePolicies;
-
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.GenericType;
-import com.sun.jersey.api.client.WebResource;
-
-
-public class ServiceRESTStore extends AbstractServiceStore {
-	private static final Log LOG = LogFactory.getLog(ServiceRESTStore.class);
-
-
-	public final String REST_URL_SERVICEDEF_CREATE      = "/service/plugins/definitions";
-	public final String REST_URL_SERVICEDEF_UPDATE      = "/service/plugins/definitions/";
-	public final String REST_URL_SERVICEDEF_DELETE      = "/service/plugins/definitions/";
-	public final String REST_URL_SERVICEDEF_GET         = "/service/plugins/definitions/";
-	public final String REST_URL_SERVICEDEF_GET_BY_NAME = "/service/plugins/definitions/name/";
-	public final String REST_URL_SERVICEDEF_GET_ALL     = "/service/plugins/definitions";
-
-	public final String REST_URL_SERVICE_CREATE      = "/service/plugins/services";
-	public final String REST_URL_SERVICE_UPDATE      = "/service/plugins/services/";
-	public final String REST_URL_SERVICE_DELETE      = "/service/plugins/services/";
-	public final String REST_URL_SERVICE_GET         = "/service/plugins/services/";
-	public final String REST_URL_SERVICE_GET_BY_NAME = "/service/plugins/services/name/";
-	public final String REST_URL_SERVICE_GET_ALL     = "/service/plugins/services";
-
-	public final String REST_URL_POLICY_CREATE      = "/service/plugins/policies";
-	public final String REST_URL_POLICY_UPDATE      = "/service/plugins/policies/";
-	public final String REST_URL_POLICY_DELETE      = "/service/plugins/policies/";
-	public final String REST_URL_POLICY_GET         = "/service/plugins/policies/";
-	public final String REST_URL_POLICY_GET_BY_NAME = "/service/plugins/policies/name/";
-	public final String REST_URL_POLICY_GET_ALL     = "/service/plugins/policies";
-	public final String REST_URL_POLICY_GET_FOR_SERVICE         = "/service/plugins/policies/service/";
-	public final String REST_URL_POLICY_GET_FOR_SERVICE_BY_NAME = "/service/plugins/policies/service/name/";
-	public final String REST_URL_POLICY_GET_FOR_SERVICE_IF_UPDATED = "/service/plugins/policies/download/";
-	public final String REST_URL_POLICY_GET_FOR_SECURE_SERVICE_IF_UPDATED = "/service/plugins/secure/policies/download/";
-
-	public static final String REST_MIME_TYPE_JSON = "application/json";
-	
-	private Boolean populateExistingBaseFields = false;
-
-	private RangerRESTClient restClient;
-
-	public ServiceRESTStore() {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.ServiceRESTStore()");
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.ServiceRESTStore()");
-		}
-	}
-
-	@Override
-	public void init() throws Exception {
-		String restUrl       = RangerConfiguration.getInstance().get("ranger.service.store.rest.url");
-		String sslConfigFile = RangerConfiguration.getInstance().get("ranger.service.store.rest.ssl.config.file");
-		String userName = RangerConfiguration.getInstance().get("ranger.service.store.rest.basicauth.username");
-		String password = RangerConfiguration.getInstance().get("ranger.service.store.rest.basicauth.password");
-
-		restClient = new RangerRESTClient(restUrl, sslConfigFile);
-		restClient.setBasicAuthInfo(userName, password);
-	}
-
-	@Override
-	public RangerServiceDef createServiceDef(RangerServiceDef serviceDef) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.createServiceDef(" + serviceDef + ")");
-		}
-
-		RangerServiceDef ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICEDEF_CREATE);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).type(REST_MIME_TYPE_JSON).post(ClientResponse.class, restClient.toJson(serviceDef));
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(RangerServiceDef.class);
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.createServiceDef(" + serviceDef + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerServiceDef updateServiceDef(RangerServiceDef serviceDef) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.updateServiceDef(" + serviceDef + ")");
-		}
-
-		RangerServiceDef ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICEDEF_UPDATE + serviceDef.getId());
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).type(REST_MIME_TYPE_JSON).put(ClientResponse.class, restClient.toJson(serviceDef));
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(RangerServiceDef.class);
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.updateServiceDef(" + serviceDef + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public void deleteServiceDef(Long id) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.deleteServiceDef(" + id + ")");
-		}
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICEDEF_DELETE + id);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).delete(ClientResponse.class);
-
-		if(response == null || (response.getStatus() != 200 && response.getStatus() != 204)) {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.deleteServiceDef(" + id + ")");
-		}
-	}
-
-	@Override
-	public RangerServiceDef getServiceDef(Long id) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.getServiceDef(" + id + ")");
-		}
-
-		RangerServiceDef ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICEDEF_GET + id);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(RangerServiceDef.class);
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.getServiceDef(" + id + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerServiceDef getServiceDefByName(String name) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.getServiceDefByName(" + name + ")");
-		}
-
-		RangerServiceDef ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICEDEF_GET_BY_NAME + name);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(RangerServiceDef.class);
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.getServiceDefByName(" + name + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerServiceDef> getServiceDefs(SearchFilter filter) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.getServiceDefs()");
-		}
-
-		List<RangerServiceDef> ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICEDEF_GET_ALL, filter);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(new GenericType<List<RangerServiceDef>>() { });
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.getAllServiceDefs(): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerService createService(RangerService service) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.createService(" + service + ")");
-		}
-
-		RangerService ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICE_CREATE);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).type(REST_MIME_TYPE_JSON).post(ClientResponse.class, restClient.toJson(service));
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(RangerService.class);
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.createService(" + service + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerService updateService(RangerService service) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.updateService(" + service + ")");
-		}
-
-		RangerService ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICE_UPDATE + service.getId());
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).type(REST_MIME_TYPE_JSON).put(ClientResponse.class, restClient.toJson(service));
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(RangerService.class);
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.updateService(" + service + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public void deleteService(Long id) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.deleteService(" + id + ")");
-		}
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICE_DELETE + id);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).delete(ClientResponse.class);
-
-		if(response == null || (response.getStatus() != 200 && response.getStatus() != 204)) {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.deleteService(" + id + ")");
-		}
-	}
-
-	@Override
-	public RangerService getService(Long id) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.getService(" + id + ")");
-		}
-
-		RangerService ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICE_GET + id);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(RangerService.class);
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.getService(" + id + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerService getServiceByName(String name) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.getServiceByName(" + name + ")");
-		}
-
-		RangerService ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICE_GET_BY_NAME + name);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(RangerService.class);
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.getServiceByName(" + name + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerService> getServices(SearchFilter filter) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.getServices()");
-		}
-
-		List<RangerService> ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_SERVICE_GET_ALL, filter);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(new GenericType<List<RangerService>>() { });
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.getServices(): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerPolicy createPolicy(RangerPolicy policy) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.createPolicy(" + policy + ")");
-		}
-
-		RangerPolicy ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_POLICY_CREATE);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).type(REST_MIME_TYPE_JSON).post(ClientResponse.class, restClient.toJson(policy));
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(RangerPolicy.class);
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.createPolicy(" + policy + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public RangerPolicy updatePolicy(RangerPolicy policy) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.updatePolicy(" + policy + ")");
-		}
-
-		RangerPolicy ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_POLICY_UPDATE + policy.getId());
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).type(REST_MIME_TYPE_JSON).put(ClientResponse.class, restClient.toJson(policy));
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(RangerPolicy.class);
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.updatePolicy(" + policy + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public void deletePolicy(Long id) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.deletePolicy(" + id + ")");
-		}
-
-		WebResource    webResource = createWebResource(REST_URL_POLICY_DELETE + id);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).delete(ClientResponse.class);
-
-		if(response == null || (response.getStatus() != 200 && response.getStatus() != 204)) {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.deletePolicy(" + id + ")");
-		}
-	}
-
-	@Override
-	public RangerPolicy getPolicy(Long id) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.getPolicy(" + id + ")");
-		}
-
-		RangerPolicy ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_POLICY_GET + id);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(RangerPolicy.class);
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.getPolicy(" + id + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerPolicy> getPolicies(SearchFilter filter) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.getPolicies()");
-		}
-
-		List<RangerPolicy> ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_POLICY_GET_ALL, filter);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(new GenericType<List<RangerPolicy>>() { });
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.getPolicies(): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerPolicy> getServicePolicies(Long serviceId, SearchFilter filter) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.getServicePolicies(" + serviceId + ")");
-		}
-
-		List<RangerPolicy> ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_POLICY_GET_FOR_SERVICE + serviceId, filter);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(new GenericType<List<RangerPolicy>>() { });
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.getServicePolicies(" + serviceId + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerPolicy> getServicePolicies(String serviceName, SearchFilter filter) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.getServicePolicies(" + serviceName + ")");
-		}
-
-		List<RangerPolicy> ret = null;
-
-		WebResource    webResource = createWebResource(REST_URL_POLICY_GET_FOR_SERVICE_BY_NAME + serviceName, filter);
-		ClientResponse response    = webResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(new GenericType<List<RangerPolicy>>() { });
-		} else {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.getServicePolicies(" + serviceName + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public ServicePolicies getServicePoliciesIfUpdated(final String serviceName, final Long lastKnownVersion) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> ServiceRESTStore.getServicePoliciesIfUpdated(" + serviceName + ", " + lastKnownVersion + ")");
-		}
-
-		ServicePolicies ret = null;
-		ClientResponse response = null;
-		if (MiscUtil.getUGILoginUser() != null && UserGroupInformation.isSecurityEnabled()) {
-			LOG.info("Checking Service policy if updated as user : "+ MiscUtil.getUGILoginUser());
-			PrivilegedAction<ClientResponse> action = new PrivilegedAction<ClientResponse>() {
-				public ClientResponse run() {
-					WebResource secureWebResource = createWebResource(REST_URL_POLICY_GET_FOR_SECURE_SERVICE_IF_UPDATED + serviceName + "/" + lastKnownVersion);
-					return secureWebResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-				};
-			};
-			response = MiscUtil.getUGILoginUser().doAs(action);
-		} else {
-			WebResource  webResource = createWebResource(REST_URL_POLICY_GET_FOR_SERVICE_IF_UPDATED + serviceName + "/" + lastKnownVersion);
-			response = webResource.accept(REST_MIME_TYPE_JSON).get(ClientResponse.class);
-		}
-
-		if(response != null && response.getStatus() == 200) {
-			ret = response.getEntity(ServicePolicies.class);
-		} else if(!(response != null && response.getStatus() == 304)) {
-			RESTResponse resp = RESTResponse.fromClientResponse(response);
-
-			throw new Exception(resp.getMessage());
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== ServiceRESTStore.getServicePoliciesIfUpdated(" + serviceName + ", " + lastKnownVersion + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	@Override
-	public ServicePolicies getServicePolicies(String serviceName) throws Exception {
-		return getServicePoliciesIfUpdated(serviceName, -1L);
-	}
-
-	private WebResource createWebResource(String url) {
-		return createWebResource(url, null);
-	}
-
-	private WebResource createWebResource(String url, SearchFilter filter) {
-		WebResource ret = restClient.getResource(url);
-
-		if(filter != null && !MapUtils.isEmpty(filter.getParams())) {
-			for(Map.Entry<String, String> e : filter.getParams().entrySet()) {
-				String name  = e.getKey();
-				String value = e.getValue();
-
-				ret.queryParam(name, value);
-			}
-		}
-
-		return ret;
-	}
-
-	@Override
-	public List<RangerPolicy> getPoliciesByResourceSignature(String serviceName, String policySignature, Boolean isPolicyEnabled) throws Exception {
-		throw new UnsupportedOperationException("Querying policies by resource signature is not supported!");
-	}
-
-	@Override
-	public void setPopulateExistingBaseFields(Boolean populateExistingBaseFields) {
-		this.populateExistingBaseFields = populateExistingBaseFields;
-	}
-
-	@Override
-	public Boolean getPopulateExistingBaseFields() {
-		return populateExistingBaseFields;
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ccd0badd/agents-common/src/test/java/org/apache/ranger/plugin/store/TestServiceStore.java
----------------------------------------------------------------------
diff --git a/agents-common/src/test/java/org/apache/ranger/plugin/store/TestServiceStore.java b/agents-common/src/test/java/org/apache/ranger/plugin/store/TestServiceStore.java
deleted file mode 100644
index 90e97b7..0000000
--- a/agents-common/src/test/java/org/apache/ranger/plugin/store/TestServiceStore.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * 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.ranger.plugin.store;
-
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.util.List;
-
-import org.apache.ranger.plugin.model.RangerPolicy;
-import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess;
-import org.apache.ranger.plugin.model.RangerService;
-import org.apache.ranger.plugin.model.RangerServiceDef;
-import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem;
-import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
-import org.apache.ranger.plugin.store.file.ServiceFileStore;
-import org.apache.ranger.plugin.util.SearchFilter;
-import org.apache.ranger.plugin.util.ServicePolicies;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-
-public class TestServiceStore {
-	static ServiceStore svcStore = null;
-	static SearchFilter filter   = null;
-
-	static final String sdName      = "svcDef-unit-test-TestServiceStore";
-	static final String serviceName = "svc-unit-test-TestServiceStore";
-	static final String policyName  = "testPolicy-1";
-
-	@BeforeClass
-	public static void setupTest() throws Exception {
-		
-		
-		File file = File.createTempFile("fileStore", "dir");
-		
-		if (file.exists()) {
-			file.delete();
-		}
-		
-		file.deleteOnExit();
-		
-		file.mkdirs();
-		
-		String fileStoreDir =  file.getAbsolutePath();
-		
-		System.out.println("Using fileStoreDirectory as [" + fileStoreDir + "]");
-
-		svcStore = new ServiceFileStore(fileStoreDir);
-		svcStore.init();
-
-		// cleanup if the test service and service-def if they already exist
-		List<RangerService> services = svcStore.getServices(filter);
-		for(RangerService service : services) {
-			if(service.getName().startsWith(serviceName)) {
-				svcStore.deleteService(service.getId());
-			}
-		}
-
-		List<RangerServiceDef> serviceDefs = svcStore.getServiceDefs(filter);
-		for(RangerServiceDef serviceDef : serviceDefs) {
-			if(serviceDef.getName().startsWith(sdName)) {
-				svcStore.deleteServiceDef(serviceDef.getId());
-			}
-		}
-	}
-
-	@Test
-	public void testServiceStore() throws Exception {
-		String updatedName, updatedDescription;
-
-		List<RangerServiceDef> sds = svcStore.getServiceDefs(filter);
-
-		int initSdCount = sds == null ? 0 : sds.size();
-
-		RangerServiceDef sd = new RangerServiceDef(sdName, "org.apache.ranger.services.TestService", "TestService", "test servicedef description", null, null, null, null, null, null, null);
-
-		RangerServiceDef createdSd = svcStore.createServiceDef(sd);
-		assertNotNull("createServiceDef() failed", createdSd != null);
-
-		sds = svcStore.getServiceDefs(filter);
-		assertEquals("createServiceDef() failed", initSdCount + 1, sds == null ? 0 : sds.size());
-
-		updatedDescription = sd.getDescription() + ": updated";
-		createdSd.setDescription(updatedDescription);
-		RangerServiceDef updatedSd = svcStore.updateServiceDef(createdSd);
-		assertNotNull("updateServiceDef(updatedDescription) failed", updatedSd);
-		assertEquals("updateServiceDef(updatedDescription) failed", updatedDescription, updatedSd.getDescription());
-
-		sds = svcStore.getServiceDefs(filter);
-		assertEquals("updateServiceDef(updatedDescription) failed", initSdCount + 1, sds == null ? 0 : sds.size());
-
-		/*
-		updatedName = sd.getName() + "-Renamed";
-		updatedSd.setName(updatedName);
-		updatedSd = sdMgr.update(updatedSd);
-		assertNotNull("updateServiceDef(updatedName) failed", updatedSd);
-		assertEquals("updateServiceDef(updatedName) failed", updatedName, updatedSd.getName());
-
-		sds = getAllServiceDef();
-		assertEquals("updateServiceDef(updatedName) failed", initSdCount + 1, sds == null ? 0 : sds.size());
-		*/
-
-		List<RangerService> services = svcStore.getServices(filter);
-
-		int initServiceCount = services == null ? 0 : services.size();
-
-		RangerService svc = new RangerService(sdName, serviceName, "test service description", null, null);
-
-		RangerService createdSvc = svcStore.createService(svc);
-		assertNotNull("createService() failed", createdSvc);
-
-		services = svcStore.getServices(filter);
-		assertEquals("createServiceDef() failed", initServiceCount + 1, services == null ? 0 : services.size());
-
-		updatedDescription = createdSvc.getDescription() + ": updated";
-		createdSvc.setDescription(updatedDescription);
-		RangerService updatedSvc = svcStore.updateService(createdSvc);
-		assertNotNull("updateService(updatedDescription) failed", updatedSvc);
-		assertEquals("updateService(updatedDescription) failed", updatedDescription, updatedSvc.getDescription());
-
-		services = svcStore.getServices(filter);
-		assertEquals("updateService(updatedDescription) failed", initServiceCount + 1, services == null ? 0 : services.size());
-
-		updatedName = serviceName + "-Renamed";
-		updatedSvc.setName(updatedName);
-		updatedSvc = svcStore.updateService(updatedSvc);
-		assertNotNull("updateService(updatedName) failed", updatedSvc);
-		assertEquals("updateService(updatedName) failed", updatedName, updatedSvc.getName());
-
-		services = svcStore.getServices(filter);
-		assertEquals("updateService(updatedName) failed", initServiceCount + 1, services == null ? 0 : services.size());
-
-		List<RangerPolicy> policies = svcStore.getPolicies(filter);
-
-		int initPolicyCount = policies == null ? 0 : policies.size();
-
-		RangerPolicy policy = new RangerPolicy(updatedSvc.getName(), policyName, 0, "test policy description", null, null, null);
-		policy.getResources().put("path", new RangerPolicyResource("/demo/test/finance", Boolean.FALSE, Boolean.TRUE));
-
-		RangerPolicyItem item1 = new RangerPolicyItem();
-		item1.getAccesses().add(new RangerPolicyItemAccess("read"));
-		item1.getAccesses().add(new RangerPolicyItemAccess("write"));
-		item1.getAccesses().add(new RangerPolicyItemAccess("execute"));
-		item1.getUsers().add("admin");
-		item1.getGroups().add("finance");
-
-		RangerPolicyItem item2 = new RangerPolicyItem();
-		item2.getAccesses().add(new RangerPolicyItemAccess("read"));
-		item2.getGroups().add("public");
-
-		policy.getPolicyItems().add(item1);
-		policy.getPolicyItems().add(item2);
-
-		RangerPolicy createdPolicy = svcStore.createPolicy(policy);
-		assertNotNull(createdPolicy);
-		assertNotNull(createdPolicy.getPolicyItems());
-		assertEquals(createdPolicy.getPolicyItems().size(), 2);
-
-		RangerPolicyItem createItem1 = createdPolicy.getPolicyItems().get(0);
-		RangerPolicyItem createItem2 = createdPolicy.getPolicyItems().get(1);
-
-		assertNotNull(createItem1.getAccesses());
-		assertEquals(createItem1.getAccesses().size(), 3);
-		assertNotNull(createItem1.getUsers());
-		assertEquals(createItem1.getUsers().size(), 1);
-		assertNotNull(createItem1.getGroups());
-		assertEquals(createItem1.getGroups().size(), 1);
-
-		assertNotNull(createItem2.getAccesses());
-		assertEquals(createItem2.getAccesses().size(), 1);
-		assertNotNull(createItem2.getUsers());
-		assertEquals(createItem2.getUsers().size(), 0);
-		assertNotNull(createItem2.getGroups());
-		assertEquals(createItem2.getGroups().size(), 1);
-
-		policies = svcStore.getPolicies(filter);
-		assertEquals("createPolicy() failed", initPolicyCount + 1, policies == null ? 0 : policies.size());
-
-		updatedDescription = policy.getDescription() + ":updated";
-		createdPolicy.setDescription(updatedDescription);
-		RangerPolicy updatedPolicy = svcStore.updatePolicy(createdPolicy);
-		assertNotNull("updatePolicy(updatedDescription) failed", updatedPolicy != null);
-
-		policies = svcStore.getPolicies(filter);
-		assertEquals("updatePolicy(updatedDescription) failed", initPolicyCount + 1, policies == null ? 0 : policies.size());
-
-		updatedName = policyName + "-Renamed";
-		updatedPolicy.setName(updatedName);
-		updatedPolicy = svcStore.updatePolicy(updatedPolicy);
-		assertNotNull("updatePolicy(updatedName) failed", updatedPolicy);
-
-		policies = svcStore.getPolicies(filter);
-		assertEquals("updatePolicy(updatedName) failed", initPolicyCount + 1, policies == null ? 0 : policies.size());
-
-		// rename the service; all the policies for this service should reflect the new service name
-		updatedName = serviceName + "-Renamed2";
-		updatedSvc.setName(updatedName);
-		updatedSvc = svcStore.updateService(updatedSvc);
-		assertNotNull("updateService(updatedName2) failed", updatedSvc);
-		assertEquals("updateService(updatedName2) failed", updatedName, updatedSvc.getName());
-
-		services = svcStore.getServices(filter);
-		assertEquals("updateService(updatedName2) failed", initServiceCount + 1, services == null ? 0 : services.size());
-
-		updatedPolicy = svcStore.getPolicy(createdPolicy.getId());
-		assertNotNull("updateService(updatedName2) failed", updatedPolicy);
-		assertEquals("updateService(updatedName2) failed", updatedPolicy.getService(), updatedSvc.getName());
-
-		ServicePolicies svcPolicies = svcStore.getServicePoliciesIfUpdated(updatedSvc.getName(), 0l);
-		assertNotNull("getServicePolicies(" + updatedSvc.getName() + ") failed", svcPolicies);
-		assertNotNull("getServicePolicies(" + updatedSvc.getName() + ") failed", svcPolicies.getPolicies());
-		assertEquals("getServicePolicies(" + updatedSvc.getName() + ") failed", svcPolicies.getServiceName(), updatedSvc.getName());
-		assertEquals("getServicePolicies(" + updatedSvc.getName() + ") failed", svcPolicies.getServiceId(), updatedSvc.getId());
-		assertEquals("getServicePolicies(" + updatedSvc.getName() + ") failed", svcPolicies.getPolicyVersion(), updatedSvc.getPolicyVersion());
-		assertEquals("getServicePolicies(" + updatedSvc.getName() + ") failed", svcPolicies.getPolicyUpdateTime(), updatedSvc.getPolicyUpdateTime());
-		assertEquals("getServicePolicies(" + updatedSvc.getName() + ") failed", svcPolicies.getServiceDef().getId(), updatedSd.getId());
-		assertEquals("getServicePolicies(" + updatedSvc.getName() + ") failed", svcPolicies.getPolicies().size(), 1);
-		assertEquals("getServicePolicies(" + updatedSvc.getName() + ") failed", svcPolicies.getPolicies().get(0).getName(), updatedPolicy.getName());
-
-		ServicePolicies updatedPolicies = svcStore.getServicePoliciesIfUpdated(updatedSvc.getName(), svcPolicies.getPolicyVersion());
-		assertNull(updatedPolicies);
-
-		filter = new SearchFilter();
-		filter.setParam(SearchFilter.POLICY_NAME, policyName);
-		policies = svcStore.getPolicies(filter);
-		assertEquals("getPolicies(filter=origPolicyName) failed", 0, policies == null ? 0 : policies.size());
-		filter = null;
-
-		filter = new SearchFilter();
-		filter.setParam(SearchFilter.POLICY_NAME, updatedPolicy.getName());
-		policies = svcStore.getPolicies(filter);
-		assertEquals("getPolicies(filter=origPolicyName) failed", 1, policies == null ? 0 : policies.size());
-		filter = null;
-		
-		String osName = System.getProperty("os.name");
-		boolean windows = (osName != null && osName.toLowerCase().startsWith("windows"));
-
-		if (! windows ) {
-
-			svcStore.deletePolicy(policy.getId());
-			
-			policies = svcStore.getPolicies(filter);
-			
-			assertEquals("deletePolicy() failed", initPolicyCount, policies == null ? 0 : policies.size());
-			
-	
-			svcStore.deleteService(svc.getId());
-			services = svcStore.getServices(filter);
-			assertEquals("deleteService() failed", initServiceCount, services == null ? 0 : services.size());
-	
-			svcStore.deleteServiceDef(sd.getId());
-			sds = svcStore.getServiceDefs(filter);
-			assertEquals("deleteServiceDef() failed", initSdCount, sds == null ? 0 : sds.size());
-		
-		}
-	}
-}


Mime
View raw message