text:
package ADT;

import java.util.List;
import java.util.ArrayList;
/*
Children are at 2i+1 and 2i+2
Parent is at floor((i-1)/2)
*/
class BinaryHeap<D extends Comparable<D>>{
	private List<D> list;

	public BinaryHeap(){
		this.list = new ArrayList<D>();
	}

	public void insert(D val){
		try{
			this.list.add(val);
			this.heapifyUp();
		}
		catch(ClassCastException e){
			System.out.println("Caught");
			this.lis
		}
	}

	public void heapifyUp(){
		int chilIndex = this.list.size()-1;
		int parentIndex = this.getParentIndex(chilIndex);

		D child = list.get(chilIndex);
		D parent = list.get(parentIndex);

		while(child.compareTo(parent)>0){

			D temp = child;

			list.set(childIndex,parent);
			list.set(parentIndex,temp);

			childIndex = parentIndex;
			parentIndex = this.getParentIndex(childIndex);

			child = list.get(childIndex);
			parent = list.get(parentIndex);
		}
	}

	public D delete(){
		if(this.list.isEmpty()){
			return null;
		}

		D delete = this.list.get(0);

		this.list.set(0,this.list.get(this.list.size()-1));
		this.list.remove(this.list.size()-1);

		if(!this.list.isEmpty()){
			this.heapifyDown(0);
		}

		return deleted;
	}

	public void heapifyDown(int index){

		D rightChild = this.getRightChild(index);
		D leftChild = this.getLeftChild(index);
		D parent = this.list.get(index);

		int nextIndex = index;

		if(rightChild == null && leftChild == null){
			return;
		}
		else ;if(rightChild == null || leftChild.compareTo(rightChild)>0){
			if(parent.compareTo(leftChild)<0){
				this.list.set(index,leftChild)
				nextIndex = this.getLeftChildIndex(index);
				this.list.set(nextIndex,parent);
			}else{
				return;
			}
		}
		this.heapifyDown(nextIndex);
	}

	public D peek(){
		if(!list.isEmpty()){
			return list.get(0);
		}else{
			return null;
		}
	}

    public void print(){
        System.out.println(this.list.toString());
    }

    public void traverseBFS(){
    	System.out.println("Heap:");
    	for (int index = 0; index < this.list.size(); index++){
    		D parent = this.getParent(index);
    		System.out.println("Parent: "+ parent);
    		D leftChild = this.getLeftChild(index);
    		System.out.println("Node: "+ this.list.get(index));
    		System.out.println("leftChild: "+ leftChild);
    		D rightChild = this.getRightChild(index);
    		System.out.println("rightChild: " + rightChild);
    		System.out.println();
    	}
    }

    public boolean validChild(int index){
    	if(index < this.list.size()){
    		return true;
    	}
    	else{
    		return false;
    	}
    }

    public D getParent(int index){
    	if(index == 0){
    		return null;
    	}
    	else{
    		return this.list.get(this.getParentIndex(index));
    	}
    }
    public int getLeftChildIndex(int index){

        return ((2*index)+1);

    }
    public D getLeftChild(int index){

        int childIndex = this.getLeftChildIndex(index);

        if(this.validChild(childIndex)){

            return this.list.get(childIndex);

        }
        else{

            return null;

        }
    }
    public int getRightChildIndex(int index){

        return ((2*index)+2);

    }
    public D getRightChild(int index){

        int childIndex = this.getRightChildIndex(index);

        if(this.validChild(childIndex)){

            return this.list.get(childIndex);

        }
        else{

            return null;

        }
    }
    public List<D> getArray(){

        return this.list;

    }
    private void setHeap(List<D> copyList){

        for(int i=0;i<copyList.size();i++){

            this.list.add(copyList.get(i));

        }
    }
}


text:
namespace KeyRevolver
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    class ShotTheSafe
    {
        public static void Main()
        {
            var bulletPrice = int.Parse(Console.ReadLine());
            var gunBarrelSize = int.Parse(Console.ReadLine());

            var bulletsInput = Console.ReadLine()
                .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse)
                .ToArray();

            var bulletsStack = new Stack<int>(bulletsInput);

            var locksInput = Console.ReadLine()
                .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse)
                .ToArray();

            var locksQueue = new Queue<int>(locksInput);

            var valueOfIntelligence = int.Parse(Console.ReadLine());

            var usedBullets = 0;
            while (bulletsStack.Count != 0 && locksQueue.Count != 0)
            {
                var currentBullet = bulletsStack.Peek();
                var currentLock = locksQueue.Peek();

                if (currentBullet <= currentLock)
                {
                    Console.WriteLine("Bang!");
                    locksQueue.Dequeue();
                    bulletsStack.Pop();
                }
                else
                {
                    Console.WriteLine("Ping!");
                    bulletsStack.Pop();
                }
                usedBullets++;
                if (usedBullets % gunBarrelSize == 0 && bulletsStack.Count > 0)
                {
                    Console.WriteLine("Reloading!");
                }
            }

            var bulletsCost = usedBullets * bulletPrice;
            var moneyEarned = valueOfIntelligence - bulletsCost;

            if (bulletsStack.Count == 0 && locksQueue.Count > 0)
            {
                Console.WriteLine($"Couldn't get through. Locks left: {locksQueue.Count}");
            }
            else
            {
                Console.WriteLine($"{bulletsStack.Count} bullets left. Earned ${moneyEarned}");
            }
        }

    }
}

redpajama_set_name: RedPajamaGithub


text:
require 'spec_helper'
require 'terminal-table'
require 'commander/import'
require 'utils/command_utils'

def load_commands
  Dir['lib/commands/**/*.rb'].each {|f|
    load File.join(File.dirname(__FILE__), '../../..', f)
    require File.join(File.dirname(__FILE__), '../../..', f.gsub(/.rb/, ''))
  }
end

def mock_terminal
  @input = StringIO.new
  @output = StringIO.new
  $terminal = HighLine.new @input, @output
end

def new_command_runner *args, &block
  Commander::Runner.instance_variable_set :"@singleton", Commander::Runner.new(args)
  program :version, '1.2.3'
  program :description, "Honey Badger Don't Care"
  yield if block
  Commander::Runner.instance
end

def run *args
  runner = new_command_runner(*args) do
    load_commands
  end
  runner.run!
  @output.string
end

RSpec::Matchers.define :exit_with_code do |exp_code|
  actual = nil
  match do |block|
    begin
      block.call
    rescue SystemExit => e
      actual = e.status
    end
    actual and actual == exp_code
  end
  failure_message_for_should do |block|
    "expected block to call exit(#{exp_code}) but exit" +
      (actual.nil? ? " not called" : "(#{actual}) was called")
  end
  failure_message_for_should_not do |block|
    "expected block not to call exit(#{exp_code})"
  end
  description do
    "expect block to call exit(#{exp_code})"
  end
end

def run_raw_command(*args)
  lambda{
    run(*args)
  }.should raise_error(SystemExit, ' ')
end

def run_command(*args, &block)
  begin
    run_raw_command *args
  rescue
    yield
  end
end


text:
'use strict';

var tartan = require('tartan');
var utils = require('../utils');

module.exports = {
  template: '
<canvas ref="canvas"></canvas>
',
  props: ['threadcount', 'schema', 'repeat'],
  watch: {
    threadcount: function() {
      this.$emit('update');
    },
    schema: function() {
      this.$emit('update');
    },
    repeat: function() {
      this.$emit('repaint');
    }
  },
  mounted: function() {
    var that = this;
    var render = null;

    var repaint = tartan.utils.repaint(function() {
      if (that.$refs.canvas) {
        render(that.$refs.canvas, null, that.repeat);
      }
    });

    var disableResize = utils.makeResizable(
      that.$refs.canvas.parentNode,
      function() {
        utils.updateCanvasSize(that.$refs.canvas);
        repaint.flush();
      }
    );

    that.$on('repaint', function() {
      repaint();
    });

    that.$on('update', function() {
      render = utils.createTartanRenderer(that.threadcount, that.schema);
      utils.updateCanvasSize(that.$refs.canvas);
      repaint.flush();
    });

    that.$on('destroy', function() {
      disableResize();
    });

    // Initial paint
    this.$emit('update');
  },
  beforeDestroy: function() {
    this.$emit('destroy');
  }
};


text:
id: security-overview
title: "Security overview"
description: Overiew of Apache Druid security. Includes best practices, configuration instructions, and a description of the security model.
---

<!--
  ~ 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.
  -->

This document provides an overview of Apache Druid security features, configuration instructions, and some best practices to secure Druid.

By default, security features in Druid are disabled, which simplifies the initial deployment experience. However, security features must be configured in a production deployment. These features include TLS, authentication, and authorization.

## Best practices

