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
The following commit(s) were added to refs/heads/master by this push:
new aac1cc719 [SCB-2813]two apis invoke to one for first time invoke
(#4050)
aac1cc719 is described below
commit aac1cc719806712b7cc1e848ce66c068d697863c
Author: liubao68 <[email protected]>
AuthorDate: Tue Nov 21 19:12:42 2023 +0800
[SCB-2813]two apis invoke to one for first time invoke (#4050)
---
.../apache/servicecomb/core/ConsumerProvider.java | 28 ---
.../servicecomb/core/SCBApplicationListener.java | 2 -
.../org/apache/servicecomb/core/SCBEngine.java | 12 +-
.../core/ServiceCombCoreConfiguration.java | 7 +
.../servicecomb/core/bootstrap/SCBBootstrap.java | 2 +
.../core/provider/LocalOpenAPIRegistry.java | 96 ++--------
.../servicecomb/core/provider/OpenAPIRegistry.java | 5 +-
.../core/provider/OpenAPIRegistryManager.java | 17 +-
.../core/provider/RegistryOpenAPIRegistry.java | 25 +--
.../consumer/AbstractConsumerProvider.java | 26 ---
.../provider/consumer/ConsumerProviderManager.java | 65 ++++++-
.../provider/consumer/ReferenceConfigManager.java | 13 +-
.../microservices/pojo/helloworld.Greeter.yaml | 74 --------
.../main/resources/microservices/pojo/server.yaml | 197 ---------------------
.../resources/microservices/pojo/smartcare.yaml | 135 --------------
.../resources/microservices/pojo/tcc-server.yaml | 108 -----------
.../springmvc/client/TestManagementEndpoint.java | 7 +-
.../provider/pojo/PojoConsumerProvider.java | 29 ---
.../provider/pojo/ProviderPojoConfiguration.java | 4 -
.../provider/pojo/TestPojoConsumerProvider.java | 32 ----
.../common/ProviderRestCommonConfiguration.java | 5 -
.../provider/rest/common/RestConsumerProvider.java | 28 ---
.../rest/common/TestRestConsumerProvider.java | 32 ----
.../basic/integration/InstanceOpenAPIRegistry.java | 51 +-----
.../basic/integration/ManagementEndpoint.java | 9 +-
.../basic/integration/ManagementEndpointImpl.java | 40 +----
.../integration/TestManagementEndpointImpl.java | 27 +--
27 files changed, 102 insertions(+), 974 deletions(-)
diff --git
a/core/src/main/java/org/apache/servicecomb/core/ConsumerProvider.java
b/core/src/main/java/org/apache/servicecomb/core/ConsumerProvider.java
deleted file mode 100644
index b4b69a3cc..000000000
--- a/core/src/main/java/org/apache/servicecomb/core/ConsumerProvider.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.core;
-
-/**
- * consumer端对业务的接口,不同场景是完全不同的
- * 所以这里只定义consumer对core的接口
- */
-public interface ConsumerProvider {
- String getName();
-
- void init();
-}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/SCBApplicationListener.java
b/core/src/main/java/org/apache/servicecomb/core/SCBApplicationListener.java
index d290a604a..3bd5bd5d8 100644
--- a/core/src/main/java/org/apache/servicecomb/core/SCBApplicationListener.java
+++ b/core/src/main/java/org/apache/servicecomb/core/SCBApplicationListener.java
@@ -80,8 +80,6 @@ public class SCBApplicationListener
scbEngine.setPriorityPropertyManager(applicationContext.getBean(PriorityPropertyManager.class));
scbEngine.setFilterChainsManager(applicationContext.getBean(FilterChainsManager.class));
- scbEngine.getConsumerProviderManager().getConsumerProviderList()
-
.addAll(applicationContext.getBeansOfType(ConsumerProvider.class).values());
scbEngine.getProducerProviderManager().getProducerProviderList()
.addAll(applicationContext.getBeansOfType(ProducerProvider.class).values());
diff --git a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
index d89a46cf9..2d8b86818 100644
--- a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
+++ b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
@@ -76,7 +76,7 @@ public class SCBEngine {
private ProducerProviderManager producerProviderManager;
- private ConsumerProviderManager consumerProviderManager = new
ConsumerProviderManager();
+ private ConsumerProviderManager consumerProviderManager;
private MicroserviceMeta producerMicroserviceMeta;
@@ -174,6 +174,11 @@ public class SCBEngine {
this.openAPIRegistryManager = openAPIRegistryManager;
}
+ @Autowired
+ public void setConsumerProviderManager(ConsumerProviderManager
consumerProviderManager) {
+ this.consumerProviderManager = consumerProviderManager;
+ }
+
@Autowired
public void setExecutorManager(ExecutorManager executorManager) {
this.executorManager = executorManager;
@@ -246,11 +251,6 @@ public class SCBEngine {
return consumerProviderManager;
}
- public SCBEngine setConsumerProviderManager(ConsumerProviderManager
consumerProviderManager) {
- this.consumerProviderManager = consumerProviderManager;
- return this;
- }
-
public TransportManager getTransportManager() {
return transportManager;
}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java
b/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java
index b18d86bf8..99d2b9788 100644
---
a/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java
+++
b/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java
@@ -23,6 +23,7 @@ import org.apache.servicecomb.core.executor.GroupExecutor;
import org.apache.servicecomb.core.provider.LocalOpenAPIRegistry;
import org.apache.servicecomb.core.provider.OpenAPIRegistryManager;
import org.apache.servicecomb.core.provider.RegistryOpenAPIRegistry;
+import org.apache.servicecomb.core.provider.consumer.ConsumerProviderManager;
import org.apache.servicecomb.core.provider.consumer.ReferenceConfigManager;
import org.apache.servicecomb.core.provider.producer.ProducerBootListener;
import org.apache.servicecomb.core.transport.TransportManager;
@@ -46,6 +47,12 @@ public class ServiceCombCoreConfiguration {
return new SCBEngine();
}
+ @Bean
+ public ConsumerProviderManager consumerProviderManager(Environment
environment,
+ OpenAPIRegistryManager openAPIRegistryManager) {
+ return new ConsumerProviderManager(environment, openAPIRegistryManager);
+ }
+
@Bean
public ReferenceConfigManager referenceConfigManager() {
return new ReferenceConfigManager();
diff --git
a/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java
b/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java
index ce5cedcb1..21040a341 100644
--- a/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java
+++ b/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java
@@ -23,6 +23,7 @@ import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.executor.ExecutorManager;
import org.apache.servicecomb.core.provider.LocalOpenAPIRegistry;
import org.apache.servicecomb.core.provider.OpenAPIRegistryManager;
+import org.apache.servicecomb.core.provider.consumer.ConsumerProviderManager;
import org.apache.servicecomb.core.transport.TransportManager;
import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
import org.apache.servicecomb.registry.DiscoveryManager;
@@ -48,6 +49,7 @@ public class SCBBootstrap {
result.setEnvironment(environment);
OpenAPIRegistryManager openAPIRegistryManager = new
OpenAPIRegistryManager();
openAPIRegistryManager.setOpenAPIRegistries(List.of(new
LocalOpenAPIRegistry(environment)));
+ result.setConsumerProviderManager(new ConsumerProviderManager(environment,
openAPIRegistryManager));
result.setOpenAPIRegistryManager(openAPIRegistryManager);
return result;
}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/provider/LocalOpenAPIRegistry.java
b/core/src/main/java/org/apache/servicecomb/core/provider/LocalOpenAPIRegistry.java
index 4707a0e12..14a27530c 100644
---
a/core/src/main/java/org/apache/servicecomb/core/provider/LocalOpenAPIRegistry.java
+++
b/core/src/main/java/org/apache/servicecomb/core/provider/LocalOpenAPIRegistry.java
@@ -16,24 +16,12 @@
*/
package org.apache.servicecomb.core.provider;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
import org.apache.servicecomb.config.BootStrapProperties;
import
org.apache.servicecomb.core.provider.OpenAPIRegistryManager.OpenAPIChangeListener;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
-import org.apache.servicecomb.foundation.common.utils.JvmUtils;
-import org.apache.servicecomb.foundation.common.utils.ResourceUtil;
-import org.apache.servicecomb.swagger.SwaggerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
@@ -64,33 +52,6 @@ public class LocalOpenAPIRegistry implements OpenAPIRegistry
{
return true;
}
- @Override
- public Set<String> getSchemaIds(String application, String serviceName) {
- Set<String> result = new HashSet<>();
- if (apps.get(application) != null &&
apps.get(application).get(serviceName) != null) {
- result.addAll(apps.get(application).get(serviceName).keySet());
- }
-
- String swaggersLocation;
- if (application.equals(BootStrapProperties.readApplication(environment))) {
- swaggersLocation = String.format("microservices/%s", serviceName);
- } else {
- swaggersLocation = String.format("applications/%s/%s", application,
serviceName);
- }
- try {
- List<URI> resourceUris =
ResourceUtil.findResourcesBySuffix(swaggersLocation, ".yaml");
- for (URI uri : resourceUris) {
- String path = uri.toURL().getPath();
- path = path.substring(path.lastIndexOf("/") + 1);
- path = path.substring(0, path.indexOf(".yaml"));
- result.add(path);
- }
- } catch (IOException | URISyntaxException e) {
- LOGGER.error("Load schema ids failed from location {}. {}.",
swaggersLocation, e.getMessage());
- }
- return result;
- }
-
@Override
public void registerOpenAPI(String application, String serviceName, String
schemaId, OpenAPI api) {
apps.computeIfAbsent(application, k -> new ConcurrentHashMapEx<>())
@@ -101,27 +62,20 @@ public class LocalOpenAPIRegistry implements
OpenAPIRegistry {
application, serviceName, schemaId);
}
+ /**
+ * Method for retrieve myself schema contents.
+ */
+ public Map<String, OpenAPI> loadOpenAPI() {
+ return loadOpenAPI(BootStrapProperties.readApplication(environment),
+ BootStrapProperties.readServiceName(environment));
+ }
+
@Override
- public Map<String, OpenAPI> loadOpenAPI(String application, String
serviceName, Set<String> schemaIds) {
- Map<String, OpenAPI> result = new HashMap<>(schemaIds.size());
- for (String schemaId : schemaIds) {
- OpenAPI api = loadFromMemory(application, serviceName, schemaId);
- if (api == null) {
- api = loadFromResource(application, serviceName, schemaId);
- }
- if (api != null) {
- result.put(schemaId, api);
- }
- }
- if (result.isEmpty()) {
- return result;
- }
- if (result.size() != schemaIds.size()) {
- LOGGER.warn("Local OpenAPI registry contains only partial schemas for
{}/{}, this is not allowed.",
- application, serviceName);
- return Collections.emptyMap();
+ public Map<String, OpenAPI> loadOpenAPI(String application, String
serviceName) {
+ if (apps.get(application) != null &&
apps.get(application).get(serviceName) != null) {
+ return apps.get(application).get(serviceName);
}
- return result;
+ return Collections.emptyMap();
}
@Override
@@ -129,32 +83,6 @@ public class LocalOpenAPIRegistry implements
OpenAPIRegistry {
this.openAPIChangeListener = listener;
}
- protected OpenAPI loadFromResource(String application, String serviceName,
String schemaId) {
- if (application.equals(BootStrapProperties.readApplication(environment))) {
- OpenAPI swagger =
loadFromResource(String.format("microservices/%s/%s.yaml", serviceName,
schemaId));
- if (swagger != null) {
- return swagger;
- }
- }
- return loadFromResource(String.format("applications/%s/%s/%s.yaml",
application, serviceName, schemaId));
- }
-
- protected OpenAPI loadFromResource(String path) {
- URL url = JvmUtils.findClassLoader().getResource(path);
- if (url == null) {
- return null;
- }
-
- return SwaggerUtils.parseAndValidateSwagger(url);
- }
-
- protected OpenAPI loadFromMemory(String application, String serviceName,
String schemaId) {
- return Optional.ofNullable(apps.get(application))
- .map(microservices -> microservices.get(serviceName))
- .map(schemas -> schemas.get(schemaId))
- .orElse(null);
- }
-
@Override
public int getOrder() {
return -10000;
diff --git
a/core/src/main/java/org/apache/servicecomb/core/provider/OpenAPIRegistry.java
b/core/src/main/java/org/apache/servicecomb/core/provider/OpenAPIRegistry.java
index 1a5367bf5..440c297d7 100644
---
a/core/src/main/java/org/apache/servicecomb/core/provider/OpenAPIRegistry.java
+++
b/core/src/main/java/org/apache/servicecomb/core/provider/OpenAPIRegistry.java
@@ -17,7 +17,6 @@
package org.apache.servicecomb.core.provider;
import java.util.Map;
-import java.util.Set;
import
org.apache.servicecomb.core.provider.OpenAPIRegistryManager.OpenAPIChangeListener;
import org.springframework.core.Ordered;
@@ -32,11 +31,9 @@ public interface OpenAPIRegistry extends Ordered {
boolean enabled();
- Set<String> getSchemaIds(String application, String serviceName);
-
void registerOpenAPI(String application, String serviceName, String
schemaId, OpenAPI api);
- Map<String, OpenAPI> loadOpenAPI(String application, String serviceName,
Set<String> schemaIds);
+ Map<String, OpenAPI> loadOpenAPI(String application, String serviceName);
void setOpenAPIChangeListener(OpenAPIChangeListener listener);
}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/provider/OpenAPIRegistryManager.java
b/core/src/main/java/org/apache/servicecomb/core/provider/OpenAPIRegistryManager.java
index e19d0830a..c357e6a24 100644
---
a/core/src/main/java/org/apache/servicecomb/core/provider/OpenAPIRegistryManager.java
+++
b/core/src/main/java/org/apache/servicecomb/core/provider/OpenAPIRegistryManager.java
@@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.apache.commons.io.FilenameUtils;
import org.apache.servicecomb.foundation.common.utils.ResourceUtil;
@@ -75,16 +74,6 @@ public class OpenAPIRegistryManager {
}
}
- public Set<String> getSchemaIds(String application, String serviceName) {
- for (OpenAPIRegistry registry : this.openAPIRegistries) {
- Set<String> content = registry.getSchemaIds(application, serviceName);
- if (!CollectionUtils.isEmpty(content)) {
- return content;
- }
- }
- return Collections.emptySet();
- }
-
public void registerOpenAPI(String application, String serviceName, String
schemaId, OpenAPI api) {
for (OpenAPIRegistry registry : this.openAPIRegistries) {
registry.registerOpenAPI(application, serviceName, schemaId, api);
@@ -115,10 +104,10 @@ public class OpenAPIRegistryManager {
}
}
- public Map<String, OpenAPI> loadOpenAPI(String appId, String
microserviceName, Set<String> schemaIds) {
+ public Map<String, OpenAPI> loadOpenAPI(String appId, String
microserviceName) {
for (OpenAPIRegistry registry : this.openAPIRegistries) {
- Map<String, OpenAPI> result = registry.loadOpenAPI(appId,
microserviceName, schemaIds);
- if (!CollectionUtils.isEmpty(result) && result.size() ==
schemaIds.size()) {
+ Map<String, OpenAPI> result = registry.loadOpenAPI(appId,
microserviceName);
+ if (!CollectionUtils.isEmpty(result)) {
return result;
}
}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/provider/RegistryOpenAPIRegistry.java
b/core/src/main/java/org/apache/servicecomb/core/provider/RegistryOpenAPIRegistry.java
index e2ff66404..cc5e6fe22 100644
---
a/core/src/main/java/org/apache/servicecomb/core/provider/RegistryOpenAPIRegistry.java
+++
b/core/src/main/java/org/apache/servicecomb/core/provider/RegistryOpenAPIRegistry.java
@@ -17,10 +17,8 @@
package org.apache.servicecomb.core.provider;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import
org.apache.servicecomb.core.provider.OpenAPIRegistryManager.OpenAPIChangeListener;
import org.apache.servicecomb.registry.DiscoveryManager;
@@ -59,34 +57,13 @@ public class RegistryOpenAPIRegistry implements
OpenAPIRegistry {
return environment.getProperty(OpenAPIRegistry.CONFIG_PREFIX +
".registry.enabled", boolean.class, false);
}
- @Override
- public Set<String> getSchemaIds(String application, String serviceName) {
- List<? extends DiscoveryInstance> discoveryInstances =
- discoveryManager.findServiceInstances(application, serviceName);
- if (discoveryInstances.isEmpty()) {
- throw new InvocationException(Status.INTERNAL_SERVER_ERROR, "no
instances");
- }
- discoveryInstances.sort((a, b) ->
VersionCompareUtil.compareVersion(b.getVersion(), a.getVersion()));
-
- Set<String> result = new HashSet<>();
- String version = null;
- for (DiscoveryInstance instance : discoveryInstances) {
- if (version != null && !version.equals(instance.getVersion())) {
- break;
- }
- version = instance.getVersion();
- result.addAll(instance.getSchemas().keySet());
- }
- return result;
- }
-
@Override
public void registerOpenAPI(String application, String serviceName, String
schemaId, OpenAPI api) {
// do noting
}
@Override
- public Map<String, OpenAPI> loadOpenAPI(String application, String
serviceName, Set<String> schemaIds) {
+ public Map<String, OpenAPI> loadOpenAPI(String application, String
serviceName) {
List<? extends DiscoveryInstance> discoveryInstances =
discoveryManager.findServiceInstances(application, serviceName);
if (discoveryInstances.isEmpty()) {
diff --git
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/AbstractConsumerProvider.java
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/AbstractConsumerProvider.java
deleted file mode 100644
index c9093c330..000000000
---
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/AbstractConsumerProvider.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.core.provider.consumer;
-
-import org.apache.servicecomb.core.ConsumerProvider;
-
-public abstract class AbstractConsumerProvider implements ConsumerProvider {
- @Override
- public void init() {
- }
-}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ConsumerProviderManager.java
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ConsumerProviderManager.java
index b1a6f8ec9..615063bd3 100644
---
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ConsumerProviderManager.java
+++
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ConsumerProviderManager.java
@@ -17,23 +17,70 @@
package org.apache.servicecomb.core.provider.consumer;
-import java.util.ArrayList;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.List;
-import org.apache.servicecomb.core.ConsumerProvider;
-import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
+import org.apache.servicecomb.config.BootStrapProperties;
+import org.apache.servicecomb.core.provider.OpenAPIRegistryManager;
+import org.apache.servicecomb.foundation.common.utils.ResourceUtil;
+import org.apache.servicecomb.swagger.SwaggerUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.env.Environment;
public class ConsumerProviderManager {
- private final List<ConsumerProvider> consumerProviderList = new ArrayList<>(
- SPIServiceUtils.getOrLoadSortedService(ConsumerProvider.class));
+ private static final Logger LOGGER =
LoggerFactory.getLogger(ConsumerProviderManager.class);
- public List<ConsumerProvider> getConsumerProviderList() {
- return consumerProviderList;
+ private final OpenAPIRegistryManager openAPIRegistryManager;
+
+ private final Environment environment;
+
+ public ConsumerProviderManager(Environment environment,
OpenAPIRegistryManager openAPIRegistryManager) {
+ this.environment = environment;
+ this.openAPIRegistryManager = openAPIRegistryManager;
}
public void init() throws Exception {
- for (ConsumerProvider provider : consumerProviderList) {
- provider.init();
+ registerSwaggerFromApplications();
+ registerSwaggerFromMicroservices();
+ }
+
+ private void registerSwaggerFromApplications() {
+ try {
+ List<URI> resourceUris =
ResourceUtil.findResourcesBySuffix("applications", ".yaml");
+ for (URI uri : resourceUris) {
+ String path = uri.toURL().getPath();
+ String[] segments = path.split("/");
+ if (segments.length < 4 ||
!"applications".equals(segments[segments.length - 4])) {
+ continue;
+ }
+ openAPIRegistryManager.registerOpenAPI(segments[segments.length - 3],
segments[segments.length - 2],
+ segments[segments.length - 1].substring(0,
segments[segments.length - 1].indexOf(".yaml")),
+ SwaggerUtils.parseAndValidateSwagger(uri.toURL()));
+ }
+ } catch (IOException | URISyntaxException e) {
+ LOGGER.error("Load schema ids failed from applications. {}.",
e.getMessage());
+ }
+ }
+
+ private void registerSwaggerFromMicroservices() {
+ try {
+ List<URI> resourceUris =
ResourceUtil.findResourcesBySuffix("microservices", ".yaml");
+ for (URI uri : resourceUris) {
+ String path = uri.toURL().getPath();
+ String[] segments = path.split("/");
+ if (segments.length < 3 ||
!"microservices".equals(segments[segments.length - 3])) {
+ continue;
+ }
+
openAPIRegistryManager.registerOpenAPI(BootStrapProperties.readApplication(environment),
+ segments[segments.length - 2],
+ segments[segments.length - 1].substring(0,
segments[segments.length - 1].indexOf(".yaml")),
+ SwaggerUtils.parseAndValidateSwagger(uri.toURL()));
+ }
+ } catch (IOException | URISyntaxException e) {
+ LOGGER.error("Load schema ids failed from microservices. {}.",
e.getMessage());
}
}
}
diff --git
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ReferenceConfigManager.java
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ReferenceConfigManager.java
index b38a8aa0b..dffecfd62 100644
---
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ReferenceConfigManager.java
+++
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ReferenceConfigManager.java
@@ -17,7 +17,7 @@
package org.apache.servicecomb.core.provider.consumer;
import java.util.Map;
-import java.util.Set;
+import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
import org.apache.servicecomb.core.SCBEngine;
@@ -141,17 +141,16 @@ public class ReferenceConfigManager {
.findEdgeChain(application, microserviceName));
microserviceMeta.setMicroserviceVersionsMeta(microserviceVersionsMeta);
- Set<String> schemaIds =
this.openAPIRegistryManager.getSchemaIds(application, microserviceName);
- Map<String, OpenAPI> schemas =
this.openAPIRegistryManager.loadOpenAPI(application, microserviceName,
schemaIds);
- for (String schemaId : schemaIds) {
- OpenAPI swagger = schemas.get(schemaId);
+ Map<String, OpenAPI> schemas =
this.openAPIRegistryManager.loadOpenAPI(application, microserviceName);
+ for (Entry<String, OpenAPI> entry : schemas.entrySet()) {
+ OpenAPI swagger = entry.getValue();
if (swagger != null) {
- microserviceMeta.registerSchemaMeta(schemaId, swagger);
+ microserviceMeta.registerSchemaMeta(entry.getKey(), entry.getValue());
continue;
}
throw new InvocationException(Status.INTERNAL_SERVER_ERROR,
String.format("Swagger %s/%s/%s can not be empty or load swagger
failed.",
- application, microserviceName, schemaId));
+ application, microserviceName, entry.getKey()));
}
EventManager.getEventBus().post(new
CreateMicroserviceMetaEvent(microserviceMeta));
diff --git
a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/helloworld.Greeter.yaml
b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/helloworld.Greeter.yaml
deleted file mode 100644
index d503f154c..000000000
---
a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/helloworld.Greeter.yaml
+++ /dev/null
@@ -1,74 +0,0 @@
-## ---------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-## ---------------------------------------------------------------------------
-
-# this is an example of the Uber API
-# as a demonstration of an API spec in YAML
-swagger: '2.0'
-info:
- title: helloworld.Greeter
- version: 1.0.0
- x-java-interface: org.apache.servicecomb.demo.helloworld.greeter.Hello
-
-# the domain of the service
-#host: api.uber.com
-
-# array of all schemes that your API supports
-#schemes:
-# - https
-
-# will be prefixed to all paths
-basePath: /pojo/rest/helloworld.Greeter
-produces:
- - application/json
-
-paths:
- /SayHello:
- post:
- operationId: SayHello
- parameters:
- - name: name
- in: body
- required: true
- schema:
- type: string
- responses:
- "200":
- description: asdf
- schema:
- type: string
- default:
- description: asf
- schema:
- type: string
- /SayHelloAgain:
- post:
- operationId: SayHelloAgain
- parameters:
- - name: name
- in: body
- required: true
- schema:
- type: string
- responses:
- "200":
- description: asdf
- schema:
- type: string
- default:
- description: asf
- schema:
- type: string
diff --git
a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/server.yaml
b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/server.yaml
deleted file mode 100644
index 4717f8e48..000000000
---
a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/server.yaml
+++ /dev/null
@@ -1,197 +0,0 @@
-## ---------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-## ---------------------------------------------------------------------------
-
-# this is an example of the Uber API
-# as a demonstration of an API spec in YAML
-swagger: '2.0'
-info:
- title: cse test
- version: 1.0.0
- x-java-interface:
org.apache.servicecomb.demo.springboot.pojo.server.schema.server.Test
-
-# the domain of the service
-#host: api.uber.com
-
-# array of all schemes that your API supports
-#schemes:
-# - https
-
-# will be prefixed to all paths
-basePath: /pojo/rest
-produces:
- - application/json
-
-paths:
- /testStringArray:
- get:
- operationId: testStringArray
- parameters:
- - name: arr
- in: query
- required: true
- type: array
- items:
- type: string
- responses:
- "200":
- description: asdf
- schema:
- type: string
- /testStatic:
- get:
- operationId: getTestString
- parameters:
- - name: code
- in: query
- required: false
- type: string
- responses:
- "200":
- description: asdf
- schema:
- type: string
- post:
- operationId: postTestStatic
- parameters:
- - name: code
- in: query
- required: true
- type: integer
- format: int32
- responses:
- "200":
- description: asdf
- schema:
- type: string
- /testException/{code}:
- get:
- operationId: testException
- parameters:
- - name: code
- in: path
- required: true
- type: integer
- format: int32
- responses:
- "200":
- description: asdf
- schema:
- type: string
- 456:
- description: asdf
- schema:
- type: string
- 556:
- description: asdf
- schema:
- type: array
- items:
- type: string
- 557:
- description: asdf
- schema:
- type: array
- items:
- type: array
- items:
- type: string
- /splitParam:
- post:
- operationId: splitParam
- parameters:
- - name: index
- in: query
- required: true
- type: number
- - name: user
- in: body
- schema:
- $ref: '#/definitions/User'
- responses:
- "200":
- description: asdf
- schema:
- $ref: '#/definitions/User'
- default:
- description: asf
- schema:
- $ref: '#/definitions/Error'
- /wrapParam:
- post:
- operationId: wrapParam
- parameters:
- - name: request
- in: body
- required: false
- schema:
- $ref: '#/definitions/TestRequest'
- responses:
- "200":
- description: asdf
- schema:
- $ref: '#/definitions/User'
- default:
- description: asf
- schema:
- $ref: '#/definitions/Error'
- /addstring:
- delete:
- operationId: addString
- parameters:
- - name: strArr
- in: query
- required: true
- type: array
- items:
- type: string
- responses:
- "200":
- description: add string
- schema:
- type: string
-
-definitions:
- Error:
- type: object
- x-java-class: org.apache.servicecomb.core.exception.CommonExceptionData
- properties:
- message:
- type: string
- TestRequest:
- type: object
- properties:
- index:
- type: number
- user:
- $ref: '#/definitions/User'
- users:
- type: array
- items:
- $ref: '#/definitions/User'
- data:
- type: string
- format: byte
- User:
- type: object
- properties:
- name:
- type: string
- age:
- type: number
- index:
- type: number
- x-java-class:
"org.apache.servicecomb.demo.springboot.pojo.server.schema.server.User"
\ No newline at end of file
diff --git
a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/smartcare.yaml
b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/smartcare.yaml
deleted file mode 100644
index 49a8ac93e..000000000
---
a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/smartcare.yaml
+++ /dev/null
@@ -1,135 +0,0 @@
-## ---------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-## ---------------------------------------------------------------------------
-
-# this is an example of the Uber API
-# as a demonstration of an API spec in YAML
-swagger: '2.0'
-info:
- title: smartcare test
- version: 1.0.0
- x-java-interface: org.apache.servicecomb.demo.smartcare.SmartCare
-
-# the domain of the service
-#host: api.uber.com
-
-# array of all schemes that your API supports
-#schemes:
-# - https
-
-# will be prefixed to all paths
-basePath: /pojo/rest/plat/meta/v1
-produces:
- - application/json
-
-paths:
- /applications:
- post:
- operationId: addApplication
- parameters:
- - name: application
- in: body
- required: true
- schema:
- $ref: '#/definitions/Application'
- responses:
- 201:
- description: success
- schema:
- $ref: '#/definitions/Response'
- 400:
- description: error
- schema:
- $ref: '#/definitions/Response'
- 500:
- description: error
- schema:
- $ref: '#/definitions/Response'
-
- /applications/{appName}:
- delete:
- operationId: delApplication
- parameters:
- - name: appName
- in: path
- required: true
- type: string
- responses:
- 201:
- description: success
- schema:
- $ref: '#/definitions/Response'
- 400:
- description: error
- schema:
- $ref: '#/definitions/Response'
- 500:
- description: error
- schema:
- $ref: '#/definitions/Response'
-
-
-definitions:
- Application:
- type: object
- properties:
- name:
- type: string
- labelEN:
- type: string
- labelCH:
- type: string
- defaultGroup:
- type: string
- version:
- type: string
- dynamicFlag:
- type: boolean
- groups:
- type: array
- items:
- $ref: '#/definitions/Group'
- required:
- - name
- - defaultGroup
- - version
- - dynamicFlag
- - groups
-
- Group:
- type: object
- properties:
- name:
- type: string
- labelEN:
- type: string
- labelCH:
- type: string
- required:
- - name
-
- Response:
- type: object
- x-java-class: org.apache.servicecomb.demo.smartcare.Response
- properties:
- resultCode:
- type: integer
- format: int32
- resultMessage:
- type: string
- required:
- - resultCode
-
diff --git
a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/tcc-server.yaml
b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/tcc-server.yaml
deleted file mode 100644
index 4af831b88..000000000
---
a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-server/src/main/resources/microservices/pojo/tcc-server.yaml
+++ /dev/null
@@ -1,108 +0,0 @@
-## ---------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-## ---------------------------------------------------------------------------
-
-# this is an example of the Uber API
-# as a demonstration of an API spec in YAML
-swagger: '2.0'
-info:
- title: cse test
- version: 1.0.0
- x-java-interface: org.apache.servicecomb.demo.tccserver.TestTcc
-
-# the domain of the service
-#host: api.uber.com
-
-# array of all schemes that your API supports
-#schemes:
-# - https
-
-# will be prefixed to all paths
-basePath: /pojo/rest/tcc-server
-produces:
- - application/json
-
-paths:
- /splitParam:
- post:
- operationId: splitParam
- parameters:
- - name: index
- in: query
- required: true
- type: number
- - name: user
- in: body
- schema:
- $ref: '#/definitions/User'
- responses:
- "200":
- description: asdf
- schema:
- $ref: '#/definitions/User'
- default:
- description: asf
- schema:
- $ref: '#/definitions/Error'
- /wrapParam:
- post:
- operationId: wrapParam
- parameters:
- - name: TestRequest
- in: body
- required: true
- schema:
- $ref: '#/definitions/TestRequest'
- responses:
- "200":
- description: asdf
- schema:
- $ref: '#/definitions/User'
- default:
- description: asf
- schema:
- $ref: '#/definitions/Error'
-
-definitions:
- Error:
- type: object
- x-java-class: org.apache.servicecomb.core.exception.CommonExceptionData
- properties:
- message:
- type: string
- TestRequest:
- type: object
- properties:
- index:
- type: number
- user:
- $ref: '#/definitions/User'
- users:
- type: array
- items:
- $ref: '#/definitions/User'
- data:
- type: string
- format: byte
- User:
- type: object
- properties:
- name:
- type: string
- age:
- type: number
- index:
- type: number
diff --git
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestManagementEndpoint.java
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestManagementEndpoint.java
index 07c04729d..edac80715 100644
---
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestManagementEndpoint.java
+++
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestManagementEndpoint.java
@@ -16,9 +16,7 @@
*/
package org.apache.servicecomb.demo.springmvc.client;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
import org.apache.servicecomb.demo.CategorizedTestCase;
import org.apache.servicecomb.demo.TestMgr;
@@ -149,10 +147,7 @@ public class TestManagementEndpoint implements
CategorizedTestCase {
}
private void testSchemeInterfaceSpringmvcContentCorrect() {
- Set<String> schemaIds = new HashSet<>();
- schemaIds.add("SchemeInterfaceSpringmvc");
- Map<String, String> contents =
managementEndpoint.schemaContents(schemaIds);
- TestMgr.check(1, contents.size());
+ Map<String, String> contents = managementEndpoint.schemaContents();
TestMgr.check(CONTENT_SCHEMA, contents.get("SchemeInterfaceSpringmvc"));
}
}
diff --git
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoConsumerProvider.java
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoConsumerProvider.java
deleted file mode 100644
index f3bae5b0c..000000000
---
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/PojoConsumerProvider.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.provider.pojo;
-
-import static org.apache.servicecomb.provider.pojo.PojoConst.POJO;
-
-import org.apache.servicecomb.core.provider.consumer.AbstractConsumerProvider;
-
-public class PojoConsumerProvider extends AbstractConsumerProvider {
- @Override
- public String getName() {
- return POJO;
- }
-}
diff --git
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/ProviderPojoConfiguration.java
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/ProviderPojoConfiguration.java
index 14f91542f..e66299c96 100644
---
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/ProviderPojoConfiguration.java
+++
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/ProviderPojoConfiguration.java
@@ -23,10 +23,6 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class ProviderPojoConfiguration {
- @Bean
- public PojoConsumerProvider pojoConsumerProvider() {
- return new PojoConsumerProvider();
- }
@Bean
public RpcReferenceProcessor rpcReferenceProcessor() {
diff --git
a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/TestPojoConsumerProvider.java
b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/TestPojoConsumerProvider.java
deleted file mode 100644
index 0321934dd..000000000
---
a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/TestPojoConsumerProvider.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.provider.pojo;
-
-import static org.apache.servicecomb.provider.pojo.PojoConst.POJO;
-import static org.hamcrest.core.Is.is;
-
-import org.hamcrest.MatcherAssert;
-import org.junit.jupiter.api.Test;
-
-public class TestPojoConsumerProvider {
- @Test
- public void providerNameIsPojo() {
- PojoConsumerProvider pojoConsumerProvider = new PojoConsumerProvider();
- MatcherAssert.assertThat(pojoConsumerProvider.getName(), is(POJO));
- }
-}
diff --git
a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProviderRestCommonConfiguration.java
b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProviderRestCommonConfiguration.java
index 7f613d10f..d4599aa42 100644
---
a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProviderRestCommonConfiguration.java
+++
b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProviderRestCommonConfiguration.java
@@ -25,9 +25,4 @@ public class ProviderRestCommonConfiguration {
public RestProducers restProducers() {
return new RestProducers();
}
-
- @Bean
- public RestConsumerProvider restConsumerProvider() {
- return new RestConsumerProvider();
- }
}
diff --git
a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/RestConsumerProvider.java
b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/RestConsumerProvider.java
deleted file mode 100644
index 31877baf4..000000000
---
a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/RestConsumerProvider.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.provider.rest.common;
-
-import org.apache.servicecomb.common.rest.RestConst;
-import org.apache.servicecomb.core.provider.consumer.AbstractConsumerProvider;
-
-public class RestConsumerProvider extends AbstractConsumerProvider {
- @Override
- public String getName() {
- return RestConst.REST;
- }
-}
diff --git
a/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestRestConsumerProvider.java
b/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestRestConsumerProvider.java
deleted file mode 100644
index 4f7109946..000000000
---
a/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestRestConsumerProvider.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.provider.rest.common;
-
-import org.apache.servicecomb.common.rest.RestConst;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class TestRestConsumerProvider {
-
- @Test
- public void testInit() throws Exception {
- RestConsumerProvider instance = new RestConsumerProvider();
- instance.init();
- Assertions.assertEquals(RestConst.REST, instance.getName());
- }
-}
diff --git
a/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/InstanceOpenAPIRegistry.java
b/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/InstanceOpenAPIRegistry.java
index 0bcf428bc..b2fd237a9 100644
---
a/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/InstanceOpenAPIRegistry.java
+++
b/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/InstanceOpenAPIRegistry.java
@@ -21,7 +21,6 @@ import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.apache.servicecomb.config.BootStrapProperties;
import org.apache.servicecomb.core.Endpoint;
@@ -76,50 +75,6 @@ public class InstanceOpenAPIRegistry implements
OpenAPIRegistry {
return environment.getProperty(OpenAPIRegistry.CONFIG_PREFIX +
".instance.enabled", boolean.class, true);
}
- @Override
- @SuppressWarnings("unchecked")
- public Set<String> getSchemaIds(String application, String serviceName) {
- List<? extends DiscoveryInstance> discoveryInstances =
- discoveryManager.findServiceInstances(application, serviceName);
- if (discoveryInstances.isEmpty()) {
- throw new InvocationException(Status.INTERNAL_SERVER_ERROR, "no
instances");
- }
- discoveryInstances.sort((a, b) ->
VersionCompareUtil.compareVersion(b.getVersion(), a.getVersion()));
-
- String version = null;
- for (DiscoveryInstance instance : discoveryInstances) {
- if (version != null && !version.equals(instance.getVersion())) {
- break;
- }
- version = instance.getVersion();
- for (String endpoint : instance.getEndpoints()) {
- URI uri = URI.create(endpoint);
- String transportName = uri.getScheme();
- Transport transport = transportManager.findTransport(transportName);
- if (transport == null) {
- continue;
- }
- // Use myself service name instead of the target. Because can avoid
create
- // MicroserviceReferenceConfig for the target.
- Invocation invocation =
InvokerUtils.createInvocation(BootStrapProperties.readServiceName(environment),
- transportName,
- ManagementEndpoint.NAME, "schemaIds",
- new HashMap<>(), new TypeReference<Set<String>>() {
- }.getType());
- invocation.setEndpoint(new Endpoint(transport, endpoint,
discoveryInstances.get(0)));
- try {
- return (Set<String>) InvokerUtils.syncInvoke(invocation);
- } catch (InvocationException e) {
- LOGGER.warn("Get schema ids {}/{}/{} from endpoint {} failed. {}",
- instance.getApplication(),
- instance.getServiceName(),
- instance.getInstanceId(), endpoint, e.getMessage());
- }
- }
- }
- throw new InvocationException(Status.INTERNAL_SERVER_ERROR, "Get schema
ids fail from all latest version.");
- }
-
@Override
public void registerOpenAPI(String application, String serviceName, String
schemaId, OpenAPI api) {
// do nothing
@@ -127,7 +82,7 @@ public class InstanceOpenAPIRegistry implements
OpenAPIRegistry {
@Override
@SuppressWarnings("unchecked")
- public Map<String, OpenAPI> loadOpenAPI(String application, String
serviceName, Set<String> schemaIds) {
+ public Map<String, OpenAPI> loadOpenAPI(String application, String
serviceName) {
List<? extends DiscoveryInstance> discoveryInstances =
discoveryManager.findServiceInstances(application, serviceName);
if (discoveryInstances.isEmpty()) {
@@ -150,12 +105,10 @@ public class InstanceOpenAPIRegistry implements
OpenAPIRegistry {
}
// Use myself service name instead of the target. Because can avoid
create
// MicroserviceReferenceConfig for the target.
- Map<String, Object> args = new HashMap<>();
- args.put("schemaIds", schemaIds);
Invocation invocation =
InvokerUtils.createInvocation(BootStrapProperties.readServiceName(environment),
transportName,
ManagementEndpoint.NAME, "schemaContents",
- args, new TypeReference<Map<String, String>>() {
+ new HashMap<>(), new TypeReference<Map<String, String>>() {
}.getType());
invocation.setEndpoint(new Endpoint(transport, endpoint,
discoveryInstances.get(0)));
try {
diff --git
a/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/ManagementEndpoint.java
b/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/ManagementEndpoint.java
index a9c10f601..f41aa8a21 100644
---
a/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/ManagementEndpoint.java
+++
b/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/ManagementEndpoint.java
@@ -17,7 +17,6 @@
package org.apache.servicecomb.solution.basic.integration;
import java.util.Map;
-import java.util.Set;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
@@ -43,15 +42,11 @@ public interface ManagementEndpoint {
boolean health(@QueryParam("instanceId") String instanceId,
@QueryParam("registryName") String registryName);
/**
- * Schema ids of this instance.
+ * Schemas of this instance.
*
* This api is for internal schema loading usage.
*/
- @GET
- @Path("/schema/ids")
- Set<String> schemaIds();
-
@POST
@Path("/schema/contents")
- Map<String, String> schemaContents(Set<String> schemaIds);
+ Map<String, String> schemaContents();
}
diff --git
a/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/ManagementEndpointImpl.java
b/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/ManagementEndpointImpl.java
index c68b13571..758136be2 100644
---
a/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/ManagementEndpointImpl.java
+++
b/solutions/solution-basic/src/main/java/org/apache/servicecomb/solution/basic/integration/ManagementEndpointImpl.java
@@ -18,21 +18,15 @@ package org.apache.servicecomb.solution.basic.integration;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import org.apache.commons.lang3.StringUtils;
-import org.apache.servicecomb.config.BootStrapProperties;
import org.apache.servicecomb.core.provider.LocalOpenAPIRegistry;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.apache.servicecomb.registry.RegistrationManager;
import org.apache.servicecomb.swagger.SwaggerUtils;
-import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
-import org.springframework.util.CollectionUtils;
import io.swagger.v3.oas.models.OpenAPI;
-import jakarta.ws.rs.core.Response.Status;
@RestSchema(schemaId = ManagementEndpoint.NAME, schemaInterface =
ManagementEndpoint.class)
public class ManagementEndpointImpl implements ManagementEndpoint {
@@ -40,8 +34,6 @@ public class ManagementEndpointImpl implements
ManagementEndpoint {
private LocalOpenAPIRegistry localOpenAPIRegistry;
- private Environment environment;
-
@Autowired
public void setRegistrationManager(RegistrationManager registrationManager) {
this.registrationManager = registrationManager;
@@ -52,11 +44,6 @@ public class ManagementEndpointImpl implements
ManagementEndpoint {
this.localOpenAPIRegistry = localOpenAPIRegistry;
}
- @Autowired
- public void setEnvironment(Environment environment) {
- this.environment = environment;
- }
-
@Override
public boolean health(String instanceId, String registryName) {
String mySelf = registrationManager.getInstanceId(registryName);
@@ -67,33 +54,10 @@ public class ManagementEndpointImpl implements
ManagementEndpoint {
}
@Override
- public Set<String> schemaIds() {
- return
localOpenAPIRegistry.getSchemaIds(BootStrapProperties.readApplication(environment),
- BootStrapProperties.readServiceName(environment));
- }
-
- @Override
- public Map<String, String> schemaContents(Set<String> schemaIds) {
- if (CollectionUtils.isEmpty(schemaIds)) {
- throw new InvocationException(Status.BAD_REQUEST, "invalid schemaIds
parameter.");
- }
- checkValid(schemaIds);
-
- Map<String, OpenAPI> apis =
localOpenAPIRegistry.loadOpenAPI(BootStrapProperties.readApplication(environment),
- BootStrapProperties.readServiceName(environment), schemaIds);
- if (apis.size() != schemaIds.size()) {
- throw new InvocationException(Status.BAD_REQUEST, "Not exists schemaIds
parameter.");
- }
+ public Map<String, String> schemaContents() {
+ Map<String, OpenAPI> apis = localOpenAPIRegistry.loadOpenAPI();
Map<String, String> result = new HashMap<>(apis.size());
apis.forEach((k, v) -> result.put(k, SwaggerUtils.swaggerToString(v)));
return result;
}
-
- private void checkValid(Set<String> schemaIds) {
- for (String schemaId : schemaIds) {
- if (schemaId.contains("/") || schemaId.contains("\\") ||
schemaId.contains("..")) {
- throw new InvocationException(Status.BAD_REQUEST, "invalid schemaIds
parameter.");
- }
- }
- }
}
diff --git
a/solutions/solution-basic/src/test/java/org/apache/servicecomb/solution/basic/integration/TestManagementEndpointImpl.java
b/solutions/solution-basic/src/test/java/org/apache/servicecomb/solution/basic/integration/TestManagementEndpointImpl.java
index 71164bc2a..02e060251 100644
---
a/solutions/solution-basic/src/test/java/org/apache/servicecomb/solution/basic/integration/TestManagementEndpointImpl.java
+++
b/solutions/solution-basic/src/test/java/org/apache/servicecomb/solution/basic/integration/TestManagementEndpointImpl.java
@@ -16,31 +16,6 @@
*/
package org.apache.servicecomb.solution.basic.integration;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
public class TestManagementEndpointImpl {
- @Test
- public void testSchemaContentsParameterNotValid() {
- ManagementEndpoint endpoint = new ManagementEndpointImpl();
- Assertions.assertThrows(InvocationException.class, () ->
endpoint.schemaContents(null));
- Assertions.assertThrows(InvocationException.class, () ->
endpoint.schemaContents(Collections.emptySet()));
- final Set<String> ids = new HashSet<>();
- ids.add("33/33");
- Assertions.assertThrows(InvocationException.class, () ->
endpoint.schemaContents(ids));
- final Set<String> ids2 = new HashSet<>();
- ids2.add("eeee\\");
- Assertions.assertThrows(InvocationException.class, () ->
endpoint.schemaContents(ids2));
- final Set<String> ids3 = new HashSet<>();
- ids3.add("eeee3333..sss");
- Assertions.assertThrows(InvocationException.class, () ->
endpoint.schemaContents(ids3));
- final Set<String> ids4 = new HashSet<>();
- ids4.add("eeee3333/sss4");
- Assertions.assertThrows(InvocationException.class, () ->
endpoint.schemaContents(ids4));
- }
+
}