2017-05-27 19:35:38 +03:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-02 00:25:45 +03:00
|
|
|
const Yamljs = require('yamljs');
|
|
|
|
|
2017-05-27 19:35:38 +03:00
|
|
|
|
2017-06-05 23:54:44 +03:00
|
|
|
exports.fromPortal = function ({ portal, datacenter, deploymentGroups, user }) {
|
2017-05-27 19:35:38 +03:00
|
|
|
return {
|
|
|
|
id: portal.id,
|
2017-06-05 23:54:44 +03:00
|
|
|
user,
|
2017-05-27 19:35:38 +03:00
|
|
|
datacenter,
|
2017-06-08 00:35:45 +03:00
|
|
|
deploymentGroups
|
2017-05-27 19:35:38 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toPortal = function (clientPortal) {
|
|
|
|
return {
|
2017-06-05 23:54:44 +03:00
|
|
|
user_id: clientPortal.user ? clientPortal.user.id : '',
|
2017-05-27 19:35:38 +03:00
|
|
|
datacenter_id: clientPortal.datacenter ? clientPortal.datacenter.id : '',
|
|
|
|
deployment_group_ids: clientPortal.deploymentGroups ? clientPortal.deploymentGroups.map((deploymentGroup) => {
|
|
|
|
return deploymentGroup.id;
|
|
|
|
}) : []
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-06-02 00:25:45 +03:00
|
|
|
|
2017-05-27 19:35:38 +03:00
|
|
|
exports.fromDeploymentGroup = function (deploymentGroup, services) {
|
|
|
|
return {
|
|
|
|
id: deploymentGroup.id,
|
|
|
|
name: deploymentGroup.name,
|
|
|
|
slug: deploymentGroup.slug,
|
2017-06-08 00:35:45 +03:00
|
|
|
services,
|
2017-05-27 19:35:38 +03:00
|
|
|
version: deploymentGroup.version_id,
|
|
|
|
history: deploymentGroup.history_version_ids || []
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-05-31 01:08:06 +03:00
|
|
|
exports.toDeploymentGroup = function ({ name }) {
|
|
|
|
return {
|
|
|
|
name,
|
2017-06-09 21:13:22 +03:00
|
|
|
slug: name,
|
2017-05-31 01:08:06 +03:00
|
|
|
services: [],
|
|
|
|
version_id: '',
|
|
|
|
history_version_ids: []
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-05-27 19:35:38 +03:00
|
|
|
|
2017-05-31 22:27:53 +03:00
|
|
|
exports.fromService = function ({ service, instances, packages }) {
|
|
|
|
return {
|
|
|
|
id: service.id,
|
|
|
|
hash: service.version_hash,
|
2017-06-02 00:25:45 +03:00
|
|
|
deploymentGroupId: service.deployment_group_id,
|
2017-05-31 22:27:53 +03:00
|
|
|
name: service.name,
|
|
|
|
slug: service.slug,
|
|
|
|
environment: service.environment || [],
|
2017-06-08 23:50:12 +03:00
|
|
|
instances,
|
2017-05-31 22:27:53 +03:00
|
|
|
currentMetrics: [],
|
|
|
|
connections: service.service_dependency_ids,
|
|
|
|
package: packages ? exports.fromPackage(packages) : {},
|
|
|
|
parent: service.parent_id || ''
|
|
|
|
};
|
|
|
|
};
|
2017-05-27 19:35:38 +03:00
|
|
|
|
2017-05-31 22:27:53 +03:00
|
|
|
exports.toService = function (clientService) {
|
|
|
|
return {
|
2017-06-09 21:13:22 +03:00
|
|
|
version_hash: clientService.hash || clientService.name,
|
2017-06-02 00:25:45 +03:00
|
|
|
deployment_group_id: clientService.deploymentGroupId,
|
2017-05-31 22:27:53 +03:00
|
|
|
name: clientService.name,
|
2017-06-02 00:25:45 +03:00
|
|
|
slug: clientService.slug || '',
|
2017-05-31 22:27:53 +03:00
|
|
|
environment: clientService.environment || {},
|
2017-06-02 00:25:45 +03:00
|
|
|
instance_ids: clientService.instances ? clientService.instances.map((instance) => { return instance.id; }) : [],
|
2017-05-31 22:27:53 +03:00
|
|
|
service_dependency_ids: clientService.connections || [],
|
|
|
|
package_id: clientService.package ? clientService.package.id : '',
|
|
|
|
parent_id: clientService.parent || ''
|
|
|
|
};
|
2017-05-27 19:35:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.toVersion = function (clientVersion) {
|
|
|
|
return {
|
|
|
|
id: clientVersion.id,
|
|
|
|
created: clientVersion.created || Date.now(),
|
|
|
|
manifest_id: clientVersion.manifestId,
|
|
|
|
service_scales: clientVersion.scales ? clientVersion.scales.map(exports.toScale) : [],
|
|
|
|
plan: exports.toPlan(clientVersion.plan || {})
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fromVersion = function (version) {
|
|
|
|
return {
|
|
|
|
id: version.id,
|
|
|
|
created: version.created,
|
|
|
|
manifestId: version.manifest_id,
|
|
|
|
scales: version.service_scales ? version.service_scales.map(exports.fromScale) : [],
|
|
|
|
plan: exports.fromPlan(version.plan || {})
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.toScale = function (clientScale) {
|
|
|
|
return {
|
|
|
|
service_name: clientScale.serviceName,
|
|
|
|
replicas: clientScale.replicas
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fromScale = function (scale) {
|
|
|
|
return {
|
|
|
|
serviceName: scale.service_name,
|
|
|
|
replicas: scale.replicas
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.toPlan = function (clientPlan) {
|
|
|
|
return {
|
|
|
|
running: clientPlan.running,
|
|
|
|
actions: clientPlan.actions
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fromPlan = function (plan) {
|
|
|
|
return {
|
|
|
|
running: plan.running,
|
|
|
|
actions: plan.actions
|
|
|
|
};
|
|
|
|
};
|
2017-05-31 01:08:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
exports.toManifest = function (clientManifest) {
|
|
|
|
return {
|
|
|
|
id: clientManifest.id,
|
|
|
|
deployment_group_id: clientManifest.deploymentGroupId,
|
|
|
|
created: clientManifest.created || Date.now(),
|
|
|
|
type: clientManifest.type,
|
|
|
|
format: clientManifest.format,
|
|
|
|
raw: clientManifest.raw,
|
2017-06-02 00:25:45 +03:00
|
|
|
json: clientManifest.json || Yamljs.parse(clientManifest.raw)
|
2017-05-31 01:08:06 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fromManifest = function (manifest) {
|
|
|
|
return {
|
|
|
|
id: manifest.id,
|
|
|
|
deploymentGroupId: manifest.deployment_group_id,
|
|
|
|
created: manifest.created,
|
|
|
|
type: manifest.type,
|
|
|
|
format: manifest.format,
|
|
|
|
raw: manifest.raw,
|
|
|
|
json: manifest.json
|
|
|
|
};
|
|
|
|
};
|
2017-05-31 22:27:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
exports.fromPackage = function (packages) {
|
|
|
|
return packages;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toPackage = function (packages) {
|
|
|
|
return packages;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.fromInstance = function (instance) {
|
|
|
|
return {
|
|
|
|
id: instance.id,
|
|
|
|
name: instance.name,
|
|
|
|
machineId: instance.machine_id,
|
|
|
|
status: instance.status || ''
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toInstance = function (clientInstance) {
|
|
|
|
return {
|
|
|
|
id: clientInstance.id,
|
|
|
|
name: clientInstance.name,
|
|
|
|
machine_id: clientInstance.machineId,
|
|
|
|
status: clientInstance.status || ''
|
|
|
|
};
|
|
|
|
};
|
2017-06-05 23:54:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
exports.fromUser = function (user) {
|
|
|
|
return {
|
|
|
|
id: user.id,
|
|
|
|
firstName: user.first_name,
|
|
|
|
lastName: user.last_name,
|
|
|
|
email: user.email,
|
|
|
|
login: user.login
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.toUser = function (clientUser) {
|
|
|
|
return {
|
|
|
|
id: clientUser.id,
|
|
|
|
first_name: clientUser.firstName,
|
|
|
|
last_name: clientUser.lastName,
|
|
|
|
email: clientUser.email,
|
|
|
|
login: clientUser.login
|
|
|
|
};
|
|
|
|
};
|