Search in sources :

Example 6 with MicroserviceStore

use of org.apache.servicecomb.registry.lightweight.store.MicroserviceStore in project java-chassis by ServiceComb.

the class StoreService method addMicroserviceAndInstance.

private CompletableFuture<InstanceStore> addMicroserviceAndInstance(Endpoint endpoint, RegisterRequest request) {
    return discoveryClient.getInfoAsync(endpoint, request.getServiceId()).thenApply(info -> {
        info.getMicroservice().getSchemaMap().putAll(info.getSchemasById());
        MicroserviceStore microserviceStore = store.addMicroservice(info.getMicroservice(), request.getSchemasSummary());
        InstanceStore instanceStore = doAddInstance(microserviceStore, info.getInstance());
        LOGGER.info("add microservice and instance, serviceId={}, instanceId={}, endpoints={}", request.getServiceId(), request.getInstanceId(), request.getEndpoints());
        return instanceStore;
    });
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore)

Example 7 with MicroserviceStore

use of org.apache.servicecomb.registry.lightweight.store.MicroserviceStore in project java-chassis by ServiceComb.

the class StoreService method addInstance.

private CompletableFuture<InstanceStore> addInstance(RegisterRequest request) {
    Endpoint endpoint = request.selectFirstEndpoint();
    if (endpoint == null) {
        return AsyncUtils.completeExceptionally(new RegisterException("can not select endpoint"));
    }
    MicroserviceStore microserviceStore = this.store.findMicroserviceStore(request.getServiceId());
    if (microserviceStore == null) {
        return addMicroserviceAndInstance(endpoint, request);
    }
    return checkSchemaSummary(request, microserviceStore).thenCompose(v -> discoveryClient.getInstanceAsync(endpoint, request.getServiceId())).thenApply(instance -> addInstance(microserviceStore, instance));
}
Also used : EventBus(com.google.common.eventbus.EventBus) MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore) Component(org.springframework.stereotype.Component) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Logger(org.slf4j.Logger) Store(org.apache.servicecomb.registry.lightweight.store.Store) AsyncUtils(org.apache.servicecomb.foundation.common.utils.AsyncUtils) Duration(java.time.Duration) InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Endpoint(org.apache.servicecomb.core.Endpoint) Endpoint(org.apache.servicecomb.core.Endpoint) MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore)

Example 8 with MicroserviceStore

use of org.apache.servicecomb.registry.lightweight.store.MicroserviceStore in project incubator-servicecomb-java-chassis by apache.

the class StoreService method addMicroserviceAndInstance.

private CompletableFuture<InstanceStore> addMicroserviceAndInstance(Endpoint endpoint, RegisterRequest request) {
    return discoveryClient.getInfoAsync(endpoint, request.getServiceId()).thenApply(info -> {
        info.getMicroservice().getSchemaMap().putAll(info.getSchemasById());
        MicroserviceStore microserviceStore = store.addMicroservice(info.getMicroservice(), request.getSchemasSummary());
        InstanceStore instanceStore = doAddInstance(microserviceStore, info.getInstance());
        LOGGER.info("add microservice and instance, serviceId={}, instanceId={}, endpoints={}", request.getServiceId(), request.getInstanceId(), request.getEndpoints());
        return instanceStore;
    });
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore)

Aggregations

MicroserviceStore (org.apache.servicecomb.registry.lightweight.store.MicroserviceStore)8 InstanceStore (org.apache.servicecomb.registry.lightweight.store.InstanceStore)6 EventBus (com.google.common.eventbus.EventBus)2 Duration (java.time.Duration)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Endpoint (org.apache.servicecomb.core.Endpoint)2 AsyncUtils (org.apache.servicecomb.foundation.common.utils.AsyncUtils)2 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)2 Store (org.apache.servicecomb.registry.lightweight.store.Store)2 Test (org.junit.jupiter.api.Test)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Component (org.springframework.stereotype.Component)2