You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2020/04/10 06:57:12 UTC
[servicecomb-java-chassis] branch master updated (e2d965b ->
10d45c6)
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git.
from e2d965b [SCB-1848] refactor: modify config-kie module to use the new mechanism to intialize client
new 144eac3 [SCB-1862] ServiceComb add extensions to support cas env variables
new 10d45c6 [SCB-1862] ServiceComb add extensions to support cas env variables:fixed as reviewed
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
dependencies/bom/pom.xml | 6 ++
distribution/pom.xml | 6 ++
.../foundation/common/RegisterManager.java | 4 ++
{solutions => huawei-cloud}/pom.xml | 11 ++--
.../model => huawei-cloud/servicestage}/pom.xml | 18 +++---
.../huaweicloud/servicestage/CasEnvConfig.java | 68 ++++++++++++++++++++++
.../servicestage/CasEnvVariablesAdapter.java | 30 +++++-----
....servicecomb.serviceregistry.adapter.EnvAdapter | 2 +-
.../servicestage/src/main/resources/mapping.yaml | 42 +++++++++++++
.../huaweicloud/servicestage/TestCasEnvConfig.java | 39 +++++--------
.../servicestage/TestEnvVariablesAdapter.java | 50 ++++++++++++++++
pom.xml | 1 +
.../DefaultEnvAdapter.java} | 13 +++--
.../CacheEndpoint.java => adapter/EnvAdapter.java} | 30 +++++-----
.../serviceregistry/adapter/EnvAdapterManager.java | 67 +++++++++++++++++++++
.../task/MicroserviceInstanceRegisterTask.java | 2 +
.../task/MicroserviceRegisterTask.java | 3 +
....servicecomb.serviceregistry.adapter.EnvAdapter | 2 +-
.../adapter/CasEnvAdapterHighOne.java | 29 ++++-----
.../serviceregistry/adapter/CasEnvAdapterOne.java} | 32 +++++-----
.../adapter/CasEnvAdapterThree.java | 17 +++---
.../serviceregistry/adapter/CasEnvAdapterTwo.java | 29 ++++-----
.../adapter/TestEnvAdapterManager.java | 63 ++++++++++++++++++++
....servicecomb.serviceregistry.adapter.EnvAdapter | 6 +-
24 files changed, 441 insertions(+), 129 deletions(-)
copy {solutions => huawei-cloud}/pom.xml (91%)
copy {demo/demo-edge/model => huawei-cloud/servicestage}/pom.xml (79%)
create mode 100644 huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvConfig.java
copy service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/CacheEndpoint.java => huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvVariablesAdapter.java (63%)
copy common/common-access-log/src/main/resources/META-INF/services/org.apache.servicecomb.core.BootListener => huawei-cloud/servicestage/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter (91%)
create mode 100644 huawei-cloud/servicestage/src/main/resources/mapping.yaml
copy integration-tests/dynamic-config-tests/src/test/java/org/apache/dynamicconfig/test/DynamicConfigurationIT.java => huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestCasEnvConfig.java (50%)
create mode 100644 huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestEnvVariablesAdapter.java
copy service-registry/src/main/java/org/apache/servicecomb/serviceregistry/{registry/ServiceRegistryTaskInitializer.java => adapter/DefaultEnvAdapter.java} (78%)
copy service-registry/src/main/java/org/apache/servicecomb/serviceregistry/{cache/CacheEndpoint.java => adapter/EnvAdapter.java} (63%)
create mode 100644 service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/EnvAdapterManager.java
copy common/common-access-log/src/main/resources/META-INF/services/org.apache.servicecomb.core.BootListener => service-registry/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter (92%)
copy demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/CustomEndpointDiscoveryFilter.java => service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterHighOne.java (60%)
copy service-registry/src/{main/java/org/apache/servicecomb/serviceregistry/cache/CacheEndpoint.java => test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterOne.java} (59%)
copy foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/encrypt/NoEncryption.java => service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterThree.java (76%)
copy demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/CustomEndpointDiscoveryFilter.java => service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterTwo.java (60%)
create mode 100644 service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/TestEnvAdapterManager.java
copy common/common-access-log/src/main/resources/META-INF/services/org.apache.servicecomb.common.accessLog.AccessLogInitializer => service-registry/src/test/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter (75%)
[servicecomb-java-chassis] 01/02: [SCB-1862] ServiceComb add
extensions to support cas env variables
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 144eac326fe18bff3c64fa9437571ae700eb641d
Author: heyile <25...@qq.com>
AuthorDate: Thu Apr 9 18:03:46 2020 +0800
[SCB-1862] ServiceComb add extensions to support cas env variables
---
dependencies/bom/pom.xml | 6 ++
.../foundation/common/RegisterManager.java | 4 ++
pom.xml | 1 +
.../serviceregistry/adapter/DefaultEnvAdapter.java | 29 +++++++++
.../serviceregistry/adapter/EnvAdapter.java | 44 ++++++++++++++
.../serviceregistry/adapter/EnvAdapterManager.java | 67 +++++++++++++++++++++
.../task/MicroserviceInstanceRegisterTask.java | 2 +
.../task/MicroserviceRegisterTask.java | 3 +
....servicecomb.serviceregistry.adapter.EnvAdapter | 18 ++++++
.../adapter/CasEnvAdapterHighOne.java | 44 ++++++++++++++
.../serviceregistry/adapter/CasEnvAdapterOne.java | 44 ++++++++++++++
.../adapter/CasEnvAdapterThree.java | 34 +++++++++++
.../serviceregistry/adapter/CasEnvAdapterTwo.java | 44 ++++++++++++++
.../adapter/TestEnvAdapterManager.java | 63 ++++++++++++++++++++
....servicecomb.serviceregistry.adapter.EnvAdapter | 21 +++++++
third-part-extensions/cas-env-variables/pom.xml | 37 ++++++++++++
.../org/apache/servicecomb/cas/CasEnvConfig.java | 68 ++++++++++++++++++++++
.../servicecomb/cas/CasEnvVariablesAdapter.java | 40 +++++++++++++
....servicecomb.serviceregistry.adapter.EnvAdapter | 18 ++++++
.../src/main/resources/mapping.yaml | 41 +++++++++++++
.../apache/servicecomb/cas/TestCasEnvConfig.java | 46 +++++++++++++++
.../servicecomb/cas/TestEnvVariablesAdapter.java | 50 ++++++++++++++++
third-part-extensions/pom.xml | 37 ++++++++++++
23 files changed, 761 insertions(+)
diff --git a/dependencies/bom/pom.xml b/dependencies/bom/pom.xml
index 21f2ca8..c691b0a 100644
--- a/dependencies/bom/pom.xml
+++ b/dependencies/bom/pom.xml
@@ -365,6 +365,12 @@
<artifactId>transport-rest-vertx</artifactId>
<version>${project.version}</version>
</dependency>
+ <!-- ServiceComb third-extensions -->
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>cas-env-variables</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>
</project>
\ No newline at end of file
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/RegisterManager.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/RegisterManager.java
index d2933cf..5fa4b8c 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/RegisterManager.java
+++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/RegisterManager.java
@@ -35,6 +35,10 @@ public class RegisterManager<KEY, VALUE> {
private Object lockObj = new Object();
+ protected Map<KEY, VALUE> getObjMap() {
+ return objMap;
+ }
+
public RegisterManager(String name) {
this.name = name;
}
diff --git a/pom.xml b/pom.xml
index 2579f06..e681f69 100755
--- a/pom.xml
+++ b/pom.xml
@@ -126,6 +126,7 @@
<module>inspector</module>
<module>solutions</module>
<module>clients</module>
+ <module>third-part-extensions</module>
</modules>
<reporting>
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/DefaultEnvAdapter.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/DefaultEnvAdapter.java
new file mode 100644
index 0000000..7895d54
--- /dev/null
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/DefaultEnvAdapter.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.serviceregistry.adapter;
+
+public class DefaultEnvAdapter implements EnvAdapter {
+ @Override
+ public String getEnvName() {
+ return "default-env-default-adapter";
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/EnvAdapter.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/EnvAdapter.java
new file mode 100644
index 0000000..02fc5b6
--- /dev/null
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/EnvAdapter.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.serviceregistry.adapter;
+
+import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+
+public interface EnvAdapter {
+
+ default boolean enabled() {
+ return true;
+ }
+
+ String getEnvName();
+
+ int getOrder();
+
+ default void beforeRegisterService(Microservice microservice) {
+ //do nothing default
+ }
+
+ default void beforeRegisterSchema(String schemaId, String content) {
+ //do nothing default
+ }
+
+ default void beforeRegisterInstance(MicroserviceInstance instance) {
+ //do nothing default
+ }
+}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/EnvAdapterManager.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/EnvAdapterManager.java
new file mode 100644
index 0000000..8b31d26
--- /dev/null
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/EnvAdapterManager.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.serviceregistry.adapter;
+
+import java.util.List;
+
+import org.apache.servicecomb.foundation.common.RegisterManager;
+import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
+import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EnvAdapterManager extends RegisterManager<String, EnvAdapter> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(EnvAdapterManager.class);
+
+ private static final List<EnvAdapter> ENV_ADAPTERS = SPIServiceUtils.getSortedService(EnvAdapter.class);
+
+ private static final String NAME = "service env adapter";
+
+ public static final EnvAdapterManager INSTANCE = new EnvAdapterManager();
+
+ public EnvAdapterManager() {
+ super(NAME);
+ ENV_ADAPTERS.forEach(envAdapter -> {
+ if (envAdapter.enabled()) {
+ getObjMap().putIfAbsent(envAdapter.getEnvName(), envAdapter);
+ }
+ });
+ }
+
+ public void processMicroserviceWithAdapters(Microservice microservice) {
+ getObjMap().forEach((name, adapter) -> {
+ LOGGER.info("Start process microservice with adapter {}", name);
+ adapter.beforeRegisterService(microservice);
+ });
+ }
+
+ public void processSchemaWithAdapters(String schemaId, String content) {
+ getObjMap().forEach((name, adapter) -> {
+ LOGGER.info("Start process schema with adapter {}", name);
+ adapter.beforeRegisterSchema(schemaId, content);
+ });
+ }
+
+ public void processInstanceWithAdapters(MicroserviceInstance instance) {
+ getObjMap().forEach((name, adapter) -> {
+ LOGGER.info("Start process instance with adapter {}", name);
+ adapter.beforeRegisterInstance(instance);
+ });
+ }
+}
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceInstanceRegisterTask.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceInstanceRegisterTask.java
index 6b18693..438fbce 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceInstanceRegisterTask.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceInstanceRegisterTask.java
@@ -21,6 +21,7 @@ import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
+import org.apache.servicecomb.serviceregistry.adapter.EnvAdapterManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
@@ -67,6 +68,7 @@ public class MicroserviceInstanceRegisterTask extends AbstractRegisterTask {
microserviceInstance.getHealthCheck().setInterval(serviceRegistryConfig.getHeartbeatInterval());
microserviceInstance.getHealthCheck().setTimes(serviceRegistryConfig.getResendHeartBeatTimes());
+ EnvAdapterManager.INSTANCE.processInstanceWithAdapters(microserviceInstance);
String instanceId = srClient.registerMicroserviceInstance(microserviceInstance);
MicroserviceInstance temIns = srClient.findServiceInstance(microserviceInstance.getServiceId(), instanceId);
if (temIns != null) {
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceRegisterTask.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceRegisterTask.java
index 3a7f33a..31909b1 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceRegisterTask.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceRegisterTask.java
@@ -33,6 +33,7 @@ import org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse;
import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient;
import org.apache.servicecomb.serviceregistry.client.http.Holder;
import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
+import org.apache.servicecomb.serviceregistry.adapter.EnvAdapterManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -93,6 +94,7 @@ public class MicroserviceRegisterTask extends AbstractRegisterTask {
return false;
}
} else {
+ EnvAdapterManager.INSTANCE.processMicroserviceWithAdapters(microservice);
serviceId = srClient.registerMicroservice(microservice);
if (StringUtils.isEmpty(serviceId)) {
LOGGER.error(
@@ -342,6 +344,7 @@ public class MicroserviceRegisterTask extends AbstractRegisterTask {
* @return true if register success, otherwise false
*/
private boolean registerSingleSchema(String schemaId, String content) {
+ EnvAdapterManager.INSTANCE.processSchemaWithAdapters(schemaId, content);
return srClient.registerSchema(microservice.getServiceId(), schemaId, content);
}
diff --git a/service-registry/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter b/service-registry/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter
new file mode 100644
index 0000000..b095b89
--- /dev/null
+++ b/service-registry/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.servicecomb.serviceregistry.adapter.DefaultEnvAdapter
\ No newline at end of file
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterHighOne.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterHighOne.java
new file mode 100644
index 0000000..b92c9ac
--- /dev/null
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterHighOne.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.serviceregistry.adapter;
+
+import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+
+public class CasEnvAdapterHighOne implements EnvAdapter {
+ private static final String NAME = "cas_env_one";
+
+ @Override
+ public String getEnvName() {
+ return NAME;
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+
+ @Override
+ public void beforeRegisterService(Microservice microservice) {
+ microservice.getProperties().put(NAME, "order=0");
+ }
+
+ @Override
+ public void beforeRegisterInstance(MicroserviceInstance instance) {
+ instance.getProperties().put(NAME, "order=0");
+ }
+}
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterOne.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterOne.java
new file mode 100644
index 0000000..86fd689
--- /dev/null
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterOne.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.serviceregistry.adapter;
+
+import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+
+public class CasEnvAdapterOne implements EnvAdapter {
+ private static final String NAME = "cas_env_one";
+
+ @Override
+ public String getEnvName() {
+ return NAME;
+ }
+
+ @Override
+ public int getOrder() {
+ return 10;
+ }
+
+ @Override
+ public void beforeRegisterService(Microservice microservice) {
+ microservice.getProperties().put(NAME, "order=10");
+ }
+
+ @Override
+ public void beforeRegisterInstance(MicroserviceInstance instance) {
+ instance.getProperties().put(NAME, "order=10");
+ }
+}
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterThree.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterThree.java
new file mode 100644
index 0000000..9bec43a
--- /dev/null
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterThree.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.serviceregistry.adapter;
+
+public class CasEnvAdapterThree implements EnvAdapter {
+ @Override
+ public String getEnvName() {
+ return "cas-env-three";
+ }
+
+ @Override
+ public boolean enabled() {
+ return false;
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+}
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterTwo.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterTwo.java
new file mode 100644
index 0000000..f3e2e9e
--- /dev/null
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/CasEnvAdapterTwo.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.serviceregistry.adapter;
+
+import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+
+public class CasEnvAdapterTwo implements EnvAdapter {
+ private static final String NAME = "cas_env_two";
+
+ @Override
+ public String getEnvName() {
+ return NAME;
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+
+ @Override
+ public void beforeRegisterService(Microservice microservice) {
+ microservice.getProperties().put(NAME, "order=0");
+ }
+
+ @Override
+ public void beforeRegisterInstance(MicroserviceInstance instance) {
+ instance.getProperties().put(NAME, "order=0");
+ }
+}
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/TestEnvAdapterManager.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/TestEnvAdapterManager.java
new file mode 100644
index 0000000..7bef5be
--- /dev/null
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/TestEnvAdapterManager.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.serviceregistry.adapter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.junit.Test;
+
+public class TestEnvAdapterManager {
+
+ private EnvAdapterManager manager = EnvAdapterManager.INSTANCE;
+
+ @Test
+ public void testLoadAdapter() {
+ assertEquals(3, manager.values().size());
+ assertNull(manager.findValue("cas-env-three"));
+ assertNotNull(manager.findValue("default-env-default-adapter"));
+ assertNotNull(manager.findValue("cas_env_one"));
+ assertNotNull(manager.findValue("cas_env_two"));
+
+ assertEquals(0, manager.findValue("cas_env_one").getOrder());
+ assertEquals(0, manager.findValue("cas_env_two").getOrder());
+ assertEquals(0, manager.findValue("default-env-default-adapter").getOrder());
+ }
+
+ @Test
+ public void testProcessMicroservice() {
+ Microservice microservice = new Microservice();
+ manager.processMicroserviceWithAdapters(microservice);
+
+ assertEquals("order=0", microservice.getProperties().get("cas_env_one"));
+ assertEquals("order=0", microservice.getProperties().get("cas_env_two"));
+ assertNull(microservice.getProperties().get("default-env-default-adapter"));
+ }
+
+ @Test
+ public void testProcessInstance() {
+ MicroserviceInstance instance = new MicroserviceInstance();
+ manager.processInstanceWithAdapters(instance);
+
+ assertEquals("order=0", instance.getProperties().get("cas_env_one"));
+ assertEquals("order=0", instance.getProperties().get("cas_env_two"));
+ assertNull(instance.getProperties().get("default-env-default-adapter"));
+ }
+}
diff --git a/service-registry/src/test/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter b/service-registry/src/test/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter
new file mode 100644
index 0000000..df069fd
--- /dev/null
+++ b/service-registry/src/test/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter
@@ -0,0 +1,21 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.servicecomb.serviceregistry.adapter.CasEnvAdapterOne
+org.apache.servicecomb.serviceregistry.adapter.CasEnvAdapterTwo
+org.apache.servicecomb.serviceregistry.adapter.CasEnvAdapterHighOne
+org.apache.servicecomb.serviceregistry.adapter.CasEnvAdapterThree
\ No newline at end of file
diff --git a/third-part-extensions/cas-env-variables/pom.xml b/third-part-extensions/cas-env-variables/pom.xml
new file mode 100644
index 0000000..4c20b62
--- /dev/null
+++ b/third-part-extensions/cas-env-variables/pom.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>third-part-extensions</artifactId>
+ <groupId>org.apache.servicecomb</groupId>
+ <version>2.0.2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>cas-env-variables</artifactId>
+ <name>Java Chassis::Third-Part Extensions::Cas Env Variables</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>service-registry</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvConfig.java b/third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvConfig.java
new file mode 100644
index 0000000..139912b
--- /dev/null
+++ b/third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvConfig.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.cas;
+
+import static org.apache.commons.lang3.StringUtils.EMPTY;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.StringUtils;
+
+import com.netflix.config.DynamicPropertyFactory;
+
+public class CasEnvConfig {
+ private static final String CAS_BASE = "servicecomb.cas.";
+
+ private static final String APPLICATION_ID = CAS_BASE + "application-id";
+
+ private static final String COMPONENT_NAME = CAS_BASE + "component-name";
+
+ private static final String INSTANCE_VERSION = CAS_BASE + "instance-version";
+
+ private static final String INSTANCE_ID = CAS_BASE + "instance-id";
+
+ private static final String ENVIRONMENT_ID = CAS_BASE + "environment-id";
+
+ public static final CasEnvConfig INSTANCE = new CasEnvConfig();
+
+ private Map<String, String> properties = new HashMap<>();
+
+ private CasEnvConfig() {
+ init();
+ }
+
+ private void init() {
+ properties.put("CAS_APPLICATION_ID", DynamicPropertyFactory
+ .getInstance().getStringProperty(APPLICATION_ID, EMPTY).get());
+ properties.put("CAS_COMPONENT_NAME", DynamicPropertyFactory
+ .getInstance().getStringProperty(COMPONENT_NAME, EMPTY).get());
+ properties.put("CAS_INSTANCE_VERSION", DynamicPropertyFactory
+ .getInstance().getStringProperty(INSTANCE_VERSION, EMPTY).get());
+ properties.put("CAS_INSTANCE_ID", DynamicPropertyFactory
+ .getInstance().getStringProperty(INSTANCE_ID, EMPTY).get());
+ properties.put("CAS_ENVIRONMENT_ID", DynamicPropertyFactory
+ .getInstance().getStringProperty(ENVIRONMENT_ID, EMPTY).get());
+ }
+
+ public Map<String, String> getNonEmptyProperties() {
+ return properties.entrySet().stream().filter(entry -> StringUtils.isNotEmpty(entry.getValue()))
+ .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
+ }
+}
diff --git a/third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvVariablesAdapter.java b/third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvVariablesAdapter.java
new file mode 100644
index 0000000..ecbd12e
--- /dev/null
+++ b/third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvVariablesAdapter.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.cas;
+
+import org.apache.servicecomb.serviceregistry.adapter.EnvAdapter;
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+
+public class CasEnvVariablesAdapter implements EnvAdapter {
+ private static final String NAME = "cas-env-variables-adapter";
+
+ @Override
+ public String getEnvName() {
+ return NAME;
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+
+ @Override
+ public void beforeRegisterInstance(MicroserviceInstance instance) {
+ instance.getProperties().putAll(CasEnvConfig.INSTANCE.getNonEmptyProperties());
+ }
+}
diff --git a/third-part-extensions/cas-env-variables/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter b/third-part-extensions/cas-env-variables/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter
new file mode 100644
index 0000000..88bdc59
--- /dev/null
+++ b/third-part-extensions/cas-env-variables/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.servicecomb.cas.CasEnvVariablesAdapter
\ No newline at end of file
diff --git a/third-part-extensions/cas-env-variables/src/main/resources/mapping.yaml b/third-part-extensions/cas-env-variables/src/main/resources/mapping.yaml
new file mode 100644
index 0000000..f986613
--- /dev/null
+++ b/third-part-extensions/cas-env-variables/src/main/resources/mapping.yaml
@@ -0,0 +1,41 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+CAS_APPLICATION_ID:
+ - servicecomb.cas.application-id
+CAS_COMPONENT_NAME:
+ - servicecomb.cas.component-name
+CAS_INSTANCE_VERSION:
+ - servicecomb.cas.instance-version
+CAS_INSTANCE_ID:
+ - servicecomb.cas.instance-id
+CAS_ENVIRONMENT_ID:
+ - servicecomb.cas.environment-id
+PAAS_CSE_ENDPOINT:
+ - servicecomb.service.registry.address
+ - servicecomb.config.client.serverUri
+PAAS_CSE_SC_ENDPOINT:
+ - servicecomb.service.registry.address
+PAAS_CSE_CC_ENDPOINT:
+ - servicecomb.config.client.serverUri
+PAAS_PROJECT_NAME:
+ - servicecomb.credentials.project
+servicecomb.monitor.client.enable:
+ - servicecomb.monitor.client.enabled
+servicecomb.monitor.client.sslEnalbed:
+ - servicecomb.monitor.client.sslEnabled
+servicecomb.engine.engineName:
+ - servicecomb.engine.name
diff --git a/third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestCasEnvConfig.java b/third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestCasEnvConfig.java
new file mode 100644
index 0000000..211bf96
--- /dev/null
+++ b/third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestCasEnvConfig.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.cas;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestCasEnvConfig {
+
+ @BeforeClass
+ public static void init() {
+ System.setProperty("servicecomb.cas.application-id", "application-id");
+ System.setProperty("servicecomb.cas.environment-id", "env-id");
+ }
+
+ @Test
+ public void testConfig() {
+ CasEnvConfig instance = CasEnvConfig.INSTANCE;
+ assertEquals(2, instance.getNonEmptyProperties().size());
+ assertEquals("application-id", instance.getNonEmptyProperties().get("CAS_APPLICATION_ID"));
+ assertEquals("env-id", instance.getNonEmptyProperties().get("CAS_ENVIRONMENT_ID"));
+ }
+
+ @AfterClass
+ public static void destroy() {
+ System.getProperties().remove("servicecomb.cas.application-id");
+ System.getProperties().remove("servicecomb.cas.environment-id");
+ }
+}
diff --git a/third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestEnvVariablesAdapter.java b/third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestEnvVariablesAdapter.java
new file mode 100644
index 0000000..0aec4cb
--- /dev/null
+++ b/third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestEnvVariablesAdapter.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.cas;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestEnvVariablesAdapter {
+
+ @BeforeClass
+ public static void init() {
+ System.setProperty("servicecomb.cas.application-id", "application-id");
+ System.setProperty("servicecomb.cas.environment-id", "env-id");
+ }
+
+ @Test
+ public void testProcessInstance() {
+ CasEnvVariablesAdapter adapter = new CasEnvVariablesAdapter();
+ MicroserviceInstance instance = new MicroserviceInstance();
+ adapter.beforeRegisterInstance(instance);
+
+ assertEquals(2, instance.getProperties().size());
+ assertEquals("application-id", instance.getProperties().get("CAS_APPLICATION_ID"));
+ assertEquals("env-id", instance.getProperties().get("CAS_ENVIRONMENT_ID"));
+ }
+
+ @AfterClass
+ public static void destroy() {
+ System.getProperties().remove("servicecomb.cas.application-id");
+ System.getProperties().remove("servicecomb.cas.environment-id");
+ }
+}
diff --git a/third-part-extensions/pom.xml b/third-part-extensions/pom.xml
new file mode 100644
index 0000000..ee2cce6
--- /dev/null
+++ b/third-part-extensions/pom.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-parent</artifactId>
+ <version>2.0.2-SNAPSHOT</version>
+ <relativePath>../parents/default</relativePath>
+ </parent>
+
+ <artifactId>third-part-extensions</artifactId>
+ <name>Java Chassis::Third-Part Extensions</name>
+ <packaging>pom</packaging>
+ <modelVersion>4.0.0</modelVersion>
+
+ <modules>
+ <module>cas-env-variables</module>
+ </modules>
+
+</project>
\ No newline at end of file
[servicecomb-java-chassis] 02/02: [SCB-1862] ServiceComb add
extensions to support cas env variables:fixed as reviewed
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 10d45c6f88de8b13b066d4db32be1eb9483803f0
Author: heyile <25...@qq.com>
AuthorDate: Thu Apr 9 22:22:22 2020 +0800
[SCB-1862] ServiceComb add extensions to support cas env variables:fixed as reviewed
---
dependencies/bom/pom.xml | 12 ++++++------
distribution/pom.xml | 6 ++++++
{third-part-extensions => huawei-cloud}/pom.xml | 6 +++---
.../cas-env-variables => huawei-cloud/servicestage}/pom.xml | 4 ++--
.../servicecomb/huaweicloud/servicestage}/CasEnvConfig.java | 4 ++--
.../huaweicloud/servicestage}/CasEnvVariablesAdapter.java | 2 +-
...org.apache.servicecomb.serviceregistry.adapter.EnvAdapter | 2 +-
.../servicestage}/src/main/resources/mapping.yaml | 11 ++++++-----
.../huaweicloud/servicestage}/TestCasEnvConfig.java | 10 +++++-----
.../huaweicloud/servicestage}/TestEnvVariablesAdapter.java | 10 +++++-----
pom.xml | 2 +-
.../serviceregistry/adapter/DefaultEnvAdapter.java | 2 +-
.../serviceregistry/adapter/TestEnvAdapterManager.java | 8 ++++----
13 files changed, 43 insertions(+), 36 deletions(-)
diff --git a/dependencies/bom/pom.xml b/dependencies/bom/pom.xml
index c691b0a..2a28e1d 100644
--- a/dependencies/bom/pom.xml
+++ b/dependencies/bom/pom.xml
@@ -287,6 +287,12 @@
<artifactId>java-chassis-spring-boot-starter-standalone</artifactId>
<version>${project.version}</version>
</dependency>
+ <!-- ServiceComb ServiceStage extension -->
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>servicestage</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- ServiceComb: swagger -->
<dependency>
<groupId>org.apache.servicecomb</groupId>
@@ -365,12 +371,6 @@
<artifactId>transport-rest-vertx</artifactId>
<version>${project.version}</version>
</dependency>
- <!-- ServiceComb third-extensions -->
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>cas-env-variables</artifactId>
- <version>${project.version}</version>
- </dependency>
</dependencies>
</dependencyManagement>
</project>
\ No newline at end of file
diff --git a/distribution/pom.xml b/distribution/pom.xml
index eed5e43..a7d0854 100644
--- a/distribution/pom.xml
+++ b/distribution/pom.xml
@@ -244,6 +244,12 @@
<artifactId>java-chassis-spring-boot-starter-standalone</artifactId>
</dependency>
+ <!-- ServiceComb ServiceStage extension -->
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>servicestage</artifactId>
+ </dependency>
+
<!-- swagger -->
<dependency>
<groupId>org.apache.servicecomb</groupId>
diff --git a/third-part-extensions/pom.xml b/huawei-cloud/pom.xml
similarity index 90%
rename from third-part-extensions/pom.xml
rename to huawei-cloud/pom.xml
index ee2cce6..a2ebd89 100644
--- a/third-part-extensions/pom.xml
+++ b/huawei-cloud/pom.xml
@@ -25,13 +25,13 @@
<relativePath>../parents/default</relativePath>
</parent>
- <artifactId>third-part-extensions</artifactId>
- <name>Java Chassis::Third-Part Extensions</name>
+ <artifactId>huawei-cloud</artifactId>
+ <name>Java Chassis::Huawei Cloud</name>
<packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>
<modules>
- <module>cas-env-variables</module>
+ <module>servicestage</module>
</modules>
</project>
\ No newline at end of file
diff --git a/third-part-extensions/cas-env-variables/pom.xml b/huawei-cloud/servicestage/pom.xml
similarity index 91%
rename from third-part-extensions/cas-env-variables/pom.xml
rename to huawei-cloud/servicestage/pom.xml
index 4c20b62..1a22b18 100644
--- a/third-part-extensions/cas-env-variables/pom.xml
+++ b/huawei-cloud/servicestage/pom.xml
@@ -24,8 +24,8 @@
<version>2.0.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>cas-env-variables</artifactId>
- <name>Java Chassis::Third-Part Extensions::Cas Env Variables</name>
+ <artifactId>servicestage</artifactId>
+ <name>Java Chassis::Huawei Cloud::ServiceStage</name>
<dependencies>
<dependency>
diff --git a/third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvConfig.java b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvConfig.java
similarity index 94%
rename from third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvConfig.java
rename to huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvConfig.java
index 139912b..9601623 100644
--- a/third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvConfig.java
+++ b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvConfig.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.cas;
+package org.apache.servicecomb.huaweicloud.servicestage;
import static org.apache.commons.lang3.StringUtils.EMPTY;
@@ -28,7 +28,7 @@ import org.apache.commons.lang3.StringUtils;
import com.netflix.config.DynamicPropertyFactory;
public class CasEnvConfig {
- private static final String CAS_BASE = "servicecomb.cas.";
+ private static final String CAS_BASE = "servicecomb.huaweicloud.servicestage.cas.";
private static final String APPLICATION_ID = CAS_BASE + "application-id";
diff --git a/third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvVariablesAdapter.java b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvVariablesAdapter.java
similarity index 96%
rename from third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvVariablesAdapter.java
rename to huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvVariablesAdapter.java
index ecbd12e..973bac4 100644
--- a/third-part-extensions/cas-env-variables/src/main/java/org/apache/servicecomb/cas/CasEnvVariablesAdapter.java
+++ b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/CasEnvVariablesAdapter.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.cas;
+package org.apache.servicecomb.huaweicloud.servicestage;
import org.apache.servicecomb.serviceregistry.adapter.EnvAdapter;
import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
diff --git a/third-part-extensions/cas-env-variables/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter b/huawei-cloud/servicestage/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter
similarity index 91%
rename from third-part-extensions/cas-env-variables/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter
rename to huawei-cloud/servicestage/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter
index 88bdc59..a7eb97b 100644
--- a/third-part-extensions/cas-env-variables/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter
+++ b/huawei-cloud/servicestage/src/main/resources/META-INF/services/org.apache.servicecomb.serviceregistry.adapter.EnvAdapter
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.servicecomb.cas.CasEnvVariablesAdapter
\ No newline at end of file
+org.apache.servicecomb.huaweicloud.servicestage.CasEnvVariablesAdapter
\ No newline at end of file
diff --git a/third-part-extensions/cas-env-variables/src/main/resources/mapping.yaml b/huawei-cloud/servicestage/src/main/resources/mapping.yaml
similarity index 82%
rename from third-part-extensions/cas-env-variables/src/main/resources/mapping.yaml
rename to huawei-cloud/servicestage/src/main/resources/mapping.yaml
index f986613..0a61d9c 100644
--- a/third-part-extensions/cas-env-variables/src/main/resources/mapping.yaml
+++ b/huawei-cloud/servicestage/src/main/resources/mapping.yaml
@@ -14,16 +14,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
CAS_APPLICATION_ID:
- - servicecomb.cas.application-id
+ - servicecomb.huaweicloud.servicestage.cas.application-id
CAS_COMPONENT_NAME:
- - servicecomb.cas.component-name
+ - servicecomb.huaweicloud.servicestage.cas.component-name
CAS_INSTANCE_VERSION:
- - servicecomb.cas.instance-version
+ - servicecomb.huaweicloud.servicestage.cas.instance-version
CAS_INSTANCE_ID:
- - servicecomb.cas.instance-id
+ - servicecomb.huaweicloud.servicestage.cas.instance-id
CAS_ENVIRONMENT_ID:
- - servicecomb.cas.environment-id
+ - servicecomb.huaweicloud.servicestage.cas.environment-id
PAAS_CSE_ENDPOINT:
- servicecomb.service.registry.address
- servicecomb.config.client.serverUri
diff --git a/third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestCasEnvConfig.java b/huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestCasEnvConfig.java
similarity index 76%
rename from third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestCasEnvConfig.java
rename to huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestCasEnvConfig.java
index 211bf96..250e79b 100644
--- a/third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestCasEnvConfig.java
+++ b/huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestCasEnvConfig.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.cas;
+package org.apache.servicecomb.huaweicloud.servicestage;
import static org.junit.Assert.assertEquals;
@@ -26,8 +26,8 @@ public class TestCasEnvConfig {
@BeforeClass
public static void init() {
- System.setProperty("servicecomb.cas.application-id", "application-id");
- System.setProperty("servicecomb.cas.environment-id", "env-id");
+ System.setProperty("servicecomb.huaweicloud.servicestage.cas.application-id", "application-id");
+ System.setProperty("servicecomb.huaweicloud.servicestage.cas.environment-id", "env-id");
}
@Test
@@ -40,7 +40,7 @@ public class TestCasEnvConfig {
@AfterClass
public static void destroy() {
- System.getProperties().remove("servicecomb.cas.application-id");
- System.getProperties().remove("servicecomb.cas.environment-id");
+ System.getProperties().remove("servicecomb.huaweicloud.servicestage.cas.application-id");
+ System.getProperties().remove("servicecomb.huaweicloud.servicestage.cas.environment-id");
}
}
diff --git a/third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestEnvVariablesAdapter.java b/huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestEnvVariablesAdapter.java
similarity index 78%
rename from third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestEnvVariablesAdapter.java
rename to huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestEnvVariablesAdapter.java
index 0aec4cb..a9b2af1 100644
--- a/third-part-extensions/cas-env-variables/src/test/java/org/apache/servicecomb/cas/TestEnvVariablesAdapter.java
+++ b/huawei-cloud/servicestage/src/test/java/org/apache/servicecomb/huaweicloud/servicestage/TestEnvVariablesAdapter.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.cas;
+package org.apache.servicecomb.huaweicloud.servicestage;
import static org.junit.Assert.assertEquals;
@@ -27,8 +27,8 @@ public class TestEnvVariablesAdapter {
@BeforeClass
public static void init() {
- System.setProperty("servicecomb.cas.application-id", "application-id");
- System.setProperty("servicecomb.cas.environment-id", "env-id");
+ System.setProperty("servicecomb.huaweicloud.servicestage.cas.application-id", "application-id");
+ System.setProperty("servicecomb.huaweicloud.servicestage.cas.environment-id", "env-id");
}
@Test
@@ -44,7 +44,7 @@ public class TestEnvVariablesAdapter {
@AfterClass
public static void destroy() {
- System.getProperties().remove("servicecomb.cas.application-id");
- System.getProperties().remove("servicecomb.cas.environment-id");
+ System.getProperties().remove("servicecomb.huaweicloud.servicestage.cas.application-id");
+ System.getProperties().remove("servicecomb.huaweicloud.servicestage.cas.environment-id");
}
}
diff --git a/pom.xml b/pom.xml
index e681f69..9329861 100755
--- a/pom.xml
+++ b/pom.xml
@@ -126,7 +126,7 @@
<module>inspector</module>
<module>solutions</module>
<module>clients</module>
- <module>third-part-extensions</module>
+ <module>huawei-cloud</module>
</modules>
<reporting>
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/DefaultEnvAdapter.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/DefaultEnvAdapter.java
index 7895d54..0ab69a1 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/DefaultEnvAdapter.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/adapter/DefaultEnvAdapter.java
@@ -19,7 +19,7 @@ package org.apache.servicecomb.serviceregistry.adapter;
public class DefaultEnvAdapter implements EnvAdapter {
@Override
public String getEnvName() {
- return "default-env-default-adapter";
+ return "default-env-adapter";
}
@Override
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/TestEnvAdapterManager.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/TestEnvAdapterManager.java
index 7bef5be..cf22311 100644
--- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/TestEnvAdapterManager.java
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/adapter/TestEnvAdapterManager.java
@@ -32,13 +32,13 @@ public class TestEnvAdapterManager {
public void testLoadAdapter() {
assertEquals(3, manager.values().size());
assertNull(manager.findValue("cas-env-three"));
- assertNotNull(manager.findValue("default-env-default-adapter"));
+ assertNotNull(manager.findValue("default-env-adapter"));
assertNotNull(manager.findValue("cas_env_one"));
assertNotNull(manager.findValue("cas_env_two"));
assertEquals(0, manager.findValue("cas_env_one").getOrder());
assertEquals(0, manager.findValue("cas_env_two").getOrder());
- assertEquals(0, manager.findValue("default-env-default-adapter").getOrder());
+ assertEquals(0, manager.findValue("default-env-adapter").getOrder());
}
@Test
@@ -48,7 +48,7 @@ public class TestEnvAdapterManager {
assertEquals("order=0", microservice.getProperties().get("cas_env_one"));
assertEquals("order=0", microservice.getProperties().get("cas_env_two"));
- assertNull(microservice.getProperties().get("default-env-default-adapter"));
+ assertNull(microservice.getProperties().get("default-env-adapter"));
}
@Test
@@ -58,6 +58,6 @@ public class TestEnvAdapterManager {
assertEquals("order=0", instance.getProperties().get("cas_env_one"));
assertEquals("order=0", instance.getProperties().get("cas_env_two"));
- assertNull(instance.getProperties().get("default-env-default-adapter"));
+ assertNull(instance.getProperties().get("default-env-adapter"));
}
}