use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.
the class PersistentClientOperationServiceImpl method registerInstance.
@Override
public void registerInstance(Service service, Instance instance, String clientId) {
Service singleton = ServiceManager.getInstance().getSingleton(service);
if (singleton.isEphemeral()) {
throw new NacosRuntimeException(NacosException.INVALID_PARAM, String.format("Current service %s is ephemeral service, can't register persistent instance.", singleton.getGroupedServiceName()));
}
final InstanceStoreRequest request = new InstanceStoreRequest();
request.setService(service);
request.setInstance(instance);
request.setClientId(clientId);
final WriteRequest writeRequest = WriteRequest.newBuilder().setGroup(group()).setData(ByteString.copyFrom(serializer.serialize(request))).setOperation(DataOperation.ADD.name()).build();
try {
protocol.write(writeRequest);
} catch (Exception e) {
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e);
}
}
use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.
the class NamingMetadataOperateService method addClusterMetadata.
/**
* Add cluster metadata to service metadata.
*
* @param service service
* @param clusterName cluster name
* @param clusterMetadata cluster metadata
*/
public void addClusterMetadata(Service service, String clusterName, ClusterMetadata clusterMetadata) {
MetadataOperation<ServiceMetadata> operation = buildMetadataOperation(service);
ServiceMetadata serviceMetadata = new ServiceMetadata();
serviceMetadata.setEphemeral(service.isEphemeral());
serviceMetadata.getClusters().put(clusterName, clusterMetadata);
operation.setMetadata(serviceMetadata);
WriteRequest operationLog = WriteRequest.newBuilder().setGroup(Constants.SERVICE_METADATA).setOperation(DataOperation.ADD.name()).setData(ByteString.copyFrom(serializer.serialize(operation))).build();
submitMetadataOperation(operationLog);
}
use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.
the class NamingMetadataOperateService method deleteServiceMetadata.
/**
* Delete service metadata.
*
* @param service service of metadata
*/
public void deleteServiceMetadata(Service service) {
MetadataOperation<ServiceMetadata> operation = buildMetadataOperation(service);
WriteRequest operationLog = WriteRequest.newBuilder().setGroup(Constants.SERVICE_METADATA).setOperation(DataOperation.DELETE.name()).setData(ByteString.copyFrom(serializer.serialize(operation))).build();
submitMetadataOperation(operationLog);
}
use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.
the class ProtoMessageUtilTest method testProto.
@Test
public void testProto() throws Exception {
WriteRequest request = WriteRequest.newBuilder().setKey("test-proto-new").build();
byte[] bytes = request.toByteArray();
Log log = Log.parseFrom(bytes);
assertEquals(request.getKey(), log.getKey());
}
use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.
the class ProtoMessageUtilTest method testConvertToWriteRequest.
@Test
public void testConvertToWriteRequest() {
ByteString data = ByteString.copyFrom("data".getBytes());
Log log = Log.newBuilder().setKey("key").setGroup("group").setData(data).setOperation("o").putExtendInfo("k", "v").build();
WriteRequest writeRequest = ProtoMessageUtil.convertToWriteRequest(log);
assertEquals(1, writeRequest.getExtendInfoCount());
assertEquals(data, writeRequest.getData());
assertEquals("key", writeRequest.getKey());
assertEquals("group", writeRequest.getGroup());
assertEquals("o", writeRequest.getOperation());
}
Aggregations