Skip to content

Commit 42fea9d

Browse files
authored
[dynamic control] Add policy config model classes (record-style structure) (open-telemetry#2736)
1 parent ae69564 commit 42fea9d

3 files changed

Lines changed: 174 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.dynamic.policy.registry;
7+
8+
import java.util.ArrayList;
9+
import java.util.Collections;
10+
import java.util.List;
11+
import java.util.Objects;
12+
13+
/** Top-level registry initialization model containing per-source mapping config. */
14+
public final class PolicyInitConfig {
15+
16+
private final List<PolicySourceConfig> sources;
17+
18+
public PolicyInitConfig(List<PolicySourceConfig> sources) {
19+
List<PolicySourceConfig> sourceCopy =
20+
new ArrayList<>(Objects.requireNonNull(sources, "sources cannot be null"));
21+
for (PolicySourceConfig source : sourceCopy) {
22+
Objects.requireNonNull(source, "sources cannot contain null elements");
23+
}
24+
this.sources = Collections.unmodifiableList(sourceCopy);
25+
}
26+
27+
public List<PolicySourceConfig> getSources() {
28+
return sources;
29+
}
30+
31+
@Override
32+
public boolean equals(Object obj) {
33+
if (this == obj) {
34+
return true;
35+
}
36+
if (!(obj instanceof PolicyInitConfig)) {
37+
return false;
38+
}
39+
PolicyInitConfig that = (PolicyInitConfig) obj;
40+
return sources.equals(that.sources);
41+
}
42+
43+
@Override
44+
public int hashCode() {
45+
return sources.hashCode();
46+
}
47+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.dynamic.policy.registry;
7+
8+
import io.opentelemetry.contrib.dynamic.policy.source.SourceFormat;
9+
import io.opentelemetry.contrib.dynamic.policy.source.SourceKind;
10+
import java.util.ArrayList;
11+
import java.util.Collections;
12+
import java.util.List;
13+
import java.util.Objects;
14+
import javax.annotation.Nullable;
15+
16+
/** One configured policy source with source-local key-to-policy mappings. */
17+
public final class PolicySourceConfig {
18+
19+
private final SourceKind kind;
20+
private final SourceFormat format;
21+
@Nullable private final String location;
22+
private final List<PolicySourceMappingConfig> mappings;
23+
24+
public PolicySourceConfig(
25+
SourceKind kind,
26+
SourceFormat format,
27+
@Nullable String location,
28+
List<PolicySourceMappingConfig> mappings) {
29+
this.kind = Objects.requireNonNull(kind, "kind cannot be null");
30+
this.format = Objects.requireNonNull(format, "format cannot be null");
31+
this.location = location;
32+
List<PolicySourceMappingConfig> mappingCopy =
33+
new ArrayList<>(Objects.requireNonNull(mappings, "mappings cannot be null"));
34+
for (PolicySourceMappingConfig mapping : mappingCopy) {
35+
Objects.requireNonNull(mapping, "mappings cannot contain null elements");
36+
}
37+
this.mappings = Collections.unmodifiableList(mappingCopy);
38+
}
39+
40+
public SourceKind getKind() {
41+
return kind;
42+
}
43+
44+
public SourceFormat getFormat() {
45+
return format;
46+
}
47+
48+
@Nullable
49+
public String getLocation() {
50+
return location;
51+
}
52+
53+
public List<PolicySourceMappingConfig> getMappings() {
54+
return mappings;
55+
}
56+
57+
@Override
58+
public boolean equals(Object obj) {
59+
if (this == obj) {
60+
return true;
61+
}
62+
if (!(obj instanceof PolicySourceConfig)) {
63+
return false;
64+
}
65+
PolicySourceConfig that = (PolicySourceConfig) obj;
66+
return kind == that.kind
67+
&& format == that.format
68+
&& Objects.equals(location, that.location)
69+
&& mappings.equals(that.mappings);
70+
}
71+
72+
@Override
73+
public int hashCode() {
74+
int result = kind.hashCode();
75+
result = 31 * result + format.hashCode();
76+
result = 31 * result + (location == null ? 0 : location.hashCode());
77+
result = 31 * result + mappings.hashCode();
78+
return result;
79+
}
80+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.dynamic.policy.registry;
7+
8+
import java.util.Objects;
9+
10+
/** One source-local mapping from source key to target policy type. */
11+
public final class PolicySourceMappingConfig {
12+
13+
private final String sourceKey;
14+
private final String policyType;
15+
16+
public PolicySourceMappingConfig(String sourceKey, String policyType) {
17+
this.sourceKey = Objects.requireNonNull(sourceKey, "sourceKey cannot be null");
18+
this.policyType = Objects.requireNonNull(policyType, "policyType cannot be null");
19+
}
20+
21+
public String getSourceKey() {
22+
return sourceKey;
23+
}
24+
25+
public String getPolicyType() {
26+
return policyType;
27+
}
28+
29+
@Override
30+
public boolean equals(Object obj) {
31+
if (this == obj) {
32+
return true;
33+
}
34+
if (!(obj instanceof PolicySourceMappingConfig)) {
35+
return false;
36+
}
37+
PolicySourceMappingConfig that = (PolicySourceMappingConfig) obj;
38+
return sourceKey.equals(that.sourceKey) && policyType.equals(that.policyType);
39+
}
40+
41+
@Override
42+
public int hashCode() {
43+
int result = sourceKey.hashCode();
44+
result = 31 * result + policyType.hashCode();
45+
return result;
46+
}
47+
}

0 commit comments

Comments
 (0)