Search in sources :

Example 1 with BasePath

use of org.apache.servicecomb.registry.api.registry.BasePath in project java-chassis by ServiceComb.

the class ProducerBootListener method saveBasePaths.

// just compatible to old 3rd components, servicecomb not use it......
private void saveBasePaths(MicroserviceMeta microserviceMeta) {
    if (!DynamicPropertyFactory.getInstance().getBooleanProperty(DefinitionConst.REGISTER_SERVICE_PATH, false).get()) {
        return;
    }
    String urlPrefix = ClassLoaderScopeContext.getClassLoaderScopeProperty(DefinitionConst.URL_PREFIX);
    Map<String, BasePath> basePaths = new LinkedHashMap<>();
    for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas().values()) {
        Swagger swagger = schemaMeta.getSwagger();
        String basePath = swagger.getBasePath();
        if (StringUtils.isNotEmpty(urlPrefix) && !basePath.startsWith(urlPrefix)) {
            basePath = urlPrefix + basePath;
        }
        if (StringUtils.isNotEmpty(basePath)) {
            BasePath basePathObj = new BasePath();
            basePathObj.setPath(basePath);
            basePaths.put(basePath, basePathObj);
        }
    }
    RegistrationManager.INSTANCE.addBasePath(basePaths.values());
}
Also used : SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) Swagger(io.swagger.models.Swagger) BasePath(org.apache.servicecomb.registry.api.registry.BasePath) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with BasePath

use of org.apache.servicecomb.registry.api.registry.BasePath in project java-chassis by ServiceComb.

the class ConfigurePropertyUtils method getMicroservicePaths.

public static List<BasePath> getMicroservicePaths(Configuration configuration) {
    List<Object> configPaths = BootStrapProperties.readServicePaths(configuration);
    List<BasePath> basePaths = DatabindCodec.mapper().convertValue(configPaths, TypeFactory.defaultInstance().constructCollectionType(List.class, BasePath.class));
    for (BasePath basePath : basePaths) {
        basePath.setPath(buildPath(basePath.getPath()));
    }
    return basePaths;
}
Also used : BasePath(org.apache.servicecomb.registry.api.registry.BasePath) List(java.util.List)

Example 3 with BasePath

use of org.apache.servicecomb.registry.api.registry.BasePath in project java-chassis by ServiceComb.

the class TestMicroService method initMicroservice.

private void initMicroservice() {
    oMicroservice.setAppId("testAppID");
    oMicroservice.setDescription("This is the test");
    oMicroservice.setLevel("INFO");
    oMicroservice.setServiceId("testServiceID");
    oMicroservice.setServiceName("testServiceName");
    oMicroservice.setStatus(MicroserviceInstanceStatus.DOWN.toString());
    oMicroservice.setVersion("1.0.0");
    oMapProperties.put("proxy", "fakeProxy");
    oListSchemas.add("testSchemas");
    oMicroservice.setProperties(oMapProperties);
    oMicroservice.setSchemas(oListSchemas);
    oMicroservice.getPaths().add(new BasePath());
    Framework framework = new Framework();
    framework.setName("JAVA-CHASSIS");
    framework.setVersion("x.x.x");
    oMicroservice.setFramework(framework);
    oMicroservice.setRegisterBy("SDK");
    oMicroservice.setEnvironment("development");
}
Also used : BasePath(org.apache.servicecomb.registry.api.registry.BasePath) Framework(org.apache.servicecomb.registry.api.registry.Framework)

Example 4 with BasePath

use of org.apache.servicecomb.registry.api.registry.BasePath in project java-chassis by ServiceComb.

the class TestConfigurePropertyUtils method testGetPropertiesWithPrefix.

@Test
public void testGetPropertiesWithPrefix() {
    ClassLoaderScopeContext.clearClassLoaderScopeProperty();
    Configuration configuration = ConfigUtil.createLocalConfig();
    String prefix = "service_description.properties";
    Map<String, String> expectedMap = new HashMap<>();
    expectedMap.put("key1", "value1");
    expectedMap.put("key2", "value2");
    Assert.assertEquals(expectedMap, ConfigurePropertyUtils.getPropertiesWithPrefix(configuration, prefix));
    List<BasePath> paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
    Assert.assertEquals(2, paths.size());
    Assert.assertEquals(paths.get(0).getPath(), "/test1/testpath");
    Assert.assertEquals(paths.get(0).getProperty().get("checksession"), "false");
    ClassLoaderScopeContext.setClassLoaderScopeProperty(DefinitionConst.URL_PREFIX, "/webroot");
    paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
    Assert.assertEquals(2, paths.size());
    Assert.assertEquals(paths.get(0).getPath(), "/webroot/test1/testpath");
    Assert.assertEquals(paths.get(0).getProperty().get("checksession"), "false");
    ClassLoaderScopeContext.clearClassLoaderScopeProperty();
}
Also used : Configuration(org.apache.commons.configuration.Configuration) HashMap(java.util.HashMap) BasePath(org.apache.servicecomb.registry.api.registry.BasePath) Test(org.junit.Test)

Aggregations

BasePath (org.apache.servicecomb.registry.api.registry.BasePath)4 Swagger (io.swagger.models.Swagger)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Configuration (org.apache.commons.configuration.Configuration)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 Framework (org.apache.servicecomb.registry.api.registry.Framework)1 Test (org.junit.Test)1