Skip to content

Commit

Permalink
Fix reserved resources on task management (ansible#3017) (ansible#3068)
Browse files Browse the repository at this point in the history
Issue: AAH-2055
(cherry picked from commit db3fcd2)

Co-authored-by: David Newswanger <dnewswan@redhat.com>
  • Loading branch information
patchback[bot] and newswangerd authored Dec 22, 2022
1 parent 7fe36eb commit 9d910d0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES/2055.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where the resource type on "reserved resources" on the task management page always returns "api".
42 changes: 37 additions & 5 deletions src/containers/task-management/task_detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ interface IState {
alerts: AlertType[];
cancelModalVisible: boolean;
taskName: string;
resources: { name: string; type: string }[];
resources: {
name?: string;
type: string;
pluginName?: string;
}[];
redirect: string;
polling: ReturnType<typeof setInterval>;
}
Expand Down Expand Up @@ -263,6 +267,14 @@ class TaskDetail extends React.Component<RouteComponentProps, IState> {
{resource.type}
</DescriptionListDescription>
</DescriptionListGroup>
{resource.pluginName && (
<DescriptionListGroup>
<DescriptionListTerm>{t`Plugin`}</DescriptionListTerm>
<DescriptionListDescription>
{resource.pluginName}
</DescriptionListDescription>
</DescriptionListGroup>
)}
{resource.name && (
<DescriptionListGroup>
<DescriptionListTerm>{t`Name`}</DescriptionListTerm>
Expand Down Expand Up @@ -456,20 +468,40 @@ class TaskDetail extends React.Component<RouteComponentProps, IState> {
result.data.reserved_resources_record.forEach((resource) => {
const url = resource.replace(PULP_API_BASE_PATH, '');
const id = parsePulpIDFromURL(url);
const urlParts = resource.split('/');
const type = id ? urlParts[4] : urlParts[urlParts.length - 2];
const urlParts = url.split('/');
let resourceType = '';
let pluginName = '';

// pulp hrefs follow this pattern for resources added by plugins:
// /<resource name>/<plugin name>/<resource type>/<pk>/
// Locks can be added on the entire resource (ex /repositories/) or on a specific
// instance of a resource (ex /repositories/ansible/ansible/123123/

// if the url has 3 or more segements, parse out the resource, plugin name, and resource type
if (urlParts.length >= 3) {
resourceType = `${urlParts[0]}: ${urlParts[2]}`;
pluginName = urlParts[1];
// otherwise, just return the resource type
} else {
resource = urlParts[0];
}

if (id) {
allRelatedTasks.push(
GenericPulpAPI.get(url)
.then((result) => {
resources.push({ name: result.data.name, type });
resources.push({
name: result.data.name,
type: resourceType,
pluginName: pluginName,
});
})
.catch(() => {
return true;
}),
);
} else {
resources.push({ type });
resources.push({ type: resourceType });
}
});
}
Expand Down

0 comments on commit 9d910d0

Please sign in to comment.