Exemple #1
0
// Build entityDTO that contains all the necessary info of a pod.
func (podProbe *PodProbe) buildPodEntityDTO(pod *api.Pod, commoditiesSold, commoditiesBought []*sdk.CommodityDTO) (*sdk.EntityDTO, error) {
	podNameWithNamespace := pod.Namespace + "/" + pod.Name
	id := podNameWithNamespace
	dispName := podNameWithNamespace

	entityDTOBuilder := sdk.NewEntityDTOBuilder(sdk.EntityDTO_CONTAINER_POD, id)
	entityDTOBuilder.DisplayName(dispName)

	minionId := pod.Spec.NodeName
	if minionId == "" {
		return nil, fmt.Errorf("Cannot find the hosting node ID for pod %s", podNameWithNamespace)
	}
	glog.V(4).Infof("Pod %s is hosted on %s", dispName, minionId)

	entityDTOBuilder.SellsCommodities(commoditiesSold)
	providerUid := nodeUidTranslationMap[minionId]
	entityDTOBuilder = entityDTOBuilder.SetProviderWithTypeAndID(sdk.EntityDTO_VIRTUAL_MACHINE, providerUid)
	entityDTOBuilder.BuysCommodities(commoditiesBought)

	ipAddress := podProbe.getIPForStitching(pod)
	entityDTOBuilder = entityDTOBuilder.SetProperty("ipAddress", ipAddress)
	glog.V(3).Infof("Pod %s will be stitched to VM with IP %s", dispName, ipAddress)

	entityDto := entityDTOBuilder.Create()
	return entityDto, nil
}
// Build entityDTOs for Applications.
func (this *ApplicationProbe) buildApplicationEntityDTOs(app vmtAdvisor.Application, host *vmtAdvisor.Host, podName, nodeName string, commoditiesSold []*sdk.CommodityDTO, commoditiesBoughtMap map[*sdk.ProviderDTO][]*sdk.CommodityDTO) *sdk.EntityDTO {
	appEntityType := sdk.EntityDTO_APPLICATION
	id := app.Cmd + "::" + podName
	dispName := app.Cmd + "::" + podName
	entityDTOBuilder := sdk.NewEntityDTOBuilder(appEntityType, id)
	entityDTOBuilder = entityDTOBuilder.DisplayName(dispName)

	entityDTOBuilder.SellsCommodities(commoditiesSold)

	for provider, commodities := range commoditiesBoughtMap {
		entityDTOBuilder.SetProvider(provider)
		entityDTOBuilder.BuysCommodities(commodities)
	}

	entityDto := entityDTOBuilder.Create()

	appType := app.Cmd

	ipAddress := this.getIPAddress(host, nodeName)

	appData := &sdk.EntityDTO_ApplicationData{
		Type:      &appType,
		IpAddress: &ipAddress,
	}
	entityDto.ApplicationData = appData
	return entityDto
}
Exemple #3
0
func (this *ServiceProbe) buildEntityDTO(appName string, commoditiesBoughtMap map[*sdk.ProviderDTO][]*sdk.CommodityDTO) *sdk.EntityDTO {
	serviceEntityType := sdk.EntityDTO_VIRTUAL_APPLICATION
	id := "vApp-" + appName
	dispName := id
	entityDTOBuilder := sdk.NewEntityDTOBuilder(serviceEntityType, id)

	entityDTOBuilder = entityDTOBuilder.DisplayName(dispName)
	for provider, commodities := range commoditiesBoughtMap {
		entityDTOBuilder.SetProvider(provider)
		entityDTOBuilder.BuysCommodities(commodities)
	}
	entityDto := entityDTOBuilder.Create()

	glog.V(4).Infof("created a service entityDTO %v", entityDto)
	return entityDto
}
Exemple #4
0
func (nodeProbe *NodeProbe) buildVMEntityDTO(nodeID, displayName string, commoditiesSold []*sdk.CommodityDTO) *sdk.EntityDTO {
	entityDTOBuilder := sdk.NewEntityDTOBuilder(sdk.EntityDTO_VIRTUAL_MACHINE, nodeID)
	entityDTOBuilder.DisplayName(displayName)
	entityDTOBuilder.SellsCommodities(commoditiesSold)

	ipAddress := nodeProbe.getIPForStitching(displayName)
	entityDTOBuilder = entityDTOBuilder.SetProperty("IP", ipAddress)
	glog.V(4).Infof("Parse node: The ip of vm to be reconcile with is %s", ipAddress)

	metaData := nodeProbe.generateReconcilationMetaData()

	entityDTOBuilder = entityDTOBuilder.ReplacedBy(metaData)

	entityDto := entityDTOBuilder.Create()

	return entityDto
}
Exemple #5
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
}