Search in sources :

Example 1 with Version

use of org.apache.servicecomb.foundation.common.Version in project java-chassis by ServiceComb.

the class VersionRuleRangeParser method parse.

@Override
public VersionRule parse(String strVersionRule) {
    int pos = strVersionRule.indexOf('-');
    if (pos <= 0 || pos == strVersionRule.length() - 1) {
        return null;
    }
    Version from = new Version(strVersionRule.substring(0, pos));
    Version to = new Version(strVersionRule.substring(pos + 1));
    return new RangeVersionRule(from.getVersion() + "-" + to.getVersion(), from, to);
}
Also used : Version(org.apache.servicecomb.foundation.common.Version)

Example 2 with Version

use of org.apache.servicecomb.foundation.common.Version in project java-chassis by ServiceComb.

the class MicroserviceFactory method createMicroserviceFromConfiguration.

private Microservice createMicroserviceFromConfiguration(Configuration configuration) {
    Microservice microservice = new Microservice();
    EnvironmentConfiguration envConfig = new EnvironmentConfiguration();
    if (!StringUtils.isEmpty(envConfig.getString(APP_MAPPING)) && !StringUtils.isEmpty(envConfig.getString(envConfig.getString(APP_MAPPING)))) {
        microservice.setAppId(envConfig.getString(envConfig.getString(APP_MAPPING)));
    } else {
        microservice.setAppId(BootStrapProperties.readApplication(configuration));
    }
    if (!StringUtils.isEmpty(envConfig.getString(SERVICE_MAPPING)) && !StringUtils.isEmpty(envConfig.getString(envConfig.getString(SERVICE_MAPPING)))) {
        microservice.setServiceName(envConfig.getString(envConfig.getString(SERVICE_MAPPING)));
    } else {
        microservice.setServiceName(BootStrapProperties.readServiceName(configuration));
    }
    String version;
    if (!StringUtils.isEmpty(envConfig.getString(VERSION_MAPPING)) && !StringUtils.isEmpty(envConfig.getString(envConfig.getString(VERSION_MAPPING)))) {
        version = envConfig.getString(envConfig.getString(VERSION_MAPPING));
    } else {
        version = BootStrapProperties.readServiceVersion(configuration);
    }
    // just check version format
    new Version(version);
    microservice.setVersion(version);
    microservice.setDescription(BootStrapProperties.readServiceDescription(configuration));
    microservice.setLevel(BootStrapProperties.readServiceRole(configuration));
    microservice.setPaths(ConfigurePropertyUtils.getMicroservicePaths(configuration));
    Map<String, String> propertiesMap = MicroservicePropertiesLoader.INSTANCE.loadProperties(configuration);
    microservice.setProperties(propertiesMap);
    microservice.setEnvironment(BootStrapProperties.readServiceEnvironment(configuration));
    // set alias name when allow cross app
    if (microservice.allowCrossApp()) {
        microservice.setAlias(Microservice.generateAbsoluteMicroserviceName(microservice.getAppId(), microservice.getServiceName()));
    }
    microservice.setFramework(createFramework());
    microservice.setRegisterBy(CONFIG_DEFAULT_REGISTER_BY);
    return microservice;
}
Also used : EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) Version(org.apache.servicecomb.foundation.common.Version)

Example 3 with Version

use of org.apache.servicecomb.foundation.common.Version in project java-chassis by ServiceComb.

the class TestVersion method testHashCode.

@Test
public void testHashCode() {
    version = new Version(s1, s1, s1, s1);
    Assert.assertEquals(version.getVersion().hashCode(), version.hashCode());
}
Also used : Version(org.apache.servicecomb.foundation.common.Version) Test(org.junit.Test)

Example 4 with Version

use of org.apache.servicecomb.foundation.common.Version in project java-chassis by ServiceComb.

the class TestVersion method constructFromStringInvalidBuildNegative.

@Test
public void constructFromStringInvalidBuildNegative() {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(Matchers.is("build \"-1\" can not be negative, version \"1.1.1.-1\"."));
    version = new Version("1.1.1.-1");
}
Also used : Version(org.apache.servicecomb.foundation.common.Version) Test(org.junit.Test)

Example 5 with Version

use of org.apache.servicecomb.foundation.common.Version in project java-chassis by ServiceComb.

the class TestVersion method constructFromStringInvalidPatchDot.

@Test
public void constructFromStringInvalidPatchDot() {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(Matchers.is("Invalid build \"\", version \"1.1.1.\"."));
    expectedException.expectCause(Matchers.instanceOf(NumberFormatException.class));
    version = new Version("1.1.1.");
}
Also used : Version(org.apache.servicecomb.foundation.common.Version) Test(org.junit.Test)

Aggregations

Version (org.apache.servicecomb.foundation.common.Version)28 Test (org.junit.Test)20 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)4 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)3 ArrayList (java.util.ArrayList)2 MicroserviceVersion (org.apache.servicecomb.registry.consumer.MicroserviceVersion)2 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Mock (mockit.Mock)1 MockUp (mockit.MockUp)1 EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)1 DiscoveryManager (org.apache.servicecomb.registry.DiscoveryManager)1 FindInstancesResponse (org.apache.servicecomb.registry.api.registry.FindInstancesResponse)1 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)1 AppManager (org.apache.servicecomb.registry.consumer.AppManager)1 MicroserviceVersionRule (org.apache.servicecomb.registry.consumer.MicroserviceVersionRule)1 MicroserviceVersions (org.apache.servicecomb.registry.consumer.MicroserviceVersions)1