The following recommendations apply to the Druid cluster setup:
* Run Druid as an unprivileged Unix user. Do not run Druid as the root user.
   > **WARNING!** \
   Druid administrators have the same OS permissions as the Unix user account running Druid. See [Authentication and authorization model](security-user-auth.md#authentication-and-authorization-model). If the Druid process is running under the OS root user account, then Druid administrators can read or write all files that the root account has access to, including sensitive files such as `/etc/passwd`.
* Enable authentication to the Druid cluster for production environments and other environments that can be accessed by untrusted networks.
* Enable authorization and do not expose the Druid Console without authorization enabled. If authorization is not enabled, any user that has access to the web console has the same privileges as the operating system user that runs the Druid Console process.
* Grant users the minimum permissions necessary to perform their functions. For instance, do not allow users who only need to query data to write to data sources or view state.
* Disable JavaScript, as noted in the [Security section](https://druid.apache.org/docs/latest/development/javascript.html#security) of the JavaScript guide.

The following recommendations apply to the network where Druid runs:
* Enable TLS to encrypt communication within the cluster.
* Use an API gateway to:
  - Restrict access from untrusted networks
  - Create an allow list of specific APIs that your users need to access
  - Implement account lockout and throttling features.
* When possible, use firewall and other network layer filtering to only expose Druid services and ports specifically required for your use case. For example, only expose Broker ports to downstream applications that execute queries. You can limit access to a specific IP address or IP range to further tighten and enhance security.

The following recommendation applies to Druids authorization and authentication model:
* Only grant `WRITE` permissions to any `DATASOURCE` to trusted users. Druid's trust model assumes those users have the same privileges as the operating system user that runs the Druid Console process.
* Only grant `STATE READ`, `STATE WRITE`, `CONFIG WRITE`, and `DATASOURCE WRITE` permissions to highly-trusted users. These permissions allow users to access resources on behalf of the Druid server process regardless of the datasource.
* If your Druid client application allows less-trusted users to control the input source or firehose of an ingestion task, validate the URLs from the users. It is possible to point unchecked URLs to other locations and resources within your network or local file system.

## Enable TLS

Enabling TLS encrypts the traffic between external clients and the Druid cluster and traffic between services within the cluster.

### Generating keys
Before you enable TLS in Druid, generate the KeyStore and truststore. When one Druid process, e.g. Broker, contacts another Druid process , e.g. Historical, the first service is a client for the second service, considered the server.

The client uses a trustStore that contains certificates trusted by the client. For example, the Broker.

The server uses a KeyStore that contains private keys and certificate chain used to securely identify itself.

The following example demonstrates how to use Java keytool to generate the KeyStore for the server and then create a trustStore to trust the key for the client:

1. Generate the KeyStore with the Java `keytool` command:
```
$> keytool -keystore keystore.jks -alias druid -genkey -keyalg RSA
```
2. Export a public certificate:
```
$> keytool -export -alias druid -keystore keystore.jks -rfc -file public.cert
```
3. Create the trustStore:
```
$> keytool -import -file public.cert -alias druid -keystore truststore.jks
```

Druid uses Jetty as its embedded web server. See [Configuring SSL/TLS KeyStores
](https://www.eclipse.org/jetty/documentation/jetty-11/operations-guide/index.html#og-keystore) from the Jetty documentation.

   > WARNING: Do not use use self-signed certificates for production environments. Instead, rely on your current public key infrastructure to generate and distribute trusted keys.

### Update Druid TLS configurations
Edit `common.runtime.properties` for all Druid services on all nodes. Add or update the following TLS options. Restart the cluster when you are finished.

```
# Turn on TLS globally
druid.enableTlsPort=true

# Disable non-TLS communicatoins
druid.enablePlaintextPort=false

# For Druid processes acting as a client
# Load simple-client-sslcontext to enable client side TLS
# Add the following to extension load list
druid.extensions.loadList=[......., "simple-client-sslcontext"]

# Setup client side TLS
druid.client.https.protocol=TLSv1.2
druid.client.https.trustStoreType=jks
druid.client.https.trustStorePath=truststore.jks # replace with correct turstStore file
druid.client.https.trustStorePassword=secret123  # replace with your own password

# Setup server side TLS
druid.server.https.keyStoreType=jks
druid.server.https.keyStorePath=my-keystore.jks # replace with correct keyStore file
druid.server.https.keyStorePassword=secret123 # replace with your own password
druid.server.https.certAlias=druid

```
For more information, see [TLS support](tls-support.md) and [Simple SSLContext Provider Module](../development/extensions-core/simple-client-sslcontext.md).

## Authentication and authorization

You can configure authentication and authorization to control access to the Druid APIs. Then configure users, roles, and permissions, as described in the following sections. Make the configuration changes in the `common.runtime.properties` file on all Druid servers in the cluster.

Within Druid's operating context, authenticators control the way user identities are verified. Authorizers employ user roles to relate authenticated users to the datasources they are permitted to access. You can set the finest-grained permissions on a per-datasource basis.

The following graphic depicts the course of request through the authentication process:

![Druid security check flow](../assets/security-model-1.png "Druid security check flow")

## Enable an authenticator

To authenticate requests in Druid, you configure an Authenticator. Authenticator extensions exist for HTTP basic authentication, LDAP, and Kerberos.

The following takes you through sample configuration steps for enabling basic auth:

1. Add the `druid-basic-security` extension to `druid.extensions.loadList` in `common.runtime.properties`. For the quickstart installation, for example, the properties file is at `conf/druid/cluster/_common`:
   ```
   druid.extensions.loadList=["druid-basic-security", "druid-histogram", "druid-datasketches", "druid-kafka-indexing-service"]
   ```
2. Configure the basic Authenticator, Authorizer, and Escalator settings in the same common.runtime.properties file. The Escalator defines how Druid processes authenticate with one another.

An example configuration:
   ```
   # Druid basic security
   druid.auth.authenticatorChain=["MyBasicMetadataAuthenticator"]
   druid.auth.authenticator.MyBasicMetadataAuthenticator.type=basic

   # Default password for 'admin' user, should be changed for production.
   druid.auth.authenticator.MyBasicMetadataAuthenticator.initialAdminPassword=password1

   # Default password for internal 'druid_system' user, should be changed for production.
   druid.auth.authenticator.MyBasicMetadataAuthenticator.initialInternalClientPassword=password2

   # Uses the metadata store for storing users, you can use authentication API to create new users and grant permissions
   druid.auth.authenticator.MyBasicMetadataAuthenticator.credentialsValidator.type=metadata

   # If true and the request credential doesn't exists in this credentials store, the request will proceed to next Authenticator in the chain.
   druid.auth.authenticator.MyBasicMetadataAuthenticator.skipOnFailure=false

   druid.auth.authenticator.MyBasicMetadataAuthenticator.authorizerName=MyBasicMetadataAuthorizer

   # Escalator
   druid.escalator.type=basic
   druid.escalator.internalClientUsername=druid_system
   druid.escalator.internalClientPassword=password2
   druid.escalator.authorizerName=MyBasicMetadataAuthorizer

   druid.auth.authorizers=["MyBasicMetadataAuthorizer"]

   druid.auth.authorizer.MyBasicMetadataAuthorizer.type=basic
   ```

3. Restart the cluster.

See [Authentication and Authorization](../design/auth.md) for more information about the Authenticator, Escalator, and Authorizer concepts. See [Basic Security](../development/extensions-core/druid-basic-security.md) for more information about the extension used in the examples above, and [Kerberos](../development/extensions-core/druid-kerberos.md) for Kerberos authentication.

## Enable authorizers

After enabling the basic auth extension, you can add users, roles, and permissions via the Druid Coordinator `user` endpoint. Note that you cannot assign permissions directly to individual users. They must be assigned through roles.

The following diagram depicts the authorization model, and the relationship between users, roles, permissions, and resources.

![Druid Security model](../assets/security-model-2.png "Druid security model")

The following steps walk through a sample setup procedure:

> The default Coordinator API port is 8081 for non-TLS connections and 8281 for secured connections.

1. Create a user by issuing a POST request to `druid-ext/basic-security/authentication/db/MyBasicMetadataAuthenticator/users/<USERNAME>`, replacing USERNAME with the *new* username you are trying to create. For example:
  ```
   curl -u admin:password1 -XPOST https://my-coordinator-ip:8281/druid-ext/basic-security/authentication/db/basic/users/myname
  ```
  >  If you have TLS enabled, be sure to adjust the curl command accordingly. For example, if your Druid servers use self-signed certificates, you may choose to include the `insecure` curl option to forgo certificate checking for the curl command.
2. Add a credential for the user by issuing a POST to `druid-ext/basic-security/authentication/db/MyBasicMetadataAuthenticator/users/<USERNAME>/credentials`. For example:
    ```
    curl -u admin:password1 -H'Content-Type: application/json' -XPOST --data-binary @pass.json https://my-coordinator-ip:8281/druid-ext/basic-security/authentication/db/basic/users/myname/credentials
    ```
    The password is conveyed in the `pass.json` file in the following form:
   	```
   	{
      "password": "myname_password"
    }
    ```
2. For each authenticator user you create, create a corresponding authorizer user by issuing a POST request to `druid-ext/basic-security/authorization/db/MyBasicMetadataAuthorizer/users/<USERNAME>`. For example:
	```
	curl -u admin:password1 -XPOST https://my-coordinator-ip:8281/druid-ext/basic-security/authorization/db/basic/users/myname
	```
3. Create authorizer roles to control permissions by issuing a POST request to `druid-ext/basic-security/authorization/db/MyBasicMetadataAuthorizer/roles/<ROLENAME>`. For example:
	```
   curl -u admin:password1 -XPOST https://my-coordinator-ip:8281/druid-ext/basic-security/authorization/db/basic/roles/myrole
   ```
4. Assign roles to users by issuing a POST request to `druid-ext/basic-security/authorization/db/MyBasicMetadataAuthorizer/users/<USERNAME>/roles/<ROLENAME>`. For example:
	```
	curl -u admin:password1 -XPOST https://my-coordinator-ip:8281/druid-ext/basic-security/authorization/db/basic/users/myname/roles/myrole | jq
	```
5. Finally, attach permissions to the roles to control how they can interact with Druid at `druid-ext/basic-security/authorization/db/MyBasicMetadataAuthorizer/roles/<ROLENAME>/permissions`.
	For example:
	```
	curl -u admin:password1 -H'Content-Type: application/json' -XPOST --data-binary @perms.json https://my-coordinator-ip:8281/druid-ext/basic-security/authorization/db/basic/roles/myrole/permissions
	```
	The payload of `perms.json` should be in the form:
   	```
    [
    {
      "resource": {
        "name": "<PATTERN>",
        "type": "DATASOURCE"
      },
      "action": "READ"
    },
    {
      "resource": {
      "name": "STATE",
      "type": "STATE"
    },
    "action": "READ"
    }
    ]
    ```
    > Note: Druid treats the resource name as a regular expression (regex). You can use a specific datasource name or regex to grant permissions for multiple datasources at a time.

## Configuring an LDAP authenticator

As an alternative to using the basic metadata authenticator, you can use LDAP to authenticate users. The following steps provide an overview of the setup procedure. For more information on these settings, see [Properties for LDAP user authentication](../development/extensions-core/druid-basic-security.md#properties-for-ldap-user-authentication).

1. In `common.runtime.properties`, add LDAP to the authenticator chain in the order in which you want requests to be evaluated. For example:
   ```
   # Druid basic security
   druid.auth.authenticatorChain=["ldap", "MyBasicMetadataAuthenticator"]
   ```

2. Configure LDAP settings in `common.runtime.properties` as appropriate for your LDAP scheme and system. For example:
   ```
   druid.auth.authenticator.ldap.type=basic
   druid.auth.authenticator.ldap.enableCacheNotifications=true
   druid.auth.authenticator.ldap.credentialsValidator.type=ldap
   druid.auth.authenticator.ldap.credentialsValidator.url=ldap://ad_host:389
   druid.auth.authenticator.ldap.credentialsValidator.bindUser=ad_admin_user
   druid.auth.authenticator.ldap.credentialsValidator.bindPassword=ad_admin_password
   druid.auth.authenticator.ldap.credentialsValidator.baseDn=dc=example,dc=com
   druid.auth.authenticator.ldap.credentialsValidator.userSearch=(&(sAMAccountName=%s)(objectClass=user))
   druid.auth.authenticator.ldap.credentialsValidator.userAttribute=sAMAccountName
   druid.auth.authenticator.ldap.authorizerName=ldapauth
   druid.escalator.type=basic
   druid.escalator.internalClientUsername=ad_interal_user
   druid.escalator.internalClientPassword=Welcome123
   druid.escalator.authorizerName=ldapauth
   druid.auth.authorizers=["ldapauth"]
   druid.auth.authorizer.ldapauth.type=basic
   druid.auth.authorizer.ldapauth.initialAdminUser=<ad_initial_admin_user>
   druid.auth.authorizer.ldapauth.initialAdminRole=admin
   druid.auth.authorizer.ldapauth.roleProvider.type=ldap
   ```

3. Use the Druid API to create the group mapping and allocate initial roles. For example, using curl and given a group named `group1` in the directory, run:
   ```
   curl -i -v  -H "Content-Type: application/json" -u internal -X POST -d @groupmap.json http://localhost:8081/druid-ext/basic-security/authorization/db/ldapauth/groupMappings/group1map
   ```
   The `groupmap.json` file contents would be something like:
   ```
   {
     "name": "group1map",
     "groupPattern": "CN=group1,CN=Users,DC=example,DC=com",
     "roles": [
         "readRole"
     ]
   }
   ```
4. Check if the group mapping is created successfully by executing the following API. This lists all group mappings.
   ```
   curl -i -v  -H "Content-Type: application/json" -u internal -X GET http://localhost:8081/druid-ext/basic-security/authorization/db/ldapauth/groupMappings
   ```

   Alternatively, to check the details of a specific group mapping, use the following API:
   ```
   curl -i -v  -H "Content-Type: application/json" -u internal -X GET http://localhost:8081/druid-ext/basic-security/authorization/db/ldapauth/groupMappings/group1map
   ```

5. To add additional roles to the group mapping, use the following API:
   ```
   curl -i -v  -H "Content-Type: application/json" -u internal -X POST http://localhost:8081/druid-ext/basic-security/authorization/db/ldapauth/groupMappings/group1/roles/<newrole>
   ```

6. Add the LDAP user to Druid. To add a user, use the following authentication API:
   ```
   curl -i -v  -H "Content-Type: application/json" -u internal -X POST http://localhost:8081/druid-ext/basic-security/authentication/db/ldap/users/<ad_user>
   ```

7. Use the following command to assign the role to a user:
   ```
   curl -i -v  -H "Content-Type: application/json" -u internal -X POST http://localhost:8081/druid-ext/basic-security/authorization/db/ldapauth/users/<ad_user>/roles/<rolename>
   ```

Congratulations, you have configured permissions for user-assigned roles in Druid!

## Druid security trust model
Within Druid's trust model there users can have different authorization levels:
- Users with resource write permissions are allowed to do anything that the druid process can do.
- Authenticated read only users can execute queries against resources to which they have permissions.
- An authenticated user without any permissions is allowed to execute queries that don't require access to a resource.

Additionally, Druid operates according to the following principles:

From the inner most layer:
1. Druid processes have the same access to the local files granted to the specified system user running the process.
2. The Druid ingestion system can create new processes to execute tasks. Those tasks inherit the user of their parent process. This means that any user authorized to submit an ingestion task can use the ingestion task permissions to read or write any local files or external resources that the Druid process has access to.

> Note: Only grant the `DATASOURCE WRITE` to trusted users because they can act as the Druid process.

Within the cluster:
1. Druid assumes it operates on an isolated, protected network where no reachable IP within the network is under adversary control. When you implement Druid, take care to setup firewalls and other security measures to secure both inbound and outbound connections.
Druid assumes network traffic within the cluster is encrypted, including API calls and data transfers. The default encryption implementation uses TLS.
3. Druid assumes auxiliary services such as the metadata store and ZooKeeper nodes are not under adversary control.

Cluster to deep storage:
1. Druid does not make assumptions about the security for deep storage. It follows the system's native security policies to authenticate and authorize with deep storage.
2. Druid does not encrypt files for deep storage. Instead, it relies on the storage system's native encryption capabilities to ensure compatibility with encryption schemes across all storage types.

Cluster to client:
1. Druid authenticates with the client based on the configured authenticator.
2. Druid only performs actions when an authorizer grants permission. The default configuration is `allowAll authorizer`.


text:
This is an **OF-Config** 1.1 parser/encoder developed to enable support for
OF-Config in [LINC][linc] - OpenFlow software switch.

[linc]:
https://github.com/FlowForwarding/LINC-Switch


text:
package waldonsm.connect4.ai;

import java.util.List;
import java.util.Random;

import waldonsm.connect4.model.Connect4Model;

public class StupidAI implements Connect4AI {

	@Override
	public int chooseColumn(Connect4Model model) {
		Random rand = new Random();
		List<Integer> list = model.getAvailableMoves();
		return list.get(rand.nextInt(list.size()));
	}

	@Override
	public void newGame() {
		// does nothing
	}

}


text:
package com.fincatto.documentofiscal.cte300.transformes;

import com.fincatto.documentofiscal.cte300.classes.CTIndicadorTomador;
import org.simpleframework.xml.transform.Transform;

public class CTIndicadorTomadorTransformer implements Transform<CTIndicadorTomador> {

	@Override
    public CTIndicadorTomador read(String arg0) {
		// TODO Auto-generated method stub
		return CTIndicadorTomador.valueOfCodigo(arg0);
	}

	@Override
    public String write(CTIndicadorTomador arg0) {
		// TODO Auto-generated method stub
		return arg0.getCodigo();
	}

}


text:
<!DOCTYPE html>
<html  lang="en">

<head>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-97706544-2"></script>
    <script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-97706544-2');
    </script>
    <title>FruitBubbleShooters</title>
    <style type="text/css">
        html {
            overflow: auto;
        }

        html,
        body,
        div,
        iframe {
            margin: 0px;
            padding: 0px;
            height: 100%;
            border: none;
        }

        iframe {
            display: block;
            width: 100%;
            border: none;
            overflow-y: auto;
            overflow-x: hidden;
        }
    </style>
    <title>GuiGhost Games</title>
    <link rel="alternate" href="https://guighostgames.com/" hreflang="en-us" />
           <link rel="icon" type="image/png" sizes="40X40" href="https://guighostgames.com/MedievalFarms/images/UI/homeButton.png">

</head>

<body>

            <!------- GAME BODY SPACE START --------->
<iframe src="https://html5.gamemonetize.com/fp75y7agqkthpybch4d47026vxr8vqea/" width="310" height="540" scrolling="none" frameborder="0"></iframe>
</body>

</html>


text:
package graph

import (
	"bytes"
	"encoding/json"
	"io/ioutil"
	"os"
	"os/exec"
	"path"
)

var (
	openshiftDefaultExcludes = []string{
		"github.com/openshift/origin/images",
		"github.com/openshift/origin/pkg/build/builder",
	}

	openshiftImportPath = "github.com/openshift/origin"
)

type openShiftRepoInfo struct {
	Dir string
}

// getOpenShiftExcludes returns a list of known
// OpenShift-specific paths to exclude
func getOpenShiftExcludes() []string {
	return openshiftDefaultExcludes
}

// getOpenShiftFilters returns a list of known
// OpenShift-specific paths to use as filters
func getOpenShiftFilters() ([]string, error) {
	result := bytes.NewBuffer([]byte{})

	// obtain path to Origin repo
	goList := exec.Command("go", "list", "--json", "-f", "'{{ .Dir }}'", openshiftImportPath)
	goList.Stdout = result
	goList.Stderr = os.Stderr

	if err := goList.Run(); err != nil {
		return nil, err
	}

	info := &openShiftRepoInfo{}
	if err := json.Unmarshal(result.Bytes(), &info); err != nil {
		return nil, err
	}

	filters, err := listDirsN([]string{"pkg"}, 1, info.Dir, "")
	if err != nil {
		return nil, err
	}

	k8s, err := listDirsN([]string{"vendor/k8s.io"}, 1, info.Dir, "")
	if err != nil {
		return nil, err
	}
	filters = append(filters, k8s...)

	gopkg, err := listDirsN([]string{"vendor/gopkg.in"}, 1, info.Dir, "")
	if err != nil {
		return nil, err
	}
	filters = append(filters, gopkg...)

	github, err := listDirsN([]string{"vendor/github.com"}, 2, info.Dir, "")
	if err != nil {
		return nil, err
	}
	filters = append(filters, github...)

	vendor, err := listDirsN([]string{"vendor"}, 1, info.Dir, "")
	if err != nil {
		return nil, err
	}

	// filter out vendor pkgs we have expanded
	skip := map[string]bool{
		"vendor/k8s.io":     true,
		"vendor/gopkg.in":   true,
		"vendor/github.com": true,
	}
	for _, v := range vendor {
		if _, shouldSkip := skip[v]; shouldSkip {
			continue
		}
		filters = append(filters, v)
	}

	originFilters := []string{}
	for _, f := range filters {
		originFilters = append(originFilters, path.Join(openshiftImportPath, f))
	}

	return originFilters, nil
}

// listDirsN receives a list of directory names and returns
// up to N levels of nested directories for each one
func listDirsN(dirs []string, N int, root, prefix string) ([]string, error) {
	if N <= 0 {
		return dirs, nil
	}

	allDirs := []string{}
	for _, dir := range dirs {
		files, err := ioutil.ReadDir(path.Join(root, prefix, dir))
		if err != nil {
			return nil, err
		}

		childDirs := []string{}
		for _, f := range files {
			if !f.IsDir() {
				continue
			}

			childDirs = append(childDirs, f.Name())
		}

		nested, err := listDirsN(childDirs, N-1, root, path.Join(prefix, dir))
		if err != nil {
			return nil, err
		}

		for _, n := range nested {
			allDirs = append(allDirs, path.Join(dir, n))
		}
	}

	return allDirs, nil
}


text:
package org.pentaho.di.core.compress.snappy;

import java.io.IOException;
import java.io.InputStream;

import org.pentaho.di.core.compress.CompressionInputStream;
import org.pentaho.di.core.compress.CompressionProvider;
import org.xerial.snappy.SnappyInputStream;

public class SnappyCompressionInputStream extends CompressionInputStream {

  public SnappyCompressionInputStream( InputStream in, CompressionProvider provider ) throws IOException {
    super( getDelegate( in ), provider );
  }

  protected static SnappyInputStream getDelegate( InputStream in ) throws IOException {
    SnappyInputStream delegate = null;
    if ( in instanceof SnappyInputStream ) {
      delegate = (SnappyInputStream) in;
    } else {
      delegate = new SnappyInputStream( in );
    }
    return delegate;
  }

  @Override
  public void close() throws IOException {
    ( (SnappyInputStream) delegate ).close();
  }

  @Override
  public int read() throws IOException {
    return ( (SnappyInputStream) delegate ).read();
  }

  @Override
  public Object nextEntry() throws IOException {
    return null;
  }

}


text:
package com.fsck.k9.mail;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import static org.junit.Assert.assertEquals;

@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class AddressTest {
    /**
     * test the possibility to parse "From:" fields with no email.
     * for example: From: News for Vector Limited - Google Finance
     * http://code.google.com/p/k9mail/issues/detail?id=3814
     */
    @Test
    public void testParseWithMissingEmail() {
        Address[] addresses = Address.parse("NAME ONLY");
        assertEquals(1, addresses.length);
        assertEquals(null, addresses[0].getAddress());
        assertEquals("NAME ONLY", addresses[0].getPersonal());
    }

    /**
     * test name + valid email
     */
    @Test
    public void testPraseWithValidEmail() {
        Address[] addresses = Address.parse("Max Mustermann <maxmuster@mann.com>");
        assertEquals(1, addresses.length);
        assertEquals("maxmuster@mann.com", addresses[0].getAddress());
        assertEquals("Max Mustermann", addresses[0].getPersonal());
    }

    /**
     * test with multi email addresses
     */
    @Test
    public void testPraseWithValidEmailMulti() {
        Address[] addresses = Address.parse("lorem@ipsum.us,mark@twain.com");
        assertEquals(2, addresses.length);
        assertEquals("lorem@ipsum.us", addresses[0].getAddress());
        assertEquals(null, addresses[0].getPersonal());
        assertEquals("mark@twain.com", addresses[1].getAddress());
        assertEquals(null, addresses[1].getPersonal());
    }
}


text:
package com.jnape.palatable.lambda.semigroup.builtin;

import org.junit.Test;

import static com.jnape.palatable.lambda.semigroup.builtin.Max.max;
import static org.junit.Assert.assertEquals;

public class MaxTest {

    @Test
    public void semigroup() {
        assertEquals((Integer) 1, max(1, 0));
        assertEquals((Integer) 1, max(1, 1));
        assertEquals((Integer) 2, max(1, 2));
    }
}


text:
struct BSedge;
struct component;
struct BSsolution;
class BoruvkaSollins
{
	public:
		BoruvkaSollins(int nodes, int edges);
		void load(int (&e)[3]);
		void solve();
		void print();
		void printRaw();
		~BoruvkaSollins();

	private:
		int numNodes;
		int numEdges;

		//initialize a component forrest
		std::vector<component*> queue;

		//store the edges that lead to a solution
		std::vector<BSedge> solution;

		void printForest();
};

struct BSedge
{
	int FromNode;
	int toNode;
	int weight;

	friend bool operator>(BSedge &E1, BSedge &E2)
	{
		return E1.weight > E2.weight;
	}

	friend bool operator<(BSedge &E1, BSedge &E2)
	{
		return E1.weight < E2.weight;
	}

	friend bool operator>=(BSedge &E1, BSedge &E2)
	{
		return E1.weight >= E2.weight;
	}

	friend bool operator<=(BSedge &E1, BSedge &E2)
	{
		return E1.weight <= E2.weight;
	}

	friend bool operator==(BSedge &E1, BSedge &E2)
	{
		if(E1.FromNode == E2.toNode && E1.toNode == E2.FromNode && E1.weight == E2.weight)
			return true;

		return false;
	}

	friend std::ostream& operator<<(std::ostream &strm, const BSedge &e)
	{
  		return strm<< "From: " << e.FromNode << " To: " << e.toNode << " Weight: " << e.weight;
	}
};

struct component
{
	hblt<BSedge> * edges;
	std::vector<int> vertexs;
	bool isEmpty();

	component()
	{
		edges = new hblt<BSedge>();
	}

	~component()
	{
		delete edges;
	}
};

BoruvkaSollins::BoruvkaSollins(int nodes, int edges)
{
	numNodes = nodes;
	numEdges = edges;

	//initialize numNodes many slots for queue
	for(int i = 0; i < nodes; i++)
	{
		queue.push_back(0);
	}
}

BoruvkaSollins::~BoruvkaSollins()
{
	for(int i = 0; i < queue.size(); i++)
	{
		delete queue[i];
	}
};

void BoruvkaSollins::load(int (&e)[3])
{
	int weight = e[2];
	int nodeA = e[0];
	int nodeB = e[1];

	//case for when TA tries to point a node to itself because they like edge cases
	if(nodeA == nodeB)
	{
		return;
	}

	BSedge * edgeA = new BSedge();
	edgeA->weight = weight;
	edgeA->FromNode = nodeA;
	edgeA->toNode = nodeB;

	BSedge * edgeB = new BSedge();
	edgeB->weight = weight;
	edgeB->FromNode = nodeB;
	edgeB->toNode = nodeA;

	//tests out edge comparison functionality
	// std::cout << "Are they equal? " << (*edgeA == *edgeB) << std::endl;
	// std::cout << "queue[nodeA]: " << queue[nodeA] << " queue[nodeB]: " << queue[nodeB] << std::endl;

	//on loading the forest into queue, it will technically be 1 to 1.

	if(queue[nodeA] == 0)
	{
		queue[nodeA] = new component();
		queue[nodeA]->vertexs.push_back(nodeA);
	}

	if(queue[nodeB] == 0)
	{
		queue[nodeB] = new component();
		queue[nodeB]->vertexs.push_back(nodeB);
	}

	queue[nodeA]->edges->push(edgeA);

	queue[nodeB]->edges->push(edgeB);
}

void BoruvkaSollins::print()
{
	//printing backwards because supposedly order matters.... (I disagree because its a MST but whatever)
	std::cout << "BoruvkaSollins's MST:" << std::endl;

	if(numNodes == 1)
	{
		std::cout << "(0)" << std::endl;
		std::cout << "Totalweight: " << 0 << std::endl;
		return;
	}

	int totalweight = 0;
	for(int i = (solution.size()-1); i >= 0; i--)
	{
		totalweight+=solution[i].weight;
		if(solution[i].toNode <= solution[i].FromNode)
		{
			std::cout << "(" << solution[i].toNode << ", " << solution[i].FromNode << ")" << std::endl;
			continue;
		}

		std::cout << "(" << solution[i].FromNode << ", " << solution[i].toNode << ")" << std::endl;
	}
	std::cout << "Totalweight: " << totalweight << std::endl;
}

void BoruvkaSollins::solve()
{

	while(queue.size() != 1)
	{
		// //temp print queue: UNCOMMENT FOR DEBUG
		// std::cout << "print queue:" << std::endl;
		// for(int i = 0; i < queue.size(); i++)
		// {
		// 	component *print = queue[i];

		// 	std::cout << "Component " << i << ": ";

		// 	for(int j = 0; j < print->vertexs.size(); j++)
		// 	{
		// 		std::cout << (print->vertexs[j]) << ",    ";
		// 	}
		// 	std::cout<<"\n" << std::endl;
		// }
		// std::cout<<"\n" << std::endl;
		// //endtempprint

		//Take from back
		component * front = queue.back();
		BSedge * minEdge = front->edges->top();

		//figure out the node to add to this component
		int connectingTo = minEdge->toNode;

		//pop current minimum edge
		front->edges->pop();

		//Figure out where the vertex is in another component
		int componentWithVertexIndex = -1;

		bool found = false;
		for(int i = 0; i < (queue.size()-1); i++)
		{
			//make a temp pointer to check for vertex
			component* toCheck = queue[i];

			//check for vertex
			for(int j = 0; j < toCheck->vertexs.size(); j++)
			{
				//if we find vertex store in solution
				if(toCheck->vertexs[j] == connectingTo)
				{

					//store in solution
					BSedge sol;
					sol.FromNode = minEdge->FromNode;
					sol.toNode = connectingTo;
					sol.weight = minEdge->weight;
					solution.push_back(sol);

					componentWithVertexIndex = i;

					toCheck->edges->pop();

					found = true;
					break;
				}
			}

			if(found)
			{
				break;
			}
		}

		//once we found the component, we are going to transfer the vertexs and edges to the front component
		if(componentWithVertexIndex == -1)
		{
			std::cout << "\n!!This should never happen!!\n" << std::endl;
			return;
		}

		//This means that this component has the node we are looking for
		component* temp = queue[componentWithVertexIndex];

		//copy vertexs
		for(int i = 0; i < temp->vertexs.size(); i++)
		{
			front->vertexs.push_back(temp->vertexs[i]);
		}

		//copy edges
		for(int i = 0; i < temp->edges->size(); i++)
		{
			BSedge *top = temp->edges->top();
			front->edges->push(top);

			temp->edges->pop();
		}

		//remove component that was merged
		queue.erase(queue.begin() + componentWithVertexIndex);

		//pop off back and stick in the front
		queue.pop_back();

		//insert in front
		queue.insert(queue.begin(), front);

		delete temp;
	}

		// //temp print queue: UNCOMMENT FOR DEBUG
		// std::cout << "print queue:" << std::endl;
		// for(int i = 0; i < queue.size(); i++)
		// {
		// 	component *print = queue[i];

		// 	std::cout << "Component " << i << ": ";

		// 	for(int j = 0; j < print->vertexs.size(); j++)
		// 	{
		// 		std::cout << (print->vertexs[j]) << ",    ";
		// 	}
		// 	std::cout<<"\n" << std::endl;
		// }
		// std::cout<<"\n" << std::endl;
		// //endtempprint
}


text:
CREATE TABLE [stg].[FactRowCached]
(
	[PackageId] INT NOT NULL
	,[Component] varchar(255) NOT NULL
	,[RowCount] BIGINT NOT NULL
	,[DurationMilliSecond] INT NOT NULL
	,[MemoryAllocated] BIGINT NOT NULL
)


text:
package com.vmware.vim25;

/**
* @author Steve Jin (http://www.doublecloud.org)
* @version 5.1
*/

public class ArrayOfHostDiskConfigurationResult {
  public HostDiskConfigurationResult[] HostDiskConfigurationResult;

  public HostDiskConfigurationResult[] getHostDiskConfigurationResult() {
    return this.HostDiskConfigurationResult;
  }

  public HostDiskConfigurationResult getHostDiskConfigurationResult(int i) {
    return this.HostDiskConfigurationResult[i];
  }

  public void setHostDiskConfigurationResult(HostDiskConfigurationResult[] HostDiskConfigurationResult) {
    this.HostDiskConfigurationResult=HostDiskConfigurationResult;
  }
}


text:
'use strict';

module.exports = function(app) {
	var users = require('../../app/controllers/users');
	var pcs = require('../../app/controllers/pcs');

	// Pcs Routes
	app.route('/pcs')
		.get(users.requiresLogin, pcs.list)
		.post(users.requiresLogin, pcs.create);

	app.route('/pcs/:pcId')
		.get(pcs.read)
		.put(users.requiresLogin, pcs.hasAuthorization, pcs.update)
		.delete(users.requiresLogin, pcs.hasAuthorization, pcs.delete);

	// Finish by binding the Pc middleware
	app.param('pcId', pcs.pcByID);
};


text:
import React from 'react';
import PropTypes from 'prop-types';
import { FavoriteJobFormItem } from 'components';
import { Wrapper, Header, HeaderRow, ContentWrapper } from './styles';
const propTypes = {
  favoriteJobs: PropTypes.array.isRequired,
  handleRemove: PropTypes.func.isRequired,
  handleUpdate: PropTypes.func.isRequired,
};

const FavoriteJobList = ({ favoriteJobs, handleRemove, handleUpdate }) => (
  <Wrapper>
    <ul>
      <Header>
        <HeaderRow size="3">Job Summary</HeaderRow>
        <HeaderRow size="2">Interest</HeaderRow>
        <HeaderRow size="2">Status</HeaderRow>
        <HeaderRow size="2">Remarks</HeaderRow>
        <HeaderRow size="1">Action</HeaderRow>
      </Header>
    </ul>
    {renderFavoriteJobRows(favoriteJobs, handleRemove, handleUpdate)}
  </Wrapper>
  );

function renderFavoriteJobRows(favoriteJobs, remove, update) {
  return favoriteJobs.map((favoriteJob, index) => {
    const property = { ...favoriteJob, index, handleRemove: remove, handleUpdate: update };
    return <FavoriteJobFormItem key={favoriteJob.jobId} {...property} />;
  });
}

FavoriteJobList.propTypes = propTypes;
export default FavoriteJobList;


text:
import { shallow } from "enzyme";
import Immutable from "immutable";
import socket from "utils/socket";

import { JobState } from "@app/utils/jobsUtils";
import JobsContent from "./JobsContent";

describe("JobsContent", () => {
  let minimalProps;
  let commonProps;
  let context;
  const durationDetails = [
    {
      phaseID: -999999999,
      phaseName: "EXECUTION_PLANNING",
      phaseStartTime: "1622102234486",
      phaseDuraton: "173",
    },
    {
      phaseID: -999999999,
      phaseName: "RUNNING",
      phaseStartTime: "1622102234827",
      phaseDuraton: "2563",
    },
    {
      phaseID: -999999999,
      phaseName: "METADATA_RETRIEVAL",
      phaseStartTime: "1622102233273",
      phaseDuraton: "325",
    },
    {
      phaseID: -999999999,
      phaseName: "STARTING",
      phaseStartTime: "1622102234659",
      phaseDuraton: "168",
    },
    {
      phaseID: -999999999,
      phaseName: "ENGINE_START",
      phaseStartTime: "1622102234467",
      phaseDuraton: "0",
    },
    {
      phaseID: -999999999,
      phaseName: "PLANNING",
      phaseStartTime: "1622102233598",
      phaseDuraton: "869",
    },
    {
      phaseID: -999999999,
      phaseName: "PENDING",
      phaseStartTime: "1622102233265",
      phaseDuraton: "8",
    },
    {
      phaseID: -999999999,
      phaseName: "QUEUED",
      phaseStartTime: "1622102234467",
      phaseDuraton: "19",
    },
  ];
  beforeEach(() => {
    minimalProps = {
      onUpdateQueryState: sinon.spy(),
      loadItemsForFilter: sinon.spy(),
      loadNextJobs: sinon.spy(),
      askGnarly: sinon.spy(),
      location: {},
      queryState: Immutable.Map(),
    };
    commonProps = {
      ...minimalProps,
      jobId: "123",
      jobs: Immutable.fromJS([
        {
          id: "123",
          state: "COMPLETED",
          plannerEstimatedCost: 7897,
          nrConcurrentQueries: 896765,
          rowsScanned: 57632,
          rowsReturned: 687216,
          durationDetails,
        },
      ]),
    };
    context = {
      router: {
        push: sinon.spy(),
        replace: sinon.spy(),
      },
    };
  });

  it("should render with minimal props without exploding", () => {
    const wrapper = shallow(<JobsContent {...minimalProps} />);
    expect(wrapper).to.have.length(1);
  });

  it("should render JobsFilters", () => {
    const wrapper = shallow(<JobsContent {...commonProps} />, { context });
    expect(wrapper.find("JobsFilters")).to.have.length(1);
  });

  describe("#componentWillReceiveProps", () => {
    let wrapper;
    let instance;
    beforeEach(() => {
      wrapper = shallow(<JobsContent {...commonProps} />, { context });
      instance = wrapper.instance();
    });

    it("should call runActionForJobs with startListenToJob as a callback when jobs change", () => {
      sinon.stub(socket, "startListenToQVJobProgress");
      sinon.spy(instance, "runActionForJobs");

      wrapper.setProps(commonProps).setContext(context);
      const jobs = Immutable.fromJS([
        {
          id: "456",
          state: "RUNNING",
          plannerEstimatedCost: 7897,
          nrConcurrentQueries: 896765,
          rowsScanned: 57632,
          rowsReturned: 687216,
          durationDetails,
        },
      ]);
      expect(instance.runActionForJobs).to.not.be.called;
      wrapper.setProps({ jobId: "456", jobs }).setContext(context);
      expect(instance.runActionForJobs).to.be.calledOnce;
      expect(instance.runActionForJobs).to.be.calledWith(jobs, false);
      expect(socket.startListenToQVJobProgress).to.be.calledWith(
        jobs.getIn([0, "id"])
      );
      socket.startListenToQVJobProgress.restore();
    });
  });

  describe("#runActionForJobs", () => {
    it("should call callback for any running job", () => {
      const props = {
        ...commonProps,
        jobId: "456",
        jobs: Immutable.fromJS([
          {
            id: "456",
            state: "RUNNING",
            plannerEstimatedCost: 7897,
            nrConcurrentQueries: 896765,
            rowsScanned: 57632,
            rowsReturned: 687216,
            durationDetails,
          },
        ]),
      };
      const instance = shallow(<JobsContent {...props} />, {
        context,
      }).instance();

      const callbackList = [];
      const callback = (id) => {
        callbackList.push(id);
      };

      const jobs = Immutable.fromJS([
        { id: "1", state: JobState.COMPLETED },
        { id: "2", state: JobState.FAILED },
        { id: "3", state: JobState.CANCELED },
        { id: "4", state: JobState.CANCELLATION_REQUESTED },
        { id: "5", state: JobState.ENQUEUED },
        { id: "6", state: JobState.STARTING },
        { id: "7", state: JobState.RUNNING },
        { id: "8", state: JobState.PLANNING },
        { id: "9", state: JobState.NOT_SUBMITTED },
      ]);

      instance.runActionForJobs(jobs, false, callback);

      expect(callbackList).to.eql(["4", "5", "6", "7", "8", "9"]);
    });
  });

  describe("#componentWillUnmount", () => {
    it("should call runActionForJobs with stopListenToJob as a callback", () => {
      const props = {
        ...commonProps,
        jobId: "456",
        jobs: Immutable.fromJS([
          {
            id: "456",
            state: "RUNNING",
            plannerEstimatedCost: 7897,
            nrConcurrentQueries: 896765,
            rowsScanned: 57632,
            rowsReturned: 687216,
            durationDetails,
          },
        ]),
      };
      const instance = shallow(<JobsContent {...props} />, {
        context,
      }).instance();

      sinon.spy(socket, "stoptListenToQVJobProgress");
      sinon.spy(instance, "runActionForJobs");

      expect(instance.runActionForJobs).to.not.be.called;

      instance.componentWillUnmount();

      expect(instance.runActionForJobs).to.be.calledOnce;
      expect(instance.runActionForJobs).to.be.calledWith(props.jobs, true);
      expect(socket.stoptListenToQVJobProgress).to.be.calledWith(
        props.jobs.getIn([0, "id"])
      );
      socket.stoptListenToQVJobProgress.restore();
    });
  });
});


text:
using System;
using System.ComponentModel;

namespace Azure.ResourceManager.Network.Models
{
    /// <summary> Type of connection monitor. </summary>
    public readonly partial struct ConnectionMonitorType : IEquatable<ConnectionMonitorType>
    {
        private readonly string _value;

        /// <summary> Determines if two <see cref="ConnectionMonitorType"/> values are the same. </summary>
        public ConnectionMonitorType(string value)
        {
            _value = value ?? throw new ArgumentNullException(nameof(value));
        }

        private const string MultiEndpointValue = "MultiEndpoint";
        private const string SingleSourceDestinationValue = "SingleSourceDestination";

        /// <summary> MultiEndpoint. </summary>
        public static ConnectionMonitorType MultiEndpoint { get; } = new ConnectionMonitorType(MultiEndpointValue);
        /// <summary> SingleSourceDestination. </summary>
        public static ConnectionMonitorType SingleSourceDestination { get; } = new ConnectionMonitorType(SingleSourceDestinationValue);
        /// <summary> Determines if two <see cref="ConnectionMonitorType"/> values are the same. </summary>
        public static bool operator ==(ConnectionMonitorType left, ConnectionMonitorType right) => left.Equals(right);
        /// <summary> Determines if two <see cref="ConnectionMonitorType"/> values are not the same. </summary>
        public static bool operator !=(ConnectionMonitorType left, ConnectionMonitorType right) => !left.Equals(right);
        /// <summary> Converts a string to a <see cref="ConnectionMonitorType"/>. </summary>
        public static implicit operator ConnectionMonitorType(string value) => new ConnectionMonitorType(value);

        /// <inheritdoc />
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override bool Equals(object obj) => obj is ConnectionMonitorType other && Equals(other);
        /// <inheritdoc />
        public bool Equals(ConnectionMonitorType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);

        /// <inheritdoc />
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override int GetHashCode() => _value?.GetHashCode() ?? 0;
        /// <inheritdoc />
        public override string ToString() => _value;
    }
}


text:
package com.blacklocus.jres.model;

public class Shards {

    private Integer total;

    private Integer successful;

    private Integer failed;

    public Integer getTotal() {
        return total;
    }

    public Integer getSuccessful() {
        return successful;
    }

    public Integer getFailed() {
        return failed;
    }
}


text:
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as mkdirp from 'mkdirp';
import * as stream from 'stream';
import * as Promise from 'bluebird';

export function checkPathDoesNotExist(path: string): Promise<void> {
  return new Promise<void>((resolve: () => void, reject: (err) => void) => {
    fs.stat(path, (err, stats: fs.Stats) => {
      if (err) resolve();
      else reject(new Error('Path exists'));
    });
  });
}

export function unlinkNoErrAsync(path: string): Promise<void> {
  return new Promise<void>((resolve, reject) => {
    fs.unlink(path, err => resolve());
  });
}

export function hashStream(stream: stream.Readable): Promise<string> {
  return new Promise((resolve: (checksum: string) => void, reject: (err) => any) => {
    let hash: stream.Duplex = crypto.createHash('sha1');
    hash.setEncoding('hex');

    stream.on('end', () => {
      hash.end();
      resolve(hash.read().toString());
    });
    stream.on('error', reject);
    hash.on('error', reject);

    stream.pipe(hash);
  });
}

export function resolveOnOpen(emitter): Promise<any> {
  return new Promise((resolve, reject) => {
    emitter.on('open', resolve);
    emitter.on('error', reject);
  });
}

export const mkdirAsync   = Promise.promisify(fs.mkdir);
export const mkdirpAsync  = Promise.promisify(mkdirp);
export const readdirAsync = Promise.promisify(fs.readdir);
export const readFileAsync: (file: string, options?: {} | string) => Promise<string | Buffer> = Promise.promisify(fs.readFile);
export const symlinkAsync: (target: string, path: string, type?: string) => Promise<void> = Promise.promisify(fs.symlink);
export const writeFileAsync: (file: string, data: any, options?: {} | string) => Promise<{}> = Promise.promisify(fs.writeFile);


text:
set(dependencies
    TiDDS
)


text:
layout: doc_page
---

# Configuring Druid

This describes the common configuration shared by all Druid nodes. These configurations can be defined in the `common.runtime.properties` file.

## JVM Configuration Best Practices

There are four JVM parameters that we set on all of our processes:

1.  `-Duser.timezone=UTC` This sets the default timezone of the JVM to UTC. We always set this and do not test with other default timezones, so local timezones might work, but they also might uncover weird and interesting bugs. To issue queries in a non-UTC timezone, see [query granularities](../querying/granularities.html#period-granularities)
2.  `-Dfile.encoding=UTF-8` This is similar to timezone, we test assuming UTF-8. Local encodings might work, but they also might result in weird and interesting bugs.
3.  `-Djava.io.tmpdir=<a path>` Various parts of the system that interact with the file system do it via temporary files, and these files can get somewhat large. Many production systems are set up to have small (but fast) `/tmp` directories, which can be problematic with Druid so we recommend pointing the JVM's tmp directory to something with a little more meat.
4.  `-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager` This allows log4j2 to handle logs for non-log4j2 components (like jetty) which use standard java logging.

### Extensions

Many of Druid's external dependencies can be plugged in as modules. Extensions can be provided using the following configs:

|Property|Description|Default|
|--------|-----------|-------|
|`druid.extensions.directory`|The root extension directory where user can put extensions related files. Druid will load extensions stored under this directory.|`extensions` (This is a relative path to Druid's working directory)|
|`druid.extensions.hadoopDependenciesDir`|The root hadoop dependencies directory where user can put hadoop related dependencies files. Druid will load the dependencies based on the hadoop coordinate specified in the hadoop index task.|`hadoop-dependencies` (This is a relative path to Druid's working directory|
|`druid.extensions.hadoopContainerDruidClasspath`|Hadoop Indexing launches hadoop jobs and this configuration provides way to explicitly set the user classpath for the hadoop job. By default this is computed automatically by druid based on the druid process classpath and set of extensions. However, sometimes you might want to be explicit to resolve dependency conflicts between druid and hadoop.|null|
|`druid.extensions.loadList`|A JSON array of extensions to load from extension directories by Druid. If it is not specified, its value will be `null` and Druid will load all the extensions under `druid.extensions.directory`. If its value is empty list `[]`, then no extensions will be loaded at all. It is also allowed to specify absolute path of other custom extensions not stored in the common extensions directory.|null|
|`druid.extensions.searchCurrentClassloader`|This is a boolean flag that determines if Druid will search the main classloader for extensions.  It defaults to true but can be turned off if you have reason to not automatically add all modules on the classpath.|true|

### Zookeeper
We recommend just setting the base ZK path and the ZK service host, but all ZK paths that Druid uses can be overwritten to absolute paths.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.zk.paths.base`|Base Zookeeper path.|`/druid`|
|`druid.zk.service.host`|The ZooKeeper hosts to connect to. This is a REQUIRED property and therefore a host address must be supplied.|none|

#### Zookeeper Behavior

|Property|Description|Default|
|--------|-----------|-------|
|`druid.zk.service.sessionTimeoutMs`|ZooKeeper session timeout, in milliseconds.|`30000`|
|`druid.zk.service.compress`|Boolean flag for whether or not created Znodes should be compressed.|`true`|
|`druid.zk.service.acl`|Boolean flag for whether or not to enable ACL security for ZooKeeper. If ACL is enabled, zNode creators will have all permissions.|`false`|

#### Path Configuration
Druid interacts with ZK through a set of standard path configurations. We recommend just setting the base ZK path, but all ZK paths that Druid uses can be overwritten to absolute paths.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.zk.paths.base`|Base Zookeeper path.|`/druid`|
|`druid.zk.paths.propertiesPath`|Zookeeper properties path.|`${druid.zk.paths.base}/properties`|
|`druid.zk.paths.announcementsPath`|Druid node announcement path.|`${druid.zk.paths.base}/announcements`|
|`druid.zk.paths.liveSegmentsPath`|Current path for where Druid nodes announce their segments.|`${druid.zk.paths.base}/segments`|
|`druid.zk.paths.loadQueuePath`|Entries here cause historical nodes to load and drop segments.|`${druid.zk.paths.base}/loadQueue`|
|`druid.zk.paths.coordinatorPath`|Used by the coordinator for leader election.|`${druid.zk.paths.base}/coordinator`|
|`druid.zk.paths.servedSegmentsPath`|@Deprecated. Legacy path for where Druid nodes announce their segments.|`${druid.zk.paths.base}/servedSegments`|

The indexing service also uses its own set of paths. These configs can be included in the common configuration.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.zk.paths.indexer.base`|Base zookeeper path for |`${druid.zk.paths.base}/indexer`|
|`druid.zk.paths.indexer.announcementsPath`|Middle managers announce themselves here.|`${druid.zk.paths.indexer.base}/announcements`|
|`druid.zk.paths.indexer.tasksPath`|Used to assign tasks to middle managers.|`${druid.zk.paths.indexer.base}/tasks`|
|`druid.zk.paths.indexer.statusPath`|Parent path for announcement of task statuses.|`${druid.zk.paths.indexer.base}/status`|
|`druid.zk.paths.indexer.leaderLatchPath`|Used for Overlord leader election.|`${druid.zk.paths.indexer.base}/leaderLatchPath`|

If `druid.zk.paths.base` and `druid.zk.paths.indexer.base` are both set, and none of the other `druid.zk.paths.*` or `druid.zk.paths.indexer.*` values are set, then the other properties will be evaluated relative to their respective `base`.
For example, if `druid.zk.paths.base` is set to `/druid1` and `druid.zk.paths.indexer.base` is set to `/druid2` then `druid.zk.paths.announcementsPath` will default to `/druid1/announcements` while `druid.zk.paths.indexer.announcementsPath` will default to `/druid2/announcements`.

The following path is used for service discovery. It is **not** affected by `druid.zk.paths.base` and **must** be specified separately.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.discovery.curator.path`|Services announce themselves under this ZooKeeper path.|`/druid/discovery`|

### Exhibitor

[Exhibitor](https://github.com/Netflix/exhibitor/wiki) is a supervisor system for ZooKeeper.
Exhibitor can dynamically scale-up/down the cluster of ZooKeeper servers.
Druid can update self-owned list of ZooKeeper servers through Exhibitor without restarting.
That is, it allows Druid to keep the connections of Exhibitor-supervised ZooKeeper servers.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.exhibitor.service.hosts`|A JSON array which contains the hostnames of Exhibitor instances. Please specify this property if you want to use Exhibitor-supervised cluster.|none|
|`druid.exhibitor.service.port`|The REST port used to connect to Exhibitor.|`8080`|
|`druid.exhibitor.service.restUriPath`|The path of the REST call used to get the server set.|`/exhibitor/v1/cluster/list`|
|`druid.exhibitor.service.useSsl`|Boolean flag for whether or not to use https protocol.|`false`|
|`druid.exhibitor.service.pollingMs`|How ofter to poll the exhibitors for the list|`10000`|

Note that `druid.zk.service.host` is used as a backup in case an Exhibitor instance can't be contacted and therefore should still be set.

### Startup Logging

All nodes can log debugging information on startup.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.startup.logging.logProperties`|Log all properties on startup (from common.runtime.properties, runtime.properties, and the JVM command line).|false|
|`druid.startup.logging.maskProperties`|Masks sensitive properties (passwords, for example) containing theses words.|["password"]|

Note that some sensitive information may be logged if these settings are enabled.

### Request Logging

All nodes that can serve queries can also log the query requests they see.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.request.logging.type`|Choices: noop, file, emitter, slf4j, filtered, composing. How to log every query request.|noop|

Note that, you can enable sending all the HTTP requests to log by setting  "io.druid.jetty.RequestLog" to DEBUG level. See [Logging](../configuration/logging.html)

#### File Request Logging

Daily request logs are stored on disk.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.request.logging.dir`|Historical, Realtime and Broker nodes maintain request logs of all of the requests they get (interacton is via POST, so normal request logs don't generally capture information about the actual query), this specifies the directory to store the request logs in|none|

#### Emitter Request Logging

Every request is emitted to some external location.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.request.logging.feed`|Feed name for requests.|none|

#### SLF4J Request Logging

Every request is logged via SLF4J. Queries are serialized into JSON in the log message regardless of the SJF4J format specification. They will be logged under the class `io.druid.server.log.LoggingRequestLogger`.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.request.logging.setMDC`|If MDC entries should be set in the log entry. Your logging setup still has to be configured to handle MDC to format this data|false|
|`druid.request.logging.setContextMDC`|If the druid query `context` should be added to the MDC entries. Has no effect unless `setMDC` is `true`|false|

MDC fields populated with `setMDC`:

|MDC field|Description|
|---------|-----------|
|`queryId`   |The query ID|
|`dataSource`|The datasource the query was against|
|`queryType` |The type of the query|
|`hasFilters`|If the query has any filters|
|`remoteAddr`|The remote address of the requesting client|
|`duration`  |The duration of the query interval|
|`resultOrdering`|The ordering of results|
|`descending`|If the query is a descending query|

#### Filtered Request Logging
Filtered Request Logger filters requests based on a configurable query/time threshold. Only request logs where query/time is above the threshold are emitted.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.request.logging.queryTimeThresholdMs`|Threshold value for query/time in milliseconds.|0 i.e no filtering|
|`druid.request.logging.delegate`|Delegate request logger to log requests.|none|

#### Composite Request Logging
Composite Request Logger emits request logs to multiple request loggers.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.request.logging.loggerProviders`|List of request loggers for emitting request logs.|none|

### Enabling Metrics

Druid nodes periodically emit metrics and different metrics monitors can be included. Each node can overwrite the default list of monitors.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.monitoring.emissionPeriod`|How often metrics are emitted.|PT1m|
|`druid.monitoring.monitors`|Sets list of Druid monitors used by a node. See below for names and more information. For example, you can specify monitors for a Broker with `druid.monitoring.monitors=["com.metamx.metrics.SysMonitor","com.metamx.metrics.JvmMonitor"]`.|none (no monitors)|

The following monitors are available:

|Name|Description|
|----|-----------|
|`io.druid.client.cache.CacheMonitor`|Emits metrics (to logs) about the segment results cache for Historical and Broker nodes. Reports typical cache statistics include hits, misses, rates, and size (bytes and number of entries), as well as timeouts and and errors.|
|`com.metamx.metrics.SysMonitor`|This uses the [SIGAR library](http://www.hyperic.com/products/sigar) to report on various system activities and statuses. Make sure to add the [sigar library jar](https://repository.jboss.org/nexus/content/repositories/thirdparty-uploads/org/hyperic/sigar/1.6.5.132/sigar-1.6.5.132.jar) to your classpath if using this monitor.|
|`io.druid.server.metrics.HistoricalMetricsMonitor`|Reports statistics on Historical nodes.|
|`com.metamx.metrics.JvmMonitor`|Reports JVM-related statistics.|
|`io.druid.segment.realtime.RealtimeMetricsMonitor`|Reports statistics on Realtime nodes.|
|`io.druid.server.metrics.EventReceiverFirehoseMonitor`|Reports how many events have been queued in the EventReceiverFirehose.|
|`io.druid.server.metrics.QueryCountStatsMonitor`|Reports how many queries have been successful/failed/interrupted.|

### Emitting Metrics

The Druid servers [emit various metrics](../operations/metrics.html) and alerts via something we call an Emitter. There are three emitter implementations included with the code, a "noop" emitter, one that just logs to log4j ("logging", which is used by default if no emitter is specified) and one that does POSTs of JSON events to a server ("http"). The properties for using the logging emitter are described below.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.emitter`|Setting this value to "noop", "logging", or "http" will initialize one of the emitter modules. value "composing" can be used to initialize multiple emitter modules. |noop|

#### Logging Emitter Module

|Property|Description|Default|
|--------|-----------|-------|
|`druid.emitter.logging.loggerClass`|Choices: HttpPostEmitter, LoggingEmitter, NoopServiceEmitter, ServiceEmitter. The class used for logging.|LoggingEmitter|
|`druid.emitter.logging.logLevel`|Choices: debug, info, warn, error. The log level at which message are logged.|info|

#### Http Emitter Module

|Property|Description|Default|
|--------|-----------|-------|
|`druid.emitter.http.timeOut`|The timeout for data reads.|PT5M|
|`druid.emitter.http.flushMillis`|How often the internal message buffer is flushed (data is sent).|60000|
|`druid.emitter.http.flushCount`|How many messages the internal message buffer can hold before flushing (sending).|500|
|`druid.emitter.http.recipientBaseUrl`|The base URL to emit messages to. Druid will POST JSON to be consumed at the HTTP endpoint specified by this property.|none|

#### Composing Emitter Module

|Property|Description|Default|
|--------|-----------|-------|
|`druid.emitter.composing.emitters`|List of emitter modules to load e.g. ["logging","http"].|[]|

#### Graphite Emitter

To use graphite as emitter set `druid.emitter=graphite`. For configuration details please follow this [link](../development/extensions-contrib/graphite.html).

### Metadata Storage

These properties specify the jdbc connection and other configuration around the metadata storage. The only processes that connect to the metadata storage with these properties are the [Coordinator](../design/coordinator.html), [Indexing service](../design/indexing-service.html) and [Realtime Nodes](../design/realtime.html).

|Property|Description|Default|
|--------|-----------|-------|
|`druid.metadata.storage.type`|The type of metadata storage to use. Choose from "mysql", "postgresql", or "derby".|derby|
|`druid.metadata.storage.connector.connectURI`|The jdbc uri for the database to connect to|none|
|`druid.metadata.storage.connector.user`|The username to connect with.|none|
|`druid.metadata.storage.connector.password`|The password provider or String password used to connect with.|none|
|`druid.metadata.storage.connector.createTables`|If Druid requires a table and it doesn't exist, create it?|true|
|`druid.metadata.storage.tables.base`|The base name for tables.|druid|
|`druid.metadata.storage.tables.segments`|The table to use to look for segments.|druid_segments|
|`druid.metadata.storage.tables.rules`|The table to use to look for segment load/drop rules.|druid_rules|
|`druid.metadata.storage.tables.config`|The table to use to look for configs.|druid_config|
|`druid.metadata.storage.tables.tasks`|Used by the indexing service to store tasks.|druid_tasks|
|`druid.metadata.storage.tables.taskLog`|Used by the indexing service to store task logs.|druid_taskLog|
|`druid.metadata.storage.tables.taskLock`|Used by the indexing service to store task locks.|druid_taskLock|
|`druid.metadata.storage.tables.supervisors`|Used by the indexing service to store supervisor configurations.|druid_supervisors|
|`druid.metadata.storage.tables.audit`|The table to use for audit history of configuration changes e.g. Coordinator rules.|druid_audit|

#### Password Provider

Environment variable password provider provides password by looking at specified environment variable. Use this in order to avoid specifying password in runtime.properties file.
e.g

```json
{
    "type": "environment",
    "variable": "METADATA_STORAGE_PASSWORD"
}
```

The values are described below.

|Field|Type|Description|Required|
|-----|----|-----------|--------|
|`type`|String|password provider type|Yes: `environment`|
|`variable`|String|environment variable to read password from|Yes|

### Deep Storage

The configurations concern how to push and pull [Segments](../design/segments.html) from deep storage.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.storage.type`|Choices:local, noop, s3, hdfs, c*. The type of deep storage to use.|local|

#### Local Deep Storage

Local deep storage uses the local filesystem.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.storage.storageDirectory`|Directory on disk to use as deep storage.|/tmp/druid/localStorage|

#### Noop Deep Storage

This deep storage doesn't do anything. There are no configs.

#### S3 Deep Storage

This deep storage is used to interface with Amazon's S3.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.s3.accessKey`|The access key to use to access S3.|none|
|`druid.s3.secretKey`|The secret key to use to access S3.|none|
|`druid.storage.bucket`|S3 bucket name.|none|
|`druid.storage.baseKey`|S3 object key prefix for storage.|none|
|`druid.storage.disableAcl`|Boolean flag for ACL.|false|
|`druid.storage.archiveBucket`|S3 bucket name for archiving when running the indexing-service *archive task*.|none|
|`druid.storage.archiveBaseKey`|S3 object key prefix for archiving.|none|

#### HDFS Deep Storage

This deep storage is used to interface with HDFS.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.storage.storageDirectory`|HDFS directory to use as deep storage.|none|

#### Cassandra Deep Storage

This deep storage is used to interface with Cassandra.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.storage.host`|Cassandra host.|none|
|`druid.storage.keyspace`|Cassandra key space.|none|

### Caching

You can enable caching of results at the broker, historical, or realtime level using following configurations.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.cache.type`|`local`, `memcached`|The type of cache to use for queries.|`local`|
|druid.(broker|historical|realtime).cache.unCacheable|All druid query types|All query types to not cache.|["groupBy", "select"]|
|druid.(broker|historical|realtime).cache.useCache|Whether to use cache for getting query results.|false|
|druid.(broker|historical|realtime).cache.populateCache|Whether to populate cache.|false|

#### Local Cache

|Property|Description|Default|
|--------|-----------|-------|
|`druid.cache.sizeInBytes`|Maximum cache size in bytes. You must set this if you enabled populateCache/useCache, or else cache size of zero wouldn't really cache anything.|0|
|`druid.cache.initialSize`|Initial size of the hashtable backing the cache.|500000|
|`druid.cache.logEvictionCount`|If non-zero, log cache eviction every `logEvictionCount` items.|0|

#### Memcache

|Property|Description|Default|
|--------|-----------|-------|
|`druid.cache.expiration`|Memcached [expiration time](https://code.google.com/p/memcached/wiki/NewCommands#Standard_Protocol).|2592000 (30 days)|
|`druid.cache.timeout`|Maximum time in milliseconds to wait for a response from Memcached.|500|
|`druid.cache.hosts`|Comma separated list of Memcached hosts `<host:port>`.|none|
|`druid.cache.maxObjectSize`|Maximum object size in bytes for a Memcached object.|52428800 (50 MB)|
|`druid.cache.memcachedPrefix`|Key prefix for all keys in Memcached.|druid|

### Indexing Service Discovery

This config is used to find the [Indexing Service](../design/indexing-service.html) using Curator service discovery. Only required if you are actually running an indexing service.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.selectors.indexing.serviceName`|The druid.service name of the indexing service Overlord node. To start the Overlord with a different name, set it with this property. |druid/overlord|

### Coordinator Discovery

This config is used to find the [Coordinator](../design/coordinator.html) using Curator service discovery. This config is used by the realtime indexing nodes to get information about the segments loaded in the cluster.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.selectors.coordinator.serviceName`|The druid.service name of the coordinator node. To start the Coordinator with a different name, set it with this property. |druid/coordinator|

### Announcing Segments

You can configure how to announce and unannounce Znodes in ZooKeeper (using Curator). For normal operations you do not need to override any of these configs.

##### Batch Data Segment Announcer

In current Druid, multiple data segments may be announced under the same Znode.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.announcer.segmentsPerNode`|Each Znode contains info for up to this many segments.|50|
|`druid.announcer.maxBytesPerNode`|Max byte size for Znode.|524288|
|`druid.announcer.skipDimensionsAndMetrics`|Skip Dimensions and Metrics list from segment announcements. NOTE: Enabling this will also remove the dimensions and metrics list from coordinator and broker endpoints.|false|
|`druid.announcer.skipLoadSpec`|Skip segment LoadSpec from segment announcements. NOTE: Enabling this will also remove the loadspec from coordinator and broker endpoints.|false|

### JavaScript

Druid supports dynamic runtime extension through JavaScript functions. This functionality can be configured through
the following properties.

|Property|Description|Default|
|--------|-----------|-------|
|`druid.javascript.disabled`|Set to "true" to disable JavaScript functionality. This affects the JavaScript parser, filter, extractionFn, aggregator, post-aggregator, router strategy, and worker selection strategy.|false|

Please refer to the Druid JavaScript programming guide for guidelines
about using Druid's JavaScript functionality.


text:
module Blug
  module ArticlesHelper
  end
end


text:
<?php
/**
 * Any time access to somewhat denied
 *
 * @author Camper (cmd@adevel.com) on 29.04.2009
 */
class Exception_AccessDenied extends BaseException{}


text: The solution is: braindead


text:
"""
Block-level deplucation utility functions.
"""
from __future__ import division
from __future__ import absolute_import
from __future__ import print_function
import os
import subprocess
import glob
import hashlib

from damn_at.utilities import calculate_hash_for_file
from io import open

BLOCK_SIZE = 2048

def block_hashes_for_file(an_uri):
    """
    Calculate the hash for each block in the given file
    as well as the hash for the entire file and return it.
    :param an_uri: the URI pointing to the file
    :rtype: string, list<string>
    """
    try:
        hashes = []
        chksum = hashlib.sha1()
        with open(an_uri, 'rb') as filehandle:
            while True:
                buf = filehandle.read(BLOCK_SIZE)
                if not buf:
                    break
                chksum.update(buf)
                blockhash = hashlib.sha1()
                blockhash.update(buf)
                hashes.append(blockhash.hexdigest())
        return chksum.hexdigest(), hashes
    except IOError:
        return 'NOT_FOUND(%s)' % an_uri, []

def block_hashes_from_file(an_uri):
    """
    Deserialize the saved block hashes from the given file.
    :param an_uri: the URI pointing to the file
    :rtype: list<string>
    """
    with open(an_uri, 'rb') as filehandle:
        for line in filehandle.readlines()[1:]:
            yield line.strip()

def block_hashes_to_file(file_hash, block_hashes, an_uri):
    """
    Serialize the given block hashes to the given uri destination.
    :param file_hash: the complete file's hash
    :param block_hashes: a list of block hashes to serialize
    :param an_uri: the file path which to save to
    :rtype: list<string>
    """
    if not os.path.exists(os.path.dirname(an_uri)):
        os.makedirs(os.path.dirname(an_uri))
    with open(an_uri, 'wb') as filehandle:
        filehandle.write('%s %d\n'.encode('utf-8')
                         % (file_hash, len(block_hashes)))
        for hash in block_hashes:
            filehandle.write(hash + '\n'.encode('utf-8'))

def hash_to_dir(hash):
    """
    Transforms a given hash to a relative path and filename
    ex: '002badb952000339cdcf1b61a3205b221766bf49' ->
        '00/2badb952000339cdcf1b61a3205b221766bf49'
    :param hash: the hash to split
    :rtype: string
    """
    return hash[:2]+'/'+hash[2:]

def blocks_for_file(an_uri, destination):
    """
    Write all blocks for the given file to the destination.
    :param an_uri: the URI pointing to the file to split
    :param destination: the destination directory for the block files
    :rtype: list<string> the paths to the written blocks
    """
    try:
        paths = []
        with open(an_uri, 'rb') as filehandle:
            while True:
                buf = filehandle.read(BLOCK_SIZE)
                if not buf:
                    break
                blockhash = hashlib.sha1()
                blockhash.update(buf)
                hash = blockhash.hexdigest()
                path = os.path.join(destination, hash_to_dir(hash))
                paths.append(path)
                if os.path.exists(path):
                    # print 'Block exists'
                    continue

                if not os.path.exists(os.path.dirname(path)):
                    os.makedirs(os.path.dirname(path))
                with open(path, 'wb') as block:
                    block.write(buf)
        return paths
    except IOError:
        return 'NOT_FOUND(%s)' % an_uri

def blocks_to_file(an_uri, block_hashes, destination):
    """
    Combine the referenced blocks into a given destination file.
    :param an_uri: the directory containing the blocks
    :param block_hashes: a list of block hashes
    :param destination: the destination file path
    """
    if not os.path.exists(os.path.dirname(destination)):
        os.makedirs(os.path.dirname(destination))
    with open(destination, 'wb') as filehandle:
        for block_hash in block_hashes:
            with open(os.path.join(
                    an_uri, hash_to_dir(block_hash)), 'rb') as block:
                filehandle.write(block.read())

def filter_existing_block_hashes(an_uri, block_hashes):
    """
    Check the given uri if it contains the given
    blocks and filter out the existing.
    :param an_uri: the directory containing the blocks
    :param block_hashes: the list of block hashes to check for existence
    :rtype: list<string> a list of block hashes that do not exist
    """
    new_block_hashes = set([])
    dirs = os.listdir(an_uri)
    cache = {}
    for bloc_hash in block_hashes:
        prefix = bloc_hash[:2]
        if prefix not in dirs:
            new_block_hashes.add(bloc_hash)
        else:
            if prefix not in cache:
                cache[prefix] = os.listdir(os.path.join(an_uri, prefix))
            else:
                print(('from cache', bloc_hash))
            if bloc_hash[2:] not in cache[prefix]:
                new_block_hashes.add(bloc_hash)
    return new_block_hashes

def walk(uri):
    for root, dirs, files in os.walk(uri):
        if '.git' in dirs:
            dirs.remove('.git')
        for file_name in files:
            if file_name.startswith('.git'):
                files.remove(file_name)
                continue
            path = os.path.join(root, file_name)
            yield path

def statistics(uri):
    blocks = {}
    block_count = 0
    for path in walk(uri):
        for block_hash in block_hashes_from_file(path):
            if block_hash in blocks:
                blocks[block_hash].append(path)
                # print '  duplicate', file_hash, block_hash, path
            else:
                blocks[block_hash] = [path]
            block_count += 1

    print(('%d unique blocks with %d references' % (len(blocks), block_count)))
    saved = ((block_count-len(blocks))*BLOCK_SIZE) // 1024
    total = (block_count*BLOCK_SIZE) // 1024
    print(('saving %.2f KB on a total of %.2f KB' % (saved, total)))
    reuse = {}
    for block_hash, paths in blocks.items():
        if len(paths) in reuse:
            reuse[len(paths)] += 1
        else:
            reuse[len(paths)] = 1
    for paths, count in reuse.items():
        print(('%d files with %d reused blocks' % (count, paths)))

def verify(uri):
    for path in walk(uri):
        file_hash = os.path.basename(
            os.path.dirname(path)) + os.path.basename(path)
        new_file_hash = calculate_hash_for_file(path)
        print(('Verification %s %s'
               % (path, 'OK' if file_hash == new_file_hash else 'FAIL')))

if __name__ == '__main__':
    test_files_dir = os.path.join(os.path.dirname(__file__),
                                  '../../../peragro-test-files')
    for path in walk(test_files_dir):
        file_hash, block_hashes = block_hashes_for_file(path)
        block_hashes_to_file(file_hash, block_hashes,
                             '/tmp/files/'+hash_to_dir(file_hash))
        blocks_for_file(path, '/tmp/blocks')

    statistics('/tmp/files/')

    for path in walk(test_files_dir):
        file_hash = calculate_hash_for_file(path)
        block_hashes = block_hashes_from_file('/tmp/files/' +
                                              hash_to_dir(file_hash))
        new_path = '/tmp/out/'+os.path.basename(path)
        blocks_to_file('/tmp/blocks', block_hashes, new_path)

        new_file_hash = calculate_hash_for_file(new_path)
        print(('Verification %s'
               % ('OK' if file_hash == new_file_hash else 'FAIL')))

    verify('/tmp/blocks')

    block_hashes = ['b499ca988473a4abc0461717cc8d4ce8753aa6d9',  # exists
                    'b497ca988473a4abc0461717cc8d4ce8753aa6d9',
                    'b497ca988473a4abc0461717cc8d4ce8753aa6d9',
                    'b48e1faa27b06f8a6fabfd32c719d685accfccf4',  # exists
                    'b48e1faa27b06f8a6fabfd32c719d685accfccf4']

    print((filter_existing_block_hashes('/tmp/blocks', block_hashes)))


text:
from statistics import mean
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
import random

style.use('ggplot')

# xs = np.array([1, 2, 3, 4, 5], dtype=np.float64)
# ys = np.array([5, 4, 6, 5, 6], dtype=np.float64)

def create_dataset(hm, variance, step=2, correlation=False):
    val = 1
    ys = []
    for i in range(hm):
        y = val + random.randrange(-variance, variance)
        ys.append(y)
        if correlation and correlation == 'pos':
            val += step
        elif correlation and correlation == 'neg':
            val -= step
    xs = [i for i in range(len(ys))]
    return np.array(xs, dtype=np.float64), np.array(ys, dtype=np.float64)

def best_fit_slope_and_intercept(xs, ys):
    m = (((mean(xs) * mean(ys)) - mean(xs * ys)) /
         ((mean(xs) * mean(xs)) - mean(xs * xs)))
    b = mean(ys) - m * mean(xs)
    return m, b

def squared_error(ys_orig, ys_line):
    return sum((ys_line - ys_orig) * (ys_line - ys_orig))

def coefficient_of_determination(ys_orig, ys_line):
    y_mean_line = [mean(ys_orig) for y in ys_orig]
    squared_error_regr = squared_error(ys_orig, ys_line)
    squared_error_y_mean = squared_error(ys_orig, y_mean_line)
    return 1 - (squared_error_regr / squared_error_y_mean)

xs, ys = create_dataset(40, 40, 2, correlation='pos')

m, b = best_fit_slope_and_intercept(xs, ys)
regression_line = [(m * x) + b for x in xs]
predict_x = 8
propert_y = (m * predict_x) + b
r_squared = coefficient_of_determination(ys, regression_line)
print(r_squared)

plt.scatter(xs, ys, color='#003F72', label='data')
plt.scatter(predict_x, propert_y, color='g', label='predict')
plt.plot(xs, regression_line, label='regression line')
plt.legend(loc=4)
plt.show()