/
asyncoperations.go
48 lines (38 loc) · 1.47 KB
/
asyncoperations.go
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
package frontend
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"net/http"
"strings"
"time"
"github.com/gorilla/mux"
uuid "github.com/satori/go.uuid"
"github.com/Azure/ARO-RP/pkg/api"
)
func (f *frontend) newAsyncOperation(ctx context.Context, r *http.Request, doc *api.OpenShiftClusterDocument) (string, error) {
id := uuid.NewV4().String()
_, err := f.db.AsyncOperations.Create(ctx, &api.AsyncOperationDocument{
ID: id,
OpenShiftClusterKey: doc.Key,
AsyncOperation: &api.AsyncOperation{
ID: f.operationsPath(r, id),
Name: id,
InitialProvisioningState: doc.OpenShiftCluster.Properties.ProvisioningState,
ProvisioningState: doc.OpenShiftCluster.Properties.ProvisioningState,
StartTime: time.Now().UTC(),
},
})
if err != nil {
return "", err
}
return id, nil
}
func (f *frontend) operationsPath(r *http.Request, id string) string {
vars := mux.Vars(r)
return "/subscriptions/" + vars["subscriptionId"] + "/providers/" + vars["resourceProviderNamespace"] + "/locations/" + strings.ToLower(f.env.Location()) + "/operationsstatus/" + id
}
func (f *frontend) operationResultsPath(r *http.Request, id string) string {
vars := mux.Vars(r)
return "/subscriptions/" + vars["subscriptionId"] + "/providers/" + vars["resourceProviderNamespace"] + "/locations/" + strings.ToLower(f.env.Location()) + "/operationresults/" + id
}