Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/server/endpoints/instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/*
* Copyright (c) 2018, Joyent, Inc.
* Copyright (c) 2019, Joyent, Inc.
*/

/*
Expand Down Expand Up @@ -47,6 +47,10 @@ function serialize(instance, version) {
obj.type = instance.type;
}

if (instance.server_uuid && !obj.params.server_uuid) {
obj.params.server_uuid = instance.server_uuid;
}

return (obj);
}

Expand Down Expand Up @@ -89,6 +93,10 @@ Instances.create = function (req, res, next) {

params.service_uuid = req.params.service_uuid;

if (req.params.params && req.params.params.server_uuid) {
params.server_uuid = req.params.params.server_uuid;
}

params.params = req.params.params;
params.metadata = req.params.metadata;
params.manifests = req.params.manifests;
Expand Down Expand Up @@ -127,6 +135,8 @@ Instances.list = function (req, res, next) {
filters.service_uuid = req.params.service_uuid;
} else if (req.params.type) {
filters.type = req.params.type;
} else if (req.params.server_uuid) {
filters.server_uuid = req.params.server_uuid;
}

var opts = {};
Expand Down Expand Up @@ -189,6 +199,7 @@ Instances.update = function (req, res, next) {
changes.metadata = req.params.metadata;
changes.manifests = req.params.manifests;


/*
* If not specified, the default action is to update existing
* attributes.
Expand Down
10 changes: 9 additions & 1 deletion lib/server/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/*
* Copyright (c) 2018, Joyent, Inc.
* Copyright (c) 2019, Joyent, Inc.
*/

/*
Expand Down Expand Up @@ -604,6 +604,7 @@ Model.prototype.createInstance = function createInstance(inst, cb) {
assert.optionalObject(inst.params, 'inst.params');
assert.optionalObject(inst.metadata, 'inst.metadata');
assert.optionalObject(inst.manifests, 'inst.manifests');
assert.optionalUuid(inst.server_uuid, 'inst.server_uuid');
assert.func(cb, 'cb');

var doAsync = inst.async || false;
Expand Down Expand Up @@ -808,6 +809,13 @@ Model.prototype.upgradeInstance = function (uuid, image_uuid, cb) {

subcb(null, inst);
});
},
function updateInst(_inst, subcb) {
self.updateInstance(uuid, {
params: {
image_uuid: image_uuid
}
}, 'update', subcb);
}
], cb);
};
Expand Down
29 changes: 27 additions & 2 deletions lib/server/stor/moray.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/*
* Copyright (c) 2018, Joyent, Inc.
* Copyright (c) 2019, Joyent, Inc.
*/

/*
Expand Down Expand Up @@ -233,6 +233,16 @@ function initBuckets(client, cb) {
type: 'string'
};

cfg.index.server_uuid = {
type: 'string'
};

// Version 0 was pre server_uuid and image_uuid, both added for
// version 1.
cfg.options = {
version: 1
};

createBucket.call(self, client,
buckets.instances, cfg, subcb);
},
Expand Down Expand Up @@ -271,10 +281,25 @@ function createBucket(client, name, cfg, cb) {
assert.object(cfg, 'cfg');
assert.func(cb, 'cb');

client.getBucket(name, function (err) {
client.getBucket(name, function (err, bucket) {
if (!err) {
log.info({ client: client.toString() },
'moray: bucket %s already exists', name);

if (cfg.options && cfg.options.version &&
bucket.options.version !== cfg.options.version) {
client.updateBucket(name, cfg, function updateBucketCb(upErr) {
if (upErr) {
log.error(err, 'failed to update bucket %s', name);
cb(err);
return;
}
log.info({ client: client.toString() },
'moray: update bucket %s', name);
cb(null);
return;
});
}
cb(null);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sapi",
"description": "Triton Services and Configuration API",
"version": "2.1.0",
"version": "2.2.0",
"author": "Joyent (joyent.com)",
"license": "MPL-2.0",
"private": true,
Expand Down
Loading