text:
DOCUMENTATION = '''
---
module: maas
short_description: Manage MAAS server configuration
options:
  maas:
    description:
      - URL of MAAS server
    default: http://localhost/MAAS/api/1.0/
  key:
    description:
      - MAAS API key
    required: yes
  options:
    description:
      - list of config options to query, this is only used for query
  enable_http_proxy: :
    description:
      - Enable the use of an APT and HTTP/HTTPS proxy.
  upstream_dns: :
    description:
      - Upstream DNS used to resolve domains not managed by this MAAS (space-separated IP addresses).
  default_storage_layout: :
    description:
      - Default storage layout.
    choices:
      - ['lvm', 'flat', 'bcache']
  default_osystem: :
    description:
      - Default operating system used for deployment.
  ports_archive: :
    description:
      - Ports archive.
  http_proxy: :
    description:
      - Proxy for APT and HTTP/HTTPS.
  boot_images_auto_import: :
    description:
      - Automatically import/refresh the boot images every 60 minutes.
  enable_third_party_drivers: :
    description:
      - Enable the installation of proprietary drivers (i.e. HPVSA).
  kernel_opts: :
    description:
      - Boot parameters to pass to the kernel by default.
  main_archive: :
    description:
      - Main archive
  maas_name: :
    description:
      - MAAS name.
  curtin_verbose: :
    description:
      - Run the fast-path installer with higher verbosity. This provides more detail in the installation logs..
  dnssec_validation: :
    description:
      - Enable DNSSEC validation of upstream zones.
  commissioning_distro_series: :
    description:
      - Default Ubuntu release used for commissioning.
  windows_kms_host: :
    description:
      - Windows KMS activation host.
  enable_disk_erasing_on_release: :
    description:
      - Erase nodes' disks prior to releasing..
  default_distro_series: :
    description:
      - Default OS release used for deployment.
  ntp_server: :
    description:
      - Address of NTP server for nodes.
  default_min_hwe_kernel: :
    description:
      - Default Minimum Kernel Version.
  state:
    description:
      - possible states for the module
    choices: ['present', 'query']
    default: present

requirements: [ipaddress, requests_oauthlib, maasclient]
author: David Bainbridge
'''

EXAMPLES = '''
examples:
  maas:
    maas: http://my.maas.server.com/MAAS/api/1.0/
    key: 'xBvr9dx5k7S52myufC:fqBXV7hJgXegNZDw9c:K8hsmL47XjAppfQy2pDVW7G49p6PELgp'
    options:
      - upstream_dns
      - ntp_servers
    state: query

  maas:
    maas: http://my.maas.server.com/MAAS/api/1.0/
    key: 'xBvr9dx5k7S52myufC:fqBXV7hJgXegNZDw9c:K8hsmL47XjAppfQy2pDVW7G49p6PELgp'
    upstream_dns: 8.8.8.8 8.8.8.4
    state: present
'''

import sys
import json
import ipaddress
import requests
from maasclient.auth import MaasAuth
from maasclient import MaasClient

# For some reason the maasclient doesn't provide a put method. So
# we will add it here
def put(client, url, params=None):
    return requests.put(url=client.auth.api_url + url,
                        auth=client._oauth(), data=params)

# Attempt to interpret the given value as a JSON object, if that fails
# just return it as a string
def string_or_object(val):
    try:
        return json.loads(val)
    except:
        return val

# Return a copy of the given dictionary with any `null` valued entries
# removed
def remove_null(d_in):
    d = d_in.copy()
    to_remove = []
    for k in d.keys():
        if d[k] == None:
            to_remove.append(k)
    for k in to_remove:
        del d[k]
    return d

# Deterine if two dictionaries are different
def different(have, want):
    have_keys = have.keys()
    for key in want.keys():
        if (key in have_keys and want[key] != have[key]) or key not in have_keys:
            return True
    return False

# Get configuration options from MAAS
def get_config(maas, desired):
    config = {}
    for o in desired.keys():
        res = maas.get('/maas/', dict(name=o, op='get_config'))
        if res.ok:
            val = json.loads(res.text)
            config[o] = val if val else ""
        else:
            config[o] = {'error': string_or_object(res.text)}
    return config

# Walk the list of options in the desired state setting those on MAAS
def update_config(maas, have, want):
    have_error = False
    status = {}
    for o in want.keys():
        if want[o] != have[o]:
            res = maas.post('/maas/', {'name': o, 'value': want[o], 'op': 'set_config'})
            if res.ok:
                status[o] = { 'error': False, 'status': want[o] }
            else:
                have_error = True
                status[o] = { 'error': True, 'status': string_or_object(res.text) }
    return {'error': have_error, 'status': status}

def main():
    module = AnsibleModule(
        argument_spec = dict(
            maas=dict(default='http://localhost/MAAS/api/1.0/'),
            key=dict(required=True),
            options=dict(required=False, type='list'),
            enable_http_proxy=dict(required=False),
            upstream_dns=dict(required=False),
            default_storage_layout=dict(required=False),
            default_osystem=dict(required=False),
            ports_archive=dict(required=False),
            http_proxy=dict(required=False),
            boot_images_auto_import=dict(required=False),
            enable_third_party_drivers=dict(required=False),
            kernel_opts=dict(required=False),
            main_archive=dict(required=False),
            maas_name=dict(required=False),
            curtin_verbose=dict(required=False),
            dnssec_validation=dict(required=False),
            commissioning_distro_series=dict(required=False),
            windows_kms_host=dict(required=False),
            enable_disk_erasing_on_release=dict(required=False),
            default_distro_series=dict(required=False),
            ntp_server=dict(required=False),
            default_min_hwe_kernel=dict(required=False),
            state=dict(default='present', choices=['present', 'query'])
        ),
        supports_check_mode = False
    )

    maas = module.params['maas']
    key = module.params['key']
    options = module.params['options']
    state = module.params['state']

    if state == 'query':
        desired = {x:None for x in options}
    else:
        # Construct a sparsely populate desired state
        desired = remove_null({
            'enable_http_proxy': module.params['enable_http_proxy'],
            'upstream_dns': module.params['upstream_dns'],
            'default_storage_layout': module.params['default_storage_layout'],
            'default_osystem': module.params['default_osystem'],
            'ports_archive': module.params['ports_archive'],
            'http_proxy': module.params['http_proxy'],
            'boot_images_auto_import': module.params['boot_images_auto_import'],
            'enable_third_party_drivers': module.params['enable_third_party_drivers'],
            'kernel_opts': module.params['kernel_opts'],
            'main_archive': module.params['main_archive'],
            'maas_name': module.params['maas_name'],
            'curtin_verbose': module.params['curtin_verbose'],
            'dnssec_validation': module.params['dnssec_validation'],
            'commissioning_distro_series': module.params['commissioning_distro_series'],
            'windows_kms_host': module.params['windows_kms_host'],
            'enable_disk_erasing_on_release': module.params['enable_disk_erasing_on_release'],
            'default_distro_series': module.params['default_distro_series'],
            'ntp_server': module.params['ntp_server'],
            'default_min_hwe_kernel': module.params['default_min_hwe_kernel'],
        })

    # Authenticate into MAAS
    auth = MaasAuth(maas, key)
    maas = MaasClient(auth)

    # Attempt to get the configuration from MAAS
    config = get_config(maas, desired)

    if state == 'query':
        # If this is a query, return the options
        module.exit_json(changed=False, found=True, maas=config)
    elif state == 'present':
        # If we want this to exists check to see if this is different and
        # needs updated
        if different(config, desired):
            res = update_config(maas, config, desired)
            if res['error']:
                module.fail_json(msg=res['status'])
            else:
                module.exit_json(changed=True, maas=res['status'])
        else:
            # No differences, to nothing to change
            module.exit_json(changed=False, maas=config)

# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
if __name__ == '__main__':
    main()


text:
Why Use Amalgam8?

The ability to route requests in a content/version-aware manner simplifies DevOps tasks such as canary and
        red/black deployments, A/B testing, and systematically testing resilience of microservices.

You can use the Amalgam8 platform with popular container runtimes like Docker, Kubernetes, Marathon/ Mesos, or your favorite cloud provider such as IBM Bluemix, Google Cloud Platform, or Amazon AWS.

redpajama_set_name: RedPajamaGithub


text: Simple off-canvas navigation menus


text:
{% load i18n %}
{% if not module.is_empty %}

        {% if module.show_title and module.title %}

{% if module.title_url %}{{ module.title|capfirst }}{% else %}
                {{ module.title|capfirst }}{% endif %}
{% endif %}

            {% spaceless %}

                    {% spaceless %}
                        {% for child in module.children %}

{{ child.action_time|date:"j M"}}

                                    {% comment %}{{ child.action_time|date }}{% endcomment %}
                                    {% if child.is_deletion %}
                                        {% if child.content_type %}{% filter capfirst %}
                                            {{ child.content_type.name }}{% endfilter %}
                                             {% endif %}{{ child.object_repr }}
                                    {% else %}

                                            {% if child.content_type %}{% filter capfirst %}{{ child.content_type.name }}
                                            {% endfilter %} {% endif %}

{{ child.object_repr }}

                                    {% endif %}

                        {% endfor %}
                    {% endspaceless %}

                {% if module.post_content %}

{{ module.post_content }}

                {% endif %}
            {% endspaceless %}

{% endif %}


text:
package com.izforge.izpack.integration.panelaction;

import com.izforge.izpack.api.data.InstallData;
import com.izforge.izpack.api.data.Panel;

/**
 * Pre-activation panel action.
 *
 * @author Tim Anderson
 */
public class PreActivatePanelAction extends TestPanelAction
{
    /**
     * Constructs a <tt>PreActivatePanelAction</tt>.
     *
     * @param panel       the panel
     * @param installData the installation data
     */
    public PreActivatePanelAction(Panel panel, InstallData installData)
    {
        super(panel, ActionStage.preactivate, installData);
    }

}


