Search in sources :

Example 1 with MicroserviceStore

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

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 2 with MicroserviceStore

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

the class StoreService method registerSelf.

public void registerSelf(Self self) {
    MicroserviceStore microserviceStore = store.addMicroservice(self.getMicroservice(), self.getSchemasSummary());
    addInstance(microserviceStore, self.getInstance());
}
Also used : MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore)

Example 3 with MicroserviceStore

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

the class StoreServiceTest method should_register_and_notify_when_schema_changed_and_has_not_existing_instance.

@Test
void should_register_and_notify_when_schema_changed_and_has_not_existing_instance() {
    should_register_microservice_and_instance_when_both_not_exist();
    MicroserviceStore microserviceStore = store.findMicroserviceStore(self.getServiceId());
    assertThat(microserviceStore.hasInstance()).isTrue();
    store.deleteInstance(self.getServiceId(), self.getInstanceId());
    assertThat(microserviceStore.hasInstance()).isFalse();
    eventBus.register(this);
    RegisterRequest request = self.buildRegisterRequest().setSchemasSummary("new summary");
    InstanceStore instanceStore = service.register(request);
    assertThat(microserviceStore.isSchemaChanged("new summary")).isFalse();
    assertThat(instanceStore.getInstance()).isSameAs(self.getInstance());
    assertThat(schemaChangedEvent.getMicroservice()).isSameAs(self.getMicroservice());
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore) Test(org.junit.jupiter.api.Test)

Example 4 with MicroserviceStore

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

the class StoreService method registerSelf.

public void registerSelf(Self self) {
    MicroserviceStore microserviceStore = store.addMicroservice(self.getMicroservice(), self.getSchemasSummary());
    addInstance(microserviceStore, self.getInstance());
}
Also used : MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore)

Example 5 with MicroserviceStore

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

the class StoreServiceTest method should_register_and_notify_when_schema_changed_and_has_not_existing_instance.

@Test
void should_register_and_notify_when_schema_changed_and_has_not_existing_instance() {
    should_register_microservice_and_instance_when_both_not_exist();
    MicroserviceStore microserviceStore = store.findMicroserviceStore(self.getServiceId());
    assertThat(microserviceStore.hasInstance()).isTrue();
    store.deleteInstance(self.getServiceId(), self.getInstanceId());
    assertThat(microserviceStore.hasInstance()).isFalse();
    eventBus.register(this);
    RegisterRequest request = self.buildRegisterRequest().setSchemasSummary("new summary");
    InstanceStore instanceStore = service.register(request);
    assertThat(microserviceStore.isSchemaChanged("new summary")).isFalse();
    assertThat(instanceStore.getInstance()).isSameAs(self.getInstance());
    assertThat(schemaChangedEvent.getMicroservice()).isSameAs(self.getMicroservice());
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) MicroserviceStore(org.apache.servicecomb.registry.lightweight.store.MicroserviceStore) Test(org.junit.jupiter.api.Test)

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