From 7abec320317397fcc32d22af0db7c6f1477d4f3d Mon Sep 17 00:00:00 2001 From: peng-yongsheng <8082209@qq.com> Date: Wed, 1 Nov 2017 18:59:46 +0800 Subject: [PATCH] All Daos are add in. --- .../storage/dao/IApplicationCacheDAO.java | 28 ++++ .../storage/dao/IGlobalTraceDAO.java | 25 ++++ .../storage/dao/IInstPerformanceDAO.java | 25 ++++ .../storage/dao/IInstanceCacheDAO.java | 26 ++++ .../collector/storage/dao/IInstanceDAO.java | 36 +++++ .../storage/dao/INodeComponentDAO.java | 25 ++++ .../storage/dao/INodeReferenceDAO.java | 25 ++++ .../storage/dao/ISegmentCostDAO.java | 25 ++++ .../collector/storage/dao/ISegmentDAO.java | 25 ++++ .../storage/dao/IServiceEntryDAO.java | 25 ++++ .../storage/dao/IServiceNameCacheDAO.java | 28 ++++ .../storage/dao/IServiceNameDAO.java | 32 +++++ .../storage/dao/IServiceReferenceDAO.java | 25 ++++ .../table/register/ApplicationDataDefine.java | 17 +++ .../table/register/InstanceDataDefine.java | 33 +++++ .../table/register/ServiceNameDataDefine.java | 21 +++ .../storage/es/dao/ApplicationEsCacheDAO.java | 71 ++++++++++ .../storage/es/dao/ApplicationEsDAO.java | 14 +- .../storage/es/dao/GlobalTraceEsDAO.java | 58 ++++++++ .../storage/es/dao/InstPerformanceEsDAO.java | 80 +++++++++++ .../storage/es/dao/InstanceEsCacheDAO.java | 43 ++++++ .../storage/es/dao/InstanceEsDAO.java | 113 +++++++++++++++ .../storage/es/dao/NodeComponentEsDAO.java | 75 ++++++++++ .../storage/es/dao/NodeReferenceEsDAO.java | 90 ++++++++++++ .../storage/es/dao/SegmentCostEsDAO.java | 63 +++++++++ .../storage/es/dao/SegmentEsDAO.java | 56 ++++++++ .../storage/es/dao/ServiceEntryEsDAO.java | 74 ++++++++++ .../storage/es/dao/ServiceNameEsCacheDAO.java | 69 ++++++++++ .../storage/es/dao/ServiceNameEsDAO.java | 65 +++++++++ .../storage/es/dao/ServiceReferenceEsDAO.java | 106 ++++++++++++++ .../resources/META-INF/defines/es_dao.define | 16 ++- .../storage/h2/dao/ApplicationH2CacheDAO.java | 72 ++++++++++ .../storage/h2/dao/ApplicationH2DAO.java | 21 +-- .../storage/h2/dao/GlobalTraceH2DAO.java | 63 +++++++++ .../storage/h2/dao/InstPerformanceH2DAO.java | 99 +++++++++++++ .../storage/h2/dao/InstanceH2CacheDAO.java | 55 ++++++++ .../storage/h2/dao/InstanceH2DAO.java | 107 ++++++++++++++ .../storage/h2/dao/NodeComponentH2DAO.java | 102 ++++++++++++++ .../storage/h2/dao/NodeReferenceH2DAO.java | 114 +++++++++++++++ .../storage/h2/dao/SegmentCostH2DAO.java | 68 +++++++++ .../storage/h2/dao/SegmentH2DAO.java | 60 ++++++++ .../storage/h2/dao/ServiceEntryH2DAO.java | 98 +++++++++++++ .../storage/h2/dao/ServiceNameH2CacheDAO.java | 74 ++++++++++ .../storage/h2/dao/ServiceNameH2DAO.java | 73 ++++++++++ .../storage/h2/dao/ServiceReferenceH2DAO.java | 130 ++++++++++++++++++ .../resources/META-INF/defines/h2_dao.define | 16 ++- 46 files changed, 2551 insertions(+), 15 deletions(-) create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTraceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstPerformanceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/INodeComponentDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/INodeReferenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstPerformanceEsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/NodeComponentEsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/NodeReferenceEsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentCostEsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceEntryEsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstPerformanceH2DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/NodeComponentH2DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/NodeReferenceH2DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentCostH2DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2DAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2DAO.java diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java new file mode 100644 index 000000000..0eeac4163 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IApplicationCacheDAO.java @@ -0,0 +1,28 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +/** + * @author peng-yongsheng + */ +public interface IApplicationCacheDAO { + int getApplicationId(String applicationCode); + + String getApplicationCode(int applicationId); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTraceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTraceDAO.java new file mode 100644 index 000000000..47782aba7 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IGlobalTraceDAO.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +/** + * @author peng-yongsheng + */ +public interface IGlobalTraceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstPerformanceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstPerformanceDAO.java new file mode 100644 index 000000000..e998085a4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstPerformanceDAO.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +/** + * @author peng-yongsheng + */ +public interface IInstPerformanceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java new file mode 100644 index 000000000..3df32233b --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceCacheDAO.java @@ -0,0 +1,26 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +/** + * @author peng-yongsheng + */ +public interface IInstanceCacheDAO { + int getApplicationId(int applicationInstanceId); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceDAO.java new file mode 100644 index 000000000..537c7a729 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IInstanceDAO.java @@ -0,0 +1,36 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +import org.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public interface IInstanceDAO { + int getInstanceId(int applicationId, String agentUUID); + + int getMaxInstanceId(); + + int getMinInstanceId(); + + void save(Data data); + + void updateHeartbeatTime(int instanceId, long heartbeatTime); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/INodeComponentDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/INodeComponentDAO.java new file mode 100644 index 000000000..edede14dc --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/INodeComponentDAO.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +/** + * @author peng-yongsheng + */ +public interface INodeComponentDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/INodeReferenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/INodeReferenceDAO.java new file mode 100644 index 000000000..50313cd7d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/INodeReferenceDAO.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +/** + * @author peng-yongsheng + */ +public interface INodeReferenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostDAO.java new file mode 100644 index 000000000..d077be792 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentCostDAO.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +/** + * @author peng-yongsheng + */ +public interface ISegmentCostDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentDAO.java new file mode 100644 index 000000000..a7aacac67 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/ISegmentDAO.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +/** + * @author peng-yongsheng + */ +public interface ISegmentDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryDAO.java new file mode 100644 index 000000000..96450a5a4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceEntryDAO.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +/** + * @author peng-yongsheng + */ +public interface IServiceEntryDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java new file mode 100644 index 000000000..f9d352ded --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameCacheDAO.java @@ -0,0 +1,28 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +/** + * @author peng-yongsheng + */ +public interface IServiceNameCacheDAO { + String getServiceName(int serviceId); + + int getServiceId(int applicationId, String serviceName); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameDAO.java new file mode 100644 index 000000000..f563d029e --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceNameDAO.java @@ -0,0 +1,32 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +import org.skywalking.apm.collector.core.data.Data; + +/** + * @author peng-yongsheng + */ +public interface IServiceNameDAO { + int getMaxServiceId(); + + int getMinServiceId(); + + void save(Data data); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceDAO.java new file mode 100644 index 000000000..90eb440c3 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/dao/IServiceReferenceDAO.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.dao; + +/** + * @author peng-yongsheng + */ +public interface IServiceReferenceDAO { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ApplicationDataDefine.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ApplicationDataDefine.java index a2e30bd25..b2e01e508 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ApplicationDataDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ApplicationDataDefine.java @@ -18,6 +18,7 @@ package org.skywalking.apm.collector.storage.table.register; +import org.skywalking.apm.collector.core.data.Data; import org.skywalking.apm.collector.storage.base.define.Attribute; import org.skywalking.apm.collector.storage.base.define.AttributeType; import org.skywalking.apm.collector.storage.base.define.DataDefine; @@ -38,4 +39,20 @@ public class ApplicationDataDefine extends DataDefine { addAttribute(1, new Attribute(ApplicationTable.COLUMN_APPLICATION_CODE, AttributeType.STRING, new CoverOperation())); addAttribute(2, new Attribute(ApplicationTable.COLUMN_APPLICATION_ID, AttributeType.INTEGER, new CoverOperation())); } + + public enum Application { + INSTANCE; + + public String getId(Data data) { + return data.getDataString(0); + } + + public String getApplicationCode(Data data) { + return data.getDataString(1); + } + + public int getApplicationId(Data data) { + return data.getDataInteger(1); + } + } } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/InstanceDataDefine.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/InstanceDataDefine.java index e3b6c526a..835c4366d 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/InstanceDataDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/InstanceDataDefine.java @@ -18,6 +18,7 @@ package org.skywalking.apm.collector.storage.table.register; +import org.skywalking.apm.collector.core.data.Data; import org.skywalking.apm.collector.storage.base.define.Attribute; import org.skywalking.apm.collector.storage.base.define.AttributeType; import org.skywalking.apm.collector.storage.base.define.DataDefine; @@ -42,4 +43,36 @@ public class InstanceDataDefine extends DataDefine { addAttribute(5, new Attribute(InstanceTable.COLUMN_HEARTBEAT_TIME, AttributeType.LONG, new CoverOperation())); addAttribute(6, new Attribute(InstanceTable.COLUMN_OS_INFO, AttributeType.STRING, new CoverOperation())); } + + public enum Instance { + INSTANCE; + + public String getId(Data data) { + return data.getDataString(0); + } + + public int getApplicationId(Data data) { + return data.getDataInteger(0); + } + + public String getAgentUUID(Data data) { + return data.getDataString(1); + } + + public long getRegisterTime(Data data) { + return data.getDataLong(0); + } + + public int getInstanceId(Data data) { + return data.getDataInteger(1); + } + + public long getHeartBeatTime(Data data) { + return data.getDataLong(1); + } + + public String getOsInfo(Data data) { + return data.getDataString(2); + } + } } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceNameDataDefine.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceNameDataDefine.java index 9ad0fddb4..b38139adb 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceNameDataDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/skywalking/apm/collector/storage/table/register/ServiceNameDataDefine.java @@ -18,6 +18,7 @@ package org.skywalking.apm.collector.storage.table.register; +import org.skywalking.apm.collector.core.data.Data; import org.skywalking.apm.collector.storage.base.define.Attribute; import org.skywalking.apm.collector.storage.base.define.AttributeType; import org.skywalking.apm.collector.storage.base.define.DataDefine; @@ -39,4 +40,24 @@ public class ServiceNameDataDefine extends DataDefine { addAttribute(2, new Attribute(ServiceNameTable.COLUMN_APPLICATION_ID, AttributeType.INTEGER, new CoverOperation())); addAttribute(3, new Attribute(ServiceNameTable.COLUMN_SERVICE_ID, AttributeType.INTEGER, new CoverOperation())); } + + public enum ServiceName { + INSTANCE; + + public String getId(Data data) { + return data.getDataString(0); + } + + public String getServiceName(Data data) { + return data.getDataString(1); + } + + public int getApplicationId(Data data) { + return data.getDataInteger(0); + } + + public int getServiceId(Data data) { + return data.getDataInteger(1); + } + } } diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java new file mode 100644 index 000000000..2710c4e14 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsCacheDAO.java @@ -0,0 +1,71 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import org.elasticsearch.action.get.GetRequestBuilder; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; +import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.skywalking.apm.collector.core.util.Const; +import org.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.register.ApplicationTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationEsCacheDAO extends EsDAO implements IApplicationCacheDAO { + + private final Logger logger = LoggerFactory.getLogger(ApplicationEsCacheDAO.class); + + @Override public int getApplicationId(String applicationCode) { + ElasticSearchClient client = getClient(); + + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(ApplicationTable.TABLE); + searchRequestBuilder.setTypes("type"); + searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH); + searchRequestBuilder.setQuery(QueryBuilders.termQuery(ApplicationTable.COLUMN_APPLICATION_CODE, applicationCode)); + searchRequestBuilder.setSize(1); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + if (searchResponse.getHits().totalHits > 0) { + SearchHit searchHit = searchResponse.getHits().iterator().next(); + return (int)searchHit.getSource().get(ApplicationTable.COLUMN_APPLICATION_ID); + } + return 0; + } + + @Override public String getApplicationCode(int applicationId) { + logger.debug("get application code, applicationId: {}", applicationId); + ElasticSearchClient client = getClient(); + GetRequestBuilder getRequestBuilder = client.prepareGet(ApplicationTable.TABLE, String.valueOf(applicationId)); + + GetResponse getResponse = getRequestBuilder.get(); + if (getResponse.isExists()) { + return (String)getResponse.getSource().get(ApplicationTable.COLUMN_APPLICATION_CODE); + } + return Const.EMPTY_STRING; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsDAO.java index a2ef0465f..68d5d3dab 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ApplicationEsDAO.java @@ -26,6 +26,7 @@ import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; import org.skywalking.apm.collector.core.data.Data; import org.skywalking.apm.collector.storage.dao.IApplicationDAO; import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.register.ApplicationDataDefine; import org.skywalking.apm.collector.storage.table.register.ApplicationTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,13 +47,16 @@ public class ApplicationEsDAO extends EsDAO implements IApplicationDAO { } @Override public void save(Data data) { - logger.debug("save application register info, application id: {}, application code: {}", application.getApplicationId(), application.getApplicationCode()); + String id = ApplicationDataDefine.Application.INSTANCE.getId(data); + int applicationId = ApplicationDataDefine.Application.INSTANCE.getApplicationId(data); + String applicationCode = ApplicationDataDefine.Application.INSTANCE.getApplicationCode(data); + logger.debug("save application register info, application id: {}, application code: {}", applicationId, applicationCode); ElasticSearchClient client = getClient(); Map source = new HashMap<>(); - source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode()); - source.put(ApplicationTable.COLUMN_APPLICATION_ID, application.getApplicationId()); + source.put(ApplicationTable.COLUMN_APPLICATION_CODE, applicationCode); + source.put(ApplicationTable.COLUMN_APPLICATION_ID, applicationId); - IndexResponse response = client.prepareIndex(ApplicationTable.TABLE, application.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); - logger.debug("save application register info, application id: {}, application code: {}, status: {}", application.getApplicationId(), application.getApplicationCode(), response.status().name()); + IndexResponse response = client.prepareIndex(ApplicationTable.TABLE, id).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); + logger.debug("save application register info, application id: {}, application code: {}, status: {}", applicationId, applicationCode, response.status().name()); } } diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsDAO.java new file mode 100644 index 000000000..56937f384 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/GlobalTraceEsDAO.java @@ -0,0 +1,58 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.skywalking.apm.collector.core.UnexpectedException; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.IGlobalTraceDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GlobalTraceEsDAO extends EsDAO implements IGlobalTraceDAO, IPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(GlobalTraceEsDAO.class); + + @Override public Data get(String id, DataDefine dataDefine) { + throw new UnexpectedException("There is no need to merge stream data with database data."); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(Data data) { + throw new UnexpectedException("There is no need to merge stream data with database data."); + } + + @Override public IndexRequestBuilder prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + source.put(GlobalTraceTable.COLUMN_SEGMENT_ID, data.getDataString(1)); + source.put(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, data.getDataString(2)); + source.put(GlobalTraceTable.COLUMN_TIME_BUCKET, data.getDataLong(0)); + logger.debug("global trace source: {}", source.toString()); + return getClient().prepareIndex(GlobalTraceTable.TABLE, data.getDataString(0)).setSource(source); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstPerformanceEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstPerformanceEsDAO.java new file mode 100644 index 000000000..d00be4129 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstPerformanceEsDAO.java @@ -0,0 +1,80 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.IInstPerformanceDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.instance.InstPerformanceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstPerformanceEsDAO extends EsDAO implements IInstPerformanceDAO, IPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(InstPerformanceEsDAO.class); + + @Override public Data get(String id, DataDefine dataDefine) { + GetResponse getResponse = getClient().prepareGet(InstPerformanceTable.TABLE, id).get(); + if (getResponse.isExists()) { + logger.debug("id: {} is exist", id); + Data data = dataDefine.build(id); + Map source = getResponse.getSource(); + data.setDataInteger(0, (Integer)source.get(InstPerformanceTable.COLUMN_APPLICATION_ID)); + data.setDataInteger(1, (Integer)source.get(InstPerformanceTable.COLUMN_INSTANCE_ID)); + data.setDataInteger(2, (Integer)source.get(InstPerformanceTable.COLUMN_CALLS)); + data.setDataLong(0, ((Number)source.get(InstPerformanceTable.COLUMN_COST_TOTAL)).longValue()); + data.setDataLong(1, ((Number)source.get(InstPerformanceTable.COLUMN_TIME_BUCKET)).longValue()); + return data; + } else { + return null; + } + } + + @Override public IndexRequestBuilder prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + source.put(InstPerformanceTable.COLUMN_APPLICATION_ID, data.getDataInteger(0)); + source.put(InstPerformanceTable.COLUMN_INSTANCE_ID, data.getDataInteger(1)); + source.put(InstPerformanceTable.COLUMN_CALLS, data.getDataInteger(2)); + source.put(InstPerformanceTable.COLUMN_COST_TOTAL, data.getDataLong(0)); + source.put(InstPerformanceTable.COLUMN_TIME_BUCKET, data.getDataLong(1)); + + return getClient().prepareIndex(InstPerformanceTable.TABLE, data.getDataString(0)).setSource(source); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(Data data) { + Map source = new HashMap<>(); + source.put(InstPerformanceTable.COLUMN_APPLICATION_ID, data.getDataInteger(0)); + source.put(InstPerformanceTable.COLUMN_INSTANCE_ID, data.getDataInteger(1)); + source.put(InstPerformanceTable.COLUMN_CALLS, data.getDataInteger(2)); + source.put(InstPerformanceTable.COLUMN_COST_TOTAL, data.getDataLong(0)); + source.put(InstPerformanceTable.COLUMN_TIME_BUCKET, data.getDataLong(1)); + + return getClient().prepareUpdate(InstPerformanceTable.TABLE, data.getDataString(0)).setDoc(source); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java new file mode 100644 index 000000000..44fbbc0a1 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsCacheDAO.java @@ -0,0 +1,43 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import org.elasticsearch.action.get.GetResponse; +import org.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceEsCacheDAO extends EsDAO implements IInstanceCacheDAO { + + private final Logger logger = LoggerFactory.getLogger(InstanceEsCacheDAO.class); + + @Override public int getApplicationId(int applicationInstanceId) { + GetResponse response = getClient().prepareGet(InstanceTable.TABLE, String.valueOf(applicationInstanceId)).get(); + if (response.isExists()) { + return (int)response.getSource().get(InstanceTable.COLUMN_APPLICATION_ID); + } else { + return 0; + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsDAO.java new file mode 100644 index 000000000..193f4d10d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/InstanceEsDAO.java @@ -0,0 +1,113 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.action.support.WriteRequest; +import org.elasticsearch.action.update.UpdateRequest; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; +import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.dao.IInstanceDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.register.InstanceDataDefine; +import org.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceEsDAO extends EsDAO implements IInstanceDAO { + + private final Logger logger = LoggerFactory.getLogger(InstanceEsDAO.class); + + @Override public int getInstanceId(int applicationId, String agentUUID) { + ElasticSearchClient client = getClient(); + + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(InstanceTable.TABLE); + searchRequestBuilder.setTypes("type"); + searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH); + BoolQueryBuilder builder = QueryBuilders.boolQuery(); + builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId)); + builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_AGENT_UUID, agentUUID)); + searchRequestBuilder.setQuery(builder); + searchRequestBuilder.setSize(1); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + if (searchResponse.getHits().totalHits > 0) { + SearchHit searchHit = searchResponse.getHits().iterator().next(); + return (int)searchHit.getSource().get(InstanceTable.COLUMN_INSTANCE_ID); + } + return 0; + } + + @Override public int getMaxInstanceId() { + return getMaxId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); + } + + @Override public int getMinInstanceId() { + return getMinId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); + } + + @Override public void save(Data data) { + String id = InstanceDataDefine.Instance.INSTANCE.getId(data); + int instanceId = InstanceDataDefine.Instance.INSTANCE.getInstanceId(data); + int applicationId = InstanceDataDefine.Instance.INSTANCE.getApplicationId(data); + String agentUUID = InstanceDataDefine.Instance.INSTANCE.getAgentUUID(data); + long registerTime = InstanceDataDefine.Instance.INSTANCE.getRegisterTime(data); + long heartBeatTime = InstanceDataDefine.Instance.INSTANCE.getHeartBeatTime(data); + String osInfo = InstanceDataDefine.Instance.INSTANCE.getOsInfo(data); + + logger.debug("save instance register info, application id: {}, agentUUID: {}", applicationId, agentUUID); + ElasticSearchClient client = getClient(); + Map source = new HashMap<>(); + source.put(InstanceTable.COLUMN_INSTANCE_ID, instanceId); + source.put(InstanceTable.COLUMN_APPLICATION_ID, applicationId); + source.put(InstanceTable.COLUMN_AGENT_UUID, agentUUID); + source.put(InstanceTable.COLUMN_REGISTER_TIME, registerTime); + source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, heartBeatTime); + source.put(InstanceTable.COLUMN_OS_INFO, osInfo); + + IndexResponse response = client.prepareIndex(InstanceTable.TABLE, id).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); + logger.debug("save instance register info, application id: {}, agentUUID: {}, status: {}", applicationId, agentUUID, response.status().name()); + } + + @Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) { + ElasticSearchClient client = getClient(); + UpdateRequest updateRequest = new UpdateRequest(); + updateRequest.index(InstanceTable.TABLE); + updateRequest.type("type"); + updateRequest.id(String.valueOf(instanceId)); + updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); + + Map source = new HashMap<>(); + source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, heartbeatTime); + + updateRequest.doc(source); + client.update(updateRequest); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/NodeComponentEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/NodeComponentEsDAO.java new file mode 100644 index 000000000..050d4bba8 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/NodeComponentEsDAO.java @@ -0,0 +1,75 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.INodeComponentDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.node.NodeComponentTable; + +/** + * @author peng-yongsheng + */ +public class NodeComponentEsDAO extends EsDAO implements INodeComponentDAO, IPersistenceDAO { + + @Override public Data get(String id, DataDefine dataDefine) { + GetResponse getResponse = getClient().prepareGet(NodeComponentTable.TABLE, id).get(); + if (getResponse.isExists()) { + Data data = dataDefine.build(id); + Map source = getResponse.getSource(); + data.setDataInteger(0, ((Number)source.get(NodeComponentTable.COLUMN_COMPONENT_ID)).intValue()); + data.setDataString(1, (String)source.get(NodeComponentTable.COLUMN_COMPONENT_NAME)); + data.setDataInteger(1, ((Number)source.get(NodeComponentTable.COLUMN_PEER_ID)).intValue()); + data.setDataString(2, (String)source.get(NodeComponentTable.COLUMN_PEER)); + data.setDataLong(0, (Long)source.get(NodeComponentTable.COLUMN_TIME_BUCKET)); + return data; + } else { + return null; + } + } + + @Override public IndexRequestBuilder prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + source.put(NodeComponentTable.COLUMN_COMPONENT_ID, data.getDataInteger(0)); + source.put(NodeComponentTable.COLUMN_COMPONENT_NAME, data.getDataString(1)); + source.put(NodeComponentTable.COLUMN_PEER_ID, data.getDataInteger(1)); + source.put(NodeComponentTable.COLUMN_PEER, data.getDataString(2)); + source.put(NodeComponentTable.COLUMN_TIME_BUCKET, data.getDataLong(0)); + + return getClient().prepareIndex(NodeComponentTable.TABLE, data.getDataString(0)).setSource(source); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(Data data) { + Map source = new HashMap<>(); + source.put(NodeComponentTable.COLUMN_COMPONENT_ID, data.getDataInteger(0)); + source.put(NodeComponentTable.COLUMN_COMPONENT_NAME, data.getDataString(1)); + source.put(NodeComponentTable.COLUMN_PEER_ID, data.getDataInteger(1)); + source.put(NodeComponentTable.COLUMN_PEER, data.getDataString(2)); + source.put(NodeComponentTable.COLUMN_TIME_BUCKET, data.getDataLong(0)); + + return getClient().prepareUpdate(NodeComponentTable.TABLE, data.getDataString(0)).setDoc(source); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/NodeReferenceEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/NodeReferenceEsDAO.java new file mode 100644 index 000000000..8fdd82ba4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/NodeReferenceEsDAO.java @@ -0,0 +1,90 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.INodeReferenceDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.noderef.NodeReferenceTable; + +/** + * @author peng-yongsheng + */ +public class NodeReferenceEsDAO extends EsDAO implements INodeReferenceDAO, IPersistenceDAO { + + @Override public Data get(String id, DataDefine dataDefine) { + GetResponse getResponse = getClient().prepareGet(NodeReferenceTable.TABLE, id).get(); + if (getResponse.isExists()) { + Data data = dataDefine.build(id); + Map source = getResponse.getSource(); + data.setDataInteger(0, ((Number)source.get(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID)).intValue()); + data.setDataInteger(1, ((Number)source.get(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID)).intValue()); + data.setDataString(1, (String)source.get(NodeReferenceTable.COLUMN_BEHIND_PEER)); + data.setDataInteger(2, ((Number)source.get(NodeReferenceTable.COLUMN_S1_LTE)).intValue()); + data.setDataInteger(3, ((Number)source.get(NodeReferenceTable.COLUMN_S3_LTE)).intValue()); + data.setDataInteger(4, ((Number)source.get(NodeReferenceTable.COLUMN_S5_LTE)).intValue()); + data.setDataInteger(5, ((Number)source.get(NodeReferenceTable.COLUMN_S5_GT)).intValue()); + data.setDataInteger(6, ((Number)source.get(NodeReferenceTable.COLUMN_SUMMARY)).intValue()); + data.setDataInteger(7, ((Number)source.get(NodeReferenceTable.COLUMN_ERROR)).intValue()); + data.setDataLong(0, ((Number)source.get(NodeReferenceTable.COLUMN_TIME_BUCKET)).longValue()); + return data; + } else { + return null; + } + } + + @Override public IndexRequestBuilder prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + source.put(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID, data.getDataInteger(0)); + source.put(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID, data.getDataInteger(1)); + source.put(NodeReferenceTable.COLUMN_BEHIND_PEER, data.getDataString(1)); + source.put(NodeReferenceTable.COLUMN_S1_LTE, data.getDataInteger(2)); + source.put(NodeReferenceTable.COLUMN_S3_LTE, data.getDataInteger(3)); + source.put(NodeReferenceTable.COLUMN_S5_LTE, data.getDataInteger(4)); + source.put(NodeReferenceTable.COLUMN_S5_GT, data.getDataInteger(5)); + source.put(NodeReferenceTable.COLUMN_SUMMARY, data.getDataInteger(6)); + source.put(NodeReferenceTable.COLUMN_ERROR, data.getDataInteger(7)); + source.put(NodeReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(0)); + + return getClient().prepareIndex(NodeReferenceTable.TABLE, data.getDataString(0)).setSource(source); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(Data data) { + Map source = new HashMap<>(); + source.put(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID, data.getDataInteger(0)); + source.put(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID, data.getDataInteger(1)); + source.put(NodeReferenceTable.COLUMN_BEHIND_PEER, data.getDataString(1)); + source.put(NodeReferenceTable.COLUMN_S1_LTE, data.getDataInteger(2)); + source.put(NodeReferenceTable.COLUMN_S3_LTE, data.getDataInteger(3)); + source.put(NodeReferenceTable.COLUMN_S5_LTE, data.getDataInteger(4)); + source.put(NodeReferenceTable.COLUMN_S5_GT, data.getDataInteger(5)); + source.put(NodeReferenceTable.COLUMN_SUMMARY, data.getDataInteger(6)); + source.put(NodeReferenceTable.COLUMN_ERROR, data.getDataInteger(7)); + source.put(NodeReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(0)); + + return getClient().prepareUpdate(NodeReferenceTable.TABLE, data.getDataString(0)).setDoc(source); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentCostEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentCostEsDAO.java new file mode 100644 index 000000000..7db9d80f4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentCostEsDAO.java @@ -0,0 +1,63 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.ISegmentCostDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.segment.SegmentCostTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class SegmentCostEsDAO extends EsDAO implements ISegmentCostDAO, IPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(SegmentCostEsDAO.class); + + @Override public Data get(String id, DataDefine dataDefine) { + return null; + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(Data data) { + return null; + } + + @Override public IndexRequestBuilder prepareBatchInsert(Data data) { + logger.debug("segment cost prepareBatchInsert, id: {}", data.getDataString(0)); + Map source = new HashMap<>(); + source.put(SegmentCostTable.COLUMN_SEGMENT_ID, data.getDataString(1)); + source.put(SegmentCostTable.COLUMN_APPLICATION_ID, data.getDataInteger(0)); + source.put(SegmentCostTable.COLUMN_SERVICE_NAME, data.getDataString(2)); + source.put(SegmentCostTable.COLUMN_COST, data.getDataLong(0)); + source.put(SegmentCostTable.COLUMN_START_TIME, data.getDataLong(1)); + source.put(SegmentCostTable.COLUMN_END_TIME, data.getDataLong(2)); + source.put(SegmentCostTable.COLUMN_IS_ERROR, data.getDataBoolean(0)); + source.put(SegmentCostTable.COLUMN_TIME_BUCKET, data.getDataLong(3)); + logger.debug("segment cost source: {}", source.toString()); + return getClient().prepareIndex(SegmentCostTable.TABLE, data.getDataString(0)).setSource(source); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsDAO.java new file mode 100644 index 000000000..615597167 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/SegmentEsDAO.java @@ -0,0 +1,56 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.ISegmentDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.segment.SegmentTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class SegmentEsDAO extends EsDAO implements ISegmentDAO, IPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(SegmentEsDAO.class); + + @Override public Data get(String id, DataDefine dataDefine) { + return null; + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(Data data) { + return null; + } + + @Override public IndexRequestBuilder prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + source.put(SegmentTable.COLUMN_DATA_BINARY, new String(Base64.getEncoder().encode(data.getDataBytes(0)))); + logger.debug("segment source: {}", source.toString()); + return getClient().prepareIndex(SegmentTable.TABLE, data.getDataString(0)).setSource(source); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceEntryEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceEntryEsDAO.java new file mode 100644 index 000000000..9b412efe9 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceEntryEsDAO.java @@ -0,0 +1,74 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.IServiceEntryDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.service.ServiceEntryTable; + +/** + * @author peng-yongsheng + */ +public class ServiceEntryEsDAO extends EsDAO implements IServiceEntryDAO, IPersistenceDAO { + + @Override public Data get(String id, DataDefine dataDefine) { + GetResponse getResponse = getClient().prepareGet(ServiceEntryTable.TABLE, id).get(); + if (getResponse.isExists()) { + Data data = dataDefine.build(id); + Map source = getResponse.getSource(); + data.setDataInteger(0, ((Number)source.get(ServiceEntryTable.COLUMN_APPLICATION_ID)).intValue()); + data.setDataInteger(1, ((Number)source.get(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID)).intValue()); + data.setDataString(1, (String)source.get(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME)); + data.setDataLong(0, ((Number)source.get(ServiceEntryTable.COLUMN_REGISTER_TIME)).longValue()); + data.setDataLong(1, ((Number)source.get(ServiceEntryTable.COLUMN_NEWEST_TIME)).longValue()); + return data; + } else { + return null; + } + } + + @Override public IndexRequestBuilder prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + source.put(ServiceEntryTable.COLUMN_APPLICATION_ID, data.getDataInteger(0)); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, data.getDataInteger(1)); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, data.getDataString(1)); + source.put(ServiceEntryTable.COLUMN_REGISTER_TIME, data.getDataLong(0)); + source.put(ServiceEntryTable.COLUMN_NEWEST_TIME, data.getDataLong(1)); + return getClient().prepareIndex(ServiceEntryTable.TABLE, data.getDataString(0)).setSource(source); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(Data data) { + Map source = new HashMap<>(); + source.put(ServiceEntryTable.COLUMN_APPLICATION_ID, data.getDataInteger(0)); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, data.getDataInteger(1)); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, data.getDataString(1)); + source.put(ServiceEntryTable.COLUMN_REGISTER_TIME, data.getDataLong(0)); + source.put(ServiceEntryTable.COLUMN_NEWEST_TIME, data.getDataLong(1)); + + return getClient().prepareUpdate(ServiceEntryTable.TABLE, data.getDataString(0)).setDoc(source); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java new file mode 100644 index 000000000..fdfbabe8f --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsCacheDAO.java @@ -0,0 +1,69 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import org.elasticsearch.action.get.GetRequestBuilder; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; +import org.skywalking.apm.collector.core.util.Const; +import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.register.ServiceNameTable; + +/** + * @author peng-yongsheng + */ +public class ServiceNameEsCacheDAO extends EsDAO implements IServiceNameCacheDAO { + + @Override public String getServiceName(int serviceId) { + GetRequestBuilder getRequestBuilder = getClient().prepareGet(ServiceNameTable.TABLE, String.valueOf(serviceId)); + + GetResponse getResponse = getRequestBuilder.get(); + if (getResponse.isExists()) { + String serviceName = (String)getResponse.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME); + int applicationId = ((Number)getResponse.getSource().get(ServiceNameTable.COLUMN_APPLICATION_ID)).intValue(); + return applicationId + Const.ID_SPLIT + serviceName; + } + return Const.EMPTY_STRING; + } + + @Override public int getServiceId(int applicationId, String serviceName) { + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceNameTable.TABLE); + searchRequestBuilder.setTypes(ServiceNameTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_APPLICATION_ID, applicationId)); + boolQuery.must().add(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName)); + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(1); + + SearchResponse searchResponse = searchRequestBuilder.get(); + if (searchResponse.getHits().totalHits > 0) { + SearchHit searchHit = searchResponse.getHits().iterator().next(); + return (int)searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_ID); + } + return 0; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsDAO.java new file mode 100644 index 000000000..0138b0f50 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceNameEsDAO.java @@ -0,0 +1,65 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.support.WriteRequest; +import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.dao.IServiceNameDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.register.ServiceNameDataDefine; +import org.skywalking.apm.collector.storage.table.register.ServiceNameTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceNameEsDAO extends EsDAO implements IServiceNameDAO { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameEsDAO.class); + + @Override public int getMaxServiceId() { + return getMaxId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); + } + + @Override public int getMinServiceId() { + return getMinId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); + } + + @Override public void save(Data data) { + String id = ServiceNameDataDefine.ServiceName.INSTANCE.getId(data); + int applicationId = ServiceNameDataDefine.ServiceName.INSTANCE.getApplicationId(data); + int serviceId = ServiceNameDataDefine.ServiceName.INSTANCE.getServiceId(data); + String serviceName = ServiceNameDataDefine.ServiceName.INSTANCE.getServiceName(data); + + logger.debug("save service name register info, application id: {}, service name: {}", applicationId, serviceName); + ElasticSearchClient client = getClient(); + Map source = new HashMap<>(); + source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceId); + source.put(ServiceNameTable.COLUMN_APPLICATION_ID, applicationId); + source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName); + + IndexResponse response = client.prepareIndex(ServiceNameTable.TABLE, id).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); + logger.debug("save service name register info, application id: {}, service name: {}, status: {}", applicationId, serviceName, response.status().name()); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsDAO.java new file mode 100644 index 000000000..964e7cf3a --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsDAO.java @@ -0,0 +1,106 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.es.dao; + +import java.util.HashMap; +import java.util.Map; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.update.UpdateRequestBuilder; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.IServiceReferenceDAO; +import org.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.skywalking.apm.collector.storage.table.serviceref.ServiceReferenceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO, IPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(ServiceReferenceEsDAO.class); + + @Override public Data get(String id, DataDefine dataDefine) { + GetResponse getResponse = getClient().prepareGet(ServiceReferenceTable.TABLE, id).get(); + if (getResponse.isExists()) { + Data data = dataDefine.build(id); + Map source = getResponse.getSource(); + data.setDataInteger(0, ((Number)source.get(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID)).intValue()); + data.setDataString(1, (String)source.get(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME)); + data.setDataInteger(1, ((Number)source.get(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)).intValue()); + data.setDataString(2, (String)source.get(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME)); + data.setDataInteger(2, ((Number)source.get(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID)).intValue()); + data.setDataString(3, (String)source.get(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME)); + data.setDataLong(0, ((Number)source.get(ServiceReferenceTable.COLUMN_S1_LTE)).longValue()); + data.setDataLong(1, ((Number)source.get(ServiceReferenceTable.COLUMN_S3_LTE)).longValue()); + data.setDataLong(2, ((Number)source.get(ServiceReferenceTable.COLUMN_S5_LTE)).longValue()); + data.setDataLong(3, ((Number)source.get(ServiceReferenceTable.COLUMN_S5_GT)).longValue()); + data.setDataLong(4, ((Number)source.get(ServiceReferenceTable.COLUMN_SUMMARY)).longValue()); + data.setDataLong(5, ((Number)source.get(ServiceReferenceTable.COLUMN_ERROR)).longValue()); + data.setDataLong(6, ((Number)source.get(ServiceReferenceTable.COLUMN_COST_SUMMARY)).longValue()); + data.setDataLong(7, ((Number)source.get(ServiceReferenceTable.COLUMN_TIME_BUCKET)).longValue()); + return data; + } else { + return null; + } + } + + @Override public IndexRequestBuilder prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + source.put(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, data.getDataInteger(0)); + source.put(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME, data.getDataString(1)); + source.put(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID, data.getDataInteger(1)); + source.put(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME, data.getDataString(2)); + source.put(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID, data.getDataInteger(2)); + source.put(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME, data.getDataString(3)); + source.put(ServiceReferenceTable.COLUMN_S1_LTE, data.getDataLong(0)); + source.put(ServiceReferenceTable.COLUMN_S3_LTE, data.getDataLong(1)); + source.put(ServiceReferenceTable.COLUMN_S5_LTE, data.getDataLong(2)); + source.put(ServiceReferenceTable.COLUMN_S5_GT, data.getDataLong(3)); + source.put(ServiceReferenceTable.COLUMN_SUMMARY, data.getDataLong(4)); + source.put(ServiceReferenceTable.COLUMN_ERROR, data.getDataLong(5)); + source.put(ServiceReferenceTable.COLUMN_COST_SUMMARY, data.getDataLong(6)); + source.put(ServiceReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(7)); + + return getClient().prepareIndex(ServiceReferenceTable.TABLE, data.getDataString(0)).setSource(source); + } + + @Override public UpdateRequestBuilder prepareBatchUpdate(Data data) { + Map source = new HashMap<>(); + source.put(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, data.getDataInteger(0)); + source.put(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME, data.getDataString(1)); + source.put(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID, data.getDataInteger(1)); + source.put(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME, data.getDataString(2)); + source.put(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID, data.getDataInteger(2)); + source.put(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME, data.getDataString(3)); + source.put(ServiceReferenceTable.COLUMN_S1_LTE, data.getDataLong(0)); + source.put(ServiceReferenceTable.COLUMN_S3_LTE, data.getDataLong(1)); + source.put(ServiceReferenceTable.COLUMN_S5_LTE, data.getDataLong(2)); + source.put(ServiceReferenceTable.COLUMN_S5_GT, data.getDataLong(3)); + source.put(ServiceReferenceTable.COLUMN_SUMMARY, data.getDataLong(4)); + source.put(ServiceReferenceTable.COLUMN_ERROR, data.getDataLong(5)); + source.put(ServiceReferenceTable.COLUMN_COST_SUMMARY, data.getDataLong(6)); + source.put(ServiceReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(7)); + + return getClient().prepareUpdate(ServiceReferenceTable.TABLE, data.getDataString(0)).setDoc(source); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/es_dao.define b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/es_dao.define index 3ee8777f5..e9d3626f4 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/es_dao.define +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/es_dao.define @@ -2,4 +2,18 @@ org.skywalking.apm.collector.storage.es.dao.CpuMetricEsDAO org.skywalking.apm.collector.storage.es.dao.GCMetricEsDAO org.skywalking.apm.collector.storage.es.dao.InstanceHeartBeatEsDAO org.skywalking.apm.collector.storage.es.dao.MemoryMetricEsDAO -org.skywalking.apm.collector.storage.es.dao.MemoryPoolMetricEsDAO \ No newline at end of file +org.skywalking.apm.collector.storage.es.dao.MemoryPoolMetricEsDAO +org.skywalking.apm.collector.storage.es.dao.ApplicationEsDAO +org.skywalking.apm.collector.storage.es.dao.InstanceEsDAO +org.skywalking.apm.collector.storage.es.dao.ServiceNameEsDAO +org.skywalking.apm.collector.storage.es.dao.GlobalTraceEsDAO +org.skywalking.apm.collector.storage.es.dao.InstPerformanceEsDAO +org.skywalking.apm.collector.storage.es.dao.NodeComponentEsDAO +org.skywalking.apm.collector.storage.es.dao.NodeReferenceEsDAO +org.skywalking.apm.collector.storage.es.dao.SegmentCostEsDAO +org.skywalking.apm.collector.storage.es.dao.SegmentEsDAO +org.skywalking.apm.collector.storage.es.dao.ServiceEntryEsDAO +org.skywalking.apm.collector.storage.es.dao.ServiceReferenceEsDAO +org.skywalking.apm.collector.storage.es.dao.ApplicationEsCacheDAO +org.skywalking.apm.collector.storage.es.dao.InstanceEsCacheDAO +org.skywalking.apm.collector.storage.es.dao.ServiceNameEsCacheDAO \ No newline at end of file diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java new file mode 100644 index 000000000..6a3ffca55 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2CacheDAO.java @@ -0,0 +1,72 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import org.skywalking.apm.collector.client.h2.H2Client; +import org.skywalking.apm.collector.client.h2.H2ClientException; +import org.skywalking.apm.collector.core.util.Const; +import org.skywalking.apm.collector.storage.dao.IApplicationCacheDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.register.ApplicationTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ApplicationH2CacheDAO extends H2DAO implements IApplicationCacheDAO { + + private final Logger logger = LoggerFactory.getLogger(ApplicationH2CacheDAO.class); + private static final String GET_APPLICATION_ID_OR_CODE_SQL = "select {0} from {1} where {2} = ?"; + + @Override + public int getApplicationId(String applicationCode) { + logger.info("get the application id with application code = {}", applicationCode); + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_OR_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_ID, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_CODE); + + Object[] params = new Object[] {applicationCode}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + return rs.getInt(1); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } + + @Override public String getApplicationCode(int applicationId) { + logger.debug("get application code, applicationId: {}", applicationId); + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_OR_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); + Object[] params = new Object[] {applicationId}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + return rs.getString(1); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return Const.EMPTY_STRING; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2DAO.java index c9e6aa39c..cecbdaf9e 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2DAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ApplicationH2DAO.java @@ -22,10 +22,12 @@ import java.util.HashMap; import java.util.Map; import org.skywalking.apm.collector.client.h2.H2Client; import org.skywalking.apm.collector.client.h2.H2ClientException; -import org.skywalking.apm.collector.storage.define.register.ApplicationDataDefine; -import org.skywalking.apm.collector.storage.define.register.ApplicationTable; -import org.skywalking.apm.collector.storage.h2.SqlBuilder; -import org.skywalking.apm.collector.storage.h2.dao.H2DAO; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.dao.IApplicationDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.register.ApplicationDataDefine; +import org.skywalking.apm.collector.storage.table.register.ApplicationTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,13 +48,16 @@ public class ApplicationH2DAO extends H2DAO implements IApplicationDAO { } @Override - public void save(ApplicationDataDefine.Application application) { + public void save(Data data) { + String id = ApplicationDataDefine.Application.INSTANCE.getId(data); + int applicationId = ApplicationDataDefine.Application.INSTANCE.getApplicationId(data); + String applicationCode = ApplicationDataDefine.Application.INSTANCE.getApplicationCode(data); H2Client client = getClient(); Map source = new HashMap<>(); - source.put(ApplicationTable.COLUMN_ID, application.getApplicationId()); - source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode()); - source.put(ApplicationTable.COLUMN_APPLICATION_ID, application.getApplicationId()); + source.put(ApplicationTable.COLUMN_ID, id); + source.put(ApplicationTable.COLUMN_APPLICATION_CODE, applicationCode); + source.put(ApplicationTable.COLUMN_APPLICATION_ID, applicationId); String sql = SqlBuilder.buildBatchInsertSql(ApplicationTable.TABLE, source.keySet()); Object[] params = source.values().toArray(new Object[0]); diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2DAO.java new file mode 100644 index 000000000..5d313b9d2 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2DAO.java @@ -0,0 +1,63 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.skywalking.apm.collector.core.UnexpectedException; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.IGlobalTraceDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.global.GlobalTraceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class GlobalTraceH2DAO extends H2DAO implements IGlobalTraceDAO, IPersistenceDAO { + private final Logger logger = LoggerFactory.getLogger(GlobalTraceH2DAO.class); + + @Override public Data get(String id, DataDefine dataDefine) { + throw new UnexpectedException("There is no need to merge stream data with database data."); + } + + @Override public H2SqlEntity prepareBatchUpdate(Data data) { + throw new UnexpectedException("There is no need to merge stream data with database data."); + } + + @Override public H2SqlEntity prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(GlobalTraceTable.COLUMN_ID, data.getDataString(0)); + source.put(GlobalTraceTable.COLUMN_SEGMENT_ID, data.getDataString(1)); + source.put(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, data.getDataString(2)); + source.put(GlobalTraceTable.COLUMN_TIME_BUCKET, data.getDataLong(0)); + logger.debug("global trace source: {}", source.toString()); + + String sql = SqlBuilder.buildBatchInsertSql(GlobalTraceTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstPerformanceH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstPerformanceH2DAO.java new file mode 100644 index 000000000..1609d3840 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstPerformanceH2DAO.java @@ -0,0 +1,99 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.skywalking.apm.collector.client.h2.H2Client; +import org.skywalking.apm.collector.client.h2.H2ClientException; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.IInstPerformanceDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.instance.InstPerformanceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class InstPerformanceH2DAO extends H2DAO implements IInstPerformanceDAO, IPersistenceDAO { + + private final Logger logger = LoggerFactory.getLogger(InstPerformanceH2DAO.class); + private static final String GET_SQL = "select * from {0} where {1} = ?"; + + @Override public Data get(String id, DataDefine dataDefine) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SQL, InstPerformanceTable.TABLE, InstPerformanceTable.COLUMN_ID); + Object[] params = new Object[] {id}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + Data data = dataDefine.build(id); + data.setDataInteger(0, rs.getInt(InstPerformanceTable.COLUMN_APPLICATION_ID)); + data.setDataInteger(1, rs.getInt(InstPerformanceTable.COLUMN_INSTANCE_ID)); + data.setDataInteger(2, rs.getInt(InstPerformanceTable.COLUMN_CALLS)); + data.setDataLong(0, rs.getLong(InstPerformanceTable.COLUMN_COST_TOTAL)); + data.setDataLong(1, rs.getLong(InstPerformanceTable.COLUMN_TIME_BUCKET)); + return data; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(InstPerformanceTable.COLUMN_ID, data.getDataString(0)); + source.put(InstPerformanceTable.COLUMN_APPLICATION_ID, data.getDataInteger(0)); + source.put(InstPerformanceTable.COLUMN_INSTANCE_ID, data.getDataInteger(1)); + source.put(InstPerformanceTable.COLUMN_CALLS, data.getDataInteger(2)); + source.put(InstPerformanceTable.COLUMN_COST_TOTAL, data.getDataLong(0)); + source.put(InstPerformanceTable.COLUMN_TIME_BUCKET, data.getDataLong(1)); + String sql = SqlBuilder.buildBatchInsertSql(InstPerformanceTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(Data data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(InstPerformanceTable.COLUMN_APPLICATION_ID, data.getDataInteger(0)); + source.put(InstPerformanceTable.COLUMN_INSTANCE_ID, data.getDataInteger(1)); + source.put(InstPerformanceTable.COLUMN_CALLS, data.getDataInteger(2)); + source.put(InstPerformanceTable.COLUMN_COST_TOTAL, data.getDataLong(0)); + source.put(InstPerformanceTable.COLUMN_TIME_BUCKET, data.getDataLong(1)); + String id = data.getDataString(0); + String sql = SqlBuilder.buildBatchUpdateSql(InstPerformanceTable.TABLE, source.keySet(), InstPerformanceTable.COLUMN_ID); + entity.setSql(sql); + List values = new ArrayList<>(source.values()); + values.add(id); + entity.setParams(values.toArray(new Object[0])); + return entity; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java new file mode 100644 index 000000000..bb9d36f6b --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2CacheDAO.java @@ -0,0 +1,55 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import org.skywalking.apm.collector.client.h2.H2Client; +import org.skywalking.apm.collector.client.h2.H2ClientException; +import org.skywalking.apm.collector.storage.dao.IInstanceCacheDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class InstanceH2CacheDAO extends H2DAO implements IInstanceCacheDAO { + + private final Logger logger = LoggerFactory.getLogger(InstanceH2CacheDAO.class); + + private static final String GET_APPLICATION_ID_SQL = "select {0} from {1} where {2} = ?"; + + @Override public int getApplicationId(int applicationInstanceId) { + logger.info("get the application id with application id = {}", applicationInstanceId); + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); + Object[] params = new Object[] {applicationInstanceId}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + return rs.getInt(InstanceTable.COLUMN_APPLICATION_ID); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2DAO.java new file mode 100644 index 000000000..6dfa1c0e4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/InstanceH2DAO.java @@ -0,0 +1,107 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import org.skywalking.apm.collector.client.h2.H2Client; +import org.skywalking.apm.collector.client.h2.H2ClientException; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.dao.IInstanceDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.register.InstanceDataDefine; +import org.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class InstanceH2DAO extends H2DAO implements IInstanceDAO { + private final Logger logger = LoggerFactory.getLogger(InstanceH2DAO.class); + + private static final String GET_INSTANCE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ?"; + private static final String UPDATE_HEARTBEAT_TIME_SQL = "update {0} set {1} = ? where {2} = ?"; + + @Override public int getInstanceId(int applicationId, String agentUUID) { + logger.info("get the application id with application id = {}, agentUUID = {}", applicationId, agentUUID); + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_INSTANCE_ID_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, + InstanceTable.COLUMN_AGENT_UUID); + Object[] params = new Object[] {applicationId, agentUUID}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + return rs.getInt(InstanceTable.COLUMN_INSTANCE_ID); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } + + @Override public int getMaxInstanceId() { + return getMaxId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); + } + + @Override public int getMinInstanceId() { + return getMinId(InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID); + } + + @Override public void save(Data data) { + String id = InstanceDataDefine.Instance.INSTANCE.getId(data); + int instanceId = InstanceDataDefine.Instance.INSTANCE.getInstanceId(data); + int applicationId = InstanceDataDefine.Instance.INSTANCE.getApplicationId(data); + String agentUUID = InstanceDataDefine.Instance.INSTANCE.getAgentUUID(data); + long registerTime = InstanceDataDefine.Instance.INSTANCE.getRegisterTime(data); + long heartBeatTime = InstanceDataDefine.Instance.INSTANCE.getHeartBeatTime(data); + String osInfo = InstanceDataDefine.Instance.INSTANCE.getOsInfo(data); + + H2Client client = getClient(); + Map source = new HashMap<>(); + source.put(InstanceTable.COLUMN_ID, id); + source.put(InstanceTable.COLUMN_INSTANCE_ID, instanceId); + source.put(InstanceTable.COLUMN_APPLICATION_ID, applicationId); + source.put(InstanceTable.COLUMN_AGENT_UUID, agentUUID); + source.put(InstanceTable.COLUMN_REGISTER_TIME, registerTime); + source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, heartBeatTime); + source.put(InstanceTable.COLUMN_OS_INFO, osInfo); + String sql = SqlBuilder.buildBatchInsertSql(InstanceTable.TABLE, source.keySet()); + Object[] params = source.values().toArray(new Object[0]); + try { + client.execute(sql, params); + } catch (H2ClientException e) { + logger.error(e.getMessage(), e); + } + } + + @Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(UPDATE_HEARTBEAT_TIME_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, + InstanceTable.COLUMN_ID); + Object[] params = new Object[] {heartbeatTime, instanceId}; + try { + client.execute(sql, params); + } catch (H2ClientException e) { + logger.error(e.getMessage(), e); + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/NodeComponentH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/NodeComponentH2DAO.java new file mode 100644 index 000000000..ec24989e9 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/NodeComponentH2DAO.java @@ -0,0 +1,102 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.skywalking.apm.collector.client.h2.H2Client; +import org.skywalking.apm.collector.client.h2.H2ClientException; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.INodeComponentDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.node.NodeComponentTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class NodeComponentH2DAO extends H2DAO implements INodeComponentDAO, IPersistenceDAO { + private final Logger logger = LoggerFactory.getLogger(NodeComponentH2DAO.class); + private static final String GET_SQL = "select * from {0} where {1} = ?"; + + @Override + public Data get(String id, DataDefine dataDefine) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SQL, NodeComponentTable.TABLE, NodeComponentTable.COLUMN_ID); + Object[] params = new Object[] {id}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + Data data = dataDefine.build(id); + data.setDataInteger(0, rs.getInt(NodeComponentTable.COLUMN_COMPONENT_ID)); + data.setDataString(1, rs.getString(NodeComponentTable.COLUMN_COMPONENT_NAME)); + data.setDataInteger(1, rs.getInt(NodeComponentTable.COLUMN_PEER_ID)); + data.setDataString(2, rs.getString(NodeComponentTable.COLUMN_PEER)); + data.setDataLong(0, rs.getLong(NodeComponentTable.COLUMN_TIME_BUCKET)); + return data; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return null; + } + + @Override + public H2SqlEntity prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(NodeComponentTable.COLUMN_ID, data.getDataString(0)); + source.put(NodeComponentTable.COLUMN_COMPONENT_ID, data.getDataInteger(0)); + source.put(NodeComponentTable.COLUMN_COMPONENT_NAME, data.getDataString(1)); + source.put(NodeComponentTable.COLUMN_PEER_ID, data.getDataInteger(1)); + source.put(NodeComponentTable.COLUMN_PEER, data.getDataString(2)); + source.put(NodeComponentTable.COLUMN_TIME_BUCKET, data.getDataLong(0)); + + String sql = SqlBuilder.buildBatchInsertSql(NodeComponentTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override + public H2SqlEntity prepareBatchUpdate(Data data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(NodeComponentTable.COLUMN_COMPONENT_ID, data.getDataInteger(0)); + source.put(NodeComponentTable.COLUMN_COMPONENT_NAME, data.getDataString(1)); + source.put(NodeComponentTable.COLUMN_PEER_ID, data.getDataInteger(1)); + source.put(NodeComponentTable.COLUMN_PEER, data.getDataString(2)); + source.put(NodeComponentTable.COLUMN_TIME_BUCKET, data.getDataLong(0)); + String id = data.getDataString(0); + String sql = SqlBuilder.buildBatchUpdateSql(NodeComponentTable.TABLE, source.keySet(), NodeComponentTable.COLUMN_ID); + entity.setSql(sql); + List values = new ArrayList<>(source.values()); + values.add(id); + entity.setParams(values.toArray(new Object[0])); + return entity; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/NodeReferenceH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/NodeReferenceH2DAO.java new file mode 100644 index 000000000..a852289db --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/NodeReferenceH2DAO.java @@ -0,0 +1,114 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.skywalking.apm.collector.client.h2.H2Client; +import org.skywalking.apm.collector.client.h2.H2ClientException; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.INodeReferenceDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.noderef.NodeReferenceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class NodeReferenceH2DAO extends H2DAO implements INodeReferenceDAO, IPersistenceDAO { + private final Logger logger = LoggerFactory.getLogger(NodeReferenceH2DAO.class); + private static final String GET_SQL = "select * from {0} where {1} = ?"; + + @Override public Data get(String id, DataDefine dataDefine) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SQL, NodeReferenceTable.TABLE, NodeReferenceTable.COLUMN_ID); + Object[] params = new Object[] {id}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + Data data = dataDefine.build(id); + data.setDataInteger(0, rs.getInt(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID)); + data.setDataInteger(1, rs.getInt(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID)); + data.setDataString(1, rs.getString(NodeReferenceTable.COLUMN_BEHIND_PEER)); + data.setDataInteger(2, rs.getInt(NodeReferenceTable.COLUMN_S1_LTE)); + data.setDataInteger(3, rs.getInt(NodeReferenceTable.COLUMN_S3_LTE)); + data.setDataInteger(4, rs.getInt(NodeReferenceTable.COLUMN_S5_LTE)); + data.setDataInteger(5, rs.getInt(NodeReferenceTable.COLUMN_S5_GT)); + data.setDataInteger(6, rs.getInt(NodeReferenceTable.COLUMN_SUMMARY)); + data.setDataInteger(7, rs.getInt(NodeReferenceTable.COLUMN_ERROR)); + data.setDataLong(0, rs.getLong(NodeReferenceTable.COLUMN_TIME_BUCKET)); + return data; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(NodeReferenceTable.COLUMN_ID, data.getDataString(0)); + source.put(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID, data.getDataInteger(0)); + source.put(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID, data.getDataInteger(1)); + source.put(NodeReferenceTable.COLUMN_BEHIND_PEER, data.getDataString(1)); + source.put(NodeReferenceTable.COLUMN_S1_LTE, data.getDataInteger(2)); + source.put(NodeReferenceTable.COLUMN_S3_LTE, data.getDataInteger(3)); + source.put(NodeReferenceTable.COLUMN_S5_LTE, data.getDataInteger(4)); + source.put(NodeReferenceTable.COLUMN_S5_GT, data.getDataInteger(5)); + source.put(NodeReferenceTable.COLUMN_SUMMARY, data.getDataInteger(6)); + source.put(NodeReferenceTable.COLUMN_ERROR, data.getDataInteger(7)); + source.put(NodeReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(0)); + String sql = SqlBuilder.buildBatchInsertSql(NodeReferenceTable.TABLE, source.keySet()); + entity.setSql(sql); + + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(Data data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID, data.getDataInteger(0)); + source.put(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID, data.getDataInteger(1)); + source.put(NodeReferenceTable.COLUMN_BEHIND_PEER, data.getDataString(1)); + source.put(NodeReferenceTable.COLUMN_S1_LTE, data.getDataInteger(2)); + source.put(NodeReferenceTable.COLUMN_S3_LTE, data.getDataInteger(3)); + source.put(NodeReferenceTable.COLUMN_S5_LTE, data.getDataInteger(4)); + source.put(NodeReferenceTable.COLUMN_S5_GT, data.getDataInteger(5)); + source.put(NodeReferenceTable.COLUMN_SUMMARY, data.getDataInteger(6)); + source.put(NodeReferenceTable.COLUMN_ERROR, data.getDataInteger(7)); + source.put(NodeReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(0)); + String id = data.getDataString(0); + String sql = SqlBuilder.buildBatchUpdateSql(NodeReferenceTable.TABLE, source.keySet(), NodeReferenceTable.COLUMN_ID); + entity.setSql(sql); + List values = new ArrayList<>(source.values()); + values.add(id); + entity.setParams(values.toArray(new Object[0])); + return entity; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentCostH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentCostH2DAO.java new file mode 100644 index 000000000..ed792dd1c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentCostH2DAO.java @@ -0,0 +1,68 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.ISegmentCostDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.segment.SegmentCostTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class SegmentCostH2DAO extends H2DAO implements ISegmentCostDAO, IPersistenceDAO { + private final Logger logger = LoggerFactory.getLogger(SegmentCostH2DAO.class); + + @Override public Data get(String id, DataDefine dataDefine) { + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(Data data) { + logger.debug("segment cost prepareBatchInsert, id: {}", data.getDataString(0)); + H2SqlEntity entity = new H2SqlEntity(); + Map source = new HashMap<>(); + source.put(SegmentCostTable.COLUMN_ID, data.getDataString(0)); + source.put(SegmentCostTable.COLUMN_SEGMENT_ID, data.getDataString(1)); + source.put(SegmentCostTable.COLUMN_APPLICATION_ID, data.getDataInteger(0)); + source.put(SegmentCostTable.COLUMN_SERVICE_NAME, data.getDataString(2)); + source.put(SegmentCostTable.COLUMN_COST, data.getDataLong(0)); + source.put(SegmentCostTable.COLUMN_START_TIME, data.getDataLong(1)); + source.put(SegmentCostTable.COLUMN_END_TIME, data.getDataLong(2)); + source.put(SegmentCostTable.COLUMN_IS_ERROR, data.getDataBoolean(0)); + source.put(SegmentCostTable.COLUMN_TIME_BUCKET, data.getDataLong(3)); + logger.debug("segment cost source: {}", source.toString()); + + String sql = SqlBuilder.buildBatchInsertSql(SegmentCostTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(Data data) { + return null; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2DAO.java new file mode 100644 index 000000000..11978e868 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/SegmentH2DAO.java @@ -0,0 +1,60 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.ISegmentDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.segment.SegmentTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class SegmentH2DAO extends H2DAO implements ISegmentDAO, IPersistenceDAO { + private final Logger logger = LoggerFactory.getLogger(SegmentH2DAO.class); + + @Override public Data get(String id, DataDefine dataDefine) { + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(Data data) { + Map source = new HashMap<>(); + H2SqlEntity entity = new H2SqlEntity(); + source.put(SegmentTable.COLUMN_ID, data.getDataString(0)); + source.put(SegmentTable.COLUMN_DATA_BINARY, data.getDataBytes(0)); + logger.debug("segment source: {}", source.toString()); + + String sql = SqlBuilder.buildBatchInsertSql(SegmentTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(Data data) { + return null; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2DAO.java new file mode 100644 index 000000000..d973821f2 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceEntryH2DAO.java @@ -0,0 +1,98 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.skywalking.apm.collector.client.h2.H2Client; +import org.skywalking.apm.collector.client.h2.H2ClientException; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.IServiceEntryDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.service.ServiceEntryTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ServiceEntryH2DAO extends H2DAO implements IServiceEntryDAO, IPersistenceDAO { + private final Logger logger = LoggerFactory.getLogger(ServiceEntryH2DAO.class); + private static final String GET_SERVICE_ENTRY_SQL = "select * from {0} where {1} = ?"; + + @Override public Data get(String id, DataDefine dataDefine) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SERVICE_ENTRY_SQL, ServiceEntryTable.TABLE, ServiceEntryTable.COLUMN_ID); + Object[] params = new Object[] {id}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + Data data = dataDefine.build(id); + data.setDataInteger(0, rs.getInt(ServiceEntryTable.COLUMN_APPLICATION_ID)); + data.setDataInteger(1, rs.getInt(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID)); + data.setDataString(1, rs.getString(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME)); + data.setDataLong(0, rs.getLong(ServiceEntryTable.COLUMN_REGISTER_TIME)); + data.setDataLong(1, rs.getLong(ServiceEntryTable.COLUMN_NEWEST_TIME)); + return data; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return null; + } + + @Override public H2SqlEntity prepareBatchInsert(Data data) { + H2SqlEntity entity = new H2SqlEntity(); + Map source = new HashMap<>(); + source.put(ServiceEntryTable.COLUMN_ID, data.getDataString(0)); + source.put(ServiceEntryTable.COLUMN_APPLICATION_ID, data.getDataInteger(0)); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, data.getDataInteger(1)); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, data.getDataString(1)); + source.put(ServiceEntryTable.COLUMN_REGISTER_TIME, data.getDataLong(0)); + source.put(ServiceEntryTable.COLUMN_NEWEST_TIME, data.getDataLong(1)); + String sql = SqlBuilder.buildBatchInsertSql(ServiceEntryTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override public H2SqlEntity prepareBatchUpdate(Data data) { + H2SqlEntity entity = new H2SqlEntity(); + Map source = new HashMap<>(); + source.put(ServiceEntryTable.COLUMN_APPLICATION_ID, data.getDataInteger(0)); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, data.getDataInteger(1)); + source.put(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, data.getDataString(1)); + source.put(ServiceEntryTable.COLUMN_REGISTER_TIME, data.getDataLong(0)); + source.put(ServiceEntryTable.COLUMN_NEWEST_TIME, data.getDataLong(1)); + String id = data.getDataString(0); + String sql = SqlBuilder.buildBatchUpdateSql(ServiceEntryTable.TABLE, source.keySet(), ServiceEntryTable.COLUMN_ID); + entity.setSql(sql); + List values = new ArrayList<>(source.values()); + values.add(id); + entity.setParams(values.toArray(new Object[0])); + return entity; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java new file mode 100644 index 000000000..0004b6d72 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2CacheDAO.java @@ -0,0 +1,74 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import org.skywalking.apm.collector.client.h2.H2Client; +import org.skywalking.apm.collector.client.h2.H2ClientException; +import org.skywalking.apm.collector.core.util.Const; +import org.skywalking.apm.collector.storage.dao.IServiceNameCacheDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.register.ServiceNameTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ServiceNameH2CacheDAO extends H2DAO implements IServiceNameCacheDAO { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameH2CacheDAO.class); + + private static final String GET_SERVICE_NAME_SQL = "select {0},{1} from {2} where {3} = ?"; + private static final String GET_SERVICE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ? limit 1"; + + @Override public String getServiceName(int serviceId) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME, + ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); + Object[] params = new Object[] {serviceId}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + String serviceName = rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME); + int applicationId = rs.getInt(ServiceNameTable.COLUMN_APPLICATION_ID); + return applicationId + Const.ID_SPLIT + serviceName; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return Const.EMPTY_STRING; + } + + @Override public int getServiceId(int applicationId, String serviceName) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID, + ServiceNameTable.TABLE, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME); + Object[] params = new Object[] {applicationId, serviceName}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + return rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2DAO.java new file mode 100644 index 000000000..c33112931 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceNameH2DAO.java @@ -0,0 +1,73 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.util.HashMap; +import java.util.Map; +import org.skywalking.apm.collector.client.h2.H2Client; +import org.skywalking.apm.collector.client.h2.H2ClientException; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.dao.IServiceNameDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.register.ServiceNameDataDefine; +import org.skywalking.apm.collector.storage.table.register.ServiceNameTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO { + private final Logger logger = LoggerFactory.getLogger(ServiceNameH2DAO.class); + + @Override + public int getMaxServiceId() { + return getMaxId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); + } + + @Override + public int getMinServiceId() { + return getMinId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); + } + + @Override + public void save(Data data) { + String id = ServiceNameDataDefine.ServiceName.INSTANCE.getId(data); + int applicationId = ServiceNameDataDefine.ServiceName.INSTANCE.getApplicationId(data); + int serviceId = ServiceNameDataDefine.ServiceName.INSTANCE.getServiceId(data); + String serviceName = ServiceNameDataDefine.ServiceName.INSTANCE.getServiceName(data); + + logger.debug("save service name register info, application id: {}, service name: {}", applicationId, serviceName); + H2Client client = getClient(); + Map source = new HashMap<>(); + source.put(ServiceNameTable.COLUMN_ID, id); + source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceId); + source.put(ServiceNameTable.COLUMN_APPLICATION_ID, applicationId); + source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName); + + String sql = SqlBuilder.buildBatchInsertSql(ServiceNameTable.TABLE, source.keySet()); + Object[] params = source.values().toArray(new Object[0]); + try { + client.execute(sql, params); + } catch (H2ClientException e) { + logger.error(e.getMessage(), e); + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2DAO.java new file mode 100644 index 000000000..21614ad0e --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2DAO.java @@ -0,0 +1,130 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.storage.h2.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.skywalking.apm.collector.client.h2.H2Client; +import org.skywalking.apm.collector.client.h2.H2ClientException; +import org.skywalking.apm.collector.core.data.Data; +import org.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; +import org.skywalking.apm.collector.storage.base.define.DataDefine; +import org.skywalking.apm.collector.storage.dao.IServiceReferenceDAO; +import org.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; +import org.skywalking.apm.collector.storage.sql.SqlBuilder; +import org.skywalking.apm.collector.storage.table.serviceref.ServiceReferenceTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO, IPersistenceDAO { + private final Logger logger = LoggerFactory.getLogger(ServiceReferenceH2DAO.class); + private static final String GET_SQL = "select * from {0} where {1} = ?"; + + @Override + public Data get(String id, DataDefine dataDefine) { + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_SQL, ServiceReferenceTable.TABLE, ServiceReferenceTable.COLUMN_ID); + Object[] params = new Object[] {id}; + try (ResultSet rs = client.executeQuery(sql, params)) { + if (rs.next()) { + Data data = dataDefine.build(id); + data.setDataInteger(0, rs.getInt(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID)); + data.setDataString(1, rs.getString(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME)); + data.setDataInteger(1, rs.getInt(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)); + data.setDataString(2, rs.getString(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME)); + data.setDataInteger(2, rs.getInt(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID)); + data.setDataString(3, rs.getString(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME)); + data.setDataLong(0, rs.getLong(ServiceReferenceTable.COLUMN_S1_LTE)); + data.setDataLong(1, rs.getLong(ServiceReferenceTable.COLUMN_S3_LTE)); + data.setDataLong(2, rs.getLong(ServiceReferenceTable.COLUMN_S5_LTE)); + data.setDataLong(3, rs.getLong(ServiceReferenceTable.COLUMN_S5_GT)); + data.setDataLong(4, rs.getLong(ServiceReferenceTable.COLUMN_SUMMARY)); + data.setDataLong(5, rs.getLong(ServiceReferenceTable.COLUMN_ERROR)); + data.setDataLong(6, rs.getLong(ServiceReferenceTable.COLUMN_COST_SUMMARY)); + data.setDataLong(7, rs.getLong(ServiceReferenceTable.COLUMN_TIME_BUCKET)); + return data; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return null; + } + + @Override + public H2SqlEntity prepareBatchInsert(Data data) { + H2SqlEntity entity = new H2SqlEntity(); + Map source = new HashMap<>(); + source.put(ServiceReferenceTable.COLUMN_ID, data.getDataString(0)); + source.put(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, data.getDataInteger(0)); + source.put(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME, data.getDataString(1)); + source.put(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID, data.getDataInteger(1)); + source.put(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME, data.getDataString(2)); + source.put(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID, data.getDataInteger(2)); + source.put(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME, data.getDataString(3)); + source.put(ServiceReferenceTable.COLUMN_S1_LTE, data.getDataLong(0)); + source.put(ServiceReferenceTable.COLUMN_S3_LTE, data.getDataLong(1)); + source.put(ServiceReferenceTable.COLUMN_S5_LTE, data.getDataLong(2)); + source.put(ServiceReferenceTable.COLUMN_S5_GT, data.getDataLong(3)); + source.put(ServiceReferenceTable.COLUMN_SUMMARY, data.getDataLong(4)); + source.put(ServiceReferenceTable.COLUMN_ERROR, data.getDataLong(5)); + source.put(ServiceReferenceTable.COLUMN_COST_SUMMARY, data.getDataLong(6)); + source.put(ServiceReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(7)); + + String sql = SqlBuilder.buildBatchInsertSql(ServiceReferenceTable.TABLE, source.keySet()); + entity.setSql(sql); + entity.setParams(source.values().toArray(new Object[0])); + return entity; + } + + @Override + public H2SqlEntity prepareBatchUpdate(Data data) { + H2SqlEntity entity = new H2SqlEntity(); + Map source = new HashMap<>(); + source.put(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, data.getDataInteger(0)); + source.put(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME, data.getDataString(1)); + source.put(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID, data.getDataInteger(1)); + source.put(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME, data.getDataString(2)); + source.put(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID, data.getDataInteger(2)); + source.put(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME, data.getDataString(3)); + source.put(ServiceReferenceTable.COLUMN_S1_LTE, data.getDataLong(0)); + source.put(ServiceReferenceTable.COLUMN_S3_LTE, data.getDataLong(1)); + source.put(ServiceReferenceTable.COLUMN_S5_LTE, data.getDataLong(2)); + source.put(ServiceReferenceTable.COLUMN_S5_GT, data.getDataLong(3)); + source.put(ServiceReferenceTable.COLUMN_SUMMARY, data.getDataLong(4)); + source.put(ServiceReferenceTable.COLUMN_ERROR, data.getDataLong(5)); + source.put(ServiceReferenceTable.COLUMN_COST_SUMMARY, data.getDataLong(6)); + source.put(ServiceReferenceTable.COLUMN_TIME_BUCKET, data.getDataLong(7)); + + String id = data.getDataString(0); + String sql = SqlBuilder.buildBatchUpdateSql(ServiceReferenceTable.TABLE, source.keySet(), ServiceReferenceTable.COLUMN_ID); + entity.setSql(sql); + List values = new ArrayList<>(source.values()); + values.add(id); + entity.setParams(values.toArray(new Object[0])); + return entity; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/h2_dao.define b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/h2_dao.define index 6753de66d..3541b3722 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/h2_dao.define +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/h2_dao.define @@ -2,4 +2,18 @@ org.skywalking.apm.collector.storage.h2.dao.CpuMetricH2DAO org.skywalking.apm.collector.storage.h2.dao.GCMetricH2DAO org.skywalking.apm.collector.storage.h2.dao.InstanceHeartBeatH2DAO org.skywalking.apm.collector.storage.h2.dao.MemoryMetricH2DAO -org.skywalking.apm.collector.storage.h2.dao.MemoryPoolMetricH2DAO \ No newline at end of file +org.skywalking.apm.collector.storage.h2.dao.MemoryPoolMetricH2DAO +org.skywalking.apm.collector.storage.h2.dao.ApplicationH2DAO +org.skywalking.apm.collector.storage.h2.dao.InstanceH2DAO +org.skywalking.apm.collector.storage.h2.dao.ServiceNameH2DAO +org.skywalking.apm.collector.storage.h2.dao.GlobalTraceH2DAO +org.skywalking.apm.collector.storage.h2.dao.InstPerformanceH2DAO +org.skywalking.apm.collector.storage.h2.dao.NodeComponentH2DAO +org.skywalking.apm.collector.storage.h2.dao.NodeReferenceH2DAO +org.skywalking.apm.collector.storage.h2.dao.SegmentCostH2DAO +org.skywalking.apm.collector.storage.h2.dao.SegmentH2DAO +org.skywalking.apm.collector.storage.h2.dao.ServiceEntryH2DAO +org.skywalking.apm.collector.storage.h2.dao.ServiceReferenceH2DAO +org.skywalking.apm.collector.storage.h2.dao.ApplicationH2CacheDAO +org.skywalking.apm.collector.storage.h2.dao.InstanceH2CacheDAO +org.skywalking.apm.collector.storage.h2.dao.ServiceNameH2CacheDAO \ No newline at end of file