mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge pull request #1036 from rags22489664/master
CLOUDSTACK-9038 - Infrastructure tab is slow because of synchronous API callsMaking parallel asynchronous calls to speed up the infrastructure page. * pr/1036: CLOUDSTACK-9038 - Infrastructure tab is slow because of synchronous API calls Signed-off-by: Remi Bergsma <github@remi.nl>
This commit is contained in:
commit
b1c29d5ed5
@ -225,60 +225,64 @@
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: createURL('listZones'),
|
url: createURL('listZones'),
|
||||||
data: {
|
data: {
|
||||||
|
listAll: true,
|
||||||
page: 1,
|
page: 1,
|
||||||
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
||||||
},
|
},
|
||||||
success: function (json) {
|
success: function (json) {
|
||||||
dataFns.podCount($.extend(data, {
|
args.response.success({
|
||||||
zoneCount: json.listzonesresponse.count ? json.listzonesresponse.count: 0,
|
data: {
|
||||||
zones: json.listzonesresponse.zone
|
zoneCount: json.listzonesresponse.count ? json.listzonesresponse.count: 0,
|
||||||
}));
|
zones: json.listzonesresponse.zone
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dataFns.podCount();
|
||||||
},
|
},
|
||||||
|
|
||||||
podCount: function (data) {
|
podCount: function (data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: createURL('listPods'),
|
url: createURL('listPods'),
|
||||||
data: {
|
data: {
|
||||||
|
listAll: true,
|
||||||
page: 1,
|
page: 1,
|
||||||
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
||||||
},
|
},
|
||||||
success: function (json) {
|
success: function (json) {
|
||||||
dataFns.clusterCount($.extend(data, {
|
args.response.success({
|
||||||
podCount: json.listpodsresponse.count ? json.listpodsresponse.count: 0
|
data: {
|
||||||
}));
|
podCount: json.listpodsresponse.count ? json.listpodsresponse.count: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dataFns.clusterCount();
|
||||||
},
|
},
|
||||||
|
|
||||||
clusterCount: function (data) {
|
clusterCount: function (data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: createURL('listClusters'),
|
url: createURL('listClusters'),
|
||||||
data: {
|
data: {
|
||||||
|
listAll: true,
|
||||||
page: 1,
|
page: 1,
|
||||||
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
||||||
},
|
},
|
||||||
success: function (json) {
|
success: function (json) {
|
||||||
dataFns.hostCount($.extend(data, {
|
args.response.success({
|
||||||
clusterCount: json.listclustersresponse.count ? json.listclustersresponse.count: 0
|
data: {
|
||||||
}));
|
clusterCount: json.listclustersresponse.count ? json.listclustersresponse.count: 0
|
||||||
|
}
|
||||||
//comment the 4 lines above and uncomment the following 4 lines if listHosts API still responds slowly.
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
dataFns.primaryStorageCount($.extend(data, {
|
|
||||||
clusterCount: json.listclustersresponse.count ?
|
|
||||||
json.listclustersresponse.count : 0
|
|
||||||
}));
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dataFns.hostCount();
|
||||||
},
|
},
|
||||||
|
|
||||||
hostCount: function (data) {
|
hostCount: function (data) {
|
||||||
var data2 = {
|
var data2 = {
|
||||||
type: 'routing',
|
type: 'routing',
|
||||||
|
listAll: true,
|
||||||
page: 1,
|
page: 1,
|
||||||
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
||||||
};
|
};
|
||||||
@ -286,15 +290,19 @@
|
|||||||
url: createURL('listHosts'),
|
url: createURL('listHosts'),
|
||||||
data: data2,
|
data: data2,
|
||||||
success: function (json) {
|
success: function (json) {
|
||||||
dataFns.primaryStorageCount($.extend(data, {
|
args.response.success({
|
||||||
hostCount: json.listhostsresponse.count ? json.listhostsresponse.count: 0
|
data: {
|
||||||
}));
|
hostCount: json.listhostsresponse.count ? json.listhostsresponse.count: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dataFns.primaryStorageCount();
|
||||||
},
|
},
|
||||||
|
|
||||||
primaryStorageCount: function (data) {
|
primaryStorageCount: function (data) {
|
||||||
var data2 = {
|
var data2 = {
|
||||||
|
listAll: true,
|
||||||
page: 1,
|
page: 1,
|
||||||
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
||||||
};
|
};
|
||||||
@ -302,15 +310,20 @@
|
|||||||
url: createURL('listStoragePools'),
|
url: createURL('listStoragePools'),
|
||||||
data: data2,
|
data: data2,
|
||||||
success: function (json) {
|
success: function (json) {
|
||||||
dataFns.secondaryStorageCount($.extend(data, {
|
args.response.success({
|
||||||
primaryStorageCount: json.liststoragepoolsresponse.count ? json.liststoragepoolsresponse.count: 0
|
data: {
|
||||||
}));
|
primaryStorageCount: json.liststoragepoolsresponse.count ? json.liststoragepoolsresponse.count: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dataFns.secondaryStorageCount();
|
||||||
},
|
},
|
||||||
|
|
||||||
secondaryStorageCount: function (data) {
|
secondaryStorageCount: function (data) {
|
||||||
var data2 = {
|
var data2 = {
|
||||||
|
type: 'SecondaryStorage',
|
||||||
|
listAll: true,
|
||||||
page: 1,
|
page: 1,
|
||||||
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
||||||
};
|
};
|
||||||
@ -318,26 +331,33 @@
|
|||||||
url: createURL('listImageStores'),
|
url: createURL('listImageStores'),
|
||||||
data: data2,
|
data: data2,
|
||||||
success: function (json) {
|
success: function (json) {
|
||||||
dataFns.systemVmCount($.extend(data, {
|
args.response.success({
|
||||||
secondaryStorageCount: json.listimagestoresresponse.imagestore ? json.listimagestoresresponse.count: 0
|
data: {
|
||||||
}));
|
secondaryStorageCount: json.listimagestoresresponse.imagestore ? json.listimagestoresresponse.count: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dataFns.systemVmCount();
|
||||||
},
|
},
|
||||||
|
|
||||||
systemVmCount: function (data) {
|
systemVmCount: function (data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: createURL('listSystemVms'),
|
url: createURL('listSystemVms'),
|
||||||
data: {
|
data: {
|
||||||
|
listAll: true,
|
||||||
page: 1,
|
page: 1,
|
||||||
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
|
||||||
},
|
},
|
||||||
success: function (json) {
|
success: function (json) {
|
||||||
dataFns.virtualRouterCount($.extend(data, {
|
args.response.success({
|
||||||
systemVmCount: json.listsystemvmsresponse.count ? json.listsystemvmsresponse.count: 0
|
data: {
|
||||||
}));
|
systemVmCount: json.listsystemvmsresponse.count ? json.listsystemvmsresponse.count: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dataFns.virtualRouterCount();
|
||||||
},
|
},
|
||||||
|
|
||||||
virtualRouterCount: function (data) {
|
virtualRouterCount: function (data) {
|
||||||
@ -375,20 +395,22 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dataFns.capacity($.extend(data, {
|
args.response.success({
|
||||||
virtualRouterCount: (total1 + total2)
|
data: {
|
||||||
}));
|
virtualRouterCount: (total1 + total2)
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dataFns.capacity();
|
||||||
},
|
},
|
||||||
|
|
||||||
capacity: function (data) {
|
capacity: function (data) {
|
||||||
if (data.zoneCount) {
|
$.ajax({
|
||||||
$.ajax({
|
url: createURL('listCapacity'),
|
||||||
url: createURL('listCapacity'),
|
success: function (json) {
|
||||||
success: function (json) {
|
var capacities = json.listcapacityresponse.capacity;
|
||||||
var capacities = json.listcapacityresponse.capacity;
|
if(capacities) {
|
||||||
|
|
||||||
var capacityTotal = function (id, converter) {
|
var capacityTotal = function (id, converter) {
|
||||||
var capacity = $.grep(capacities, function (capacity) {
|
var capacity = $.grep(capacities, function (capacity) {
|
||||||
return capacity.type == id;
|
return capacity.type == id;
|
||||||
@ -403,90 +425,117 @@
|
|||||||
return total;
|
return total;
|
||||||
};
|
};
|
||||||
|
|
||||||
dataFns.socketInfo($.extend(data, {
|
args.response.success({
|
||||||
cpuCapacityTotal: capacityTotal(1, cloudStack.converters.convertHz),
|
data: {
|
||||||
memCapacityTotal: capacityTotal(0, cloudStack.converters.convertBytes),
|
cpuCapacityTotal: capacityTotal(1, cloudStack.converters.convertHz),
|
||||||
storageCapacityTotal: capacityTotal(2, cloudStack.converters.convertBytes)
|
memCapacityTotal: capacityTotal(0, cloudStack.converters.convertBytes),
|
||||||
}));
|
storageCapacityTotal: capacityTotal(2, cloudStack.converters.convertBytes)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
args.response.success({
|
||||||
|
data: {
|
||||||
|
cpuCapacityTotal: cloudStack.converters.convertHz(0),
|
||||||
|
memCapacityTotal: cloudStack.converters.convertBytes(0),
|
||||||
|
storageCapacityTotal: cloudStack.converters.convertBytes(0)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} else {
|
});
|
||||||
dataFns.socketInfo($.extend(data, {
|
|
||||||
cpuCapacityTotal: cloudStack.converters.convertHz(0),
|
dataFns.socketInfo();
|
||||||
memCapacityTotal: cloudStack.converters.convertBytes(0),
|
|
||||||
storageCapacityTotal: cloudStack.converters.convertBytes(0)
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
socketInfo: function (data) {
|
socketInfo: function (data) {
|
||||||
var socketCount = 0;
|
var socketCount = 0;
|
||||||
$.ajax({
|
|
||||||
url: createURL('listHypervisors'),
|
|
||||||
async: false,
|
|
||||||
success: function (json) {
|
|
||||||
args.response.success({
|
|
||||||
data: $(json.listhypervisorsresponse.hypervisor).map(function (index, hypervisor) {
|
|
||||||
var totalHostCount = 0;
|
|
||||||
var currentPage = 1;
|
|
||||||
var returnedHostCount = 0;
|
|
||||||
var returnedHostCpusocketsSum = 0;
|
|
||||||
|
|
||||||
var callListHostsWithPage = function() {
|
function listHostFunction(hypervisor, pageSizeValue) {
|
||||||
$.ajax({
|
var deferred = $.Deferred();
|
||||||
url: createURL('listHosts'),
|
var totalHostCount = 0;
|
||||||
async: false,
|
var returnedHostCount = 0;
|
||||||
data: {
|
var returnedHostCpusocketsSum = 0;
|
||||||
type: 'routing',
|
|
||||||
hypervisor: hypervisor.name,
|
|
||||||
page: currentPage,
|
|
||||||
pagesize: pageSize //global variable
|
|
||||||
},
|
|
||||||
success: function (json) {
|
|
||||||
if (json.listhostsresponse.count == undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
totalHostCount = json.listhostsresponse.count;
|
var callListHostsWithPage = function(page) {
|
||||||
returnedHostCount += json.listhostsresponse.host.length;
|
$.ajax({
|
||||||
|
url: createURL('listHosts'),
|
||||||
var items = json.listhostsresponse.host;
|
data: {
|
||||||
for (var i = 0; i < items.length; i++) {
|
type: 'routing',
|
||||||
if (items[i].cpusockets != undefined && isNaN(items[i].cpusockets) == false) {
|
hypervisor: hypervisor,
|
||||||
returnedHostCpusocketsSum += items[i].cpusockets;
|
page: page,
|
||||||
}
|
details: 'min',
|
||||||
}
|
pagesize: pageSizeValue
|
||||||
|
},
|
||||||
if (returnedHostCount < totalHostCount) {
|
success: function (json) {
|
||||||
currentPage++;
|
if (json.listhostsresponse.count == undefined) {
|
||||||
callListHostsWithPage();
|
deferred.resolve();
|
||||||
}
|
return;
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callListHostsWithPage();
|
totalHostCount = json.listhostsresponse.count;
|
||||||
|
returnedHostCount += json.listhostsresponse.host.length;
|
||||||
|
|
||||||
socketCount += returnedHostCpusocketsSum;
|
var items = json.listhostsresponse.host;
|
||||||
})
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
if (items[i].cpusockets != undefined && isNaN(items[i].cpusockets) == false) {
|
||||||
|
returnedHostCpusocketsSum += items[i].cpusockets;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (returnedHostCount < totalHostCount) {
|
||||||
|
callListHostsWithPage(++page);
|
||||||
|
} else {
|
||||||
|
socketCount += returnedHostCpusocketsSum;
|
||||||
|
deferred.resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
callListHostsWithPage(1);
|
||||||
|
|
||||||
|
return deferred;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: createURL('listConfigurations'),
|
||||||
|
data: {
|
||||||
|
name : 'default.page.size'
|
||||||
|
},
|
||||||
|
success: function (json) {
|
||||||
|
pageSizeValue = json.listconfigurationsresponse.configuration[0].value;
|
||||||
|
if(!pageSizeValue) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: createURL('listHypervisors'),
|
||||||
|
success: function (json) {
|
||||||
|
var deferredArray = [];
|
||||||
|
|
||||||
|
$(json.listhypervisorsresponse.hypervisor).map(function (index, hypervisor) {
|
||||||
|
deferredArray.push(listHostFunction(hypervisor.name, pageSizeValue));
|
||||||
|
});
|
||||||
|
|
||||||
|
$.when.apply(null, deferredArray).then(function(){
|
||||||
|
args.response.success({
|
||||||
|
data: {
|
||||||
|
socketCount: socketCount
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
complete($.extend(data, {
|
|
||||||
socketCount: socketCount
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var complete = function (data) {
|
dataFns.zoneCount();
|
||||||
args.response.success({
|
|
||||||
data: data
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
dataFns.zoneCount({
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user