Search in sources :

Example 56 with Microservice

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

the class LocalServiceRegistryClientImpl method getSchemas.

@Override
public Holder<List<GetSchemaResponse>> getSchemas(String microserviceId) {
    Microservice microservice = microserviceIdMap.get(microserviceId);
    if (microservice == null) {
        throw new IllegalArgumentException("Invalid serviceId, serviceId=" + microserviceId);
    }
    List<GetSchemaResponse> schemas = new ArrayList<>();
    microservice.getSchemaMap().forEach((key, val) -> {
        GetSchemaResponse schema = new GetSchemaResponse();
        schema.setSchema(val);
        schema.setSchemaId(key);
        schema.setSummary(Hashing.sha256().newHasher().putString(val, Charsets.UTF_8).hash().toString());
        schemas.add(schema);
    });
    Holder<List<GetSchemaResponse>> resultHolder = new Holder<>();
    resultHolder.setStatusCode(Status.OK.getStatusCode()).setValue(schemas);
    return resultHolder;
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Holder(org.apache.servicecomb.serviceregistry.client.http.Holder) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GetSchemaResponse(org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse)

Example 57 with Microservice

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

the class LocalServiceRegistryClientImpl method registerSchema.

@Override
public boolean registerSchema(String microserviceId, String schemaId, String schemaContent) {
    Microservice microservice = microserviceIdMap.get(microserviceId);
    if (microservice == null) {
        throw new IllegalArgumentException("Invalid serviceId, serviceId=" + microserviceId);
    }
    microservice.getSchemaMap().put(schemaId, schemaContent);
    return true;
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice)

Example 58 with Microservice

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

the class LocalServiceRegistryClientImpl method getMicroserviceId.

@Override
public String getMicroserviceId(String appId, String microserviceName, String strVersionRule, String environment) {
    VersionRule versionRule = VersionRuleUtils.getOrCreate(strVersionRule);
    Microservice latest = findLatest(appId, microserviceName, versionRule);
    return latest != null ? latest.getServiceId() : null;
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) VersionRule(org.apache.servicecomb.registry.version.VersionRule)

Example 59 with Microservice

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

the class LocalServiceRegistryClientImpl method findLatest.

protected Microservice findLatest(String appId, String serviceName, VersionRule versionRule) {
    Version latestVersion = null;
    Microservice latest = null;
    for (Entry<String, Microservice> entry : microserviceIdMap.entrySet()) {
        Microservice microservice = entry.getValue();
        if (!isSameMicroservice(microservice, appId, serviceName)) {
            continue;
        }
        Version version = VersionUtils.getOrCreate(microservice.getVersion());
        if (!versionRule.isAccept(version)) {
            continue;
        }
        if (latestVersion == null || version.compareTo(latestVersion) > 0) {
            latestVersion = version;
            latest = microservice;
        }
    }
    return latest;
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Version(org.apache.servicecomb.foundation.common.Version)

Example 60 with Microservice

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

the class TestEnvAdapterManager method testProcessMicroservice.

@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-adapter"));
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Aggregations

Microservice (org.apache.servicecomb.registry.api.registry.Microservice)86 Test (org.junit.Test)53 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)20 Expectations (mockit.Expectations)15 ArrayList (java.util.ArrayList)14 List (java.util.List)13 GetSchemaResponse (org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse)10 Holder (org.apache.servicecomb.serviceregistry.client.http.Holder)10 HashMap (java.util.HashMap)9 MicroserviceFactory (org.apache.servicecomb.registry.api.registry.MicroserviceFactory)9 Swagger (io.swagger.models.Swagger)8 Before (org.junit.Before)8 MockUp (mockit.MockUp)6 Configuration (org.apache.commons.configuration.Configuration)6 AccessController (org.apache.servicecomb.authentication.provider.AccessController)6 Subscribe (com.google.common.eventbus.Subscribe)5 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)5 EventBus (com.google.common.eventbus.EventBus)4 Version (org.apache.servicecomb.foundation.common.Version)4 HashSet (java.util.HashSet)3