You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2026/02/11 15:01:11 UTC
(skywalking) 12/21: Remove V1 OAL engine code and update V2 documentation
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch oal-v2
in repository https://gitbox.apache.org/repos/asf/skywalking.git
commit bbc7b47c3e4af8ed6f9f5b086ffc836cb98ba343
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Tue Feb 10 12:23:25 2026 +0800
Remove V1 OAL engine code and update V2 documentation
V1 engine removal:
- Delete oal/rt/ directory (27 files): OALKernel, OALRuntime,
ScriptParser, AnalysisResult, DeepAnalysis, EntryMethod, etc.
- Delete code-templates/ directory (13 files): dispatcher/*.ftl,
metrics/*.ftl, metrics-builder/*.ftl
- Delete V1 comparison tests (4 files): AllOALScriptsComparisonTest,
V1V2ComparisonTest, V1ClassGenerator, DiagnosticTest
Documentation updates:
- CodeGenModel: Add class-level example showing OAL input/output,
document nested classes with examples (SourceFieldV2, DataFieldV2,
EntranceMethodV2, FilterExpressionV2)
- MetricDefinitionEnricher: Add enrichment pipeline documentation,
rename mapV2OperatorToV1ExpressionType to mapOperatorToExpressionType
- Remove all "V1-compatible" comment references
Co-Authored-By: Claude Opus 4.5 <no...@anthropic.com>
---
.../org/apache/skywalking/oal/rt/OALKernel.java | 135 -----
.../org/apache/skywalking/oal/rt/OALRuntime.java | 28 -
.../oal/rt/output/AllDispatcherContext.java | 30 -
.../oal/rt/output/DispatcherContext.java | 36 --
.../oal/rt/parser/AggregationFuncStmt.java | 74 ---
.../skywalking/oal/rt/parser/AnalysisResult.java | 146 -----
.../apache/skywalking/oal/rt/parser/Argument.java | 43 --
.../oal/rt/parser/ConditionExpression.java | 68 ---
.../skywalking/oal/rt/parser/DataColumn.java | 44 --
.../skywalking/oal/rt/parser/DeepAnalysis.java | 163 ------
.../oal/rt/parser/DisableCollection.java | 32 --
.../skywalking/oal/rt/parser/EntryMethod.java | 73 ---
.../skywalking/oal/rt/parser/Expression.java | 38 --
.../skywalking/oal/rt/parser/FilterMatchers.java | 95 ---
.../skywalking/oal/rt/parser/FilterStmts.java | 54 --
.../apache/skywalking/oal/rt/parser/FromStmt.java | 48 --
.../skywalking/oal/rt/parser/MetricsHolder.java | 64 ---
.../skywalking/oal/rt/parser/OALListener.java | 310 ----------
.../skywalking/oal/rt/parser/OALScripts.java | 34 --
.../oal/rt/parser/PersistenceColumns.java | 70 ---
.../skywalking/oal/rt/parser/PersistenceField.java | 39 --
.../skywalking/oal/rt/parser/ScriptParser.java | 73 ---
.../skywalking/oal/rt/parser/SourceColumn.java | 113 ----
.../oal/rt/parser/SourceColumnsFactory.java | 38 --
.../skywalking/oal/rt/util/ClassMethodUtil.java | 84 ---
.../skywalking/oal/rt/util/OALClassGenerator.java | 634 ---------------------
.../skywalking/oal/rt/util/TypeCastUtil.java | 43 --
.../skywalking/oal/v2/generator/CodeGenModel.java | 148 ++++-
.../oal/v2/generator/MetricDefinitionEnricher.java | 58 +-
.../code-templates/dispatcher/dispatch.ftl | 6 -
.../code-templates/dispatcher/doMetrics.ftl | 33 --
.../metrics-builder/entity2Storage.ftl | 29 -
.../metrics-builder/storage2Entity.ftl | 22 -
.../code-templates/metrics/deserialize.ftl | 24 -
.../resources/code-templates/metrics/equals.ftl | 25 -
.../resources/code-templates/metrics/getMeta.ftl | 3 -
.../resources/code-templates/metrics/hashCode.ftl | 14 -
.../main/resources/code-templates/metrics/id.ftl | 9 -
.../code-templates/metrics/remoteHashCode.ftl | 13 -
.../resources/code-templates/metrics/serialize.ftl | 24 -
.../resources/code-templates/metrics/toDay.ftl | 26 -
.../resources/code-templates/metrics/toHour.ftl | 26 -
.../v2/generator/AllOALScriptsComparisonTest.java | 361 ------------
.../oal/v2/generator/DiagnosticTest.java | 122 ----
.../oal/v2/generator/V1ClassGenerator.java | 253 --------
.../oal/v2/generator/V1V2ComparisonTest.java | 551 ------------------
46 files changed, 164 insertions(+), 4192 deletions(-)
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALKernel.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALKernel.java
deleted file mode 100644
index 3f1c3758c5..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALKernel.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt;
-
-import lombok.extern.slf4j.Slf4j;
-import org.apache.skywalking.oal.rt.parser.OALScripts;
-import org.apache.skywalking.oal.rt.parser.ScriptParser;
-import org.apache.skywalking.oal.rt.util.OALClassGenerator;
-import org.apache.skywalking.oap.server.core.analysis.DispatcherDetectorListener;
-import org.apache.skywalking.oap.server.core.analysis.StreamAnnotationListener;
-import org.apache.skywalking.oap.server.core.oal.rt.OALCompileException;
-import org.apache.skywalking.oap.server.core.oal.rt.OALDefine;
-import org.apache.skywalking.oap.server.core.oal.rt.OALEngine;
-import org.apache.skywalking.oap.server.core.storage.StorageBuilderFactory;
-import org.apache.skywalking.oap.server.core.storage.StorageException;
-
-import org.apache.skywalking.oap.server.library.module.ModuleStartException;
-import org.apache.skywalking.oap.server.library.util.ResourceUtils;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * OAL Runtime is the class generation engine, which load the generated classes from OAL scrip definitions. This runtime
- * is loaded dynamically.
- */
-@Slf4j
-public class OALKernel implements OALEngine {
-
- private static boolean IS_RT_TEMP_FOLDER_INIT_COMPLETED = false;
-
- private OALClassGenerator oalClassGenerator;
-
- private StreamAnnotationListener streamAnnotationListener;
- private DispatcherDetectorListener dispatcherDetectorListener;
- private final List<Class> metricsClasses;
- private final List<Class> dispatcherClasses;
-
- private final OALDefine oalDefine;
-
- public OALKernel(OALDefine define) {
- oalDefine = define;
- metricsClasses = new ArrayList<>();
- dispatcherClasses = new ArrayList<>();
-
- oalClassGenerator = new OALClassGenerator(define);
- }
-
- @Override
- public void setStreamListener(StreamAnnotationListener listener) throws ModuleStartException {
- this.streamAnnotationListener = listener;
- }
-
- @Override
- public void setDispatcherListener(DispatcherDetectorListener listener) throws ModuleStartException {
- dispatcherDetectorListener = listener;
- }
-
- @Override
- public void setStorageBuilderFactory(final StorageBuilderFactory factory) {
- oalClassGenerator.setStorageBuilderFactory(factory);
- }
-
- @Override
- public void start(ClassLoader currentClassLoader) throws ModuleStartException, OALCompileException {
- if (!IS_RT_TEMP_FOLDER_INIT_COMPLETED) {
- oalClassGenerator.prepareRTTempFolder();
- IS_RT_TEMP_FOLDER_INIT_COMPLETED = true;
- }
-
- Reader read;
- oalClassGenerator.setCurrentClassLoader(currentClassLoader);
-
- try {
- read = ResourceUtils.read(oalDefine.getConfigFile());
- } catch (FileNotFoundException e) {
- throw new ModuleStartException("Can't locate " + oalDefine.getConfigFile(), e);
- }
-
- OALScripts oalScripts;
- try {
- ScriptParser scriptParser = ScriptParser.createFromFile(read, oalDefine.getSourcePackage());
- oalScripts = scriptParser.parse();
- } catch (IOException e) {
- throw new ModuleStartException("OAL script parse analysis failure.", e);
- }
-
- oalClassGenerator.generateClassAtRuntime(oalScripts, metricsClasses, dispatcherClasses);
- }
-
- @Override
- public void notifyAllListeners() throws ModuleStartException {
- for (Class metricsClass : metricsClasses) {
- try {
- streamAnnotationListener.notify(metricsClass);
- } catch (StorageException e) {
- throw new ModuleStartException(e.getMessage(), e);
- }
- }
- for (Class dispatcherClass : dispatcherClasses) {
- try {
- dispatcherDetectorListener.addIfAsSourceDispatcher(dispatcherClass);
- } catch (Exception e) {
- throw new ModuleStartException(e.getMessage(), e);
- }
- }
- }
-
- protected List<Class> getMetricsClasses() {
- return metricsClasses;
- }
-
- protected List<Class> getDispatcherClasses() {
- return dispatcherClasses;
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALRuntime.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALRuntime.java
deleted file mode 100644
index a0721c5de0..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALRuntime.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt;
-
-import org.apache.skywalking.oap.server.core.oal.rt.OALDefine;
-
-public class OALRuntime extends OALKernel {
- public OALRuntime(OALDefine define) {
- super(define);
- }
-
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/output/AllDispatcherContext.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/output/AllDispatcherContext.java
deleted file mode 100644
index 15f04d3ec3..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/output/AllDispatcherContext.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.output;
-
-import java.util.HashMap;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
-
-@Getter
-@Setter
-public class AllDispatcherContext {
- private Map<String, DispatcherContext> allContext = new HashMap<>();
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/output/DispatcherContext.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/output/DispatcherContext.java
deleted file mode 100644
index 4430fb142e..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/output/DispatcherContext.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.output;
-
-import java.util.ArrayList;
-import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.skywalking.oal.rt.parser.AnalysisResult;
-
-@Getter
-@Setter
-public class DispatcherContext {
-
- private String sourcePackage;
- private String source;
- private String packageName;
- private List<AnalysisResult> metrics = new ArrayList<>();
- private String sourceDecorator;
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/AggregationFuncStmt.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/AggregationFuncStmt.java
deleted file mode 100644
index f4f2a8dbd5..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/AggregationFuncStmt.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.LinkedList;
-import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
-
-@Setter
-@Getter
-public class AggregationFuncStmt {
- private String aggregationFunctionName;
-
- private List<ConditionExpression> funcConditionExpressions;
-
- private int funcConditionExpressionGetIdx = 0;
-
- private List<Argument> funcArgs;
-
- private int argGetIdx = 0;
-
- private String nextArgCast = null;
-
- public void addFuncConditionExpression(ConditionExpression conditionExpression) {
- if (funcConditionExpressions == null) {
- funcConditionExpressions = new LinkedList<>();
- }
- funcConditionExpressions.add(conditionExpression);
- }
-
- public ConditionExpression getNextFuncConditionExpression() {
- return funcConditionExpressions.get(funcConditionExpressionGetIdx++);
- }
-
- public void addFuncArg(Argument argument) {
- if (funcArgs == null) {
- funcArgs = new LinkedList<>();
- }
- if (nextArgCast != null) {
- argument.setCastType(nextArgCast);
- nextArgCast = null;
- }
- funcArgs.add(argument);
- }
-
- public Argument getLastArgument() {
- return funcArgs.get(funcArgs.size() - 1);
- }
-
- public Argument getNextFuncArg() {
- return funcArgs.get(argGetIdx++);
- }
-
- public boolean hasNextArg() {
- return argGetIdx < funcArgs.size();
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/AnalysisResult.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/AnalysisResult.java
deleted file mode 100644
index b6d57d57b4..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/AnalysisResult.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.ArrayList;
-import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.skywalking.oap.server.core.storage.type.StorageDataComplexObject;
-
-/**
- * OAL analysis result.
- */
-@Getter
-@Setter
-public class AnalysisResult {
- /**
- * Variable name of one OAL expression.
- */
- private String varName;
- /**
- * Generated metric name.
- */
- private String metricsName;
- /**
- * Package name of generated metric class.
- */
- private String metricsClassPackage;
- /**
- * Table name for the storage.
- */
- private String tableName;
- /**
- * The package name of source class from {@link org.apache.skywalking.oap.server.core.oal.rt.OALDefine}
- */
- private String sourcePackage;
- /**
- * The class name of generated metric class.
- */
- private String metricsClassName;
- /**
- * The raw parsed result of from statement.
- */
- private FromStmt from = new FromStmt();
- /**
- * The raw parsed result of filter statements.
- */
- private FilterStmts filters = new FilterStmts();
- /**
- * The raw parsed result of aggregation function with arguments.
- */
- private AggregationFuncStmt aggregationFuncStmt = new AggregationFuncStmt();
-
- /**
- * Generated through {@link #aggregationFuncStmt}
- */
- private EntryMethod entryMethod;
-
- /**
- * Persistent columns are generated by {@link org.apache.skywalking.oap.server.core.storage.annotation.Column}
- * definition of {@link org.apache.skywalking.oap.server.core.analysis.metrics.annotation.MetricsFunction}.
- */
- private List<DataColumn> persistentFields;
- /**
- * Fields of metric class are generated by the fields annotated {@link org.apache.skywalking.oap.server.core.source.ScopeDefaultColumn.DefinedByField}
- * and class level definition through {@link org.apache.skywalking.oap.server.core.source.ScopeDefaultColumn.VirtualColumnDefinition}
- * in the {@link org.apache.skywalking.oap.server.core.source.Source}
- */
- private List<SourceColumn> fieldsFromSource;
- /**
- * Fields generated by {@link #fieldsFromSource} and {@link #persistentFields}. These fields are used in final
- * persistence.
- */
- private PersistenceColumns serializeFields;
-
- private String sourceDecorator;
-
- public void addPersistentField(String fieldName, String columnName, Class<?> type) {
- if (persistentFields == null) {
- persistentFields = new ArrayList<>();
- }
- DataColumn dataColumn = new DataColumn(fieldName, columnName, type);
- persistentFields.add(dataColumn);
- }
-
- public void generateSerializeFields() {
- serializeFields = new PersistenceColumns();
- for (SourceColumn sourceColumn : fieldsFromSource) {
- String type = sourceColumn.getType().getSimpleName();
- switch (type) {
- case "int":
- serializeFields.addIntField(sourceColumn.getFieldName());
- break;
- case "double":
- serializeFields.addDoubleField(sourceColumn.getFieldName());
- break;
- case "String":
- serializeFields.addStringField(sourceColumn.getFieldName());
- break;
- case "long":
- serializeFields.addLongField(sourceColumn.getFieldName());
- break;
- default:
- throw new IllegalStateException(
- "Unexpected field type [" + type + "] of source sourceColumn [" + sourceColumn
- .getFieldName() + "]");
- }
- }
-
- for (DataColumn column : persistentFields) {
- final Class<?> columnType = column.getType();
-
- if (columnType.equals(int.class)) {
- serializeFields.addIntField(column.getFieldName());
- } else if (columnType.equals(double.class)) {
- serializeFields.addDoubleField(column.getFieldName());
- } else if (columnType.equals(String.class)) {
- serializeFields.addStringField(column.getFieldName());
- } else if (columnType.equals(long.class)) {
- serializeFields.addLongField(column.getFieldName());
- } else if (StorageDataComplexObject.class.isAssignableFrom(columnType)) {
- serializeFields.addObjectField(column.getFieldName(), columnType.getName());
- } else {
- throw new IllegalStateException(
- "Unexpected field type [" + columnType.getSimpleName() + "] of persistence column [" + column
- .getFieldName() + "]");
- }
- }
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/Argument.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/Argument.java
deleted file mode 100644
index fe1954dc38..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/Argument.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.List;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.Setter;
-
-/**
- * Function argument.
- */
-@Getter
-@RequiredArgsConstructor
-public class Argument {
-
- private final int type;
-
- private final List<String> text;
-
- @Setter
- private String castType;
-
- public void addText(String text) {
- this.text.add(text);
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/ConditionExpression.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/ConditionExpression.java
deleted file mode 100644
index 3e611ba0fd..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/ConditionExpression.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-@Getter
-@Setter
-@NoArgsConstructor
-public class ConditionExpression {
- // original from script
- private String expressionType;
- private List<String> attributes = new ArrayList<>();
- private String value;
- private List<String> values;
- private boolean number;
- private String castType;
-
- public ConditionExpression(final String expressionType, final String attributes, final String value) {
- this.expressionType = expressionType;
- this.attributes = Arrays.asList(attributes.split("\\."));
- this.value = value;
- }
-
- public void addValue(String value) {
- if (values != null) {
- values.add(value);
- } else {
- this.value = value;
- }
- }
-
- public void isNumber() {
- number = true;
- }
-
- public void enterMultiConditionValue() {
- values = new LinkedList<>();
- }
-
- public void exitMultiConditionValue() {
- value = number ?
- "new long[]{" + String.join(",", values) + "}" :
- "new Object[]{" + String.join(",", values) + "}";
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/DataColumn.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/DataColumn.java
deleted file mode 100644
index 8a43f9b6eb..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/DataColumn.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.skywalking.oal.rt.util.ClassMethodUtil;
-
-@Getter
-@Setter
-public class DataColumn {
- private String fieldName;
- private String columnName;
- private Class<?> type;
- private String typeName;
- private String fieldSetter;
- private String fieldGetter;
-
- public DataColumn(String fieldName, String columnName, Class<?> type) {
- this.fieldName = fieldName;
- this.columnName = columnName;
- this.type = type;
- this.typeName = type.getName();
-
- this.fieldGetter = ClassMethodUtil.toGetMethod(fieldName);
- this.fieldSetter = ClassMethodUtil.toSetMethod(fieldName);
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/DeepAnalysis.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/DeepAnalysis.java
deleted file mode 100644
index 375158493d..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/DeepAnalysis.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import org.apache.skywalking.oal.rt.util.ClassMethodUtil;
-import org.apache.skywalking.oal.rt.util.TypeCastUtil;
-import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
-import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.Arg;
-import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.ConstOne;
-import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.DefaultValue;
-import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.Entrance;
-import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.SourceFrom;
-import org.apache.skywalking.oap.server.core.storage.annotation.Column;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
-import java.util.List;
-import static java.util.Objects.isNull;
-
-public class DeepAnalysis {
- public AnalysisResult analysis(AnalysisResult result) {
- // 1. Set sub package name by source.metrics
- Class<? extends Metrics> metricsClass = MetricsHolder.find(result.getAggregationFuncStmt().getAggregationFunctionName());
- String metricsClassSimpleName = metricsClass.getSimpleName();
-
- result.setMetricsClassName(metricsClassSimpleName);
-
- // Optional for filter
- List<ConditionExpression> expressions = result.getFilters().getFilterExpressionsParserResult();
- if (expressions != null && expressions.size() > 0) {
- for (ConditionExpression expression : expressions) {
- final FilterMatchers.MatcherInfo matcherInfo = FilterMatchers.INSTANCE.find(
- expression.getExpressionType());
-
- final String getter = matcherInfo.isBooleanType()
- ? ClassMethodUtil.toIsMethod(expression.getAttributes())
- : ClassMethodUtil.toGetMethod(expression.getAttributes());
-
- final Expression filterExpression = new Expression();
- filterExpression.setExpressionObject(matcherInfo.getMatcher().getName());
- filterExpression.setLeft(TypeCastUtil.withCast(expression.getCastType(), "source." + getter));
- filterExpression.setRight(expression.getValue());
- result.getFilters().addFilterExpressions(filterExpression);
- }
- }
-
- // 3. Find Entrance method of this metrics
- Class<?> c = metricsClass;
- Method entranceMethod = null;
- SearchEntrance:
- while (!c.equals(Object.class)) {
- for (Method method : c.getMethods()) {
- Entrance annotation = method.getAnnotation(Entrance.class);
- if (annotation != null) {
- entranceMethod = method;
- break SearchEntrance;
- }
- }
- c = c.getSuperclass();
- }
- if (entranceMethod == null) {
- throw new IllegalArgumentException("Can't find Entrance method in class: " + metricsClass.getName());
- }
- EntryMethod entryMethod = new EntryMethod();
- result.setEntryMethod(entryMethod);
- entryMethod.setMethodName(entranceMethod.getName());
-
- // 4. Use parameter's annotation of entrance method to generate aggregation entrance.
- for (Parameter parameter : entranceMethod.getParameters()) {
- Class<?> parameterType = parameter.getType();
- Annotation[] parameterAnnotations = parameter.getAnnotations();
- if (parameterAnnotations == null || parameterAnnotations.length == 0) {
- throw new IllegalArgumentException(
- "Entrance method:" + entranceMethod + " doesn't include the annotation.");
- }
- Annotation annotation = parameterAnnotations[0];
- if (annotation instanceof SourceFrom) {
- entryMethod.addArg(
- parameterType,
- TypeCastUtil.withCast(
- result.getFrom().getSourceCastType(),
- "source." + ClassMethodUtil.toGetMethod(result.getFrom().getSourceAttribute())
- )
- );
- } else if (annotation instanceof ConstOne) {
- entryMethod.addArg(parameterType, "1");
- } else if (annotation instanceof org.apache.skywalking.oap.server.core.analysis.metrics.annotation.Expression) {
- if (isNull(result.getAggregationFuncStmt().getFuncConditionExpressions())
- || result.getAggregationFuncStmt().getFuncConditionExpressions().isEmpty()) {
- throw new IllegalArgumentException(
- "Entrance method:" + entranceMethod + " argument can't find funcParamExpression.");
- } else {
- ConditionExpression expression = result.getAggregationFuncStmt().getNextFuncConditionExpression();
- final FilterMatchers.MatcherInfo matcherInfo = FilterMatchers.INSTANCE.find(
- expression.getExpressionType());
-
- final String getter = matcherInfo.isBooleanType()
- ? ClassMethodUtil.toIsMethod(expression.getAttributes())
- : ClassMethodUtil.toGetMethod(expression.getAttributes());
-
- final Expression argExpression = new Expression();
- argExpression.setRight(expression.getValue());
- argExpression.setExpressionObject(matcherInfo.getMatcher().getName());
- argExpression.setLeft(TypeCastUtil.withCast(expression.getCastType(), "source." + getter));
-
- entryMethod.addArg(argExpression);
- }
- } else if (annotation instanceof Arg) {
- entryMethod.addArg(parameterType, result.getAggregationFuncStmt().getNextFuncArg());
- } else if (annotation instanceof DefaultValue) {
- if (result.getAggregationFuncStmt().hasNextArg()) {
- entryMethod.addArg(parameterType, result.getAggregationFuncStmt().getNextFuncArg());
- } else {
- entryMethod.addArg(parameterType, ((DefaultValue) annotation).value());
- }
- } else {
- throw new IllegalArgumentException(
- "Entrance method:" + entranceMethod + " doesn't the expected annotation.");
- }
- }
-
- // 5. Get all column declared in MetricsHolder class.
- c = metricsClass;
- while (!c.equals(Object.class)) {
- for (Field field : c.getDeclaredFields()) {
- Column column = field.getAnnotation(Column.class);
- if (column != null) {
- result.addPersistentField(
- field.getName(),
- column.name(),
- field.getType());
- }
- }
- c = c.getSuperclass();
- }
-
- // 6. Based on Source, generate default columns
- List<SourceColumn> columns = SourceColumnsFactory.getColumns(result.getFrom().getSourceName());
- result.setFieldsFromSource(columns);
-
- result.generateSerializeFields();
-
- return result;
- }
-
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/DisableCollection.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/DisableCollection.java
deleted file mode 100644
index 517ec1fcbc..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/DisableCollection.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.ArrayList;
-import java.util.List;
-import lombok.Getter;
-
-@Getter
-public class DisableCollection {
- private List<String> allDisableSources = new ArrayList<>();
-
- public void add(String source) {
- allDisableSources.add(source);
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/EntryMethod.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/EntryMethod.java
deleted file mode 100644
index b3eda815ec..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/EntryMethod.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.ArrayList;
-import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.skywalking.oal.rt.util.ClassMethodUtil;
-import org.apache.skywalking.oal.rt.util.TypeCastUtil;
-
-@Getter
-@Setter
-public class EntryMethod {
- static final int LITERAL_TYPE = 1;
- static final int ATTRIBUTE_EXP_TYPE = 2;
- static final int EXPRESSION_TYPE = 3;
-
- private String methodName;
- private List<Integer> argTypes = new ArrayList<>();
- private List<Object> argsExpressions = new ArrayList<>();
-
- void addArg(Class<?> parameterType, Argument arg) {
- if (arg.getType() == LITERAL_TYPE) {
- // As literal type, there is always one element.
- addArg(parameterType, arg.getType(), arg.getText().get(0));
- return;
- }
- addArg(parameterType, arg.getType(), parameterType.equals(boolean.class) ?
- TypeCastUtil.withCast(arg.getCastType(), "source." + ClassMethodUtil.toIsMethod(arg.getText()))
- :
- TypeCastUtil.withCast(arg.getCastType(), "source." + ClassMethodUtil.toGetMethod(arg.getText())));
- }
-
- void addArg(Class<?> parameterType, String expression) {
- addArg(parameterType, LITERAL_TYPE, expression);
- }
-
- void addArg(Expression expression) {
- argTypes.add(EXPRESSION_TYPE);
- argsExpressions.add(expression);
- }
-
- private void addArg(Class<?> parameterType, int type, String expression) {
- if (parameterType.equals(int.class)) {
- expression = "(int)(" + expression + ")";
- } else if (parameterType.equals(long.class)) {
- expression = "(long)(" + expression + ")";
- } else if (parameterType.equals(double.class)) {
- expression = "(double)(" + expression + ")";
- } else if (parameterType.equals(float.class)) {
- expression = "(float)(" + expression + ")";
- }
- argTypes.add(type);
- argsExpressions.add(expression);
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/Expression.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/Expression.java
deleted file mode 100644
index aed15128d4..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/Expression.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import lombok.Getter;
-import lombok.Setter;
-
-@Getter
-public class Expression {
- @Setter
- private String expressionObject;
- private String left;
- private String right;
-
- public void setLeft(String left) {
- this.left = left;
- }
-
- public void setRight(String right) {
- this.right = right;
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/FilterMatchers.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/FilterMatchers.java
deleted file mode 100644
index 27e8ae1acb..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/FilterMatchers.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import com.google.common.reflect.ClassPath;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.BooleanValueFilterMatcher;
-import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.FilterMatcher;
-
-@SuppressWarnings("UnstableApiUsage")
-public enum FilterMatchers {
- INSTANCE;
-
- FilterMatchers() {
- try {
- init();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- private final Map<String, MatcherInfo> matchersKeyedByType = new HashMap<>();
-
- private void init() throws IOException {
- final ClassPath classpath = ClassPath.from(FilterMatchers.class.getClassLoader());
- final Set<ClassPath.ClassInfo> classes = classpath.getTopLevelClassesRecursive("org.apache.skywalking");
- for (ClassPath.ClassInfo classInfo : classes) {
- final Class<?> clazz = classInfo.load();
-
- final FilterMatcher plainFilterMatcher = clazz.getAnnotation(FilterMatcher.class);
- final BooleanValueFilterMatcher booleanFilterMatcher = clazz.getAnnotation(BooleanValueFilterMatcher.class);
- if (plainFilterMatcher != null && booleanFilterMatcher != null) {
- throw new IllegalStateException(
- "A matcher class can not be annotated with both @FilterMatcher and @BooleanValueFilterMatcher"
- );
- }
-
- if (plainFilterMatcher != null) {
- for (final String type : plainFilterMatcher.value()) {
- matchersKeyedByType.put(type, new MatcherInfo(clazz, false));
- }
- if (plainFilterMatcher.value().length == 0) {
- final String defaultTypeName = StringUtils.uncapitalize(clazz.getSimpleName());
- matchersKeyedByType.put(defaultTypeName, new MatcherInfo(clazz, false));
- }
- }
-
- if (booleanFilterMatcher != null) {
- for (final String type : booleanFilterMatcher.value()) {
- matchersKeyedByType.put(type, new MatcherInfo(clazz, true));
- }
- if (booleanFilterMatcher.value().length == 0) {
- final String defaultTypeName = StringUtils.uncapitalize(clazz.getSimpleName());
- matchersKeyedByType.put(defaultTypeName, new MatcherInfo(clazz, true));
- }
- }
- }
- }
-
- public MatcherInfo find(final String type) {
- if (!matchersKeyedByType.containsKey(type)) {
- throw new IllegalArgumentException("filter expression [" + type + "] not found");
- }
- return matchersKeyedByType.get(type);
- }
-
- @Getter
- @AllArgsConstructor
- public static class MatcherInfo {
- private final Class<?> matcher;
- private final boolean isBooleanType;
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/FilterStmts.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/FilterStmts.java
deleted file mode 100644
index 40dcc4f854..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/FilterStmts.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.LinkedList;
-import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * Filter statements in the OAL scripts.
- */
-@Getter
-@Setter
-public class FilterStmts {
- /**
- * Parsed raw result from grammar tree.
- */
- private List<ConditionExpression> filterExpressionsParserResult;
- /**
- * Generated expressions for code generation.
- */
- private List<Expression> filterExpressions;
-
- public void addFilterExpressions(Expression filterExpression) {
- if (filterExpressions == null) {
- filterExpressions = new LinkedList<>();
- }
- filterExpressions.add(filterExpression);
- }
-
- public void addFilterExpressionsParserResult(ConditionExpression conditionExpression) {
- if (filterExpressionsParserResult == null) {
- filterExpressionsParserResult = new LinkedList<>();
- }
- filterExpressionsParserResult.add(conditionExpression);
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/FromStmt.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/FromStmt.java
deleted file mode 100644
index 94be18494a..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/FromStmt.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.ArrayList;
-import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * FROM statement in the OAL script
- */
-@Setter
-@Getter
-public class FromStmt {
- /**
- * Source name in the FROM statement
- */
- private String sourceName;
- /**
- * source id according to {@link #sourceName}
- */
- private int sourceScopeId;
- /**
- * Attribute accessor
- */
- private List<String> sourceAttribute = new ArrayList<>();
- /**
- * Type cast function if exists. NULL as default, means no cast.
- */
- private String sourceCastType;
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/MetricsHolder.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/MetricsHolder.java
deleted file mode 100644
index fc62590a12..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/MetricsHolder.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.reflect.ClassPath;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import lombok.SneakyThrows;
-import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
-import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.MetricsFunction;
-
-@SuppressWarnings("UnstableApiUsage")
-public class MetricsHolder {
- private static final Map<String, Class<? extends Metrics>> REGISTER = new HashMap<>();
- private static volatile boolean INITIALIZED = false;
-
- private static void init() throws IOException {
- ClassPath classpath = ClassPath.from(MetricsHolder.class.getClassLoader());
- ImmutableSet<ClassPath.ClassInfo> classes = classpath.getTopLevelClassesRecursive("org.apache.skywalking");
- for (ClassPath.ClassInfo classInfo : classes) {
- Class<?> aClass = classInfo.load();
-
- if (aClass.isAnnotationPresent(MetricsFunction.class)) {
- MetricsFunction metricsFunction = aClass.getAnnotation(MetricsFunction.class);
- REGISTER.put(
- metricsFunction.functionName(),
- (Class<? extends Metrics>) aClass
- );
- }
- }
- }
-
- @SneakyThrows
- public static Class<? extends Metrics> find(String functionName) {
- if (!INITIALIZED) {
- init();
- INITIALIZED = true;
- }
-
- Class<? extends Metrics> metricsClass = REGISTER.get(functionName);
- if (metricsClass == null) {
- throw new IllegalArgumentException("Can't find metrics, " + functionName);
- }
- return metricsClass;
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALListener.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALListener.java
deleted file mode 100644
index daab84c656..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALListener.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import org.antlr.v4.runtime.misc.NotNull;
-import org.apache.skywalking.oal.rt.grammar.OALParser;
-import org.apache.skywalking.oal.rt.grammar.OALParserBaseListener;
-import org.apache.skywalking.oap.server.core.analysis.ISourceDecorator;
-import org.apache.skywalking.oap.server.core.analysis.SourceDecoratorManager;
-import org.apache.skywalking.oap.server.core.analysis.metrics.LabeledValueHolder;
-import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
-import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
-import org.apache.skywalking.oap.server.core.source.ISource;
-
-public class OALListener extends OALParserBaseListener {
- private List<AnalysisResult> results;
- private AnalysisResult current;
- private DisableCollection collection;
-
- private ConditionExpression conditionExpression;
-
- private final String sourcePackage;
-
- public OALListener(OALScripts scripts, String sourcePackage) {
- this.results = scripts.getMetricsStmts();
- this.collection = scripts.getDisableCollection();
- this.sourcePackage = sourcePackage;
- }
-
- @Override
- public void enterAggregationStatement(@NotNull OALParser.AggregationStatementContext ctx) {
- current = new AnalysisResult();
- }
-
- @Override
- public void exitAggregationStatement(@NotNull OALParser.AggregationStatementContext ctx) {
- DeepAnalysis deepAnalysis = new DeepAnalysis();
- results.add(deepAnalysis.analysis(current));
- current = null;
- }
-
- @Override
- public void enterSource(OALParser.SourceContext ctx) {
- current.getFrom().setSourceName(ctx.getText());
- current.getFrom().setSourceScopeId(DefaultScopeDefine.valueOf(metricsNameFormat(ctx.getText())));
- }
-
- @Override
- public void enterSourceAttribute(OALParser.SourceAttributeContext ctx) {
- current.getFrom().getSourceAttribute().add(ctx.getText());
- }
-
- @Override
- public void enterSourceAttrCast(OALParser.SourceAttrCastContext ctx) {
- current.getFrom().setSourceCastType(ctx.getText());
- }
-
- @Override
- public void enterVariable(OALParser.VariableContext ctx) {
- }
-
- @Override
- public void exitVariable(OALParser.VariableContext ctx) {
- current.setVarName(ctx.getText());
- current.setMetricsName(metricsNameFormat(ctx.getText()));
- current.setTableName(ctx.getText().toLowerCase());
- }
-
- @Override
- public void enterFunctionName(OALParser.FunctionNameContext ctx) {
- current.getAggregationFuncStmt().setAggregationFunctionName(ctx.getText());
- }
-
- @Override
- public void enterFilterStatement(OALParser.FilterStatementContext ctx) {
- conditionExpression = new ConditionExpression();
- }
-
- @Override
- public void exitFilterStatement(OALParser.FilterStatementContext ctx) {
- current.getFilters().addFilterExpressionsParserResult(conditionExpression);
- conditionExpression = null;
- }
-
- @Override
- public void enterFuncParamExpression(OALParser.FuncParamExpressionContext ctx) {
- conditionExpression = new ConditionExpression();
- }
-
- @Override
- public void exitFuncParamExpression(OALParser.FuncParamExpressionContext ctx) {
- current.getAggregationFuncStmt().addFuncConditionExpression(conditionExpression);
- conditionExpression = null;
- }
-
- @Override
- public void enterDecorateSource(OALParser.DecorateSourceContext ctx) {
- Class<? extends Metrics> metricsClass = MetricsHolder.find(current.getAggregationFuncStmt().getAggregationFunctionName());
- if (LabeledValueHolder.class.isAssignableFrom(metricsClass)) {
- throw new IllegalArgumentException(
- "OAL metric: " + current.getMetricsName() + ", decorate source not support labeled value metrics.");
- }
- String decoratorName = ctx.STRING_LITERAL().getText();
- String decoratorNameTrim = decoratorName.substring(1, decoratorName.length() - 1);
- current.setSourceDecorator(decoratorNameTrim);
- Map<String, ISourceDecorator<ISource>> map = SourceDecoratorManager.DECORATOR_MAP;
- int currentScopeId = current.getFrom().getSourceScopeId();
- if (currentScopeId != DefaultScopeDefine.SERVICE
- && currentScopeId != DefaultScopeDefine.K8S_SERVICE
- && currentScopeId != DefaultScopeDefine.ENDPOINT) {
- throw new IllegalArgumentException("OAL metric: " + current.getMetricsName() + ", decorate source not support scope: " + DefaultScopeDefine.nameOf(currentScopeId));
- }
- ISourceDecorator<ISource> decorator = map.get(decoratorNameTrim);
- if (decorator == null) {
- throw new IllegalArgumentException("OAL metric: " + current.getMetricsName() + " define a decorator: " + decoratorNameTrim
- + ", but can't find it.");
- }
- int scopeId = decorator.getSourceScope();
- if (scopeId != currentScopeId) {
- throw new IllegalArgumentException("OAL Decorate Source, expect decorator scope id is: " + currentScopeId + ", but got: " + scopeId);
- }
- }
-
- /////////////
- // Expression
- ////////////
- @Override
- public void enterConditionAttribute(OALParser.ConditionAttributeContext ctx) {
- conditionExpression.getAttributes().add(ctx.getText());
- }
-
- @Override
- public void enterBooleanMatch(OALParser.BooleanMatchContext ctx) {
- conditionExpression.setExpressionType("booleanMatch");
- }
-
- @Override
- public void enterNumberMatch(OALParser.NumberMatchContext ctx) {
- conditionExpression.setExpressionType("numberMatch");
- }
-
- @Override
- public void enterStringMatch(OALParser.StringMatchContext ctx) {
- conditionExpression.setExpressionType("stringMatch");
- }
-
- @Override
- public void enterGreaterMatch(OALParser.GreaterMatchContext ctx) {
- conditionExpression.setExpressionType("greaterMatch");
- }
-
- @Override
- public void enterGreaterEqualMatch(OALParser.GreaterEqualMatchContext ctx) {
- conditionExpression.setExpressionType("greaterEqualMatch");
- }
-
- @Override
- public void enterLessMatch(OALParser.LessMatchContext ctx) {
- conditionExpression.setExpressionType("lessMatch");
- }
-
- @Override
- public void enterLessEqualMatch(OALParser.LessEqualMatchContext ctx) {
- conditionExpression.setExpressionType("lessEqualMatch");
- }
-
- @Override
- public void enterNotEqualMatch(final OALParser.NotEqualMatchContext ctx) {
- conditionExpression.setExpressionType("notEqualMatch");
- }
-
- @Override
- public void enterBooleanNotEqualMatch(final OALParser.BooleanNotEqualMatchContext ctx) {
- conditionExpression.setExpressionType("booleanNotEqualMatch");
- }
-
- @Override
- public void enterLikeMatch(final OALParser.LikeMatchContext ctx) {
- conditionExpression.setExpressionType("likeMatch");
- }
-
- @Override
- public void enterContainMatch(final OALParser.ContainMatchContext ctx) {
- conditionExpression.setExpressionType("containMatch");
- }
-
- @Override
- public void enterNotContainMatch(final OALParser.NotContainMatchContext ctx) {
- conditionExpression.setExpressionType("notContainMatch");
- }
-
- @Override
- public void enterInMatch(final OALParser.InMatchContext ctx) {
- conditionExpression.setExpressionType("inMatch");
- }
-
- @Override
- public void enterMultiConditionValue(final OALParser.MultiConditionValueContext ctx) {
- conditionExpression.enterMultiConditionValue();
- }
-
- @Override
- public void exitMultiConditionValue(final OALParser.MultiConditionValueContext ctx) {
- conditionExpression.exitMultiConditionValue();
- }
-
- @Override
- public void enterBooleanConditionValue(OALParser.BooleanConditionValueContext ctx) {
- enterConditionValue(ctx.getText());
- }
-
- @Override
- public void enterStringConditionValue(OALParser.StringConditionValueContext ctx) {
- enterConditionValue(ctx.getText());
- }
-
- @Override
- public void enterEnumConditionValue(OALParser.EnumConditionValueContext ctx) {
- enterEnumConditionValue(ctx.getText());
- }
-
- @Override
- public void enterNumberConditionValue(OALParser.NumberConditionValueContext ctx) {
- conditionExpression.isNumber();
- enterConditionValue(ctx.getText());
- }
-
- @Override
- public void enterNullConditionValue(OALParser.NullConditionValueContext ctx) {
- enterConditionValue(ctx.getText());
- }
-
- @Override
- public void enterExpressionAttrCast(final OALParser.ExpressionAttrCastContext ctx) {
- conditionExpression.setCastType(ctx.getText());
- }
-
- private void enterConditionValue(String value) {
- conditionExpression.addValue(value);
- }
-
- private void enterEnumConditionValue(String value) {
- conditionExpression.addValue(sourcePackage + value);
- }
-
- /////////////
- // Expression end.
- ////////////
-
- @Override
- public void enterLiteralExpression(OALParser.LiteralExpressionContext ctx) {
- current.getAggregationFuncStmt().addFuncArg(new Argument(EntryMethod.LITERAL_TYPE, Arrays.asList(ctx.getText())));
- }
-
- @Override
- public void enterAttributeExpression(final OALParser.AttributeExpressionContext ctx) {
- current.getAggregationFuncStmt().addFuncArg(new Argument(EntryMethod.ATTRIBUTE_EXP_TYPE, new ArrayList<>(3)));
- }
-
- @Override
- public void enterAttributeExpressionSegment(OALParser.AttributeExpressionSegmentContext ctx) {
- current.getAggregationFuncStmt().getLastArgument().addText(ctx.getText());
- }
-
- @Override
- public void enterFunctionArgCast(final OALParser.FunctionArgCastContext ctx) {
- current.getAggregationFuncStmt().getLastArgument().setCastType(ctx.getText());
- }
-
- private String metricsNameFormat(String source) {
- source = firstLetterUpper(source);
- int idx;
- while ((idx = source.indexOf("_")) > -1) {
- source = source.substring(0, idx) + firstLetterUpper(source.substring(idx + 1));
- }
- return source;
- }
-
- /**
- * Disable source
- */
- @Override
- public void enterDisableSource(OALParser.DisableSourceContext ctx) {
- collection.add(ctx.getText());
- }
-
- private String firstLetterUpper(String source) {
- return source.substring(0, 1).toUpperCase() + source.substring(1);
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALScripts.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALScripts.java
deleted file mode 100644
index 18f16a2aa3..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALScripts.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.ArrayList;
-import java.util.List;
-import lombok.Getter;
-
-@Getter
-public class OALScripts {
- private List<AnalysisResult> metricsStmts;
- private DisableCollection disableCollection;
-
- public OALScripts() {
- metricsStmts = new ArrayList<>();
- disableCollection = new DisableCollection();
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/PersistenceColumns.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/PersistenceColumns.java
deleted file mode 100644
index 30280c22a4..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/PersistenceColumns.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class PersistenceColumns {
- private List<PersistenceField> stringFields = new ArrayList<>();
- private List<PersistenceField> longFields = new ArrayList<>();
- private List<PersistenceField> doubleFields = new ArrayList<>();
- private List<PersistenceField> intFields = new ArrayList<>();
- private List<PersistenceField> objectFields = new ArrayList<>();
-
- public void addStringField(String fieldName) {
- stringFields.add(new PersistenceField(fieldName, "String"));
- }
-
- public void addLongField(String fieldName) {
- longFields.add(new PersistenceField(fieldName, "long"));
- }
-
- public void addDoubleField(String fieldName) {
- doubleFields.add(new PersistenceField(fieldName, "double"));
- }
-
- public void addIntField(String fieldName) {
- intFields.add(new PersistenceField(fieldName, "int"));
- }
-
- public void addObjectField(String fieldName, String fieldType) {
- objectFields.add(new PersistenceField(fieldName, fieldType));
- }
-
- public List<PersistenceField> getStringFields() {
- return stringFields;
- }
-
- public List<PersistenceField> getLongFields() {
- return longFields;
- }
-
- public List<PersistenceField> getDoubleFields() {
- return doubleFields;
- }
-
- public List<PersistenceField> getIntFields() {
- return intFields;
- }
-
- public List<PersistenceField> getObjectFields() {
- return objectFields;
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/PersistenceField.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/PersistenceField.java
deleted file mode 100644
index 45c5a10516..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/PersistenceField.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.skywalking.oal.rt.util.ClassMethodUtil;
-
-@Getter
-@Setter
-public class PersistenceField {
- private String fieldName;
- private String setter;
- private String getter;
- private String fieldType;
-
- public PersistenceField(String fieldName, String fieldType) {
- this.fieldName = fieldName;
- this.setter = ClassMethodUtil.toSetMethod(fieldName);
- this.getter = ClassMethodUtil.toGetMethod(fieldName);
- this.fieldType = fieldType;
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/ScriptParser.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/ScriptParser.java
deleted file mode 100644
index c69fa2a9d2..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/ScriptParser.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.io.IOException;
-import java.io.Reader;
-import org.antlr.v4.runtime.CharStreams;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.tree.ParseTree;
-import org.antlr.v4.runtime.tree.ParseTreeWalker;
-import org.apache.skywalking.oal.rt.grammar.OALLexer;
-import org.apache.skywalking.oal.rt.grammar.OALParser;
-
-/**
- * Script reader and parser.
- */
-public class ScriptParser {
- private OALLexer lexer;
-
- private String sourcePackage;
-
- private ScriptParser() {
-
- }
-
- public static ScriptParser createFromFile(Reader scriptReader, String sourcePackage) throws IOException {
- ScriptParser parser = new ScriptParser();
- parser.lexer = new OALLexer(CharStreams.fromReader(scriptReader));
- parser.sourcePackage = sourcePackage;
- return parser;
- }
-
- public static ScriptParser createFromScriptText(String script, String sourcePackage) throws IOException {
- ScriptParser parser = new ScriptParser();
- parser.lexer = new OALLexer(CharStreams.fromString(script));
- parser.sourcePackage = sourcePackage;
- return parser;
- }
-
- public OALScripts parse() throws IOException {
- OALScripts scripts = new OALScripts();
-
- CommonTokenStream tokens = new CommonTokenStream(lexer);
-
- OALParser parser = new OALParser(tokens);
-
- ParseTree tree = parser.root();
- ParseTreeWalker walker = new ParseTreeWalker();
-
- walker.walk(new OALListener(scripts, sourcePackage), tree);
-
- return scripts;
- }
-
- public void close() {
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumn.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumn.java
deleted file mode 100644
index 479c9bafd3..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumn.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.Objects;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.skywalking.oal.rt.util.ClassMethodUtil;
-
-@Getter
-@Setter
-public class SourceColumn {
- private String fieldName;
- private String columnName;
- private Class<?> type;
- private String typeName;
- private boolean isID;
- private int length;
- private String fieldSetter;
- private String fieldGetter;
- private final int shardingKeyIdx;
- private final boolean attribute;
-
- public SourceColumn(String fieldName, String columnName, Class<?> type, boolean isID, int length,
- int shardingKeyIdx, boolean attribute) {
- this.fieldName = fieldName;
- this.columnName = columnName;
- this.type = type;
- this.typeName = type.getName();
- this.isID = isID;
- this.length = length;
-
- this.fieldGetter = ClassMethodUtil.toGetMethod(fieldName);
- this.fieldSetter = ClassMethodUtil.toSetMethod(fieldName);
- this.shardingKeyIdx = shardingKeyIdx;
- this.attribute = attribute;
- }
-
- public void setFieldName(String fieldName) {
- this.fieldName = fieldName;
- this.fieldGetter = ClassMethodUtil.toGetMethod(fieldName);
- this.fieldSetter = ClassMethodUtil.toSetMethod(fieldName);
- }
-
- public void setTypeName(String typeName) {
- switch (typeName) {
- case "int":
- this.type = int.class;
- break;
- case "long":
- this.type = long.class;
- break;
- case "string":
- case "String":
- this.type = String.class;
- typeName = "String";
- break;
- default:
- try {
- this.type = Class.forName(typeName);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
-
- this.typeName = typeName;
- }
-
- /**
- * @return true if this column is a part of sharding key
- */
- public boolean isShardingKey() {
- return this.shardingKeyIdx > -1;
- }
-
- @Override
- public String toString() {
- return "SourceColumn{" + "fieldName=" + fieldName + ", columnName=" + columnName + ", type=" + type + ", isID=" + isID + ", shardingKeyIdx=" + shardingKeyIdx + ", isAttribute=" + attribute + "}";
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (o == null || getClass() != o.getClass())
- return false;
- SourceColumn column = (SourceColumn) o;
- return isID == column.isID && Objects.equals(fieldName, column.fieldName) && Objects.equals(columnName, column.columnName) && Objects
- .equals(type, column.type) && Objects.equals(typeName, column.typeName) && Objects.equals(fieldSetter, column.fieldSetter) && Objects
- .equals(fieldGetter, column.fieldGetter);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(fieldName, columnName, type, typeName, isID, fieldSetter, fieldGetter);
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumnsFactory.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumnsFactory.java
deleted file mode 100644
index 494a1b650c..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumnsFactory.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.parser;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
-import org.apache.skywalking.oap.server.core.source.ScopeDefaultColumn;
-
-public class SourceColumnsFactory {
- public static List<SourceColumn> getColumns(String source) {
- List<SourceColumn> sourceColumns = new ArrayList<>();
-
- List<ScopeDefaultColumn> columns = DefaultScopeDefine.getDefaultColumns(source);
- for (ScopeDefaultColumn defaultColumn : columns) {
- sourceColumns.add(
- new SourceColumn(defaultColumn.getFieldName(), defaultColumn.getColumnName(), defaultColumn
- .getType(), defaultColumn.isID(), defaultColumn.getLength(), defaultColumn.getShardingKeyIdx(), defaultColumn.isAttribute()));
- }
- return sourceColumns;
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/util/ClassMethodUtil.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/util/ClassMethodUtil.java
deleted file mode 100644
index 0b7f0f1287..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/util/ClassMethodUtil.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.util;
-
-import java.util.List;
-
-public class ClassMethodUtil {
- public static String toGetMethod(String attribute) {
- return "get" + attribute.substring(0, 1).toUpperCase() + attribute.substring(1);
- }
-
- public static String toSetMethod(String attribute) {
- return "set" + attribute.substring(0, 1).toUpperCase() + attribute.substring(1);
- }
-
- public static String toIsMethod(String attribute) {
- return "is" + attribute.substring(0, 1).toUpperCase() + attribute.substring(1);
- }
-
- /**
- * @return nested get methods.
- */
- public static String toGetMethod(List<String> attributes) {
- StringBuilder method = new StringBuilder();
- for (int i = 0; i < attributes.size(); i++) {
- if (i != 0) {
- method.append(".");
- }
- if (isMapExpression(attributes.get(i))) {
- method.append(mapExpression(attributes.get(i)));
- } else {
- method.append(toGetMethod(attributes.get(i))).append("()");
- }
- }
- return method.toString();
- }
-
- /**
- * @return nested get/is methods.
- */
- public static String toIsMethod(List<String> attributes) {
- StringBuilder method = new StringBuilder();
- for (int i = 0; i < attributes.size(); i++) {
- if (i != 0) {
- method.append(".");
- }
- if (i != attributes.size() - 1) {
- method.append(toGetMethod(attributes.get(i))).append("()");
- } else {
- method.append(toIsMethod(attributes.get(i))).append("()");
- }
- }
- return method.toString();
- }
-
- /**
- * @return empty if this attribute is not type of map.
- */
- private static String mapExpression(String attribute) {
- final int indexOf = attribute.indexOf("[");
- return toGetMethod(attribute.substring(0, indexOf))
- + "(" + attribute.substring(indexOf + 1, attribute.length() - 1) + ")";
- }
-
- private static boolean isMapExpression(String attribute) {
- return attribute.indexOf("[") > 0 && attribute.endsWith("]");
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/util/OALClassGenerator.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/util/OALClassGenerator.java
deleted file mode 100644
index 46f2039fd2..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/util/OALClassGenerator.java
+++ /dev/null
@@ -1,634 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.util;
-
-import freemarker.template.Configuration;
-import freemarker.template.Version;
-import javassist.CannotCompileException;
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtConstructor;
-import javassist.CtField;
-import javassist.CtNewConstructor;
-import javassist.CtNewMethod;
-import javassist.NotFoundException;
-import javassist.bytecode.AnnotationsAttribute;
-import javassist.bytecode.ClassFile;
-import javassist.bytecode.ConstPool;
-import javassist.bytecode.SignatureAttribute;
-import javassist.bytecode.annotation.Annotation;
-import javassist.bytecode.annotation.ClassMemberValue;
-import javassist.bytecode.annotation.IntegerMemberValue;
-import javassist.bytecode.annotation.StringMemberValue;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.JavaVersion;
-import org.apache.commons.lang3.SystemUtils;
-import org.apache.skywalking.oal.rt.OALRuntime;
-import org.apache.skywalking.oal.rt.output.AllDispatcherContext;
-import org.apache.skywalking.oal.rt.output.DispatcherContext;
-import org.apache.skywalking.oal.rt.parser.AnalysisResult;
-import org.apache.skywalking.oal.rt.parser.OALScripts;
-import org.apache.skywalking.oal.rt.parser.SourceColumn;
-import org.apache.skywalking.oap.server.core.WorkPath;
-import org.apache.skywalking.oap.server.core.analysis.DisableRegister;
-import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
-import org.apache.skywalking.oap.server.core.analysis.Stream;
-import org.apache.skywalking.oap.server.core.oal.rt.OALCompileException;
-import org.apache.skywalking.oap.server.core.oal.rt.OALDefine;
-import org.apache.skywalking.oap.server.core.source.oal.rt.dispatcher.DispatcherClassPackageHolder;
-import org.apache.skywalking.oap.server.core.source.oal.rt.metrics.MetricClassPackageHolder;
-import org.apache.skywalking.oap.server.core.source.oal.rt.metrics.builder.MetricBuilderClassPackageHolder;
-import org.apache.skywalking.oap.server.core.storage.StorageBuilderFactory;
-import org.apache.skywalking.oap.server.core.storage.annotation.BanyanDB;
-import org.apache.skywalking.oap.server.core.storage.annotation.Column;
-import org.apache.skywalking.oap.server.core.storage.annotation.ElasticSearch;
-import org.apache.skywalking.oap.server.library.util.StringUtil;
-
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-@Slf4j
-public class OALClassGenerator {
-
- private static final String METRICS_FUNCTION_PACKAGE = "org.apache.skywalking.oap.server.core.analysis.metrics.";
- private static final String WITH_METADATA_INTERFACE = "org.apache.skywalking.oap.server.core.analysis.metrics.WithMetadata";
- private static final String DISPATCHER_INTERFACE = "org.apache.skywalking.oap.server.core.analysis.SourceDispatcher";
- private static final String METRICS_STREAM_PROCESSOR = "org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor";
- private static final String[] METRICS_CLASS_METHODS = {
- "id",
- "hashCode",
- "remoteHashCode",
- "equals",
- "serialize",
- "deserialize",
- "getMeta",
- "toHour",
- "toDay"
- };
- private static final String[] METRICS_BUILDER_CLASS_METHODS = {
- "entity2Storage",
- "storage2Entity"
- };
-
- private static final String CLASS_FILE_CHARSET = "UTF-8";
-
- private boolean openEngineDebug;
-
- private AllDispatcherContext allDispatcherContext;
-
- private final ClassPool classPool;
-
- private final OALDefine oalDefine;
-
- private Configuration configuration;
-
- private ClassLoader currentClassLoader;
-
- private StorageBuilderFactory storageBuilderFactory;
-
- private static String GENERATED_FILE_PATH;
-
- public OALClassGenerator(OALDefine define) {
- this(define, ClassPool.getDefault());
- }
-
- /**
- * Constructor with custom ClassPool for test isolation.
- */
- public OALClassGenerator(OALDefine define, ClassPool classPool) {
- openEngineDebug = StringUtil.isNotEmpty(System.getenv("SW_OAL_ENGINE_DEBUG"));
- allDispatcherContext = new AllDispatcherContext();
- this.classPool = classPool;
- oalDefine = define;
-
- configuration = new Configuration(new Version("2.3.28"));
- configuration.setEncoding(Locale.ENGLISH, CLASS_FILE_CHARSET);
- configuration.setClassLoaderForTemplateLoading(OALRuntime.class.getClassLoader(), "/code-templates");
- }
-
- public void generateClassAtRuntime(OALScripts oalScripts, List<Class> metricsClasses, List<Class> dispatcherClasses) throws OALCompileException {
- List<AnalysisResult> metricsStmts = oalScripts.getMetricsStmts();
- metricsStmts.forEach(this::buildDispatcherContext);
-
- for (AnalysisResult metricsStmt : metricsStmts) {
- metricsClasses.add(generateMetricsClass(metricsStmt));
- generateMetricsBuilderClass(metricsStmt);
- }
-
- for (Map.Entry<String, DispatcherContext> entry : allDispatcherContext.getAllContext().entrySet()) {
- dispatcherClasses.add(generateDispatcherClass(entry.getKey(), entry.getValue()));
- }
-
- oalScripts.getDisableCollection().getAllDisableSources().forEach(disable -> {
- DisableRegister.INSTANCE.add(disable);
- });
- }
-
- /**
- * Generate metrics class, and inject it to classloader
- */
- private Class generateMetricsClass(AnalysisResult metricsStmt) throws OALCompileException {
- String className = metricsClassName(metricsStmt, false);
- CtClass parentMetricsClass = null;
- try {
- parentMetricsClass = classPool.get(METRICS_FUNCTION_PACKAGE + metricsStmt.getMetricsClassName());
- } catch (NotFoundException e) {
- log.error("Can't find parent class for " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
- CtClass metricsClass = classPool.makeClass(metricsClassName(metricsStmt, true), parentMetricsClass);
- try {
- metricsClass.addInterface(classPool.get(WITH_METADATA_INTERFACE));
- } catch (NotFoundException e) {
- log.error("Can't find WithMetadata interface for " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
-
- ClassFile metricsClassClassFile = metricsClass.getClassFile();
- ConstPool constPool = metricsClassClassFile.getConstPool();
-
- /**
- * Create empty construct
- */
- try {
- CtConstructor defaultConstructor = CtNewConstructor.make("public " + className + "() {}", metricsClass);
- metricsClass.addConstructor(defaultConstructor);
- } catch (CannotCompileException e) {
- log.error("Can't add empty constructor in " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
-
- /**
- * Add fields with annotations.
- *
- * private ${sourceField.typeName} ${sourceField.fieldName};
- */
- for (SourceColumn field : metricsStmt.getFieldsFromSource()) {
- try {
- CtField newField = CtField.make(
- "private " + field.getType()
- .getName() + " " + field.getFieldName() + ";", metricsClass);
-
- metricsClass.addField(newField);
-
- metricsClass.addMethod(CtNewMethod.getter(field.getFieldGetter(), newField));
- metricsClass.addMethod(CtNewMethod.setter(field.getFieldSetter(), newField));
-
- AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(
- constPool, AnnotationsAttribute.visibleTag);
- /**
- * Add @Column(name = "${sourceField.columnName}")
- */
- Annotation columnAnnotation = new Annotation(Column.class.getName(), constPool);
- columnAnnotation.addMemberValue("name", new StringMemberValue(field.getColumnName(), constPool));
- if (field.getType().equals(String.class)) {
- columnAnnotation.addMemberValue("length", new IntegerMemberValue(constPool, field.getLength()));
- }
- annotationsAttribute.addAnnotation(columnAnnotation);
- if (field.isID()) {
- // Add SeriesID = 0 annotation to ID field.
- Annotation banyanSeriesIDAnnotation = new Annotation(BanyanDB.SeriesID.class.getName(), constPool);
- banyanSeriesIDAnnotation.addMemberValue("index", new IntegerMemberValue(constPool, 0));
- annotationsAttribute.addAnnotation(banyanSeriesIDAnnotation);
-
- // Entity id field should enable doc values.
- final var enableDocValuesAnnotation = new Annotation(ElasticSearch.EnableDocValues.class.getName(), constPool);
- annotationsAttribute.addAnnotation(enableDocValuesAnnotation);
- }
- if (field.isShardingKey()) {
- Annotation banyanShardingKeyAnnotation = new Annotation(BanyanDB.ShardingKey.class.getName(), constPool);
- banyanShardingKeyAnnotation.addMemberValue("index", new IntegerMemberValue(constPool, field.getShardingKeyIdx()));
- annotationsAttribute.addAnnotation(banyanShardingKeyAnnotation);
- }
-
- newField.getFieldInfo().addAttribute(annotationsAttribute);
- } catch (CannotCompileException e) {
- log.error(
- "Can't add field(including set/get) " + field.getFieldName() + " in " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
- }
-
- /**
- * Generate methods
- */
- for (String method : METRICS_CLASS_METHODS) {
- StringWriter methodEntity = new StringWriter();
- try {
- configuration.getTemplate("metrics/" + method + ".ftl").process(metricsStmt, methodEntity);
- metricsClass.addMethod(CtNewMethod.make(methodEntity.toString(), metricsClass));
- } catch (Exception e) {
- log.error("Can't generate method " + method + " for " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
- }
-
- /**
- * Add following annotation to the metrics class
- *
- * at Stream(name = "${tableName}", scopeId = ${sourceScopeId}, builder = ${metricsName}Metrics.Builder.class, processor = MetricsStreamProcessor.class)
- */
- AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(
- constPool, AnnotationsAttribute.visibleTag);
- Annotation streamAnnotation = new Annotation(Stream.class.getName(), constPool);
- streamAnnotation.addMemberValue("name", new StringMemberValue(metricsStmt.getTableName(), constPool));
- streamAnnotation.addMemberValue(
- "scopeId", new IntegerMemberValue(constPool, metricsStmt.getFrom().getSourceScopeId()));
- streamAnnotation.addMemberValue(
- "builder", new ClassMemberValue(metricsBuilderClassName(metricsStmt, true), constPool));
- streamAnnotation.addMemberValue("processor", new ClassMemberValue(METRICS_STREAM_PROCESSOR, constPool));
-
- annotationsAttribute.addAnnotation(streamAnnotation);
- metricsClassClassFile.addAttribute(annotationsAttribute);
-
- Class targetClass;
- try {
- if (SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_8)) {
- targetClass = metricsClass.toClass(currentClassLoader, null);
- } else {
- targetClass = metricsClass.toClass(MetricClassPackageHolder.class);
- }
- } catch (CannotCompileException e) {
- log.error("Can't compile/load " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
-
- log.debug("Generate metrics class, " + metricsClass.getName());
- writeGeneratedFile(metricsClass, "metrics");
- writeSourceFile(metricsStmt, "metrics");
-
- return targetClass;
- }
-
- /**
- * Generate metrics class builder and inject it to classloader
- */
- private void generateMetricsBuilderClass(AnalysisResult metricsStmt) throws OALCompileException {
- String className = metricsBuilderClassName(metricsStmt, false);
- CtClass metricsBuilderClass = classPool.makeClass(metricsBuilderClassName(metricsStmt, true));
- try {
- metricsBuilderClass.addInterface(classPool.get(storageBuilderFactory.builderTemplate().getSuperClass()));
- } catch (NotFoundException e) {
- log.error("Can't find StorageBuilder interface for " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
-
- /**
- * Create empty construct
- */
- try {
- CtConstructor defaultConstructor = CtNewConstructor.make(
- "public " + className + "() {}", metricsBuilderClass);
- metricsBuilderClass.addConstructor(defaultConstructor);
- } catch (CannotCompileException e) {
- log.error("Can't add empty constructor in " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
-
- /**
- * Generate methods
- */
- for (String method : METRICS_BUILDER_CLASS_METHODS) {
- StringWriter methodEntity = new StringWriter();
- try {
- configuration
- .getTemplate(storageBuilderFactory.builderTemplate().getTemplatePath() + "/" + method + ".ftl")
- .process(metricsStmt, methodEntity);
- metricsBuilderClass.addMethod(CtNewMethod.make(methodEntity.toString(), metricsBuilderClass));
- } catch (Exception e) {
- log.error("Can't generate method " + method + " for " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
- }
-
- try {
- if (SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_8)) {
- metricsBuilderClass.toClass(currentClassLoader, null);
- } else {
- metricsBuilderClass.toClass(MetricBuilderClassPackageHolder.class);
- }
- } catch (CannotCompileException e) {
- log.error("Can't compile/load " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
-
- writeGeneratedFile(metricsBuilderClass, "metrics/builder");
- }
-
- /**
- * Generate SourceDispatcher class and inject it to classloader
- */
- private Class generateDispatcherClass(String scopeName,
- DispatcherContext dispatcherContext) throws OALCompileException {
-
- String className = dispatcherClassName(scopeName, false);
- CtClass dispatcherClass = classPool.makeClass(dispatcherClassName(scopeName, true));
- try {
- CtClass dispatcherInterface = classPool.get(DISPATCHER_INTERFACE);
-
- dispatcherClass.addInterface(dispatcherInterface);
-
- /**
- * Set generic signature
- */
- String sourceClassName = oalDefine.getSourcePackage() + dispatcherContext.getSource();
- SignatureAttribute.ClassSignature dispatcherSignature =
- new SignatureAttribute.ClassSignature(
- null, null,
- // Set interface and its generic params
- new SignatureAttribute.ClassType[] {
- new SignatureAttribute.ClassType(
- SourceDispatcher.class
- .getCanonicalName(),
- new SignatureAttribute.TypeArgument[] {
- new SignatureAttribute.TypeArgument(
- new SignatureAttribute.ClassType(
- sourceClassName))
- }
- )
- }
- );
-
- dispatcherClass.setGenericSignature(dispatcherSignature.encode());
- } catch (NotFoundException e) {
- log.error("Can't find Dispatcher interface for " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
-
- /**
- * Generate methods
- */
- for (AnalysisResult dispatcherContextMetric : dispatcherContext.getMetrics()) {
- StringWriter methodEntity = new StringWriter();
- try {
- configuration.getTemplate("dispatcher/doMetrics.ftl").process(dispatcherContextMetric, methodEntity);
- dispatcherClass.addMethod(CtNewMethod.make(methodEntity.toString(), dispatcherClass));
- } catch (Exception e) {
- log.error(
- "Can't generate method do" + dispatcherContextMetric.getMetricsName() + " for " + className + ".",
- e
- );
- log.error("Method body as following" + System.lineSeparator() + "{}", methodEntity);
- throw new OALCompileException(e.getMessage(), e);
- }
- }
-
- try {
- StringWriter methodEntity = new StringWriter();
- configuration.getTemplate("dispatcher/dispatch.ftl").process(dispatcherContext, methodEntity);
- dispatcherClass.addMethod(CtNewMethod.make(methodEntity.toString(), dispatcherClass));
- } catch (Exception e) {
- log.error("Can't generate method dispatch for " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
-
- Class targetClass;
- try {
- if (SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_8)) {
- targetClass = dispatcherClass.toClass(currentClassLoader, null);
- } else {
- targetClass = dispatcherClass.toClass(DispatcherClassPackageHolder.class);
- }
- } catch (CannotCompileException e) {
- log.error("Can't compile/load " + className + ".", e);
- throw new OALCompileException(e.getMessage(), e);
- }
-
- writeGeneratedFile(dispatcherClass, "dispatcher");
- return targetClass;
- }
-
- private String metricsClassName(AnalysisResult metricsStmt, boolean fullName) {
- return (fullName ? oalDefine.getDynamicMetricsClassPackage() : "") + metricsStmt.getMetricsName() + "Metrics";
- }
-
- private String metricsBuilderClassName(AnalysisResult metricsStmt, boolean fullName) {
- return (fullName ? oalDefine.getDynamicMetricsBuilderClassPackage() : "") + metricsStmt.getMetricsName() + "MetricsBuilder";
- }
-
- private String dispatcherClassName(String scopeName, boolean fullName) {
- return (fullName ? oalDefine.getDynamicDispatcherClassPackage() : "") + scopeName + "Dispatcher";
- }
-
- private void buildDispatcherContext(AnalysisResult metricsStmt) {
- String sourceName = metricsStmt.getFrom().getSourceName();
-
- DispatcherContext context = allDispatcherContext.getAllContext().computeIfAbsent(sourceName, name -> {
- DispatcherContext absent = new DispatcherContext();
- absent.setSourcePackage(oalDefine.getSourcePackage());
- absent.setSource(name);
- absent.setPackageName(name.toLowerCase());
- absent.setSourceDecorator(metricsStmt.getSourceDecorator());
- return absent;
- });
- metricsStmt.setMetricsClassPackage(oalDefine.getDynamicMetricsClassPackage());
- metricsStmt.setSourcePackage(oalDefine.getSourcePackage());
- context.getMetrics().add(metricsStmt);
- }
-
- public void prepareRTTempFolder() {
- if (openEngineDebug) {
- File workPath = WorkPath.getPath();
- File folder = new File(workPath.getParentFile(), "oal-rt/");
- if (folder.exists()) {
- try {
- FileUtils.deleteDirectory(folder);
- } catch (IOException e) {
- log.warn("Can't delete " + folder.getAbsolutePath() + " temp folder.", e);
- }
- }
- folder.mkdirs();
- }
- }
-
- private void writeGeneratedFile(CtClass metricsClass, String type) throws OALCompileException {
- if (openEngineDebug) {
- String className = metricsClass.getSimpleName();
- DataOutputStream printWriter = null;
- try {
- File folder = new File(getGeneratedFilePath() + File.separator + type);
- if (!folder.exists()) {
- folder.mkdirs();
- }
- File file = new File(folder, className + ".class");
- if (file.exists()) {
- file.delete();
- }
- file.createNewFile();
-
- printWriter = new DataOutputStream(new FileOutputStream(file));
- metricsClass.toBytecode(printWriter);
- printWriter.flush();
- } catch (IOException e) {
- log.warn("Can't create " + className + ".txt, ignore.", e);
- return;
- } catch (CannotCompileException e) {
- log.warn("Can't compile " + className + ".class(should not happen), ignore.", e);
- return;
- } finally {
- if (printWriter != null) {
- try {
- printWriter.close();
- } catch (IOException e) {
-
- }
- }
- }
- }
- }
-
- public void setCurrentClassLoader(ClassLoader currentClassLoader) {
- this.currentClassLoader = currentClassLoader;
- }
-
- public void setStorageBuilderFactory(StorageBuilderFactory storageBuilderFactory) {
- this.storageBuilderFactory = storageBuilderFactory;
- }
-
- public static void setGeneratedFilePath(String generatedFilePath) {
- GENERATED_FILE_PATH = generatedFilePath;
- }
-
- public static String getGeneratedFilePath() {
- if (GENERATED_FILE_PATH == null) {
- return String.valueOf(new File(WorkPath.getPath().getParentFile(), "oal-rt/"));
- }
- return GENERATED_FILE_PATH;
- }
-
- public OALDefine getOalDefine() {
- return oalDefine;
- }
-
- public void setOpenEngineDebug(boolean debug) {
- this.openEngineDebug = debug;
- }
-
- /**
- * Generate complete Java source code for a metrics class (V1).
- * This is useful for comparing V1 vs V2 generated code.
- *
- * @param metricsStmt The V1 analysis result
- * @return Complete Java source code as a string
- */
- public String generateMetricsClassSourceCode(AnalysisResult metricsStmt) throws OALCompileException {
- StringBuilder source = new StringBuilder();
-
- // Package declaration
- source.append("package ").append(oalDefine.getDynamicMetricsClassPackage()).append(";\n\n");
-
- // Imports
- source.append("import org.apache.skywalking.oap.server.core.analysis.Stream;\n");
- source.append("import org.apache.skywalking.oap.server.core.analysis.metrics.WithMetadata;\n");
- source.append("import org.apache.skywalking.oap.server.core.analysis.metrics.").append(metricsStmt.getMetricsClassName()).append(";\n");
- source.append("import org.apache.skywalking.oap.server.core.storage.annotation.*;\n");
- source.append("import lombok.Getter;\n");
- source.append("import lombok.Setter;\n\n");
-
- // Class-level @Stream annotation
- source.append("@Stream(\n");
- source.append(" name = \"").append(metricsStmt.getTableName()).append("\",\n");
- source.append(" scopeId = ").append(metricsStmt.getFrom().getSourceScopeId()).append(",\n");
- source.append(" builder = ").append(metricsBuilderClassName(metricsStmt, false)).append(".class,\n");
- source.append(" processor = ").append(METRICS_STREAM_PROCESSOR).append(".class\n");
- source.append(")\n");
-
- // Class declaration
- String className = metricsClassName(metricsStmt, false);
- source.append("public class ").append(className)
- .append(" extends ").append(metricsStmt.getMetricsClassName())
- .append(" implements WithMetadata {\n\n");
-
- // Fields with annotations
- for (SourceColumn column : metricsStmt.getFieldsFromSource()) {
- source.append(" @Column(name = \"").append(column.getColumnName()).append("\"");
- if (column.getType().equals(String.class)) {
- source.append(", length = ").append(column.getLength());
- }
- source.append(")\n");
-
- if (column.isID()) {
- source.append(" @BanyanDB.SeriesID(index = 0)\n");
- source.append(" @ElasticSearch.EnableDocValues\n");
- }
-
- if (column.isShardingKey()) {
- source.append(" @BanyanDB.ShardingKey(index = ").append(column.getShardingKeyIdx()).append(")\n");
- }
-
- source.append(" @Getter @Setter\n");
- source.append(" private ").append(column.getType().getSimpleName())
- .append(" ").append(column.getFieldName()).append(";\n\n");
- }
-
- // Constructor
- source.append(" public ").append(className).append("() {\n");
- source.append(" }\n\n");
-
- // Methods from templates
- for (String method : METRICS_CLASS_METHODS) {
- StringWriter methodEntity = new StringWriter();
- try {
- configuration.getTemplate("metrics/" + method + ".ftl").process(metricsStmt, methodEntity);
- source.append(" ").append(methodEntity.toString()).append("\n\n");
- } catch (Exception e) {
- log.error("Can't generate method " + method + " for V1 source code.", e);
- throw new OALCompileException(e.getMessage(), e);
- }
- }
-
- source.append("}\n");
-
- return source.toString();
- }
-
- /**
- * Write complete Java source file to disk for comparison (V1).
- */
- private void writeSourceFile(AnalysisResult metricsStmt, String type) throws OALCompileException {
- if (openEngineDebug) {
- String className = metricsClassName(metricsStmt, false);
- try {
- File folder = new File(getGeneratedFilePath() + File.separator + type + "-source");
- if (!folder.exists()) {
- folder.mkdirs();
- }
- File file = new File(folder, className + ".java");
- if (file.exists()) {
- file.delete();
- }
-
- String sourceCode = generateMetricsClassSourceCode(metricsStmt);
- FileUtils.writeStringToFile(file, sourceCode, CLASS_FILE_CHARSET);
-
- log.debug("Wrote V1 source file: " + file.getAbsolutePath());
- } catch (IOException e) {
- log.warn("Can't write V1 source file for " + className + ", ignore.", e);
- }
- }
- }
-
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/util/TypeCastUtil.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/util/TypeCastUtil.java
deleted file mode 100644
index 479502b604..0000000000
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/util/TypeCastUtil.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.rt.util;
-
-public class TypeCastUtil {
- /**
- * @param castType to change the value of given original expression.
- * @param originalExpression to read the value
- * @return cast expression if cast type exists and is legal.
- */
- public static String withCast(String castType, String originalExpression) {
- if (castType == null) {
- return originalExpression;
- }
- switch (castType) {
- case "(str->long)":
- case "(long)":
- return "Long.parseLong(" + originalExpression + ")";
- case "(str->int)":
- case "(int)":
- return "Integer.parseInt(" + originalExpression + ")";
- default:
- throw new IllegalArgumentException(
- "castType:" + castType + " is legal, context expression:" + originalExpression);
- }
- }
-}
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/v2/generator/CodeGenModel.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/v2/generator/CodeGenModel.java
index 1c0fdf26fb..080775b668 100644
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/v2/generator/CodeGenModel.java
+++ b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/v2/generator/CodeGenModel.java
@@ -25,20 +25,39 @@ import lombok.Getter;
import org.apache.skywalking.oal.v2.model.MetricDefinition;
/**
- * V2 code generation model.
+ * Code generation model for OAL metrics.
*
- * This model contains all information needed by Freemarker templates to generate
- * metrics classes, builders, and dispatchers.
+ * <p>This model contains all information needed by FreeMarker templates to generate
+ * metrics classes, builders, and dispatchers at runtime.
*
- * Unlike V1's AnalysisResult, this model is built directly from V2's MetricDefinition
- * without any V1 dependency.
+ * <p>Built from {@link MetricDefinition} via {@link MetricDefinitionEnricher}, this model
+ * provides template-ready data structures with precomputed method names, type information,
+ * and serialization metadata.
+ *
+ * <p>Example OAL input:
+ * <pre>
+ * service_resp_time = from(Service.latency).longAvg();
+ * </pre>
+ *
+ * <p>Produces a CodeGenModel with:
+ * <ul>
+ * <li>varName = "service_resp_time"</li>
+ * <li>metricsName = "ServiceRespTime"</li>
+ * <li>tableName = "service_resp_time"</li>
+ * <li>sourceName = "Service"</li>
+ * <li>functionName = "longAvg"</li>
+ * <li>metricsClassName = "LongAvgMetrics"</li>
+ * </ul>
+ *
+ * @see MetricDefinitionEnricher
+ * @see OALClassGeneratorV2
*/
@Getter
@Builder
public class CodeGenModel {
/**
- * Original V2 metric definition.
+ * Original parsed metric definition from OAL script.
*/
private MetricDefinition metricDefinition;
@@ -84,8 +103,8 @@ public class CodeGenModel {
private int sourceScopeId;
/**
- * V1-compatible "from" structure for templates.
- * Templates reference ${from.sourceScopeId}.
+ * Source statement for templates.
+ * Templates reference {@code ${from.sourceScopeId}}.
*/
private FromStmtV2 from;
@@ -102,8 +121,8 @@ public class CodeGenModel {
private String metricsClassName;
/**
- * V1-compatible wrapper for filter expressions.
- * Templates use ${filters.filterExpressions}.
+ * Filter expressions wrapper for templates.
+ * Templates access via {@code ${filters.filterExpressions}}.
*/
private FiltersV2 filters;
@@ -132,8 +151,8 @@ public class CodeGenModel {
private SerializeFieldsV2 serializeFields;
/**
- * Entrance method information.
- * Also exposed as 'entryMethod' for V1 template compatibility.
+ * Entrance method information for dispatcher code generation.
+ * Contains method name, argument expressions, and argument types.
*/
private EntranceMethodV2 entranceMethod;
@@ -143,14 +162,23 @@ public class CodeGenModel {
private String sourceDecorator;
/**
- * V1-compatible getter for entryMethod (alias for entranceMethod).
+ * Alias getter for entranceMethod.
+ * Templates may reference {@code ${entryMethod.methodName}}.
+ *
+ * @return the entrance method information
*/
public EntranceMethodV2 getEntryMethod() {
return entranceMethod;
}
/**
- * Source field for code generation templates.
+ * Source field extracted from a source class (e.g., Service, Endpoint).
+ *
+ * <p>These fields become columns in the generated metrics class and are used
+ * for entity identification (ID fields) and storage partitioning (sharding keys).
+ *
+ * <p>Example: For source "Service", fields include "entityId" (ID field)
+ * and "name" (regular field).
*/
@Getter
@Builder
@@ -165,18 +193,34 @@ public class CodeGenModel {
private int length;
private boolean attribute;
+ /**
+ * Returns getter method name for this field.
+ * Example: fieldName="entityId" returns "getEntityId"
+ *
+ * @return getter method name
+ */
public String getFieldGetter() {
return "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
}
+ /**
+ * Returns setter method name for this field.
+ * Example: fieldName="entityId" returns "setEntityId"
+ *
+ * @return setter method name
+ */
public String getFieldSetter() {
return "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
}
}
/**
- * Data field (persistent column from metrics function).
- * Compatible with V1's DataColumn structure.
+ * Data field representing a persistent column from the metrics function class.
+ *
+ * <p>These fields come from {@code @Column} annotations on the parent metrics class
+ * (e.g., LongAvgMetrics has "summation", "count", "value" fields).
+ *
+ * <p>Used for serialization/deserialization and storage operations.
*/
@Getter
@Builder
@@ -184,23 +228,50 @@ public class CodeGenModel {
private String fieldName;
private String columnName;
private Class<?> type;
- private String typeName; // V1 compatibility: string representation of type
+ private String typeName;
+ /**
+ * Returns getter method name for this field.
+ * Example: fieldName="summation" returns "getSummation"
+ *
+ * @return getter method name
+ */
public String getFieldGetter() {
return "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
}
+ /**
+ * Returns setter method name for this field.
+ * Example: fieldName="summation" returns "setSummation"
+ *
+ * @return setter method name
+ */
public String getFieldSetter() {
return "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
}
+ /**
+ * Returns fully qualified type name for this field.
+ *
+ * @return type name (e.g., "long", "java.lang.String")
+ */
public String getFieldType() {
return typeName != null ? typeName : (type != null ? type.getName() : "");
}
}
/**
- * Entrance method information for dispatcher.
+ * Entrance method information for dispatcher code generation.
+ *
+ * <p>The entrance method is the method annotated with {@code @Entrance} on the
+ * metrics function class. The dispatcher calls this method to process source data.
+ *
+ * <p>Argument types:
+ * <ul>
+ * <li>1 = LITERAL_TYPE - literal value (e.g., "1", "100")</li>
+ * <li>2 = ATTRIBUTE_EXP_TYPE - source attribute expression (e.g., "source.getLatency()")</li>
+ * <li>3 = EXPRESSION_TYPE - filter expression object with matcher</li>
+ * </ul>
*/
@Getter
@Builder
@@ -213,8 +284,11 @@ public class CodeGenModel {
}
/**
- * Serialization fields model for templates.
- * Compatible with V1's PersistenceColumns structure.
+ * Serialization fields grouped by type for template-based code generation.
+ *
+ * <p>Used by serialize/deserialize templates to generate type-specific
+ * serialization code. Fields are grouped by primitive type to enable
+ * efficient batch processing in generated code.
*/
@Getter
@Builder
@@ -252,8 +326,10 @@ public class CodeGenModel {
}
/**
- * Persistence field compatible with V1's PersistenceField.
- * Provides getter/setter method names for templates.
+ * Persistence field with precomputed getter/setter method names.
+ *
+ * <p>Provides the field name, type, and accessor method names needed
+ * by serialization templates to generate accessor code.
*/
@Getter
public static class PersistenceFieldV2 {
@@ -272,29 +348,49 @@ public class CodeGenModel {
/**
- * Filter expression model for templates.
+ * Filter expression for dispatcher code generation.
+ *
+ * <p>Represents a filter condition from OAL like {@code filter(status == 200)}.
+ * Contains the matcher class and operand expressions.
+ *
+ * <p>Example for {@code filter(status == 200)}:
+ * <ul>
+ * <li>expressionObject = "org.apache.skywalking.oap...EqualMatch"</li>
+ * <li>left = "source.getStatus()"</li>
+ * <li>right = "200"</li>
+ * </ul>
*/
@Getter
@Builder
public static class FilterExpressionV2 {
+ /** Fully qualified matcher class name. */
private String expressionObject;
+ /** Left operand expression (usually source getter). */
private String left;
+ /** Right operand expression (literal or source getter). */
private String right;
}
/**
- * V1-compatible "from" statement for templates.
+ * Source (from) statement information.
+ *
+ * <p>Contains the source class name and scope ID from the OAL "from" clause.
+ * Templates access via {@code ${from.sourceName}} and {@code ${from.sourceScopeId}}.
*/
@Getter
@Builder
public static class FromStmtV2 {
+ /** Source class name (e.g., "Service", "Endpoint"). */
private String sourceName;
+ /** Scope ID for this source type. */
private int sourceScopeId;
}
/**
- * V1-compatible "filters" wrapper for templates.
- * Templates access ${filters.filterExpressions}.
+ * Filter expressions wrapper for template access.
+ *
+ * <p>Wraps the list of filter expressions for template iteration.
+ * Templates access via {@code ${filters.filterExpressions}}.
*/
@Getter
@Builder
diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/v2/generator/MetricDefinitionEnricher.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/v2/generator/MetricDefinitionEnricher.java
index 69abfbbdb5..4c18544630 100644
--- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/v2/generator/MetricDefinitionEnricher.java
+++ b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/v2/generator/MetricDefinitionEnricher.java
@@ -47,17 +47,34 @@ import org.apache.skywalking.oap.server.core.storage.annotation.Column;
import org.apache.skywalking.oap.server.core.storage.type.StorageDataComplexObject;
/**
- * Enriches V2 MetricDefinition with metadata needed for code generation.
+ * Enriches MetricDefinition with metadata needed for code generation.
*
- * This is V2's equivalent of V1's DeepAnalysis. It:
- * 1. Looks up metrics function class
- * 2. Extracts source columns/fields
- * 3. Finds entrance method
- * 4. Builds entrance method arguments
- * 5. Collects persistent fields from @Column annotations
- * 6. Generates serialization fields
+ * <p>This enricher transforms a parsed {@link MetricDefinition} into a complete
+ * {@link CodeGenModel} by:
+ * <ol>
+ * <li>Looking up the metrics function class (e.g., LongAvgMetrics)</li>
+ * <li>Extracting source columns/fields from the source class</li>
+ * <li>Finding the entrance method annotated with {@code @Entrance}</li>
+ * <li>Building entrance method arguments with type casts and expressions</li>
+ * <li>Collecting persistent fields from {@code @Column} annotations</li>
+ * <li>Generating serialization field lists grouped by type</li>
+ * </ol>
*
- * Unlike V1, this works entirely with V2 models and has no V1 dependencies.
+ * <p>Example input (MetricDefinition from OAL):
+ * <pre>
+ * service_resp_time = from(Service.latency).longAvg();
+ * </pre>
+ *
+ * <p>Example output (CodeGenModel):
+ * <ul>
+ * <li>metricsClassName = "LongAvgMetrics"</li>
+ * <li>entranceMethod.methodName = "combine"</li>
+ * <li>fieldsFromSource = [entityId, name, ...]</li>
+ * <li>persistentFields = [summation, count, value]</li>
+ * </ul>
+ *
+ * @see CodeGenModel
+ * @see OALClassGeneratorV2
*/
@Slf4j
public class MetricDefinitionEnricher {
@@ -73,8 +90,8 @@ public class MetricDefinitionEnricher {
/**
* Enrich a MetricDefinition with metadata for code generation.
*
- * @param metric V2 metric definition
- * @return enriched code generation model
+ * @param metric parsed metric definition from OAL script
+ * @return enriched code generation model ready for template processing
*/
public CodeGenModel enrich(MetricDefinition metric) {
// 1. Look up metrics function class
@@ -130,7 +147,10 @@ public class MetricDefinitionEnricher {
}
/**
- * Convert V1 SourceColumn to V2 SourceFieldV2.
+ * Convert SourceColumn metadata to SourceFieldV2 for code generation.
+ *
+ * @param sourceColumns source columns extracted from the source class
+ * @return list of source fields ready for template processing
*/
private List<CodeGenModel.SourceFieldV2> convertSourceColumns(List<SourceColumn> sourceColumns) {
List<CodeGenModel.SourceFieldV2> fields = new ArrayList<>();
@@ -284,7 +304,7 @@ public class MetricDefinitionEnricher {
* Get matcher class name from filter expression.
*/
private String getMatcherClassName(FilterExpression filterExpr) {
- String expressionType = mapV2OperatorToV1ExpressionType(filterExpr);
+ String expressionType = mapOperatorToExpressionType(filterExpr);
FilterMatchers.MatcherInfo matcherInfo = FilterMatchers.INSTANCE.find(expressionType);
return matcherInfo.getMatcher().getName();
}
@@ -294,7 +314,7 @@ public class MetricDefinitionEnricher {
*/
private String buildFilterLeft(FilterExpression filterExpr) {
FilterMatchers.MatcherInfo matcherInfo = FilterMatchers.INSTANCE.find(
- mapV2OperatorToV1ExpressionType(filterExpr));
+ mapOperatorToExpressionType(filterExpr));
String getter = matcherInfo.isBooleanType()
? ClassMethodUtil.toIsMethod(filterExpr.getFieldName())
: ClassMethodUtil.toGetMethod(filterExpr.getFieldName());
@@ -332,9 +352,15 @@ public class MetricDefinitionEnricher {
}
/**
- * Map V2 operator + value type to V1 expression type string.
+ * Map filter operator and value type to matcher expression type.
+ *
+ * <p>The expression type string is used to look up the appropriate matcher class
+ * from {@link FilterMatchers}.
+ *
+ * @param filterExpr filter expression containing operator and value
+ * @return matcher type string (e.g., "stringMatch", "greaterMatch")
*/
- private String mapV2OperatorToV1ExpressionType(FilterExpression filterExpr) {
+ private String mapOperatorToExpressionType(FilterExpression filterExpr) {
FilterOperator op = filterExpr.getOperator();
FilterValue value = filterExpr.getValue();
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/dispatcher/dispatch.ftl b/oap-server/oal-rt/src/main/resources/code-templates/dispatcher/dispatch.ftl
deleted file mode 100644
index e9d16cb167..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/dispatcher/dispatch.ftl
+++ /dev/null
@@ -1,6 +0,0 @@
-public void dispatch(org.apache.skywalking.oap.server.core.source.ISource source) {
-${sourcePackage}${source} _source = (${sourcePackage}${source})source;
-<#list metrics as metrics>
- do${metrics.metricsName}(_source);
-</#list>
-}
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/dispatcher/doMetrics.ftl b/oap-server/oal-rt/src/main/resources/code-templates/dispatcher/doMetrics.ftl
deleted file mode 100644
index 5d82d00197..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/dispatcher/doMetrics.ftl
+++ /dev/null
@@ -1,33 +0,0 @@
-private void do${metricsName}(${sourcePackage}${from.sourceName} source) {
-
-<#if filters.filterExpressions??>
- <#list filters.filterExpressions as filterExpression>
- if (!new ${filterExpression.expressionObject}().match(${filterExpression.left}, ${filterExpression.right})) {
- return;
- }
- </#list>
-</#if>
-
-${metricsClassPackage}${metricsName}Metrics metrics = new ${metricsClassPackage}${metricsName}Metrics();
-<#if sourceDecorator??>
- source.decorate("${sourceDecorator}");
-</#if>
-metrics.setTimeBucket(source.getTimeBucket());
-<#list fieldsFromSource as field>
- <#if field.attribute && !sourceDecorator??>
- <#--Metrics share the source instance, do not process attributes unless added decorator func-->
- <#else>
- metrics.${field.fieldSetter}(source.${field.fieldGetter}());
- </#if>
-</#list>
-metrics.${entryMethod.methodName}(
-<#list entryMethod.argsExpressions as arg>
- <#if entryMethod.argTypes[arg_index] < 3>
- ${arg}
- <#else>
- new ${arg.expressionObject}().match(${arg.left}, ${arg.right})
- </#if><#if arg_has_next>, </#if>
-</#list>);
-
-org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor.getInstance().in(metrics);
-}
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/metrics-builder/entity2Storage.ftl b/oap-server/oal-rt/src/main/resources/code-templates/metrics-builder/entity2Storage.ftl
deleted file mode 100644
index caaf896209..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/metrics-builder/entity2Storage.ftl
+++ /dev/null
@@ -1,29 +0,0 @@
-public void entity2Storage(org.apache.skywalking.oap.server.core.storage.StorageData input, org.apache.skywalking.oap.server.core.storage.type.Convert2Storage converter) {
-${metricsClassPackage}${metricsName}Metrics storageData = (${metricsClassPackage}${metricsName}Metrics)input;
-<#list fieldsFromSource as field>
- <#if field.typeName == "long">
- converter.accept("${field.columnName}", new Long(storageData.${field.fieldGetter}()));
- <#elseif field.typeName == "int">
- converter.accept("${field.columnName}", new Integer(storageData.${field.fieldGetter}()));
- <#elseif field.typeName == "double">
- converter.accept("${field.columnName}", new Double(storageData.${field.fieldGetter}()));
- <#elseif field.typeName == "float">
- converter.accept("${field.columnName}", new Float(storageData.${field.fieldGetter}()));
- <#else>
- converter.accept("${field.columnName}", storageData.${field.fieldGetter}());
- </#if>
-</#list>
-<#list persistentFields as field>
- <#if field.typeName == "long">
- converter.accept("${field.columnName}", new Long(storageData.${field.fieldGetter}()));
- <#elseif field.typeName == "int">
- converter.accept("${field.columnName}", new Integer(storageData.${field.fieldGetter}()));
- <#elseif field.typeName == "double">
- converter.accept("${field.columnName}", new Double(storageData.${field.fieldGetter}()));
- <#elseif field.typeName == "float">
- converter.accept("${field.columnName}", new Float(storageData.${field.fieldGetter}()));
- <#else>
- converter.accept("${field.columnName}", storageData.${field.fieldGetter}());
- </#if>
-</#list>
-}
\ No newline at end of file
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/metrics-builder/storage2Entity.ftl b/oap-server/oal-rt/src/main/resources/code-templates/metrics-builder/storage2Entity.ftl
deleted file mode 100644
index bbf56f96e5..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/metrics-builder/storage2Entity.ftl
+++ /dev/null
@@ -1,22 +0,0 @@
-public org.apache.skywalking.oap.server.core.storage.StorageData storage2Entity( org.apache.skywalking.oap.server.core.storage.type.Convert2Entity converter) {
-${metricsClassPackage}${metricsName}Metrics metrics = new ${metricsClassPackage}${metricsName}Metrics();
-<#list fieldsFromSource as field>
- <#if field.typeName == "long" || field.typeName == "int" || field.typeName == "double" || field.typeName == "float">
- metrics.${field.fieldSetter}(((Number)converter.get("${field.columnName}")).${field.typeName}Value());
- <#elseif field.typeName == "java.lang.String">
- metrics.${field.fieldSetter}((String)converter.get("${field.columnName}"));
- <#else>
- metrics.${field.fieldSetter}(new ${field.typeName}((String)converter.get("${field.columnName}")));
- </#if>
-</#list>
-<#list persistentFields as field>
- <#if field.typeName == "long" || field.typeName == "int" || field.typeName == "double" || field.typeName == "float">
- metrics.${field.fieldSetter}(((Number)converter.get("${field.columnName}")).${field.typeName}Value());
- <#elseif field.typeName == "java.lang.String">
- metrics.${field.fieldSetter}((String)converter.get("${field.columnName}"));
- <#else>
- metrics.${field.fieldSetter}(new ${field.typeName}((String)converter.get("${field.columnName}")));
- </#if>
-</#list>
-return metrics;
-}
\ No newline at end of file
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/metrics/deserialize.ftl b/oap-server/oal-rt/src/main/resources/code-templates/metrics/deserialize.ftl
deleted file mode 100644
index 8063915f8d..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/metrics/deserialize.ftl
+++ /dev/null
@@ -1,24 +0,0 @@
-public void deserialize(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData remoteData) {
-<#list serializeFields.stringFields as field>
- if (remoteData.getDataStrings(${field?index}) != "") {
- ${field.setter}(remoteData.getDataStrings(${field?index}));
- }
-</#list>
-
-<#list serializeFields.longFields as field>
- ${field.setter}(remoteData.getDataLongs(${field?index}));
-</#list>
-
-<#list serializeFields.doubleFields as field>
- ${field.setter}(remoteData.getDataDoubles(${field?index}));
-</#list>
-
-<#list serializeFields.intFields as field>
- ${field.setter}(remoteData.getDataIntegers(${field?index}));
-</#list>
-
-<#list serializeFields.objectFields as field>
- ${field.setter}(new ${field.fieldType}(remoteData.getDataObjectStrings(${field?index})));
-</#list>
-
-}
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/metrics/equals.ftl b/oap-server/oal-rt/src/main/resources/code-templates/metrics/equals.ftl
deleted file mode 100644
index a094af8e80..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/metrics/equals.ftl
+++ /dev/null
@@ -1,25 +0,0 @@
-public boolean equals(Object obj) {
-if (this == obj)
-return true;
-if (obj == null)
-return false;
-if (getClass() != obj.getClass())
-return false;
-
-${metricsClassPackage}${metricsName}Metrics metrics = (${metricsClassPackage}${metricsName}Metrics)obj;
-<#list fieldsFromSource as sourceField>
- <#if sourceField.isID()>
- <#if sourceField.getTypeName() == "java.lang.String">
- if (!${sourceField.fieldName}.equals(metrics.${sourceField.fieldName}))
- <#else>
- if (${sourceField.fieldName} != metrics.${sourceField.fieldName})
- </#if>
- return false;
- </#if>
-</#list>
-
-if (getTimeBucket() != metrics.getTimeBucket())
-return false;
-
-return true;
-}
\ No newline at end of file
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/metrics/getMeta.ftl b/oap-server/oal-rt/src/main/resources/code-templates/metrics/getMeta.ftl
deleted file mode 100644
index 909d8c5076..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/metrics/getMeta.ftl
+++ /dev/null
@@ -1,3 +0,0 @@
-public org.apache.skywalking.oap.server.core.analysis.metrics.MetricsMetaInfo getMeta() {
-return new org.apache.skywalking.oap.server.core.analysis.metrics.MetricsMetaInfo("${varName}", ${from.sourceScopeId?c}<#if (fieldsFromSource?size>0) ><#list fieldsFromSource as field><#if field.isID()>, ${field.fieldName}</#if></#list></#if>);
-}
\ No newline at end of file
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/metrics/hashCode.ftl b/oap-server/oal-rt/src/main/resources/code-templates/metrics/hashCode.ftl
deleted file mode 100644
index bd5889cb1c..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/metrics/hashCode.ftl
+++ /dev/null
@@ -1,14 +0,0 @@
-public int hashCode() {
-int result = 17;
-<#list fieldsFromSource as sourceField>
- <#if sourceField.isID()>
- <#if sourceField.getTypeName() == "java.lang.String">
- result = 31 * result + ${sourceField.fieldName}.hashCode();
- <#else>
- result = 31 * result + ${sourceField.fieldName};
- </#if>
- </#if>
-</#list>
-result = 31 * result + (int)getTimeBucket();
-return result;
-}
\ No newline at end of file
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/metrics/id.ftl b/oap-server/oal-rt/src/main/resources/code-templates/metrics/id.ftl
deleted file mode 100644
index 55cb3c87a7..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/metrics/id.ftl
+++ /dev/null
@@ -1,9 +0,0 @@
-protected org.apache.skywalking.oap.server.core.storage.StorageID id0() {
-org.apache.skywalking.oap.server.core.storage.StorageID id = new org.apache.skywalking.oap.server.core.storage.StorageID().append(TIME_BUCKET, getTimeBucket());
-<#list fieldsFromSource as sourceField>
- <#if sourceField.isID()>
- id.append("${sourceField.columnName}", ${sourceField.fieldName});
- </#if>
-</#list>
-return id;
-}
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/metrics/remoteHashCode.ftl b/oap-server/oal-rt/src/main/resources/code-templates/metrics/remoteHashCode.ftl
deleted file mode 100644
index 0e3a944c3d..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/metrics/remoteHashCode.ftl
+++ /dev/null
@@ -1,13 +0,0 @@
-public int remoteHashCode() {
-int result = 17;
-<#list fieldsFromSource as sourceField>
- <#if sourceField.isID()>
- <#if sourceField.getTypeName() == "java.lang.String">
- result = 31 * result + ${sourceField.fieldName}.hashCode();
- <#else>
- result = 31 * result + ${sourceField.fieldName};
- </#if>
- </#if>
-</#list>
-return result;
-}
\ No newline at end of file
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/metrics/serialize.ftl b/oap-server/oal-rt/src/main/resources/code-templates/metrics/serialize.ftl
deleted file mode 100644
index 0fd9fdcd22..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/metrics/serialize.ftl
+++ /dev/null
@@ -1,24 +0,0 @@
-public org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData.Builder serialize() {
-org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData.Builder remoteBuilder = org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData.newBuilder();
-<#list serializeFields.stringFields as field>
- remoteBuilder.addDataStrings(${field.getter}() == null ? "" : ${field.getter}());
-</#list>
-
-<#list serializeFields.longFields as field>
- remoteBuilder.addDataLongs(${field.getter}());
-</#list>
-
-<#list serializeFields.doubleFields as field>
- remoteBuilder.addDataDoubles(${field.getter}());
-</#list>
-
-<#list serializeFields.intFields as field>
- remoteBuilder.addDataIntegers(${field.getter}());
-</#list>
-
-<#list serializeFields.objectFields as field>
- remoteBuilder.addDataObjectStrings(${field.getter}().toStorageData());
-</#list>
-
-return remoteBuilder;
-}
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/metrics/toDay.ftl b/oap-server/oal-rt/src/main/resources/code-templates/metrics/toDay.ftl
deleted file mode 100644
index e3c5bf9ddb..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/metrics/toDay.ftl
+++ /dev/null
@@ -1,26 +0,0 @@
-public org.apache.skywalking.oap.server.core.analysis.metrics.Metrics toDay() {
-${metricsClassPackage}${metricsName}Metrics metrics = new ${metricsClassPackage}${metricsName}Metrics();
-<#list fieldsFromSource as field>
- <#if field.columnName == "time_bucket">
- metrics.setTimeBucket(toTimeBucketInDay());
- <#elseif field.typeName == "java.lang.String" || field.typeName == "long" || field.typeName == "int" || field.typeName == "double" || field.typeName == "float">
- metrics.${field.fieldSetter}(this.${field.fieldGetter}());
- <#else>
- ${field.typeName} newValue = new ${field.typeName}();
- newValue.copyFrom(this.${field.fieldGetter}());
- metrics.${field.fieldSetter}(newValue);
- </#if>
-</#list>
-<#list persistentFields as field>
- <#if field.columnName == "time_bucket">
- metrics.setTimeBucket(toTimeBucketInDay());
- <#elseif field.typeName == "java.lang.String" || field.typeName == "long" || field.typeName == "int" || field.typeName == "double" || field.typeName == "float">
- metrics.${field.fieldSetter}(this.${field.fieldGetter}());
- <#else>
- ${field.typeName} newValue = new ${field.typeName}();
- newValue.copyFrom(this.${field.fieldGetter}());
- metrics.${field.fieldSetter}(newValue);
- </#if>
-</#list>
-return metrics;
-}
\ No newline at end of file
diff --git a/oap-server/oal-rt/src/main/resources/code-templates/metrics/toHour.ftl b/oap-server/oal-rt/src/main/resources/code-templates/metrics/toHour.ftl
deleted file mode 100644
index b0bddbd863..0000000000
--- a/oap-server/oal-rt/src/main/resources/code-templates/metrics/toHour.ftl
+++ /dev/null
@@ -1,26 +0,0 @@
-public org.apache.skywalking.oap.server.core.analysis.metrics.Metrics toHour() {
-${metricsClassPackage}${metricsName}Metrics metrics = new ${metricsClassPackage}${metricsName}Metrics();
-<#list fieldsFromSource as field>
- <#if field.columnName == "time_bucket">
- metrics.setTimeBucket(toTimeBucketInHour());
- <#elseif field.typeName == "java.lang.String" || field.typeName == "long" || field.typeName == "int" || field.typeName == "double" || field.typeName == "float">
- metrics.${field.fieldSetter}(this.${field.fieldGetter}());
- <#else>
- ${field.typeName} newValue = new ${field.typeName}();
- newValue.copyFrom(this.${field.fieldGetter}());
- metrics.${field.fieldSetter}(newValue);
- </#if>
-</#list>
-<#list persistentFields as field>
- <#if field.columnName == "time_bucket">
- metrics.setTimeBucket(toTimeBucketInHour());
- <#elseif field.typeName == "java.lang.String" || field.typeName == "long" || field.typeName == "int" || field.typeName == "double" || field.typeName == "float">
- metrics.${field.fieldSetter}(this.${field.fieldGetter}());
- <#else>
- ${field.typeName} newValue = new ${field.typeName}();
- newValue.copyFrom(this.${field.fieldGetter}());
- metrics.${field.fieldSetter}(newValue);
- </#if>
-</#list>
-return metrics;
-}
\ No newline at end of file
diff --git a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/AllOALScriptsComparisonTest.java b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/AllOALScriptsComparisonTest.java
deleted file mode 100644
index 78f94650e7..0000000000
--- a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/AllOALScriptsComparisonTest.java
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.v2.generator;
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.skywalking.oal.rt.parser.AnalysisResult;
-import org.apache.skywalking.oal.rt.parser.OALScripts;
-import org.apache.skywalking.oal.rt.parser.ScriptParser;
-import org.apache.skywalking.oal.v2.model.MetricDefinition;
-import org.apache.skywalking.oal.v2.parser.OALScriptParserV2;
-import org.apache.skywalking.oap.server.core.analysis.SourceDecoratorManager;
-import org.apache.skywalking.oap.server.core.oal.rt.OALDefine;
-import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-/**
- * Comprehensive comparison test using all OAL scripts in the project.
- *
- * This test loads every OAL script from test resources and verifies that
- * V1 and V2 engines generate byte-for-byte identical bytecode.
- */
-@Slf4j
-public class AllOALScriptsComparisonTest {
-
- private static final String SOURCE_PACKAGE = "org.apache.skywalking.oap.server.core.source.";
- private static final String METRICS_PACKAGE = "org.apache.skywalking.oap.server.core.source.oal.rt.metrics.";
-
- private static final String[] OAL_SCRIPTS = {
- "oal/core.oal",
- "oal/java-agent.oal",
- "oal/browser.oal",
- "oal/mesh.oal",
- "oal/tcp.oal",
- "oal/dotnet-agent.oal",
- "oal/ebpf.oal",
- "oal/cilium.oal"
- };
-
- @BeforeAll
- public static void initializeScopes() {
- // Initialize all scope classes needed by the OAL scripts
- DefaultScopeDefine.Listener listener = new DefaultScopeDefine.Listener();
-
- // Core sources
- notifyClass(listener, "Service");
- notifyClass(listener, "ServiceInstance");
- notifyClass(listener, "Endpoint");
- notifyClass(listener, "ServiceRelation");
- notifyClass(listener, "ServiceInstanceRelation");
- notifyClass(listener, "EndpointRelation");
- notifyClass(listener, "DatabaseAccess");
- notifyClass(listener, "CacheAccess");
- notifyClass(listener, "MQAccess");
- notifyClass(listener, "MQEndpointAccess");
-
- // JVM sources (for java-agent.oal)
- notifyClass(listener, "ServiceInstanceJVMCPU");
- notifyClass(listener, "ServiceInstanceJVMMemory");
- notifyClass(listener, "ServiceInstanceJVMMemoryPool");
- notifyClass(listener, "ServiceInstanceJVMGC");
- notifyClass(listener, "ServiceInstanceJVMThread");
- notifyClass(listener, "ServiceInstanceJVMClass");
-
- // CLR sources (for dotnet-agent.oal)
- notifyClass(listener, "ServiceInstanceCLRCPU");
- notifyClass(listener, "ServiceInstanceCLRGC");
- notifyClass(listener, "ServiceInstanceCLRThread");
-
- // Browser sources (different package: browser.source)
- String browserPackage = "org.apache.skywalking.oap.server.core.browser.source.";
- notifyClassFromPackage(listener, browserPackage, "BrowserAppTraffic");
- notifyClassFromPackage(listener, browserPackage, "BrowserAppPageTraffic");
- notifyClassFromPackage(listener, browserPackage, "BrowserAppSingleVersionTraffic");
- notifyClassFromPackage(listener, browserPackage, "BrowserAppPerf");
- notifyClassFromPackage(listener, browserPackage, "BrowserAppPagePerf");
- notifyClassFromPackage(listener, browserPackage, "BrowserAppSingleVersionPerf");
- notifyClassFromPackage(listener, browserPackage, "BrowserAppResourcePerf");
- notifyClassFromPackage(listener, browserPackage, "BrowserAppWebInteractionPerf");
- notifyClassFromPackage(listener, browserPackage, "BrowserAppWebVitalsPerf");
- notifyClassFromPackage(listener, browserPackage, "BrowserErrorLog");
-
- // Mesh sources
- notifyClass(listener, "ServiceMesh");
- notifyClass(listener, "ServiceMeshService");
- notifyClass(listener, "ServiceMeshServiceInstance");
- notifyClass(listener, "ServiceMeshServiceRelation");
- notifyClass(listener, "ServiceMeshServiceInstanceRelation");
-
- // TCP sources
- notifyClass(listener, "TCPService");
- notifyClass(listener, "TCPServiceInstance");
- notifyClass(listener, "TCPServiceRelation");
- notifyClass(listener, "TCPServiceInstanceRelation");
-
- // eBPF sources
- notifyClass(listener, "EBPFProfilingSchedule");
-
- // Cilium sources
- notifyClass(listener, "CiliumService");
- notifyClass(listener, "CiliumServiceInstance");
- notifyClass(listener, "CiliumEndpoint");
- notifyClass(listener, "CiliumServiceRelation");
- notifyClass(listener, "CiliumServiceInstanceRelation");
-
- // K8s sources
- notifyClass(listener, "K8SService");
- notifyClass(listener, "K8SServiceInstance");
- notifyClass(listener, "K8SEndpoint");
- notifyClass(listener, "K8SServiceRelation");
- notifyClass(listener, "K8SServiceInstanceRelation");
-
- // Process sources
- notifyClass(listener, "Process");
- notifyClass(listener, "ProcessRelation");
-
- // Register decorators (for core.oal, ebpf.oal)
- registerDecorator("ServiceDecorator");
- registerDecorator("EndpointDecorator");
- registerDecorator("K8SServiceDecorator");
- registerDecorator("K8SEndpointDecorator");
- }
-
- private static void registerDecorator(String decoratorName) {
- try {
- Class<?> clazz = Class.forName(SOURCE_PACKAGE + decoratorName);
- SourceDecoratorManager manager = new SourceDecoratorManager();
- manager.addIfAsSourceDecorator(clazz);
- } catch (ClassNotFoundException e) {
- log.debug("Decorator class not found: {}, skipping", decoratorName);
- } catch (IllegalAccessException | InstantiationException e) {
- log.debug("Decorator {} instantiation error: {}", decoratorName, e.getMessage());
- } catch (RuntimeException e) {
- // Decorator may already be registered or other error
- log.debug("Decorator {} registration: {}", decoratorName, e.getMessage());
- }
- }
-
- private static void notifyClass(DefaultScopeDefine.Listener listener, String className) {
- notifyClassFromPackage(listener, SOURCE_PACKAGE, className);
- }
-
- private static void notifyClassFromPackage(DefaultScopeDefine.Listener listener, String packageName, String className) {
- try {
- Class<?> clazz = Class.forName(packageName + className);
- listener.notify(clazz);
- } catch (ClassNotFoundException e) {
- log.debug("Source class not found: {}{}, skipping", packageName, className);
- } catch (RuntimeException e) {
- // Scope may already be registered by other tests (UnexpectedException)
- log.debug("Scope {} already registered or error: {}", className, e.getMessage());
- }
- }
-
- @Test
- public void compareAllOALScripts() throws Exception {
- int totalMetrics = 0;
- int passedMetrics = 0;
- int skippedScripts = 0;
- List<String> failures = new ArrayList<>();
- List<String> successfulScripts = new ArrayList<>();
-
- for (String scriptPath : OAL_SCRIPTS) {
- log.info("=== Testing {} ===", scriptPath);
-
- String oalContent = loadOALScript(scriptPath);
- if (oalContent == null) {
- log.warn("Script not found: {}, skipping", scriptPath);
- skippedScripts++;
- continue;
- }
-
- try {
- ComparisonResult result = compareOALScript(scriptPath, oalContent);
- totalMetrics += result.totalMetrics;
- passedMetrics += result.passedMetrics;
- failures.addAll(result.failures);
-
- if (result.passedMetrics == result.totalMetrics && result.totalMetrics > 0) {
- successfulScripts.add(scriptPath + " (" + result.totalMetrics + " metrics)");
- }
-
- log.info("{}: {}/{} metrics passed",
- scriptPath, result.passedMetrics, result.totalMetrics);
- } catch (Exception e) {
- // Scripts that fail to parse due to missing decorators/scopes are skipped
- failures.add("SKIPPED " + scriptPath + ": " + e.getClass().getSimpleName() + " - " + e.getMessage());
- skippedScripts++;
- }
- }
-
- log.info("=== Summary ===");
- log.info("Successful scripts: {}", successfulScripts.size());
- for (String script : successfulScripts) {
- log.info(" - {}", script);
- }
- log.info("Total metrics compared: {}", totalMetrics);
- log.info("Passed metrics: {}", passedMetrics);
- log.info("Skipped scripts (missing deps): {}", skippedScripts);
-
- if (!failures.isEmpty()) {
- log.error("Failures:");
- for (String failure : failures) {
- log.error(" - {}", failure);
- }
- }
-
- // Build summary for assertion message
- StringBuilder summary = new StringBuilder();
- summary.append("\n=== V1 vs V2 OAL Comparison Summary ===\n");
- summary.append("Successful scripts: ").append(successfulScripts.size()).append("\n");
- for (String script : successfulScripts) {
- summary.append(" - ").append(script).append("\n");
- }
- summary.append("Total metrics compared: ").append(totalMetrics).append("\n");
- summary.append("Passed metrics: ").append(passedMetrics).append("\n");
- summary.append("Skipped scripts: ").append(skippedScripts).append("\n");
- if (!failures.isEmpty()) {
- summary.append("Failures: ").append(failures).append("\n");
- }
-
- // At least some metrics should be tested
- Assertions.assertTrue(totalMetrics > 0, "At least some metrics should be testable. " + summary);
-
- // All testable metrics must produce identical bytecode
- Assertions.assertEquals(totalMetrics, passedMetrics,
- "All testable metrics should produce identical bytecode. " + summary);
-
- // All scripts should be testable now that we've registered scopes and decorators
- Assertions.assertEquals(0, skippedScripts,
- "All scripts should be testable. Skips: " + failures);
- }
-
- private String loadOALScript(String scriptPath) {
- try (InputStream is = getClass().getClassLoader().getResourceAsStream(scriptPath)) {
- if (is == null) {
- return null;
- }
- return new String(is.readAllBytes(), StandardCharsets.UTF_8);
- } catch (IOException e) {
- return null;
- }
- }
-
- private ComparisonResult compareOALScript(String scriptPath, String oalContent) throws Exception {
- ComparisonResult result = new ComparisonResult();
-
- // Parse with V1
- ClassPool v1Pool = new ClassPool(true);
- ScriptParser v1Parser = ScriptParser.createFromScriptText(oalContent, SOURCE_PACKAGE);
- OALScripts v1Scripts = v1Parser.parse();
- List<AnalysisResult> v1Results = v1Scripts.getMetricsStmts();
-
- // Parse with V2
- ClassPool v2Pool = new ClassPool(true);
- OALScriptParserV2 v2Parser = OALScriptParserV2.parse(oalContent);
- List<MetricDefinition> v2Metrics = v2Parser.getMetrics();
-
- // Verify same number of metrics parsed
- Assertions.assertEquals(v1Results.size(), v2Metrics.size(),
- scriptPath + ": V1 and V2 should parse same number of metrics");
-
- result.totalMetrics = v1Results.size();
-
- // Enrich V1 results
- for (AnalysisResult metricsStmt : v1Results) {
- metricsStmt.setMetricsClassPackage(METRICS_PACKAGE);
- metricsStmt.setSourcePackage(SOURCE_PACKAGE);
- }
-
- // Enrich V2 models
- MetricDefinitionEnricher enricher = new MetricDefinitionEnricher(SOURCE_PACKAGE, METRICS_PACKAGE);
- List<CodeGenModel> v2Models = new ArrayList<>();
- for (MetricDefinition metric : v2Metrics) {
- v2Models.add(enricher.enrich(metric));
- }
-
- // Generate and compare each metric
- TestOALDefine define = new TestOALDefine();
- V1ClassGenerator v1Gen = new V1ClassGenerator(define, v1Pool);
- V2ClassGenerator v2Gen = new V2ClassGenerator(define, v2Pool);
-
- for (int i = 0; i < v1Results.size(); i++) {
- AnalysisResult v1Result = v1Results.get(i);
- CodeGenModel v2Model = v2Models.get(i);
-
- String metricsName = v1Result.getMetricsName();
-
- try {
- // Generate metrics classes
- CtClass v1MetricsClass = v1Gen.generateMetricsCtClass(v1Result);
- CtClass v2MetricsClass = v2Gen.generateMetricsCtClass(v2Model);
-
- // Compare bytecode
- boolean match = compareBytecode(v1MetricsClass, v2MetricsClass);
- if (match) {
- result.passedMetrics++;
- } else {
- result.failures.add(scriptPath + ":" + metricsName + " - bytecode mismatch");
- }
- } catch (Exception e) {
- result.failures.add(scriptPath + ":" + metricsName + " - " + e.getMessage());
- }
- }
-
- return result;
- }
-
- private boolean compareBytecode(CtClass v1Class, CtClass v2Class) throws Exception {
- ByteArrayOutputStream v1Baos = new ByteArrayOutputStream();
- ByteArrayOutputStream v2Baos = new ByteArrayOutputStream();
-
- v1Class.toBytecode(new DataOutputStream(v1Baos));
- v2Class.toBytecode(new DataOutputStream(v2Baos));
-
- byte[] v1Bytecode = v1Baos.toByteArray();
- byte[] v2Bytecode = v2Baos.toByteArray();
-
- return Arrays.equals(v1Bytecode, v2Bytecode);
- }
-
- private static class ComparisonResult {
- int totalMetrics = 0;
- int passedMetrics = 0;
- List<String> failures = new ArrayList<>();
- }
-
- private static class TestOALDefine extends OALDefine {
- protected TestOALDefine() {
- super("test.oal", SOURCE_PACKAGE);
- }
- }
-}
diff --git a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/DiagnosticTest.java b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/DiagnosticTest.java
deleted file mode 100644
index 4b594d7304..0000000000
--- a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/DiagnosticTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.v2.generator;
-
-import freemarker.template.Configuration;
-import freemarker.template.Version;
-import java.io.StringWriter;
-import java.util.List;
-import java.util.Locale;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.skywalking.oal.rt.OALRuntime;
-import org.apache.skywalking.oal.rt.parser.AnalysisResult;
-import org.apache.skywalking.oal.rt.parser.OALScripts;
-import org.apache.skywalking.oal.rt.parser.ScriptParser;
-import org.apache.skywalking.oal.v2.model.MetricDefinition;
-import org.apache.skywalking.oal.v2.parser.OALScriptParserV2;
-import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
-import org.apache.skywalking.oap.server.core.source.Service;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-/**
- * Diagnostic test to compare generated source code from V1 and V2.
- */
-@Slf4j
-public class DiagnosticTest {
-
- private static final String SOURCE_PACKAGE = "org.apache.skywalking.oap.server.core.source.";
- private static final String METRICS_PACKAGE = "org.apache.skywalking.oap.server.core.source.oal.rt.metrics.";
-
- @BeforeAll
- public static void initializeScopes() {
- try {
- DefaultScopeDefine.Listener listener = new DefaultScopeDefine.Listener();
- listener.notify(Service.class);
- } catch (RuntimeException e) {
- // Scope may already be registered by other tests
- }
- }
-
- @Test
- public void compareGeneratedDoMetrics() throws Exception {
- String oal = "service_cpm = from(Service.*).cpm();";
-
- // V1
- String v1Source = generateV1DoMetrics(oal);
- log.info("=== V1 Generated doMetrics (length={}) ===\n{}", v1Source.length(), v1Source);
-
- // V2
- String v2Source = generateV2DoMetrics(oal);
- log.info("=== V2 Generated doMetrics (length={}) ===\n{}", v2Source.length(), v2Source);
-
- // Character by character comparison
- int minLen = Math.min(v1Source.length(), v2Source.length());
- for (int i = 0; i < minLen; i++) {
- if (v1Source.charAt(i) != v2Source.charAt(i)) {
- log.info("First difference at index {}", i);
- log.info("V1 char: '{}' (code: {})", v1Source.charAt(i), (int) v1Source.charAt(i));
- log.info("V2 char: '{}' (code: {})", v2Source.charAt(i), (int) v2Source.charAt(i));
- log.info("V1 context: {}", v1Source.substring(Math.max(0, i - 20), Math.min(v1Source.length(), i + 20)));
- log.info("V2 context: {}", v2Source.substring(Math.max(0, i - 20), Math.min(v2Source.length(), i + 20)));
- break;
- }
- }
- if (v1Source.length() != v2Source.length()) {
- log.info("Length difference: V1={}, V2={}", v1Source.length(), v2Source.length());
- }
-
- Assertions.assertEquals(v1Source, v2Source, "V1 and V2 should generate identical source code");
- }
-
- private String generateV1DoMetrics(String oal) throws Exception {
- ScriptParser scriptParser = ScriptParser.createFromScriptText(oal, SOURCE_PACKAGE);
- OALScripts scripts = scriptParser.parse();
- List<AnalysisResult> results = scripts.getMetricsStmts();
-
- AnalysisResult metricsStmt = results.get(0);
- metricsStmt.setMetricsClassPackage(METRICS_PACKAGE);
- metricsStmt.setSourcePackage(SOURCE_PACKAGE);
-
- Configuration configuration = new Configuration(new Version("2.3.28"));
- configuration.setEncoding(Locale.ENGLISH, "UTF-8");
- configuration.setClassLoaderForTemplateLoading(OALRuntime.class.getClassLoader(), "/code-templates");
-
- StringWriter methodEntity = new StringWriter();
- configuration.getTemplate("dispatcher/doMetrics.ftl").process(metricsStmt, methodEntity);
- return methodEntity.toString();
- }
-
- private String generateV2DoMetrics(String oal) throws Exception {
- MetricDefinitionEnricher enricher = new MetricDefinitionEnricher(SOURCE_PACKAGE, METRICS_PACKAGE);
- OALScriptParserV2 parser = OALScriptParserV2.parse(oal);
- List<MetricDefinition> metrics = parser.getMetrics();
-
- CodeGenModel model = enricher.enrich(metrics.get(0));
-
- Configuration configuration = new Configuration(new Version("2.3.28"));
- configuration.setEncoding(Locale.ENGLISH, "UTF-8");
- configuration.setClassLoaderForTemplateLoading(OALClassGeneratorV2.class.getClassLoader(), "/code-templates-v2");
-
- StringWriter methodEntity = new StringWriter();
- configuration.getTemplate("dispatcher/doMetrics.ftl").process(model, methodEntity);
- return methodEntity.toString();
- }
-}
diff --git a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/V1ClassGenerator.java b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/V1ClassGenerator.java
deleted file mode 100644
index b20f9e0669..0000000000
--- a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/V1ClassGenerator.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.v2.generator;
-
-import freemarker.template.Configuration;
-import freemarker.template.Version;
-import java.io.StringWriter;
-import java.util.Locale;
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtConstructor;
-import javassist.CtField;
-import javassist.CtNewConstructor;
-import javassist.CtNewMethod;
-import javassist.bytecode.AnnotationsAttribute;
-import javassist.bytecode.ClassFile;
-import javassist.bytecode.ConstPool;
-import javassist.bytecode.SignatureAttribute;
-import javassist.bytecode.annotation.Annotation;
-import javassist.bytecode.annotation.ClassMemberValue;
-import javassist.bytecode.annotation.IntegerMemberValue;
-import javassist.bytecode.annotation.StringMemberValue;
-import org.apache.skywalking.oal.rt.OALRuntime;
-import org.apache.skywalking.oal.rt.output.DispatcherContext;
-import org.apache.skywalking.oal.rt.parser.AnalysisResult;
-import org.apache.skywalking.oal.rt.parser.SourceColumn;
-import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
-import org.apache.skywalking.oap.server.core.analysis.Stream;
-import org.apache.skywalking.oap.server.core.oal.rt.OALCompileException;
-import org.apache.skywalking.oap.server.core.oal.rt.OALDefine;
-import org.apache.skywalking.oap.server.core.storage.annotation.BanyanDB;
-import org.apache.skywalking.oap.server.core.storage.annotation.Column;
-import org.apache.skywalking.oap.server.core.storage.annotation.ElasticSearch;
-
-/**
- * V1 class generator that produces CtClass without loading to JVM.
- * Used for bytecode comparison tests.
- */
-public class V1ClassGenerator {
-
- private static final String METRICS_FUNCTION_PACKAGE = "org.apache.skywalking.oap.server.core.analysis.metrics.";
- private static final String WITH_METADATA_INTERFACE = "org.apache.skywalking.oap.server.core.analysis.metrics.WithMetadata";
- private static final String DISPATCHER_INTERFACE = "org.apache.skywalking.oap.server.core.analysis.SourceDispatcher";
- private static final String METRICS_STREAM_PROCESSOR = "org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor";
- private static final String[] METRICS_CLASS_METHODS = {
- "id",
- "hashCode",
- "remoteHashCode",
- "equals",
- "serialize",
- "deserialize",
- "getMeta",
- "toHour",
- "toDay"
- };
-
- private final ClassPool classPool;
- private final OALDefine oalDefine;
- private final Configuration configuration;
-
- public V1ClassGenerator(OALDefine define, ClassPool classPool) {
- this.classPool = classPool;
- this.oalDefine = define;
-
- configuration = new Configuration(new Version("2.3.28"));
- configuration.setEncoding(Locale.ENGLISH, "UTF-8");
- configuration.setClassLoaderForTemplateLoading(OALRuntime.class.getClassLoader(), "/code-templates");
- }
-
- /**
- * Generate metrics CtClass without loading to JVM.
- */
- public CtClass generateMetricsCtClass(AnalysisResult metricsStmt) throws OALCompileException {
- String className = metricsClassName(metricsStmt, false);
- CtClass parentMetricsClass;
-
- try {
- parentMetricsClass = classPool.get(METRICS_FUNCTION_PACKAGE + metricsStmt.getMetricsClassName());
- } catch (Exception e) {
- throw new OALCompileException("Can't find parent class for " + className, e);
- }
-
- CtClass metricsClass = classPool.makeClass(metricsClassName(metricsStmt, true), parentMetricsClass);
-
- try {
- metricsClass.addInterface(classPool.get(WITH_METADATA_INTERFACE));
- } catch (Exception e) {
- throw new OALCompileException("Can't find WithMetadata interface for " + className, e);
- }
-
- ClassFile metricsClassClassFile = metricsClass.getClassFile();
- ConstPool constPool = metricsClassClassFile.getConstPool();
-
- // Create empty constructor
- try {
- CtConstructor defaultConstructor = CtNewConstructor.make("public " + className + "() {}", metricsClass);
- metricsClass.addConstructor(defaultConstructor);
- } catch (Exception e) {
- throw new OALCompileException("Can't add empty constructor in " + className, e);
- }
-
- // Add fields with annotations
- for (SourceColumn field : metricsStmt.getFieldsFromSource()) {
- try {
- CtField newField = CtField.make(
- "private " + field.getType().getName() + " " + field.getFieldName() + ";", metricsClass);
-
- metricsClass.addField(newField);
- metricsClass.addMethod(CtNewMethod.getter(field.getFieldGetter(), newField));
- metricsClass.addMethod(CtNewMethod.setter(field.getFieldSetter(), newField));
-
- AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(
- constPool, AnnotationsAttribute.visibleTag);
-
- // Add @Column annotation
- Annotation columnAnnotation = new Annotation(Column.class.getName(), constPool);
- columnAnnotation.addMemberValue("name", new StringMemberValue(field.getColumnName(), constPool));
- if (field.getType().equals(String.class)) {
- columnAnnotation.addMemberValue("length", new IntegerMemberValue(constPool, field.getLength()));
- }
- annotationsAttribute.addAnnotation(columnAnnotation);
-
- if (field.isID()) {
- Annotation banyanSeriesIDAnnotation = new Annotation(BanyanDB.SeriesID.class.getName(), constPool);
- banyanSeriesIDAnnotation.addMemberValue("index", new IntegerMemberValue(constPool, 0));
- annotationsAttribute.addAnnotation(banyanSeriesIDAnnotation);
-
- Annotation enableDocValuesAnnotation = new Annotation(ElasticSearch.EnableDocValues.class.getName(), constPool);
- annotationsAttribute.addAnnotation(enableDocValuesAnnotation);
- }
-
- if (field.isShardingKey()) {
- Annotation banyanShardingKeyAnnotation = new Annotation(BanyanDB.ShardingKey.class.getName(), constPool);
- banyanShardingKeyAnnotation.addMemberValue("index", new IntegerMemberValue(constPool, field.getShardingKeyIdx()));
- annotationsAttribute.addAnnotation(banyanShardingKeyAnnotation);
- }
-
- newField.getFieldInfo().addAttribute(annotationsAttribute);
- } catch (Exception e) {
- throw new OALCompileException("Can't add field " + field.getFieldName() + " in " + className, e);
- }
- }
-
- // Generate methods using V1 templates
- for (String method : METRICS_CLASS_METHODS) {
- StringWriter methodEntity = new StringWriter();
- try {
- configuration.getTemplate("metrics/" + method + ".ftl").process(metricsStmt, methodEntity);
- metricsClass.addMethod(CtNewMethod.make(methodEntity.toString(), metricsClass));
- } catch (Exception e) {
- throw new OALCompileException("Can't generate method " + method + " for " + className, e);
- }
- }
-
- // Add @Stream annotation
- AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(
- constPool, AnnotationsAttribute.visibleTag);
- Annotation streamAnnotation = new Annotation(Stream.class.getName(), constPool);
- streamAnnotation.addMemberValue("name", new StringMemberValue(metricsStmt.getTableName(), constPool));
- streamAnnotation.addMemberValue("scopeId", new IntegerMemberValue(constPool, metricsStmt.getFrom().getSourceScopeId()));
- streamAnnotation.addMemberValue(
- "builder", new ClassMemberValue(metricsBuilderClassName(metricsStmt, true), constPool));
- streamAnnotation.addMemberValue("processor", new ClassMemberValue(METRICS_STREAM_PROCESSOR, constPool));
-
- annotationsAttribute.addAnnotation(streamAnnotation);
- metricsClassClassFile.addAttribute(annotationsAttribute);
-
- return metricsClass;
- }
-
- /**
- * Generate dispatcher CtClass without loading to JVM.
- */
- public CtClass generateDispatcherCtClass(String scopeName, DispatcherContext dispatcherContext) throws OALCompileException {
- String className = dispatcherClassName(scopeName, false);
- CtClass dispatcherClass = classPool.makeClass(dispatcherClassName(scopeName, true));
-
- try {
- CtClass dispatcherInterface = classPool.get(DISPATCHER_INTERFACE);
- dispatcherClass.addInterface(dispatcherInterface);
-
- // Set generic signature
- String sourceClassName = oalDefine.getSourcePackage() + dispatcherContext.getSource();
- SignatureAttribute.ClassSignature dispatcherSignature =
- new SignatureAttribute.ClassSignature(
- null, null,
- new SignatureAttribute.ClassType[]{
- new SignatureAttribute.ClassType(
- SourceDispatcher.class.getCanonicalName(),
- new SignatureAttribute.TypeArgument[]{
- new SignatureAttribute.TypeArgument(
- new SignatureAttribute.ClassType(sourceClassName))
- }
- )
- }
- );
-
- dispatcherClass.setGenericSignature(dispatcherSignature.encode());
- } catch (Exception e) {
- throw new OALCompileException("Can't find Dispatcher interface for " + className, e);
- }
-
- // Generate doMetrics methods for each metric
- for (AnalysisResult dispatcherContextMetric : dispatcherContext.getMetrics()) {
- StringWriter methodEntity = new StringWriter();
- try {
- configuration.getTemplate("dispatcher/doMetrics.ftl").process(dispatcherContextMetric, methodEntity);
- dispatcherClass.addMethod(CtNewMethod.make(methodEntity.toString(), dispatcherClass));
- } catch (Exception e) {
- throw new OALCompileException("Can't generate method do" + dispatcherContextMetric.getMetricsName() + " for " + className, e);
- }
- }
-
- // Generate dispatch method
- try {
- StringWriter methodEntity = new StringWriter();
- configuration.getTemplate("dispatcher/dispatch.ftl").process(dispatcherContext, methodEntity);
- dispatcherClass.addMethod(CtNewMethod.make(methodEntity.toString(), dispatcherClass));
- } catch (Exception e) {
- throw new OALCompileException("Can't generate method dispatch for " + className, e);
- }
-
- return dispatcherClass;
- }
-
- private String metricsClassName(AnalysisResult metricsStmt, boolean fullName) {
- return (fullName ? oalDefine.getDynamicMetricsClassPackage() : "") + metricsStmt.getMetricsName() + "Metrics";
- }
-
- private String metricsBuilderClassName(AnalysisResult metricsStmt, boolean fullName) {
- return (fullName ? oalDefine.getDynamicMetricsBuilderClassPackage() : "") + metricsStmt.getMetricsName() + "MetricsBuilder";
- }
-
- private String dispatcherClassName(String scopeName, boolean fullName) {
- return (fullName ? oalDefine.getDynamicDispatcherClassPackage() : "") + scopeName + "Dispatcher";
- }
-}
diff --git a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/V1V2ComparisonTest.java b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/V1V2ComparisonTest.java
deleted file mode 100644
index d9bf34b7d9..0000000000
--- a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/v2/generator/V1V2ComparisonTest.java
+++ /dev/null
@@ -1,551 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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 org.apache.skywalking.oal.v2.generator;
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtField;
-import javassist.CtMethod;
-import javassist.bytecode.AnnotationsAttribute;
-import javassist.bytecode.FieldInfo;
-import javassist.bytecode.MethodInfo;
-import javassist.bytecode.annotation.Annotation;
-import javassist.bytecode.annotation.MemberValue;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.skywalking.oal.rt.output.AllDispatcherContext;
-import org.apache.skywalking.oal.rt.output.DispatcherContext;
-import org.apache.skywalking.oal.rt.parser.AnalysisResult;
-import org.apache.skywalking.oal.rt.parser.OALScripts;
-import org.apache.skywalking.oal.rt.parser.ScriptParser;
-import org.apache.skywalking.oal.v2.model.MetricDefinition;
-import org.apache.skywalking.oal.v2.parser.OALScriptParserV2;
-import org.apache.skywalking.oap.server.core.oal.rt.OALDefine;
-import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
-import org.apache.skywalking.oap.server.core.source.Service;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-/**
- * Deep comparison test between V1 and V2 OAL engines.
- *
- * Uses isolated ClassPools to generate the same OAL scripts with both engines,
- * then compares the generated bytecode in detail:
- * - Class annotations
- * - Fields and their annotations
- * - Methods (signatures and bytecode)
- *
- * Both engines should produce identical bytecode for the same OAL input.
- */
-@Slf4j
-public class V1V2ComparisonTest {
-
- private static final String SOURCE_PACKAGE = "org.apache.skywalking.oap.server.core.source.";
- private static final String METRICS_PACKAGE = "org.apache.skywalking.oap.server.core.source.oal.rt.metrics.";
-
- @BeforeAll
- public static void initializeScopes() {
- try {
- DefaultScopeDefine.Listener listener = new DefaultScopeDefine.Listener();
- listener.notify(Service.class);
- } catch (RuntimeException e) {
- // Scope may already be registered by other tests
- }
- }
-
- /**
- * Test that V1 and V2 generate identical metrics classes for simple OAL.
- */
- @Test
- public void testMetricsClassIdentical() throws Exception {
- String oal = "service_cpm = from(Service.*).cpm();";
-
- // Generate with V1 using isolated ClassPool
- ClassPool v1Pool = new ClassPool(true);
- V1GeneratedClasses v1Classes = generateWithV1(oal, v1Pool);
-
- // Generate with V2 using isolated ClassPool
- ClassPool v2Pool = new ClassPool(true);
- V2GeneratedClasses v2Classes = generateWithV2(oal, v2Pool);
-
- // Compare metrics classes
- Assertions.assertEquals(1, v1Classes.metricsClasses.size(), "V1 should generate 1 metrics class");
- Assertions.assertEquals(1, v2Classes.metricsClasses.size(), "V2 should generate 1 metrics class");
-
- CtClass v1Metrics = v1Classes.metricsClasses.get(0);
- CtClass v2Metrics = v2Classes.metricsClasses.get(0);
-
- log.info("=== Comparing Metrics Classes ===");
- log.info("V1: {}", v1Metrics.getName());
- log.info("V2: {}", v2Metrics.getName());
-
- compareClasses(v1Metrics, v2Metrics, "Metrics");
- }
-
- /**
- * Test that V1 and V2 generate identical dispatcher classes.
- */
- @Test
- public void testDispatcherClassIdentical() throws Exception {
- String oal = "service_cpm = from(Service.*).cpm();";
-
- ClassPool v1Pool = new ClassPool(true);
- V1GeneratedClasses v1Classes = generateWithV1(oal, v1Pool);
-
- ClassPool v2Pool = new ClassPool(true);
- V2GeneratedClasses v2Classes = generateWithV2(oal, v2Pool);
-
- Assertions.assertEquals(1, v1Classes.dispatcherClasses.size(), "V1 should generate 1 dispatcher class");
- Assertions.assertEquals(1, v2Classes.dispatcherClasses.size(), "V2 should generate 1 dispatcher class");
-
- CtClass v1Dispatcher = v1Classes.dispatcherClasses.get(0);
- CtClass v2Dispatcher = v2Classes.dispatcherClasses.get(0);
-
- log.info("=== Comparing Dispatcher Classes ===");
- log.info("V1: {}", v1Dispatcher.getName());
- log.info("V2: {}", v2Dispatcher.getName());
-
- compareClasses(v1Dispatcher, v2Dispatcher, "Dispatcher");
- }
-
- /**
- * Test complex OAL with longAvg function.
- */
- @Test
- public void testLongAvgMetricsIdentical() throws Exception {
- String oal = "service_resp_time = from(Service.latency).longAvg();";
-
- ClassPool v1Pool = new ClassPool(true);
- V1GeneratedClasses v1Classes = generateWithV1(oal, v1Pool);
-
- ClassPool v2Pool = new ClassPool(true);
- V2GeneratedClasses v2Classes = generateWithV2(oal, v2Pool);
-
- CtClass v1Metrics = v1Classes.metricsClasses.get(0);
- CtClass v2Metrics = v2Classes.metricsClasses.get(0);
-
- log.info("=== Comparing LongAvg Metrics Classes ===");
- compareClasses(v1Metrics, v2Metrics, "LongAvgMetrics");
- }
-
- /**
- * Test OAL with filter expression.
- */
- @Test
- public void testFilteredMetricsIdentical() throws Exception {
- String oal = "service_cpm_valid = from(Service.*).filter(status == true).cpm();";
-
- ClassPool v1Pool = new ClassPool(true);
- V1GeneratedClasses v1Classes = generateWithV1(oal, v1Pool);
-
- ClassPool v2Pool = new ClassPool(true);
- V2GeneratedClasses v2Classes = generateWithV2(oal, v2Pool);
-
- CtClass v1Metrics = v1Classes.metricsClasses.get(0);
- CtClass v2Metrics = v2Classes.metricsClasses.get(0);
-
- log.info("=== Comparing Filtered Metrics Classes ===");
- compareClasses(v1Metrics, v2Metrics, "FilteredMetrics");
-
- // Also compare dispatcher (filter logic is in doMetrics method)
- CtClass v1Dispatcher = v1Classes.dispatcherClasses.get(0);
- CtClass v2Dispatcher = v2Classes.dispatcherClasses.get(0);
-
- log.info("=== Comparing Filtered Dispatcher Classes ===");
- compareClasses(v1Dispatcher, v2Dispatcher, "FilteredDispatcher");
- }
-
- /**
- * Test multiple metrics from same source.
- */
- @Test
- public void testMultipleMetricsIdentical() throws Exception {
- String oal = "service_cpm = from(Service.*).cpm();\n"
- + "service_resp_time = from(Service.latency).longAvg();";
-
- ClassPool v1Pool = new ClassPool(true);
- V1GeneratedClasses v1Classes = generateWithV1(oal, v1Pool);
-
- ClassPool v2Pool = new ClassPool(true);
- V2GeneratedClasses v2Classes = generateWithV2(oal, v2Pool);
-
- Assertions.assertEquals(2, v1Classes.metricsClasses.size());
- Assertions.assertEquals(2, v2Classes.metricsClasses.size());
-
- // Sort by name for consistent comparison
- v1Classes.metricsClasses.sort((a, b) -> a.getName().compareTo(b.getName()));
- v2Classes.metricsClasses.sort((a, b) -> a.getName().compareTo(b.getName()));
-
- for (int i = 0; i < v1Classes.metricsClasses.size(); i++) {
- log.info("=== Comparing Multiple Metrics {} ===", i);
- compareClasses(v1Classes.metricsClasses.get(i), v2Classes.metricsClasses.get(i), "MultiMetrics" + i);
- }
-
- // Should have only 1 dispatcher (both metrics from Service)
- Assertions.assertEquals(1, v1Classes.dispatcherClasses.size());
- Assertions.assertEquals(1, v2Classes.dispatcherClasses.size());
-
- compareClasses(v1Classes.dispatcherClasses.get(0), v2Classes.dispatcherClasses.get(0), "MultiDispatcher");
- }
-
- private void compareClasses(CtClass v1Class, CtClass v2Class, String context) throws Exception {
- // 1. Compare class names
- Assertions.assertEquals(v1Class.getName(), v2Class.getName(),
- context + ": Class names should match");
- log.info("{}: Class name matches: {}", context, v1Class.getName());
-
- // 2. Compare superclass
- Assertions.assertEquals(
- v1Class.getSuperclass() != null ? v1Class.getSuperclass().getName() : null,
- v2Class.getSuperclass() != null ? v2Class.getSuperclass().getName() : null,
- context + ": Superclass should match");
- log.info("{}: Superclass matches: {}", context,
- v1Class.getSuperclass() != null ? v1Class.getSuperclass().getName() : "none");
-
- // 3. Compare interfaces
- String[] v1Interfaces = Arrays.stream(v1Class.getInterfaces())
- .map(CtClass::getName).sorted().toArray(String[]::new);
- String[] v2Interfaces = Arrays.stream(v2Class.getInterfaces())
- .map(CtClass::getName).sorted().toArray(String[]::new);
- Assertions.assertArrayEquals(v1Interfaces, v2Interfaces,
- context + ": Interfaces should match");
- log.info("{}: Interfaces match: {}", context, Arrays.toString(v1Interfaces));
-
- // 4. Compare class-level annotations
- compareClassAnnotations(v1Class, v2Class, context);
-
- // 5. Compare fields
- compareFields(v1Class, v2Class, context);
-
- // 6. Compare methods
- compareMethods(v1Class, v2Class, context);
-
- // 7. Compare bytecode
- compareBytecode(v1Class, v2Class, context);
- }
-
- private void compareClassAnnotations(CtClass v1Class, CtClass v2Class, String context) {
- AnnotationsAttribute v1Annos = (AnnotationsAttribute) v1Class.getClassFile()
- .getAttribute(AnnotationsAttribute.visibleTag);
- AnnotationsAttribute v2Annos = (AnnotationsAttribute) v2Class.getClassFile()
- .getAttribute(AnnotationsAttribute.visibleTag);
-
- if (v1Annos == null && v2Annos == null) {
- log.info("{}: No class-level annotations", context);
- return;
- }
-
- Assertions.assertEquals(v1Annos != null, v2Annos != null,
- context + ": Both should have or not have class annotations");
-
- if (v1Annos != null) {
- Annotation[] v1AnnoArray = v1Annos.getAnnotations();
- Annotation[] v2AnnoArray = v2Annos.getAnnotations();
-
- Assertions.assertEquals(v1AnnoArray.length, v2AnnoArray.length,
- context + ": Annotation count should match");
-
- for (int i = 0; i < v1AnnoArray.length; i++) {
- compareAnnotation(v1AnnoArray[i], v2AnnoArray[i], context + " class annotation");
- }
- log.info("{}: Class annotations match (count={})", context, v1AnnoArray.length);
- }
- }
-
- private void compareAnnotation(Annotation v1Anno, Annotation v2Anno, String context) {
- Assertions.assertEquals(v1Anno.getTypeName(), v2Anno.getTypeName(),
- context + ": Annotation type should match");
-
- // Compare member values
- if (v1Anno.getMemberNames() == null && v2Anno.getMemberNames() == null) {
- return;
- }
-
- Assertions.assertEquals(
- v1Anno.getMemberNames() != null ? v1Anno.getMemberNames().size() : 0,
- v2Anno.getMemberNames() != null ? v2Anno.getMemberNames().size() : 0,
- context + ": Annotation member count should match");
-
- if (v1Anno.getMemberNames() != null) {
- for (String memberName : v1Anno.getMemberNames()) {
- MemberValue v1Value = v1Anno.getMemberValue(memberName);
- MemberValue v2Value = v2Anno.getMemberValue(memberName);
- Assertions.assertNotNull(v2Value,
- context + ": V2 should have member " + memberName);
- Assertions.assertEquals(v1Value.toString(), v2Value.toString(),
- context + ": Member " + memberName + " should match");
- }
- }
- }
-
- private void compareFields(CtClass v1Class, CtClass v2Class, String context) throws Exception {
- CtField[] v1Fields = v1Class.getDeclaredFields();
- CtField[] v2Fields = v2Class.getDeclaredFields();
-
- // Sort fields by name for consistent comparison
- Map<String, CtField> v1FieldMap = new TreeMap<>();
- Map<String, CtField> v2FieldMap = new TreeMap<>();
-
- for (CtField f : v1Fields) {
- v1FieldMap.put(f.getName(), f);
- }
- for (CtField f : v2Fields) {
- v2FieldMap.put(f.getName(), f);
- }
-
- Assertions.assertEquals(v1FieldMap.keySet(), v2FieldMap.keySet(),
- context + ": Field names should match");
-
- for (String fieldName : v1FieldMap.keySet()) {
- CtField v1Field = v1FieldMap.get(fieldName);
- CtField v2Field = v2FieldMap.get(fieldName);
-
- // Compare field type
- Assertions.assertEquals(v1Field.getType().getName(), v2Field.getType().getName(),
- context + ": Field " + fieldName + " type should match");
-
- // Compare field modifiers
- Assertions.assertEquals(v1Field.getModifiers(), v2Field.getModifiers(),
- context + ": Field " + fieldName + " modifiers should match");
-
- // Compare field annotations
- FieldInfo v1FieldInfo = v1Field.getFieldInfo();
- FieldInfo v2FieldInfo = v2Field.getFieldInfo();
-
- AnnotationsAttribute v1FieldAnnos = (AnnotationsAttribute) v1FieldInfo
- .getAttribute(AnnotationsAttribute.visibleTag);
- AnnotationsAttribute v2FieldAnnos = (AnnotationsAttribute) v2FieldInfo
- .getAttribute(AnnotationsAttribute.visibleTag);
-
- if (v1FieldAnnos != null && v2FieldAnnos != null) {
- Annotation[] v1AnnoArray = v1FieldAnnos.getAnnotations();
- Annotation[] v2AnnoArray = v2FieldAnnos.getAnnotations();
-
- // Sort annotations by type name for consistent comparison
- Arrays.sort(v1AnnoArray, (a, b) -> a.getTypeName().compareTo(b.getTypeName()));
- Arrays.sort(v2AnnoArray, (a, b) -> a.getTypeName().compareTo(b.getTypeName()));
-
- Assertions.assertEquals(v1AnnoArray.length, v2AnnoArray.length,
- context + ": Field " + fieldName + " annotation count should match");
-
- for (int i = 0; i < v1AnnoArray.length; i++) {
- compareAnnotation(v1AnnoArray[i], v2AnnoArray[i],
- context + " field " + fieldName);
- }
- }
- }
-
- log.info("{}: Fields match (count={})", context, v1FieldMap.size());
- }
-
- private void compareMethods(CtClass v1Class, CtClass v2Class, String context) throws Exception {
- CtMethod[] v1Methods = v1Class.getDeclaredMethods();
- CtMethod[] v2Methods = v2Class.getDeclaredMethods();
-
- // Map methods by signature for comparison
- Map<String, CtMethod> v1MethodMap = new TreeMap<>();
- Map<String, CtMethod> v2MethodMap = new TreeMap<>();
-
- for (CtMethod m : v1Methods) {
- String sig = m.getName() + m.getSignature();
- v1MethodMap.put(sig, m);
- }
- for (CtMethod m : v2Methods) {
- String sig = m.getName() + m.getSignature();
- v2MethodMap.put(sig, m);
- }
-
- Assertions.assertEquals(v1MethodMap.keySet(), v2MethodMap.keySet(),
- context + ": Method signatures should match. V1: " + v1MethodMap.keySet()
- + ", V2: " + v2MethodMap.keySet());
-
- for (String sig : v1MethodMap.keySet()) {
- CtMethod v1Method = v1MethodMap.get(sig);
- CtMethod v2Method = v2MethodMap.get(sig);
-
- // Compare method modifiers
- Assertions.assertEquals(v1Method.getModifiers(), v2Method.getModifiers(),
- context + ": Method " + sig + " modifiers should match");
-
- // Compare method bytecode
- MethodInfo v1MethodInfo = v1Method.getMethodInfo();
- MethodInfo v2MethodInfo = v2Method.getMethodInfo();
-
- // Compare code attribute (bytecode)
- if (v1MethodInfo.getCodeAttribute() != null && v2MethodInfo.getCodeAttribute() != null) {
- byte[] v1Code = v1MethodInfo.getCodeAttribute().getCode();
- byte[] v2Code = v2MethodInfo.getCodeAttribute().getCode();
-
- Assertions.assertArrayEquals(v1Code, v2Code,
- context + ": Method " + sig + " bytecode should match");
- }
- }
-
- log.info("{}: Methods match (count={})", context, v1MethodMap.size());
- }
-
- private void compareBytecode(CtClass v1Class, CtClass v2Class, String context) throws Exception {
- ByteArrayOutputStream v1Baos = new ByteArrayOutputStream();
- ByteArrayOutputStream v2Baos = new ByteArrayOutputStream();
-
- v1Class.toBytecode(new DataOutputStream(v1Baos));
- v2Class.toBytecode(new DataOutputStream(v2Baos));
-
- byte[] v1Bytecode = v1Baos.toByteArray();
- byte[] v2Bytecode = v2Baos.toByteArray();
-
- Assertions.assertEquals(v1Bytecode.length, v2Bytecode.length,
- context + ": Bytecode length should match");
-
- Assertions.assertArrayEquals(v1Bytecode, v2Bytecode,
- context + ": Complete bytecode should be identical");
-
- log.info("{}: Complete bytecode identical ({} bytes)", context, v1Bytecode.length);
- }
-
- /**
- * Generate classes with V1 engine using isolated ClassPool.
- */
- private V1GeneratedClasses generateWithV1(String oal, ClassPool classPool) throws Exception {
- V1OALDefine define = new V1OALDefine();
-
- ScriptParser scriptParser = ScriptParser.createFromScriptText(oal, SOURCE_PACKAGE);
- OALScripts scripts = scriptParser.parse();
-
- // OALListener already applies DeepAnalysis during parsing
- List<AnalysisResult> results = scripts.getMetricsStmts();
-
- // Build dispatcher context
- AllDispatcherContext allDispatcherContext = new AllDispatcherContext();
- for (AnalysisResult metricsStmt : results) {
- String sourceName = metricsStmt.getFrom().getSourceName();
- DispatcherContext context = allDispatcherContext.getAllContext().computeIfAbsent(sourceName, name -> {
- DispatcherContext absent = new DispatcherContext();
- absent.setSourcePackage(define.getSourcePackage());
- absent.setSource(name);
- absent.setPackageName(name.toLowerCase());
- absent.setSourceDecorator(metricsStmt.getSourceDecorator());
- return absent;
- });
- metricsStmt.setMetricsClassPackage(define.getDynamicMetricsClassPackage());
- metricsStmt.setSourcePackage(define.getSourcePackage());
- context.getMetrics().add(metricsStmt);
- }
-
- // Generate classes using V1 generator (CtClass only, no JVM loading)
- V1ClassGenerator generator = new V1ClassGenerator(define, classPool);
- V1GeneratedClasses classes = new V1GeneratedClasses();
-
- for (AnalysisResult metricsStmt : results) {
- classes.metricsClasses.add(generator.generateMetricsCtClass(metricsStmt));
- }
-
- for (Map.Entry<String, DispatcherContext> entry : allDispatcherContext.getAllContext().entrySet()) {
- classes.dispatcherClasses.add(generator.generateDispatcherCtClass(entry.getKey(), entry.getValue()));
- }
-
- return classes;
- }
-
- /**
- * Generate classes with V2 engine using isolated ClassPool.
- */
- private V2GeneratedClasses generateWithV2(String oal, ClassPool classPool) throws Exception {
- V2OALDefine define = new V2OALDefine();
- MetricDefinitionEnricher enricher = new MetricDefinitionEnricher(SOURCE_PACKAGE, METRICS_PACKAGE);
- OALScriptParserV2 parser = OALScriptParserV2.parse(oal);
-
- List<CodeGenModel> codeGenModels = new ArrayList<>();
- for (MetricDefinition metric : parser.getMetrics()) {
- CodeGenModel model = enricher.enrich(metric);
- codeGenModels.add(model);
- }
-
- // Build dispatcher context
- Map<String, OALClassGeneratorV2.DispatcherContextV2> dispatcherContextMap = new java.util.HashMap<>();
- for (CodeGenModel model : codeGenModels) {
- String sourceName = model.getSourceName();
- OALClassGeneratorV2.DispatcherContextV2 context = dispatcherContextMap.computeIfAbsent(sourceName, name -> {
- OALClassGeneratorV2.DispatcherContextV2 ctx = new OALClassGeneratorV2.DispatcherContextV2();
- ctx.setSourcePackage(define.getSourcePackage());
- ctx.setSourceName(name);
- ctx.setPackageName(name.toLowerCase());
- ctx.setSourceDecorator(model.getSourceDecorator());
- return ctx;
- });
- context.getMetrics().add(model);
- }
-
- // Generate classes using V2 generator (CtClass only, no JVM loading)
- V2ClassGenerator generator = new V2ClassGenerator(define, classPool);
- V2GeneratedClasses classes = new V2GeneratedClasses();
-
- for (CodeGenModel model : codeGenModels) {
- classes.metricsClasses.add(generator.generateMetricsCtClass(model));
- }
-
- for (Map.Entry<String, OALClassGeneratorV2.DispatcherContextV2> entry : dispatcherContextMap.entrySet()) {
- classes.dispatcherClasses.add(generator.generateDispatcherCtClass(entry.getKey(), entry.getValue()));
- }
-
- return classes;
- }
-
- /**
- * Container for V1 generated classes.
- */
- private static class V1GeneratedClasses {
- List<CtClass> metricsClasses = new ArrayList<>();
- List<CtClass> dispatcherClasses = new ArrayList<>();
- }
-
- /**
- * Container for V2 generated classes.
- */
- private static class V2GeneratedClasses {
- List<CtClass> metricsClasses = new ArrayList<>();
- List<CtClass> dispatcherClasses = new ArrayList<>();
- }
-
- /**
- * OALDefine for V1 engine tests.
- */
- private static class V1OALDefine extends OALDefine {
- protected V1OALDefine() {
- super("test-v1.oal", SOURCE_PACKAGE);
- }
- }
-
- /**
- * OALDefine for V2 engine tests.
- */
- private static class V2OALDefine extends OALDefine {
- protected V2OALDefine() {
- super("test-v2.oal", SOURCE_PACKAGE);
- }
- }
-}