Skip to content

Commit

Permalink
EWC-311 postman QA collections for user, controller, agent + some cod…
Browse files Browse the repository at this point in the history
…e fixes (#313)
  • Loading branch information
Railag authored and mchepelev committed Nov 5, 2018
1 parent 04ad3b1 commit b663f4f
Show file tree
Hide file tree
Showing 6 changed files with 1,809 additions and 15 deletions.
6 changes: 3 additions & 3 deletions specs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ paths:
description: Invalid Node Id
'500':
description: Internal Server Error
'/agent/microservices/{microserviceId}':
'/agent/microservices/{microserviceUuid}':
get:
tags:
- Agent
Expand All @@ -559,8 +559,8 @@ paths:
parameters:
- in: path
required: true
name: microserviceId
description: Microservice id
name: microserviceUuid
description: Microservice UUID
type: string
- in: header
name: Authorization
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/agent-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ const getAgentMicroservicesEndPoint = async function (req, fog) {
};

const getAgentMicroserviceEndPoint = async function (req, fog) {
const microserviceId = req.params.microserviceId;
const microserviceUuid = req.params.microserviceUuid;

logger.info("Microservice id:" + JSON.stringify(microserviceId));
logger.info("Microservice UUID:" + JSON.stringify(microserviceUuid));

return await AgentService.getAgentMicroservice(microserviceId, fog);
return await AgentService.getAgentMicroservice(microserviceUuid, fog);
};

const getAgentRegistriesEndPoint = async function (req, fog) {
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
UNABLE_TO_GET_ACTIVATION_CODE: 'Unable to create activation code',
INVALID_FOG_NODE_UUID: 'Invalid ioFog UUID {}',
INVALID_USER_EMAIL: 'Invalid user email',
INVALID_MICROSERVICE_UUID: 'Invalid microservice UUID {}',
INVALID_MICROSERVICE_UUID: "Invalid microservice UUID '{}'",
ACTIVATION_CODE_NOT_FOUND: 'Activation code not found',
INVALID_OLD_PASSWORD: 'Old password is incorrect',
ACCOUNT_NOT_FOUND: 'Account not found',
Expand Down Expand Up @@ -53,6 +53,10 @@ module.exports = {
REQUIRED_FOG_NODE: 'ioFog node is required.',
INVALID_CONNECTOR_DOMAIN: 'Invalid connector domain {}',
CERT_PROPERTY_REQUIRED: 'Property "certificate" is required if property "requiresCert" is set to true',
TUNNEL_NOT_FOUND: 'Tunnel not found',
STRACE_NOT_FOUND: 'Strace not found',
INVALID_CONTENT_TYPE: 'Invalid content type',
UPLOADED_FILE_NOT_FOUND: 'Uploaded image snapshot file not found',
CLI: {
INVALID_PORT_MAPPING: 'Port mapping parsing error. Please provide valid port mapping.',
INVALID_VOLUME_MAPPING: 'Volume mapping parsing error. Please provide valid volume mapping.',
Expand Down
2 changes: 1 addition & 1 deletion src/routes/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ module.exports = [
},
{
method: 'get',
path: '/api/v3/agent/microservices/:microserviceId',
path: '/api/v3/agent/microservices/:microserviceUuid',
middleware: async (req, res) => {
const successCode = constants.HTTP_CODE_SUCCESS;
const errorCodes = [
Expand Down
37 changes: 30 additions & 7 deletions src/services/agent-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,15 @@ const getAgentMicroservices = async function (fog, transaction) {
}
};

const getAgentMicroservice = async function (microserviceId, fog, transaction) {
const getAgentMicroservice = async function (microserviceUuid, fog, transaction) {
const microservice = await MicroserviceManager.findOneWithDependencies({
uuid: microserviceId,
uuid: microserviceUuid,
iofogUuid: fog.uuid
}, {}, transaction);

if (!microservice) {
throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, microserviceUuid));
}
return {
microservice: microservice
}
Expand All @@ -280,16 +284,26 @@ const getAgentTunnel = async function (fog, transaction) {
const tunnel = await TunnelManager.findOne({
iofogUuid: fog.uuid
}, transaction);

if (!tunnel) {
throw new Errors.NotFoundError(ErrorMessages.TUNNEL_NOT_FOUND);
}

return {
tunnel: tunnel
}
};

const getAgentStrace = async function (fog, transaction) {
const fogWithDependencies = FogManager.findFogStraces({
const fogWithStrace = FogManager.findFogStraces({
uuid: fog.uuid
}, transaction);
return fogWithDependencies.strace;

if (!fogWithStrace) {
throw new Errors.NotFoundError(ErrorMessages.STRACE_NOT_FOUND);
}

return fogWithStrace.strace;
};

const updateAgentStrace = async function (straceData, fog, transaction) {
Expand Down Expand Up @@ -363,6 +377,10 @@ const getImageSnapshot = async function (fog, transaction) {
};

const putImageSnapshot = async function (req, fog, transaction) {
if (req.headers['content-type'] !== 'application/zip') {
throw new Errors.ValidationError(ErrorMessages.INVALID_CONTENT_TYPE);
}

const form = new formidable.IncomingForm();
form.uploadDir = path.join(appRoot, '../') + 'data';
if (!fs.existsSync(form.uploadDir)) {
Expand All @@ -380,12 +398,17 @@ const putImageSnapshot = async function (req, fog, transaction) {

const saveSnapShot = function (req, form) {
return new Promise((resolve, reject) => {

form.parse(req, async function (error, fields, files) {
if (error) {
reject(new Errors.ValidationError());
const file = files['upstream'];

if (file === undefined) {
reject(new Errors.ValidationError(ErrorMessages.UPLOADED_FILE_NOT_FOUND));
return;
}

const filePath = files['upstream']['path'];
const filePath = file['path'];


let absolutePath = path.resolve(filePath);
fs.rename(absolutePath, absolutePath + '.tar.gz');
Expand Down
Loading

0 comments on commit b663f4f

Please sign in to comment.