Search in sources :

Example 1 with InstanceStore

use of org.apache.servicecomb.registry.lightweight.store.InstanceStore 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)

Example 2 with InstanceStore

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

the class StoreService method doAddInstance.

private InstanceStore doAddInstance(MicroserviceStore microserviceStore, MicroserviceInstance instance) {
    InstanceStore instanceStore = store.addInstance(microserviceStore, instance);
    eventBus.post(new RegisterInstanceEvent(microserviceStore.getMicroservice(), instance));
    return instanceStore;
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore)

Example 3 with InstanceStore

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

the class StoreService method deleteInstance.

public void deleteInstance(String action, String serviceId, String instanceId) {
    InstanceStore instanceStore = store.deleteInstance(serviceId, instanceId);
    if (instanceStore == null) {
        return;
    }
    LOGGER.info("{} instance, serviceId={}, instanceId={}, endpoints={}", action, instanceStore.getServiceId(), instanceStore.getInstanceId(), instanceStore.getEndpoints());
}
Also used : InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore)

Example 4 with InstanceStore

use of org.apache.servicecomb.registry.lightweight.store.InstanceStore 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 5 with InstanceStore

use of org.apache.servicecomb.registry.lightweight.store.InstanceStore 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)

Aggregations

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