use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class LocalRegistryStore method addInstances.
private void addInstances(RegistryBean bean, Microservice microservice) {
Map<String, MicroserviceInstance> instanceMap = new ConcurrentHashMap<>();
microserviceInstanceMap.put(microservice.getServiceId(), instanceMap);
for (Instance item : bean.getInstances().getInstances()) {
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId(UUID.randomUUID().toString());
instance.setEndpoints(item.getEndpoints());
instance.setServiceId(microservice.getServiceId());
instanceMap.put(instance.getInstanceId(), instance);
}
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class ServiceCenterRegistration method updateMicroserviceInstanceStatus.
@Override
public boolean updateMicroserviceInstanceStatus(MicroserviceInstanceStatus status) {
RegistryUtils.executeOnEachServiceRegistry(sr -> new SuppressedRunnableWrapper(() -> {
MicroserviceInstance selfInstance = sr.getMicroserviceInstance();
sr.getServiceRegistryClient().updateMicroserviceInstanceStatus(selfInstance.getServiceId(), selfInstance.getInstanceId(), status);
}).run());
return true;
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class MicroserviceStore method findServiceInstances.
public MicroserviceInstances findServiceInstances(String revision) {
if (instancesRevision.equals(revision)) {
return new MicroserviceInstances().setRevision(instancesRevision).setNeedRefresh(false);
}
List<MicroserviceInstance> instances = instancesById.values().stream().map(InstanceStore::getInstance).collect(Collectors.toList());
FindInstancesResponse response = new FindInstancesResponse().setInstances(instances);
return new MicroserviceInstances().setRevision(instancesRevision).setInstancesResponse(response);
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class TestMicroserviceInstanceRegisterTask method setup.
@Before
public void setup() {
ConfigUtil.installDynamicConfig();
eventBus = new EventBus();
taskList = new ArrayList<>();
eventBus.register(new Object() {
@Subscribe
public void onEvent(MicroserviceInstanceRegisterTask task) {
taskList.add(task);
}
});
microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceName("ms");
microservice.setServiceId("serviceId");
microservice.setInstance(new MicroserviceInstance());
HealthCheck healthCheck = new HealthCheck();
healthCheck.setMode(HealthCheckMode.HEARTBEAT);
microservice.getInstance().setHealthCheck(healthCheck);
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class TestMicroserviceInstanceRegisterTask method registerHostSuccess.
@Test
public void registerHostSuccess() {
MicroserviceInstance instance = microservice.getInstance();
new Expectations(RegistrationManager.class) {
{
RegistrationManager.getPublishHostName();
result = "hostName";
}
};
new Expectations(RegistryUtils.class) {
{
serviceRegistryConfig.isPreferIpAddress();
result = false;
serviceRegistryConfig.getHeartbeatInterval();
result = 10;
serviceRegistryConfig.getResendHeartBeatTimes();
result = 20;
srClient.registerMicroserviceInstance(instance);
result = "instanceId";
}
};
MicroserviceInstanceRegisterTask registerTask = new MicroserviceInstanceRegisterTask(eventBus, serviceRegistryConfig, srClient, microservice);
registerTask.taskStatus = TaskStatus.READY;
registerTask.run();
Assert.assertEquals(true, registerTask.isRegistered());
Assert.assertEquals("hostName", instance.getHostName());
Assert.assertEquals("instanceId", instance.getInstanceId());
Assert.assertEquals(10, instance.getHealthCheck().getInterval());
Assert.assertEquals(20, instance.getHealthCheck().getTimes());
Assert.assertEquals(1, taskList.size());
}
Aggregations