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