Exemplo n.º 1
0
// Build commodities bought by an applicaiton.
// An application buys vCpu and vMem from a VM, cpuAllocation and memAllocation from a containerPod.
func (this *ApplicationProbe) getCommoditiesBought(podName, nodeName string, appResourceStat *ApplicationResourceStat) map[*sdk.ProviderDTO][]*sdk.CommodityDTO {
	commoditiesBoughtMap := make(map[*sdk.ProviderDTO][]*sdk.CommodityDTO)

	podProvider := sdk.CreateProvider(sdk.EntityDTO_CONTAINER_POD, podName)
	var commoditiesBoughtFromPod []*sdk.CommodityDTO
	cpuAllocationCommBought := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_CPU_ALLOCATION).
		Key(podName).
		Used(appResourceStat.cpuAllocationUsed).
		Create()
	commoditiesBoughtFromPod = append(commoditiesBoughtFromPod, cpuAllocationCommBought)
	memAllocationCommBought := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_MEM_ALLOCATION).
		Key(podName).
		Used(appResourceStat.memAllocationUsed).
		Create()
	commoditiesBoughtFromPod = append(commoditiesBoughtFromPod, memAllocationCommBought)
	commoditiesBoughtMap[podProvider] = commoditiesBoughtFromPod

	nodeUID := nodeUidTranslationMap[nodeName]
	nodeProvider := sdk.CreateProvider(sdk.EntityDTO_VIRTUAL_MACHINE, nodeUID)
	var commoditiesBoughtFromNode []*sdk.CommodityDTO
	vCpuCommBought := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_VCPU).
		Key(nodeUID).
		Used(appResourceStat.vCpuUsed).
		Create()
	commoditiesBoughtFromNode = append(commoditiesBoughtFromNode, vCpuCommBought)

	vMemCommBought := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_VMEM).
		Key(nodeUID).
		Used(appResourceStat.vMemUsed).
		Create()
	commoditiesBoughtFromNode = append(commoditiesBoughtFromNode, vMemCommBought)
	appCommBought := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_APPLICATION).
		Key(nodeUID).
		Create()
	commoditiesBoughtFromNode = append(commoditiesBoughtFromNode, appCommBought)
	commoditiesBoughtMap[nodeProvider] = commoditiesBoughtFromNode

	return commoditiesBoughtMap
}
Exemplo n.º 2
0
func (this *ServiceProbe) getCommoditiesBought(appName string, podIDList []string) map[*sdk.ProviderDTO][]*sdk.CommodityDTO {
	commoditiesBoughtMap := make(map[*sdk.ProviderDTO][]*sdk.CommodityDTO)

	for _, podID := range podIDList {
		serviceResourceStat := getServiceResourceStat(podTransactionCountMap, podID)

		appID := appName + "::" + podID
		// We might want to check here if the appID exist.
		appProvider := sdk.CreateProvider(sdk.EntityDTO_APPLICATION, appID)
		var commoditiesBoughtFromApp []*sdk.CommodityDTO
		transactionCommBought := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_TRANSACTION).
			Key(appName).
			Used(serviceResourceStat.transactionBought).
			Create()
		commoditiesBoughtFromApp = append(commoditiesBoughtFromApp, transactionCommBought)

		commoditiesBoughtMap[appProvider] = commoditiesBoughtFromApp

	}
	return commoditiesBoughtMap
}