Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Refactor storage by leveraging persistent volumes
Browse files Browse the repository at this point in the history
Refactor storage by leveraging kubernetes pv and pvc.
  • Loading branch information
abuccts committed Jan 20, 2020
1 parent 0746d77 commit ecc4aaa
Show file tree
Hide file tree
Showing 15 changed files with 258 additions and 975 deletions.
362 changes: 58 additions & 304 deletions src/rest-server/docs/swagger.yaml

Large diffs are not rendered by default.

213 changes: 17 additions & 196 deletions src/rest-server/src/controllers/v2/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,206 +16,27 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// module dependencies
const createError = require('@pai/utils/error');
const storageModel = require('@pai/models/v2/storage');
const {isArray, isEmpty} = require('lodash');
const asyncHandler = require('@pai/middlewares/v2/asyncHandler');
const storage = require('@pai/models/v2/storage');

const getStorageServer = async (req, res, next) => {
try {
const name = req.params.name;
const storageServerInfo = await storageModel.getStorageServer(name);
return res.status(200).json(storageServerInfo);
} catch (error) {
return next(createError.unknown(error));
}
};

const getStorageServers = async (req, res, next) => {
try {
const names = isEmpty(req.query.names)
? []
: isArray(req.query.names)
? req.query.names
: [req.query.names];
const storageServerList = await storageModel.getStorageServers(names);
return res.status(200).json(storageServerList);
} catch (error) {
return next(createError.unknown(error));
}
};
const list = asyncHandler(async (req, res) => {
const userName = req.user.username;
const admin = req.user.admin;
const data = await storage.list(admin ? undefined : userName);
res.json(data);
});

const getStorageConfig = async (req, res, next) => {
try {
const name = req.params.name;
const storageConfigInfo = await storageModel.getStorageConfig(name);
return res.status(200).json(storageConfigInfo);
} catch (error) {
return next(createError.unknown(error));
}
};

const getStorageConfigs = async (req, res, next) => {
try {
const names = isEmpty(req.query.names)
? []
: isArray(req.query.names)
? req.query.names
: [req.query.names];
const storageConfigList = await storageModel.getStorageConfigs(names);
return res.status(200).json(storageConfigList);
} catch (error) {
return next(createError.unknown(error));
}
};

const createStorageServer = async (req, res, next) => {
try {
if (!req.user.admin) {
next(
createError(
'Forbidden',
'ForbiddenUserError',
`Non-admin is not allow to do this operation.`
)
);
}
const name = req.body.spn;
const value = {
spn: req.body.spn,
type: req.body.type,
data: req.body.data,
};
await storageModel.createStorageServer(name, value);
return res.status(201).json({
message: 'Storage Server is created successfully',
});
} catch (error) {
return next(createError.unknown(error));
}
};

const updateStorageServer = async (req, res, next) => {
try {
if (!req.user.admin) {
next(
createError(
'Forbidden',
'ForbiddenUserError',
`Non-admin is not allow to do this operation.`
)
);
}
const name = req.body.spn;
const value = {
spn: req.body.spn,
type: req.body.type,
data: req.body.data,
};
await storageModel.updateStorageServer(name, value);
return res.status(201).json({
message: 'Storage Server is updated successfully',
});
} catch (error) {
return next(createError.unknown(error));
}
};

const deleteStorageServer = async (req, res, next) => {
try {
if (!req.user.admin) {
next(
createError(
'Forbidden',
'ForbiddenUserError',
`Non-admin is not allow to do this operation.`
)
);
}
const name = req.params.name;
await storageModel.deleteStorageServer(name);
return res.status(201).json({
message: 'Storage Server is deleted successfully',
});
} catch (error) {
return next(createError.unknown(error));
}
};

const createStorageConfig = async (req, res, next) => {
try {
if (!req.user.admin) {
next(
createError(
'Forbidden',
'ForbiddenUserError',
`Non-admin is not allow to do this operation.`
)
);
}
const name = req.body.name;
const value = req.body;
await storageModel.createStorageConfig(name, value);
return res.status(201).json({
message: 'Storage Config is created successfully',
});
} catch (error) {
return next(createError.unknown(error));
}
};

const updateStorageConfig = async (req, res, next) => {
try {
if (!req.user.admin) {
next(
createError(
'Forbidden',
'ForbiddenUserError',
`Non-admin is not allow to do this operation.`
)
);
}
const name = req.body.name;
const value = req.body;
await storageModel.updateStorageConfig(name, value);
return res.status(201).json({
message: 'Storage Config is updated successfully',
});
} catch (error) {
return next(createError.unknown(error));
}
};

const deleteStorageConfig = async (req, res, next) => {
try {
if (!req.user.admin) {
next(
createError(
'Forbidden',
'ForbiddenUserError',
`Non-admin is not allow to do this operation.`
)
);
}
const name = req.params.name;
await storageModel.deleteStorageConfig(name);
return res.status(201).json({
message: 'Storage Config is deleted successfully',
});
} catch (error) {
return next(createError.unknown(error));
}
};
const get = asyncHandler(async (req, res) => {
const storageName = req.params.storageName
const userName = req.user.username;
const admin = req.user.admin;
const data = await storage.get(storageName, admin ? undefined : userName);
res.json(data);
});

// module exports
module.exports = {
getStorageServer,
getStorageServers,
getStorageConfig,
getStorageConfigs,
createStorageServer,
updateStorageServer,
deleteStorageServer,
createStorageConfig,
updateStorageConfig,
deleteStorageConfig,
list,
get,
};
11 changes: 0 additions & 11 deletions src/rest-server/src/controllers/v2/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ const getUserVCs = async (username) => {
return [...virtualClusters];
};

const getUserStorageConfigs = async (username) => {
const userInfo = await userModel.getUser(username);
let storageConfigs = new Set();
for (const group of userInfo.grouplist) {
const groupStorageConfigs = await groupModel.getGroupStorageConfigs(group);
storageConfigs = new Set([...storageConfigs, ...groupStorageConfigs]);
}
return [...storageConfigs];
};

const getUser = async (req, res, next) => {
try {
const username = req.params.username;
Expand Down Expand Up @@ -472,5 +462,4 @@ module.exports = {
updateUserPassword,
createUser,
getUserVCs,
getUserStorageConfigs,
};
66 changes: 0 additions & 66 deletions src/rest-server/src/middlewares/cache.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/rest-server/src/models/v2/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ const getStorageConfigsWithGroupInfo = async (groupItems) => {
return [...storageConfigs];
};

const getGroupStorageConfigs = async (groupname) => {
const getGroupStorages = async (groupname) => {
const groupItem = await getGroup(groupname);
return getStorageConfigsWithGroupInfo([groupItem]);
};

const getGroupsStorageConfigs = async (grouplist) => {
const getGroupsStorages = async (grouplist) => {
const groupItems = await getListGroup(grouplist);
return getStorageConfigsWithGroupInfo(groupItems);
};
Expand Down Expand Up @@ -489,8 +489,8 @@ module.exports = {
getGroupVCs,
getGroupsVCs,
getVCsWithGroupInfo,
getGroupStorageConfigs,
getGroupsStorageConfigs,
getGroupStorages,
getGroupsStorages,
getStorageConfigsWithGroupInfo,
filterExistGroups,
};
Loading

0 comments on commit ecc4aaa

Please sign in to comment.