text:
#include <functional>
#include <btBulletDynamicsCommon.h>

namespace BtOgre {
class DebugDrawer;
}
namespace Ogre {
class SceneManager;
}

namespace ShipProject {
class GameObject;

typedef std::function<void (GameObject*,GameObject*,btManifoldPoint&)> CollisionLogic;

class PhysicsManager {
public:
	static PhysicsManager* reference() { return reference_ ? reference_ : reference_ = new PhysicsManager; }

	~PhysicsManager();

    void Initialize(const btVector3& grav, Ogre::SceneManager* sceneMgr);
    void Update(double dt);

    void AddBody(GameObject* obj);
    void RemoveBody(GameObject* obj);

    void set_debug_draw_enabled(bool enable);
    bool debug_draw_enabled();

    void set_collision_logic(CollisionLogic& logic) { col_logic_ = logic; }
    CollisionLogic& collision_logic() { return col_logic_; }

private:
	static PhysicsManager* reference_;

	PhysicsManager();

    btBroadphaseInterface* broadphase_;
    btDefaultCollisionConfiguration* config_;
    btCollisionDispatcher* dispatcher_;
    btSequentialImpulseConstraintSolver* solver_;
    btDiscreteDynamicsWorld* world_;

    BtOgre::DebugDrawer* debug_drawer_;

    CollisionLogic col_logic_;
};

}
#endif


text:
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>

#include "qiodevicedelegate_p.h"
#include "quriloader_p.h"

QT_BEGIN_NAMESPACE

using namespace QPatternist;

URILoader::URILoader(QObject *const parent,
                     const NamePool::Ptr &np,
                     const VariableLoader::Ptr &l) : QNetworkAccessManager(parent)
                                                   , m_variableNS(QLatin1String("tag:trolltech.com,2007:QtXmlPatterns:QIODeviceVariable:"))
                                                   , m_namePool(np)
                                                   , m_variableLoader(l)
{
    Q_ASSERT(m_variableLoader);
}

QNetworkReply *URILoader::createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData)
{
    const QString requestedUrl(req.url().toString());

    /* We got a QIODevice variable. */
    const QString name(requestedUrl.right(requestedUrl.length() - m_variableNS.length()));

    const QVariant variant(m_variableLoader->valueFor(m_namePool->allocateQName(QString(), name, QString())));

    if(!variant.isNull() && variant.userType() == qMetaTypeId<QIODevice *>())
        return new QIODeviceDelegate(qvariant_cast<QIODevice *>(variant));
    else
    {
        /* If we're entering this code path, the variable URI identified a variable
         * which we don't have, which means we either have a bug, or the user had
         * crafted an invalid URI manually. */

        return QNetworkAccessManager::createRequest(op, req, outgoingData);
    }
}

QT_END_NAMESPACE


text:
export EDITOR="code -w"

# Ensure languages are set
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

#Git
export GIT_DIFF_OPTS=-U999999

#Homebrew
export HOMEBREW_CASK_OPTS="--appdir=~/Applications"


text:
local cFunc = {};		-- Local Functions
local cSetting = {};	-- Local Settings

Settings = {};
Settings.__index = Settings;

--[[

]]

-- ///////////////////////////////
-- ///// New 				//////
-- ///// Returns: Object	//////
-- ///////////////////////////////

function Settings:New(...)
	local obj = setmetatable({}, {__index = self});
	if obj.Constructor then
		obj:Constructor(...);
	end
	return obj;
end

-- ///////////////////////////////
-- ///// StartResources		//////
-- ///// Returns: void		//////
-- ///////////////////////////////

function Settings:StartResources()
	local resources	=
	{
		["shader_flashlight_test"] 	= true,
		["shader_gloom1"]			= true,
		["bone_attach"]				= true,
		["helpmanager"]				= false,
	};

	logger:OutputInfo("(Re)starting Resources...");

	for res, _ in pairs(resources) do
		if(getResourceFromName(res)) then
			res = getResourceFromName(res);
			if(_ == true) then
				if(getResourceState(res) == "running") then
					restartResource(res);
				else
					startResource(res);
				end
			else
				if(getResourceState(res) == "running") then
					stopResource(res);
					logger:OutputInfo("Resource '"..getResourceName(res).."' was shut down (not allowed resource)");
				end
			end
		else
			logger:OutputInfo("URGENT: Resource '"..getResourceName(res).."' was not found! Please install.");
			stopResource(getThisResource())
		end
	end

end

-- ///////////////////////////////
-- ///// Constructor 		//////
-- ///// Returns: void		//////
-- ///////////////////////////////

function Settings:Constructor(...)
	setFPSLimit(60)
	setTime(0, 0)
	setMinuteDuration(99999999)
	setSkyGradient(0, 0, 0, 0, 0, 0)

	-- Restart and Start resouces --
	self:StartResources();
	logger:OutputInfo("[CALLING] Settings: Constructor");
end

-- EVENT HANDLER --


text:
public class QuickSelect {
    /*
     * partition function
     * array     : array on which partitioning has to be done
     * left      : left index of the partitioning subarray
     * right     : right index of the partitioning subarray
     * pivotIndex : pivot index from which partition has to done
     * return    : the index of the last element of the left subarray
     */
    private static int partition(int[] array, int left, int right, int pivotIndex) {
        int pivotValue = array[pivotIndex];
        int temp = array[right];
        array[right] = array[pivotIndex];
        array[pivotIndex] = temp;
        int storeIndex = left;
        while (left < right) {
            if (array[left] < pivotValue) {
                temp = array[storeIndex];
                array[storeIndex] = array[left];
                array[left] = temp;
                storeIndex++;
            }
            left++;
        }
        temp = array[right];
        array[right] = array[storeIndex];
        array[storeIndex] = temp;
        return storeIndex;
    }

    /*
     * Quick Select function
     * left        : left index of the subarray
     * right       : right index of the subarray
     * pos         : position to find the element using quick sort
     * return      : the value of element at pos place in the sorted array
     */
    public static int quickSelect(int[] array, int left, int right, int pos) {
        int pivotIndex;
        if(pos < 0 || pos >= array.length) {
            throw new IndexOutOfBoundsException("index: " + pos);
        }
        if (left == right) {
            return array[left];
        }
        pivotIndex = right - 1;
        pivotIndex = partition(array, left, right, pivotIndex);
        if (pos == pivotIndex) {
            return array[pivotIndex];
        }
        else if (pos < pivotIndex) {
            return quickSelect(array, left, pivotIndex - 1, pos);
        }
        else {
            return quickSelect(array, pivotIndex + 1, right, pos);
        }
    }

    public static void main(String[] args) {
        int[] array = {10, 5, 1, 6, 7, 3, 2, 4, 8, 9};
        System.out.println(quickSelect(array, 0, array.length - 1, 3));
    }

}


text:
<?php
/**
 * Created by PhpStorm.
 * User: christian
 * Date: 06/04/16
 * Time: 00:36
 */

namespace Core\Repository;

use bar\foo\baz\Object;
use Veloci\Core\Helper\Metadata\ModelAnalyzer;
use Veloci\Core\Helper\Metadata\ObjectMetadata;
use Veloci\Core\Model\EntityModel;
use Veloci\Core\Repository\KeyValueStore;
use Veloci\Core\Repository\MetadataRepositoryDefault;
use Veloci\User\User;

class MetadataRepositoryTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @test
     */
    public function shouldGetMetadata1()
    {
        $model = User::class;

        $objectMetadata = $this->mockObjectMetadata();

        $store = $this->mockKeyValueStore();

        $store
            ->shouldReceive('contains')
            ->once()
            ->with($model)
            ->andReturnTrue();

        $store
            ->shouldReceive('get')
            ->once()
            ->with($model)
            ->andReturn($objectMetadata);

        $analyzer = $this->mockModelAnalyzer();

        $metadataRepository = new MetadataRepositoryDefault($store, $analyzer);

        $data = $metadataRepository->getMetadata($model);

        \PHPUnit_Framework_Assert::assertEquals($objectMetadata, $data);
    }

    /**
     * @test
     */
    public function shouldGetMetadata2()
    {
        $model = User::class;

        $objectMetadata = $this->mockObjectMetadata();

        $store = $this->mockKeyValueStore();

        $store
            ->shouldReceive('contains')
            ->once()
            ->with($model)
            ->andReturnFalse();

        $store
            ->shouldReceive('set')
            ->once()
            ->with($model, $objectMetadata);

        $analyzer = $this->mockModelAnalyzer();

        $analyzer
            ->shouldReceive('analyze')
            ->once()
            ->with($model)
            ->andReturn($objectMetadata);

        $metadataRepository = new MetadataRepositoryDefault($store, $analyzer);

        $data = $metadataRepository->getMetadata($model);

        \PHPUnit_Framework_Assert::assertEquals($objectMetadata, $data);
    }

    /**
     * @test
     * @expectedException \InvalidArgumentException
     * @expectedExceptionMessage Invalid class. Accepted only MetadataAware instances
     */
    public function shouldRaiseException () {
        $model = \stdClass::class;

        $store = $this->mockKeyValueStore();
        $analyzer = $this->mockModelAnalyzer();

        $metadataRepository = new MetadataRepositoryDefault($store, $analyzer);

        $metadataRepository->getMetadata($model);
    }

    /**
     * @return \Mockery\MockInterface | KeyValueStore
     */
    private function mockKeyValueStore():KeyValueStore
    {
        return \Mockery::mock(KeyValueStore::class);
    }

    /**
     * @return \Mockery\MockInterface | ModelAnalyzer
     */
    private function mockModelAnalyzer():ModelAnalyzer
    {
        return \Mockery::mock(ModelAnalyzer::class);
    }

    private function mockObjectMetadata()
    {
        return \Mockery::mock(ObjectMetadata::class);
    }
}


