Search in sources :

Example 36 with Microservice

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

the class TestRegistry method testDelegate.

@Test
public void testDelegate() {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    serviceRegistry.run();
    RegistryUtils.setServiceRegistry(serviceRegistry);
    Assert.assertEquals(serviceRegistry, RegistryUtils.getServiceRegistry());
    Assert.assertEquals(serviceRegistry.getServiceRegistryClient(), RegistryUtils.getServiceRegistryClient());
    Assert.assertEquals(serviceRegistry.getInstanceCacheManager(), RegistryUtils.getInstanceCacheManager());
    Microservice microservice = RegistryUtils.getMicroservice();
    Assert.assertEquals(serviceRegistry.getMicroservice(), microservice);
    Assert.assertEquals(serviceRegistry.getMicroserviceInstance(), RegistryUtils.getMicroserviceInstance());
    List<MicroserviceInstance> instanceList = RegistryUtils.findServiceInstance("default", "default", "0.0.1");
    Assert.assertEquals(1, instanceList.size());
    Assert.assertEquals(RegistryUtils.getMicroservice().getServiceId(), instanceList.get(0).getServiceId());
    MicroserviceInstances microserviceInstances = RegistryUtils.findServiceInstances("default", "default", "0.0.1", "0");
    List<MicroserviceInstance> instanceLists = microserviceInstances.getInstancesResponse().getInstances();
    Assert.assertEquals(1, instanceLists.size());
    Assert.assertEquals(RegistryUtils.getMicroservice().getServiceId(), instanceLists.get(0).getServiceId());
    Map<String, String> properties = new HashMap<>();
    properties.put("k", "v");
    RegistryUtils.updateInstanceProperties(properties);
    Assert.assertEquals(properties, RegistryUtils.getMicroserviceInstance().getProperties());
    Assert.assertEquals(microservice, RegistryUtils.getMicroservice(microservice.getServiceId()));
    Assert.assertEquals("default", RegistryUtils.getAppId());
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) HashMap(java.util.HashMap) MicroserviceInstances(org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 37 with Microservice

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

the class LocalServiceRegistryClientImpl method findServiceInstances.

@Override
public MicroserviceInstances findServiceInstances(String selfMicroserviceId, String appId, String serviceName, String strVersionRule, String revision) {
    int currentRevision = this.revision.get();
    List<MicroserviceInstance> allInstances = new ArrayList<>();
    MicroserviceInstances microserviceInstances = new MicroserviceInstances();
    FindInstancesResponse response = new FindInstancesResponse();
    if (revision != null && currentRevision == Integer.parseInt(revision)) {
        microserviceInstances.setNeedRefresh(false);
        return microserviceInstances;
    }
    microserviceInstances.setRevision(String.valueOf(currentRevision));
    VersionRule versionRule = VersionRuleUtils.getOrCreate(strVersionRule);
    Microservice latestMicroservice = findLatest(appId, serviceName, versionRule);
    if (latestMicroservice == null) {
        response.setInstances(allInstances);
        microserviceInstances.setInstancesResponse(response);
        return microserviceInstances;
    }
    Version latestVersion = VersionUtils.getOrCreate(latestMicroservice.getVersion());
    for (Entry<String, Microservice> entry : microserviceIdMap.entrySet()) {
        Microservice microservice = entry.getValue();
        if (!isSameMicroservice(microservice, appId, serviceName)) {
            continue;
        }
        Version version = VersionUtils.getOrCreate(entry.getValue().getVersion());
        if (!versionRule.isMatch(version, latestVersion)) {
            continue;
        }
        Map<String, MicroserviceInstance> instances = microserviceInstanceMap.get(entry.getValue().getServiceId());
        allInstances.addAll(instances.values());
    }
    response.setInstances(allInstances);
    microserviceInstances.setInstancesResponse(response);
    return microserviceInstances;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Version(org.apache.servicecomb.serviceregistry.version.Version) MicroserviceInstances(org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) FindInstancesResponse(org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse) VersionRule(org.apache.servicecomb.serviceregistry.version.VersionRule)

Example 38 with Microservice

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

the class LocalServiceRegistryClientImpl method getMicroserviceId.

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

Example 39 with Microservice

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

the class WriteFileInitializer method startOutput.

public void startOutput() {
    if (StringUtils.isEmpty(filePrefix)) {
        Microservice microservice = RegistryUtils.getMicroservice();
        filePrefix = microservice.getAppId() + "." + microservice.getServiceName();
    }
    if (StringUtils.isEmpty(hostName)) {
        hostName = NetUtils.getHostName();
        if (StringUtils.isEmpty(hostName)) {
            hostName = NetUtils.getHostAddress();
        }
    }
    formatter = new SimpleFileContentFormatter(hostName, filePrefix);
    final Runnable poller = this::run;
    Executors.newScheduledThreadPool(1).scheduleWithFixedDelay(poller, 0, metricPoll, MILLISECONDS);
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice)

Example 40 with Microservice

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

the class ProducerProviderManager method init.

public void init() throws Exception {
    for (ProducerProvider provider : producerProviderList) {
        provider.init();
    }
    Microservice microservice = RegistryUtils.getMicroservice();
    MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(microservice);
    for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas()) {
        String content = SchemaUtils.swaggerToString(schemaMeta.getSwagger());
        microservice.addSchema(schemaMeta.getSchemaId(), content);
    }
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) ProducerProvider(org.apache.servicecomb.core.ProducerProvider) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta)

Aggregations

Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)47 Test (org.junit.Test)24 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)15 Expectations (mockit.Expectations)11 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 EventBus (com.google.common.eventbus.EventBus)4 Before (org.junit.Before)4 Subscribe (com.google.common.eventbus.Subscribe)3 MockUp (mockit.MockUp)3 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)3 MicroserviceFactory (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory)3 MicroserviceInstances (org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances)3 Endpoint (org.apache.servicecomb.core.Endpoint)2 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)2 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)2 Version (org.apache.servicecomb.serviceregistry.version.Version)2 VersionRule (org.apache.servicecomb.serviceregistry.version.VersionRule)2 Handler (io.vertx.core.Handler)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1