Skip to content

Commit 433957f

Browse files
authored
Merge pull request ray-project#2 from eisber/marcozo/azure_autoscaler_v2
Marcozo/azure autoscaler v2
2 parents d63d180 + aa011ea commit 433957f

File tree

6 files changed

+348
-51
lines changed

6 files changed

+348
-51
lines changed

python/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ray/ray-schema.json

python/ray/autoscaler/autoscaler.py

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import numpy as np
1313
import ray.services as services
1414
import yaml
15+
import jsonschema
16+
from importlib_resources import read_text
1517
from ray.worker import global_worker
1618
from ray.autoscaler.docker import dockerize_if_needed
1719
from ray.autoscaler.node_provider import get_node_provider, \
@@ -25,7 +27,6 @@
2527
AUTOSCALER_MAX_LAUNCH_BATCH, AUTOSCALER_MAX_CONCURRENT_LAUNCHES, \
2628
AUTOSCALER_UPDATE_INTERVAL_S, AUTOSCALER_HEARTBEAT_TIMEOUT_S, \
2729
AUTOSCALER_RESOURCE_REQUEST_CHANNEL, MEMORY_RESOURCE_UNIT_BYTES
28-
from six import string_types
2930
from six.moves import queue
3031

3132
logger = logging.getLogger(__name__)
@@ -774,61 +775,13 @@ def kill_workers(self):
774775
len(nodes)))
775776

776777

777-
def typename(v):
778-
if isinstance(v, type):
779-
return v.__name__
780-
else:
781-
return type(v).__name__
782-
783-
784-
def check_required(config, schema):
785-
# Check required schema entries
786-
if not isinstance(config, dict):
787-
raise ValueError("Config is not a dictionary")
788-
789-
for k, (v, kreq) in schema.items():
790-
if v is None:
791-
continue # None means we don't validate the field
792-
if kreq is REQUIRED:
793-
if k not in config:
794-
type_str = typename(v)
795-
raise ValueError(
796-
"Missing required config key `{}` of type {}".format(
797-
k, type_str))
798-
if not isinstance(v, type):
799-
check_required(config[k], v)
800-
801-
802-
def check_extraneous(config, schema):
803-
"""Make sure all items of config are in schema"""
804-
if not isinstance(config, dict):
805-
raise ValueError("Config {} is not a dictionary".format(config))
806-
for k in config:
807-
if k not in schema:
808-
raise ValueError("Unexpected config key `{}` not in {}".format(
809-
k, list(schema.keys())))
810-
v, kreq = schema[k]
811-
if v is None:
812-
continue
813-
elif isinstance(v, type):
814-
if not isinstance(config[k], v):
815-
if v is str and isinstance(config[k], string_types):
816-
continue
817-
raise ValueError(
818-
"Config key `{}` has wrong type {}, expected {}".format(
819-
k,
820-
type(config[k]).__name__, v.__name__))
821-
else:
822-
check_extraneous(config[k], v)
823-
824-
825778
def validate_config(config, schema=CLUSTER_CONFIG_SCHEMA):
826779
"""Required Dicts indicate that no extra fields can be introduced."""
827780
if not isinstance(config, dict):
828781
raise ValueError("Config {} is not a dictionary".format(config))
829782

830-
check_required(config, schema)
831-
check_extraneous(config, schema)
783+
schema = read_text("ray", "ray-schema.json")
784+
jsonschema.validate(config, json.loads(schema))
832785

833786

