Search in sources :

Example 6 with TreeMap

use of java.util.TreeMap in project jetty.project by eclipse.

the class OSGiWebInfConfiguration method configure.

/* ------------------------------------------------------------ */
/** 
     * Allow fragments to supply some resources that are added to the baseResource of the webapp.
     * 
     * The resources can be either prepended or appended to the baseResource.
     * 
     * @see org.eclipse.jetty.webapp.WebInfConfiguration#configure(org.eclipse.jetty.webapp.WebAppContext)
     */
@Override
public void configure(WebAppContext context) throws Exception {
    TreeMap<String, Resource> prependedResourcesPath = new TreeMap<String, Resource>();
    TreeMap<String, Resource> appendedResourcesPath = new TreeMap<String, Resource>();
    Bundle bundle = (Bundle) context.getAttribute(OSGiWebappConstants.JETTY_OSGI_BUNDLE);
    if (bundle != null) {
        Set<Bundle> fragments = (Set<Bundle>) context.getAttribute(FRAGMENT_AND_REQUIRED_BUNDLES);
        if (fragments != null && !fragments.isEmpty()) {
            // looked up.
            for (Bundle frag : fragments) {
                String path = Util.getManifestHeaderValue(OSGiWebappConstants.JETTY_WAR_FRAGMENT_FOLDER_PATH, OSGiWebappConstants.JETTY_WAR_FRAGMENT_RESOURCE_PATH, frag.getHeaders());
                convertFragmentPathToResource(path, frag, appendedResourcesPath);
                path = Util.getManifestHeaderValue(OSGiWebappConstants.JETTY_WAR_PATCH_FRAGMENT_FOLDER_PATH, OSGiWebappConstants.JETTY_WAR_PREPEND_FRAGMENT_RESOURCE_PATH, frag.getHeaders());
                convertFragmentPathToResource(path, frag, prependedResourcesPath);
            }
            if (!appendedResourcesPath.isEmpty()) {
                LinkedHashSet<Resource> resources = new LinkedHashSet<Resource>();
                //Add in any existing setting of extra resource dirs
                Set<Resource> resourceDirs = (Set<Resource>) context.getAttribute(WebInfConfiguration.RESOURCE_DIRS);
                if (resourceDirs != null && !resourceDirs.isEmpty())
                    resources.addAll(resourceDirs);
                //Then append the values from JETTY_WAR_FRAGMENT_FOLDER_PATH
                resources.addAll(appendedResourcesPath.values());
                context.setAttribute(WebInfConfiguration.RESOURCE_DIRS, resources);
            }
        }
    }
    super.configure(context);
    // place the prepended resources at the beginning of the contexts's resource base
    if (!prependedResourcesPath.isEmpty()) {
        Resource[] resources = new Resource[1 + prependedResourcesPath.size()];
        System.arraycopy(prependedResourcesPath.values().toArray(new Resource[prependedResourcesPath.size()]), 0, resources, 0, prependedResourcesPath.size());
        resources[resources.length - 1] = context.getBaseResource();
        context.setBaseResource(new ResourceCollection(resources));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Bundle(org.osgi.framework.Bundle) Resource(org.eclipse.jetty.util.resource.Resource) TreeMap(java.util.TreeMap) ResourceCollection(org.eclipse.jetty.util.resource.ResourceCollection)

Example 7 with TreeMap

use of java.util.TreeMap in project che by eclipse.

the class BuildFileGenerator method createProperty.

/**
     * Create property tag.
     * <property name="value" {location,value}="value"/>
     */
private void createProperty() {
    Map<String, String> locationProperties = new TreeMap<>();
    locationProperties.put("build", "${basedir}/build");
    locationProperties.put("build.classes", "${build}/classes");
    locationProperties.put("src.dir", "${basedir}/src");
    Element nameProperty = doc.createElement("property");
    nameProperty.setAttribute("name", "name");
    nameProperty.setAttribute("value", projectName);
    Node node = root.getFirstChild();
    node = root.insertBefore(nameProperty, node);
    for (Map.Entry<String, String> locationProperty : locationProperties.entrySet()) {
        Element locationElement = doc.createElement("property");
        locationElement.setAttribute("name", locationProperty.getKey());
        locationElement.setAttribute("location", locationProperty.getValue());
        node = node.getNextSibling();
        node = root.insertBefore(locationElement, node);
    }
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 8 with TreeMap

use of java.util.TreeMap in project storm by apache.

the class AuthUtils method pullConfig.

/**
     * Pull a set of keys out of a Configuration.
     * @param configuration The config to pull the key/value pairs out of.
     * @param section The app configuration entry name to get stuff from.
     * @return Return a map of the configs in conf.
     */
public static SortedMap<String, ?> pullConfig(Configuration configuration, String section) throws IOException {
    AppConfigurationEntry[] configurationEntries = AuthUtils.getEntries(configuration, section);
    if (configurationEntries == null) {
        return null;
    }
    TreeMap<String, Object> results = new TreeMap<>();
    for (AppConfigurationEntry entry : configurationEntries) {
        Map<String, ?> options = entry.getOptions();
        for (String key : options.keySet()) {
            results.put(key, options.get(key));
        }
    }
    return results;
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) TreeMap(java.util.TreeMap)

Example 9 with TreeMap

use of java.util.TreeMap in project storm by apache.

the class KerberosSaslTransportPlugin method getServerTransportFactory.

public TTransportFactory getServerTransportFactory() throws IOException {
    //create an authentication callback handler
    CallbackHandler server_callback_handler = new ServerCallbackHandler(login_conf, storm_conf);
    //login our principal
    Subject subject = null;
    try {
        //specify a configuration object to be used
        Configuration.setConfiguration(login_conf);
        //now login
        Login login = new Login(AuthUtils.LOGIN_CONTEXT_SERVER, server_callback_handler);
        subject = login.getSubject();
        login.startThreadIfNeeded();
    } catch (LoginException ex) {
        LOG.error("Server failed to login in principal:" + ex, ex);
        throw new RuntimeException(ex);
    }
    //check the credential of our principal
    if (subject.getPrivateCredentials(KerberosTicket.class).isEmpty()) {
        throw new RuntimeException("Fail to verify user principal with section \"" + AuthUtils.LOGIN_CONTEXT_SERVER + "\" in login configuration file " + login_conf);
    }
    String principal = AuthUtils.get(login_conf, AuthUtils.LOGIN_CONTEXT_SERVER, "principal");
    LOG.debug("principal:" + principal);
    KerberosName serviceKerberosName = new KerberosName(principal);
    String serviceName = serviceKerberosName.getServiceName();
    String hostName = serviceKerberosName.getHostName();
    Map<String, String> props = new TreeMap<String, String>();
    props.put(Sasl.QOP, "auth");
    props.put(Sasl.SERVER_AUTH, "false");
    //create a transport factory that will invoke our auth callback for digest
    TSaslServerTransport.Factory factory = new TSaslServerTransport.Factory();
    factory.addServerDefinition(KERBEROS, serviceName, hostName, props, server_callback_handler);
    //create a wrap transport factory so that we could apply user credential during connections
    TUGIAssumingTransportFactory wrapFactory = new TUGIAssumingTransportFactory(factory, subject);
    LOG.info("SASL GSSAPI transport factory will be used");
    return wrapFactory;
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) KerberosTicket(javax.security.auth.kerberos.KerberosTicket) LoggerFactory(org.slf4j.LoggerFactory) TTransportFactory(org.apache.thrift.transport.TTransportFactory) Login(org.apache.storm.messaging.netty.Login) KerberosName(org.apache.zookeeper.server.auth.KerberosName) TreeMap(java.util.TreeMap) Subject(javax.security.auth.Subject) TSaslServerTransport(org.apache.thrift.transport.TSaslServerTransport) LoginException(javax.security.auth.login.LoginException)

Example 10 with TreeMap

use of java.util.TreeMap in project hbase by apache.

the class CatalogJanitor method getMergedRegionsAndSplitParents.

/**
   * Scans hbase:meta and returns a number of scanned rows, and a map of merged
   * regions, and an ordered map of split parents. if the given table name is
   * null, return merged regions and split parents of all tables, else only the
   * specified table
   * @param tableName null represents all tables
   * @return triple of scanned rows, and map of merged regions, and map of split
   *         parent regioninfos
   * @throws IOException
   */
Triple<Integer, Map<HRegionInfo, Result>, Map<HRegionInfo, Result>> getMergedRegionsAndSplitParents(final TableName tableName) throws IOException {
    final boolean isTableSpecified = (tableName != null);
    // TODO: Only works with single hbase:meta region currently.  Fix.
    final AtomicInteger count = new AtomicInteger(0);
    // Keep Map of found split parents.  There are candidates for cleanup.
    // Use a comparator that has split parents come before its daughters.
    final Map<HRegionInfo, Result> splitParents = new TreeMap<>(new SplitParentFirstComparator());
    final Map<HRegionInfo, Result> mergedRegions = new TreeMap<>();
    // This visitor collects split parents and counts rows in the hbase:meta table
    MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() {

        @Override
        public boolean visit(Result r) throws IOException {
            if (r == null || r.isEmpty())
                return true;
            count.incrementAndGet();
            HRegionInfo info = MetaTableAccessor.getHRegionInfo(r);
            // Keep scanning
            if (info == null)
                return true;
            if (isTableSpecified && info.getTable().compareTo(tableName) > 0) {
                // Another table, stop scanning
                return false;
            }
            if (info.isSplitParent())
                splitParents.put(info, r);
            if (r.getValue(HConstants.CATALOG_FAMILY, HConstants.MERGEA_QUALIFIER) != null) {
                mergedRegions.put(info, r);
            }
            // Returning true means "keep scanning"
            return true;
        }
    };
    // Run full scan of hbase:meta catalog table passing in our custom visitor with
    // the start row
    MetaTableAccessor.scanMetaForTableRegions(this.connection, visitor, tableName);
    return new Triple<>(count.get(), mergedRegions, splitParents);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Triple(org.apache.hadoop.hbase.util.Triple) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MetaTableAccessor(org.apache.hadoop.hbase.MetaTableAccessor) TreeMap(java.util.TreeMap) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

TreeMap (java.util.TreeMap)4328 Map (java.util.Map)1215 ArrayList (java.util.ArrayList)908 HashMap (java.util.HashMap)848 Test (org.junit.Test)610 List (java.util.List)530 Before (org.junit.Before)504 IOException (java.io.IOException)390 HashSet (java.util.HashSet)292 File (java.io.File)260 Set (java.util.Set)258 SortedMap (java.util.SortedMap)238 TreeSet (java.util.TreeSet)208 LinkedHashMap (java.util.LinkedHashMap)181 Key (org.apache.accumulo.core.data.Key)156 Value (org.apache.accumulo.core.data.Value)156 Iterator (java.util.Iterator)147 NavigableMap (java.util.NavigableMap)124 Collection (java.util.Collection)111 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)110