func()

in src/go/cmd/vmscaler/vmscaler/vmscaler.go [419:518]


func (v *VMScaler) executePlan(p *Plan) error {
	log.Debug.Printf("[VMScaler.executePlan")
	defer log.Debug.Printf("VMScaler.executePlan]")

	// tag the VMs
	if b, e := time.Now().MarshalText(); e != nil {
		log.Error.Printf("ERROR running time.Now().MarshalText(), bug in Golang?")
	} else {
		for _, element := range p.VmssAtCapacity {
			vmss, ok := p.VmssMap[element]
			if !ok {
				log.Error.Printf("BUG: element %s not found in vmssMap", element)
				continue
			}
			str := string(b)
			if vmss.Tags == nil {
				vmss.Tags = make(map[string]*string)
			}
			vmss.Tags[LAST_TIME_AT_CAPACITY_TAG_KEY] = &str
			future, err := v.vmssClient.Update(v.ResourceGroup, vmss)
			if err != nil {
				log.Error.Printf("error updating '%s': %v, %v", element, err, future)
				continue
			}
			v.vmssOpManager.AddWatchOperation(*vmss.Name, future.FutureAPI)
		}
	}

	// seal the VMs
	if b, e := time.Now().MarshalText(); e != nil {
		log.Error.Printf("ERROR running time.Now().MarshalText(), bug in Golang?")
	} else {
		for _, element := range p.VMSSToSeal {
			vmss, ok := p.VmssMap[element]
			if !ok {
				log.Error.Printf("BUG: element %s not found in vmssMap", element)
				continue
			}
			str := string(b)
			if vmss.Tags == nil {
				vmss.Tags = make(map[string]*string)
			}
			vmss.Tags[SEALED_TAG_KEY] = &str
			future, err := v.vmssClient.Update(v.ResourceGroup, vmss)
			if err != nil {
				log.Error.Printf("error updating '%s': %v, %v", element, err, future)
				continue
			}
			v.vmssOpManager.AddWatchOperation(*vmss.Name, future.FutureAPI)
		}
	}

	// increase the VMs
	if b, e := time.Now().MarshalText(); e != nil {
		log.Error.Printf("ERROR running time.Now().MarshalText(), bug in Golang?")
	} else {
		for _, element := range p.VMSSToIncrease {
			vmss, ok := p.VmssMap[element]
			if !ok {
				log.Error.Printf("BUG: element %s not found in vmssMap", element)
				continue
			}
			str := string(b)
			if vmss.Tags == nil {
				vmss.Tags = make(map[string]*string)
			}
			vmss.Tags[LAST_TIME_AT_CAPACITY_TAG_KEY] = &str
			vmss.Sku.Capacity = &v.VMsPerVMSS
			future, err := v.vmssClient.Update(v.ResourceGroup, vmss)
			if err != nil {
				log.Error.Printf("error updating '%s': %v, %v", element, err, future)
				continue
			}
			v.vmssOpManager.AddWatchOperation(*vmss.Name, future.FutureAPI)
		}
	}

	// delete 0 capacity vmss instances
	for _, element := range p.VMSSToDelete {
		future, err := v.vmssClient.VmssClient.Delete(v.Context, v.ResourceGroup, element)
		if err != nil {
			log.Error.Printf("error deleting '%s': %v, %v", element, err, future)
			continue
		}
		v.vmssOpManager.AddWatchOperation(element, future.FutureAPI)
	}

	// create the new VMSS
	for _, element := range p.NewVMSSNames {
		vmssModel := v.createNewVmssModel(element)
		future, err := v.vmssClient.Create(v.ResourceGroup, vmssModel)
		if err != nil {
			log.Error.Printf("error updating '%s': %v, %v", element, err, future)
			continue
		}
		v.vmssOpManager.AddWatchOperation(element, future.FutureAPI)
	}

	return nil
}