<commit_before>/*
 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
 *
 * lib/server/model.js: SAPI's data model and associated operations on those
 *     objects.
 */

var async = require('async');
var assert = require('assert-plus');
var common = require('./common');
var fs = require('fs');
var jsprim = require('jsprim');
var LRU = require('lru-cache');
var restify = require('restify');
var sdc = require('sdc-clients');
var node_uuid = require('node-uuid');
var vasync = require('vasync');

var VMAPIPlus = require('./vmapiplus');

var LocalStorage = require('./stor/local');
var MorayStorage = require('./stor/moray');

var mod_attr = require('./attributes');
var mod_errors = require('./errors');
var mod_images = require('./images');
var mod_valid = require('./validation');

var exec = require('child_process').exec;
var sprintf = require('util').format;


// -- Moray bucket names

var BUCKETS = {
	applications: 'sapi_applications',
	services: 'sapi_services',
	instances: 'sapi_instances',
	manifests: 'sapi_manifests'
};



// -- Constructor and initialization routines

function Model(config) {
	this.config = config;
	this.log = config.log;

	assert.object(config, 'config');

	assert.object(config.log, 'config.log');

	assert.object(config.moray, 'config.moray');
	assert.string(config.moray.host, 'config.moray.host');

	assert.object(config.ufds, 'config.ufds');
	assert.string(config.ufds.url, 'config.ufds.url');
	assert.string(config.ufds.bindDN, 'config.ufds.bindDN');
	assert.string(config.ufds.bindPassword, 'config.ufds.bindPassword');

	assert.object(config.vmapi, 'config.vmapi');
	assert.string(config.vmapi.url, 'config.vmapi.url');

	assert.object(config.imgapi, 'config.imgapi');
	assert.string(config.imgapi.url, 'config.imgapi.url');

	assert.object(config.remote_imgapi, 'config.remote_imgapi');
	assert.string(config.remote_imgapi.url, 'config.remote_imgapi.url');

	assert.object(config.napi, 'config.napi');
	assert.string(config.napi.url, 'config.napi.url');

	config.moray.log = this.log;
	config.ufds.log = this.log;
	config.vmapi.log = this.log;
	config.imgapi.log = this.log;
	config.remote_imgapi.log = this.log;
	config.napi.log = this.log;

	config.moray.noCache = true;
	config.moray.connectTimeout = 10000;
	config.moray.retry = {};
	config.moray.retry.retries = Infinity;
	config.moray.retry.minTimeout = 1000;
	config.moray.retry.maxTimeout = 60000;

	this.mc_callbacks = [];
}

Model.prototype.initClients = function (cb) {
	var self = this;
	var config = self.config;
	var log = self.log;

	config.buckets = BUCKETS;<commit_msg>SAPI-108 align moray config with NAPI to avoid reboot race.<commit_after>/*
 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
 *
 * lib/server/model.js: SAPI's data model and associated operations on those
 *     objects.
 */

var async = require('async');
var assert = require('assert-plus');
var common = require('./common');
var fs = require('fs');
var jsprim = require('jsprim');
var LRU = require('lru-cache');
var restify = require('restify');
var sdc = require('sdc-clients');
var node_uuid = require('node-uuid');
var vasync = require('vasync');

var VMAPIPlus = require('./vmapiplus');

var LocalStorage = require('./stor/local');
var MorayStorage = require('./stor/moray');

var mod_attr = require('./attributes');
var mod_errors = require('./errors');
var mod_images = require('./images');
var mod_valid = require('./validation');

var exec = require('child_process').exec;
var sprintf = require('util').format;


// -- Moray bucket names

var BUCKETS = {
	applications: 'sapi_applications',
	services: 'sapi_services',
	instances: 'sapi_instances',
	manifests: 'sapi_manifests'
};



// -- Constructor and initialization routines

function Model(config) {
	this.config = config;
	this.log = config.log;

	assert.object(config, 'config');

	assert.object(config.log, 'config.log');

	assert.object(config.moray, 'config.moray');
	assert.string(config.moray.host, 'config.moray.host');

	assert.object(config.ufds, 'config.ufds');
	assert.string(config.ufds.url, 'config.ufds.url');
	assert.string(config.ufds.bindDN, 'config.ufds.bindDN');
	assert.string(config.ufds.bindPassword, 'config.ufds.bindPassword');

	assert.object(config.vmapi, 'config.vmapi');
	assert.string(config.vmapi.url, 'config.vmapi.url');

	assert.object(config.imgapi, 'config.imgapi');
	assert.string(config.imgapi.url, 'config.imgapi.url');

	assert.object(config.remote_imgapi, 'config.remote_imgapi');
	assert.string(config.remote_imgapi.url, 'config.remote_imgapi.url');

	assert.object(config.napi, 'config.napi');
	assert.string(config.napi.url, 'config.napi.url');

	config.moray.log = this.log;
	config.ufds.log = this.log;
	config.vmapi.log = this.log;
	config.imgapi.log = this.log;
	config.remote_imgapi.log = this.log;
	config.napi.log = this.log;

	config.moray.noCache = true;
	config.moray.connectTimeout = 1000;
	config.moray.reconnect = true;
	config.moray.retry = {};
	config.moray.retry.retries = Infinity;
	config.moray.retry.minTimeout = 100;
	config.moray.retry.maxTimeout = 6000;

	this.mc_callbacks = [];
}

Model.prototype.initClients = function (cb) {
	var self = this;
	var config = self.config;
	var log = self.log;

	config.buckets = BUCKETS;
{'fraction_non_alphanumeric': 0.16796800609407733, 'fraction_numerical': 0.006855836983431727, 'mean_word_length': 4.835555555555556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5588541', 'n_tokens_mistral': 1895, 'n_tokens_neox': 1831, 'n_words': 348}