• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.tradefed.clearcut;
17 
18 import com.android.asuite.clearcut.Common.UserType;
19 import com.android.asuite.clearcut.ExternalUserLog.AtestLogEventExternal;
20 import com.android.asuite.clearcut.ExternalUserLog.AtestLogEventExternal.AtestStartEvent;
21 import com.android.asuite.clearcut.InternalUserLog.AtestLogEventInternal;
22 
23 import com.google.protobuf.ByteString;
24 
25 /** Utility to help populate the event protos */
26 public class ClearcutEventHelper {
27 
28     private static final String TOOL_NAME = "Tradefed";
29 
30     /**
31      * Create the start event for Tradefed.
32      *
33      * @param userKey The unique id representing the user
34      * @param runId The current id for the session.
35      * @param userType The type of the user: internal or external.
36      * @return a ByteString representation of the even proto.
37      */
createStartEvent(String userKey, String runId, UserType userType)38     public static ByteString createStartEvent(String userKey, String runId, UserType userType) {
39         if (UserType.GOOGLE.equals(userType)) {
40             AtestLogEventInternal.Builder builder =
41                     createBaseInternalEventBuilder(userKey, runId, userType);
42             AtestLogEventInternal.AtestStartEvent.Builder startEventBuilder =
43                     AtestLogEventInternal.AtestStartEvent.newBuilder();
44             builder.setAtestStartEvent(startEventBuilder.build());
45             return builder.build().toByteString();
46         }
47 
48         AtestLogEventExternal.Builder builder =
49                 createBaseExternalEventBuilder(userKey, runId, userType);
50         AtestStartEvent.Builder startBuilder = AtestStartEvent.newBuilder();
51         builder.setAtestStartEvent(startBuilder.build());
52         return builder.build().toByteString();
53     }
54 
55     /**
56      * Create the basic event builder with all the common informations.
57      *
58      * @param userKey The unique id representing the user
59      * @param runId The current id for the session.
60      * @param userType The type of the user: internal or external.
61      * @return a builder for the event.
62      */
createBaseExternalEventBuilder( String userKey, String runId, UserType userType)63     private static AtestLogEventExternal.Builder createBaseExternalEventBuilder(
64             String userKey, String runId, UserType userType) {
65         AtestLogEventExternal.Builder builder = AtestLogEventExternal.newBuilder();
66         builder.setUserKey(userKey);
67         builder.setRunId(runId);
68         builder.setUserType(userType);
69         builder.setToolName(TOOL_NAME);
70         return builder;
71     }
72 
73     /**
74      * Create the basic event builder with all the common informations.
75      *
76      * @param userKey The unique id representing the user
77      * @param runId The current id for the session.
78      * @param userType The type of the user: internal or external.
79      * @return a builder for the event.
80      */
createBaseInternalEventBuilder( String userKey, String runId, UserType userType)81     private static AtestLogEventInternal.Builder createBaseInternalEventBuilder(
82             String userKey, String runId, UserType userType) {
83         AtestLogEventInternal.Builder builder = AtestLogEventInternal.newBuilder();
84         builder.setUserKey(userKey);
85         builder.setRunId(runId);
86         builder.setUserType(userType);
87         builder.setToolName(TOOL_NAME);
88         return builder;
89     }
90 }
91