Skip to content

Commit 601d8e7

Browse files
committed
feat(dedicated.pcc): remove 2API to fetch hosts
decommission sws-dedicatedCloud-datacenters-hosts resolves: #MANAGER-17155 Signed-off-by: David Arsène <david.arsene.ext@ovhcloud.com>
1 parent 8e14670 commit 601d8e7

File tree

9 files changed

+129
-132
lines changed

9 files changed

+129
-132
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import get from 'lodash/get';
2+
import set from 'lodash/set';
23

34
import {
4-
RESOURCE_BILLING_2API_TYPES,
5+
RESOURCE_BILLING_TYPES,
6+
RESOURCE_STATES,
57
RESOURCE_UPGRADE_TYPES,
68
} from '../../resource/upgrade/upgrade.constants';
79

@@ -20,46 +22,39 @@ export default class {
2022
this.dedicatedCloudDataCenterHostService = dedicatedCloudDataCenterHostService;
2123
this.ovhManagerPccDatacenterService = ovhManagerPccDatacenterService;
2224
this.DEDICATED_CLOUD_DATACENTER = DEDICATED_CLOUD_DATACENTER;
25+
this.RESOURCE_BILLING_TYPES = RESOURCE_BILLING_TYPES;
26+
this.RESOURCE_UPGRADE_TYPES = RESOURCE_UPGRADE_TYPES;
27+
this.RESOURCE_STATES = RESOURCE_STATES;
2328
}
2429

