未验证 提交 fb62025d 编写于 作者: wu-sheng's avatar wu-sheng 提交者: GitHub

Improve OAP extendibility (#2288)

* Make scope meta configurable.

* Fix test cases in ci.

* Change step 1

* Refactor step 2

* Other compile issue done. Prepare the generator changes.

* Revert some wrong changes to Istio receiver.

* Step 3, make compile pass.

* Try to make CI passed.

* Add a check.

* Fix generated code style

* Provide new and extendable dispatcher generator tool

* Fix startup.

* Can't guarantee the dispatchers are always existing. Put explicit comments at there to avoid confusion, since this is different with old version.

* Fix a H2 query for endpoint search.

* Fix a wrong mysql alarm query.

* Provide new document and `generate-tool-grammer` module.

* Add missing last section of document.

* Fix typo

* Relocate the @ScopeDeclaration annotation, make it more sense. Also remove the useless @SourceType annotation. And adjust document for these changes

* ScopeDeclaration can be used once for each class only, now.
上级 8b4de0d4
...@@ -30,7 +30,7 @@ For each official Apache release, there is a complete and independent source cod ...@@ -30,7 +30,7 @@ For each official Apache release, there is a complete and independent source cod
* `grpc-java` and `java` folders in **apm-protocol/apm-network/target/generated-sources/protobuf** * `grpc-java` and `java` folders in **apm-protocol/apm-network/target/generated-sources/protobuf**
* `grpc-java` and `java` folders in **oap-server/server-core/target/generated-sources/protobuf** * `grpc-java` and `java` folders in **oap-server/server-core/target/generated-sources/protobuf**
* `grpc-java` and `java` folders in **oap-server/server-receiver-plugin/skywalking-istio-telemetry-receiver-plugin/target/generated-sources/protobuf** * `grpc-java` and `java` folders in **oap-server/server-receiver-plugin/skywalking-istio-telemetry-receiver-plugin/target/generated-sources/protobuf**
* `antlr4` folder in **oap-server/generate-tool/target/generated-sources** * `antlr4` folder in **oap-server/generate-tool-grammar/target/generated-sources**
* `oal` folder in **oap-server/generated-analysis/target/generated-sources** * `oal` folder in **oap-server/generated-analysis/target/generated-sources**
## Setup your Eclipse IDE ## Setup your Eclipse IDE
......
...@@ -27,7 +27,7 @@ All the following channels are open to the community, you could choose the way y ...@@ -27,7 +27,7 @@ All the following channels are open to the community, you could choose the way y
As a develop, first step, read [Compiling Guide](How-to-build.md). It teaches developer how to build the project in local. As a develop, first step, read [Compiling Guide](How-to-build.md). It teaches developer how to build the project in local.
### Project Extensions ### Project Extensions
SkyWalking project supports many ways to extends existing features. If you are interesting in these ways, SkyWalking project supports many ways to extend existing features. If you are interesting in these ways,
read the following guides. read the following guides.
- [Java agent plugin development guide](Java-Plugin-Development-Guide.md). - [Java agent plugin development guide](Java-Plugin-Development-Guide.md).
...@@ -37,6 +37,11 @@ and private plugin developer should read this. ...@@ -37,6 +37,11 @@ and private plugin developer should read this.
- [Storage extension development guide](storage-extention.md). Help potential contributors to build a new - [Storage extension development guide](storage-extention.md). Help potential contributors to build a new
storage implementor besides the official. storage implementor besides the official.
- [Customize analysis by oal script](write-oal.md). Guide you to use oal script to make your own metric available. - [Customize analysis by oal script](write-oal.md). Guide you to use oal script to make your own metric available.
- [Source and scope extension for new metric](source-extension.md). If you want to analysis a new metric, which SkyWalking
haven't provide. You need to
add a new receiver rather than choosing [existed receiver](../setup/backend/backend-receivers.md).
At that moment,
you most likely need to add a new source and scope. This document will teach you how to do.
- [Backend Inventory entity extension](inventory-extension.md). If you want to extend SkyWalking inventory entities, and - [Backend Inventory entity extension](inventory-extension.md). If you want to extend SkyWalking inventory entities, and
want to push upstream back to our Apache OSS repo, please read these principles. want to push upstream back to our Apache OSS repo, please read these principles.
......
# Source and Scope extension for new metric
From [OAL scope introduction](../concepts-and-designs/oal.md#scope), you should already have understood what the scope is.
At here, as you want to do more extension, you need understand deeper, which is the **Source**.
**Source** and **Scope** are binding concepts. **Scope** declare the id(int) and name, **Source** declare the attributes.
Please follow these steps to create a new Source and Scope.
1. In the OAP core module, it provide **SourceReceiver** internal service.
```java
public interface SourceReceiver extends Service {
void receive(Source source);
}
```
2. All analysis data must be a **org.apache.skywalking.oap.server.core.source.Source** sub class,
tagged by `@SourceType` annotation, and in `org.apache.skywalking` package.
Then it could be supported by OAL script and OAP core.
Such as existed source, **Service**.
```java
@ScopeDeclaration(id = SERVICE, name = "Service")
public class Service extends Source {
@Override public int scope() {
return DefaultScopeDefine.SERVICE;
}
@Override public String getEntityId() {
return String.valueOf(id);
}
@Getter @Setter private int id;
@Getter @Setter private String name;
@Getter @Setter private String serviceInstanceName;
@Getter @Setter private String endpointName;
@Getter @Setter private int latency;
@Getter @Setter private boolean status;
@Getter @Setter private int responseCode;
@Getter @Setter private RequestType type;
}
```
3. The `scope()` method in Source, returns an ID, which is not a random number. This ID need to be declared through
`@ScopeDeclaration` annotation too. The ID in `@ScopeDeclaration` and ID in `scope()` method should be same for this Source.
4. The `String getEntityId()` method in Source, requests the return value representing unique entity which the scope related.
Such as,
in this Service scope, the id is service id, representing a particular service, like `Order` service.
This value is used in [OAL group mechanism](../concepts-and-designs/oal.md#group).
5. Add scope name as keyword to oal grammar definition file, `OALLexer.g4`, which is at `antlr4` folder of `generate-tool-grammar` module.
6. Add scope name keyword as source in parser definition file, `OALParser.g4`, which is at same fold of `OALLexer.g4`.
7. Set the default columns for new scope, at `generator-scope-meta.yml` file in `generated-analysis/src/main/resources`.
If you want to understand why need these columns, you have to understand all existing query(s). But there is an easy way,
follow other existing scopes. Such as, if you are adding metric, connection number for service instance, follow existing `ServiceInstance`.
___
After you done all of these, you could build a receiver, which do
1. Get the original data of the metric,
1. Build the source, send into `SourceReceiver`.
1. Write your whole OAL scripts.
1. Repackage the project.
\ No newline at end of file
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
* **apm-protocol/apm-network/target/generated-sources/protobuf** 文件夹下的`grpc-java``java` * **apm-protocol/apm-network/target/generated-sources/protobuf** 文件夹下的`grpc-java``java`
* **oap-server/server-core/target/generated-sources/protobuf** 文件夹下的`grpc-java``java` * **oap-server/server-core/target/generated-sources/protobuf** 文件夹下的`grpc-java``java`
* **oap-server/server-receiver-plugin/skywalking-istio-telemetry-receiver-plugin/target/generated-sources/protobuf** 文件夹下的`grpc-java``java` * **oap-server/server-receiver-plugin/skywalking-istio-telemetry-receiver-plugin/target/generated-sources/protobuf** 文件夹下的`grpc-java``java`
* **oap-server/generate-tool/target/generated-sources** 文件夹下的 `antlr4` * **oap-server/generate-tool-grammar/target/generated-sources** 文件夹下的 `antlr4`
* **oap-server/generated-analysis/target/generated-sources** 文件夹下的 `oal` * **oap-server/generated-analysis/target/generated-sources** 文件夹下的 `oal`
## 设置Eclipse IDE ## 设置Eclipse IDE
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>oap-server</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>6.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>generate-tool-grammar</artifactId>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId>
<version>4.7.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.7.1</version>
<executions>
<execution>
<id>antlr</id>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
...@@ -33,6 +33,11 @@ ...@@ -33,6 +33,11 @@
<artifactId>server-core</artifactId> <artifactId>server-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>generate-tool-grammar</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.antlr</groupId> <groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId> <artifactId>antlr4</artifactId>
...@@ -54,22 +59,4 @@ ...@@ -54,22 +59,4 @@
<version>2.3.28</version> <version>2.3.28</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.7.1</version>
<executions>
<execution>
<id>antlr</id>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> </project>
\ No newline at end of file
...@@ -22,17 +22,25 @@ import freemarker.template.TemplateException; ...@@ -22,17 +22,25 @@ import freemarker.template.TemplateException;
import java.io.*; import java.io.*;
import java.util.List; import java.util.List;
import org.apache.skywalking.apm.util.StringUtil; import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oal.tool.meta.*;
import org.apache.skywalking.oal.tool.output.FileGenerator; import org.apache.skywalking.oal.tool.output.FileGenerator;
import org.apache.skywalking.oal.tool.parser.*; import org.apache.skywalking.oal.tool.parser.*;
import org.apache.skywalking.oap.server.core.annotation.AnnotationScan;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
public class Main { public class Main {
public static void main(String[] args) throws IOException, TemplateException { public static void main(String[] args) throws IOException, TemplateException {
AnnotationScan scopeScan = new AnnotationScan();
scopeScan.registerListener(new DefaultScopeDefine.Listener());
scopeScan.scan(null);
String modulePath = args[0]; String modulePath = args[0];
String scriptFilePath = StringUtil.join(File.separatorChar, modulePath, "src", "main", "resources", "official_analysis.oal"); String scriptFilePath = StringUtil.join(File.separatorChar, modulePath, "src", "main", "resources", "official_analysis.oal");
String outputPath = StringUtil.join(File.separatorChar, modulePath, "..", "generated-analysis", "target", "generated-sources", "oal", String outputPath = StringUtil.join(File.separatorChar, modulePath, "..", "generated-analysis", "target", "generated-sources", "oal",
"org", "apache", "skywalking", "oap", "server", "core", "analysis"); "org", "apache", "skywalking", "oap", "server", "core", "analysis");
String metaFilePath = StringUtil.join(File.separatorChar, modulePath, "src", "main", "resources", "generator-scope-meta.yml");
Indicators.init(); Indicators.init();
...@@ -41,6 +49,15 @@ public class Main { ...@@ -41,6 +49,15 @@ public class Main {
throw new IllegalArgumentException("OAL script file [" + scriptFilePath + "] doesn't exist"); throw new IllegalArgumentException("OAL script file [" + scriptFilePath + "] doesn't exist");
} }
File metaFile = new File(metaFilePath);
if (!metaFile.exists()) {
throw new IllegalArgumentException("Generator meta file [" + metaFilePath + "] doesn't exist");
}
MetaReader reader = new MetaReader();
MetaSettings metaSettings = reader.read(new FileInputStream(metaFile));
SourceColumnsFactory.setSettings(metaSettings);
ScriptParser scriptParser = ScriptParser.createFromFile(scriptFilePath); ScriptParser scriptParser = ScriptParser.createFromFile(scriptFilePath);
List<AnalysisResult> analysisResults = scriptParser.parse(); List<AnalysisResult> analysisResults = scriptParser.parse();
......
/*
* 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.tool.meta;
import java.io.InputStream;
import org.yaml.snakeyaml.Yaml;
/**
* @author wusheng
*/
public class MetaReader {
public MetaSettings read(InputStream settingFileStream) {
Yaml yaml = new Yaml();
MetaSettings settings = yaml.loadAs(settingFileStream, MetaSettings.class);
return settings;
}
}
...@@ -16,14 +16,16 @@ ...@@ -16,14 +16,16 @@
* *
*/ */
package org.apache.skywalking.oap.server.core.source.annotation; package org.apache.skywalking.oal.tool.meta;
import java.lang.annotation.*; import java.util.List;
import lombok.*;
/** /**
* @author peng-yongsheng * @author wusheng
*/ */
@Target(ElementType.TYPE) @Setter
@Retention(RetentionPolicy.SOURCE) @Getter
public @interface SourceType { public class MetaSettings {
private List<ScopeMeta> scopes;
} }
/*
* 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.tool.meta;
import java.util.*;
import lombok.*;
import org.apache.skywalking.oal.tool.parser.SourceColumn;
/**
* @author wusheng
*/
@Setter
@Getter
public class ScopeMeta {
private String name;
private List<SourceColumn> columns = new ArrayList<>();
}
/*
* 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.tool.output;
import java.util.*;
import lombok.*;
@Getter
@Setter
public class AllDispatcherContext {
private Map<String, DispatcherContext> allContext = new HashMap<>();
}
...@@ -22,19 +22,10 @@ import java.util.*; ...@@ -22,19 +22,10 @@ import java.util.*;
import lombok.*; import lombok.*;
import org.apache.skywalking.oal.tool.parser.AnalysisResult; import org.apache.skywalking.oal.tool.parser.AnalysisResult;
@Getter(AccessLevel.PUBLIC) @Getter
@Setter(AccessLevel.PUBLIC) @Setter
public class DispatcherContext { public class DispatcherContext {
private List<AnalysisResult> allIndicators = new LinkedList<>(); private String source;
private List<AnalysisResult> serviceIndicators = new LinkedList<>(); private String packageName;
private List<AnalysisResult> serviceInstanceIndicators = new LinkedList<>(); private List<AnalysisResult> indicators = new ArrayList<>();
private List<AnalysisResult> endpointIndicators = new LinkedList<>();
private List<AnalysisResult> serviceRelationIndicators = new LinkedList<>();
private List<AnalysisResult> serviceInstanceRelationIndicators = new LinkedList<>();
private List<AnalysisResult> endpointRelationIndicators = new LinkedList<>();
private List<AnalysisResult> serviceInstanceJVMCPUIndicators = new LinkedList<>();
private List<AnalysisResult> serviceInstanceJVMMemoryIndicators = new LinkedList<>();
private List<AnalysisResult> serviceInstanceJVMMemoryPoolIndicators = new LinkedList<>();
private List<AnalysisResult> serviceInstanceJVMGCIndicators = new LinkedList<>();
private List<AnalysisResult> databaseAccessIndicators = new LinkedList<>();
} }
...@@ -27,7 +27,7 @@ public class FileGenerator { ...@@ -27,7 +27,7 @@ public class FileGenerator {
private List<AnalysisResult> results; private List<AnalysisResult> results;
private String outputPath; private String outputPath;
private Configuration configuration; private Configuration configuration;
private DispatcherContext dispatcherContext; private AllDispatcherContext allDispatcherContext;
public FileGenerator(List<AnalysisResult> results, String outputPath) { public FileGenerator(List<AnalysisResult> results, String outputPath) {
this.results = results; this.results = results;
...@@ -35,61 +35,19 @@ public class FileGenerator { ...@@ -35,61 +35,19 @@ public class FileGenerator {
configuration = new Configuration(new Version("2.3.28")); configuration = new Configuration(new Version("2.3.28"));
configuration.setEncoding(Locale.ENGLISH, "UTF-8"); configuration.setEncoding(Locale.ENGLISH, "UTF-8");
configuration.setClassLoaderForTemplateLoading(FileGenerator.class.getClassLoader(), "/code-templates"); configuration.setClassLoaderForTemplateLoading(FileGenerator.class.getClassLoader(), "/code-templates");
this.toDispatchers(); allDispatcherContext = new AllDispatcherContext();
buildDispatcherContext();
} }
public void generate() throws IOException, TemplateException { public void generate() throws IOException, TemplateException {
for (AnalysisResult result : results) { for (AnalysisResult result : results) {
generate(result, "Indicator.java", writer -> generateIndicatorImplementor(result, writer)); generate(result, "Indicator.java", writer -> generateIndicatorImplementor(result, writer));
}
File file = new File(outputPath, "generated/all/AllDispatcher.java");
createFile(file);
this.generateAllDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/service/ServiceDispatcher.java");
createFile(file);
this.generateServiceDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/databaseaccess/DatabaseAccessDispatcher.java");
createFile(file);
this.generateDatabaseAccessDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/servicerelation/ServiceRelationDispatcher.java");
createFile(file);
this.generateServiceRelationDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/endpoint/EndpointDispatcher.java");
createFile(file);
this.generateEndpointDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/endpointrelation/EndpointRelationDispatcher.java");
createFile(file);
this.generateEndpointRelationDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/serviceinstance/ServiceInstanceDispatcher.java"); String scopeName = result.getSourceName();
createFile(file); File file = new File(outputPath, "generated/" + scopeName.toLowerCase() + "/" + scopeName + "Dispatcher.java");
this.generateServiceInstanceDispatcher(new FileWriter(file)); createFile(file);
generateDispatcher(result, new FileWriter(file));
file = new File(outputPath, "generated/serviceinstancerelation/ServiceInstanceRelationDispatcher.java"); }
createFile(file);
this.generateServiceInstanceRelationDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/serviceinstancejvmcpu/ServiceInstanceJVMCPUDispatcher.java");
createFile(file);
this.generateServiceInstanceJVMCPUDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/serviceinstancejvmmemory/ServiceInstanceJVMMemoryDispatcher.java");
createFile(file);
this.generateServiceInstanceJVMMemoryDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/serviceinstancejvmmemorypool/ServiceInstanceJVMMemoryPoolDispatcher.java");
createFile(file);
this.generateServiceInstanceJVMMemoryPoolDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/serviceinstancejvmgc/ServiceInstanceJVMGCDispatcher.java");
createFile(file);
this.generateServiceInstanceJVMGCDispatcher(new FileWriter(file));
} }
private void generate(AnalysisResult result, String fileSuffix, private void generate(AnalysisResult result, String fileSuffix,
...@@ -123,98 +81,26 @@ public class FileGenerator { ...@@ -123,98 +81,26 @@ public class FileGenerator {
configuration.getTemplate("IndicatorImplementor.ftl").process(result, output); configuration.getTemplate("IndicatorImplementor.ftl").process(result, output);
} }
void generateAllDispatcher(Writer output) throws IOException, TemplateException { void generateDispatcher(AnalysisResult result, Writer output) throws IOException, TemplateException {
configuration.getTemplate("AllDispatcherTemplate.ftl").process(dispatcherContext, output); String scopeName = result.getSourceName();
} DispatcherContext context = allDispatcherContext.getAllContext().get(scopeName);
if (context != null) {
void generateServiceDispatcher(Writer output) throws IOException, TemplateException { configuration.getTemplate("DispatcherTemplate.ftl").process(context, output);
configuration.getTemplate("ServiceDispatcherTemplate.ftl").process(dispatcherContext, output); }
}
void generateDatabaseAccessDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("DatabaseAccessDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceRelationDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceRelationDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateEndpointDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("EndpointDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateEndpointRelationDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("EndpointRelationDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceRelationDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceRelationDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceJVMCPUDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceJVMCPUDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceJVMMemoryDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceJVMMemoryDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceJVMMemoryPoolDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceJVMMemoryPoolDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceJVMGCDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceJVMGCDispatcherTemplate.ftl").process(dispatcherContext, output);
} }
private void toDispatchers() { private void buildDispatcherContext() {
dispatcherContext = new DispatcherContext();
for (AnalysisResult result : results) { for (AnalysisResult result : results) {
String sourceName = result.getSourceName(); String sourceName = result.getSourceName();
switch (sourceName) {
case "All": DispatcherContext context = allDispatcherContext.getAllContext().get(sourceName);
dispatcherContext.getAllIndicators().add(result); if (context == null) {
break; context = new DispatcherContext();
case "Service": context.setSource(sourceName);
dispatcherContext.getServiceIndicators().add(result); context.setPackageName(sourceName.toLowerCase());
break; allDispatcherContext.getAllContext().put(sourceName, context);
case "ServiceRelation":
dispatcherContext.getServiceRelationIndicators().add(result);
break;
case "ServiceInstance":
dispatcherContext.getServiceInstanceIndicators().add(result);
break;
case "ServiceInstanceRelation":
dispatcherContext.getServiceInstanceRelationIndicators().add(result);
break;
case "Endpoint":
dispatcherContext.getEndpointIndicators().add(result);
break;
case "EndpointRelation":
dispatcherContext.getEndpointRelationIndicators().add(result);
break;
case "ServiceInstanceJVMCPU":
dispatcherContext.getServiceInstanceJVMCPUIndicators().add(result);
break;
case "ServiceInstanceJVMMemory":
dispatcherContext.getServiceInstanceJVMMemoryIndicators().add(result);
break;
case "ServiceInstanceJVMMemoryPool":
dispatcherContext.getServiceInstanceJVMMemoryPoolIndicators().add(result);
break;
case "ServiceInstanceJVMGC":
dispatcherContext.getServiceInstanceJVMGCIndicators().add(result);
break;
case "DatabaseAccess":
dispatcherContext.getDatabaseAccessIndicators().add(result);
break;
default:
throw new RuntimeException("Unexpected dispatcher");
} }
context.getIndicators().add(result);
} }
} }
} }
...@@ -34,6 +34,8 @@ public class AnalysisResult { ...@@ -34,6 +34,8 @@ public class AnalysisResult {
private String sourceName; private String sourceName;
private int sourceScopeId;
private String sourceAttribute; private String sourceAttribute;
private String aggregationFunctionName; private String aggregationFunctionName;
......
...@@ -21,6 +21,7 @@ package org.apache.skywalking.oal.tool.parser; ...@@ -21,6 +21,7 @@ package org.apache.skywalking.oal.tool.parser;
import java.util.List; import java.util.List;
import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.misc.NotNull;
import org.apache.skywalking.oal.tool.grammar.*; import org.apache.skywalking.oal.tool.grammar.*;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
public class OALListener extends OALParserBaseListener { public class OALListener extends OALParserBaseListener {
private List<AnalysisResult> results; private List<AnalysisResult> results;
...@@ -46,6 +47,7 @@ public class OALListener extends OALParserBaseListener { ...@@ -46,6 +47,7 @@ public class OALListener extends OALParserBaseListener {
@Override public void enterSource(OALParser.SourceContext ctx) { @Override public void enterSource(OALParser.SourceContext ctx) {
current.setSourceName(ctx.getText()); current.setSourceName(ctx.getText());
current.setSourceScopeId(DefaultScopeDefine.valueOf(metricNameFormat(ctx.getText())));
} }
@Override @Override
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.skywalking.oal.tool.parser; package org.apache.skywalking.oal.tool.parser;
import java.util.Objects;
import lombok.*; import lombok.*;
import org.apache.skywalking.oal.tool.util.ClassMethodUtil; import org.apache.skywalking.oal.tool.util.ClassMethodUtil;
...@@ -32,6 +33,9 @@ public class SourceColumn { ...@@ -32,6 +33,9 @@ public class SourceColumn {
private String fieldSetter; private String fieldSetter;
private String fieldGetter; private String fieldGetter;
public SourceColumn() {
}
public SourceColumn(String fieldName, String columnName, Class<?> type, boolean isID) { public SourceColumn(String fieldName, String columnName, Class<?> type, boolean isID) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.columnName = columnName; this.columnName = columnName;
...@@ -43,6 +47,35 @@ public class SourceColumn { ...@@ -43,6 +47,35 @@ public class SourceColumn {
this.fieldSetter = ClassMethodUtil.toSetMethod(fieldName); this.fieldSetter = ClassMethodUtil.toSetMethod(fieldName);
} }
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";
default:
try {
this.type = Class.forName(typeName);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
this.typeName = typeName;
}
@Override public String toString() { @Override public String toString() {
return "SourceColumn{" + return "SourceColumn{" +
"fieldName='" + fieldName + '\'' + "fieldName='" + fieldName + '\'' +
...@@ -51,4 +84,23 @@ public class SourceColumn { ...@@ -51,4 +84,23 @@ public class SourceColumn {
", isID=" + isID + ", isID=" + isID +
'}'; '}';
} }
@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);
}
} }
...@@ -19,85 +19,22 @@ ...@@ -19,85 +19,22 @@
package org.apache.skywalking.oal.tool.parser; package org.apache.skywalking.oal.tool.parser;
import java.util.*; import java.util.*;
import org.apache.skywalking.oal.tool.meta.*;
/**
* @author wusheng
*/
public class SourceColumnsFactory { public class SourceColumnsFactory {
public static List<SourceColumn> getColumns(String source) { private static Map<String, ScopeMeta> SETTINGS;
List<SourceColumn> columnList;
SourceColumn idColumn;
switch (source) {
case "All":
return new LinkedList<>();
case "Service":
columnList = new LinkedList<>();
// Service id;
idColumn = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(idColumn);
return columnList;
case "ServiceInstance":
columnList = new LinkedList<>();
// Service instance id;
idColumn = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(idColumn);
SourceColumn serviceIdColumn = new SourceColumn("serviceId", "service_id", int.class, false);
columnList.add(serviceIdColumn);
return columnList;
case "Endpoint":
columnList = new LinkedList<>();
// Endpoint id;
idColumn = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(idColumn);
serviceIdColumn = new SourceColumn("serviceId", "service_id", int.class, false);
columnList.add(serviceIdColumn);
SourceColumn serviceInstanceIdColumn = new SourceColumn("serviceInstanceId", "service_instance_id", int.class, false);
columnList.add(serviceInstanceIdColumn);
return columnList;
case "ServiceInstanceJVMCPU":
case "ServiceInstanceJVMMemory":
case "ServiceInstanceJVMMemoryPool":
case "ServiceInstanceJVMGC":
columnList = new LinkedList<>();
// Service instance id;
idColumn = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(idColumn);
serviceInstanceIdColumn = new SourceColumn("serviceInstanceId", "service_instance_id", int.class, false);
columnList.add(serviceInstanceIdColumn);
return columnList;
case "ServiceRelation":
columnList = new LinkedList<>();
SourceColumn sourceService = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(sourceService);
return columnList;
case "ServiceInstanceRelation":
columnList = new LinkedList<>();
sourceService = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(sourceService);
sourceService = new SourceColumn("sourceServiceId", "source_service_id", int.class, false);
columnList.add(sourceService);
SourceColumn destService = new SourceColumn("destServiceId", "destServiceId", int.class, false);
columnList.add(destService);
return columnList; public static void setSettings(MetaSettings settings) {
case "EndpointRelation": SourceColumnsFactory.SETTINGS = new HashMap<>();
columnList = new LinkedList<>(); settings.getScopes().forEach(scope -> {
SourceColumn sourceEndpointColumn = new SourceColumn("entityId", "entity_id", String.class, true); SourceColumnsFactory.SETTINGS.put(scope.getName(), scope);
columnList.add(sourceEndpointColumn); });
sourceService = new SourceColumn("serviceId", "service_id", int.class, false); }
columnList.add(sourceService);
destService = new SourceColumn("childServiceId", "child_service_id", int.class, false); public static List<SourceColumn> getColumns(String source) {
columnList.add(destService); return SETTINGS.get(source).getColumns();
SourceColumn sourceServiceInstance = new SourceColumn("serviceInstanceId", "service_instance_id", int.class, false);
columnList.add(sourceServiceInstance);
SourceColumn destServiceInstance = new SourceColumn("childServiceInstanceId", "child_service_instance_id", int.class, false);
columnList.add(destServiceInstance);
return columnList;
case "DatabaseAccess":
columnList = new LinkedList<>();
// Service id;
idColumn = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(idColumn);
return columnList;
default:
throw new IllegalArgumentException("Illegal source :" + source);
}
} }
} }
/*
* 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.oap.server.core.analysis.generated.databaseaccess;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (databaseAccessIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list databaseAccessIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class DatabaseAccessDispatcher implements SourceDispatcher<DatabaseAccess> {
@Override public void dispatch(DatabaseAccess source) {
<#list databaseAccessIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list databaseAccessIndicators as indicator>
private void do${indicator.metricName}(DatabaseAccess source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
* *
*/ */
package org.apache.skywalking.oap.server.core.analysis.generated.all; package org.apache.skywalking.oap.server.core.analysis.generated.${packageName};
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher; import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (allIndicators?size>0)> <#if (indicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess; import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list allIndicators as indicator> <#list indicators as indicator>
<#if indicator.filterExpressions??> <#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*; import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break> <#break>
...@@ -35,16 +35,16 @@ import org.apache.skywalking.oap.server.core.source.*; ...@@ -35,16 +35,16 @@ import org.apache.skywalking.oap.server.core.source.*;
* *
* @author Observability Analysis Language code generator * @author Observability Analysis Language code generator
*/ */
public class AllDispatcher implements SourceDispatcher<All> { public class ${source}Dispatcher implements SourceDispatcher<${source}> {
@Override public void dispatch(All source) { @Override public void dispatch(${source} source) {
<#list allIndicators as indicator> <#list indicators as indicator>
do${indicator.metricName}(source); do${indicator.metricName}(source);
</#list> </#list>
} }
<#list allIndicators as indicator> <#list indicators as indicator>
private void do${indicator.metricName}(All source) { private void do${indicator.metricName}(${source} source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator(); ${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??> <#if indicator.filterExpressions??>
......
/*
* 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.oap.server.core.analysis.generated.endpoint;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (endpointIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list endpointIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class EndpointDispatcher implements SourceDispatcher<Endpoint> {
@Override public void dispatch(Endpoint source) {
<#list endpointIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list endpointIndicators as indicator>
private void do${indicator.metricName}(Endpoint source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}
/*
* 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.oap.server.core.analysis.generated.endpointrelation;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (endpointRelationIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list endpointRelationIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class EndpointRelationDispatcher implements SourceDispatcher<EndpointRelation> {
@Override public void dispatch(EndpointRelation source) {
<#list endpointRelationIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list endpointRelationIndicators as indicator>
private void do${indicator.metricName}(EndpointRelation source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}
...@@ -36,7 +36,6 @@ import org.apache.skywalking.oap.server.core.remote.annotation.StreamData; ...@@ -36,7 +36,6 @@ import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.source.Scope;
/** /**
* This class is auto generated. Please don't change this class manually. * This class is auto generated. Please don't change this class manually.
...@@ -45,7 +44,7 @@ import org.apache.skywalking.oap.server.core.source.Scope; ...@@ -45,7 +44,7 @@ import org.apache.skywalking.oap.server.core.source.Scope;
*/ */
@IndicatorType @IndicatorType
@StreamData @StreamData
@StorageEntity(name = "${tableName}", builder = ${metricName}Indicator.Builder.class, source = Scope.${sourceName}) @StorageEntity(name = "${tableName}", builder = ${metricName}Indicator.Builder.class, sourceScopeId = ${sourceScopeId})
public class ${metricName}Indicator extends ${indicatorClassName} implements AlarmSupported { public class ${metricName}Indicator extends ${indicatorClassName} implements AlarmSupported {
<#list fieldsFromSource as sourceField> <#list fieldsFromSource as sourceField>
...@@ -172,7 +171,7 @@ public class ${metricName}Indicator extends ${indicatorClassName} implements Ala ...@@ -172,7 +171,7 @@ public class ${metricName}Indicator extends ${indicatorClassName} implements Ala
} }
@Override public AlarmMeta getAlarmMeta() { @Override public AlarmMeta getAlarmMeta() {
return new AlarmMeta("${varName}", Scope.${sourceName}<#if (fieldsFromSource?size>0) ><#list fieldsFromSource as field><#if field.isID()>, ${field.fieldName}</#if></#list></#if>); return new AlarmMeta("${varName}", ${sourceScopeId}<#if (fieldsFromSource?size>0) ><#list fieldsFromSource as field><#if field.isID()>, ${field.fieldName}</#if></#list></#if>);
} }
@Override @Override
......
/*
* 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.oap.server.core.analysis.generated.service;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceDispatcher implements SourceDispatcher<Service> {
@Override public void dispatch(Service source) {
<#list serviceIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceIndicators as indicator>
private void do${indicator.metricName}(Service source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}
/*
* 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.oap.server.core.analysis.generated.serviceinstance;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceDispatcher implements SourceDispatcher<ServiceInstance> {
@Override public void dispatch(ServiceInstance source) {
<#list serviceInstanceIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceIndicators as indicator>
private void do${indicator.metricName}(ServiceInstance source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}
/*
* 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.oap.server.core.analysis.generated.serviceinstancejvmcpu;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceJVMCPUIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceJVMCPUIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceJVMCPUDispatcher implements SourceDispatcher<ServiceInstanceJVMCPU> {
@Override public void dispatch(ServiceInstanceJVMCPU source) {
<#list serviceInstanceJVMCPUIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceJVMCPUIndicators as indicator>
private void do${indicator.metricName}(ServiceInstanceJVMCPU source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}
/*
* 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.oap.server.core.analysis.generated.serviceinstancejvmgc;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceJVMGCIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceJVMGCIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceJVMGCDispatcher implements SourceDispatcher<ServiceInstanceJVMGC> {
@Override public void dispatch(ServiceInstanceJVMGC source) {
<#list serviceInstanceJVMGCIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceJVMGCIndicators as indicator>
private void do${indicator.metricName}(ServiceInstanceJVMGC source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}
/*
* 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.oap.server.core.analysis.generated.serviceinstancejvmmemory;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceJVMMemoryIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceJVMMemoryIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceJVMMemoryDispatcher implements SourceDispatcher<ServiceInstanceJVMMemory> {
@Override public void dispatch(ServiceInstanceJVMMemory source) {
<#list serviceInstanceJVMMemoryIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceJVMMemoryIndicators as indicator>
private void do${indicator.metricName}(ServiceInstanceJVMMemory source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}
/*
* 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.oap.server.core.analysis.generated.serviceinstancejvmmemorypool;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceJVMMemoryPoolIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceJVMMemoryPoolIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceJVMMemoryPoolDispatcher implements SourceDispatcher<ServiceInstanceJVMMemoryPool> {
@Override public void dispatch(ServiceInstanceJVMMemoryPool source) {
<#list serviceInstanceJVMMemoryPoolIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceJVMMemoryPoolIndicators as indicator>
private void do${indicator.metricName}(ServiceInstanceJVMMemoryPool source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}
/*
* 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.oap.server.core.analysis.generated.serviceinstancerelation;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceRelationIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceRelationIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceRelationDispatcher implements SourceDispatcher<ServiceInstanceRelation> {
@Override public void dispatch(ServiceInstanceRelation source) {
<#list serviceInstanceRelationIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceRelationIndicators as indicator>
private void do${indicator.metricName}(ServiceInstanceRelation source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}
/*
* 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.oap.server.core.analysis.generated.servicerelation;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceRelationIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceRelationIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceRelationDispatcher implements SourceDispatcher<ServiceRelation> {
@Override public void dispatch(ServiceRelation source) {
<#list serviceRelationIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceRelationIndicators as indicator>
private void do${indicator.metricName}(ServiceRelation source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}
/*
* 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.tool.meta;
import java.io.InputStream;
import java.util.List;
import org.apache.skywalking.oal.tool.parser.SourceColumn;
import org.junit.*;
public class MetaReaderTest {
@Test
public void testFileParser() {
MetaReader reader = new MetaReader();
InputStream stream = MetaReaderTest.class.getResourceAsStream("/scope-meta.yml");
MetaSettings metaSettings = reader.read(stream);
Assert.assertNotEquals(0, metaSettings.getScopes().size());
metaSettings.getScopes().forEach(scopeMeta -> {
List<SourceColumn> sourceColumns = MockSourceColumnsFactory.getColumns(scopeMeta.getName());
for (int i = 0; i < sourceColumns.size(); i++) {
SourceColumn column = scopeMeta.getColumns().get(i);
SourceColumn expected = sourceColumns.get(i);
Assert.assertEquals(expected, column);
}
});
}
}
/*
* 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.tool.meta;
import java.util.*;
import org.apache.skywalking.oal.tool.parser.SourceColumn;
public class MockSourceColumnsFactory {
public static List<SourceColumn> getColumns(String source) {
List<SourceColumn> columnList;
SourceColumn idColumn;
switch (source) {
case "All":
return new LinkedList<>();
case "Service":
columnList = new LinkedList<>();
// Service id;
idColumn = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(idColumn);
return columnList;
case "ServiceInstance":
columnList = new LinkedList<>();
// Service instance id;
idColumn = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(idColumn);
SourceColumn serviceIdColumn = new SourceColumn("serviceId", "service_id", int.class, false);
columnList.add(serviceIdColumn);
return columnList;
case "Endpoint":
columnList = new LinkedList<>();
// Endpoint id;
idColumn = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(idColumn);
serviceIdColumn = new SourceColumn("serviceId", "service_id", int.class, false);
columnList.add(serviceIdColumn);
SourceColumn serviceInstanceIdColumn = new SourceColumn("serviceInstanceId", "service_instance_id", int.class, false);
columnList.add(serviceInstanceIdColumn);
return columnList;
case "ServiceInstanceJVMCPU":
case "ServiceInstanceJVMMemory":
case "ServiceInstanceJVMMemoryPool":
case "ServiceInstanceJVMGC":
columnList = new LinkedList<>();
// Service instance id;
idColumn = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(idColumn);
serviceInstanceIdColumn = new SourceColumn("serviceInstanceId", "service_instance_id", int.class, false);
columnList.add(serviceInstanceIdColumn);
return columnList;
case "ServiceRelation":
columnList = new LinkedList<>();
SourceColumn sourceService = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(sourceService);
return columnList;
case "ServiceInstanceRelation":
columnList = new LinkedList<>();
sourceService = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(sourceService);
sourceService = new SourceColumn("sourceServiceId", "source_service_id", int.class, false);
columnList.add(sourceService);
SourceColumn destService = new SourceColumn("destServiceId", "dest_service_id", int.class, false);
columnList.add(destService);
return columnList;
case "EndpointRelation":
columnList = new LinkedList<>();
SourceColumn sourceEndpointColumn = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(sourceEndpointColumn);
sourceService = new SourceColumn("serviceId", "service_id", int.class, false);
columnList.add(sourceService);
destService = new SourceColumn("childServiceId", "child_service_id", int.class, false);
columnList.add(destService);
SourceColumn sourceServiceInstance = new SourceColumn("serviceInstanceId", "service_instance_id", int.class, false);
columnList.add(sourceServiceInstance);
SourceColumn destServiceInstance = new SourceColumn("childServiceInstanceId", "child_service_instance_id", int.class, false);
columnList.add(destServiceInstance);
return columnList;
case "DatabaseAccess":
columnList = new LinkedList<>();
// Service id;
idColumn = new SourceColumn("entityId", "entity_id", String.class, true);
columnList.add(idColumn);
return columnList;
default:
throw new IllegalArgumentException("Illegal sourceScopeId :" + source);
}
}
}
...@@ -21,14 +21,24 @@ package org.apache.skywalking.oal.tool.output; ...@@ -21,14 +21,24 @@ package org.apache.skywalking.oal.tool.output;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import org.apache.skywalking.oal.tool.meta.*;
import org.apache.skywalking.oal.tool.parser.*; import org.apache.skywalking.oal.tool.parser.*;
import org.junit.*; import org.junit.*;
public class FileGeneratorTest { public class FileGeneratorTest {
@BeforeClass
public static void init() {
MetaReader reader = new MetaReader();
InputStream stream = MetaReaderTest.class.getResourceAsStream("/scope-meta.yml");
MetaSettings metaSettings = reader.read(stream);
SourceColumnsFactory.setSettings(metaSettings);
}
private AnalysisResult buildResult() { private AnalysisResult buildResult() {
AnalysisResult result = new AnalysisResult(); AnalysisResult result = new AnalysisResult();
result.setVarName("generate_indicator"); result.setVarName("generate_indicator");
result.setSourceName("Service"); result.setSourceName("Service");
result.setSourceScopeId(1);
result.setPackageName("service.serviceavg"); result.setPackageName("service.serviceavg");
result.setTableName("service_avg"); result.setTableName("service_avg");
result.setSourceAttribute("latency"); result.setSourceAttribute("latency");
...@@ -83,7 +93,7 @@ public class FileGeneratorTest { ...@@ -83,7 +93,7 @@ public class FileGeneratorTest {
FileGenerator fileGenerator = new FileGenerator(results, "."); FileGenerator fileGenerator = new FileGenerator(results, ".");
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
fileGenerator.generateServiceDispatcher(writer); fileGenerator.generateDispatcher(result, writer);
Assert.assertEquals(readExpectedFile("ServiceDispatcherExpected.java"), writer.toString()); Assert.assertEquals(readExpectedFile("ServiceDispatcherExpected.java"), writer.toString());
//fileGenerator.generateServiceDispatcher(new OutputStreamWriter(System.out)); //fileGenerator.generateServiceDispatcher(new OutputStreamWriter(System.out));
......
...@@ -18,13 +18,18 @@ ...@@ -18,13 +18,18 @@
package org.apache.skywalking.oal.tool.parser; package org.apache.skywalking.oal.tool.parser;
import java.io.IOException; import java.io.*;
import java.util.List; import java.util.List;
import org.apache.skywalking.oal.tool.meta.*;
import org.junit.*; import org.junit.*;
public class DeepAnalysisTest { public class DeepAnalysisTest {
@BeforeClass @BeforeClass
public static void init() throws IOException { public static void init() throws IOException {
MetaReader reader = new MetaReader();
InputStream stream = MetaReaderTest.class.getResourceAsStream("/scope-meta.yml");
MetaSettings metaSettings = reader.read(stream);
SourceColumnsFactory.setSettings(metaSettings);
Indicators.init(); Indicators.init();
} }
......
...@@ -18,14 +18,30 @@ ...@@ -18,14 +18,30 @@
package org.apache.skywalking.oal.tool.parser; package org.apache.skywalking.oal.tool.parser;
import java.io.IOException; import java.io.*;
import java.util.List; import java.util.List;
import org.apache.skywalking.oal.tool.meta.*;
import org.apache.skywalking.oap.server.core.annotation.AnnotationScan;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.junit.*; import org.junit.*;
public class ScriptParserTest { public class ScriptParserTest {
@BeforeClass @BeforeClass
public static void init() throws IOException { public static void init() throws IOException {
MetaReader reader = new MetaReader();
InputStream stream = MetaReaderTest.class.getResourceAsStream("/scope-meta.yml");
MetaSettings metaSettings = reader.read(stream);
SourceColumnsFactory.setSettings(metaSettings);
Indicators.init(); Indicators.init();
AnnotationScan scopeScan = new AnnotationScan();
scopeScan.registerListener(new DefaultScopeDefine.Listener());
scopeScan.scan(null);
}
@AfterClass
public static void clear() {
DefaultScopeDefine.reset();
} }
@Test @Test
......
...@@ -29,7 +29,6 @@ import org.apache.skywalking.oap.server.core.remote.annotation.StreamData; ...@@ -29,7 +29,6 @@ import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.source.Scope;
/** /**
* This class is auto generated. Please don't change this class manually. * This class is auto generated. Please don't change this class manually.
...@@ -38,7 +37,7 @@ import org.apache.skywalking.oap.server.core.source.Scope; ...@@ -38,7 +37,7 @@ import org.apache.skywalking.oap.server.core.source.Scope;
*/ */
@IndicatorType @IndicatorType
@StreamData @StreamData
@StorageEntity(name = "service_avg", builder = ServiceAvgIndicator.Builder.class, source = Scope.Service) @StorageEntity(name = "service_avg", builder = ServiceAvgIndicator.Builder.class, sourceScopeId = 1)
public class ServiceAvgIndicator extends LongAvgIndicator implements AlarmSupported { public class ServiceAvgIndicator extends LongAvgIndicator implements AlarmSupported {
@Setter @Getter @Column(columnName = "entity_id") @IDColumn private java.lang.String entityId; @Setter @Getter @Column(columnName = "entity_id") @IDColumn private java.lang.String entityId;
...@@ -110,7 +109,7 @@ public class ServiceAvgIndicator extends LongAvgIndicator implements AlarmSuppor ...@@ -110,7 +109,7 @@ public class ServiceAvgIndicator extends LongAvgIndicator implements AlarmSuppor
} }
@Override public AlarmMeta getAlarmMeta() { @Override public AlarmMeta getAlarmMeta() {
return new AlarmMeta("generate_indicator", Scope.Service, entityId); return new AlarmMeta("generate_indicator", 1, entityId);
} }
@Override @Override
......
# 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.
scopes:
- name: All
- name: Service
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- name: ServiceInstance
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceId
columnName: service_id
typeName: int
ID: false
- name: Endpoint
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceId
columnName: service_id
typeName: int
ID: false
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- name: ServiceInstanceJVMCPU
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- name: ServiceInstanceJVMMemory
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- name: ServiceInstanceJVMMemoryPool
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- name: ServiceInstanceJVMGC
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- name: ServiceRelation
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- name: ServiceInstanceRelation
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: sourceServiceId
columnName: source_service_id
typeName: int
ID: false
- fieldName: destServiceId
columnName: dest_service_id
typeName: int
ID: false
- name: EndpointRelation
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceId
columnName: service_id
typeName: int
ID: false
- fieldName: childServiceId
columnName: child_service_id
typeName: int
ID: false
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- fieldName: childServiceInstanceId
columnName: child_service_instance_id
typeName: int
ID: false
- name: DatabaseAccess
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
# 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.
scopes:
- name: All
- name: Service
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- name: ServiceInstance
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceId
columnName: service_id
typeName: int
ID: false
- name: Endpoint
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceId
columnName: service_id
typeName: int
ID: false
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- name: ServiceInstanceJVMCPU
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- name: ServiceInstanceJVMMemory
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- name: ServiceInstanceJVMMemoryPool
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- name: ServiceInstanceJVMGC
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- name: ServiceRelation
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- name: ServiceInstanceRelation
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: sourceServiceId
columnName: source_service_id
typeName: int
ID: false
- fieldName: destServiceId
columnName: dest_service_id
typeName: int
ID: false
- name: EndpointRelation
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
- fieldName: serviceId
columnName: service_id
typeName: int
ID: false
- fieldName: childServiceId
columnName: child_service_id
typeName: int
ID: false
- fieldName: serviceInstanceId
columnName: service_instance_id
typeName: int
ID: false
- fieldName: childServiceInstanceId
columnName: child_service_instance_id
typeName: int
ID: false
- name: DatabaseAccess
columns:
- fieldName: entityId
columnName: entity_id
typeName: java.lang.String
ID: true
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
<module>generated-analysis</module> <module>generated-analysis</module>
<module>generate-tool</module> <module>generate-tool</module>
<module>server-telemetry</module> <module>server-telemetry</module>
<module>generate-tool-grammar</module>
</modules> </modules>
<properties> <properties>
......
...@@ -25,6 +25,8 @@ import org.apache.skywalking.oap.server.core.alarm.IndicatorNotify; ...@@ -25,6 +25,8 @@ import org.apache.skywalking.oap.server.core.alarm.IndicatorNotify;
import org.apache.skywalking.oap.server.core.alarm.MetaInAlarm; import org.apache.skywalking.oap.server.core.alarm.MetaInAlarm;
import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator; import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.*;
public class NotifyHandler implements IndicatorNotify { public class NotifyHandler implements IndicatorNotify {
private final AlarmCore core; private final AlarmCore core;
private final Rules rules; private final Rules rules;
...@@ -35,12 +37,12 @@ public class NotifyHandler implements IndicatorNotify { ...@@ -35,12 +37,12 @@ public class NotifyHandler implements IndicatorNotify {
} }
@Override public void notify(MetaInAlarm meta, Indicator indicator) { @Override public void notify(MetaInAlarm meta, Indicator indicator) {
switch (meta.getScope()) { switch (meta.getScopeId()) {
case Service: case SERVICE:
break; break;
case ServiceInstance: case SERVICE_INSTANCE:
break; break;
case Endpoint: case ENDPOINT:
break; break;
default: default:
return; return;
......
...@@ -30,7 +30,6 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.DoubleValueHolde ...@@ -30,7 +30,6 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.DoubleValueHolde
import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator; import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.analysis.indicator.IntValueHolder; import org.apache.skywalking.oap.server.core.analysis.indicator.IntValueHolder;
import org.apache.skywalking.oap.server.core.analysis.indicator.LongValueHolder; import org.apache.skywalking.oap.server.core.analysis.indicator.LongValueHolder;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.library.util.CollectionUtils; import org.apache.skywalking.oap.server.library.util.CollectionUtils;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
import org.joda.time.Minutes; import org.joda.time.Minutes;
...@@ -57,7 +56,7 @@ public class RunningRule { ...@@ -57,7 +56,7 @@ public class RunningRule {
private final int silencePeriod; private final int silencePeriod;
private Map<MetaInAlarm, Window> windows; private Map<MetaInAlarm, Window> windows;
private volatile IndicatorValueType valueType; private volatile IndicatorValueType valueType;
private Scope targetScope; private int targetScopeId;
private List<String> includeNames; private List<String> includeNames;
private AlarmMessageFormatter formatter; private AlarmMessageFormatter formatter;
...@@ -111,7 +110,7 @@ public class RunningRule { ...@@ -111,7 +110,7 @@ public class RunningRule {
} else { } else {
return; return;
} }
targetScope = meta.getScope(); targetScopeId = meta.getScopeId();
} }
if (valueType != null) { if (valueType != null) {
...@@ -147,7 +146,7 @@ public class RunningRule { ...@@ -147,7 +146,7 @@ public class RunningRule {
Window window = entry.getValue(); Window window = entry.getValue();
AlarmMessage alarmMessage = window.checkAlarm(); AlarmMessage alarmMessage = window.checkAlarm();
if (alarmMessage != AlarmMessage.NONE) { if (alarmMessage != AlarmMessage.NONE) {
alarmMessage.setScope(meta.getScope()); alarmMessage.setScopeId(meta.getScopeId());
alarmMessage.setName(meta.getName()); alarmMessage.setName(meta.getName());
alarmMessage.setId0(meta.getId0()); alarmMessage.setId0(meta.getId0());
alarmMessage.setId1(meta.getId1()); alarmMessage.setId1(meta.getId1());
......
...@@ -19,9 +19,7 @@ ...@@ -19,9 +19,7 @@
package org.apache.skywalking.oap.server.core.alarm.provider; package org.apache.skywalking.oap.server.core.alarm.provider;
import org.apache.skywalking.oap.server.core.alarm.MetaInAlarm; import org.apache.skywalking.oap.server.core.alarm.MetaInAlarm;
import org.apache.skywalking.oap.server.core.source.Scope; import org.junit.*;
import org.junit.Assert;
import org.junit.Test;
public class AlarmMessageFormatterTest { public class AlarmMessageFormatterTest {
@Test @Test
...@@ -29,8 +27,8 @@ public class AlarmMessageFormatterTest { ...@@ -29,8 +27,8 @@ public class AlarmMessageFormatterTest {
AlarmMessageFormatter formatter = new AlarmMessageFormatter("abc words {sdf"); AlarmMessageFormatter formatter = new AlarmMessageFormatter("abc words {sdf");
String message = formatter.format(new MetaInAlarm() { String message = formatter.format(new MetaInAlarm() {
@Override public Scope getScope() { @Override public int getScopeId() {
return null; return -1;
} }
@Override public String getName() { @Override public String getName() {
...@@ -58,8 +56,8 @@ public class AlarmMessageFormatterTest { ...@@ -58,8 +56,8 @@ public class AlarmMessageFormatterTest {
AlarmMessageFormatter formatter = new AlarmMessageFormatter("abc} words {name} - {id} .. {"); AlarmMessageFormatter formatter = new AlarmMessageFormatter("abc} words {name} - {id} .. {");
String message = formatter.format(new MetaInAlarm() { String message = formatter.format(new MetaInAlarm() {
@Override public Scope getScope() { @Override public int getScopeId() {
return null; return -1;
} }
@Override public String getName() { @Override public String getName() {
......
...@@ -18,22 +18,14 @@ ...@@ -18,22 +18,14 @@
package org.apache.skywalking.oap.server.core.alarm.provider; package org.apache.skywalking.oap.server.core.alarm.provider;
import java.util.LinkedList; import java.util.*;
import java.util.List; import org.apache.skywalking.oap.server.core.alarm.*;
import java.util.Map; import org.apache.skywalking.oap.server.core.analysis.indicator.*;
import java.util.Objects;
import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
import org.apache.skywalking.oap.server.core.alarm.MetaInAlarm;
import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.analysis.indicator.IntValueHolder;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormat; import org.joda.time.format.*;
import org.joda.time.format.DateTimeFormatter; import org.junit.*;
import org.junit.Assert;
import org.junit.Test;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
/** /**
...@@ -177,7 +169,7 @@ public class RunningRuleTest { ...@@ -177,7 +169,7 @@ public class RunningRuleTest {
Assert.assertEquals(0, runningRule.check().size()); //check matches, no alarm Assert.assertEquals(0, runningRule.check().size()); //check matches, no alarm
runningRule.moveTo(TIME_BUCKET_FORMATTER.parseLocalDateTime("201808301441")); runningRule.moveTo(TIME_BUCKET_FORMATTER.parseLocalDateTime("201808301441"));
// check at 201808301441 // check at 201808301441
Assert.assertEquals(0, runningRule.check().size()); //check matches, no alarm Assert.assertEquals(0, runningRule.check().size()); //check matches, no alarm
runningRule.moveTo(TIME_BUCKET_FORMATTER.parseLocalDateTime("201808301442")); runningRule.moveTo(TIME_BUCKET_FORMATTER.parseLocalDateTime("201808301442"));
// check at 201808301442 // check at 201808301442
Assert.assertNotEquals(0, runningRule.check().size()); //alarm Assert.assertNotEquals(0, runningRule.check().size()); //alarm
...@@ -191,8 +183,8 @@ public class RunningRuleTest { ...@@ -191,8 +183,8 @@ public class RunningRuleTest {
private MetaInAlarm getMetaInAlarm(int id) { private MetaInAlarm getMetaInAlarm(int id) {
return new MetaInAlarm() { return new MetaInAlarm() {
@Override public Scope getScope() { @Override public int getScopeId() {
return Scope.Service; return DefaultScopeDefine.SERVICE;
} }
@Override public String getName() { @Override public String getName() {
......
...@@ -18,30 +18,17 @@ ...@@ -18,30 +18,17 @@
package org.apache.skywalking.oap.server.core.alarm.provider; package org.apache.skywalking.oap.server.core.alarm.provider;
import com.google.gson.Gson; import com.google.gson.*;
import com.google.gson.JsonArray; import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.ArrayList; import java.util.*;
import java.util.List; import javax.servlet.*;
import javax.servlet.Servlet; import javax.servlet.http.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.skywalking.oap.server.core.alarm.AlarmMessage; import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.*;
import org.eclipse.jetty.servlet.ServletHolder; import org.junit.*;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class WebhookCallbackTest implements Servlet { public class WebhookCallbackTest implements Servlet {
private Server server; private Server server;
...@@ -74,12 +61,12 @@ public class WebhookCallbackTest implements Servlet { ...@@ -74,12 +61,12 @@ public class WebhookCallbackTest implements Servlet {
WebhookCallback webhookCallback = new WebhookCallback(remoteEndpoints); WebhookCallback webhookCallback = new WebhookCallback(remoteEndpoints);
List<AlarmMessage> alarmMessages = new ArrayList<>(2); List<AlarmMessage> alarmMessages = new ArrayList<>(2);
AlarmMessage alarmMessage = new AlarmMessage(); AlarmMessage alarmMessage = new AlarmMessage();
alarmMessage.setScope(Scope.All); alarmMessage.setScopeId(DefaultScopeDefine.ALL);
alarmMessage.setAlarmMessage("alarmMessage with [Scope.All]"); alarmMessage.setAlarmMessage("alarmMessage with [DefaultScopeDefine.All]");
alarmMessages.add(alarmMessage); alarmMessages.add(alarmMessage);
AlarmMessage anotherAlarmMessage = new AlarmMessage(); AlarmMessage anotherAlarmMessage = new AlarmMessage();
anotherAlarmMessage.setScope(Scope.Endpoint); anotherAlarmMessage.setScopeId(DefaultScopeDefine.ENDPOINT);
anotherAlarmMessage.setAlarmMessage("anotherAlarmMessage with [Scope.Endpoint]"); anotherAlarmMessage.setAlarmMessage("anotherAlarmMessage with [DefaultScopeDefine.Endpoint]");
alarmMessages.add(anotherAlarmMessage); alarmMessages.add(anotherAlarmMessage);
webhookCallback.doAlarm(alarmMessages); webhookCallback.doAlarm(alarmMessages);
......
...@@ -85,7 +85,15 @@ public class CoreModuleProvider extends ModuleProvider { ...@@ -85,7 +85,15 @@ public class CoreModuleProvider extends ModuleProvider {
return moduleConfig; return moduleConfig;
} }
@Override public void prepare() throws ServiceNotProvidedException { @Override public void prepare() throws ServiceNotProvidedException, ModuleStartException {
AnnotationScan scopeScan = new AnnotationScan();
scopeScan.registerListener(new DefaultScopeDefine.Listener());
try {
scopeScan.scan(null);
} catch (IOException e) {
throw new ModuleStartException(e.getMessage(), e);
}
grpcServer = new GRPCServer(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort()); grpcServer = new GRPCServer(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort());
if (moduleConfig.getMaxConcurrentCallsPerConnection() > 0) { if (moduleConfig.getMaxConcurrentCallsPerConnection() > 0) {
grpcServer.setMaxConcurrentCallsPerConnection(moduleConfig.getMaxConcurrentCallsPerConnection()); grpcServer.setMaxConcurrentCallsPerConnection(moduleConfig.getMaxConcurrentCallsPerConnection());
......
...@@ -21,14 +21,12 @@ package org.apache.skywalking.oap.server.core.alarm; ...@@ -21,14 +21,12 @@ package org.apache.skywalking.oap.server.core.alarm;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import org.apache.skywalking.oap.server.core.CoreModule; import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator; import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache; import org.apache.skywalking.oap.server.core.cache.*;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache; import org.apache.skywalking.oap.server.core.register.*;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInventory;
import org.apache.skywalking.oap.server.library.module.ModuleManager; import org.apache.skywalking.oap.server.library.module.ModuleManager;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.*;
/** /**
* @author wusheng * @author wusheng
*/ */
...@@ -56,7 +54,7 @@ public class AlarmEntrance { ...@@ -56,7 +54,7 @@ public class AlarmEntrance {
MetaInAlarm metaInAlarm; MetaInAlarm metaInAlarm;
switch (alarmMeta.getScope()) { switch (alarmMeta.getScope()) {
case Service: case SERVICE:
int serviceId = Integer.parseInt(alarmMeta.getId()); int serviceId = Integer.parseInt(alarmMeta.getId());
ServiceInventory serviceInventory = serviceInventoryCache.get(serviceId); ServiceInventory serviceInventory = serviceInventoryCache.get(serviceId);
ServiceMetaInAlarm serviceMetaInAlarm = new ServiceMetaInAlarm(); ServiceMetaInAlarm serviceMetaInAlarm = new ServiceMetaInAlarm();
...@@ -65,7 +63,7 @@ public class AlarmEntrance { ...@@ -65,7 +63,7 @@ public class AlarmEntrance {
serviceMetaInAlarm.setName(serviceInventory.getName()); serviceMetaInAlarm.setName(serviceInventory.getName());
metaInAlarm = serviceMetaInAlarm; metaInAlarm = serviceMetaInAlarm;
break; break;
case ServiceInstance: case SERVICE_INSTANCE:
int serviceInstanceId = Integer.parseInt(alarmMeta.getId()); int serviceInstanceId = Integer.parseInt(alarmMeta.getId());
ServiceInstanceInventory serviceInstanceInventory = serviceInstanceInventoryCache.get(serviceInstanceId); ServiceInstanceInventory serviceInstanceInventory = serviceInstanceInventoryCache.get(serviceInstanceId);
ServiceInstanceMetaInAlarm instanceMetaInAlarm = new ServiceInstanceMetaInAlarm(); ServiceInstanceMetaInAlarm instanceMetaInAlarm = new ServiceInstanceMetaInAlarm();
...@@ -74,7 +72,7 @@ public class AlarmEntrance { ...@@ -74,7 +72,7 @@ public class AlarmEntrance {
instanceMetaInAlarm.setName(serviceInstanceInventory.getName()); instanceMetaInAlarm.setName(serviceInstanceInventory.getName());
metaInAlarm = instanceMetaInAlarm; metaInAlarm = instanceMetaInAlarm;
break; break;
case Endpoint: case ENDPOINT:
int endpointId = Integer.parseInt(alarmMeta.getId()); int endpointId = Integer.parseInt(alarmMeta.getId());
EndpointInventory endpointInventory = endpointInventoryCache.get(endpointId); EndpointInventory endpointInventory = endpointInventoryCache.get(endpointId);
EndpointMetaInAlarm endpointMetaInAlarm = new EndpointMetaInAlarm(); EndpointMetaInAlarm endpointMetaInAlarm = new EndpointMetaInAlarm();
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.core.alarm; package org.apache.skywalking.oap.server.core.alarm;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.source.Scope;
/** /**
* Alarm message represents the details of each alarm. * Alarm message represents the details of each alarm.
...@@ -32,7 +31,7 @@ public class AlarmMessage { ...@@ -32,7 +31,7 @@ public class AlarmMessage {
public static AlarmMessage NONE = new NoAlarm(); public static AlarmMessage NONE = new NoAlarm();
private Scope scope; private int scopeId;
private String name; private String name;
private int id0; private int id0;
private int id1; private int id1;
......
...@@ -18,26 +18,24 @@ ...@@ -18,26 +18,24 @@
package org.apache.skywalking.oap.server.core.alarm; package org.apache.skywalking.oap.server.core.alarm;
import lombok.Getter; import lombok.*;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.source.Scope;
/** /**
* @author wusheng * @author wusheng
*/ */
public class AlarmMeta { public class AlarmMeta {
@Setter @Getter private String indicatorName; @Setter @Getter private String indicatorName;
@Setter @Getter private Scope scope; @Setter @Getter private int scope;
@Setter @Getter private String id; @Setter @Getter private String id;
public AlarmMeta(String indicatorName, Scope scope) { public AlarmMeta(String indicatorName, int scope) {
this.indicatorName = indicatorName; this.indicatorName = indicatorName;
this.scope = scope; this.scope = scope;
this.id = Const.EMPTY_STRING; this.id = Const.EMPTY_STRING;
} }
public AlarmMeta(String indicatorName, Scope scope, String id) { public AlarmMeta(String indicatorName, int scope, String id) {
this.indicatorName = indicatorName; this.indicatorName = indicatorName;
this.scope = scope; this.scope = scope;
this.id = id; this.id = id;
......
...@@ -23,17 +23,20 @@ import lombok.*; ...@@ -23,17 +23,20 @@ import lombok.*;
import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.analysis.record.Record; import org.apache.skywalking.oap.server.core.analysis.record.Record;
import org.apache.skywalking.oap.server.core.analysis.record.annotation.RecordType; import org.apache.skywalking.oap.server.core.analysis.record.annotation.RecordType;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ALARM;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@Getter @Getter
@Setter @Setter
@RecordType @RecordType
@StorageEntity(name = AlarmRecord.INDEX_NAME, builder = AlarmRecord.Builder.class, source = Scope.Alarm) @ScopeDeclaration(id = ALARM, name = "Alarm")
@StorageEntity(name = AlarmRecord.INDEX_NAME, builder = AlarmRecord.Builder.class, sourceScopeId = DefaultScopeDefine.ALARM)
public class AlarmRecord extends Record { public class AlarmRecord extends Record {
public static final String INDEX_NAME = "alarm_record"; public static final String INDEX_NAME = "alarm_record";
......
...@@ -39,7 +39,7 @@ public class AlarmStandardPersistence implements AlarmCallback { ...@@ -39,7 +39,7 @@ public class AlarmStandardPersistence implements AlarmCallback {
} }
AlarmRecord record = new AlarmRecord(); AlarmRecord record = new AlarmRecord();
record.setScope(message.getScope().ordinal()); record.setScope(message.getScopeId());
record.setId0(message.getId0()); record.setId0(message.getId0());
record.setId1(message.getId1()); record.setId1(message.getId1());
record.setName(message.getName()); record.setName(message.getName());
......
...@@ -21,7 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm; ...@@ -21,7 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
@Getter(AccessLevel.PUBLIC) @Getter(AccessLevel.PUBLIC)
@Setter(AccessLevel.PUBLIC) @Setter(AccessLevel.PUBLIC)
...@@ -33,8 +33,8 @@ public class EndpointMetaInAlarm extends MetaInAlarm { ...@@ -33,8 +33,8 @@ public class EndpointMetaInAlarm extends MetaInAlarm {
private String[] tags; private String[] tags;
private String[] properties; private String[] properties;
@Override public Scope getScope() { @Override public int getScopeId() {
return Scope.Endpoint; return DefaultScopeDefine.ENDPOINT;
} }
@Override public int getId0() { @Override public int getId0() {
......
...@@ -19,10 +19,9 @@ ...@@ -19,10 +19,9 @@
package org.apache.skywalking.oap.server.core.alarm; package org.apache.skywalking.oap.server.core.alarm;
import java.util.Objects; import java.util.Objects;
import org.apache.skywalking.oap.server.core.source.Scope;
public abstract class MetaInAlarm { public abstract class MetaInAlarm {
public abstract Scope getScope(); public abstract int getScopeId();
public abstract String getName(); public abstract String getName();
...@@ -30,7 +29,7 @@ public abstract class MetaInAlarm { ...@@ -30,7 +29,7 @@ public abstract class MetaInAlarm {
/** /**
* In most scopes, there is only id0, as primary id. Such as Service, Endpoint. But in relation, the ID includes * In most scopes, there is only id0, as primary id. Such as Service, Endpoint. But in relation, the ID includes
* two, actually. Such as ServiceRelation, id0 represents the source service id * two, actually. Such as ServiceRelation, id0 represents the sourceScopeId service id
* *
* @return the primary id. * @return the primary id.
*/ */
......
...@@ -21,7 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm; ...@@ -21,7 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
@Getter(AccessLevel.PUBLIC) @Getter(AccessLevel.PUBLIC)
@Setter(AccessLevel.PUBLIC) @Setter(AccessLevel.PUBLIC)
...@@ -33,8 +33,8 @@ public class ServiceInstanceMetaInAlarm extends MetaInAlarm { ...@@ -33,8 +33,8 @@ public class ServiceInstanceMetaInAlarm extends MetaInAlarm {
private String[] tags; private String[] tags;
private String[] properties; private String[] properties;
@Override public Scope getScope() { @Override public int getScopeId() {
return Scope.ServiceInstance; return DefaultScopeDefine.SERVICE_INSTANCE;
} }
@Override public int getId0() { @Override public int getId0() {
......
...@@ -21,7 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm; ...@@ -21,7 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
@Getter(AccessLevel.PUBLIC) @Getter(AccessLevel.PUBLIC)
@Setter(AccessLevel.PUBLIC) @Setter(AccessLevel.PUBLIC)
...@@ -33,8 +33,8 @@ public class ServiceMetaInAlarm extends MetaInAlarm { ...@@ -33,8 +33,8 @@ public class ServiceMetaInAlarm extends MetaInAlarm {
private String[] tags; private String[] tags;
private String[] properties; private String[] properties;
@Override public Scope getScope() { @Override public int getScopeId() {
return Scope.Service; return DefaultScopeDefine.SERVICE;
} }
@Override public int getId0() { @Override public int getId0() {
......
...@@ -21,17 +21,11 @@ package org.apache.skywalking.oap.server.core.analysis; ...@@ -21,17 +21,11 @@ package org.apache.skywalking.oap.server.core.analysis;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath; import com.google.common.reflect.ClassPath;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.*;
import java.lang.reflect.Type; import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.skywalking.oap.server.core.UnexpectedException; import org.apache.skywalking.oap.server.core.UnexpectedException;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.Source; import org.apache.skywalking.oap.server.core.source.Source;
import org.slf4j.Logger; import org.slf4j.*;
import org.slf4j.LoggerFactory;
/** /**
* @author peng-yongsheng, wusheng * @author peng-yongsheng, wusheng
...@@ -40,7 +34,7 @@ public class DispatcherManager { ...@@ -40,7 +34,7 @@ public class DispatcherManager {
private static final Logger logger = LoggerFactory.getLogger(DispatcherManager.class); private static final Logger logger = LoggerFactory.getLogger(DispatcherManager.class);
private Map<Scope, List<SourceDispatcher>> dispatcherMap; private Map<Integer, List<SourceDispatcher>> dispatcherMap;
public DispatcherManager() { public DispatcherManager() {
this.dispatcherMap = new HashMap<>(); this.dispatcherMap = new HashMap<>();
...@@ -51,8 +45,17 @@ public class DispatcherManager { ...@@ -51,8 +45,17 @@ public class DispatcherManager {
return; return;
} }
for (SourceDispatcher dispatcher : dispatcherMap.get(source.scope())) { List<SourceDispatcher> dispatchers = dispatcherMap.get(source.scope());
dispatcher.dispatch(source);
/**
* Dispatcher is only generated by oal script analysis result.
* So these will/could be possible, the given source doesn't have the dispatcher,
* when the receiver is open, and oal script doesn't ask for analysis.
*/
if (dispatchers != null) {
for (SourceDispatcher dispatcher : dispatchers) {
dispatcher.dispatch(source);
}
} }
} }
...@@ -93,17 +96,17 @@ public class DispatcherManager { ...@@ -93,17 +96,17 @@ public class DispatcherManager {
Source dispatcherSource = (Source)source; Source dispatcherSource = (Source)source;
SourceDispatcher dispatcher = (SourceDispatcher)aClass.newInstance(); SourceDispatcher dispatcher = (SourceDispatcher)aClass.newInstance();
Scope scope = dispatcherSource.scope(); int scopeId = dispatcherSource.scope();
List<SourceDispatcher> dispatchers = this.dispatcherMap.get(scope); List<SourceDispatcher> dispatchers = this.dispatcherMap.get(scopeId);
if (dispatchers == null) { if (dispatchers == null) {
dispatchers = new ArrayList<>(); dispatchers = new ArrayList<>();
this.dispatcherMap.put(scope, dispatchers); this.dispatcherMap.put(scopeId, dispatchers);
} }
dispatchers.add(dispatcher); dispatchers.add(dispatcher);
logger.info("Dispatcher {} is added into Scope {}.", dispatcher.getClass().getName(), scope); logger.info("Dispatcher {} is added into DefaultScopeDefine {}.", dispatcher.getClass().getName(), scopeId);
} }
} }
} }
......
...@@ -20,10 +20,9 @@ package org.apache.skywalking.oap.server.core.analysis.manual.database; ...@@ -20,10 +20,9 @@ package org.apache.skywalking.oap.server.core.analysis.manual.database;
import java.util.*; import java.util.*;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.analysis.topn.TopN; import org.apache.skywalking.oap.server.core.analysis.topn.TopN;
import org.apache.skywalking.oap.server.core.analysis.topn.annotation.TopNType; import org.apache.skywalking.oap.server.core.analysis.topn.annotation.TopNType;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
...@@ -33,7 +32,7 @@ import org.apache.skywalking.oap.server.core.storage.annotation.*; ...@@ -33,7 +32,7 @@ import org.apache.skywalking.oap.server.core.storage.annotation.*;
* @author wusheng * @author wusheng
*/ */
@TopNType @TopNType
@StorageEntity(name = TopNDatabaseStatement.INDEX_NAME, builder = TopNDatabaseStatement.Builder.class, source = Scope.DatabaseSlowStatement) @StorageEntity(name = TopNDatabaseStatement.INDEX_NAME, builder = TopNDatabaseStatement.Builder.class, sourceScopeId = DefaultScopeDefine.DATABASE_SLOW_STATEMENT)
public class TopNDatabaseStatement extends TopN { public class TopNDatabaseStatement extends TopN {
public static final String INDEX_NAME = "top_n_database_statement"; public static final String INDEX_NAME = "top_n_database_statement";
......
...@@ -25,13 +25,13 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator; ...@@ -25,13 +25,13 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorType; import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData; import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
@IndicatorType @IndicatorType
@StreamData @StreamData
@StorageEntity(name = EndpointRelationServerSideIndicator.INDEX_NAME, builder = EndpointRelationServerSideIndicator.Builder.class, source = Scope.EndpointRelation) @StorageEntity(name = EndpointRelationServerSideIndicator.INDEX_NAME, builder = EndpointRelationServerSideIndicator.Builder.class, sourceScopeId = DefaultScopeDefine.ENDPOINT_RELATION)
public class EndpointRelationServerSideIndicator extends Indicator { public class EndpointRelationServerSideIndicator extends Indicator {
public static final String INDEX_NAME = "endpoint_relation_server_side"; public static final String INDEX_NAME = "endpoint_relation_server_side";
......
...@@ -24,7 +24,7 @@ import org.apache.skywalking.apm.util.StringUtil; ...@@ -24,7 +24,7 @@ import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.analysis.record.Record; import org.apache.skywalking.oap.server.core.analysis.record.Record;
import org.apache.skywalking.oap.server.core.analysis.record.annotation.RecordType; import org.apache.skywalking.oap.server.core.analysis.record.annotation.RecordType;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.library.util.CollectionUtils; import org.apache.skywalking.oap.server.library.util.CollectionUtils;
...@@ -33,7 +33,7 @@ import org.apache.skywalking.oap.server.library.util.CollectionUtils; ...@@ -33,7 +33,7 @@ import org.apache.skywalking.oap.server.library.util.CollectionUtils;
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@RecordType @RecordType
@StorageEntity(name = SegmentRecord.INDEX_NAME, builder = SegmentRecord.Builder.class, source = Scope.Segment) @StorageEntity(name = SegmentRecord.INDEX_NAME, builder = SegmentRecord.Builder.class, sourceScopeId = DefaultScopeDefine.SEGMENT)
public class SegmentRecord extends Record { public class SegmentRecord extends Record {
public static final String INDEX_NAME = "segment"; public static final String INDEX_NAME = "segment";
......
...@@ -25,13 +25,13 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator; ...@@ -25,13 +25,13 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorType; import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData; import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
@IndicatorType @IndicatorType
@StreamData @StreamData
@StorageEntity(name = ServiceRelationClientSideIndicator.INDEX_NAME, builder = ServiceRelationClientSideIndicator.Builder.class, source = Scope.ServiceRelation) @StorageEntity(name = ServiceRelationClientSideIndicator.INDEX_NAME, builder = ServiceRelationClientSideIndicator.Builder.class, sourceScopeId = DefaultScopeDefine.SERVICE_RELATION)
public class ServiceRelationClientSideIndicator extends Indicator { public class ServiceRelationClientSideIndicator extends Indicator {
public static final String INDEX_NAME = "service_relation_client_side"; public static final String INDEX_NAME = "service_relation_client_side";
......
...@@ -25,14 +25,14 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator; ...@@ -25,14 +25,14 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorType; import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData; import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
@IndicatorType @IndicatorType
@StreamData @StreamData
@StorageEntity(name = ServiceRelationServerSideIndicator.INDEX_NAME, builder = ServiceRelationServerSideIndicator.Builder.class, @StorageEntity(name = ServiceRelationServerSideIndicator.INDEX_NAME, builder = ServiceRelationServerSideIndicator.Builder.class,
source = Scope.ServiceRelation) sourceScopeId = DefaultScopeDefine.SERVICE_RELATION)
public class ServiceRelationServerSideIndicator extends Indicator { public class ServiceRelationServerSideIndicator extends Indicator {
public static final String INDEX_NAME = "service_relation_server_side"; public static final String INDEX_NAME = "service_relation_server_side";
......
...@@ -56,7 +56,9 @@ public class AnnotationScan { ...@@ -56,7 +56,9 @@ public class AnnotationScan {
listener.complete() listener.complete()
); );
callBack.run(); if (callBack != null) {
callBack.run();
}
} }
public class AnnotationListenerCache { public class AnnotationListenerCache {
......
...@@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.core.query; ...@@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.core.query;
import java.io.IOException; import java.io.IOException;
import org.apache.skywalking.oap.server.core.query.entity.*; import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageModule; import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO; import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO;
import org.apache.skywalking.oap.server.library.module.*; import org.apache.skywalking.oap.server.library.module.*;
...@@ -48,9 +47,9 @@ public class AlarmQueryService implements Service { ...@@ -48,9 +47,9 @@ public class AlarmQueryService implements Service {
return alarmQueryDAO; return alarmQueryDAO;
} }
public Alarms getAlarm(final Scope scope, final String keyword, final Pagination paging, final long startTB, public Alarms getAlarm(final Integer scopeId, final String keyword, final Pagination paging, final long startTB,
final long endTB) throws IOException { final long endTB) throws IOException {
PaginationUtils.Page page = PaginationUtils.INSTANCE.exchange(paging); PaginationUtils.Page page = PaginationUtils.INSTANCE.exchange(paging);
return getAlarmQueryDAO().getAlarm(scope, keyword, page.getLimit(), page.getFrom(), startTB, endTB); return getAlarmQueryDAO().getAlarm(scopeId, keyword, page.getLimit(), page.getFrom(), startTB, endTB);
} }
} }
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.core.query.entity; package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.source.Scope;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
...@@ -28,6 +27,7 @@ import org.apache.skywalking.oap.server.core.source.Scope; ...@@ -28,6 +27,7 @@ import org.apache.skywalking.oap.server.core.source.Scope;
@Setter @Setter
public class AlarmMessage { public class AlarmMessage {
private Scope scope; private Scope scope;
private int scopeId;
private String id; private String id;
private String message; private String message;
private Long startTime; private Long startTime;
......
/*
* 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.oap.server.core.query.entity;
import java.util.HashMap;
import lombok.Getter;
import org.apache.skywalking.oap.server.core.UnexpectedException;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
/**
* @author wusheng
*/
public enum Scope {
Service(DefaultScopeDefine.SERVICE),
ServiceInstance(DefaultScopeDefine.SERVICE_INSTANCE),
Endpoint(DefaultScopeDefine.ENDPOINT),
ServiceRelation(DefaultScopeDefine.SERVICE_RELATION),
ServiceInstanceRelation(DefaultScopeDefine.SERVICE_INSTANCE_RELATION),
EndpointRelation(DefaultScopeDefine.ENDPOINT_RELATION);
@Getter
private int scopeId;
Scope(int scopeId) {
this.scopeId = scopeId;
Finder.ALL_QUERY_SCOPES.put(scopeId, this);
}
public static class Finder {
private static HashMap<Integer, Scope> ALL_QUERY_SCOPES = new HashMap<>();
public static Scope valueOf(int scopeId) {
Scope scope = ALL_QUERY_SCOPES.get(scopeId);
if (scope == null) {
throw new UnexpectedException("Can't find scope id =" + scopeId);
}
return scope;
}
}
}
...@@ -24,17 +24,20 @@ import org.apache.skywalking.oap.server.core.Const; ...@@ -24,17 +24,20 @@ import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.annotation.InventoryType; import org.apache.skywalking.oap.server.core.register.annotation.InventoryType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData; import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT_INVENTORY;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@InventoryType @InventoryType
@StreamData @StreamData
@StorageEntity(name = EndpointInventory.MODEL_NAME, builder = EndpointInventory.Builder.class, deleteHistory = false, source = Scope.EndpointInventory) @ScopeDeclaration(id = ENDPOINT_INVENTORY, name = "EndpointInventory")
@StorageEntity(name = EndpointInventory.MODEL_NAME, builder = EndpointInventory.Builder.class, deleteHistory = false, sourceScopeId = DefaultScopeDefine.ENDPOINT_INVENTORY)
public class EndpointInventory extends RegisterSource { public class EndpointInventory extends RegisterSource {
public static final String MODEL_NAME = "endpoint_inventory"; public static final String MODEL_NAME = "endpoint_inventory";
......
...@@ -24,17 +24,20 @@ import org.apache.skywalking.oap.server.core.Const; ...@@ -24,17 +24,20 @@ import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.annotation.InventoryType; import org.apache.skywalking.oap.server.core.register.annotation.InventoryType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData; import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.NETWORK_ADDRESS;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@InventoryType @InventoryType
@StreamData @StreamData
@StorageEntity(name = NetworkAddressInventory.MODEL_NAME, builder = NetworkAddressInventory.Builder.class, deleteHistory = false, source = Scope.NetworkAddress) @ScopeDeclaration(id = NETWORK_ADDRESS, name = "NetworkAddress")
@StorageEntity(name = NetworkAddressInventory.MODEL_NAME, builder = NetworkAddressInventory.Builder.class, deleteHistory = false, sourceScopeId = DefaultScopeDefine.NETWORK_ADDRESS)
public class NetworkAddressInventory extends RegisterSource { public class NetworkAddressInventory extends RegisterSource {
public static final String MODEL_NAME = "network_address_inventory"; public static final String MODEL_NAME = "network_address_inventory";
......
...@@ -26,18 +26,21 @@ import org.apache.skywalking.oap.server.core.Const; ...@@ -26,18 +26,21 @@ import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.annotation.InventoryType; import org.apache.skywalking.oap.server.core.register.annotation.InventoryType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData; import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.library.util.BooleanUtils; import org.apache.skywalking.oap.server.library.util.BooleanUtils;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_INVENTORY;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@InventoryType @InventoryType
@StreamData @StreamData
@StorageEntity(name = ServiceInstanceInventory.MODEL_NAME, builder = ServiceInstanceInventory.Builder.class, deleteHistory = false, source = Scope.ServiceInstanceInventory) @ScopeDeclaration(id = SERVICE_INSTANCE_INVENTORY, name = "ServiceInstanceInventory")
@StorageEntity(name = ServiceInstanceInventory.MODEL_NAME, builder = ServiceInstanceInventory.Builder.class, deleteHistory = false, sourceScopeId = DefaultScopeDefine.SERVICE_INSTANCE_INVENTORY)
public class ServiceInstanceInventory extends RegisterSource { public class ServiceInstanceInventory extends RegisterSource {
public static final String MODEL_NAME = "service_instance_inventory"; public static final String MODEL_NAME = "service_instance_inventory";
......
...@@ -25,18 +25,21 @@ import org.apache.skywalking.oap.server.core.Const; ...@@ -25,18 +25,21 @@ import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.annotation.InventoryType; import org.apache.skywalking.oap.server.core.register.annotation.InventoryType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData; import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*; import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.library.util.BooleanUtils; import org.apache.skywalking.oap.server.library.util.BooleanUtils;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INVENTORY;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@InventoryType @InventoryType
@StreamData @StreamData
@StorageEntity(name = ServiceInventory.MODEL_NAME, builder = ServiceInventory.Builder.class, deleteHistory = false, source = Scope.ServiceInventory) @ScopeDeclaration(id = SERVICE_INVENTORY, name = "ServiceInventory")
@StorageEntity(name = ServiceInventory.MODEL_NAME, builder = ServiceInventory.Builder.class, deleteHistory = false, sourceScopeId = DefaultScopeDefine.SERVICE_INVENTORY)
public class ServiceInventory extends RegisterSource { public class ServiceInventory extends RegisterSource {
public static final String MODEL_NAME = "service_inventory"; public static final String MODEL_NAME = "service_inventory";
......
...@@ -18,20 +18,12 @@ ...@@ -18,20 +18,12 @@
package org.apache.skywalking.oap.server.core.register.worker; package org.apache.skywalking.oap.server.core.register.worker;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.skywalking.oap.server.core.UnexpectedException; import org.apache.skywalking.oap.server.core.UnexpectedException;
import org.apache.skywalking.oap.server.core.register.RegisterSource; import org.apache.skywalking.oap.server.core.register.RegisterSource;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.storage.*;
import org.apache.skywalking.oap.server.core.storage.IRegisterDAO;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.StorageDAO;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntityAnnotationUtils; import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntityAnnotationUtils;
import org.apache.skywalking.oap.server.core.worker.WorkerIdGenerator; import org.apache.skywalking.oap.server.core.worker.*;
import org.apache.skywalking.oap.server.core.worker.WorkerInstances;
import org.apache.skywalking.oap.server.library.module.ModuleManager; import org.apache.skywalking.oap.server.library.module.ModuleManager;
/** /**
...@@ -48,7 +40,7 @@ public enum InventoryProcess { ...@@ -48,7 +40,7 @@ public enum InventoryProcess {
public void create(ModuleManager moduleManager, Class<? extends RegisterSource> inventoryClass) { public void create(ModuleManager moduleManager, Class<? extends RegisterSource> inventoryClass) {
String modelName = StorageEntityAnnotationUtils.getModelName(inventoryClass); String modelName = StorageEntityAnnotationUtils.getModelName(inventoryClass);
Scope scope = StorageEntityAnnotationUtils.getSourceScope(inventoryClass); int scopeId = StorageEntityAnnotationUtils.getSourceScope(inventoryClass);
Class<? extends StorageBuilder> builderClass = StorageEntityAnnotationUtils.getBuilder(inventoryClass); Class<? extends StorageBuilder> builderClass = StorageEntityAnnotationUtils.getBuilder(inventoryClass);
...@@ -60,7 +52,7 @@ public enum InventoryProcess { ...@@ -60,7 +52,7 @@ public enum InventoryProcess {
throw new UnexpectedException(""); throw new UnexpectedException("");
} }
RegisterPersistentWorker persistentWorker = new RegisterPersistentWorker(WorkerIdGenerator.INSTANCES.generate(), modelName, moduleManager, registerDAO, scope); RegisterPersistentWorker persistentWorker = new RegisterPersistentWorker(WorkerIdGenerator.INSTANCES.generate(), modelName, moduleManager, registerDAO, scopeId);
WorkerInstances.INSTANCES.put(persistentWorker.getWorkerId(), persistentWorker); WorkerInstances.INSTANCES.put(persistentWorker.getWorkerId(), persistentWorker);
RegisterRemoteWorker remoteWorker = new RegisterRemoteWorker(WorkerIdGenerator.INSTANCES.generate(), moduleManager, persistentWorker); RegisterRemoteWorker remoteWorker = new RegisterRemoteWorker(WorkerIdGenerator.INSTANCES.generate(), moduleManager, persistentWorker);
...@@ -73,7 +65,7 @@ public enum InventoryProcess { ...@@ -73,7 +65,7 @@ public enum InventoryProcess {
} }
/** /**
* @return all register source class types * @return all register sourceScopeId class types
*/ */
public List<Class> getAllRegisterSources() { public List<Class> getAllRegisterSources() {
List allSources = new ArrayList<>(); List allSources = new ArrayList<>();
......
...@@ -24,7 +24,7 @@ import org.apache.skywalking.apm.commons.datacarrier.consumer.*; ...@@ -24,7 +24,7 @@ import org.apache.skywalking.apm.commons.datacarrier.consumer.*;
import org.apache.skywalking.oap.server.core.*; import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.analysis.data.EndOfBatchContext; import org.apache.skywalking.oap.server.core.analysis.data.EndOfBatchContext;
import org.apache.skywalking.oap.server.core.register.RegisterSource; import org.apache.skywalking.oap.server.core.register.RegisterSource;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.*; import org.apache.skywalking.oap.server.core.storage.*;
import org.apache.skywalking.oap.server.core.worker.AbstractWorker; import org.apache.skywalking.oap.server.core.worker.AbstractWorker;
import org.apache.skywalking.oap.server.library.module.ModuleManager; import org.apache.skywalking.oap.server.library.module.ModuleManager;
...@@ -37,7 +37,7 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> { ...@@ -37,7 +37,7 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> {
private static final Logger logger = LoggerFactory.getLogger(RegisterPersistentWorker.class); private static final Logger logger = LoggerFactory.getLogger(RegisterPersistentWorker.class);
private final Scope scope; private final int scopeId;
private final String modelName; private final String modelName;
private final Map<RegisterSource, RegisterSource> sources; private final Map<RegisterSource, RegisterSource> sources;
private final IRegisterLockDAO registerLockDAO; private final IRegisterLockDAO registerLockDAO;
...@@ -45,13 +45,13 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> { ...@@ -45,13 +45,13 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> {
private final DataCarrier<RegisterSource> dataCarrier; private final DataCarrier<RegisterSource> dataCarrier;
RegisterPersistentWorker(int workerId, String modelName, ModuleManager moduleManager, RegisterPersistentWorker(int workerId, String modelName, ModuleManager moduleManager,
IRegisterDAO registerDAO, Scope scope) { IRegisterDAO registerDAO, int scopeId) {
super(workerId); super(workerId);
this.modelName = modelName; this.modelName = modelName;
this.sources = new HashMap<>(); this.sources = new HashMap<>();
this.registerDAO = registerDAO; this.registerDAO = registerDAO;
this.registerLockDAO = moduleManager.find(StorageModule.NAME).provider().getService(IRegisterLockDAO.class); this.registerLockDAO = moduleManager.find(StorageModule.NAME).provider().getService(IRegisterLockDAO.class);
this.scope = scope; this.scopeId = scopeId;
this.dataCarrier = new DataCarrier<>("IndicatorPersistentWorker." + modelName, 1, 1000); this.dataCarrier = new DataCarrier<>("IndicatorPersistentWorker." + modelName, 1, 1000);
String name = "REGISTER_L2"; String name = "REGISTER_L2";
...@@ -91,7 +91,7 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> { ...@@ -91,7 +91,7 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> {
} }
} else { } else {
int sequence; int sequence;
if ((sequence = registerLockDAO.getId(scope, registerSource)) != Const.NONE) { if ((sequence = registerLockDAO.getId(scopeId, registerSource)) != Const.NONE) {
try { try {
dbSource = registerDAO.get(modelName, source.id()); dbSource = registerDAO.get(modelName, source.id());
if (Objects.nonNull(dbSource)) { if (Objects.nonNull(dbSource)) {
...@@ -106,7 +106,7 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> { ...@@ -106,7 +106,7 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> {
logger.error(t.getMessage(), t); logger.error(t.getMessage(), t);
} }
} else { } else {
logger.info("{} inventory register try lock and increment sequence failure.", scope.name()); logger.info("{} inventory register try lock and increment sequence failure.", DefaultScopeDefine.nameOf(scopeId));
} }
} }
} catch (Throwable t) { } catch (Throwable t) {
......
...@@ -18,17 +18,16 @@ ...@@ -18,17 +18,16 @@
package org.apache.skywalking.oap.server.core.source; package org.apache.skywalking.oap.server.core.source;
import lombok.Getter; import lombok.*;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
@SourceType import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ALL;
@ScopeDeclaration(id = ALL, name = "All")
public class All extends Source { public class All extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.All; return DefaultScopeDefine.ALL;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
return ""; return "";
} }
......
...@@ -18,17 +18,19 @@ ...@@ -18,17 +18,19 @@
package org.apache.skywalking.oap.server.core.source; package org.apache.skywalking.oap.server.core.source;
import lombok.Getter; import lombok.*;
import lombok.Setter;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.DATABASE_ACCESS;
/** /**
* @author: liuhaoyang * @author: liuhaoyang
*/ */
@ScopeDeclaration(id = DATABASE_ACCESS, name = "DatabaseAccess")
public class DatabaseAccess extends Source { public class DatabaseAccess extends Source {
@Override @Override
public Scope scope() { public int scope() {
return Scope.DatabaseAccess; return DefaultScopeDefine.DATABASE_ACCESS;
} }
@Override @Override
......
...@@ -20,12 +20,13 @@ package org.apache.skywalking.oap.server.core.source; ...@@ -20,12 +20,13 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.DATABASE_SLOW_STATEMENT;
/** /**
* @author wusheng * @author wusheng
*/ */
@SourceType @ScopeDeclaration(id = DATABASE_SLOW_STATEMENT, name = "DatabaseSlowStatement")
public class DatabaseSlowStatement extends Source { public class DatabaseSlowStatement extends Source {
@Getter @Setter private String id; @Getter @Setter private String id;
@Getter @Setter private int databaseServiceId; @Getter @Setter private int databaseServiceId;
...@@ -33,8 +34,8 @@ public class DatabaseSlowStatement extends Source { ...@@ -33,8 +34,8 @@ public class DatabaseSlowStatement extends Source {
@Getter @Setter private long latency; @Getter @Setter private long latency;
@Getter @Setter private String traceId; @Getter @Setter private String traceId;
@Override public Scope scope() { @Override public int scope() {
return Scope.DatabaseSlowStatement; return DefaultScopeDefine.DATABASE_SLOW_STATEMENT;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
/*
* 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.oap.server.core.source;
import java.lang.annotation.Annotation;
import java.util.*;
import org.apache.skywalking.oap.server.core.UnexpectedException;
import org.apache.skywalking.oap.server.core.annotation.AnnotationListener;
/**
* @author peng-yongsheng, wusheng
*/
public class DefaultScopeDefine {
private static final Map<String, Integer> NAME_2_ID = new HashMap<>();
private static final Map<Integer, String> ID_2_NAME = new HashMap<>();
public static final int ALL = 0;
public static final int SERVICE = 1;
public static final int SERVICE_INSTANCE = 2;
public static final int ENDPOINT = 3;
public static final int SERVICE_RELATION = 4;
public static final int SERVICE_INSTANCE_RELATION = 5;
public static final int ENDPOINT_RELATION = 6;
public static final int NETWORK_ADDRESS = 7;
public static final int SERVICE_INSTANCE_JVM_CPU = 8;
public static final int SERVICE_INSTANCE_JVM_MEMORY = 9;
public static final int SERVICE_INSTANCE_JVM_MEMORY_POOL = 10;
public static final int SERVICE_INSTANCE_JVM_GC = 11;
public static final int SEGMENT = 12;
public static final int ALARM = 13;
public static final int SERVICE_INVENTORY = 14;
public static final int SERVICE_INSTANCE_INVENTORY = 15;
public static final int ENDPOINT_INVENTORY = 16;
public static final int DATABASE_ACCESS = 17;
public static final int DATABASE_SLOW_STATEMENT = 18;
public static class Listener implements AnnotationListener {
@Override public Class<? extends Annotation> annotation() {
return ScopeDeclaration.class;
}
@Override public void notify(Class originalClass) {
ScopeDeclaration declaration = (ScopeDeclaration)originalClass.getAnnotation(ScopeDeclaration.class);
if (declaration != null) {
addNewScope(declaration, originalClass);
}
}
}
public static final void addNewScope(ScopeDeclaration declaration, Class originalClass) {
int id = declaration.id();
if (ID_2_NAME.containsKey(id)) {
throw new UnexpectedException("ScopeDeclaration id=" + id + " at " + originalClass.getName() + " has conflict with another named " + ID_2_NAME.get(id));
}
String name = declaration.name();
if (NAME_2_ID.containsKey(name)) {
throw new UnexpectedException("ScopeDeclaration name=" + name + " at " + originalClass.getName() + " has conflict with another id= " + NAME_2_ID.get(name));
}
ID_2_NAME.put(id, name);
NAME_2_ID.put(name, id);
}
public static String nameOf(int id) {
String name = ID_2_NAME.get(id);
if (name == null) {
throw new UnexpectedException("ScopeDefine id = " + id + " not found.");
}
return name;
}
public static int valueOf(String name) {
Integer id = NAME_2_ID.get(name);
if (id == null) {
throw new UnexpectedException("ScopeDefine name = " + name + " not found.");
}
return id;
}
public static void reset() {
NAME_2_ID.clear();
ID_2_NAME.clear();
}
}
...@@ -19,15 +19,16 @@ ...@@ -19,15 +19,16 @@
package org.apache.skywalking.oap.server.core.source; package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@SourceType @ScopeDeclaration(id = ENDPOINT, name = "Endpoint")
public class Endpoint extends Source { public class Endpoint extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.Endpoint; return DefaultScopeDefine.ENDPOINT;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
...@@ -21,13 +21,16 @@ package org.apache.skywalking.oap.server.core.source; ...@@ -21,13 +21,16 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.Const;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT_RELATION;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@ScopeDeclaration(id = ENDPOINT_RELATION, name = "EndpointRelation")
public class EndpointRelation extends Source { public class EndpointRelation extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.EndpointRelation; return DefaultScopeDefine.ENDPOINT_RELATION;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
...@@ -18,18 +18,16 @@ ...@@ -18,18 +18,16 @@
package org.apache.skywalking.oap.server.core.source; package org.apache.skywalking.oap.server.core.source;
import java.lang.annotation.*;
/** /**
* @author peng-yongsheng, wusheng * DefaultScopeDefine id declaration.
*
* @author wusheng
*/ */
public enum Scope { @Target({ElementType.TYPE})
All, Service, ServiceInstance, Endpoint, ServiceRelation, ServiceInstanceRelation, EndpointRelation, NetworkAddress, @Retention(RetentionPolicy.RUNTIME)
ServiceInstanceJVMCPU, ServiceInstanceJVMMemory, ServiceInstanceJVMMemoryPool, ServiceInstanceJVMGC, public @interface ScopeDeclaration {
Segment, Alarm, ServiceInventory, ServiceInstanceInventory, EndpointInventory, DatabaseAccess, DatabaseSlowStatement; int id();
String name();
public static Scope valueOf(int ordinal) {
if (ordinal < 0 || ordinal >= values().length) {
throw new IndexOutOfBoundsException("Invalid ordinal");
}
return values()[ordinal];
}
} }
...@@ -19,16 +19,17 @@ ...@@ -19,16 +19,17 @@
package org.apache.skywalking.oap.server.core.source; package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SEGMENT;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@SourceType @ScopeDeclaration(id = SEGMENT, name = "Segment")
public class Segment extends Source { public class Segment extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.Segment; return DefaultScopeDefine.SEGMENT;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
...@@ -19,15 +19,16 @@ ...@@ -19,15 +19,16 @@
package org.apache.skywalking.oap.server.core.source; package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE;
/** /**
* @author wusheng, peng-yongsheng * @author wusheng, peng-yongsheng
*/ */
@SourceType @ScopeDeclaration(id = SERVICE, name = "Service")
public class Service extends Source { public class Service extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.Service; return DefaultScopeDefine.SERVICE;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
...@@ -19,15 +19,16 @@ ...@@ -19,15 +19,16 @@
package org.apache.skywalking.oap.server.core.source; package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@SourceType @ScopeDeclaration(id = SERVICE_INSTANCE, name = "ServiceInstance")
public class ServiceInstance extends Source { public class ServiceInstance extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.ServiceInstance; return DefaultScopeDefine.SERVICE_INSTANCE;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
...@@ -19,15 +19,16 @@ ...@@ -19,15 +19,16 @@
package org.apache.skywalking.oap.server.core.source; package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_CPU;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@SourceType @ScopeDeclaration(id = SERVICE_INSTANCE_JVM_CPU, name = "ServiceInstanceJVMCPU")
public class ServiceInstanceJVMCPU extends Source { public class ServiceInstanceJVMCPU extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.ServiceInstanceJVMCPU; return DefaultScopeDefine.SERVICE_INSTANCE_JVM_CPU;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
...@@ -19,15 +19,16 @@ ...@@ -19,15 +19,16 @@
package org.apache.skywalking.oap.server.core.source; package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_GC;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@SourceType @ScopeDeclaration(id = SERVICE_INSTANCE_JVM_GC, name = "ServiceInstanceJVMGC")
public class ServiceInstanceJVMGC extends Source { public class ServiceInstanceJVMGC extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.ServiceInstanceJVMGC; return DefaultScopeDefine.SERVICE_INSTANCE_JVM_GC;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
...@@ -20,12 +20,15 @@ package org.apache.skywalking.oap.server.core.source; ...@@ -20,12 +20,15 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_MEMORY, name = "ServiceInstanceJVMMemory")
public class ServiceInstanceJVMMemory extends Source { public class ServiceInstanceJVMMemory extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.ServiceInstanceJVMMemory; return DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
...@@ -20,12 +20,15 @@ package org.apache.skywalking.oap.server.core.source; ...@@ -20,12 +20,15 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY_POOL;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_MEMORY_POOL, name = "ServiceInstanceJVMMemoryPool")
public class ServiceInstanceJVMMemoryPool extends Source { public class ServiceInstanceJVMMemoryPool extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.ServiceInstanceJVMMemoryPool; return DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY_POOL;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
...@@ -21,13 +21,16 @@ package org.apache.skywalking.oap.server.core.source; ...@@ -21,13 +21,16 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.Const;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_RELATION;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@ScopeDeclaration(id = SERVICE_INSTANCE_RELATION, name = "ServiceInstanceRelation")
public class ServiceInstanceRelation extends Source { public class ServiceInstanceRelation extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.ServiceInstanceRelation; return DefaultScopeDefine.SERVICE_INSTANCE_RELATION;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
...@@ -21,13 +21,16 @@ package org.apache.skywalking.oap.server.core.source; ...@@ -21,13 +21,16 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*; import lombok.*;
import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.Const;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_RELATION;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
@ScopeDeclaration(id = SERVICE_RELATION, name = "ServiceRelation")
public class ServiceRelation extends Source { public class ServiceRelation extends Source {
@Override public Scope scope() { @Override public int scope() {
return Scope.ServiceRelation; return DefaultScopeDefine.SERVICE_RELATION;
} }
@Override public String getEntityId() { @Override public String getEntityId() {
......
...@@ -24,7 +24,7 @@ import lombok.*; ...@@ -24,7 +24,7 @@ import lombok.*;
* @author peng-yongsheng * @author peng-yongsheng
*/ */
public abstract class Source { public abstract class Source {
public abstract Scope scope(); public abstract int scope();
@Getter @Setter private long timeBucket; @Getter @Setter private long timeBucket;
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.core.storage; package org.apache.skywalking.oap.server.core.storage;
import org.apache.skywalking.oap.server.core.register.RegisterSource; import org.apache.skywalking.oap.server.core.register.RegisterSource;
import org.apache.skywalking.oap.server.core.source.Scope;
/** /**
* Entity register and ID generator. * Entity register and ID generator.
...@@ -32,8 +31,8 @@ public interface IRegisterLockDAO extends DAO { ...@@ -32,8 +31,8 @@ public interface IRegisterLockDAO extends DAO {
* in concurrent way, so no `sync` in method level, but the implementation must make sure the return id is unique no * in concurrent way, so no `sync` in method level, but the implementation must make sure the return id is unique no
* matter the cluster size. * matter the cluster size.
* *
* @param scope for the id. IDs at different scopes could be same, but unique in same scope. * @param scopeId for the id. IDs at different scopes could be same, but unique in same scope.
* @return Unique ID. * @return Unique ID.
*/ */
int getId(Scope scope, RegisterSource registerSource); int getId(int scopeId, RegisterSource registerSource);
} }
...@@ -20,20 +20,13 @@ package org.apache.skywalking.oap.server.core.storage.annotation; ...@@ -20,20 +20,13 @@ package org.apache.skywalking.oap.server.core.storage.annotation;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.LinkedList; import java.util.*;
import java.util.List;
import java.util.Objects;
import lombok.Getter; import lombok.Getter;
import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorAnnotationUtils; import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorAnnotationUtils;
import org.apache.skywalking.oap.server.core.annotation.AnnotationListener; import org.apache.skywalking.oap.server.core.annotation.AnnotationListener;
import org.apache.skywalking.oap.server.core.source.Scope; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.model.ColumnName; import org.apache.skywalking.oap.server.core.storage.model.*;
import org.apache.skywalking.oap.server.core.storage.model.IModelGetter; import org.slf4j.*;
import org.apache.skywalking.oap.server.core.storage.model.IModelOverride;
import org.apache.skywalking.oap.server.core.storage.model.Model;
import org.apache.skywalking.oap.server.core.storage.model.ModelColumn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
...@@ -57,12 +50,14 @@ public class StorageAnnotationListener implements AnnotationListener, IModelGett ...@@ -57,12 +50,14 @@ public class StorageAnnotationListener implements AnnotationListener, IModelGett
String modelName = StorageEntityAnnotationUtils.getModelName(aClass); String modelName = StorageEntityAnnotationUtils.getModelName(aClass);
boolean deleteHistory = StorageEntityAnnotationUtils.getDeleteHistory(aClass); boolean deleteHistory = StorageEntityAnnotationUtils.getDeleteHistory(aClass);
Scope sourceScope = StorageEntityAnnotationUtils.getSourceScope(aClass); int sourceScopeId = StorageEntityAnnotationUtils.getSourceScope(aClass);
// Check this scope id is valid.
DefaultScopeDefine.nameOf(sourceScopeId);
List<ModelColumn> modelColumns = new LinkedList<>(); List<ModelColumn> modelColumns = new LinkedList<>();
boolean isIndicator = IndicatorAnnotationUtils.isIndicator(aClass); boolean isIndicator = IndicatorAnnotationUtils.isIndicator(aClass);
retrieval(aClass, modelName, modelColumns); retrieval(aClass, modelName, modelColumns);
models.add(new Model(modelName, modelColumns, isIndicator, deleteHistory, sourceScope)); models.add(new Model(modelName, modelColumns, isIndicator, deleteHistory, sourceScopeId));
} }
private void retrieval(Class clazz, String modelName, List<ModelColumn> modelColumns) { private void retrieval(Class clazz, String modelName, List<ModelColumn> modelColumns) {
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.core.storage.annotation; package org.apache.skywalking.oap.server.core.storage.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
/** /**
...@@ -32,7 +31,10 @@ public @interface StorageEntity { ...@@ -32,7 +31,10 @@ public @interface StorageEntity {
Class<? extends StorageBuilder> builder(); Class<? extends StorageBuilder> builder();
Scope source(); /**
* @return scope id.
*/
int sourceScopeId();
boolean deleteHistory() default true; boolean deleteHistory() default true;
} }
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.core.storage.annotation; package org.apache.skywalking.oap.server.core.storage.annotation;
import org.apache.skywalking.oap.server.core.UnexpectedException; import org.apache.skywalking.oap.server.core.UnexpectedException;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder; import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
/** /**
...@@ -54,10 +53,10 @@ public class StorageEntityAnnotationUtils { ...@@ -54,10 +53,10 @@ public class StorageEntityAnnotationUtils {
} }
} }
public static Scope getSourceScope(Class aClass) { public static int getSourceScope(Class aClass) {
if (aClass.isAnnotationPresent(StorageEntity.class)) { if (aClass.isAnnotationPresent(StorageEntity.class)) {
StorageEntity annotation = (StorageEntity)aClass.getAnnotation(StorageEntity.class); StorageEntity annotation = (StorageEntity)aClass.getAnnotation(StorageEntity.class);
return annotation.source(); return annotation.sourceScopeId();
} else { } else {
throw new UnexpectedException(""); throw new UnexpectedException("");
} }
......
...@@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.core.storage.model; ...@@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.core.storage.model;
import java.util.List; import java.util.List;
import lombok.Getter; import lombok.Getter;
import org.apache.skywalking.oap.server.core.source.Scope;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
...@@ -31,17 +30,18 @@ public class Model { ...@@ -31,17 +30,18 @@ public class Model {
private final boolean isIndicator; private final boolean isIndicator;
private final boolean deleteHistory; private final boolean deleteHistory;
private final List<ModelColumn> columns; private final List<ModelColumn> columns;
private final Scope source; private final int sourceScopeId;
public Model(String name, List<ModelColumn> columns, boolean isIndicator, boolean deleteHistory, Scope source) { public Model(String name, List<ModelColumn> columns, boolean isIndicator, boolean deleteHistory,
int sourceScopeId) {
this.name = name; this.name = name;
this.columns = columns; this.columns = columns;
this.isIndicator = isIndicator; this.isIndicator = isIndicator;
this.deleteHistory = deleteHistory; this.deleteHistory = deleteHistory;
this.source = source; this.sourceScopeId = sourceScopeId;
} }
public Model copy(String name) { public Model copy(String name) {
return new Model(name, columns, isIndicator, deleteHistory, source); return new Model(name, columns, isIndicator, deleteHistory, sourceScopeId);
} }
} }
...@@ -19,8 +19,7 @@ ...@@ -19,8 +19,7 @@
package org.apache.skywalking.oap.server.core.storage.query; package org.apache.skywalking.oap.server.core.storage.query;
import java.io.IOException; import java.io.IOException;
import org.apache.skywalking.oap.server.core.query.entity.*; import org.apache.skywalking.oap.server.core.query.entity.Alarms;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.DAO; import org.apache.skywalking.oap.server.core.storage.DAO;
/** /**
...@@ -28,6 +27,6 @@ import org.apache.skywalking.oap.server.core.storage.DAO; ...@@ -28,6 +27,6 @@ import org.apache.skywalking.oap.server.core.storage.DAO;
*/ */
public interface IAlarmQueryDAO extends DAO { public interface IAlarmQueryDAO extends DAO {
Alarms getAlarm(final Scope scope, final String keyword, final int limit, final int from, final long startTB, Alarms getAlarm(final Integer scopeId, final String keyword, final int limit, final int from, final long startTB,
final long endTB) throws IOException; final long endTB) throws IOException;
} }
...@@ -20,11 +20,10 @@ package org.apache.skywalking.oap.query.graphql.resolver; ...@@ -20,11 +20,10 @@ package org.apache.skywalking.oap.query.graphql.resolver;
import com.coxautodev.graphql.tools.GraphQLQueryResolver; import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import java.io.IOException; import java.io.IOException;
import org.apache.skywalking.oap.query.graphql.type.Duration; import org.apache.skywalking.oap.query.graphql.type.*;
import org.apache.skywalking.oap.server.core.CoreModule; import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.query.*; import org.apache.skywalking.oap.server.core.query.*;
import org.apache.skywalking.oap.server.core.query.entity.*; import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.library.module.ModuleManager; import org.apache.skywalking.oap.server.library.module.ModuleManager;
/** /**
...@@ -55,6 +54,6 @@ public class AlarmQuery implements GraphQLQueryResolver { ...@@ -55,6 +54,6 @@ public class AlarmQuery implements GraphQLQueryResolver {
long startTimeBucket = DurationUtils.INSTANCE.startTimeDurationToSecondTimeBucket(duration.getStep(), duration.getStart()); long startTimeBucket = DurationUtils.INSTANCE.startTimeDurationToSecondTimeBucket(duration.getStep(), duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.endTimeDurationToSecondTimeBucket(duration.getStep(), duration.getEnd()); long endTimeBucket = DurationUtils.INSTANCE.endTimeDurationToSecondTimeBucket(duration.getStep(), duration.getEnd());
return getQueryService().getAlarm(scope, keyword, paging, startTimeBucket, endTimeBucket); return getQueryService().getAlarm(scope.getScopeId(), keyword, paging, startTimeBucket, endTimeBucket);
} }
} }
...@@ -22,7 +22,6 @@ import java.io.IOException; ...@@ -22,7 +22,6 @@ import java.io.IOException;
import java.util.Map; import java.util.Map;
import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.RegisterSource; import org.apache.skywalking.oap.server.core.register.RegisterSource;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.IRegisterLockDAO; import org.apache.skywalking.oap.server.core.storage.IRegisterLockDAO;
import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient; import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.EsDAO; import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.EsDAO;
...@@ -41,8 +40,8 @@ public class RegisterLockDAOImpl extends EsDAO implements IRegisterLockDAO { ...@@ -41,8 +40,8 @@ public class RegisterLockDAOImpl extends EsDAO implements IRegisterLockDAO {
super(client); super(client);
} }
@Override public int getId(Scope scope, RegisterSource registerSource) { @Override public int getId(int scopeId, RegisterSource registerSource) {
String id = String.valueOf(scope.ordinal()); String id = scopeId + "";
int sequence = Const.NONE; int sequence = Const.NONE;
try { try {
......
...@@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.lock; ...@@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.lock;
import java.io.IOException; import java.io.IOException;
import org.apache.skywalking.oap.server.core.register.worker.InventoryProcess; import org.apache.skywalking.oap.server.core.register.worker.InventoryProcess;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageException; import org.apache.skywalking.oap.server.core.storage.StorageException;
import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntityAnnotationUtils; import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntityAnnotationUtils;
import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient; import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
...@@ -56,8 +55,8 @@ public class RegisterLockInstaller { ...@@ -56,8 +55,8 @@ public class RegisterLockInstaller {
} }
for (Class registerSource : InventoryProcess.INSTANCE.getAllRegisterSources()) { for (Class registerSource : InventoryProcess.INSTANCE.getAllRegisterSources()) {
Scope sourceScope = StorageEntityAnnotationUtils.getSourceScope(registerSource); int sourceScopeId = StorageEntityAnnotationUtils.getSourceScope(registerSource);
putIfAbsent(sourceScope.ordinal()); putIfAbsent(sourceScopeId);
} }
} catch (IOException e) { } catch (IOException e) {
throw new StorageException(e.getMessage()); throw new StorageException(e.getMessage());
......
...@@ -23,7 +23,6 @@ import java.io.IOException; ...@@ -23,7 +23,6 @@ import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import org.apache.skywalking.oap.server.core.alarm.AlarmRecord; import org.apache.skywalking.oap.server.core.alarm.AlarmRecord;
import org.apache.skywalking.oap.server.core.query.entity.*; import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO; import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO;
import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient; import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.*; import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.*;
...@@ -41,15 +40,16 @@ public class AlarmQueryEsDAO extends EsDAO implements IAlarmQueryDAO { ...@@ -41,15 +40,16 @@ public class AlarmQueryEsDAO extends EsDAO implements IAlarmQueryDAO {
super(client); super(client);
} }
public Alarms getAlarm(final Scope scope, final String keyword, final int limit, final int from, final long startTB, public Alarms getAlarm(final Integer scopeId, final String keyword, final int limit, final int from,
final long startTB,
final long endTB) throws IOException { final long endTB) throws IOException {
SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource(); SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must().add(QueryBuilders.rangeQuery(AlarmRecord.TIME_BUCKET).gte(startTB).lte(endTB)); boolQueryBuilder.must().add(QueryBuilders.rangeQuery(AlarmRecord.TIME_BUCKET).gte(startTB).lte(endTB));
if (Objects.nonNull(scope)) { if (Objects.nonNull(scopeId)) {
boolQueryBuilder.must().add(QueryBuilders.termQuery(AlarmRecord.SCOPE, scope.ordinal())); boolQueryBuilder.must().add(QueryBuilders.termQuery(AlarmRecord.SCOPE, scopeId.intValue()));
} }
if (!Strings.isNullOrEmpty(keyword)) { if (!Strings.isNullOrEmpty(keyword)) {
...@@ -74,7 +74,8 @@ public class AlarmQueryEsDAO extends EsDAO implements IAlarmQueryDAO { ...@@ -74,7 +74,8 @@ public class AlarmQueryEsDAO extends EsDAO implements IAlarmQueryDAO {
message.setId(String.valueOf(alarmRecord.getId0())); message.setId(String.valueOf(alarmRecord.getId0()));
message.setMessage(alarmRecord.getAlarmMessage()); message.setMessage(alarmRecord.getAlarmMessage());
message.setStartTime(alarmRecord.getStartTime()); message.setStartTime(alarmRecord.getStartTime());
message.setScope(Scope.valueOf(alarmRecord.getScope())); message.setScope(Scope.Finder.valueOf(alarmRecord.getScope()));
message.setScopeId(alarmRecord.getScope());
alarms.getMsgs().add(message); alarms.getMsgs().add(message);
} }
return alarms; return alarms;
......
...@@ -23,7 +23,6 @@ import java.sql.*; ...@@ -23,7 +23,6 @@ import java.sql.*;
import java.util.*; import java.util.*;
import org.apache.skywalking.oap.server.core.alarm.AlarmRecord; import org.apache.skywalking.oap.server.core.alarm.AlarmRecord;
import org.apache.skywalking.oap.server.core.query.entity.*; import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO; import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO;
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient; import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
...@@ -39,13 +38,15 @@ public class H2AlarmQueryDAO implements IAlarmQueryDAO { ...@@ -39,13 +38,15 @@ public class H2AlarmQueryDAO implements IAlarmQueryDAO {
} }
@Override @Override
public Alarms getAlarm(Scope scope, String keyword, int limit, int from, long startTB, public Alarms getAlarm(Integer scopeId, String keyword, int limit, int from, long startTB,
long endTB) throws IOException { long endTB) throws IOException {
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
List<Object> parameters = new ArrayList<>(10); List<Object> parameters = new ArrayList<>(10);
sql.append("from ").append(AlarmRecord.INDEX_NAME).append(" where "); sql.append("from ").append(AlarmRecord.INDEX_NAME).append(" where ");
sql.append(" 1=1 "); sql.append(" 1=1 ");
sql.append(" and ").append(AlarmRecord.SCOPE).append(" = ?");
parameters.add(scopeId.intValue());
if (startTB != 0 && endTB != 0) { if (startTB != 0 && endTB != 0) {
sql.append(" and ").append(AlarmRecord.TIME_BUCKET).append(" >= ?"); sql.append(" and ").append(AlarmRecord.TIME_BUCKET).append(" >= ?");
parameters.add(startTB); parameters.add(startTB);
...@@ -75,7 +76,8 @@ public class H2AlarmQueryDAO implements IAlarmQueryDAO { ...@@ -75,7 +76,8 @@ public class H2AlarmQueryDAO implements IAlarmQueryDAO {
message.setId(resultSet.getString(AlarmRecord.ID0)); message.setId(resultSet.getString(AlarmRecord.ID0));
message.setMessage(resultSet.getString(AlarmRecord.ALARM_MESSAGE)); message.setMessage(resultSet.getString(AlarmRecord.ALARM_MESSAGE));
message.setStartTime(resultSet.getLong(AlarmRecord.START_TIME)); message.setStartTime(resultSet.getLong(AlarmRecord.START_TIME));
message.setScope(Scope.valueOf(resultSet.getInt(AlarmRecord.SCOPE))); message.setScope(Scope.Finder.valueOf(resultSet.getInt(AlarmRecord.SCOPE)));
message.setScopeId(resultSet.getInt(AlarmRecord.SCOPE));
alarms.getMsgs().add(message); alarms.getMsgs().add(message);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册