-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate_personalizer.sh
71 lines (57 loc) · 2.42 KB
/
migrate_personalizer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
source common.sh
source_resource_name=chrricepersonalizersrc
source_rg=personalizertest
destination_resource_name=chrricepersonalizerdst
destination_rg=personalizertest
copy_configuration() {
config_type="$1"
log "Downloading $config_type configuration from source resource $source_resource_name..."
configuration="$(curl -s \
-H "Ocp-Apim-Subscription-Key: $source_api_key" \
-H 'Content-Type: application/json' \
"${source_api_endpoint}personalizer/v1.0/configurations/$config_type")"
log "Configuration: $configuration"
log "Uploading $config_type configuration to destination resource $destination_resource_name..."
output="$(curl -s -w "\n%{http_code}" \
-H "Ocp-Apim-Subscription-Key: $destination_api_key" \
-H 'Content-Type: application/json' \
-X PUT \
-d "$configuration" \
"${destination_api_endpoint}personalizer/v1.0/configurations/$config_type")"
status="$(echo -n "$output" | tail -n 1)"
body="$(echo -n "$output" | head -n -1)"
if [[ $status == 200 ]]; then
log "Successfully copied $config_type configuration to destination resource $destination_resource_name"
else
log "Failed to copy $config_type configuration to destination resource $destination_resource_name"
log "Status Code: $status"
log "Body: $body"
fi
}
copy_model() {
log "Downloading model file from source resource $source_resource_name..."
curl -s \
-H "Ocp-Apim-Subscription-Key: $source_api_key" \
-o ./personalizer_model.zip \
"${source_api_endpoint}personalizer/v1.1-preview.3/model?signed=True"
log "Uploading model file to destination resource $destination_resource_name..."
output="$(curl -s -w "\n%{http_code}" \
-H "Ocp-Apim-Subscription-Key: $destination_api_key" \
-H "Content-Type: application/octet-stream" \
-X PUT \
--data-binary @./personalizer_model.zip \
"${destination_api_endpoint}personalizer/v1.1-preview.3/model")"
status="$(echo -n "$output" | tail -n 1)"
body="$(echo -n "$output" | head -n -1)"
if [[ $status == 204 ]]; then
log "Successfully copied model to destination resource $destination_resource_name"
else
log "Failed to copy model to destination resource $destination_resource_name"
log "Status Code: $status"
log "Body: $body"
fi
}
load_api_config "$source_resource_name" "$source_rg" "$destination_resource_name" "$destination_rg"
copy_configuration service
copy_model