Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
batmen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sepia-pub
mael
batmen
Commits
acbd989b
Commit
acbd989b
authored
2 years ago
by
Maël Madon
Browse files
Options
Downloads
Patches
Plain Diff
refac: new class UserSubmitQueue, use of class Queue was misleading. Issue#13
parent
e4c85e93
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!14
Submission queue for replay users
Pipeline
#5514
passed with warnings
2 years ago
Stage: build-and-test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/json_workload.cpp
+74
-29
74 additions, 29 deletions
src/json_workload.cpp
src/json_workload.hpp
+30
-1
30 additions, 1 deletion
src/json_workload.hpp
src/queue.hpp
+4
-4
4 additions, 4 deletions
src/queue.hpp
with
108 additions
and
34 deletions
src/json_workload.cpp
+
74
−
29
View file @
acbd989b
...
...
@@ -206,6 +206,14 @@ bool JobComparator::operator()(Job j1, Job j2) const
return
JobComparator
::
operator
()(
&
j1
,
&
j2
);
}
bool
JobSubmissionOrder
::
operator
()(
const
Job
*
j1
,
const
Job
*
j2
)
const
{
if
(
j1
->
submission_time
==
j2
->
submission_time
)
return
jobcmp
(
j1
,
j2
);
else
return
j1
->
submission_time
<
j2
->
submission_time
;
}
bool
SessionComparator
::
operator
()(
const
Session
*
s1
,
const
Session
*
s2
)
const
{
PPK_ASSERT_ERROR
(
...
...
@@ -214,6 +222,72 @@ bool SessionComparator::operator()(const Session *s1, const Session *s2) const
return
s1
->
start_time
>
s2
->
start_time
;
}
UserSubmitQueue
::
UserSubmitQueue
(
const
std
::
string
user_name
,
const
std
::
string
input_json
)
{
/* Parse the JSON input... */
Document
doc
=
Parser
::
parse_input_json
(
input_json
);
string
error_prefix
=
"Invalid JSON file '"
+
input_json
+
"'"
;
PPK_ASSERT_ERROR
(
doc
.
IsObject
(),
"%s: not a JSON object"
,
error_prefix
.
c_str
());
PPK_ASSERT_ERROR
(
doc
.
HasMember
(
"jobs"
),
"%s: the 'jobs' array is missing"
,
error_prefix
.
c_str
());
const
Value
&
jobs
=
doc
[
"jobs"
];
PPK_ASSERT_ERROR
(
jobs
.
IsArray
(),
"%s: the 'jobs' member is not an array"
,
error_prefix
.
c_str
());
for
(
SizeType
i
=
0
;
i
<
jobs
.
Size
();
i
++
)
{
const
Value
&
job_json_description
=
jobs
[
i
];
Job
*
j
=
Parser
::
job_from_json_object
(
user_name
,
job_json_description
);
_jobs
.
push_back
(
j
);
}
/* Sort the list by submission time */
_jobs
.
sort
(
submission_order
);
}
UserSubmitQueue
::~
UserSubmitQueue
(){
for
(
auto
j
:
_jobs
){
delete
j
;
}
}
void
UserSubmitQueue
::
insert_sorted
(
const
Job
*
j
)
{
Job
*
job
=
new
Job
;
*
job
=
*
job
;
auto
start
=
_jobs
.
begin
();
auto
end
=
_jobs
.
end
();
while
(
start
!=
end
&&
submission_order
((
*
start
),
job
))
{
++
start
;
}
_jobs
.
insert
(
start
,
job
);
}
const
Job
*
UserSubmitQueue
::
top
()
const
{
return
_jobs
.
front
();
}
const
Job
*
UserSubmitQueue
::
pop
()
{
Job
*
j
=
_jobs
.
front
();
_jobs
.
pop_front
();
return
j
;
}
bool
UserSubmitQueue
::
is_empty
()
const
{
return
_jobs
.
size
()
==
0
;
}
// Mainly copy-paste from the 'load_from_json' methods from the classes
// Workload, Jobs and Profiles in batsim
Document
Parser
::
parse_input_json
(
const
string
input_json
)
...
...
@@ -243,35 +317,6 @@ Document Parser::parse_input_json(const string input_json)
return
doc
;
}
Queue
*
Parser
::
job_queue_from_input_json
(
string
user_name
,
const
string
input_json
)
{
Queue
*
job_trace
=
new
Queue
(
new
FCFSOrder
());
Document
doc
=
Parser
::
parse_input_json
(
input_json
);
string
error_prefix
=
"Invalid JSON file '"
+
input_json
+
"'"
;
PPK_ASSERT_ERROR
(
doc
.
IsObject
(),
"%s: not a JSON object"
,
error_prefix
.
c_str
());
PPK_ASSERT_ERROR
(
doc
.
HasMember
(
"jobs"
),
"%s: the 'jobs' array is missing"
,
error_prefix
.
c_str
());
const
Value
&
jobs
=
doc
[
"jobs"
];
PPK_ASSERT_ERROR
(
jobs
.
IsArray
(),
"%s: the 'jobs' member is not an array"
,
error_prefix
.
c_str
());
for
(
SizeType
i
=
0
;
i
<
jobs
.
Size
();
i
++
)
// Uses SizeType instead of size_t
{
const
Value
&
job_json_description
=
jobs
[
i
];
auto
j
=
Parser
::
job_from_json_object
(
user_name
,
job_json_description
);
job_trace
->
insert_job
(
j
);
}
return
job_trace
;
}
Session
*
Parser
::
session_graph_from_SABjson
(
const
string
user_name
,
const
string
input_json
)
{
...
...
This diff is collapsed.
Click to expand it.
src/json_workload.hpp
+
30
−
1
View file @
acbd989b
...
...
@@ -56,6 +56,12 @@ struct JobComparator
bool
operator
()(
Job
j1
,
Job
j2
)
const
;
};
struct
JobSubmissionOrder
{
JobComparator
jobcmp
;
bool
operator
()(
const
Job
*
j1
,
const
Job
*
j2
)
const
;
};
struct
Profile
{
std
::
string
name
;
...
...
@@ -86,6 +92,7 @@ struct SessionComparator
bool
operator
()(
const
Session
*
s1
,
const
Session
*
s2
)
const
;
};
/* Map of all jobs, for keeping track in the scheduler */
class
Workload
{
public:
...
...
@@ -116,7 +123,29 @@ private:
int
_job_number
=
0
;
};
class
Queue
;
/* List of jobs to submit for users, sorted by submission time */
class
UserSubmitQueue
{
public:
UserSubmitQueue
(
const
std
::
string
user_name
,
const
std
::
string
input_json
);
~
UserSubmitQueue
();
/* Insert the job in the sorted queue */
void
insert_sorted
(
const
Job
*
job
);
/* Give a pointer to the first elem */
const
Job
*
top
()
const
;
/* Remove and give a pointer to the first elem */
const
Job
*
pop
();
bool
is_empty
()
const
;
private:
std
::
list
<
Job
*>
_jobs
;
JobSubmissionOrder
submission_order
;
};
/**
* Useful parsers
...
...
This diff is collapsed.
Click to expand it.
src/queue.hpp
+
4
−
4
View file @
acbd989b
...
...
@@ -91,14 +91,14 @@ public:
Queue
(
SortableJobOrder
*
order
);
~
Queue
();
/* Insert the job at the beginning of the queue, setting its release_date
* to the current date. */
void
append_job
(
const
Job
*
job
,
SortableJobOrder
::
UpdateInformation
*
update_info
);
/* Insert the job at the beginning of the queue */
/* Insert the job at the beginning of the queue, setting its release_date
* to the job's submission date. */
void
insert_job
(
const
Job
*
job
);
/* Insert the job at the right place in the queue.
* Caution: this function assumes that the queue is already sorted! */
void
insert_sorted_job
(
const
Job
*
job
);
std
::
list
<
SortableJob
*>::
iterator
remove_job
(
const
Job
*
job
);
std
::
list
<
SortableJob
*>::
iterator
remove_job
(
std
::
list
<
SortableJob
*>::
iterator
job_it
);
void
sort_queue
(
SortableJobOrder
::
UpdateInformation
*
update_info
,
SortableJobOrder
::
CompareInformation
*
compare_info
=
nullptr
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment