Skip to content

Commit

Permalink
Merge branch 'master' into get-hierarchy-worker
Browse files Browse the repository at this point in the history
  • Loading branch information
iamigo committed May 23, 2017
2 parents 26a5b94 + b405cfc commit 4831dca
Show file tree
Hide file tree
Showing 19 changed files with 982 additions and 44 deletions.
10 changes: 10 additions & 0 deletions api/v1/controllers/lenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ function parseLensMetadata(zip, lensJson, seqObj) {
}

for (const metadataEntry in metadataJson) {
// validate lens name
if (metadataEntry === 'name' &&
(/^[0-9A-Za-z_\\-]{0,60}$/).test(metadataJson[metadataEntry]) === false) {
throw new apiErrors.ValidationError({
explanation: 'Name field should be max 60 characters; case ' +
'insensitive; allows alpha-numeric characters,underscore (_) ' +
'and dash (-).',
});
}

// lens metadata name will be saved as sourceName.
// Same with description and version
if (metadataEntry === 'name' || metadataEntry === 'description' ||
Expand Down
23 changes: 23 additions & 0 deletions api/v1/controllers/rooms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2017, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/

/**
* api/v1/controllers/rooms.js
*/
'use strict';

const httpStatus = require('../constants').httpStatus;

module.exports = {
findRooms(req, res, next) {
return res.status(httpStatus.OK).json({
success: true,
});
},
};

37 changes: 36 additions & 1 deletion api/v1/controllers/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ const doPost = require('../helpers/verbs/doPost');
const doPut = require('../helpers/verbs/doPut');
const u = require('../helpers/verbs/utils');
const httpStatus = require('../constants').httpStatus;
const apiErrors = require('../apiErrors');
const sampleStore = require('../../../cache/sampleStore');
const sampleStoreConstants = sampleStore.constants;
const redisModelSample = require('../../../cache/models/samples');
const utils = require('./utils');
const publisher = u.publisher;

const kueSetup = require('../../../jobQueue/setup');
const kue = kueSetup.kue;
module.exports = {

/**
Expand Down Expand Up @@ -86,6 +88,36 @@ module.exports = {
doGet(req, res, next, helper);
},

/**
* GET /samples/upsert/bulk/{key}/status
*
* Retrieves the status of the bulk upsert job and sends it back in the
* response
* @param {IncomingMessage} req - The request object
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
*/
getSampleBulkUpsertStatus(req, res, next) {
const reqParams = req.swagger.params;
const jobId = reqParams.key.value;
kue.Job.get(jobId, (_err, job) => {
/*
* throw the "ResourceNotFoundError" if there is an error in getting the
* job or the job is not a bulkUpsert job
*/
if (_err || !job || job.type !== kueSetup.jobType.BULKUPSERTSAMPLES) {
const err = new apiErrors.ResourceNotFoundError();
return u.handleError(next, err, helper.modelName);
}

// return the job status and the errors in the response
const ret = {};
ret.status = job._state;
ret.errors = job.result ? job.result.errors : [];
return res.status(httpStatus.OK).json(ret);
});
},

/**
* PATCH /samples/{key}
*
Expand Down Expand Up @@ -141,6 +173,9 @@ module.exports = {
* @param {IncomingMessage} req - The request object
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
* @returns {ServerResponse} - The response object indicating that the sample
* has been either created or updated.
*
*/
upsertSample(req, res, next) {
// make the name post-able
Expand Down
101 changes: 94 additions & 7 deletions api/v1/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1533,9 +1533,12 @@ paths:
name: name
in: formData
description: >-
A unique name for the lens. Leave empty if you want to use the
name provided by the lens publisher (i.e. sourceName).
A unique name for the lens. Max 60 characters; case insensitive;
allows alpha-numeric characters, underscore (_) and dash (-). Leave
empty if you want to use the name provided by the lens publisher
(i.e. sourceName).
type: string
pattern: ^[0-9A-Za-z_\\-]{0,60}$
-
name: version
in: formData
Expand Down Expand Up @@ -1663,9 +1666,12 @@ paths:
default: false
name:
description: >-
A unique name for the lens. Leave empty if you want to use the
name provided by the lens publisher (i.e. sourceName).
A unique name for the lens. Max 60 characters; case insensitive;
allows alpha-numeric characters, underscore (_) and dash (-). Leave
empty if you want to use the name provided by the lens publisher
(i.e. sourceName).
type: string
pattern: ^[0-9A-Za-z_\\-]{0,60}$
version:
description: >-
A version for the lens. Leave empty if you want to use the
Expand Down Expand Up @@ -1731,9 +1737,12 @@ paths:
name: name
in: formData
description: >-
A unique name for the lens. Leave empty if you want to use the
name provided by the lens publisher (i.e. sourceName).
A unique name for the lens. Max 60 characters; case insensitive;
allows alpha-numeric characters, underscore (_) and dash (-). Leave
empty if you want to use the name provided by the lens publisher
(i.e. sourceName).
type: string
pattern: ^[0-9A-Za-z_\\-]{0,60}$
-
name: version
in: formData
Expand Down Expand Up @@ -3625,6 +3634,37 @@ paths:
$ref: "#/responses/404"
default:
$ref: "#/responses/genericError"
# ---------------------------------------------------------------------------
/samples/upsert/bulk/{key}/status:
x-swagger-router-controller: samples
get:
security:
- jwt: []
summary: Retrieve the specified sample
tags: [ samples ]
description: >-
Retrieve the status of the job identified by id in the request.
operationId: getSampleBulkUpsertStatus
parameters:
-
name: key
in: path
description: >-
The id the job
required: true
type: integer
responses:
200:
description: >-
Success.
schema:
$ref: "#/definitions/GetBulkUpsertStatusResponse"
400:
$ref: "#/responses/400"
404:
$ref: "#/responses/404"
default:
$ref: "#/responses/genericError"

# ---------------------------------------------------------------------------
/samples/{key}/relatedLinks:
Expand Down Expand Up @@ -6094,6 +6134,31 @@ paths:
schema:
$ref: '#/definitions/ErrorResponse'

# =============================================================================
/rooms:
x-swagger-router-controller: rooms
get:
tags: [ rooms ]
operationId: findRooms
responses:
200:
description: >-
Success
schema:
type: object
properties:
Success:
type: boolean
readOnly: true
400:
$ref: "#/responses/400"
401:
$ref: "#/responses/401"
404:
$ref: "#/responses/404"
default:
$ref: "#/responses/genericError"

# =============================================================================
definitions:

Expand Down Expand Up @@ -6486,7 +6551,8 @@ definitions:
readOnly: true
pattern: ^[0-9A-Za-z_\\-]{0,60}$
description: >
The name of the lens.
The name of lens. Max 60 characters; case insensitive;
allows alpha-numeric characters, underscore (_) and dash (-).
sourceDescription:
type: string
readOnly: true
Expand Down Expand Up @@ -6857,6 +6923,27 @@ definitions:
request is enqueued as a job for the workers to process it
asynchronously. The returned jobId can be used to check the status
of the bulk upsert request.
GetBulkUpsertStatusResponse:
type: object
description: >
Status of bulk upsert request.
properties:
status:
type: string
readOnly: true
maxLength: 254
description: >
Status.
errors:
type: array
readOnly: true
description: >
An array containing the error information of the samples that
were not upserted.
items:
type: object

SubjectsResponse:
type: object
description: >
Expand Down
4 changes: 4 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
'use strict'; // eslint-disable-line strict
require('./config/toggles'); // Loads the feature toggles
const featureToggles = require('feature-toggles');
const configUtil = require('./config/configUtil');
const defaultPort = 3000;
const defaultPostgresPort = 5432;
Expand All @@ -34,6 +35,8 @@ const DEFAULT_DB_CONNECTION_POOL = { // sequelize defaults
min: 0,
idle: 10000,
};
const hiddenRoutes = pe.HIDDEN_ROUTES ?
pe.HIDDEN_ROUTES.split[','] : ['/rooms']; // Routes to hide

// By default, allow all IP's
const ipWhitelist = pe.IP_WHITELIST || '[[0.0.0.0,255.255.255.255]]';
Expand Down Expand Up @@ -241,4 +244,5 @@ module.exports = {
rateLimit,
rateWindow,
readReplicas,
hiddenRoutes,
};
4 changes: 4 additions & 0 deletions config/toggles.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const longTermToggles = {
enableRedisSampleStore:
environmentVariableTrue(pe, 'ENABLE_REDIS_SAMPLE_STORE'),

// Enable Rooms functionality
enableRooms: environmentVariableTrue(pe, 'ENABLE_ROOMS'),

// Enable worker activity logging
enableWorkerActivityLogs:
environmentVariableTrue(pe, 'ENABLE_WORKER_ACTIVITY_LOGS'),
Expand All @@ -91,6 +94,7 @@ const longTermToggles = {

// Disable HTTP, i.e. only use https
requireHttps: environmentVariableTrue(pe, 'REQUIRE_HTTPS'),

}; // longTermToggles

/*
Expand Down
5 changes: 5 additions & 0 deletions db/model/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ module.exports = function sample(seq, dataTypes) {
if (o === null) {
return Sample.create(toUpsert);
}

// DO NOT update the name
// for existing samples
delete toUpsert.name;

/*
* set value changed to true during updates to avoid timeouts.
* Adding this to the before update hook does
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ function start() { // eslint-disable-line max-statements
const swaggerFile = fs // eslint-disable-line no-sync
.readFileSync(conf.api.swagger.doc, ENCODING);
const swaggerDoc = yaml.safeLoad(swaggerFile);

// Filter out hidden routes
if (!featureToggles.isFeatureEnabled('enableRooms')) {
for (let i = 0; i < conf.hiddenRoutes.length; i++) {
delete swaggerDoc.paths[conf.hiddenRoutes[i]];
}
}

swaggerTools.initializeMiddleware(swaggerDoc, (mw) => {
app.use('/static', express.static(path.join(__dirname, 'public')));

Expand Down
1 change: 1 addition & 0 deletions jobQueue/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ module.exports = {
},
ttlForJobs: conf.JOB_QUEUE_TTL_SECONDS,
delayToRemoveJobs: conf.JOB_REMOVAL_DELAY_SECONDS,
kue,
}; // exports
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
"test-api-log": "ENABLE_API_ACTIVITY_LOGS=true mocha -R dot --recursive tests/api",
"test-disablehttp": "REQUIRE_HTTPS=true mocha -R dot --recursive tests/disableHttp",
"test-enforced": "REQUIRE_ACCESS_TOKEN=true mocha -R dot --recursive tests/enforceToken",
"test-rooms-enabled": "ENABLE_ROOMS=true mocha -R dot --recursive tests/roomFlag/roomFlagEnabled",
"test-rooms-disabled": "ENABLE_ROOMS=false mocha -R dot --recursive tests/roomFlag/roomFlagDisabled",
"test-db": "npm run checkdb && mocha -R dot --recursive tests/db",
"test-cache": "mocha -R dot --recursive tests/cache",
"test-view": "NODE_ENV=build mocha -R dot --recursive --compilers js:babel-core/register --require ./tests/view/setup.js tests/view",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R dot --recursive tests/api tests/cache tests/clock tests/config tests/db tests/jobQueue tests/realtime tests/tokenNotReq tests/enableCache tests/logging && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage && npm run test-view && npm run test-disablehttp && npm run test-enforced",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R dot --recursive tests/api tests/cache tests/clock tests/config tests/db tests/jobQueue tests/realtime tests/tokenNotReq tests/enableCache tests/logging && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage && npm run test-view && npm run test-disablehttp && npm run test-enforced && npm run test-rooms-enabled && npm run test-rooms-disabled",
"undo-migratedb": "node db/migrateUndo.js",
"view": "NODE_ENV=production gulp browserifyViews && npm start"
},
Expand Down
Binary file not shown.
Loading

0 comments on commit 4831dca

Please sign in to comment.