Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.dynamic.policy.registry;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/** Top-level registry initialization model containing per-source mapping config. */
public final class PolicyInitConfig {

private final List<PolicySourceConfig> sources;

public PolicyInitConfig(List<PolicySourceConfig> sources) {
List<PolicySourceConfig> sourceCopy =
new ArrayList<>(Objects.requireNonNull(sources, "sources cannot be null"));
for (PolicySourceConfig source : sourceCopy) {
Objects.requireNonNull(source, "sources cannot contain null elements");
}
this.sources = Collections.unmodifiableList(sourceCopy);
}

public List<PolicySourceConfig> getSources() {
return sources;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof PolicyInitConfig)) {
return false;
}
PolicyInitConfig that = (PolicyInitConfig) obj;
return sources.equals(that.sources);
}

@Override
public int hashCode() {
return sources.hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.dynamic.policy.registry;

import io.opentelemetry.contrib.dynamic.policy.source.SourceFormat;
import io.opentelemetry.contrib.dynamic.policy.source.SourceKind;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;

/** One configured policy source with source-local key-to-policy mappings. */
public final class PolicySourceConfig {

private final SourceKind kind;
private final SourceFormat format;
@Nullable private final String location;
private final List<PolicySourceMappingConfig> mappings;

public PolicySourceConfig(
SourceKind kind,
SourceFormat format,
@Nullable String location,
List<PolicySourceMappingConfig> mappings) {
this.kind = Objects.requireNonNull(kind, "kind cannot be null");
this.format = Objects.requireNonNull(format, "format cannot be null");
this.location = location;
List<PolicySourceMappingConfig> mappingCopy =
new ArrayList<>(Objects.requireNonNull(mappings, "mappings cannot be null"));
for (PolicySourceMappingConfig mapping : mappingCopy) {
Objects.requireNonNull(mapping, "mappings cannot contain null elements");
}
this.mappings = Collections.unmodifiableList(mappingCopy);
}

public SourceKind getKind() {
return kind;
}

public SourceFormat getFormat() {
return format;
}

@Nullable
public String getLocation() {
return location;
}

public List<PolicySourceMappingConfig> getMappings() {
return mappings;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof PolicySourceConfig)) {
return false;
}
PolicySourceConfig that = (PolicySourceConfig) obj;
return kind == that.kind
&& format == that.format
&& Objects.equals(location, that.location)
&& mappings.equals(that.mappings);
}

@Override
public int hashCode() {
int result = kind.hashCode();
result = 31 * result + format.hashCode();
result = 31 * result + (location == null ? 0 : location.hashCode());
result = 31 * result + mappings.hashCode();
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.dynamic.policy.registry;

import java.util.Objects;

/** One source-local mapping from source key to target policy type. */
public final class PolicySourceMappingConfig {

private final String sourceKey;
private final String policyType;

public PolicySourceMappingConfig(String sourceKey, String policyType) {
this.sourceKey = Objects.requireNonNull(sourceKey, "sourceKey cannot be null");
this.policyType = Objects.requireNonNull(policyType, "policyType cannot be null");
}

public String getSourceKey() {
return sourceKey;
}

public String getPolicyType() {
return policyType;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof PolicySourceMappingConfig)) {
return false;
}
PolicySourceMappingConfig that = (PolicySourceMappingConfig) obj;
return sourceKey.equals(that.sourceKey) && policyType.equals(that.policyType);
}

@Override
public int hashCode() {
int result = sourceKey.hashCode();
result = 31 * result + policyType.hashCode();
return result;
}
}
Loading