本文整理了Java中com.netflix.zuul.scriptManager.ZuulFilterDAOCassandra
类的一些代码示例,展示了ZuulFilterDAOCassandra
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZuulFilterDAOCassandra
类的具体详情如下:
包路径:com.netflix.zuul.scriptManager.ZuulFilterDAOCassandra
类名称:ZuulFilterDAOCassandra
[英]from zuul_filters DAO for CRUD operations on filter scripts.
[中]来自zuul_filters DAO,用于过滤脚本上的CRUD操作。
代码示例来源:origin: com.netflix.zuul/zuul-netflix
/**
* Default constructor that instantiates default dependencies (ie. the ones that are functional as opposed to those for testing).
*/
public FilterScriptManagerServlet() {
super();
if (scriptDAO == null) scriptDAO = new ZuulFilterDAOCassandra(ZuulFilterDAOCassandra.getCassKeyspace());
}
代码示例来源:origin: com.netflix.zuul/zuul-core
@Override
public FilterInfo addFilter(String filtercode, FilterType filter_type, String filter_name, String disableFilterPropertyName, String filter_order) {
String filter_id = buildFilterID(filter_type, filter_name);
FilterInfo latest = getLatestFilterInfoForFilter(filter_id);
int revision = 1;
if (latest != null) {
List<String> filterIds = getFilterIdsIndex(FILTER_ID + ZuulApplicationInfo.getApplicationName());
if (!filterIds.contains(filter_id)) {
addFilterIdToIndex(FILTER_ID + ZuulApplicationInfo.getApplicationName(), filter_id);
addFilterIdToIndex(APPLICATION_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + revision);
addFilterIdToIndex(getScriptsForFilterIndexKey(filter_id), filter_id + "_" + revision);
return getFilterInfoForFilter(filter_id, revision);
代码示例来源:origin: com.netflix.zuul/zuul-core
public List<String> getFilterIdsIndex(String index) {
String filter_ids = getFilterIdsRaw(index);
if (filter_ids == null || "".equals(filter_ids)) {
return new ArrayList<String>();
}
String[] aFilterIds = filter_ids.split("[|]");
List l = Arrays.asList(aFilterIds);
ArrayList<String> list = new ArrayList<String>();
list.addAll(l);
return list;
}
代码示例来源:origin: com.netflix.zuul/zuul-core
private void removeFilterIdFromIndex(String index, String filter_id) {
List<String> filters = getFilterIdsIndex(index);
if (filters.contains(filter_id)) {
filters.remove(filter_id);
String filterList = toFilterList(filters);
cassandraGateway.updateFilterIndex(index, filterList);
}
}
代码示例来源:origin: com.netflix.zuul/zuul-core
@Override
public FilterInfo deActivateFilter(String filter_id, int revision) throws Exception {
FilterInfo filter = getFilterInfo(filter_id, revision);
if (filter == null) throw new Exception("Filter not Found " + filter_id + "revision:" + revision);
if (!filter.isCanary() && !filter.isActive()) {
throw new Exception("Filter must be canary or active to deactivate" + filter_id + "revision:" + revision);
}
removeFilterIdFromIndex(ACTIVE_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + filter.getRevision());
removeFilterIdFromIndex(CANARY_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + filter.getRevision());
/* activate the revision */
Map<String, Object> attributesForActivation = new HashMap<String, Object>();
attributesForActivation.put("active", false);
attributesForActivation.put("canary", false);
cassandraGateway.upsert(filter_id + "_" + revision, attributesForActivation);
setChanged();
notifyObservers(new ZuulEvent("ZUUL_SCRIPT_CHANGE", "DEACTIVATED ZUUL FILTER id = " + filter_id + " revision = " + revision));
return getFilterInfoForFilter(filter_id, revision);
}
代码示例来源:origin: com.netflix.zuul/zuul-core
@Override
public FilterInfo setFilterActive(String filter_id, int revision) throws Exception {
FilterInfo filter = getFilterInfo(filter_id, revision);
if (filter == null) throw new Exception("Filter not Found " + filter_id + "revision:" + revision);
FilterInfo filterInfo = getActiveFilterInfoForFilter(filter_id);
if (filterInfo != null) {
revisionsToDeactivate.add(filterInfo.getRevision());
removeFilterIdFromIndex(ACTIVE_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + filterInfo.getRevision());
removeFilterIdFromIndex(CANARY_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + revision);
addFilterIdToIndex(ACTIVE_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + revision);
setChanged();
notifyObservers(new ZuulEvent("ZUUL_SCRIPT_CHANGE", "ACTIVATED NEW ZUUL FILTER id = " + filter_id + " revision = " + revision));
return getFilterInfoForFilter(filter_id, revision);
代码示例来源:origin: com.netflix.zuul/zuul-core
@Override
public FilterInfo setCanaryFilter(String filter_id, int revision) {
ArrayList<Integer> revisionsToDeactivate = new ArrayList<Integer>();
FilterInfo filterInfo = getCanaryScriptForFilter(filter_id);
if (filterInfo != null) {
revisionsToDeactivate.add(filterInfo.getRevision());
removeFilterIdFromIndex(ACTIVE_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + filterInfo.getRevision());
removeFilterIdFromIndex(CANARY_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + filterInfo.getRevision());
}
/* activate the revision */
Map<String, Object> attributesForActivation = new HashMap<String, Object>();
attributesForActivation.put("canary", true);
attributesForActivation.put("active", false);
cassandraGateway.upsert(filter_id + "_" + revision, attributesForActivation);
addFilterIdToIndex(CANARY_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + revision);
/* de-activate previously active revisions */
// do this AFTER activating so we don't allow a period where no active scripts will respond
for (int revisionToDeactivate : revisionsToDeactivate) {
// do NOT deactivate if we just activated this (can occur if someone calls this twice in a row, cleaning up bad data, etc)
if (revisionToDeactivate != revision) {
Map<String, Object> attributesForDeactivation = new HashMap<String, Object>();
attributesForDeactivation.put("canary", false);
cassandraGateway.upsert(filter_id + "_" + revisionToDeactivate, attributesForDeactivation);
}
}
setChanged();
notifyObservers(new ZuulEvent("ZUUL_SCRIPT_CHANGE", "CANARY FILTER SET id = " + filter_id + "revision = " + revision));
return getFilterInfoForFilter(filter_id, revision);
}
代码示例来源:origin: com.netflix.zuul/zuul-core
@Test
public void testGetScriptForLatestEndpointReturnsNullWhenNotFound() {
ZuulFilterDAO dao = new ZuulFilterDAOCassandra(gateway);
// setup empty response
when(gateway.select(anyString())).thenReturn(response);
when(response.isEmpty()).thenReturn(true);
FilterInfo filterInfo = dao.getLatestFilterInfoForFilter("/unknown/filter");
assertNull(filterInfo);
}
代码示例来源:origin: com.netflix.zuul/zuul-core
ZuulFilterDAOCassandra dao = new ZuulFilterDAOCassandra(gateway);
doReturn("name:in").when(dao).getFilterIdsRaw(anyString());
when(gateway.getByFilterIds(anyList())).thenReturn(response3, response, response2);
filterInfo = dao.setFilterActive(filter, 4);
} catch (Exception e) {
e.printStackTrace();
代码示例来源:origin: com.netflix.zuul/zuul-netflix
public List<FilterInfo> getFiltersForIndex(String index) {
List<String> filterInfoList = getFilterIdsIndex(index);
if (filterInfoList.isEmpty()) {
return Collections.emptyList();
}
Rows<String, String> result = cassandraGateway.getByFilterIds(filterInfoList);
if (result == null || result.isEmpty()) {
return Collections.emptyList();
} else {
List<FilterInfo> filterInfos = new ArrayList<FilterInfo>();
Iterator<Row<String, String>> rows = result.iterator();
while (rows.hasNext()) {
Row<String, String> row = rows.next();
FilterInfo script = getFilterScriptFromCassandraRow(row);
if (script != null) {
filterInfos.add(script);
}
}
Collections.sort(filterInfos);
return filterInfos;
}
}
代码示例来源:origin: com.netflix.zuul/zuul-core
@Override
public List<String> getAllFilterIDs() {
return getFilterIdsIndex(FILTER_ID + ZuulApplicationInfo.getApplicationName());
}
代码示例来源:origin: com.netflix.zuul/zuul-netflix
@Override
public FilterInfo getFilterInfoForFilter(String filter_id, int revision) {
return getFilterInfo(filter_id, revision);
}
代码示例来源:origin: com.netflix.zuul/zuul-netflix
@Override
public FilterInfo setFilterActive(String filter_id, int revision) throws Exception {
FilterInfo filter = getFilterInfo(filter_id, revision);
if (filter == null) throw new Exception("Filter not Found " + filter_id + "revision:" + revision);
FilterInfo filterInfo = getActiveFilterInfoForFilter(filter_id);
if (filterInfo != null) {
revisionsToDeactivate.add(filterInfo.getRevision());
removeFilterIdFromIndex(ACTIVE_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + filterInfo.getRevision());
removeFilterIdFromIndex(CANARY_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + revision);
addFilterIdToIndex(ACTIVE_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + revision);
setChanged();
notifyObservers(new ZuulEvent("ZUUL_SCRIPT_CHANGE", "ACTIVATED NEW ZUUL FILTER id = " + filter_id + " revision = " + revision));
return getFilterInfoForFilter(filter_id, revision);
代码示例来源:origin: com.netflix.zuul/zuul-netflix
@Override
public FilterInfo setCanaryFilter(String filter_id, int revision) {
ArrayList<Integer> revisionsToDeactivate = new ArrayList<Integer>();
FilterInfo filterInfo = getCanaryScriptForFilter(filter_id);
if (filterInfo != null) {
revisionsToDeactivate.add(filterInfo.getRevision());
removeFilterIdFromIndex(ACTIVE_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + filterInfo.getRevision());
removeFilterIdFromIndex(CANARY_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + filterInfo.getRevision());
}
/* activate the revision */
Map<String, Object> attributesForActivation = new HashMap<String, Object>();
attributesForActivation.put("canary", true);
attributesForActivation.put("active", false);
cassandraGateway.upsert(filter_id + "_" + revision, attributesForActivation);
addFilterIdToIndex(CANARY_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + revision);
/* de-activate previously active revisions */
// do this AFTER activating so we don't allow a period where no active scripts will respond
for (int revisionToDeactivate : revisionsToDeactivate) {
// do NOT deactivate if we just activated this (can occur if someone calls this twice in a row, cleaning up bad data, etc)
if (revisionToDeactivate != revision) {
Map<String, Object> attributesForDeactivation = new HashMap<String, Object>();
attributesForDeactivation.put("canary", false);
cassandraGateway.upsert(filter_id + "_" + revisionToDeactivate, attributesForDeactivation);
}
}
setChanged();
notifyObservers(new ZuulEvent("ZUUL_SCRIPT_CHANGE", "CANARY FILTER SET id = " + filter_id + "revision = " + revision));
return getFilterInfoForFilter(filter_id, revision);
}
代码示例来源:origin: com.netflix.zuul/zuul-netflix
@Override
public FilterInfo deActivateFilter(String filter_id, int revision) throws Exception {
FilterInfo filter = getFilterInfo(filter_id, revision);
if (filter == null) throw new Exception("Filter not Found " + filter_id + "revision:" + revision);
if (!filter.isCanary() && !filter.isActive()) {
throw new Exception("Filter must be canary or active to deactivate" + filter_id + "revision:" + revision);
}
removeFilterIdFromIndex(ACTIVE_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + filter.getRevision());
removeFilterIdFromIndex(CANARY_SCRIPTS + ZuulApplicationInfo.getApplicationName(), filter_id + "_" + filter.getRevision());
/* activate the revision */
Map<String, Object> attributesForActivation = new HashMap<String, Object>();
attributesForActivation.put("active", false);
attributesForActivation.put("canary", false);
cassandraGateway.upsert(filter_id + "_" + revision, attributesForActivation);
setChanged();
notifyObservers(new ZuulEvent("ZUUL_SCRIPT_CHANGE", "DEACTIVATED ZUUL FILTER id = " + filter_id + " revision = " + revision));
return getFilterInfoForFilter(filter_id, revision);
}
代码示例来源:origin: com.netflix.zuul/zuul-core
@Test
public void testGetScriptForEndpointAndRevisionReturnsNullWhenNotFound() {
ZuulFilterDAO dao = new ZuulFilterDAOCassandra(gateway);
// setup empty response
when(gateway.select(anyString())).thenReturn(response);
when(response.isEmpty()).thenReturn(true);
FilterInfo filterInfo = dao.getFilterInfoForFilter("/unknown/filter", 2);
assertNull(filterInfo);
}
代码示例来源:origin: com.netflix.zuul/zuul-netflix
ZuulFilterDAOCassandra dao = new ZuulFilterDAOCassandra(gateway);
doReturn("name:type").when(dao).getFilterIdsRaw(anyString());
when(gateway.getByFilterIds(anyList())).thenReturn(response3, response, response2);
filterInfo = dao.setFilterActive(filter, 4);
} catch (Exception e) {
e.printStackTrace();
代码示例来源:origin: com.netflix.zuul/zuul-netflix
private void removeFilterIdFromIndex(String index, String filter_id) {
List<String> filters = getFilterIdsIndex(index);
if (filters.contains(filter_id)) {
filters.remove(filter_id);
String filterList = toFilterList(filters);
cassandraGateway.updateFilterIndex(index, filterList);
}
}
代码示例来源:origin: com.netflix.zuul/zuul-core
public List<FilterInfo> getFiltersForIndex(String index) {
List<String> filterInfoList = getFilterIdsIndex(index);
if (filterInfoList.isEmpty()) {
return Collections.emptyList();
}
Rows<String, String> result = cassandraGateway.getByFilterIds(filterInfoList);
if (result == null || result.isEmpty()) {
return Collections.emptyList();
} else {
List<FilterInfo> filterInfos = new ArrayList<FilterInfo>();
Iterator<Row<String, String>> rows = result.iterator();
while (rows.hasNext()) {
Row<String, String> row = rows.next();
FilterInfo script = getFilterScriptFromCassandraRow(row);
if (script != null) {
filterInfos.add(script);
}
}
Collections.sort(filterInfos);
return filterInfos;
}
}
代码示例来源:origin: com.netflix.zuul/zuul-netflix
@Override
public List<String> getAllFilterIDs() {
return getFilterIdsIndex(FILTER_ID + ZuulApplicationInfo.getApplicationName());
}
内容来源于网络,如有侵权,请联系作者删除!