Browse Source

机器申请调整

zhangjinkun 6 years ago
parent
commit
a54d3eaced
3 changed files with 72 additions and 43 deletions
  1. 20 3
      src/config.json
  2. 51 33
      src/jy/cluster/aliecs.go
  3. 1 7
      src/jy/extract/extractudp.go

+ 20 - 3
src/config.json

@@ -35,9 +35,26 @@
         "available": false,
         "AccessID": "",
         "AccessSecret": "",
-        "LaunchTemplateId4": "lt-2ze19qyi8votdjgeq2ma",
-        "LaunchTemplateId8": "lt-2zeidqiydzusn7hw7lt8",
-        "VSwitchId": "vsw-2ze23am2bl9e3v6rnyhfb"
+        "ZoneIds": [
+            {
+                "zoneid": "cn-beijing-f",
+                "LaunchTemplateId4": "lt-2zejb8ayql48hn0hcjpy",
+                "LaunchTemplateId8": "lt-2zegx87hj07phcdtoh61",
+                "vswitchid": "vsw-2zei6snkgmqxcnnx6g04d"
+            },
+            {
+                "zoneid": "cn-beijing-g",
+                "LaunchTemplateId4": "lt-2ze5ktfgopayi48ok0hu",
+                "LaunchTemplateId8": "lt-2ze0qfrxdnkuwldj9s0u",
+                "vswitchid": "vsw-2ze586sxfwsaov4s5w88d"
+            },
+            {
+                "zoneid": "cn-beijing-h",
+                "LaunchTemplateId4": "lt-2ze5ir54gy4ui8okr71f",
+                "LaunchTemplateId8": "	lt-2ze5fzxwgt8jcqczvmjy",
+                "vswitchid": "vsw-2ze1n1k3mo3fv2irsfdps"
+            }
+        ]
     },
     "filelength": 100000,
     "saveblock": true

+ 51 - 33
src/jy/cluster/aliecs.go

@@ -30,50 +30,68 @@ const (
 )
 
 //批量创建实例
