use of com.alibaba.nacos.naming.core.v2.index.ServiceStorage in project nacos by alibaba.
the class DoubleWriteInstanceChangeToV1Task method getNewInstances.
private Instances getNewInstances() {
Instances result = new Instances();
ServiceStorage serviceStorage = ApplicationUtils.getBean(ServiceStorage.class);
InstanceUpgradeHelper instanceUpgradeHelper = ApplicationUtils.getBean(InstanceUpgradeHelper.class);
long currentTimeStamp = System.currentTimeMillis();
for (Instance each : serviceStorage.getData(service).getHosts()) {
com.alibaba.nacos.naming.core.Instance instance = instanceUpgradeHelper.toV1(each);
instance.setLastBeat(currentTimeStamp);
result.getInstanceList().add(instance);
}
return result;
}
use of com.alibaba.nacos.naming.core.v2.index.ServiceStorage in project nacos by alibaba.
the class AsyncServicesCheckTask method run.
@Override
public void run() {
if (upgradeJudgement.isUseGrpcFeatures()) {
return;
}
try {
ServiceManager serviceManager = ApplicationUtils.getBean(ServiceManager.class);
ServiceStorage serviceStorage = ApplicationUtils.getBean(ServiceStorage.class);
Map<String, Service> v1Services = new HashMap<>(INITIALCAPACITY);
for (String each : serviceManager.getAllNamespaces()) {
for (Map.Entry<String, Service> entry : serviceManager.chooseServiceMap(each).entrySet()) {
v1Services.put(buildServiceKey(each, entry.getKey()), entry.getValue());
checkService(each, entry.getKey(), entry.getValue(), serviceStorage);
}
}
Map<String, com.alibaba.nacos.naming.core.v2.pojo.Service> v2Services = new HashMap<>(INITIALCAPACITY);
for (String each : com.alibaba.nacos.naming.core.v2.ServiceManager.getInstance().getAllNamespaces()) {
for (com.alibaba.nacos.naming.core.v2.pojo.Service serviceV2 : com.alibaba.nacos.naming.core.v2.ServiceManager.getInstance().getSingletons(each)) {
v2Services.put(buildServiceKey(each, serviceV2.getGroupedServiceName()), serviceV2);
}
}
// only check v2 services when upgrading.
v2Services.keySet().removeIf(v1Services::containsKey);
if (v2Services.isEmpty()) {
return;
}
if (Loggers.SRV_LOG.isDebugEnabled()) {
Loggers.SRV_LOG.debug("{} service in v2 to removed.", v2Services.size());
}
for (com.alibaba.nacos.naming.core.v2.pojo.Service service : v2Services.values()) {
deleteV2Service(service);
}
} catch (Exception e) {
Loggers.SRV_LOG.warn("async check for service error", e);
}
}
use of com.alibaba.nacos.naming.core.v2.index.ServiceStorage in project nacos by alibaba.
the class CatalogServiceV2ImplTest method setUp.
@Before
public void setUp() {
catalogServiceV2Impl = new CatalogServiceV2Impl(serviceStorage, metadataManager);
ServiceManager serviceManager = ServiceManager.getInstance();
Service service = Service.newService("A", "B", "C");
serviceManager.getSingleton(service);
}
use of com.alibaba.nacos.naming.core.v2.index.ServiceStorage in project nacos by alibaba.
the class ServiceStorageTest method testGetInstanceInfo.
@Test
public void testGetInstanceInfo() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<ServiceStorage> serviceStorageClass = ServiceStorage.class;
Method getInstanceInfo = serviceStorageClass.getDeclaredMethod("getInstanceInfo", String.class, Service.class);
getInstanceInfo.setAccessible(true);
Optional<InstancePublishInfo> optionalInstancePublishInfo = (Optional<InstancePublishInfo>) getInstanceInfo.invoke(serviceStorage, NACOS, SERVICE);
Assert.assertFalse(optionalInstancePublishInfo.isPresent());
}
use of com.alibaba.nacos.naming.core.v2.index.ServiceStorage in project nacos by alibaba.
the class ServiceStorageTest method setUp.
@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
serviceStorage = new ServiceStorage(clientServiceIndexesManager, clientManagerDelegate, switchDomain, namingMetadataManager);
Field serviceClusterIndex = ServiceStorage.class.getDeclaredField("serviceClusterIndex");
serviceClusterIndex.setAccessible(true);
ConcurrentMap<Service, Set<String>> serviceSetConcurrentMap = (ConcurrentMap<Service, Set<String>>) serviceClusterIndex.get(serviceStorage);
serviceSetConcurrentMap.put(SERVICE, new HashSet<>(Collections.singletonList(NACOS)));
Field serviceDataIndexes = ServiceStorage.class.getDeclaredField("serviceDataIndexes");
serviceDataIndexes.setAccessible(true);
ConcurrentMap<Service, ServiceInfo> infoConcurrentMap = (ConcurrentMap<Service, ServiceInfo>) serviceDataIndexes.get(serviceStorage);
infoConcurrentMap.put(SERVICE, serviceInfo);
}
Aggregations