-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (core): Expose Descriptor Protos as a new EntityKind
- Loading branch information
Showing
14 changed files
with
332 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
core/impl/src/main/java/dev/enola/core/meta/SchemaAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2023 The Enola <https://enola.dev> Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.enola.core.meta; | ||
|
||
import static com.google.protobuf.Any.pack; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.protobuf.DescriptorProtos; | ||
import com.google.protobuf.Descriptors; | ||
|
||
import dev.enola.core.EnolaException; | ||
import dev.enola.core.EnolaServiceProvider; | ||
import dev.enola.core.EntityAspect; | ||
import dev.enola.core.connector.proto.ConnectorServiceListRequest; | ||
import dev.enola.core.meta.proto.EntityKind; | ||
import dev.enola.core.proto.Entity; | ||
import dev.enola.core.proto.ID; | ||
|
||
import java.util.List; | ||
|
||
public class SchemaAspect implements EntityAspect { | ||
|
||
// Matching schema.textproto | ||
static final ID.Builder idBuilderTemplate = ID.newBuilder().setNs("enola").setEntity("schema"); | ||
|
||
private EnolaServiceProvider esp; | ||
|
||
public void setESP(EnolaServiceProvider enolaServiceProvider) { | ||
this.esp = enolaServiceProvider; | ||
} | ||
|
||
@Override | ||
public void augment(Entity.Builder entity, EntityKind entityKind) throws EnolaException { | ||
var name = entity.getId().getPaths(0); | ||
var descriptor = esp.getTypeRegistryWrapper().get().find(name).toProto(); | ||
var any = pack(descriptor, "type.googleapis.com/"); | ||
entity.putData("proto", any); | ||
} | ||
|
||
@Override | ||
public void list( | ||
ConnectorServiceListRequest request, | ||
EntityKind entityKind, | ||
List<Entity.Builder> entities) | ||
throws EnolaException { | ||
// TODO if (!IDs.withoutPath(request.getId()).equals(idBuilderTemplate)) return | ||
for (var name : esp.getTypeRegistryWrapper().names()) { | ||
var id = idBuilderTemplate.clone().addPaths(name); | ||
var newSchemaEntity = Entity.newBuilder().setId(id); | ||
augment(newSchemaEntity, null); | ||
entities.add(newSchemaEntity); | ||
} | ||
} | ||
|
||
public List<Descriptors.Descriptor> getDescriptors() throws EnolaException { | ||
return ImmutableList.of(DescriptorProtos.DescriptorProto.getDescriptor()); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
core/impl/src/main/java/dev/enola/core/meta/TypeRegistryWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2023 The Enola <https://enola.dev> Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.enola.core.meta; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.protobuf.Descriptors; | ||
import com.google.protobuf.TypeRegistry; | ||
|
||
import java.util.List; | ||
|
||
public class TypeRegistryWrapper { | ||
private final TypeRegistry originalTypeRegistry; | ||
private final ImmutableSet<String> names; | ||
|
||
private TypeRegistryWrapper(TypeRegistry typeRegistry, ImmutableSet<String> names) { | ||
this.originalTypeRegistry = typeRegistry; | ||
this.names = names; | ||
} | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
public TypeRegistry get() { | ||
return originalTypeRegistry; | ||
} | ||
|
||
public ImmutableSet<String> names() { | ||
return names; | ||
} | ||
|
||
public static final class Builder { | ||
private final TypeRegistry.Builder originalBuilder = TypeRegistry.newBuilder(); | ||
private final ImmutableSet.Builder<String> names = ImmutableSet.builder(); | ||
|
||
private Builder() {} | ||
|
||
public Builder add(List<Descriptors.Descriptor> descriptors) { | ||
originalBuilder.add(descriptors); | ||
for (Descriptors.Descriptor type : descriptors) { | ||
addFile(type.getFile()); | ||
} | ||
return this; | ||
} | ||
|
||
private void addFile(Descriptors.FileDescriptor file) { | ||
for (Descriptors.FileDescriptor dependency : file.getDependencies()) { | ||
addFile(dependency); | ||
} | ||
for (Descriptors.Descriptor message : file.getMessageTypes()) { | ||
addMessage(message); | ||
} | ||
} | ||
|
||
private void addMessage(Descriptors.Descriptor message) { | ||
for (Descriptors.Descriptor nestedType : message.getNestedTypes()) { | ||
addMessage(nestedType); | ||
} | ||
names.add(message.getFullName()); | ||
} | ||
|
||
public TypeRegistryWrapper build() { | ||
return new TypeRegistryWrapper(originalBuilder.build(), names.build()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Copyright 2023 The Enola <https://enola.dev> Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# https://protobuf.dev/reference/protobuf/textformat-spec/ | ||
# proto-file: dev/enola/core/meta/enola_meta.proto | ||
# proto-message: EntityKinds | ||
|
||
kinds { | ||
id: { ns: "enola" entity: "schema" paths: "fqn" } | ||
label: "Schema (Proto) used in Enola Entity Data" | ||
emoji: "💠" | ||
doc_url: "https://docs.enola.dev/use/connector/#grpc" | ||
connectors: { java_class: "dev.enola.core.meta.SchemaAspect" } | ||
data: { | ||
key: "proto" | ||
value: { | ||
label: "Protocol Buffer Descriptor (Proto)" | ||
description: "This is the Proto ('Schema') for the 'Any' fields in the 'data' of a Connector." | ||
type_url: "type.googleapis.com/google.protobuf.DescriptorProto" | ||
} | ||
} | ||
# TODO Add a "source" kind of data entry, which links to the Connector? | ||
} |
Oops, something went wrong.