Skip to content

Commit cde5516

Browse files
committed
[DAPS-1515] Make usage of globus and metadata files
1 parent 8bfc1d1 commit cde5516

File tree

2 files changed

+72
-41
lines changed

2 files changed

+72
-41
lines changed

core/database/foxx/api/repo_router.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,11 @@ router
773773
throw g_lib.ERR_PERM_DENIED;
774774
}
775775

776+
// Check if subject exists
777+
if (!g_db._exists(subject_id)) {
778+
throw [g_lib.ERR_NOT_FOUND, "Subject not found: " + subject_id];
779+
}
780+
776781
// Delete allocation using the new system
777782
var deleteResult = RepositoryOps.deleteAllocation(repository, subject_id);
778783

core/database/foxx/api/tasks.js

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use strict";
22

3-
// local imports
43
const g_lib = require("./support");
54
const { UserToken } = require("./lib/user_token");
65
const { RepositoryOps } = require("./repository/operations");
@@ -11,8 +10,31 @@ const g_graph = require("@arangodb/general-graph")._graph("sdmsg");
1110
const g_proc = require("./process");
1211
var g_internal = require("internal");
1312

14-
var tasks_func = (function () {
15-
var obj = {};
13+
const tasks_func = (function () {
14+
const obj = {};
15+
16+
// Helper function to validate repository supports data operations
17+
function validateRepositorySupportsDataOperations(loc, dataId) {
18+
if (loc) {
19+
const findResult = RepositoryOps.find(loc._to);
20+
if (findResult.ok) {
21+
const repository = findResult.value;
22+
const dataOpsResult = RepositoryOps.supportsDataOperations(repository);
23+
24+
if (dataOpsResult.ok && !dataOpsResult.value) {
25+
throw [
26+
g_lib.ERR_INVALID_OPERATION,
27+
`Data transfers not supported for ${repository.type} repository`,
28+
{
29+
repo_type: repository.type,
30+
repo_id: repository.data._id,
31+
data_id: dataId,
32+
},
33+
];
34+
}
35+
}
36+
}
37+
}
1638

1739
// ----------------------- ALLOC CREATE ----------------------------
1840

@@ -316,25 +338,7 @@ var tasks_func = (function () {
316338
var data = result.glob_data[i];
317339
// Get repository from data location
318340
var loc = g_db.loc.firstExample({ _from: data.id });
319-
if (loc) {
320-
var findResult = RepositoryOps.find(loc._to);
321-
if (findResult.ok) {
322-
var repository = findResult.value;
323-
var dataOpsResult = RepositoryOps.supportsDataOperations(repository);
324-
325-
if (dataOpsResult.ok && !dataOpsResult.value) {
326-
throw [
327-
g_lib.ERR_INVALID_OPERATION,
328-
"Data transfers not supported for metadata-only repository",
329-
{
330-
repo_type: repository.type,
331-
repo_id: repository.data._id,
332-
data_id: data.id,
333-
},
334-
];
335-
}
336-
}
337-
}
341+
validateRepositorySupportsDataOperations(loc, data.id);
338342
}
339343
}
340344

@@ -528,25 +532,7 @@ var tasks_func = (function () {
528532
var data = result.glob_data[i];
529533
// Get repository from data location
530534
var loc = g_db.loc.firstExample({ _from: data.id });
531-
if (loc) {
532-
var findResult = RepositoryOps.find(loc._to);
533-
if (findResult.ok) {
534-
var repository = findResult.value;
535-
var dataOpsResult = RepositoryOps.supportsDataOperations(repository);
536-
537-
if (dataOpsResult.ok && !dataOpsResult.value) {
538-
throw [
539-
g_lib.ERR_INVALID_OPERATION,
540-
"Data transfers not supported for metadata-only repository",
541-
{
542-
repo_type: repository.type,
543-
repo_id: repository.data._id,
544-
data_id: data.id,
545-
},
546-
];
547-
}
548-
}
549-
}
535+
validateRepositorySupportsDataOperations(loc, data.id);
550536
}
551537
}
552538

@@ -2874,6 +2860,46 @@ var tasks_func = (function () {
28742860
//console.log("_ensureExclusiveAccess done", Date.now());
28752861
};
28762862

2863+
// ----------------------- REPO ALLOCATION WRAPPERS ----------------------------
2864+
2865+
// Wrapper for allocation creation (used by repository factory pattern)
2866+
obj.repoAllocationCreateTask = function (params) {
2867+
// Extract parameters from the params object
2868+
const { repo_id, subject, size, path, metadata } = params;
2869+
2870+
// Get the repository to determine limits
2871+
const repo = g_db.repo.document(repo_id);
2872+
2873+
// Use a reasonable default for rec_limit if not specified
2874+
const rec_limit = params.rec_limit || 1000000; // 1 million records as default
2875+
2876+
// Create a dummy client object that has admin permissions
2877+
// This is because the repository operations have already validated permissions
2878+
const systemClient = { _id: "system", is_admin: true };
2879+
2880+
// Call the existing taskInitAllocCreate function
2881+
return obj.taskInitAllocCreate(
2882+
systemClient,
2883+
repo_id,
2884+
subject,
2885+
size || repo.capacity, // Use repo capacity if size not specified
2886+
rec_limit,
2887+
);
2888+
};
2889+
2890+
// Wrapper for allocation deletion (used by repository factory pattern)
2891+
obj.repoAllocationDeleteTask = function (params) {
2892+
// Extract parameters from the params object
2893+
const { repo_id, subject } = params;
2894+
2895+
// Create a dummy client object that has admin permissions
2896+
// This is because the repository operations have already validated permissions
2897+
const systemClient = { _id: "system", is_admin: true };
2898+
2899+
// Call the existing taskInitAllocDelete function
2900+
return obj.taskInitAllocDelete(systemClient, repo_id, subject);
2901+
};
2902+
28772903
return obj;
28782904
})();
28792905

0 commit comments

Comments
 (0)