-func RunInstances(TaskName, computer, flow string, num, hours int) {
+func RunInstances(taskName, computer, flow string, num, hours int) {
 	if esconfig, ok := ju.Config["esconfig"].(map[string]interface{}); ok {
-		InternetMaxBandwidthOut := "0"
+		widthOut := "0"
 		if flow == "true" {
-			InternetMaxBandwidthOut = "10"
+			widthOut = "10"
 		}
-		log.Println(esconfig["LaunchTemplateId"+computer], InternetMaxBandwidthOut)
+		log.Println(esconfig["LaunchTemplateId"+computer], widthOut)
 		if b, ok := esconfig["available"].(bool); ok && b {
-			res := GET("RunInstances", [][]string{
-				[]string{"RegionId", "cn-beijing"},
-				[]string{"LaunchTemplateId", qu.ObjToString(esconfig["LaunchTemplateId"+computer])},
-				//[]string{"ImageId", "centos_7_06_64_20G_alibase_20181212.vhd"},
-				//[]string{"InstanceType", "ecs.ic5.large"},
-				//[]string{"SecurityGroupId", "sg-bp16x3td2evrejhkshp7"},
-				[]string{"VSwitchId", qu.ObjToString(esconfig["VSwitchId"])},
-				[]string{"InternetMaxBandwidthIn", "50"},
-				[]string{"InternetMaxBandwidthOut", InternetMaxBandwidthOut},
-				[]string{"InstanceChargeType", "PostPaid"},
-				[]string{"SpotStrategy", "SpotWithPriceLimit"},
-				[]string{"SpotPriceLimit", "4.99"},
-				[]string{"InstanceName", "extract"},
-				[]string{"UniqueSuffix", "true"},
-				[]string{"Password", Password},
-				[]string{"Amount", fmt.Sprint(num)},
-				[]string{"AutoReleaseTime", time.Now().Add(time.Duration(hours) * time.Hour).UTC().Format("2006-01-02T15:04:05Z")},
-			})
-			//  {"RequestId":"95653A72-4907-4DD0-86F9-00E216193173","InstanceIdSets":{"InstanceIdSet":["i-2ze0z0xdiqgtwji5jd9s"]}}
-			if tmp, ok := res["InstanceIdSets"].(map[string]interface{}); ok {
-				if t, ok := tmp["InstanceIdSet"].([]interface{}); ok {
-					//实例id持久化
-					for _, v := range t {
-						db.Mgo.Save("ecs", map[string]interface{}{
-							"InstanceId": v,
-							"TaskName":   TaskName,
-							"UseFor":     "extract",
-						})
+			if zoneIds, _ := esconfig["ZoneIds"].([]interface{}); ok {
+				pernum := num / len(zoneIds)
+				if pernum < 1 {
+					kv, _ := zoneIds[len(zoneIds)-1].(map[string]interface{})
+					runInstances(kv, taskName, widthOut, computer, num, hours)
+				} else {
+					for k, v := range zoneIds {
+						if (k == len(zoneIds)-1) && (num%len(zoneIds) != 0) {
+							pernum = num - pernum*(len(zoneIds)-1)
+						}
+						kv, _ := v.(map[string]interface{})
+						runInstances(kv, taskName, widthOut, computer, pernum, hours)
 					}
 				}
 			}
-			log.Println(res)
 		}
 	}
 }
 
+func runInstances(kv map[string]interface{}, taskName, widthOut, computer string, pernum, hours int) {
+	log.Println(kv, taskName, widthOut, computer, pernum, hours)
+	res := GET("RunInstances", [][]string{
+		[]string{"RegionId", "cn-beijing"},
+		[]string{"ZoneId", qu.ObjToString(kv["zoneid"])},
+		[]string{"VSwitchId", qu.ObjToString(kv["vswitchid"])},
+		[]string{"LaunchTemplateId", qu.ObjToString(kv["LaunchTemplateId"+computer])},
+		//[]string{"ImageId", "centos_7_06_64_20G_alibase_20181212.vhd"},
+		//[]string{"InstanceType", "ecs.ic5.large"},
+		//[]string{"SecurityGroupId", "sg-bp16x3td2evrejhkshp7"},[]string{"InternetMaxBandwidthIn", "50"},
+		[]string{"InternetMaxBandwidthOut", widthOut},
+		[]string{"InstanceChargeType", "PostPaid"},
+		[]string{"SpotStrategy", "SpotWithPriceLimit"},
+		[]string{"SpotPriceLimit", "4.99"},
+		[]string{"InstanceName", "extract"},
+		[]string{"UniqueSuffix", "true"},
+		[]string{"Password", Password},
+		[]string{"Amount", fmt.Sprint(pernum)},
+		[]string{"AutoReleaseTime", time.Now().Add(time.Duration(hours) * time.Hour).UTC().Format("2006-01-02T15:04:05Z")},
+	})
+	if tmp, ok := res["InstanceIdSets"].(map[string]interface{}); ok {
+		if t, ok := tmp["InstanceIdSet"].([]interface{}); ok {
+			//实例id持久化
+			for _, v := range t {
+				db.Mgo.Save("ecs", map[string]interface{}{
+					"InstanceId": v,
+					"TaskName":   taskName,
+					"UseFor":     "extract",
+				})
+			}
+		}
+	}
+	log.Println(res)
+}
+
 //查询多台实例的详细信息
 func DescribeInstances() {
 	res := GET("DescribeInstances", [][]string{

+ 1 - 7
src/jy/extract/extractudp.go

@@ -79,13 +79,7 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
 			}
 		}
 	case mu.OP_NOOP: //下个节点回应
-		var rep map[string]interface{}
-		err := json.Unmarshal(data, &rep)
-		if err != nil {
-			log.Debug(err)
-		} else {
-			log.Debug(rep)
-		}
+		log.Debug(string(data))
 	}
 }