use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.
the class ServiceOperatorV2Impl method create.
@Override
public void create(String namespaceId, String serviceName, ServiceMetadata metadata) throws NacosException {
Service service = getServiceFromGroupedServiceName(namespaceId, serviceName, metadata.isEphemeral());
create(service, metadata);
}
use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.
the class ServiceOperatorV1ImplTest method testUpdate.
@Test
public void testUpdate() throws NacosException {
String serviceName = "DEFAULT_GROUP@@order-service";
serviceManager.createEmptyService(TEST_NAMESPACE, serviceName, true);
com.alibaba.nacos.naming.core.v2.pojo.Service service = Service.newService(TEST_NAMESPACE, NamingUtils.getGroupName(serviceName), NamingUtils.getServiceName(serviceName));
ServiceMetadata metadata = new ServiceMetadata();
metadata.setProtectThreshold(0.1F);
serviceOperatorV1Impl.update(service, metadata);
assertThat(serviceManager.getService(TEST_NAMESPACE, serviceName).getProtectThreshold(), is(0.1F));
}
use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.
the class ServiceQueryRequestHandler method handle.
@Override
@Secured(action = ActionTypes.READ)
public QueryServiceResponse handle(ServiceQueryRequest request, RequestMeta meta) throws NacosException {
String namespaceId = request.getNamespace();
String groupName = request.getGroupName();
String serviceName = request.getServiceName();
Service service = Service.newService(namespaceId, groupName, serviceName);
String cluster = null == request.getCluster() ? "" : request.getCluster();
boolean healthyOnly = request.isHealthyOnly();
ServiceInfo result = serviceStorage.getData(service);
ServiceMetadata serviceMetadata = metadataManager.getServiceMetadata(service).orElse(null);
result = ServiceUtil.selectInstancesWithHealthyProtection(result, serviceMetadata, cluster, healthyOnly, true, meta.getClientIp());
return QueryServiceResponse.buildSuccessResponse(result);
}
use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.
the class CatalogServiceV2ImplTest method testPageListService.
@Test
public void testPageListService() {
try {
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setHosts(Collections.singletonList(new Instance()));
Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
ServiceMetadata metadata = new ServiceMetadata();
metadata.setProtectThreshold(0.75F);
Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(metadata));
ObjectNode obj = (ObjectNode) catalogServiceV2Impl.pageListService("A", "B", "C", 1, 10, null, false);
Assert.assertEquals(1, obj.get(FieldsConstants.COUNT).asInt());
} catch (NacosException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.
the class InstanceOperatorClientImplTest method testListInstance.
@Test
public void testListInstance() {
Mockito.when(pushService.canEnablePush(Mockito.anyString())).thenReturn(true);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setGroupName("DEFAULT_GROUP");
serviceInfo.setName("B");
Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
ServiceMetadata metadata = new ServiceMetadata();
Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(metadata));
Subscriber subscriber = new Subscriber("2.2.2.2", "", "app", "1.1.1.1", "A", "B", 8848);
instanceOperatorClient.listInstance("A", "B", subscriber, "C", true);
Mockito.verify(clientOperationService).subscribeService(Mockito.any(), Mockito.any(), Mockito.anyString());
}
Aggregations