Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release notes #92

Merged
merged 8 commits into from May 1, 2012
Merged
20 changes: 19 additions & 1 deletion lib/crawler/app.js
@@ -1,3 +1,21 @@
/*
* Copyright 2011 Rackspace
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/


var http = require('http'),
https = require('https'),
fs = require('fs'),
Expand Down Expand Up @@ -28,7 +46,7 @@ var generate_worker = function(name, devopsjson_url) {
console.log("Error writing file ", devopsjson_url, filename, error);
next(error, null);
}else{
fs.writeFile(filename, data, function (err) {
fs.writeFile(filename, data.data, function (err) {
if (err) {
console.log("Error writing file ", filename, err);
} else {
Expand Down
83 changes: 75 additions & 8 deletions lib/utils.js
@@ -1,12 +1,31 @@
/*
* Copyright 2011 Rackspace
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

var fs = require('fs');
var path = require('path');
var http = require('http');
var https = require('https');
var url = require('url');
var JSV = require('JSV').JSV;
var _ = require('underscore');

var urls = require('./web/urls');
var settings = require('./settings');
var schema = require('../extern/devopsjson/lib/web/schema').schema;
var JSV = require('JSV').JSV;
var _ = require('underscore');

// A bunch of enum like things for the stats push API (no hidden interfaces via magic strings!)
var HEALTH_UNKNOWN = 0;
Expand Down Expand Up @@ -286,26 +305,74 @@ exports.load_devops = function(devops_path) {
* @param {fn} on_error callback that takes an Exception as a parameter
*/
exports.request_maker = function(options, call_back) {
var method = options.port === 443 ? https : http;
var req = method.get(options, function(res) {
var post_data = "";
var headers = {};
if ( options.post_data !== undefined ){
post_data = JSON.stringify(options.post_data);
delete options.post_data;
}

headers['Content-length'] = post_data.length;

if (options.headers){
_.extend(options.headers, headers);
}else{
options.headers = headers;
}

var req = https.request(options, function(res) {
var data = '';
res.setEncoding('utf8');
res.on('data', function(d) {
data += d;
});
res.on('end', function() {
//TODO: this is pretty strange, change me.
try{
call_back(null, data);
call_back(null, {data: data, res: res});
}catch(e){
call_back(e, data);
call_back(e, {data: data, res: res});
}
});
}).on('error', function(e) {
});
req.on('error', function(e) {
call_back(e, null);
});

if (post_data){
req.write(post_data);
}
req.end();
};

/**
*
* @param devops_github
* @param is_closed
* @returns
*/
exports.github_request_options = function(api_config, uri) {
var parsed = url.parse(uri || api_config.url);
var _path = parsed.path === '/' ? [
"/repos/",
api_config.org,
"/",
api_config.repo,
'/pulls?state=closed&per_page=100&page=1'
].join('') : parsed.path;

return {
return_response: true,
host: parsed.host,
port: 443,
path: _path,
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': exports.create_basic_auth(api_config.username,
api_config.apikey)
}
};
};
/**
* @param string
* @returns new string with first letter capitalized
Expand Down
22 changes: 21 additions & 1 deletion lib/web/app.js
@@ -1,3 +1,19 @@
/*
* Copyright 2011 Rackspace
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

var path = require('path');
var fs = require('fs');
Expand All @@ -9,6 +25,7 @@ var express = require('express');
var load_devops = require('./load_devops');
var middleware = require('./middleware');
var routes = require('./routes');
var routes_secure = require('./routes_secure');
var utils = require('../utils');
var settings = require('../settings');
var pollers = require('./pollers');
Expand Down Expand Up @@ -62,9 +79,12 @@ exports.run = function(port, devops_directory, host) {

pollers.install(devops, function(polling_data){
app.use(middleware.injector.inject(polling_data, devops));
routes.install(app, secure_app, status_api, devops);

routes.install(app, status_api, devops);
app.listen(port, host);

if (secure_app){
routes_secure.install(secure_app, status_api, devops);
secure_app.listen(443, '0.0.0.0');
}
if (settings.testing !== true){
Expand Down
3 changes: 2 additions & 1 deletion lib/web/middleware/injector.js
Expand Up @@ -77,7 +77,8 @@ var jade_locals = utils.make_class({
}

if (related_apis.github) {
_navbar.DevHealth = urls.DEVHEALTH.replace(':project', project);
_navbar['Dev Health'] = urls.DEVHEALTH.replace(':project', project);
_navbar['Release Notes'] = urls.RELEASE_NOTES.replace(':project', project);
}

_navbar["Service Health"] = urls.SERVICE_HEALTH.replace(':project', project);
Expand Down
6 changes: 3 additions & 3 deletions lib/web/pollers/dreadnot.js
Expand Up @@ -27,8 +27,8 @@ request.prototype = {
}
};

module.exports = function dreadnot(payload, api_config) {

module.exports = function dreadnot(payload) {
var api_config = payload.config;
var requests = [];
_.each(api_config.stacks, function(a_stack){
_.each(_.keys(a_stack), function(stack_name){
Expand All @@ -53,7 +53,7 @@ module.exports = function dreadnot(payload, api_config) {

try{
_.each(results, function(value){
value = JSON.parse(value);
value = JSON.parse(value.data);
if (value instanceof Array){
stacks[value[0].stackName].deploys = value;
}else{
Expand Down
7 changes: 4 additions & 3 deletions lib/web/pollers/github.js
Expand Up @@ -7,10 +7,11 @@ var url = require('url');
/** Adds github field to devops if github related api is present
* @param {object} devops devops object
*/
module.exports = function github(payload, api_config) {

module.exports = function github(payload) {
var api_config = payload.config;
var open_options = make_github_options(api_config);
var closed_options = make_github_options(api_config, true);

var pulls;

async.parallel({
Expand All @@ -31,7 +32,7 @@ module.exports = function github(payload, api_config) {
try{
// open_pull_requests: github response string
_.each(results, function(val, key) {
val = JSON.parse(val);
val = JSON.parse(val.data);
data = data.concat(val);
});
data = parse_github_response(data);
Expand Down
6 changes: 3 additions & 3 deletions lib/web/pollers/highscores.js
Expand Up @@ -26,8 +26,8 @@ module.exports = _highscores;
/** Adds github field to devops if github related api is present
* @param {object} devops devops object
*/
function _highscores(payload, api_config) {

function _highscores(payload) {
var api_config = payload.config;
var options = {
host: api_config.url,
port: api_config.port,
Expand All @@ -43,7 +43,7 @@ function _highscores(payload, api_config) {
return;
}

data = JSON.parse(results);
data = JSON.parse(results.data);

var position = 1;
var modifier = " ";
Expand Down
28 changes: 21 additions & 7 deletions lib/web/pollers/index.js
Expand Up @@ -27,14 +27,25 @@ var polling_apis = {
github: require('./github'),
new_relic: require('./new_relic'),
dreadnot: require('./dreadnot'),
highscores: require('./highscores')
highscores: require('./highscores'),
release_notes: require('./release_notes')
};

// which apis does a given poller depend on?
var poller_to_relatedapi = {release_notes: 'github'};
// defaults to its own name
_.each(polling_apis, function(val, name){
if (!poller_to_relatedapi[name]){
poller_to_relatedapi[name] = name;
}
});

var to_call = [];

var _install_api = function(api, api_config, payload){
var _install_api = function(api, payload){
var call_api = function(){
try{
api(payload, api_config);
api(payload);
}catch (e){
payload.error = e;
}
Expand All @@ -44,7 +55,7 @@ var _install_api = function(api, api_config, payload){
call_api();
// NOTE: we don't make users wait for all api calls to finish, just to start
cb();
setInterval(call_api, 5*60*1000);
setInterval(call_api, payload.config.poll_interval || 5*60*1000);
});
};

Expand All @@ -57,6 +68,7 @@ exports.install = function(devops, cb){
var name;
var this_devops;
var payload;
var related_api_name;
for (name in polling_apis){
api = polling_apis[name];
this_devops = devops[project];
Expand All @@ -65,11 +77,13 @@ exports.install = function(devops, cb){
}
payload = {error: null, data: null, config: null};
polling_data[project][name] = payload;
if (!this_devops.related_apis || !this_devops.related_apis[name]) {
related_api_name = poller_to_relatedapi[name];
if (!this_devops.related_apis || !this_devops.related_apis[related_api_name]) {
continue;
}
payload.config = this_devops.related_apis[name];
_install_api(api, this_devops.related_apis[name], payload);

payload.config = this_devops.related_apis[related_api_name];
_install_api(api, payload);
}
});

Expand Down
3 changes: 2 additions & 1 deletion lib/web/pollers/new_relic.js
@@ -1,7 +1,8 @@
var utils = require('../../utils'),
NewRelicApi = require('newrelicapi');

module.exports = function _new_relic(payload, api_config) {
module.exports = function _new_relic(payload) {
var api_config = payload.config;
var appid = api_config.appid;
var nra = new NewRelicApi({
apikey: api_config.apikey,
Expand Down
5 changes: 3 additions & 2 deletions lib/web/pollers/pager_duty.js
Expand Up @@ -8,7 +8,8 @@ var _ = require('underscore');
* on_end_cb a callback that gets called with the XHR response data
*/

module.exports = function(payload, api_config) {
module.exports = function(payload) {
var api_config = payload.config;

// PagerDuty requires the date range for all requests.
var now, until, options;
Expand Down Expand Up @@ -42,7 +43,7 @@ module.exports = function(payload, api_config) {
return;
}
try{
payload.data = JSON.parse(data);
payload.data = JSON.parse(data.data);
} catch (e){
payload.error = e;
return;
Expand Down
5 changes: 5 additions & 0 deletions lib/web/pollers/release_notes.js
@@ -0,0 +1,5 @@
var _ = require('underscore');
var util = require('util');
var utils = require('../../utils');
var async = require('async');
var url = require('url');
5 changes: 3 additions & 2 deletions lib/web/pollers/version_one.js
Expand Up @@ -35,7 +35,8 @@ var selection = ["Custom_Severity.Name",
"Scope",
"Priority"];

module.exports = function(payload, api_config) {
module.exports = function(payload) {
var api_config = payload.config;
var options = {
port: api_config.port,
host: api_config.host,
Expand Down Expand Up @@ -77,7 +78,7 @@ module.exports = function(payload, api_config) {
payload.error = error;
return;
}
var etree = et.parse(data);
var etree = et.parse(data.data);
if (!_.isEmpty(data.error)){
payload.error = data.error.code + ": " + data.error.message;
return;
Expand Down