use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class TestMicroserviceInstanceResponse method testMicroserviceInstanceResponse.
@Test
public void testMicroserviceInstanceResponse() {
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
MicroserviceInstanceResponse microserviceInstanceResponse = new MicroserviceInstanceResponse();
microserviceInstanceResponse.setInstance(microserviceInstance);
Assert.assertNotNull(microserviceInstanceResponse.getInstance());
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImpl method initFromData.
private void initFromData(Map<String, Object> data) {
for (Entry<String, Object> entry : data.entrySet()) {
String name = entry.getKey();
@SuppressWarnings("unchecked") List<Map<String, Object>> serviceConfigs = (List<Map<String, Object>>) entry.getValue();
for (Map<String, Object> serviceConfig : serviceConfigs) {
@SuppressWarnings("unchecked") List<Map<String, Object>> instancesConfig = (List<Map<String, Object>>) serviceConfig.get("instances");
String appId = (String) serviceConfig.get("appid");
String version = (String) serviceConfig.get("version");
String serviceId = (String) serviceConfig.get("id");
@SuppressWarnings("unchecked") List<String> schemas = (List<String>) serviceConfig.get("schemaIds");
Microservice microservice = new Microservice();
microservice.setAppId(appId == null ? BootStrapProperties.DEFAULT_APPLICATION : appId);
microservice.setServiceName(name);
microservice.setVersion(version);
microservice.setServiceId(serviceId == null ? UUID.randomUUID().toString() : serviceId);
microserviceIdMap.put(microservice.getServiceId(), microservice);
if (schemas != null) {
microservice.setSchemas(schemas);
}
Map<String, MicroserviceInstance> instanceMap = new ConcurrentHashMap<>();
for (Map<String, Object> instanceConfig : instancesConfig) {
@SuppressWarnings("unchecked") List<String> endpoints = (List<String>) instanceConfig.get("endpoints");
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId(UUID.randomUUID().toString());
instance.setEndpoints(endpoints);
instance.setServiceId(microservice.getServiceId());
instanceMap.put(instance.getInstanceId(), instance);
}
microserviceInstanceMap.put(microservice.getServiceId(), instanceMap);
}
}
if (!data.isEmpty()) {
revision.incrementAndGet();
}
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImpl method updateInstanceProperties.
@Override
public boolean updateInstanceProperties(String microserviceId, String microserviceInstanceId, Map<String, String> instanceProperties) {
Map<String, MicroserviceInstance> instanceMap = microserviceInstanceMap.get(microserviceId);
if (instanceMap == null) {
throw new IllegalArgumentException("Invalid serviceId, serviceId=" + microserviceId);
}
MicroserviceInstance microserviceInstance = instanceMap.get(microserviceInstanceId);
if (microserviceInstance == null) {
throw new IllegalArgumentException(String.format("Invalid argument. microserviceId=%s, microserviceInstanceId=%s.", microserviceId, microserviceInstanceId));
}
if (instanceProperties != null) {
microserviceInstance.getProperties().putAll(instanceProperties);
}
return true;
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImpl method findServiceInstances.
@Override
public MicroserviceInstances findServiceInstances(String selfMicroserviceId, String appId, String serviceName, String strVersionRule, String revision) {
int currentRevision = this.revision.get();
List<MicroserviceInstance> allInstances = new ArrayList<>();
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
FindInstancesResponse response = new FindInstancesResponse();
if (revision != null && currentRevision == Integer.parseInt(revision)) {
microserviceInstances.setNeedRefresh(false);
return microserviceInstances;
}
microserviceInstances.setRevision(String.valueOf(currentRevision));
VersionRule versionRule = VersionRuleUtils.getOrCreate(strVersionRule);
Microservice latestMicroservice = findLatest(appId, serviceName, versionRule);
if (latestMicroservice == null) {
microserviceInstances.setMicroserviceNotExist(true);
return microserviceInstances;
}
Version latestVersion = VersionUtils.getOrCreate(latestMicroservice.getVersion());
for (Entry<String, Microservice> entry : microserviceIdMap.entrySet()) {
Microservice microservice = entry.getValue();
if (!isSameMicroservice(microservice, appId, serviceName)) {
continue;
}
Version version = VersionUtils.getOrCreate(entry.getValue().getVersion());
if (!versionRule.isMatch(version, latestVersion)) {
continue;
}
Map<String, MicroserviceInstance> instances = microserviceInstanceMap.get(entry.getValue().getServiceId());
allInstances.addAll(instances.values());
}
response.setInstances(allInstances);
microserviceInstances.setInstancesResponse(response);
return microserviceInstances;
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImplTest method testFindServiceInstance.
@Test
public void testFindServiceInstance() {
Microservice microservice = mockRegisterMicroservice(appId, microserviceName, "1.0.0");
MicroserviceInstance instance = new MicroserviceInstance();
instance.setServiceId(microservice.getServiceId());
String instanceId = registryClient.registerMicroserviceInstance(instance);
Assert.assertNotNull(registryClient.findServiceInstance(microservice.getServiceId(), instanceId));
}
Aggregations