Search in sources :

Example 31 with ServiceMetadata

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);
}
Also used : NamingMetadataOperateService(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService) Service(com.alibaba.nacos.naming.core.v2.pojo.Service)

Example 32 with ServiceMetadata

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));
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) Test(org.junit.Test) BaseTest(com.alibaba.nacos.naming.BaseTest)

Example 33 with ServiceMetadata

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);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 34 with ServiceMetadata

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());
    }
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Instance(com.alibaba.nacos.api.naming.pojo.Instance) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 35 with ServiceMetadata

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());
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Subscriber(com.alibaba.nacos.naming.pojo.Subscriber) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) Test(org.junit.Test)

Aggregations

ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)33 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)18 Test (org.junit.Test)13 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)11 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)8 NacosException (com.alibaba.nacos.api.exception.NacosException)7 Secured (com.alibaba.nacos.auth.annotation.Secured)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Instance (com.alibaba.nacos.api.naming.pojo.Instance)5 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)4 PushDataWrapper (com.alibaba.nacos.naming.push.v2.PushDataWrapper)4 Before (org.junit.Before)4 ServiceDetailInfo (com.alibaba.nacos.naming.pojo.ServiceDetailInfo)3 HashMap (java.util.HashMap)3 PutMapping (org.springframework.web.bind.annotation.PutMapping)3 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)2 Serializer (com.alibaba.nacos.consistency.Serializer)2 Cluster (com.alibaba.nacos.naming.core.Cluster)2 NamingMetadataManager (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)2 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)2