834787
def fillout_defaults(config):
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
# Resource group name - we are using myImageBuilderRG in this example
4+
imageResourceGroup=marcozo-ray-vm-image-10
5+
# Datacenter location - we are using West US in this example
6+
location=WestUS2
7+
# Name for the image - we are using myBuilderImage in this example
8+
imageName=ray-dev-image
9+
# Run output name
10+
runOutputName=ray-dev-image-run
11+
# VM Image Name
12+
imageName=ray-dev-image-01
13+
14+
subscriptionID=6187b663-b744-4d24-8226-7e66525baf8f
15+
16+
echo Create the resource group
17+
az group create -n $imageResourceGroup -l $location
18+
19+
echo Set permissions on the resource group for the image builder
20+
az role assignment create \
21+
--assignee cf32a0cc-373c-47c9-9156-0db11f6a6dfc \
22+
--role Contributor \
23+
--scope /subscriptions/$subscriptionID/resourceGroups/$imageResourceGroup
24+
25+
az role assignment create \
26+
--assignee ef511139-6170-438e-a6e1-763dc31bdf74 \
27+
--role Contributor \
28+
--scope /subscriptions/$subscriptionID/resourceGroups/$imageResourceGroup
29+
30+
# Apply the values
31+
sed -i -e "s/<subscriptionID>/$subscriptionID/g" vmImageDevTemplate.json
32+
sed -i -e "s/<rgName>/$imageResourceGroup/g" vmImageDevTemplate.json
33+
sed -i -e "s/<region>/$location/g" vmImageDevTemplate.json
34+
sed -i -e "s/<imageName>/$imageName/g" vmImageDevTemplate.json
35+
sed -i -e "s/<runOutputName>/$runOutputName/g" vmImageDevTemplate.json
36+
37+
echo Submit the image configuration
38+
az resource create \
39+
--resource-group $imageResourceGroup \
40+
--properties @vmImageDevTemplate.json \
41+
--is-full-object \
42+
--resource-type Microsoft.VirtualMachineImages/imageTemplates \
43+
-n $imageName
44+
45+
# Cleanup if above failed
46+
# az resource delete \
47+
# --resource-group $imageResourceGroup \
48+
# --resource-type Microsoft.VirtualMachineImages/imageTemplates \
49+
# -n $imageName
50+
51+
echo Start the image build
52+
az resource invoke-action \
53+
--resource-group $imageResourceGroup \
54+
--resource-type Microsoft.VirtualMachineImages/imageTemplates \
55+
-n $imageName \
56+
--action Run
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"type": "Microsoft.VirtualMachineImages/imageTemplates",
3+
"apiVersion": "2019-05-01-preview",
4+
"location": "WestUS2",
5+
"dependsOn": [],
6+
"tags": {
7+
"imagebuilderTemplate": "ubuntu1804"
8+
},
9+
"properties": {
10+
11+
"buildTimeoutInMinutes" : 300,
12+
13+
"vmProfile":
14+
{
15+
"vmSize": "Standard_D2s_v3"
16+
},
17+
18+
"source": {
19+
"type": "PlatformImage",
20+
"publisher": "microsoft-dsvm",
21+
"offer": "ubuntu-1804",
22+
"sku": "1804",
23+
"version": "20.02.01"
24+
25+
},
26+
"customize": [
27+
{
28+
"type": "Shell",
29+
"name": "Build Ray",
30+
"inline": [
31+
"sudo mkdir -p /opt/ray",
32+
"sudo bash -c 'git clone https://github.com/ray-project/ray /opt/ray || true'",
33+
"sudo /opt/ray/ci/travis/install-bazel.sh",
34+
"sudo /anaconda/condabin/conda init bash",
35+
"sudo bash -c 'cd /opt/ray/python/ray/dashboard/client; npm ci; npm run build || true'",
36+
"sudo bash -c '/anaconda/envs/py37_default/bin/pip install azure-cli-core azure-core azure-mgmt-msi paramiko aiohttp grpcio psutil setproctitle'",
37+
"sudo bash -c 'cd /opt/ray/python; /anaconda/envs/py37_default/bin/pip install -e . --verbose'"
38+
]
39+
}
40+
],
41+
"distribute":
42+
[
43+
{ "type":"ManagedImage",
44+
"imageId": "/subscriptions/6187b663-b744-4d24-8226-7e66525baf8f/resourceGroups/marcozo-ray-vm-image/providers/Microsoft.Compute/images/ray-dev-image-01",
45+
"location": "WestUS2",
46+
"runOutputName": "ray-dev-image-run",
47+
"artifactTags": {
48+
"source": "azVmImageBuilder",
49+
"baseosimg": "ubuntu1804"
50+
}
51+
}
52+
]
53+
}
54+
}

0 commit comments

Comments
 (0)