2530
$onInit() {
26-
this.RESOURCE_BILLING_TYPES = RESOURCE_BILLING_2API_TYPES;
27-
this.RESOURCE_UPGRADE_TYPES = RESOURCE_UPGRADE_TYPES;
28-
2931
this.datacenter.model.commercialRangeName = this.commercialRangeName;
30-
}
31-
32-
fetchLegacyHostConsumption(hosts) {
33-
return this.$q.all(
34-
hosts.map((host) =>
35-
host.billingType === this.RESOURCE_BILLING_TYPES.hourly
36-
? this.dedicatedCloudDataCenterHostService
37-
.getHostHourlyConsumption(
38-
this.productId,
39-
this.datacenterId,
40-
host.hostId,
41-
)
42-
.then((consumption) => ({ ...host, ...consumption }))
43-
.catch(() => host)
44-
: host,
45-
),
32+
this.$serviceConsumption = this.ovhManagerPccDatacenterService.fetchConsumptionForService(
33+
this.serviceId,
4634
);
4735
}
4836

49-
fetchConsumptionForHosts(hosts) {
50-
return (serviceConsumption) =>
51-
this.$q.all(
52-
serviceConsumption
53-
? hosts.map(this.fetchConsumptionForHost(serviceConsumption))
54-
: hosts,
55-
);
37+
fetchLegacyHostConsumption(host) {
38+
return host.billingType === this.RESOURCE_BILLING_TYPES.hourly
39+
? this.dedicatedCloudDataCenterHostService
40+
.getHostHourlyConsumption(
41+
this.productId,
42+
this.datacenterId,
43+
host.hostId,
44+
)
45+
.then((consumption) => {
46+
set(host, 'consumption', consumption);
47+
})
48+
.catch(() => null)
49+
: host;
5650
}
5751

58-
fetchConsumptionForHost(serviceConsumption) {
59-
return (host) => {
52+
fetchConsumptionForHost(host) {
53+
return (serviceConsumption) => {
6054
if (
55+
serviceConsumption &&
6156
host.billingType === this.RESOURCE_BILLING_TYPES.hourly &&
62-
host.status === 'DELIVERED'
57+
host.state === RESOURCE_STATES.delivered
6358
) {
6459
const hostConsumption = this.ovhManagerPccDatacenterService.constructor.extractElementConsumption(
6560
serviceConsumption,
@@ -69,56 +64,51 @@ export default class {
6964
},
7065
);
7166

72-
return {
73-
...host,
74-
consumption: {
75-
value: get(hostConsumption, 'quantity', 0),
76-
},
77-
lastUpdate: serviceConsumption.lastUpdate,
78-
};
67+
set(host, 'consumption', {
68+
value: get(hostConsumption, 'quantity', 0),
69+
});
70+
set(host, 'lastUpdate', serviceConsumption.lastUpdate);
7971
}
8072

8173
return host;
8274
};
8375
}
8476

85-
chooseConsumptionFetchingMethod(hosts) {
77+
chooseConsumptionFetchingMethod(host) {
8678
return !this.usesLegacyOrder
87-
? this.ovhManagerPccDatacenterService
88-
.fetchConsumptionForService(this.serviceId)
89-
.then(this.fetchConsumptionForHosts(hosts))
90-
: this.fetchLegacyHostConsumption(hosts);
79+
? this.$serviceConsumption.then(this.fetchConsumptionForHost(host))
80+
: this.fetchLegacyHostConsumption(host);
9181
}
9282

93-
fetchLocations(hosts) {
94-
return this.$q.all(
95-
hosts.map((host) => {
96-
return this.dedicatedCloudDataCenterHostService
97-
.getHostLocation(this.productId, this.datacenterId, host.hostId)
98-
.then((location) => ({ ...host, location }))
99-
.catch(() => host);
100-
}),
101-
);
83+
fetchLocation(host) {
84+
return this.dedicatedCloudDataCenterHostService
85+
.getHostLocation(this.productId, this.datacenterId, host.hostId)
86+
.then((location) => {
87+
set(host, 'location', location);
88+
})
89+
.catch(() => null);
10290
}
10391

10492
loadHosts({ offset, pageSize }) {
105-
return this.DedicatedCloud.getPaginatedHosts(
106-
this.productId,
107-
this.datacenterId,
108-
pageSize,
109-
offset - 1,
110-
).then((result) =>
111-
this.chooseConsumptionFetchingMethod(result.list.results).then(
112-
(hostsWithConsumption) =>
113-
this.fetchLocations(hostsWithConsumption).then(
114-
(hostsWithLocation) => ({
115-
data: hostsWithLocation,
116-
meta: {
117-
totalCount: result.count,
118-
},
119-
}),
120-
),
121-
),
122-
);
93+
return this.dedicatedCloudDataCenterHostService
94+
.getPaginatedHosts(this.productId, this.datacenterId, {
95+
pageSize,
96+
offset: offset - 1,
97+
sort: 'hostId',
98+
})
99+
.then(({ data, meta }) => {
100+
data.forEach((host) => {
101+
set(host, 'asyncLoading', true);
102+
this.$q
103+
.all([
104+
this.chooseConsumptionFetchingMethod(host),
105+
this.fetchLocation(host),
106+
])
107+
.finally(() => {
108+
set(host, 'asyncLoading', false);
109+
});
110+
});
111+
return { data, meta };
112+
});
123113
}
124114
}

packages/manager/apps/dedicated/client/app/components/dedicated-cloud/datacenter/host/dedicatedCloud-datacenter-host.html

+24-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ <h2 data-translate="dedicatedCloud_tab_host"></h2>
2424
data-title=":: 'dedicatedCloud_tab_host_profile' | translate"
2525
data-property="profile"
2626
>
27-
<span data-ng-bind=":: $row.profile"></span>
2827
</oui-datagrid-column>
2928
<oui-datagrid-column
3029
data-title=":: 'dedicatedCloud_tab_host_billing' | translate"
@@ -37,18 +36,32 @@ <h2 data-translate="dedicatedCloud_tab_host"></h2>
3736
data-title=":: 'dedicatedCloud_tab_host_status' | translate"
3837
>
3938
<span
40-
data-translate="{{ 'dedicatedCloud_tab_host_status_' + $row.status }}"
39+
data-translate="{{ 'dedicatedCloud_tab_host_status_' + $row.state }}"
4140
></span>
4241
</oui-datagrid-column>
4342
<oui-datagrid-column
4443
data-title=":: 'dedicatedCloud_tab_host_location_datacenter' | translate"
4544
>
46-
<span data-ng-bind="$row.location.datacenter"></span>
45+
<oui-skeleton
46+
size="xs"
47+
data-ng-if="$row.asyncLoading"
48+
></oui-skeleton>
49+
<span
50+
data-ng-if="!$row.asyncLoading"
51+
data-ng-bind="$row.location.datacenter"
52+
></span>
4753
</oui-datagrid-column>
4854
<oui-datagrid-column
4955
data-title=":: 'dedicatedCloud_tab_host_location_room' | translate"
5056
>
51-
<span data-ng-bind="$row.location.room"></span>
57+
<oui-skeleton
58+
size="xs"
59+
data-ng-if="$row.asyncLoading"
60+
></oui-skeleton>
61+
<span
62+
data-ng-if="!$row.asyncLoading"
63+
data-ng-bind="$row.location.room"
64+
></span>
5265
</oui-datagrid-column>
5366
<oui-datagrid-column
5467
data-title=":: 'dedicatedCloud_tab_host_location_rack' | translate"
@@ -58,8 +71,12 @@ <h2 data-translate="dedicatedCloud_tab_host"></h2>
5871
<oui-datagrid-column
5972
data-title=":: 'dedicatedCloud_tab_host_consumption' | translate"
6073
>
74+
<oui-skeleton
75+
size="xs"
76+
data-ng-if="$row.asyncLoading"
77+
></oui-skeleton>
6178
<span
62-
data-ng-if="$row.billingType === $ctrl.RESOURCE_BILLING_TYPES.hourly"
79+
data-ng-if="!$row.asyncLoading && $row.billingType === $ctrl.RESOURCE_BILLING_TYPES.hourly"
6380
>
6481
<span
6582
data-ng-if="!$row.consumption"
@@ -82,7 +99,8 @@ <h2 data-translate="dedicatedCloud_tab_host"></h2>
8299
</oui-datagrid-column>
83100
<oui-action-menu
84101
data-compact
85-
data-ng-if="$row.billingType === $ctrl.RESOURCE_BILLING_TYPES.hourly && $row.status === 'DELIVERED'"
102+
data-ng-if="$row.billingType === $ctrl.RESOURCE_BILLING_TYPES.hourly && $row.state === $ctrl.RESOURCE_STATES.delivered"
103+
data-disabled="$row.asyncLoading"
86104
data-placement="end"
87105
>
88106
<oui-action-menu-item
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
export default class {
22
/* @ngInject */
3-
constructor(OvhHttp, $http) {
4-
this.OvhHttp = OvhHttp;
3+
constructor($http, icerbergUtils) {
54
this.$http = $http;
5+
this.icerbergUtils = icerbergUtils;
66
}
77

88
getHostHourlyConsumption(serviceName, datacenterId, hostId) {
9-
return this.OvhHttp.get(
10-
`/dedicatedCloud/${serviceName}/datacenter/${datacenterId}/host/${hostId}/hourlyConsumption`,
11-
{
12-
rootPath: 'apiv6',
13-
},
14-
);
9+
return this.$http
10+
.get(
11+
`/dedicatedCloud/${serviceName}/datacenter/${datacenterId}/host/${hostId}/hourlyConsumption`,
12+
)
13+
.then(({ data }) => data);
1514
}
1615

1716
getHostLocation(serviceName, datacenterId, hostId) {
@@ -21,4 +20,11 @@ export default class {
2120
)
2221
.then(({ data }) => data);
2322
}
23+
24+
getPaginatedHosts(serviceName, datacenterId, paginationParams) {
25+
return this.icerbergUtils.icebergQuery(
26+
`/dedicatedCloud/${serviceName}/datacenter/${datacenterId}/host`,
27+
paginationParams,
28+
);
29+
}
2430
}

packages/manager/apps/dedicated/client/app/components/dedicated-cloud/datacenter/host/translations/Messages_fr_FR.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
"dedicatedCloud_tab_host_name": "Nom",
44
"dedicatedCloud_tab_host_profile": "Profil",
55
"dedicatedCloud_tab_host_billing": "Facturation",
6-
"dedicatedCloud_tab_host_billing_HOURLY": "A l'heure",
7-
"dedicatedCloud_tab_host_billing_MONTHLY": "Au mois",
8-
"dedicatedCloud_tab_host_billing_FREE_SPARE": "Spare gratuit",
9-
"dedicatedCloud_tab_host_billing_UNDEFINED": "Indéfini",
6+
"dedicatedCloud_tab_host_billing_hourly": "A l'heure",
7+
"dedicatedCloud_tab_host_billing_monthly": "Au mois",
8+
"dedicatedCloud_tab_host_billing_freeSpare": "Spare gratuit",
9+
"dedicatedCloud_tab_host_billing_undefined": "Indéfini",
1010
"dedicatedCloud_tab_host_status": "État",
11-
"dedicatedCloud_tab_host_status_ADDING": "Ajout en cours",
12-
"dedicatedCloud_tab_host_status_DELIVERED": "Actif",
13-
"dedicatedCloud_tab_host_status_ERROR": "Erreur",
14-
"dedicatedCloud_tab_host_status_REMOVING": "Suppression en cours",
15-
"dedicatedCloud_tab_host_status_UNKNOWN": "Inconnu",
11+
"dedicatedCloud_tab_host_status_adding": "Ajout en cours",
12+
"dedicatedCloud_tab_host_status_delivered": "Actif",
13+
"dedicatedCloud_tab_host_status_error": "Erreur",
14+
"dedicatedCloud_tab_host_status_removing": "Suppression en cours",
15+
"dedicatedCloud_tab_host_status_unknown": "Inconnu",
1616
"dedicatedCloud_tab_host_location_datacenter": "Datacenter",
1717
"dedicatedCloud_tab_host_location_room": "Salle",
1818
"dedicatedCloud_tab_host_location_rack": "Baie",

packages/manager/apps/dedicated/client/app/components/dedicated-cloud/dedicatedCloud.service.js

-17
Original file line numberDiff line numberDiff line change
@@ -436,23 +436,6 @@ class DedicatedCloudService {
436436

437437
/* ------- SUB DATACENTER HOSTS -------*/
438438

439-
getPaginatedHosts(serviceName, datacenterId, elementsByPage, elementsToSkip) {
440-
return this.OvhHttp.get(
441-
'/sws/dedicatedCloud/{serviceName}/datacenters/{datacenterId}/hosts',
442-
{
443-
rootPath: '2api',
444-
urlParams: {
445-
serviceName,
446-
datacenterId,
447-
},
448-
params: {
449-
count: elementsByPage,
450-
offset: elementsToSkip,
451-
},
452-
},
453-
);
454-
}
455-
456439
getHosts(serviceName, datacenterId) {
457440
return this.OvhHttp.get(
458441
'/dedicatedCloud/{serviceName}/datacenter/{datacenterId}/host',

packages/manager/apps/dedicated/client/app/components/dedicated-cloud/resource/upgrade/upgrade.constants.js

-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ export const RESOURCE_BILLING_TYPES = {
1414
freeSpare: 'freeSpare',
1515
};
1616

17-
export const RESOURCE_BILLING_2API_TYPES = {
18-
hourly: 'HOURLY',
19-
monthly: 'MONTHLY',
20-
freeSpare: 'FREE_SPARE',
21-
};
22-
2317
export const RESOURCE_STATES = {
2418
delivered: 'delivered',
2519
};

packages/manager/apps/dedicated/client/app/components/dedicated-cloud/vmware-cloud-director/order/controller.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ import { VCD_PLAN_CODE } from '../../dedicatedCloud.constant';
22

33
export default class VdcOrderController {
44
/* @ngInject */
5-
constructor($q, $window, $translate, DedicatedCloud, RedirectionService) {
5+
constructor(
6+
$q,
7+
$window,
8+
$translate,
9+
DedicatedCloud,
10+
dedicatedCloudDataCenterHostService,
11+
RedirectionService,
12+
) {
613
this.$q = $q;
714
this.$window = $window;
815
this.$translate = $translate;
916
this.DedicatedCloud = DedicatedCloud;
17+
this.dedicatedCloudDataCenterHostService = dedicatedCloudDataCenterHostService;
1018
this.expressOrderURL = RedirectionService.getURL('expressOrder');
1119
}
1220

@@ -20,17 +28,14 @@ export default class VdcOrderController {
2028
return this.$q
2129
.all(
2230
this.datacenters.map(({ datacenterId }) =>
23-
this.DedicatedCloud.getPaginatedHosts(
31+
this.dedicatedCloudDataCenterHostService.getPaginatedHosts(
2432
this.productId,
2533
datacenterId,
26-
).then(({ list: { results } }) => results),
34+
{ pageSize: 100, offset: 0 },
35+
),
2736
),
2837
)
29-
.then((hosts) =>
30-
hosts
31-
.flat()
32-
.map(({ hostId, profile, name }) => ({ name, profile, hostId })),
33-
);
38+
.then((results) => results.map(({ data }) => data).flat());
3439
}
3540

3641
loadData() {

packages/manager/apps/dedicated/client/app/components/dedicated-cloud/vmware-cloud-director/order/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import hostModule from '../../datacenter/host';
12
import component from './component';
23

34
const moduleName = 'ovhManagerPccDashboardVmwareCloudDirectorOrder';
45

56
angular
6-
.module(moduleName, ['oui', 'pascalprecht.translate', 'ui.router'])
7+
.module(moduleName, [
8+
'oui',
9+
'pascalprecht.translate',
10+
'ui.router',
11+
hostModule,
12+
])
713
.component(component.name, component)
814
.run(/* @ngTranslationsInject:json ./translations */);
915

0 commit comments

Comments
 (0)