text:
package org.fakereplace.api;

import java.util.List;

/**
 * interface that should be implemented by classes that with to be notified of
 * class changes.
 *
 *
 * @author stuart
 */
public interface ClassChangeAware {

    void afterChange(List<ChangedClass> changed, List<NewClassData> added);
}


text:
package org.apache.druid.query.movingaverage;

import org.apache.druid.data.input.MapBasedRow;
import org.apache.druid.data.input.Row;
import org.apache.druid.java.util.common.guava.Sequence;
import org.apache.druid.java.util.common.guava.Sequences;
import org.apache.druid.query.aggregation.AggregatorFactory;
import org.apache.druid.query.aggregation.FilteredAggregatorFactory;
import org.apache.druid.query.aggregation.LongSumAggregatorFactory;
import org.apache.druid.query.dimension.DefaultDimensionSpec;
import org.apache.druid.query.dimension.DimensionSpec;
import org.apache.druid.query.filter.DimFilter;
import org.apache.druid.query.filter.SelectorDimFilter;
import org.apache.druid.query.movingaverage.averagers.AveragerFactory;
import org.apache.druid.query.movingaverage.averagers.ConstantAveragerFactory;
import org.apache.druid.query.movingaverage.averagers.LongMeanAveragerFactory;
import org.joda.time.DateTime;
import org.joda.time.chrono.ISOChronology;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

/**
 *
 */
public class MovingAverageIterableTest
{
  private static final DateTime JAN_1 = new DateTime(2017, 1, 1, 0, 0, 0, 0, ISOChronology.getInstanceUTC());
  private static final DateTime JAN_2 = new DateTime(2017, 1, 2, 0, 0, 0, 0, ISOChronology.getInstanceUTC());
  private static final DateTime JAN_3 = new DateTime(2017, 1, 3, 0, 0, 0, 0, ISOChronology.getInstanceUTC());
  private static final DateTime JAN_4 = new DateTime(2017, 1, 4, 0, 0, 0, 0, ISOChronology.getInstanceUTC());
  private static final DateTime JAN_5 = new DateTime(2017, 1, 5, 0, 0, 0, 0, ISOChronology.getInstanceUTC());
  private static final DateTime JAN_6 = new DateTime(2017, 1, 6, 0, 0, 0, 0, ISOChronology.getInstanceUTC());

  private static final String GENDER = "gender";
  private static final String AGE = "age";
  private static final String COUNTRY = "country";

  private static final Map<String, Object> dims1 = new HashMap<>();
  private static final Map<String, Object> dims2 = new HashMap<>();
  private static final Map<String, Object> dims3 = new HashMap<>();

  static {
    dims1.put(GENDER, "m");
    dims1.put(AGE, "10");
    dims1.put(COUNTRY, "US");

    dims2.put(GENDER, "f");
    dims2.put(AGE, "8");
    dims2.put(COUNTRY, "US");

    dims3.put(GENDER, "u");
    dims3.put(AGE, "5");
    dims3.put(COUNTRY, "UK");
  }

  @Test
  public void testNext()
  {

    List<DimensionSpec> dims = Arrays.asList(
        new DefaultDimensionSpec(GENDER, GENDER),
        new DefaultDimensionSpec(AGE, AGE),
        new DefaultDimensionSpec(COUNTRY, COUNTRY)
    );

    Sequence<RowBucket> dayBuckets = Sequences.simple(Arrays.asList(
        new RowBucket(JAN_1, Arrays.asList(
            new MapBasedRow(JAN_1, dims1),
            new MapBasedRow(JAN_1, dims2)
        )),
        new RowBucket(JAN_2, Collections.singletonList(
            new MapBasedRow(JAN_2, dims1)
        )),
        new RowBucket(JAN_3, Collections.emptyList()),
        new RowBucket(JAN_4, Arrays.asList(
            new MapBasedRow(JAN_4, dims2),
            new MapBasedRow(JAN_4, dims3)
        ))
    ));

    Iterable<Row> iterable = new MovingAverageIterable(
        dayBuckets,
        dims,
        Collections.singletonList(new ConstantAveragerFactory("noop", 1, 1.1f)),
        Collections.emptyList(),
        Collections.emptyList()
    );

    Iterator<Row> iter = iterable.iterator();

    assertTrue(iter.hasNext());
    Row r = iter.next();
    assertEquals(JAN_1, r.getTimestamp());
    assertEquals("m", r.getRaw(GENDER));

    assertTrue(iter.hasNext());
    r = iter.next();
    assertEquals(JAN_1, r.getTimestamp());
    assertEquals("f", r.getRaw(GENDER));

    assertTrue(iter.hasNext());
    r = iter.next();
    assertEquals(JAN_2, r.getTimestamp());
    assertEquals("m", r.getRaw(GENDER));

    assertTrue(iter.hasNext());
    r = iter.next();
    assertEquals(JAN_2, r.getTimestamp());
    assertEquals("f", r.getRaw(GENDER));

    assertTrue(iter.hasNext());
    r = iter.next();
    Row r2 = r;
    assertEquals(JAN_3, r.getTimestamp());
    assertEquals("US", r.getRaw(COUNTRY));

    assertTrue(iter.hasNext());
    r = iter.next();
    assertEquals(JAN_3, r.getTimestamp());
    assertEquals("US", r.getRaw(COUNTRY));
    assertThat(r.getRaw(AGE), not(equalTo(r2.getRaw(AGE))));

    assertTrue(iter.hasNext());
    r = iter.next();
    assertEquals(JAN_4, r.getTimestamp());
    assertEquals("f", r.getRaw(GENDER));

    assertTrue(iter.hasNext());
    r = iter.next();
    assertEquals(JAN_4, r.getTimestamp());
    assertEquals("u", r.getRaw(GENDER));

    assertTrue(iter.hasNext());
    r = iter.next();
    assertEquals(JAN_4, r.getTimestamp());
    assertEquals("m", r.getRaw(GENDER));

    assertFalse(iter.hasNext());
  }

