Esempio n. 1
0
// Build commodityDTOs for commodity sold by the pod
func (podProbe *PodProbe) getCommoditiesSold(pod *api.Pod, podResourceStat *PodResourceStat) []*sdk.CommodityDTO {
	podNameWithNamespace := pod.Namespace + "/" + pod.Name
	var commoditiesSold []*sdk.CommodityDTO
	memAllocationComm := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_MEM_ALLOCATION).
		Key(podNameWithNamespace).
		Capacity(float64(podResourceStat.memAllocationCapacity)).
		Used(podResourceStat.memAllocationUsed).
		Create()
	commoditiesSold = append(commoditiesSold, memAllocationComm)
	cpuAllocationComm := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_CPU_ALLOCATION).
		Key(podNameWithNamespace).
		Capacity(float64(podResourceStat.cpuAllocationCapacity)).
		Used(podResourceStat.cpuAllocationUsed).
		Create()
	commoditiesSold = append(commoditiesSold, cpuAllocationComm)
	return commoditiesSold
}
Esempio n. 2
0
// Build commodities sold for each application. An application sells transaction, which a virtual application buys.
func (this *ApplicationProbe) getCommoditiesSold(app vmtAdvisor.Application, appResourceStat *ApplicationResourceStat) []*sdk.CommodityDTO {
	var commoditiesSold []*sdk.CommodityDTO
	transactionComm := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_TRANSACTION).
		Key(app.Cmd).
		Capacity(appResourceStat.transactionCapacity).
		Used(appResourceStat.transactionUsed).
		Create()
	commoditiesSold = append(commoditiesSold, transactionComm)
	return commoditiesSold
}
Esempio n. 3
0
// Build commodityDTOs for commodity sold by the pod
func (podProbe *PodProbe) getCommoditiesBought(pod *api.Pod, podResourceStat *PodResourceStat) []*sdk.CommodityDTO {
	var commoditiesBought []*sdk.CommodityDTO
	cpuAllocationCommBought := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_CPU_ALLOCATION).
		Key("Container").
		Used(podResourceStat.cpuAllocationUsed).
		Create()
	commoditiesBought = append(commoditiesBought, cpuAllocationCommBought)
	memAllocationCommBought := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_MEM_ALLOCATION).
		Key("Container").
		Used(podResourceStat.memAllocationUsed).
		Create()
	commoditiesBought = append(commoditiesBought, memAllocationCommBought)
	selectormap := pod.Spec.NodeSelector
	if len(selectormap) > 0 {
		for key, value := range selectormap {
			str1 := key + "=" + value
			accessComm := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_VMPM_ACCESS).Key(str1).Create()
			commoditiesBought = append(commoditiesBought, accessComm)
		}
	}
	return commoditiesBought
}
Esempio n. 4
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
}
Esempio n. 5
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
}
Esempio n. 6
0
func (nodeProbe *NodeProbe) createCommoditySold(node *api.Node) ([]*sdk.CommodityDTO, error) {
	var commoditiesSold []*sdk.CommodityDTO
	nodeResourceStat, err := nodeProbe.getNodeResourceStat(node)
	if err != nil {
		return commoditiesSold, err
	}
	nodeID := string(node.UID)

	//TODO: create const value for keys
	memAllocationComm := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_MEM_ALLOCATION).
		Key("Container").
		Capacity(float64(nodeResourceStat.memAllocationCapacity)).
		Used(nodeResourceStat.memAllocationUsed).
		Create()
	commoditiesSold = append(commoditiesSold, memAllocationComm)
	cpuAllocationComm := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_CPU_ALLOCATION).
		Key("Container").
		Capacity(float64(nodeResourceStat.cpuAllocationCapacity)).
		Used(nodeResourceStat.cpuAllocationUsed).
		Create()
	commoditiesSold = append(commoditiesSold, cpuAllocationComm)
	vMemComm := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_VMEM).
		Key(nodeID).
		Capacity(nodeResourceStat.vMemCapacity).
		Used(nodeResourceStat.vMemUsed).
		Create()
	commoditiesSold = append(commoditiesSold, vMemComm)
	vCpuComm := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_VCPU).
		Key(nodeID).
		Capacity(float64(nodeResourceStat.vCpuCapacity)).
		Used(nodeResourceStat.vCpuUsed).
		Create()
	commoditiesSold = append(commoditiesSold, vCpuComm)
	appComm := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_APPLICATION).
		Key(nodeID).
		Create()
	commoditiesSold = append(commoditiesSold, appComm)
	labelsmap := node.ObjectMeta.Labels
	if len(labelsmap) > 0 {
		for key, value := range labelsmap {
			str1 := key + "=" + value
			glog.V(4).Infof("label for this Node is : %s", str1)
			accessComm := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_VMPM_ACCESS).Key(str1).Create()
			commoditiesSold = append(commoditiesSold, accessComm)
		}
	}
	return commoditiesSold, nil
}
Esempio n. 7
0
// For testing purpose, create fake vm entityDTO
func (this *NodeProbe) buildFakeVMEntityDTO() *sdk.EntityDTO {
	nodeEntityType := sdk.EntityDTO_VIRTUAL_MACHINE

	// create a fake VM
	entityDTOBuilder2 := sdk.NewEntityDTOBuilder(nodeEntityType, "1.1.1.1")
	// Find out the used value for each commodity
	cpuUsed := float64(0)
	memUsed := float64(0)
	nodeMemCapacity := float64(1000)
	nodeCpuCapacity := float64(1000)
	// Build the entityDTO.
	entityDTOBuilder2 = entityDTOBuilder2.DisplayName("1.1.1.1")
	var commodityDTOs []*sdk.CommodityDTO
	memAllocationComm := sdk.NewCommodtiyDTOBuilder(sdk.CommodityDTO_MEM_ALLOCATION).
		Key("Container").
		Capacity(float64(nodeMemCapacity)).
		Used(memUsed).
		Create()
	commodityDTOs = append(commodityDTOs, memAllocationComm)
	entityDTOBuilder2 = entityDTOBuilder2.Sells(sdk.CommodityDTO_MEM_ALLOCATION, "Container").
		Capacity(float64(nodeMemCapacity)).Used(memUsed)
	entityDTOBuilder2 = entityDTOBuilder2.Sells(sdk.CommodityDTO_CPU_ALLOCATION, "Container").
		Capacity(float64(nodeCpuCapacity)).Used(cpuUsed)
	entityDTOBuilder2 = entityDTOBuilder2.Sells(sdk.CommodityDTO_VMEM, "1.1.1.1").
		Capacity(float64(nodeMemCapacity)).Used(memUsed)
	entityDTOBuilder2 = entityDTOBuilder2.Sells(sdk.CommodityDTO_VCPU, "1.1.1.1").
		Capacity(float64(nodeCpuCapacity)).Used(cpuUsed)
	entityDTOBuilder2 = entityDTOBuilder2.SetProperty("IP", localTestStitchingIP)

	metaData2 := this.generateReconcilationMetaData()

	entityDTOBuilder2 = entityDTOBuilder2.ReplacedBy(metaData2)
	entityDto2 := entityDTOBuilder2.Create()

	return entityDto2
}