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());
}
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;
}
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());
}
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;
});
}
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));
}
Aggregations