  @Test
  public void testAveraging()
  {

    Map<String, Object> event1 = new HashMap<>();
    Map<String, Object> event2 = new HashMap<>();
    Map<String, Object> event3 = new HashMap<>();
    Map<String, Object> event4 = new HashMap<>();

    List<DimensionSpec> ds = new ArrayList<>();
    ds.add(new DefaultDimensionSpec("gender", "gender"));

    event1.put("gender", "m");
    event1.put("pageViews", 10L);
    Row row1 = new MapBasedRow(JAN_1, event1);

    event2.put("gender", "m");
    event2.put("pageViews", 20L);
    Row row2 = new MapBasedRow(JAN_2, event2);

    event3.put("gender", "m");
    event3.put("pageViews", 30L);
    Row row3 = new MapBasedRow(JAN_3, event3);

    event4.put("gender", "f");
    event4.put("pageViews", 40L);
    Row row4 = new MapBasedRow(JAN_3, event4);

    float retval = 14.5f;

    Sequence<RowBucket> seq = Sequences.simple(Arrays.asList(
        new RowBucket(JAN_1, Collections.singletonList(row1)),
        new RowBucket(JAN_2, Collections.singletonList(row2)),
        new RowBucket(JAN_3, Arrays.asList(row3, row4))
    ));

    Iterator<Row> iter = new MovingAverageIterable(seq, ds, Arrays.asList(
        new ConstantAveragerFactory("costPageViews", 7, retval),
        new LongMeanAveragerFactory("movingAvgPageViews", 7, 1, "pageViews")
    ),
                                                   Collections.emptyList(),
                                                   Collections.singletonList(new LongSumAggregatorFactory("pageViews",
                                                                                "pageViews"
                                                   ))
    ).iterator();

    assertTrue(iter.hasNext());
    Row caResult = iter.next();

    assertEquals(JAN_1, caResult.getTimestamp());
    assertEquals("m", (caResult.getDimension("gender")).get(0));
    assertEquals(retval, caResult.getMetric("costPageViews").floatValue(), 0.0f);
    assertEquals(1.4285715f, caResult.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    caResult = iter.next();
    assertEquals("m", (caResult.getDimension("gender")).get(0));
    assertEquals(4.285714f, caResult.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    caResult = iter.next();
    assertEquals("m", (caResult.getDimension("gender")).get(0));
    assertEquals(8.571428f, caResult.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    caResult = iter.next();
    assertEquals("f", (caResult.getDimension("gender")).get(0));
    assertEquals(5.714285850f, caResult.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertFalse(iter.hasNext());

  }

  @Test
  public void testCompleteData()
  {

    Map<String, Object> event1 = new HashMap<>();
    Map<String, Object> event2 = new HashMap<>();
    Map<String, Object> event3 = new HashMap<>();

    event1.put("gender", "m");
    event1.put("pageViews", 10L);
    event2.put("gender", "f");
    event2.put("pageViews", 20L);
    event3.put("gender", "u");
    event3.put("pageViews", 30L);

    List<DimensionSpec> ds = new ArrayList<>();
    ds.add(new DefaultDimensionSpec("gender", "gender"));

    Row jan1Row1 = new MapBasedRow(JAN_1, event1);
    Row jan1Row2 = new MapBasedRow(JAN_1, event2);
    Row jan1Row3 = new MapBasedRow(JAN_1, event3);

    Row jan2Row1 = new MapBasedRow(JAN_2, event1);
    Row jan2Row2 = new MapBasedRow(JAN_2, event2);
    Row jan2Row3 = new MapBasedRow(JAN_2, event3);

    Sequence<RowBucket> seq = Sequences.simple(Arrays.asList(
        new RowBucket(JAN_1, Arrays.asList(jan1Row1, jan1Row2, jan1Row3)),
        new RowBucket(JAN_2, Arrays.asList(jan2Row1, jan2Row2, jan2Row3))
    ));

    Iterator<Row> iter = new MovingAverageIterable(seq, ds, Collections.singletonList(
        new LongMeanAveragerFactory("movingAvgPageViews", 2, 1, "pageViews")),
                                                   Collections.emptyList(),
                                                   Collections.singletonList(new LongSumAggregatorFactory("pageViews",
                                                                                "pageViews"
                                                   ))
    ).iterator();

    assertTrue(iter.hasNext());
    Row result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(JAN_1, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("f", (result.getDimension("gender")).get(0));
    assertEquals(JAN_1, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("u", (result.getDimension("gender")).get(0));
    assertEquals(JAN_1, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("f", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("u", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    assertFalse(iter.hasNext());

  }

  // no injection if the data missing at the begining
  @Test
  public void testMissingDataAtBeginning()
  {

    Map<String, Object> event1 = new HashMap<>();
    Map<String, Object> event2 = new HashMap<>();
    Map<String, Object> event3 = new HashMap<>();

    event1.put("gender", "m");
    event1.put("pageViews", 10L);
    event2.put("gender", "f");
    event2.put("pageViews", 20L);
    event3.put("gender", "u");
    event3.put("pageViews", 30L);

    List<DimensionSpec> ds = new ArrayList<>();
    ds.add(new DefaultDimensionSpec("gender", "gender"));

    Row jan1Row1 = new MapBasedRow(JAN_1, event1);

    Row jan2Row1 = new MapBasedRow(JAN_2, event1);
    Row jan2Row2 = new MapBasedRow(JAN_2, event2);
    Row jan2Row3 = new MapBasedRow(JAN_2, event3);

    Sequence<RowBucket> seq = Sequences.simple(Arrays.asList(
        new RowBucket(JAN_1, Collections.singletonList(jan1Row1)),
        new RowBucket(JAN_2, Arrays.asList(jan2Row1, jan2Row2, jan2Row3))
    ));

    Iterator<Row> iter = new MovingAverageIterable(seq, ds, Collections.singletonList(
        new LongMeanAveragerFactory("movingAvgPageViews", 2, 1, "pageViews")),
                                                   Collections.emptyList(),
                                                   Collections.singletonList(new LongSumAggregatorFactory("pageViews",
                                                                                "pageViews"
                                                   ))
    ).iterator();

    assertTrue(iter.hasNext());
    Row result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(JAN_1, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("f", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("u", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    assertFalse(iter.hasNext());
  }

  // test injection when the data is missing at the end
  @Test
  public void testMissingDataAtTheEnd()
  {

    Map<String, Object> event1 = new HashMap<>();
    Map<String, Object> event2 = new HashMap<>();
    Map<String, Object> event3 = new HashMap<>();

    event1.put("gender", "m");
    event1.put("pageViews", 10L);
    event2.put("gender", "f");
    event2.put("pageViews", 20L);
    event3.put("gender", "u");
    event3.put("pageViews", 30L);

    List<DimensionSpec> ds = new ArrayList<>();
    ds.add(new DefaultDimensionSpec("gender", "gender"));

    Row jan1Row1 = new MapBasedRow(JAN_1, event1);
    Row jan1Row2 = new MapBasedRow(JAN_1, event2);
    Row jan1Row3 = new MapBasedRow(JAN_1, event3);
    Row jan2Row1 = new MapBasedRow(JAN_2, event1);

    Sequence<RowBucket> seq = Sequences.simple(Arrays.asList(
        new RowBucket(JAN_1, Arrays.asList(jan1Row1, jan1Row2, jan1Row3)),
        new RowBucket(JAN_2, Collections.singletonList(jan2Row1))
    ));

    Iterator<Row> iter = new MovingAverageIterable(seq, ds, Collections.singletonList(
        new LongMeanAveragerFactory("movingAvgPageViews", 2, 1, "pageViews")),
                                                   Collections.emptyList(),
                                                   Collections.singletonList(new LongSumAggregatorFactory("pageViews",
                                                                                "pageViews"
                                                   ))
    ).iterator();

    assertTrue(iter.hasNext());
    Row result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(JAN_1, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("f", (result.getDimension("gender")).get(0));
    assertEquals(JAN_1, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("u", (result.getDimension("gender")).get(0));
    assertEquals(JAN_1, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("u", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("f", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    assertFalse(iter.hasNext());
  }

  // test injection when the data is missing in the middle
  @Test
  public void testMissingDataAtMiddle()
  {

    Map<String, Object> eventM = new HashMap<>();
    Map<String, Object> eventF = new HashMap<>();
    Map<String, Object> eventU = new HashMap<>();
    Map<String, Object> event4 = new HashMap<>();

    eventM.put("gender", "m");
    eventM.put("pageViews", 10L);
    eventF.put("gender", "f");
    eventF.put("pageViews", 20L);
    eventU.put("gender", "u");
    eventU.put("pageViews", 30L);

    List<DimensionSpec> ds = new ArrayList<>();
    ds.add(new DefaultDimensionSpec("gender", "gender"));

    Row jan1Row1M = new MapBasedRow(JAN_1, eventM);
    Row jan1Row2F = new MapBasedRow(JAN_1, eventF);
    Row jan1Row3U = new MapBasedRow(JAN_1, eventU);
    Row jan2Row1M = new MapBasedRow(JAN_2, eventM);
    Row jan3Row1M = new MapBasedRow(JAN_3, eventM);
    Row jan3Row2F = new MapBasedRow(JAN_3, eventF);
    Row jan3Row3U = new MapBasedRow(JAN_3, eventU);
    Row jan4Row1M = new MapBasedRow(JAN_4, eventM);

    Sequence<RowBucket> seq = Sequences.simple(Arrays.asList(
        new RowBucket(JAN_1, Arrays.asList(jan1Row1M, jan1Row2F, jan1Row3U)),
        new RowBucket(JAN_2, Collections.singletonList(jan2Row1M)),
        new RowBucket(JAN_3, Arrays.asList(jan3Row1M, jan3Row2F, jan3Row3U)),
        new RowBucket(JAN_4, Collections.singletonList(jan4Row1M))
    ));

    Iterator<Row> iter = new MovingAverageIterable(seq, ds, Collections.singletonList(
        new LongMeanAveragerFactory("movingAvgPageViews", 3, 1, "pageViews")),
                                                   Collections.emptyList(),
                                                   Collections.singletonList(new LongSumAggregatorFactory("pageViews",
                                                                                "pageViews"
                                                   ))
    ).iterator();

    // Jan 1
    assertTrue(iter.hasNext());
    Row result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(JAN_1, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("f", (result.getDimension("gender")).get(0));
    assertEquals(JAN_1, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("u", (result.getDimension("gender")).get(0));
    assertEquals(JAN_1, (result.getTimestamp()));

    // Jan 2
    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("u", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("f", (result.getDimension("gender")).get(0));
    assertEquals(JAN_2, (result.getTimestamp()));

    // Jan 3
    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(JAN_3, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("f", (result.getDimension("gender")).get(0));
    assertEquals(JAN_3, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("u", (result.getDimension("gender")).get(0));
    assertEquals(JAN_3, (result.getTimestamp()));

    // Jan 4
    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(JAN_4, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("u", (result.getDimension("gender")).get(0));
    assertEquals(JAN_4, (result.getTimestamp()));

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("f", (result.getDimension("gender")).get(0));
    assertEquals(JAN_4, (result.getTimestamp()));

    assertFalse(iter.hasNext());
  }

  @Test
  public void testMissingDaysAtBegining()
  {

    Map<String, Object> event1 = new HashMap<>();
    Map<String, Object> event2 = new HashMap<>();

    List<DimensionSpec> ds = new ArrayList<>();
    ds.add(new DefaultDimensionSpec("gender", "gender"));

    event1.put("gender", "m");
    event1.put("pageViews", 10L);
    Row row1 = new MapBasedRow(JAN_3, event1);

    event2.put("gender", "m");
    event2.put("pageViews", 20L);
    Row row2 = new MapBasedRow(JAN_4, event2);

    Sequence<RowBucket> seq = Sequences.simple(Arrays.asList(
        new RowBucket(JAN_1, Collections.emptyList()),
        new RowBucket(JAN_2, Collections.emptyList()),
        new RowBucket(JAN_3, Collections.singletonList(row1)),
        new RowBucket(JAN_4, Collections.singletonList(row2))
    ));

    Iterator<Row> iter = new MovingAverageIterable(seq, ds, Collections.singletonList(
        new LongMeanAveragerFactory("movingAvgPageViews", 4, 1, "pageViews")),
                                                   Collections.emptyList(),
                                                   Collections.singletonList(new LongSumAggregatorFactory("pageViews",
                                                                                "pageViews"
                                                   ))
    ).iterator();

    assertTrue(iter.hasNext());
    Row result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(2.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(7.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertFalse(iter.hasNext());
  }

  @Test
  public void testMissingDaysInMiddle()
  {
    System.setProperty("druid.generic.useDefaultValueForNull", "true");

    Map<String, Object> event1 = new HashMap<>();
    Map<String, Object> event2 = new HashMap<>();

    List<DimensionSpec> ds = new ArrayList<>();
    ds.add(new DefaultDimensionSpec("gender", "gender"));

    event1.put("gender", "m");
    event1.put("pageViews", 10L);
    Row row1 = new MapBasedRow(JAN_1, event1);

    event2.put("gender", "m");
    event2.put("pageViews", 20L);
    Row row2 = new MapBasedRow(JAN_4, event2);

    Sequence<RowBucket> seq = Sequences.simple(Arrays.asList(
        new RowBucket(JAN_1, Collections.singletonList(row1)),
        new RowBucket(JAN_2, Collections.emptyList()),
        new RowBucket(JAN_3, Collections.emptyList()),
        new RowBucket(JAN_4, Collections.singletonList(row2))
    ));

    Iterator<Row> iter = new MovingAverageIterable(seq, ds, Collections.singletonList(
        new LongMeanAveragerFactory("movingAvgPageViews", 4, 1, "pageViews")),
                                                   Collections.emptyList(),
                                                   Collections.singletonList(new LongSumAggregatorFactory("pageViews",
                                                                                "pageViews"
                                                   ))
    ).iterator();

    assertTrue(iter.hasNext());
    Row result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(2.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(2.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(2.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(7.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertFalse(iter.hasNext());
  }

  @Test
  public void testWithFilteredAggregation()
  {

    Map<String, Object> event1 = new HashMap<>();
    Map<String, Object> event2 = new HashMap<>();

    List<DimensionSpec> ds = new ArrayList<>();
    ds.add(new DefaultDimensionSpec("gender", "gender"));

    event1.put("gender", "m");
    event1.put("pageViews", 10L);
    Row row1 = new MapBasedRow(JAN_1, event1);

    event2.put("gender", "m");
    event2.put("pageViews", 20L);
    Row row2 = new MapBasedRow(JAN_4, event2);

    Sequence<RowBucket> seq = Sequences.simple(Arrays.asList(
        new RowBucket(JAN_1, Collections.singletonList(row1)),
        new RowBucket(JAN_2, Collections.emptyList()),
        new RowBucket(JAN_3, Collections.emptyList()),
        new RowBucket(JAN_4, Collections.singletonList(row2))
    ));

    AveragerFactory averagerfactory = new LongMeanAveragerFactory("movingAvgPageViews", 4, 1, "pageViews");
    AggregatorFactory aggregatorFactory = new LongSumAggregatorFactory("pageViews", "pageViews");
    DimFilter filter = new SelectorDimFilter("gender", "m", null);
    FilteredAggregatorFactory filteredAggregatorFactory = new FilteredAggregatorFactory(aggregatorFactory, filter);

    Iterator<Row> iter = new MovingAverageIterable(seq, ds, Collections.singletonList(
        averagerfactory),
                                                   Collections.emptyList(),
                                                   Collections.singletonList(
                                                       filteredAggregatorFactory)
    ).iterator();

    assertTrue(iter.hasNext());
    Row result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(2.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(2.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(2.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(7.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertFalse(iter.hasNext());
  }

  @Test
  public void testMissingDaysAtEnd()
  {
    System.setProperty("druid.generic.useDefaultValueForNull", "true");

    Map<String, Object> event1 = new HashMap<>();
    Map<String, Object> event2 = new HashMap<>();

    List<DimensionSpec> ds = new ArrayList<>();
    ds.add(new DefaultDimensionSpec("gender", "gender"));

    event1.put("gender", "m");
    event1.put("pageViews", 10L);
    Row row1 = new MapBasedRow(JAN_1, event1);

    event2.put("gender", "m");
    event2.put("pageViews", 20L);
    Row row2 = new MapBasedRow(JAN_2, event2);

    Sequence<RowBucket> seq = Sequences.simple(Arrays.asList(
        new RowBucket(JAN_1, Collections.singletonList(row1)),
        new RowBucket(JAN_2, Collections.singletonList(row2)),
        new RowBucket(JAN_3, Collections.emptyList()),
        new RowBucket(JAN_4, Collections.emptyList()),
        new RowBucket(JAN_5, Collections.emptyList()),
        new RowBucket(JAN_6, Collections.emptyList())
    ));

    Iterator<Row> iter = new MovingAverageIterable(seq, ds, Collections.singletonList(
        new LongMeanAveragerFactory("movingAvgPageViews", 4, 1, "pageViews")),
                                                   Collections.emptyList(),
                                                   Collections.singletonList(new LongSumAggregatorFactory("pageViews",
                                                                                "pageViews"
                                                   ))
    ).iterator();

    assertTrue(iter.hasNext());
    Row result = iter.next();

    assertEquals(JAN_1, result.getTimestamp());
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(2.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals(JAN_2, result.getTimestamp());
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(7.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals(JAN_3, result.getTimestamp());
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(7.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals(JAN_4, result.getTimestamp());
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(7.5f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals(JAN_5, result.getTimestamp());
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(5.0f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertTrue(iter.hasNext());
    result = iter.next();
    assertEquals(JAN_6, result.getTimestamp());
    assertEquals("m", (result.getDimension("gender")).get(0));
    assertEquals(0.0f, result.getMetric("movingAvgPageViews").floatValue(), 0.0f);

    assertFalse(iter.hasNext());

  }

}


text:
package com.spotify.scio.extra.sparkey.instances

import com.spotify.sparkey.SparkeyReader
import org.apache.beam.sdk.coders.Coder
import org.apache.beam.sdk.util.CoderUtils

import scala.jdk.CollectionConverters._

/**
 * Enhanced version of [[SparkeyReader]] that assumes the underlying Sparkey is encoded with the
 * given Coders, providing a very similar interface to Map[K, V].
 */
class SparkeyMap[K, V](val sparkey: SparkeyReader, val koder: Coder[K], val voder: Coder[V])
    extends SparkeyMapBase[K, V] {

  private def loadValueFromSparkey(key: K): V = {
    val value = sparkey.getAsByteArray(CoderUtils.encodeToByteArray(koder, key))
    if (value == null) {
      // This is fine since `SparkeyMapBase` defeats primitive specialization
      null.asInstanceOf[V]
    } else {
      CoderUtils.decodeFromByteArray(voder, value)
    }
  }

  override def get(key: K): Option[V] = Option(loadValueFromSparkey(key))

  override def iterator: Iterator[(K, V)] =
    sparkey.iterator.asScala.map { e =>
      val key = CoderUtils.decodeFromByteArray(koder, e.getKey)
      val value = CoderUtils.decodeFromByteArray(voder, e.getValue)
      (key, value)
    }

  def close(): Unit = sparkey.close()

  override def contains(key: K): Boolean =
    sparkey.getAsEntry(CoderUtils.encodeToByteArray(koder, key)) != null
}


text:
package strategy

import (
	log "github.com/Sirupsen/logrus"
	"github.com/intelsdi-x/snap/core"
)

import (
	"fmt"
	"time"
)

// config-based provides a strategy that selects plugin based on given config
type configBased struct {
	plugins     map[string]AvailablePlugin
	metricCache map[string]*cache
	logger      *log.Entry
	cacheTTL    time.Duration
}

func NewConfigBased(cacheTTL time.Duration) *configBased {
	return &configBased{
		metricCache: make(map[string]*cache),
		plugins:     make(map[string]AvailablePlugin),
		cacheTTL:    cacheTTL,
		logger: log.WithFields(log.Fields{
			"_module": "control-routing",
		}),
	}
}

// Select selects an available plugin using the config based plugin strategy.
func (cb *configBased) Select(aps []AvailablePlugin, id string) (AvailablePlugin, error) {
	if ap, ok := cb.plugins[id]; ok && ap != nil {
		return ap, nil
	}

	// add first one in case it's new id
	for _, ap := range aps {
		available := true
		for _, busyPlugin := range cb.plugins {
			if ap == busyPlugin {
				available = false
			}
		}
		if available {
			cb.plugins[id] = ap
			return ap, nil
		}
	}
	cb.logger.WithFields(log.Fields{
		"_block":   "findAvailablePlugin",
		"strategy": cb.String(),
		"error":    fmt.Sprintf("%v of %v plugins are available", len(aps)-len(cb.plugins), len(aps)),
	}).Error(ErrCouldNotSelect)
	return nil, ErrCouldNotSelect
}

// Remove selects a plugin and and removes it from the cache
func (cb *configBased) Remove(aps []AvailablePlugin, id string) (AvailablePlugin, error) {
	ap, err := cb.Select(aps, id)
	if err != nil {
		return nil, err
	}
	delete(cb.metricCache, id)
	delete(cb.plugins, id)
	return ap, nil
}

// String returns the strategy name.
func (cb *configBased) String() string {
	return "config-based"
}

// CacheTTL returns the TTL for the cache.
func (cb *configBased) CacheTTL(id string) (time.Duration, error) {
	return cb.cacheTTL, nil
}

// checkCache checks the cache for metric types.
// returns:
//  - array of metrics that need to be collected
//  - array of metrics that were returned from the cache
func (cb *configBased) CheckCache(mts []core.Metric, id string) ([]core.Metric, []core.Metric) {
	if _, ok := cb.metricCache[id]; !ok {
		cb.metricCache[id] = NewCache(cb.cacheTTL)
	}
	return cb.metricCache[id].checkCache(mts)
}

// updateCache updates the cache with the given array of metrics.
func (cb *configBased) UpdateCache(mts []core.Metric, id string) {
	if _, ok := cb.metricCache[id]; !ok {
		cb.metricCache[id] = NewCache(cb.cacheTTL)
	}
	cb.metricCache[id].updateCache(mts)
}

// AllCacheHits returns cache hits across all metrics.
func (cb *configBased) AllCacheHits() uint64 {
	var total uint64
	for _, cache := range cb.metricCache {
		total += cache.allCacheHits()
	}
	return total
}

// AllCacheMisses returns cache misses across all metrics.
func (cb *configBased) AllCacheMisses() uint64 {
	var total uint64
	for _, cache := range cb.metricCache {
		total += cache.allCacheMisses()
	}
	return total
}

// CacheHits returns the cache hits for a given metric namespace and version.
func (cb *configBased) CacheHits(ns string, version int, id string) (uint64, error) {
	if cache, ok := cb.metricCache[id]; ok {
		return cache.cacheHits(ns, version)
	}
	return 0, ErrCacheDoesNotExist
}

// CacheMisses returns the cache misses for a given metric namespace and version.
func (cb *configBased) CacheMisses(ns string, version int, id string) (uint64, error) {
	if cache, ok := cb.metricCache[id]; ok {
		return cache.cacheMisses(ns, version)
	}
	return 0, ErrCacheDoesNotExist
}


text:
var Entity = require('./entity'),
    inherits = require('inherits'),
    extend = require('xtend'),
    gameOptions = require('./game-options'),
    testIcon = document.getElementById('testicon'),
    bundleIcon = require('../img/me.png');

// This is how to load images as base64 url strings using browserify
//   this requires brfs transform to be run (e.g. browserify -t brfs index.js -o bundle.js)
// var fs = require('fs');
// it seems to have trouble if I put this in a variable list, but is ok in its own statement
// var bundleIcon = 'data:image/png;base64,' + fs.readFileSync(__dirname + '/../img/me.png', 'base64');

var bundleImg = new Image();
bundleImg.src = bundleIcon;

module.exports = Bubble;

inherits(Bubble, Entity);

var defaultOptions = {
  position: {
    x: 400,
    y: -100 },
  size: { x: 40, y: 40 },
  color: 'rgba(100, 100, 100, 0.25)',
  layer: 0,
  speed: 0.2,
  boundary: { bottom: parseInt(gameOptions.height, 10) + 100 },
  drawRectangle: false,
  value: 1
};

function Bubble(options) {
  options = extend({}, defaultOptions, options);
  Bubble.super_.call(this, options);
  this.velocity = { x: 0, y: options.speed };

  this.on('boundary-collision', function (boundary) {
    if (boundary === 'bottom') {
      this.remove();
    }
  });

  this.on('collision', function () {
    if (this.options.chain) {
      var newOptions = extend(
        {},
        this.options,
        {
          chain: this.options.chain - 1,
          position: {
            x: this.position.x,
            y: this.position.y - 100
          }
        }
      );
      (new Bubble(newOptions)).addTo(this.game);
    }
  });

  this.on('draw-local', this.drawCircle);
}

Bubble.prototype.drawCircle = function (context) {
  // temp: drawing test image
  var img = bundleImg ;// testIcon;
  context.drawImage(img, (this.size.x - img.width) / 2, (this.size.y - img.height) / 2);

  context.beginPath();
  context.arc(this.size.x / 2, this.size.y / 2, this.size.x / 2, 0, 2 * Math.PI, false);
  context.fillStyle = this.color;
  context.fill();
}


text:
local hash = joaat(argv[1])
local _a = GetEntityCoords(GetPlayerPed())
local retries = 3

while retries > 0 do
	RequestModel(hash)
	Wait(200)
	retries = retries -1
	if(HasModelLoaded(hash)) then
		retries = 0
	end
end

if(HasModelLoaded(hash)) then
	local veh = CreateVehicle(hash, _a)
	local ped = GetPlayerPed()
	SetPedIntoVehicle(ped, veh)
else
	print("Model didn't load")
end


text:
RequestCorrelation
==================

Note:  this product is deprecated.   Use RequestCorrelationSlf4J instead.

This project is a Java library that facilitates establishing and tracking correlation ids for micro-services.

The objectives are as follows:

* Ensure that a correlation id is assigned for each transaction (will be generated if not on service request).
* Ensure that the correlation id is documented on all log messages so that it can be correlated across services.
* Insulate micro-service code from having to be concerned with correlation ids at all.

This product has two components:

* Servlet filter to maintain the correlation id
* Extensions (Log4J and Logback) to ensure correlation id publishing in the log

System Requirements
-------------------

* Java JDK 6.0 or above (it was compiled under JDK 7 using 1.6 as the target source).
* Apache Commons Lang version 3.0 or above
* Either Log4J V1.x or Logback logging configuration

Installation Instructions
-------------------------
RequestCorrelation is easy to install whether you use maven or not.  There are two artifacts: one jar for RequestCorrelation-core and another to support either log4J v1.x or Logback logging configurations.

### Maven Users
Maven users must list two dependencies:
* RequestCorrelation-core -- [dependency information](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22RequestCorrelation-core%22).
* RequestCorrelation [log4j](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22RequestCorrelation-log4j-1x%22) or [logback](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22RequestCorrelation-logback%22)

### Non-Maven Users
Include the following jars in your class path:
* Download the RequestCorrelation-core jar and either the jog4j or logback companion jars from [Github](https://github.com/Derek-Ashmore/RequestCorrelation/releases) and put them in your class path.
* Insure Apache Commons Lang version 3.0 or above is in your class path.

Filter configuration
---------------------------
The correlation id must be established or set at service entry.  For RESTful or SOAP service requests, this is accomplished by servlet filter.

A sample web.xml filter configuration is as follows:
```

	<filter>
		<filter-name>correlationIdFilter</filter-name>
		<filter-class>org.force66.correlate.RequestCorrelationFilter</filter-class>
		<init-param>  <!-- Optional: 'requestCorrelationId' is the default -->
			<param-name>correlation.id.header</param-name>
			<param-value>CorrelationId</param-value>
		</init-param>
	</filter>

	<filter-mapping>
		<filter-name>correlationIdFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

```

For work that is initiated either by a message receiver or batch job, ensure that a line of code like the following gets executed in the thread performing the work (the correlation id is stored using a ThreadLocal):
```

RequestCorrelationContext.getCurrent().setCorrelationId(correlationId);

```

Log4J configuration
--------------------------

If you specify the layout class as org.force66.correlate.log4j.CorrelationPatternLayout, then you
can use the pattern marker %I to insert the correlation id on the log message
```

log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.force66.correlate.log4j.CorrelationPatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %I %-5p %c{1}:%L - %m%n

```

Logback configuration
---------------------
If you specify the custom encoder org.force66.correlate.logback.CorrelationPatternLayoutEncoder,
then you can use the %id or %correlationId markers to insert the correlation id in the log message.

```XML

	<!-- Send debug messages to System.out -->
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<encoder class="org.force66.correlate.logback.CorrelationPatternLayoutEncoder">
			<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} %id - %msg%n</pattern>
		</encoder>
	</appender>

```


text:
<?php

$texte="
Bienvenue sur IX-TEAM, le nouveau portail pour les Gamer'z.

A partir de ce site, vous pouvez suivre l'actu du développement de notre portail, et tester les modules que nous codons au fur et à mesure moi (YoTsumi) et Phoenix.

Si vous avez des talents en Codage, Design, Traduction, n'hésitez pas à nous contacter.

Etat d'avancement :IIIIIIIIIIIIIIIIIIIII

Déjà programmé :

   - [14.05.05] Nouvelle Shoutbox, Stats Serveur

  - [01.05.05] Système de News avec Commentaires, Messagerie Privé

  - [08.04.05] Mon Compte, Profil, mes Options

  - [08.04.05] Administration des membres

  - [29.03.05] Module Match utilisateur et admin

  - [29.03.05] Inscription, Login & Espace admin

  - [28.03.05] Système de gestion des thèmes

  - [25.03.05] Architecture du site

En cours de codage :

  - Téléchargements

  - Calendrier

Prévu à coder :

  - Modules spécials teams : défier, membres ...

  - Module Article, Téléchargement, Gallerie, Annuaire

  - Et pleins d'autres choses !

Design en cours :

  - Revelation

  - Suspiction Game

  - Reality Dream
";

$afficher->AddSession($handle,"contenu");
$afficher->setVar($handle,"contenu.module_titre","Info sur le codage");
$afficher->setVar($handle,"contenu.module_texte",$texte);
$afficher->CloseSession($handle,"contenu");

?>


text:
from oslo_config import cfg
from oslo_log import log as logging

from sahara import conductor as c
from sahara import context
from sahara.i18n import _
from sahara.i18n import _LI
from sahara.plugins import exceptions as ex
from sahara.plugins.hdp import hadoopserver as h
from sahara.plugins.hdp import saharautils as utils
from sahara.plugins.hdp.versions import versionhandlerfactory as vhf
from sahara.plugins import provisioning as p
from sahara.topology import topology_helper as th
from sahara.utils import cluster_progress_ops as cpo
from sahara.utils import general as g

conductor = c.API
LOG = logging.getLogger(__name__)
CONF = cfg.CONF

class AmbariPlugin(p.ProvisioningPluginBase):
    def __init__(self):
        self.cluster_ambari_mapping = {}
        self.version_factory = vhf.VersionHandlerFactory.get_instance()

    def create_cluster(self, cluster):
        version = cluster.hadoop_version
        handler = self.version_factory.get_version_handler(version)

        cluster_spec = handler.get_cluster_spec(
            cluster, self._map_to_user_inputs(
                version, cluster.cluster_configs))
        hosts = self._get_servers(cluster)
        ambari_info = self.get_ambari_info(cluster_spec)
        self.cluster_ambari_mapping[cluster.name] = ambari_info
        rpm = self._get_rpm_uri(cluster_spec)

        servers = []
        for host in hosts:
            host_role = utils.get_host_role(host)
            servers.append(
                h.HadoopServer(host, cluster_spec.node_groups[host_role],
                               ambari_rpm=rpm))

        self._provision_cluster(
            cluster.name, cluster_spec, ambari_info, servers,
            cluster.hadoop_version)

        # add the topology data file and script if rack awareness is
        # enabled
        self._configure_topology_for_cluster(cluster, servers)

        LOG.info(_LI("Install of Hadoop stack successful."))
        # add service urls
        self._set_cluster_info(cluster, cluster_spec)

        # check if HDFS HA is enabled; set it up if so
        if cluster_spec.is_hdfs_ha_enabled(cluster):
            cluster = g.change_cluster_status(cluster, "Configuring HA")
            self.configure_hdfs_ha(cluster)

    @cpo.event_wrapper(
        True, step=_("Add configurations to cluster"), param=('cluster', 1))
    def configure_hdfs_ha(self, cluster):
        version = cluster.hadoop_version
        handler = self.version_factory.get_version_handler(version)

        cluster_spec = handler.get_cluster_spec(
            cluster, self._map_to_user_inputs(
                version, cluster.cluster_configs))
        hosts = self._get_servers(cluster)
        ambari_info = self.get_ambari_info(cluster_spec)
        self.cluster_ambari_mapping[cluster.name] = ambari_info
        rpm = self._get_rpm_uri(cluster_spec)

        servers = []
        for host in hosts:
            host_role = utils.get_host_role(host)
            servers.append(
                h.HadoopServer(host, cluster_spec.node_groups[host_role],
                               ambari_rpm=rpm))

        ambari_client = handler.get_ambari_client()
        ambari_client.setup_hdfs_ha(cluster_spec, servers, ambari_info,
                                    cluster.name)

    def _get_servers(self, cluster):
        servers = []
        if hasattr(cluster, 'node_groups') and cluster.node_groups is not None:
            # code for a cluster object
            for node_group in cluster.node_groups:
                servers += node_group.instances
        else:
            # cluster is actually a cloud context
            servers = cluster.instances

        return servers

    def get_node_processes(self, hadoop_version):
        node_processes = {}
        version_handler = (
            self.version_factory.get_version_handler(hadoop_version))
        default_config = version_handler.get_default_cluster_configuration()
        for service in default_config.services:
            components = []
            for component in service.components:
                if service.is_user_template_component(component):
                    components.append(component.name)
            node_processes[service.name] = components

        return node_processes

    def convert(self, config, plugin_name, version, template_name,
                cluster_template_create):
        handler = self.version_factory.get_version_handler(version)
        normalized_config = handler.get_cluster_spec(
            None, None, cluster_template=config).normalize()

        node_groups = []
        for ng in normalized_config.node_groups:
            node_group = {
                "name": ng.name,
                "flavor_id": ng.flavor,
                "node_processes": ng.node_processes,
                "count": ng.count
            }
            node_groups.append(node_group)

        cluster_configs = dict()
        config_resource = handler.get_config_items()
        for entry in normalized_config.cluster_configs:
            user_input = next((ui for ui in config_resource
                               if entry.config.name == ui.name), None)
            if user_input is not None:
                ci = entry.config
                # get the associated service dictionary
                target = entry.config.applicable_target
                service_dict = cluster_configs.get(target, {})
                service_dict[ci.name] = entry.value
                cluster_configs[target] = service_dict
            else:
                LOG.debug('Template based input "{entry_name}" is being'
                          ' filtered out as it is not considered a user input'
                          .format(entry_name=entry.config.name))

        ctx = context.ctx()
        return cluster_template_create(ctx,
                                       {"name": template_name,
                                        "plugin_name": plugin_name,
                                        "hadoop_version": version,
                                        "node_groups": node_groups,
                                        "cluster_configs": cluster_configs})

    def update_infra(self, cluster):
        pass

    def convert_props_to_template(self, props):
        raise NotImplementedError('not yet supported')

    def _spawn(self, description, func, *args, **kwargs):
        context.spawn(description, func, *args, **kwargs)

    def _provision_cluster(self, name, cluster_spec, ambari_info,
                           servers, version):
        # TODO(jspeidel): encapsulate in another class

        if servers:
            cpo.add_provisioning_step(
                servers[0].cluster_id,
                _("Provision cluster via Ambari"), len(servers))

        for server in servers:
            self._spawn(
                "hdp-provision-instance-%s" % server.instance.hostname(),
                server.provision_ambari, ambari_info, cluster_spec)

        handler = self.version_factory.get_version_handler(version)
        ambari_client = handler.get_ambari_client()

        ambari_client.wait_for_host_registrations(len(servers), ambari_info)
        self._set_ambari_credentials(cluster_spec, ambari_info, version)

        ambari_client.provision_cluster(
            cluster_spec, servers, ambari_info, name)

        LOG.info(_LI('Cluster provisioned via Ambari Server: {server_ip}')
                 .format(server_ip=ambari_info.get_address()))

    # TODO(jspeidel): invoke during scale cluster.  Will need to handle dups
    def _set_cluster_info(self, cluster, cluster_spec):
        info = {}
        for service in cluster_spec.services:
            if service.deployed:
                service.register_service_urls(cluster_spec, info)

        conductor.cluster_update(context.ctx(), cluster, {'info': info})

    def _set_ambari_credentials(self, cluster_spec, ambari_info, version):
        services = cluster_spec.services
        ambari_client = (self.version_factory.get_version_handler(version).
                         get_ambari_client())
        for service in services:
            if service.name == 'AMBARI':
                is_admin_provided = False
                admin_user = ambari_info.user
                admin_password = ambari_info.password
                for user in service.users:
                    if user.name == 'admin':
                        ambari_client.update_ambari_admin_user(
                            user.password, ambari_info)
                        is_admin_provided = True
                        ambari_info.user = 'admin'
                        ambari_info.password = user.password
                    else:
                        ambari_client.add_ambari_user(user, ambari_info)
                        if 'admin' in user.groups:
                            admin_user = user.name
                            admin_password = user.password

                if not is_admin_provided:
                    if admin_user is None:
                        raise ex.HadoopProvisionError(_("An Ambari user in the"
                                                        " admin group must be "
                                                        "configured."))
                    ambari_info.user = admin_user
                    ambari_info.password = admin_password
                    ambari_client.delete_ambari_user('admin', ambari_info)
                break

    def _update_ambari_info_credentials(self, cluster_spec, ambari_info):
        services = cluster_spec.services
        ambari_service = next((service for service in services if
                               service.name == 'AMBARI'), None)
        if ambari_service is not None:
            admin_user = next((user for user in ambari_service.users
                              if 'admin' in user.groups), None)
            if admin_user is not None:
                ambari_info.user = admin_user.name
                ambari_info.password = admin_user.password

        LOG.info(_LI('Using "{username}" as admin user for scaling of cluster')
                 .format(username=ambari_info.user))

    # PLUGIN SPI METHODS:
    def get_versions(self):
        return self.version_factory.get_versions()

    def configure_cluster(self, cluster):
        self.create_cluster(cluster)

    def get_configs(self, hadoop_version):
        handler = self.version_factory.get_version_handler(hadoop_version)
        return handler.get_config_items()

    # cluster name argument supports the non-sahara cluster creation mode
    def start_cluster(self, cluster):
        client = self.version_factory.get_version_handler(
            cluster.hadoop_version).get_ambari_client()

        handler = self.version_factory.get_version_handler(
            cluster.hadoop_version)

        cluster_spec = handler.get_cluster_spec(
            cluster, self._map_to_user_inputs(
                cluster.hadoop_version, cluster.cluster_configs))

        try:
            client.start_services(cluster.name, cluster_spec,
                                  self.cluster_ambari_mapping[cluster.name])
        finally:
            client.cleanup(self.cluster_ambari_mapping[cluster.name])

    def get_title(self):
        return 'Hortonworks Data Platform'

    def get_description(self):
        return _('The Hortonworks Sahara plugin automates the deployment '
                 'of the Hortonworks Data Platform (HDP) on OpenStack.')

    def validate(self, cluster):
        # creating operational config results in validation
        handler = self.version_factory.get_version_handler(
            cluster.hadoop_version)

        handler.get_cluster_spec(cluster, self._map_to_user_inputs(
            cluster.hadoop_version, cluster.cluster_configs))

    def scale_cluster(self, cluster, instances):
        handler = self.version_factory.get_version_handler(
            cluster.hadoop_version)
        ambari_client = handler.get_ambari_client()
        cluster_spec = handler.get_cluster_spec(
            cluster, self._map_to_user_inputs(
                cluster.hadoop_version, cluster.cluster_configs))
        rpm = self._get_rpm_uri(cluster_spec)

        servers = []
        for instance in instances:
            host_role = utils.get_host_role(instance)
            servers.append(h.HadoopServer(instance,
                                          cluster_spec.node_groups
                                          [host_role],
                                          ambari_rpm=rpm))

        ambari_info = self.get_ambari_info(cluster_spec)
        self._update_ambari_info_credentials(cluster_spec, ambari_info)

        cpo.add_provisioning_step(
            cluster.id, _("Provision cluster via Ambari"), len(servers))

        for server in servers:
            self._spawn('Ambari provisioning thread',
                        server.provision_ambari, ambari_info, cluster_spec)

        ambari_client.configure_scaled_cluster_instances(
            cluster.name, cluster_spec, self._get_num_hosts(cluster),
            ambari_info)
        self._configure_topology_for_cluster(cluster, servers)
        ambari_client.start_scaled_cluster_instances(cluster.name,
                                                     cluster_spec, servers,
                                                     ambari_info)

        ambari_client.cleanup(ambari_info)

    def get_edp_engine(self, cluster, job_type):
        version_handler = (
            self.version_factory.get_version_handler(cluster.hadoop_version))
        return version_handler.get_edp_engine(cluster, job_type)

    def get_edp_job_types(self, versions=[]):
        res = {}
        for vers in self.version_factory.get_versions():
            if not versions or vers in versions:
                vh = self.version_factory.get_version_handler(vers)
                res[vers] = vh.get_edp_job_types()
        return res

    def get_edp_config_hints(self, job_type, version):
        version_handler = (
            self.version_factory.get_version_handler(version))
        return version_handler.get_edp_config_hints(job_type)

    def decommission_nodes(self, cluster, instances):
        LOG.info(_LI('AmbariPlugin: decommission_nodes called for '
                 'HDP version = {version}')
                 .format(version=cluster.hadoop_version))

        handler = self.version_factory.get_version_handler(
            cluster.hadoop_version)
        ambari_client = handler.get_ambari_client()
        cluster_spec = handler.get_cluster_spec(
            cluster, self._map_to_user_inputs(
                cluster.hadoop_version, cluster.cluster_configs))

        ambari_info = self.get_ambari_info(cluster_spec)
        ambari_client.decommission_cluster_instances(cluster, cluster_spec,
                                                     instances,
                                                     ambari_info)

    def validate_scaling(self, cluster, existing, additional):
        handler = self.version_factory.get_version_handler(
            cluster.hadoop_version)

        # results in validation
        handler.get_cluster_spec(
            cluster, [], dict(existing.items() + additional.items()))

    def _get_num_hosts(self, cluster):
        count = 0
        for node_group in cluster.node_groups:
            count += node_group.count

        return count

    def _get_host_list(self, servers):
        host_list = [server.instance.fqdn().lower() for server in servers]
        return ",".join(host_list)

    def _get_rpm_uri(self, cluster_spec):
        ambari_config = cluster_spec.configurations['ambari']
        return ambari_config.get('rpm', None)

    def get_ambari_info(self, cluster_spec):
        ambari_host = cluster_spec.determine_component_hosts(
            'AMBARI_SERVER').pop()

        port = cluster_spec.configurations['ambari'].get(
            'server.port', '8080')

        return AmbariInfo(ambari_host, port, 'admin', 'admin')

    def _configure_topology_for_cluster(self, cluster, servers):
        if CONF.enable_data_locality:
            cpo.add_provisioning_step(
                cluster.id, _("Enable data locality for cluster"),
                len(servers))
            topology_data = th.generate_topology_map(
                cluster, CONF.enable_hypervisor_awareness)
            topology_str = "\n".join(
                [k + " " + v for k, v in topology_data.items()]) + "\n"
            for server in servers:
                server.configure_topology(topology_str)

    def get_open_ports(self, node_group):
        handler = self.version_factory.get_version_handler(
            node_group.cluster.hadoop_version)
        return handler.get_open_ports(node_group)

class AmbariInfo(object):
    def __init__(self, host, port, user, password):
        self.host = host
        self.port = port
        self.user = user
        self.password = password

    def get_address(self):
        return '{0}:{1}'.format(self.host.management_ip, self.port)

    def is_ambari_info(self):
        pass

    def get_cluster(self):
        sahara_instance = self.host.sahara_instance
        return sahara_instance.cluster

    def get_event_info(self):
        return self.host.sahara_instance


text:
//
//  GQNetworkDefine.h
//  GQNetWorkDemo
//
//  Created by 高旗 on 16/9/29.
//  Copyright © 2016年 gaoqi. All rights reserved.
//

#ifndef GQNetworkDefine_h
#define GQNetworkDefine_h

@class GQBaseDataRequest;
@class GQRequestResult;
#pragma mark -- blockTypedef  普通函数式block

typedef void (^GQRequestStart)(GQBaseDataRequest * request);//请求开始block
typedef NSURLSessionResponseDisposition (^GQRequestRechiveResponse)(GQBaseDataRequest * request,NSURLResponse *response);//收到请求头block
typedef NSURLRequest *(^GQRequestWillRedirection)(GQBaseDataRequest * request,NSURLRequest *urlRequest,NSURLResponse *response);//HTTP重定向block
typedef NSInputStream * (^GQRequestNeedNewBodyStream)(GQBaseDataRequest * request,NSURLSession *session,NSURLSessionTask *task);//需要新的数据流block
typedef NSCachedURLResponse * (^GQRequestWillCacheResponse)(GQBaseDataRequest * request,NSCachedURLResponse *proposedResponse);//将要缓存到web的block
typedef void (^GQRequestFinished)(GQBaseDataRequest * request, GQRequestResult * result);//请求完成block
typedef void (^GQRequestCanceled)(GQBaseDataRequest * request);//请求取消block
typedef void (^GQRequestFailed)(GQBaseDataRequest * request, NSError * error);//请求失败block
typedef void (^GQProgressChanged)(GQBaseDataRequest * request, CGFloat progress);//请求进度改变block

#pragma mark -- ChainBlockTypedef 链式写法block

typedef GQBaseDataRequest *(^GQChainObjectRequest)(id value);//NSObject block
typedef GQBaseDataRequest *(^GQChainStuctRequest)(NSInteger value);   //NSInteger block
//typedef GQBaseDataRequest *(^GQDispatchRequest)(dispatch_queue_t value);

typedef void(^GQChainBlockStartRequest)(void);//发送请求block

typedef GQBaseDataRequest * (^GQChainBlockRequestStart)(GQRequestStart);//请求开始block
typedef GQBaseDataRequest * (^GQChainBlockRequestRechiveResponse)(GQRequestRechiveResponse);//收到请求头block
typedef GQBaseDataRequest * (^GQChainBlockRequestWillRedirection)(GQRequestWillRedirection);//HTTP重定向block
typedef GQBaseDataRequest * (^GQChainBlockRequestNeedNewBodyStream) (GQRequestNeedNewBodyStream);//需要新的数据流block
typedef GQBaseDataRequest * (^GQChainBlockRequestWillCacheResponse)(GQRequestWillCacheResponse);//将要缓存到web的block
typedef GQBaseDataRequest * (^GQChainBlockRequestFinished)(GQRequestFinished);//请求完成block
typedef GQBaseDataRequest * (^GQChainBlockRequestCanceled)(GQRequestCanceled);//请求取消block
typedef GQBaseDataRequest * (^GQChainBlockRequestFailed)(GQRequestFailed);//请求失败block
typedef GQBaseDataRequest * (^GQChainBlockProgressChanged)(GQProgressChanged);//请求进度改变block

#pragma mark -- GQDataRequestDelegate
@protocol GQDataRequestDelegate <NSObject>

@required
- (void)requestDidFinishLoad:(GQBaseDataRequest*)request mappingResult:(GQRequestResult *)result;//请求完成代理
- (void)request:(GQBaseDataRequest*)request didFailLoadWithError:(NSError*)error;//请求失败代理

@optional
- (void)requestDidStartLoad:(GQBaseDataRequest*)request;//请求开始代理
- (NSURLSessionResponseDisposition )requestRechiveResponse:(GQBaseDataRequest *)request urlResponse:(NSURLResponse *)response;//收到请求头代理
- (NSURLRequest *)requestWillRedirection:(GQBaseDataRequest *)request urlRequset:(NSURLRequest *)urlRequest urlResponse:(NSURLResponse *)response;//HTTP重定向代理
- (NSInputStream *)requestNeedNewBodyStream:(GQBaseDataRequest *)request session:(NSURLSession *)session task:(NSURLSessionTask *)task;//需要新的数据流代理
- (NSCachedURLResponse *)requestWillCacheResponse:(GQBaseDataRequest *)request originStream:(NSCachedURLResponse *)originStream;//将要缓存到web代理
- (void)requestDidCancelLoad:(GQBaseDataRequest*)request;//请求取消代理
- (void)request:(GQBaseDataRequest*)request progressChanged:(CGFloat)progress;//请求数据变化代理

@end

#endif /* GQNetworkDefine_h */


text:
package oracle

// Code generated by xo. DO NOT EDIT.

import (
	"context"
)

// APrimary represents a row from 'a_bit_of_everything.a_primary'.
type APrimary struct {
	AKey int `json:"a_key"` // a_key
	// xo fields
	_exists, _deleted bool
}

// Exists returns true when the APrimary exists in the database.
func (ap *APrimary) Exists() bool {
	return ap._exists
}

// Deleted returns true when the APrimary has been marked for deletion from
// the database.
func (ap *APrimary) Deleted() bool {
	return ap._deleted
}

// Insert inserts the APrimary to the database.
func (ap *APrimary) Insert(ctx context.Context, db DB) error {
	switch {
	case ap._exists: // already exists
		return logerror(&ErrInsertFailed{ErrAlreadyExists})
	case ap._deleted: // deleted
		return logerror(&ErrInsertFailed{ErrMarkedForDeletion})
	}
	// insert (manual)
	const sqlstr = `INSERT INTO a_bit_of_everything.a_primary (` +
		`a_key` +
		`) VALUES (` +
		`:1` +
		`)`
	// run
	logf(sqlstr, ap.AKey)
	if _, err := db.ExecContext(ctx, sqlstr, ap.AKey); err != nil {
		return logerror(err)
	}
	// set exists
	ap._exists = true
	return nil
}

// ------ NOTE: Update statements omitted due to lack of fields other than primary key ------

// Delete deletes the APrimary from the database.
func (ap *APrimary) Delete(ctx context.Context, db DB) error {
	switch {
	case !ap._exists: // doesn't exist
		return nil
	case ap._deleted: // deleted
		return nil
	}
	// delete with single primary key
	const sqlstr = `DELETE FROM a_bit_of_everything.a_primary ` +
		`WHERE a_key = :1`
	// run
	logf(sqlstr, ap.AKey)
	if _, err := db.ExecContext(ctx, sqlstr, ap.AKey); err != nil {
		return logerror(err)
	}
	// set deleted
	ap._deleted = true
	return nil
}

// APrimaryByAKey retrieves a row from 'a_bit_of_everything.a_primary' as a APrimary.
//
// Generated from index 'a_primary_pkey'.
func APrimaryByAKey(ctx context.Context, db DB, aKey int) (*APrimary, error) {
	// query
	const sqlstr = `SELECT ` +
		`a_key ` +
		`FROM a_bit_of_everything.a_primary ` +
		`WHERE a_key = :1`
	// run
	logf(sqlstr, aKey)
	ap := APrimary{
		_exists: true,
	}
	if err := db.QueryRowContext(ctx, sqlstr, aKey).Scan(&ap.AKey); err != nil {
		return nil, logerror(err)
	}
	return &ap, nil
}