Skip to content

Commit 9304779

Browse files
committed
Adding api types
1 parent 5aa8781 commit 9304779

File tree

3 files changed

+164
-0
lines changed

3 files changed

+164
-0
lines changed

opamp-client/build.gradle.kts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id("otel.java-conventions")
3+
id("com.google.protobuf") version "0.9.4"
34
}
45

56
description = "Client implementation of the OpAMP spec."
@@ -9,3 +10,33 @@ java {
910
sourceCompatibility = JavaVersion.VERSION_1_8
1011
targetCompatibility = JavaVersion.VERSION_1_8
1112
}
13+
14+
sourceSets {
15+
main {
16+
proto {
17+
srcDir("opamp-spec/proto")
18+
}
19+
}
20+
}
21+
22+
tasks.withType<JavaCompile>().configureEach {
23+
with(options) {
24+
// Suppressing warnings about the usage of deprecated methods.
25+
// This is needed because the Protobuf plugin (com.google.protobuf) generates code that uses deprecated methods.
26+
compilerArgs.add("-Xlint:-deprecation")
27+
}
28+
}
29+
30+
val protobufVersion = "4.28.2"
31+
32+
protobuf {
33+
protoc {
34+
artifact = "com.google.protobuf:protoc:$protobufVersion"
35+
}
36+
}
37+
38+
dependencies {
39+
implementation("com.google.protobuf:protobuf-java:$protobufVersion")
40+
annotationProcessor("com.google.auto.value:auto-value")
41+
compileOnly("com.google.auto.value:auto-value-annotations")
42+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.opamp.client.internal;
7+
8+
import io.opentelemetry.opamp.client.internal.response.MessageData;
9+
import opamp.proto.Opamp;
10+
11+
public interface OpampClient {
12+
13+
/**
14+
* Starts the client and begin attempts to connect to the Server. Once connection is established
15+
* the client will attempt to maintain it by reconnecting if the connection is lost. All failed
16+
* connection attempts will be reported via {@link Callbacks#onConnectFailed(OpampClient,
17+
* Throwable)} callback.
18+
*
19+
* <p>This method does not wait until the connection to the Server is established and will likely
20+
* return before the connection attempts are even made.
21+
*
22+
* <p>This method may be called only once.
23+
*
24+
* @param callbacks The Callback to which the Client will notify about any Server requests and
25+
* responses.
26+
*/
27+
void start(Callbacks callbacks);
28+
29+
/**
30+
* Stops the client. May be called only after {@link #start(Callbacks)}. May be called only once.
31+
* After this call returns successfully it is guaranteed that no callbacks will be called. Once
32+
* stopped, the client cannot be started again.
33+
*/
34+
void stop();
35+
36+
/**
37+
* Sets attributes of the Agent. The attributes will be included in the next status report sent to
38+
* the Server. When called after {@link #start(Callbacks)}, the attributes will be included in the
39+
* next outgoing status report. This is typically used by Agents which allow their
40+
* AgentDescription to change dynamically while the OpAMPClient is started. May be also called
41+
* from {@link Callbacks#onMessage(OpampClient, MessageData)}.
42+
*
43+
* @param agentDescription The new agent description.
44+
*/
45+
void setAgentDescription(Opamp.AgentDescription agentDescription);
46+
47+
/**
48+
* Sets the current remote config status which will be sent in the next agent to server request.
49+
*
50+
* @param remoteConfigStatus The new remote config status.
51+
*/
52+
void setRemoteConfigStatus(Opamp.RemoteConfigStatus remoteConfigStatus);
53+
54+
interface Callbacks {
55+
/**
56+
* Called when the connection is successfully established to the Server. May be called after
57+
* {@link #start(Callbacks)} is called and every time a connection is established to the Server.
58+
* For WebSocket clients this is called after the handshake is completed without any error. For
59+
* HTTP clients this is called for any request if the response status is OK.
60+
*
61+
* @param client The relevant {@link OpampClient} instance.
62+
*/
63+
void onConnect(OpampClient client);
64+
65+
/**
66+
* Called when the connection to the Server cannot be established. May be called after {@link
67+
* #start(Callbacks)} is called and tries to connect to the Server. May also be called if the
68+
* connection is lost and reconnection attempt fails.
69+
*
70+
* @param client The relevant {@link OpampClient} instance.
71+
* @param throwable The exception.
72+
*/
73+
void onConnectFailed(OpampClient client, Throwable throwable);
74+
75+
/**
76+
* Called when the Server reports an error in response to some previously sent request. Useful
77+
* for logging purposes. The Agent should not attempt to process the error by reconnecting or
78+
* retrying previous operations. The client handles the ErrorResponse_UNAVAILABLE case
79+
* internally by performing retries as necessary.
80+
*
81+
* @param client The relevant {@link OpampClient} instance.
82+
* @param errorResponse The error returned by the Server.
83+
*/
84+
void onErrorResponse(OpampClient client, Opamp.ServerErrorResponse errorResponse);
85+
86+
/**
87+
* Called when the Agent receives a message that needs processing. See {@link MessageData}
88+
* definition for the data that may be available for processing. During onMessage execution the
89+
* {@link OpampClient} functions that change the status of the client may be called, e.g. if
90+
* RemoteConfig is processed then {@link
91+
* #setRemoteConfigStatus(opamp.proto.Opamp.RemoteConfigStatus)} should be called to reflect the
92+
* processing result. These functions may also be called after onMessage returns. This is
93+
* advisable if processing can take a long time. In that case returning quickly is preferable to
94+
* avoid blocking the {@link OpampClient}.
95+
*
96+
* @param client The relevant {@link OpampClient} instance.
97+
* @param messageData The server response data that needs processing.
98+
*/
99+
void onMessage(OpampClient client, MessageData messageData);
100+
}
101+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.opamp.client.internal.response;
7+
8+
import com.google.auto.value.AutoValue;
9+
import io.opentelemetry.opamp.client.internal.OpampClient;
10+
import javax.annotation.Nullable;
11+
import opamp.proto.Opamp;
12+
13+
/**
14+
* Data class provided in {@link OpampClient.Callbacks#onMessage(OpampClient, MessageData)} with
15+
* Server's provided status changes.
16+
*/
17+
@AutoValue
18+
public abstract class MessageData {
19+
@Nullable
20+
public abstract Opamp.AgentRemoteConfig getRemoteConfig();
21+
22+
public static Builder builder() {
23+
return new AutoValue_MessageData.Builder();
24+
}
25+
26+
@AutoValue.Builder
27+
public abstract static class Builder {
28+
public abstract Builder setRemoteConfig(Opamp.AgentRemoteConfig remoteConfig);
29+
30+
public abstract MessageData build();
31+
}
32+
}

0 commit comments

Comments
 (0)