List of usage examples for java.util NavigableMap get
V get(Object key);
From source file:org.apache.hadoop.hbase.TestMultiVersions.java
/** * Verifies versions across a cluster restart. * Port of old TestGetRowVersions test to here so can better utilize the spun * up cluster running more than a single test per spin up. Keep old tests' * crazyness./*from w ww . j a v a 2 s . c om*/ */ @Test public void testGetRowVersions() throws Exception { final String tableName = "testGetRowVersions"; final byte[] contents = Bytes.toBytes("contents"); final byte[] row = Bytes.toBytes("row"); final byte[] value1 = Bytes.toBytes("value1"); final byte[] value2 = Bytes.toBytes("value2"); final long timestamp1 = 100L; final long timestamp2 = 200L; final HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); HColumnDescriptor hcd = new HColumnDescriptor(contents); hcd.setMaxVersions(3); desc.addFamily(hcd); this.admin.createTable(desc); Put put = new Put(row, timestamp1); put.add(contents, contents, value1); HTable table = new HTable(UTIL.getConfiguration(), tableName); table.put(put); // Shut down and restart the HBase cluster table.close(); UTIL.shutdownMiniHBaseCluster(); LOG.debug("HBase cluster shut down -- restarting"); UTIL.startMiniHBaseCluster(1, NUM_SLAVES); // Make a new connection. Use new Configuration instance because old one // is tied to an HConnection that has since gone stale. table = new HTable(new Configuration(UTIL.getConfiguration()), tableName); // Overwrite previous value put = new Put(row, timestamp2); put.add(contents, contents, value2); table.put(put); // Now verify that getRow(row, column, latest) works Get get = new Get(row); // Should get one version by default Result r = table.get(get); assertNotNull(r); assertFalse(r.isEmpty()); assertTrue(r.size() == 1); byte[] value = r.getValue(contents, contents); assertTrue(value.length != 0); assertTrue(Bytes.equals(value, value2)); // Now check getRow with multiple versions get = new Get(row); get.setMaxVersions(); r = table.get(get); assertTrue(r.size() == 2); value = r.getValue(contents, contents); assertTrue(value.length != 0); assertTrue(Bytes.equals(value, value2)); NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> map = r.getMap(); NavigableMap<byte[], NavigableMap<Long, byte[]>> familyMap = map.get(contents); NavigableMap<Long, byte[]> versionMap = familyMap.get(contents); assertTrue(versionMap.size() == 2); assertTrue(Bytes.equals(value1, versionMap.get(timestamp1))); assertTrue(Bytes.equals(value2, versionMap.get(timestamp2))); table.close(); }
From source file:org.apache.kylin.rest.security.MockHTable.java
private static List<KeyValue> toKeyValue(byte[] row, NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowdata, long timestampStart, long timestampEnd, int maxVersions) { List<KeyValue> ret = new ArrayList<KeyValue>(); for (byte[] family : rowdata.keySet()) for (byte[] qualifier : rowdata.get(family).keySet()) { int versionsAdded = 0; for (Map.Entry<Long, byte[]> tsToVal : rowdata.get(family).get(qualifier).descendingMap() .entrySet()) {//from w ww . java 2 s .c o m if (versionsAdded++ == maxVersions) break; Long timestamp = tsToVal.getKey(); if (timestamp < timestampStart) continue; if (timestamp > timestampEnd) continue; byte[] value = tsToVal.getValue(); ret.add(new KeyValue(row, family, qualifier, timestamp, value)); } } return ret; }
From source file:org.apache.kylin.rest.security.MockHTable.java
private <K, V> V forceFind(NavigableMap<K, V> map, K key, V newObject) { V data = map.get(key); if (data == null) { data = newObject;/*from w ww. j a v a2 s. c o m*/ map.put(key, data); } return data; }
From source file:org.apache.kylin.rest.service.AclService.java
private void genAces(List<Sid> sids, Result result, AclImpl acl) throws JsonParseException, JsonMappingException, IOException { List<AceInfo> aceInfos = new ArrayList<AceInfo>(); if (null != sids) { // Just return aces in sids for (Sid sid : sids) { String sidName = null; if (sid instanceof PrincipalSid) { sidName = ((PrincipalSid) sid).getPrincipal(); } else if (sid instanceof GrantedAuthoritySid) { sidName = ((GrantedAuthoritySid) sid).getGrantedAuthority(); }/* w w w . ja v a 2 s .com*/ AceInfo aceInfo = aceSerializer.deserialize( result.getValue(Bytes.toBytes(AclHBaseStorage.ACL_ACES_FAMILY), Bytes.toBytes(sidName))); if (null != aceInfo) { aceInfos.add(aceInfo); } } } else { NavigableMap<byte[], byte[]> familyMap = result .getFamilyMap(Bytes.toBytes(AclHBaseStorage.ACL_ACES_FAMILY)); for (byte[] qualifier : familyMap.keySet()) { AceInfo aceInfo = aceSerializer.deserialize(familyMap.get(qualifier)); if (null != aceInfo) { aceInfos.add(aceInfo); } } } List<AccessControlEntry> newAces = new ArrayList<AccessControlEntry>(); for (int i = 0; i < aceInfos.size(); i++) { AceInfo aceInfo = aceInfos.get(i); if (null != aceInfo) { Sid sid = aceInfo.getSidInfo().isPrincipal() ? new PrincipalSid(aceInfo.getSidInfo().getSid()) : new GrantedAuthoritySid(aceInfo.getSidInfo().getSid()); AccessControlEntry ace = new AccessControlEntryImpl(Long.valueOf(i), acl, sid, aclPermissionFactory.buildFromMask(aceInfo.getPermissionMask()), true, false, false); newAces.add(ace); } } this.setAces(acl, newAces); }
From source file:org.apache.sling.distribution.serialization.impl.vlt.VltUtils.java
private static void initFilterSet(PathFilterSet filterSet, NavigableMap<String, List<String>> globalFilters, List<String> patterns) { // add the most specific filter rules String root = filterSet.getRoot(); for (String key : globalFilters.descendingKeySet()) { if (root.startsWith(key)) { patterns.addAll(globalFilters.get(key)); break; }//from w w w .ja v a 2 s . co m } for (String pattern : patterns) { PathFilterSet.Entry<DefaultPathFilter> entry = extractPathPattern(pattern); if (entry.isInclude()) { filterSet.addInclude(entry.getFilter()); } else { filterSet.addExclude(entry.getFilter()); } } }
From source file:org.apache.vysper.storage.hbase.roster.HBaseRosterManager.java
@Override protected Roster retrieveRosterInternal(Entity bareJid) { final Result entityRow = hBaseStorage.getEntityRow(bareJid, COLUMN_FAMILY_NAME_CONTACT, COLUMN_FAMILY_NAME_ROSTER);/*from w ww . j a va2 s . co m*/ MutableRoster roster = new MutableRoster(); final NavigableMap<byte[], byte[]> contacts = entityRow.getFamilyMap(COLUMN_FAMILY_NAME_CONTACT_BYTES); if (contacts == null) return roster; for (byte[] contactBytes : contacts.keySet()) { String contactAsString = null; EntityImpl contactJID = null; try { contactAsString = new String(contactBytes, "UTF-8"); contactJID = EntityImpl.parse(contactAsString); } catch (Exception e) { LOG.warn("failed to read contact identified by '{}' for user {}", bareJid, contactAsString); continue; } final NavigableMap<byte[], byte[]> contactDetails = entityRow .getFamilyMap(COLUMN_FAMILY_NAME_ROSTER_BYTES); String name = toStr(contactDetails.get(asBytes(COLUMN_PREFIX_NAME + contactAsString))); String typeString = toStr(contactDetails.get(asBytes(COLUMN_PREFIX_TYPE + contactAsString))); String askTypeString = toStr(contactDetails.get(asBytes(COLUMN_PREFIX_ASKTYPE + contactAsString))); SubscriptionType subscriptionType = null; try { subscriptionType = SubscriptionType.valueOf(typeString == null ? "NONE" : typeString.toUpperCase()); } catch (IllegalArgumentException e) { LOG.warn("when loading roster for user " + bareJid + ", contact " + contactJID + " misses a subscription type"); } AskSubscriptionType askSubscriptionType = AskSubscriptionType.NOT_SET; try { if (StringUtils.isNotBlank(askTypeString)) { askSubscriptionType = AskSubscriptionType.valueOf(askTypeString); } } catch (IllegalArgumentException e) { LOG.warn("when loading roster for user " + bareJid.getFullQualifiedName() + ", contact " + contactJID.getFullQualifiedName() + ", the ask subscription type '" + askTypeString + "' is unparsable. skipping!"); continue; // don't return it, don't set a default! } List<RosterGroup> groups = new ArrayList<RosterGroup>(); int i = 1; while (true) { String columnName = COLUMN_PREFIX_GROUP + i + ":" + contactAsString; String groupName = toStr(contactDetails.get(asBytes(columnName))); if (groupName == null) break; groups.add(new RosterGroup(groupName)); i++; } RosterItem item = new RosterItem(contactJID, name, subscriptionType, askSubscriptionType, groups); LOG.info("item loaded for " + bareJid.getFullQualifiedName() + ": " + item.toString()); roster.addItem(item); } return roster; }
From source file:org.cloudgraph.hbase.mutation.GraphMutationWriter.java
private void debugRowValues(Row row) { if (row instanceof Mutation) { Mutation mutation = (Mutation) row; NavigableMap<byte[], List<Cell>> map = mutation.getFamilyCellMap(); StringBuilder buf = new StringBuilder(); Iterator<byte[]> iter = map.keySet().iterator(); buf.append("["); int i = 0; while (iter.hasNext()) { if (i > 0) buf.append(", "); byte[] family = iter.next(); List<Cell> list = map.get(family); for (Cell cell : list) { buf.append(Bytes.toString(family)); buf.append(":"); byte[] qual = CellUtil.cloneQualifier(cell); buf.append(Bytes.toString(qual)); buf.append("="); byte[] value = CellUtil.cloneValue(cell); buf.append(Bytes.toString(value)); }// w w w. ja v a 2s . c om } buf.append("]"); log.debug("values: " + buf.toString()); } }
From source file:org.jahia.modules.tagcloud.taglibs.TagCloudTag.java
/** * Generates the tag cloud associated with the specified bound component, including only tags with a cardinality above the specified minimum cardinality for inclusion, up to * the specified maximum number of tags. * * @param boundComponent the component for which we want to generate a tag cloud. * @param minimumCardinalityForInclusion minimum cardinality (i.e. number of tagged elements) for a tag to be included in the tag cloud * @param maxNumberOfTags maximum number of tags included in the cloud, keeping most numerous tags first (i.e. tags with lower cardinality will be excluded from * the cloud first) * @param currentQuery the currently applied facet query * @param renderContext the {@link org.jahia.services.render.RenderContext} in which this tag cloud is being generated * @throws RepositoryException if something went wrong accessing the JCR repository while processing the bound component's tags *///from w ww . jav a 2s . c o m public void generateTagCloud(JCRNodeWrapper boundComponent, int minimumCardinalityForInclusion, int maxNumberOfTags, String currentQuery, RenderContext renderContext) throws RepositoryException { // applied facets final Map<String, List<KeyValue>> appliedFacets = Functions.getAppliedFacetFilters(currentQuery); // query QueryResultWrapper filteredTags = getNodesWithFacets(boundComponent, minimumCardinalityForInclusion, maxNumberOfTags, appliedFacets); if (!filteredTags.isFacetResultsEmpty()) { // map recording which unapplied tags have which cardinality, sorted in reverse cardinality order (most numerous tags first, being more important) final NavigableMap<Integer, Set<Tag>> tagCounts = new TreeMap<Integer, Set<Tag>>(); // applied tags facets final List<KeyValue> appliedTagsValues = appliedFacets.get(Constants.TAGS); // list of applied tags List<Tag> appliedTagsList = Collections.emptyList(); if (appliedTagsValues != null) { appliedTagsList = new ArrayList<Tag>(appliedTagsValues.size()); } // action URL start final String facetURLParameterName = getFacetURLParameterName(boundComponent.getName()); final String url = renderContext.getURLGenerator().getMainResource(); final String actionURLStart = url + "?" + facetURLParameterName + "="; // process the query results final FacetField tags = filteredTags.getFacetField(Constants.TAGS); final List<FacetField.Count> values = tags.getValues(); int totalCardinality = 0; for (FacetField.Count value : values) { // facet query should only return tags with a cardinality greater than the one we specified final int count = (int) value.getCount(); // facets return value of the j:tags property which is a weak reference to a node so we need to load it to get its name final String tagUUID = value.getName(); final JCRNodeWrapper tagNode = boundComponent.getSession().getNodeByUUID(tagUUID); final String name = tagNode.getDisplayableName(); // create tag final Tag tag = new Tag(name, count, tagUUID, value); if (!Functions.isFacetValueApplied(value, appliedFacets)) { // only add tag to cloud if it's not applied // increase totalCardinality with the current tag's count, this is used to compute the tag's weight in the cloud totalCardinality += count; // add tag to tag counts Set<Tag> associatedTags = tagCounts.get(count); if (associatedTags == null) { associatedTags = new HashSet<Tag>(); tagCounts.put(count, associatedTags); } associatedTags.add(tag); } else { // get KeyValue for current tag KeyValue current = null; for (KeyValue tagsValue : appliedTagsValues) { if (tagUUID.equals(tagsValue.getKey())) { current = tagsValue; break; } } tag.setDeleteActionURL( getActionURL(actionURLStart, Functions.getDeleteFacetUrl(current, currentQuery))); appliedTagsList.add(tag); } } Tag.setTotalCardinality(totalCardinality); // extract only the maxNumberOfTags most numerous tags final Map<String, Tag> tagCloud = new LinkedHashMap<String, Tag>(maxNumberOfTags); boolean stop = false; for (Set<Tag> tags1 : tagCounts.descendingMap().values()) { if (stop) { break; } for (Tag tag : tags1) { if (tagCloud.size() < maxNumberOfTags) { String result = getActionURL(actionURLStart, Functions.getFacetDrillDownUrl(tag.getFacetValue(), currentQuery)); tag.setActionURL(result); tagCloud.put(tag.getName(), tag); } else { stop = true; break; } } } // put cloud and applied tags in their respective page context variables pageContext.setAttribute(cloudVar, tagCloud, PageContext.REQUEST_SCOPE); pageContext.setAttribute(appliedTags, appliedTagsList, PageContext.REQUEST_SCOPE); } }
From source file:org.kiji.schema.tools.LsTool.java
/** * Prints cell data from the <code>row</code> for each column specified on the * <code>request</code>./*from w w w .ja v a 2s.c om*/ * * @param row The row to read from. * @param mapTypeFamilies The map type families to print. * @param groupTypeColumns The group type columns to print. * @throws IOException if there is an error retrieving data from the KijiRowData. */ private void printRow(KijiRowData row, Map<FamilyLayout, List<String>> mapTypeFamilies, Map<FamilyLayout, List<ColumnLayout>> groupTypeColumns) throws IOException { // Unpack and print result for the map type families. for (Entry<FamilyLayout, List<String>> entry : mapTypeFamilies.entrySet()) { final FamilyLayout family = entry.getKey(); if (family.getDesc().getMapSchema().getType() == SchemaType.COUNTER) { // If this map family of counters has no qualifiers, print entire family. if (entry.getValue().isEmpty()) { for (String key : row.getQualifiers(family.getName())) { KijiCounter counter = row.getCounter(family.getName(), key); if (null != counter) { printCell(row.getEntityId(), counter.getTimestamp(), family.getName(), key, Long.valueOf(counter.getValue())); } } // If this map family of counters has been qualified, print only the given columns. } else { for (String key : entry.getValue()) { KijiCounter counter = row.getCounter(family.getName(), key); if (null != counter) { printCell(row.getEntityId(), counter.getTimestamp(), family.getName(), key, Long.valueOf(counter.getValue())); } } } } else { // If this map family of non-counters has no qualifiers, print entire family. if (entry.getValue().isEmpty()) { NavigableMap<String, NavigableMap<Long, Object>> keyTimeseriesMap = row .getValues(family.getName(), (Schema) null); for (String key : keyTimeseriesMap.keySet()) { for (Entry<Long, Object> timestampedCell : keyTimeseriesMap.get(key).entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, family.getName(), key, timestampedCell.getValue()); } } // If this map family of non-counters has been qualified, print only the given columns. } else { for (String key : entry.getValue()) { NavigableMap<Long, Object> timeseriesMap = row.getValues(family.getName(), key, (Schema) null); for (Entry<Long, Object> timestampedCell : timeseriesMap.entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, family.getName(), key, timestampedCell.getValue()); } } } } } // Unpack and print result for the group type families. for (Entry<FamilyLayout, List<ColumnLayout>> entry : groupTypeColumns.entrySet()) { String familyName = entry.getKey().getName(); for (ColumnLayout column : entry.getValue()) { final KijiColumnName colName = new KijiColumnName(familyName, column.getName()); if (column.getDesc().getColumnSchema().getType() == SchemaType.COUNTER) { final KijiCounter counter = row.getCounter(colName.getFamily(), colName.getQualifier()); if (null != counter) { printCell(row.getEntityId(), counter.getTimestamp(), colName.getFamily(), colName.getQualifier(), Long.valueOf(counter.getValue())); } } else { for (Entry<Long, Object> timestampedCell : row .getValues(colName.getFamily(), colName.getQualifier(), (Schema) null).entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, colName.getFamily(), colName.getQualifier(), timestampedCell.getValue()); } } } } getPrintStream().println(""); }
From source file:org.kiji.schema.tools.ToolUtils.java
/** * Prints cell data from the <code>row</code> for each column specified on the * <code>request</code>./*w ww . j a v a2 s .c o m*/ * * @param row The row to read from. * @param mapTypeFamilies The map type families to print. * @param groupTypeColumns The group type columns to print. * @param printStream The stream to print to. * @throws IOException if there is an error retrieving data from the KijiRowData. */ public static void printRow(KijiRowData row, Map<FamilyLayout, List<String>> mapTypeFamilies, Map<FamilyLayout, List<ColumnLayout>> groupTypeColumns, PrintStream printStream) throws IOException { // Unpack and print result for the map type families. for (Entry<FamilyLayout, List<String>> entry : mapTypeFamilies.entrySet()) { final FamilyLayout family = entry.getKey(); if (family.getDesc().getMapSchema().getType() == SchemaType.COUNTER) { // If this map family of counters has no qualifiers, print entire family. if (entry.getValue().isEmpty()) { for (String key : row.getQualifiers(family.getName())) { KijiCell<Long> counter = row.getMostRecentCell(family.getName(), key); if (null != counter) { printCell(row.getEntityId(), counter, printStream); } } // If this map family of counters has been qualified, print only the given columns. } else { for (String key : entry.getValue()) { KijiCell<Long> counter = row.getMostRecentCell(family.getName(), key); if (null != counter) { printCell(row.getEntityId(), counter, printStream); } } } } else { // If this map family of non-counters has no qualifiers, print entire family. if (entry.getValue().isEmpty()) { NavigableMap<String, NavigableMap<Long, Object>> keyTimeseriesMap = row .getValues(family.getName()); for (String key : keyTimeseriesMap.keySet()) { for (Entry<Long, Object> timestampedCell : keyTimeseriesMap.get(key).entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, family.getName(), key, timestampedCell.getValue(), printStream); } } // If this map family of non-counters has been qualified, print only the given columns. } else { for (String key : entry.getValue()) { NavigableMap<Long, Object> timeseriesMap = row.getValues(family.getName(), key); for (Entry<Long, Object> timestampedCell : timeseriesMap.entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, family.getName(), key, timestampedCell.getValue(), printStream); } } } } } // Unpack and print result for the group type families. for (Entry<FamilyLayout, List<ColumnLayout>> entry : groupTypeColumns.entrySet()) { String familyName = entry.getKey().getName(); for (ColumnLayout column : entry.getValue()) { final KijiColumnName colName = KijiColumnName.create(familyName, column.getName()); if (column.getDesc().getColumnSchema().getType() == SchemaType.COUNTER) { final KijiCell<Long> counter = row.getMostRecentCell(colName.getFamily(), colName.getQualifier()); if (null != counter) { printCell(row.getEntityId(), counter, printStream); } } else { for (Entry<Long, Object> timestampedCell : row .getValues(colName.getFamily(), colName.getQualifier()).entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, colName.getFamily(), colName.getQualifier(), timestampedCell.getValue(), printStream); } } } } printStream.println(""); }