1 // SPDX-License-Identifier: Apache-2.0
\r
2 // Copyright (c) 2020 Intel Corporation
\r
4 package contextupdateclient
\r
10 contextpb "github.com/open-ness/EMCO/src/orchestrator/pkg/grpc/contextupdate"
\r
11 log "github.com/open-ness/EMCO/src/orchestrator/pkg/infra/logutils"
\r
12 "github.com/open-ness/EMCO/src/orchestrator/pkg/infra/rpc"
\r
13 pkgerrors "github.com/pkg/errors"
\r
16 // InvokeContextUpdate will make the grpc call to the specified controller
\r
17 // The controller will take the specified intentName and update the AppContext
\r
18 // appropriatly based on its operation as a placement or action controller.
\r
19 func InvokeContextUpdate(controllerName, intentName, appContextId string) error {
\r
21 var rpcClient contextpb.ContextupdateClient
\r
22 var updateRes *contextpb.ContextUpdateResponse
\r
23 ctx, cancel := context.WithTimeout(context.Background(), 600*time.Second)
\r
26 conn := rpc.GetRpcConn(controllerName)
\r
29 rpcClient = contextpb.NewContextupdateClient(conn)
\r
30 updateReq := new(contextpb.ContextUpdateRequest)
\r
31 updateReq.AppContext = appContextId
\r
32 updateReq.IntentName = intentName
\r
33 updateRes, err = rpcClient.UpdateAppContext(ctx, updateReq)
\r
35 return pkgerrors.Errorf("ContextUpdate Failed - Could not get ContextupdateClient: %v", controllerName)
\r
39 if updateRes.AppContextUpdated {
\r
40 log.Info("ContextUpdate Passed", log.Fields{
\r
41 "Controller": controllerName,
\r
42 "Intent": intentName,
\r
43 "AppContext": appContextId,
\r
44 "Message": updateRes.AppContextUpdateMessage,
\r
48 return pkgerrors.Errorf("ContextUpdate Failed: %v", updateRes.AppContextUpdateMessage)
\r