Search in sources :

Example 21 with Service

use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.

the class ServiceMetadataProcessor method deleteServiceMetadata.

private void deleteServiceMetadata(MetadataOperation<ServiceMetadata> op) {
    Service service = Service.newService(op.getNamespace(), op.getGroup(), op.getServiceName());
    namingMetadataManager.removeServiceMetadata(service);
    Service removed = ServiceManager.getInstance().removeSingleton(service);
    if (removed != null) {
        service = removed;
    }
    serviceStorage.removeData(service);
    doubleWriteMetadata(service, true);
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service)

Example 22 with Service

use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.

the class NamingSubscriberServiceV1ImplTest method testGetSubscribersWithServiceParam.

@Test
public void testGetSubscribersWithServiceParam() {
    Service service = Service.newService("1", "G1", "S1");
    Collection<Subscriber> actual = namingSubscriberService.getSubscribers(service);
    assertEquals(1, actual.size());
    assertSubscriber("1", "G1@@S1", actual.iterator().next());
}
Also used : Subscriber(com.alibaba.nacos.naming.pojo.Subscriber) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) Test(org.junit.Test)

Example 23 with Service

use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.

the class NamingSubscriberServiceV1ImplTest method testGetFuzzySubscribersWithServiceParam.

@Test
public void testGetFuzzySubscribersWithServiceParam() {
    Service service = Service.newService("1", "G", "S");
    Collection<Subscriber> actual = namingSubscriberService.getFuzzySubscribers(service);
    assertEquals(2, actual.size());
    assertSubscriber("1", "DEFAULT_GROUP@@S2", actual.iterator().next());
}
Also used : Subscriber(com.alibaba.nacos.naming.pojo.Subscriber) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) Test(org.junit.Test)

Example 24 with Service

use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.

the class ServiceController method create.

/**
 * Create a new service. This API will create a persistence service.
 *
 * @param namespaceId      namespace id
 * @param serviceName      service name
 * @param protectThreshold protect threshold
 * @param metadata         service metadata
 * @param selector         selector
 * @return 'ok' if success
 * @throws Exception exception
 */
@PostMapping
@Secured(action = ActionTypes.WRITE)
public String create(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam(required = false, defaultValue = "0.0F") float protectThreshold, @RequestParam(defaultValue = StringUtils.EMPTY) String metadata, @RequestParam(defaultValue = StringUtils.EMPTY) String selector) throws Exception {
    ServiceMetadata serviceMetadata = new ServiceMetadata();
    serviceMetadata.setProtectThreshold(protectThreshold);
    serviceMetadata.setSelector(parseSelector(selector));
    serviceMetadata.setExtendData(UtilsAndCommons.parseMetadata(metadata));
    serviceMetadata.setEphemeral(false);
    getServiceOperator().create(namespaceId, serviceName, serviceMetadata);
    return "ok";
}
Also used : ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) PostMapping(org.springframework.web.bind.annotation.PostMapping) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 25 with Service

use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.

the class ServiceControllerV2 method update.

/**
 * Update service.
 *
 * @param namespaceId      namespace id
 * @param serviceName      service name
 * @param protectThreshold protect threshold
 * @param metadata         service metadata
 * @param selector         selector
 * @return 'ok' if success
 * @throws Exception exception
 */
@PutMapping(value = "/{serviceName}")
@Secured(action = ActionTypes.WRITE)
public RestResult<String> update(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @PathVariable String serviceName, @RequestParam(defaultValue = Constants.DEFAULT_GROUP) String groupName, @RequestParam(required = false, defaultValue = "0.0F") float protectThreshold, @RequestParam(defaultValue = StringUtils.EMPTY) String metadata, @RequestParam(defaultValue = StringUtils.EMPTY) String selector) throws Exception {
    ServiceMetadata serviceMetadata = new ServiceMetadata();
    serviceMetadata.setProtectThreshold(protectThreshold);
    serviceMetadata.setExtendData(UtilsAndCommons.parseMetadata(metadata));
    serviceMetadata.setSelector(parseSelector(selector));
    Service service = Service.newService(namespaceId, groupName, serviceName);
    serviceOperatorV2.update(service, serviceMetadata);
    return RestResultUtils.success("ok");
}
Also used : 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) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Aggregations

Service (com.alibaba.nacos.naming.core.v2.pojo.Service)75 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)20 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)19 ClientOperationService (com.alibaba.nacos.naming.core.v2.service.ClientOperationService)17 Test (org.junit.Test)16 Instance (com.alibaba.nacos.api.naming.pojo.Instance)13 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)13 UdpPushService (com.alibaba.nacos.naming.push.UdpPushService)13 NacosException (com.alibaba.nacos.api.exception.NacosException)11 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)11 HealthCheckInstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)11 HashSet (java.util.HashSet)11 Secured (com.alibaba.nacos.auth.annotation.Secured)10 Before (org.junit.Before)10 Client (com.alibaba.nacos.naming.core.v2.client.Client)9 ClientOperationEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientOperationEvent)8 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)8 InstanceMetadata (com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)8 IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)7 Set (java.util.Set)7