Search in sources :

Example 11 with NacosRuntimeException

use of com.alibaba.nacos.api.exception.runtime.NacosRuntimeException in project nacos by alibaba.

the class DistributedDatabaseOperateImpl method queryMany.

@Override
public <R> List<R> queryMany(String sql, Object[] args, Class<R> rClass) {
    try {
        LoggerUtils.printIfDebugEnabled(LogUtil.DEFAULT_LOG, "queryMany info : sql : {}, args : {}", sql, args);
        byte[] data = serializer.serialize(SelectRequest.builder().queryType(QueryType.QUERY_MANY_NO_MAPPER_WITH_ARGS).sql(sql).args(args).className(rClass.getCanonicalName()).build());
        final boolean blockRead = EmbeddedStorageContextUtils.containsExtendInfo(Constants.EXTEND_NEED_READ_UNTIL_HAVE_DATA);
        Response response = innerRead(ReadRequest.newBuilder().setGroup(group()).setData(ByteString.copyFrom(data)).build(), blockRead);
        if (response.getSuccess()) {
            return serializer.deserialize(response.getData().toByteArray(), List.class);
        }
        throw new NJdbcException(response.getErrMsg());
    } catch (Exception e) {
        LogUtil.FATAL_LOG.error("An exception occurred during the query operation : {}", e.toString());
        throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
    }
}
Also used : Response(com.alibaba.nacos.consistency.entity.Response) NJdbcException(com.alibaba.nacos.config.server.exception.NJdbcException) TimeoutException(java.util.concurrent.TimeoutException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ConsistencyException(com.alibaba.nacos.consistency.exception.ConsistencyException) DataAccessException(org.springframework.dao.DataAccessException) NJdbcException(com.alibaba.nacos.config.server.exception.NJdbcException) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosRuntimeException(com.alibaba.nacos.api.exception.runtime.NacosRuntimeException) BadSqlGrammarException(org.springframework.jdbc.BadSqlGrammarException) NacosRuntimeException(com.alibaba.nacos.api.exception.runtime.NacosRuntimeException)

Example 12 with NacosRuntimeException

use of com.alibaba.nacos.api.exception.runtime.NacosRuntimeException in project nacos by alibaba.

the class ConfigResourceInjector method getStsResponse.

private static String getStsResponse() {
    String securityCredentials = StsConfig.getInstance().getSecurityCredentials();
    if (securityCredentials != null) {
        return securityCredentials;
    }
    String securityCredentialsUrl = StsConfig.getInstance().getSecurityCredentialsUrl();
    try {
        HttpRestResult<String> result = ConfigHttpClientManager.getInstance().getNacosRestTemplate().get(securityCredentialsUrl, Header.EMPTY, Query.EMPTY, String.class);
        if (!result.ok()) {
            LOGGER.error("can not get security credentials, securityCredentialsUrl: {}, responseCode: {}, response: {}", securityCredentialsUrl, result.getCode(), result.getMessage());
            throw new NacosRuntimeException(NacosException.SERVER_ERROR, "can not get security credentials, responseCode: " + result.getCode() + ", response: " + result.getMessage());
        }
        return result.getData();
    } catch (Exception e) {
        LOGGER.error("can not get security credentials", e);
        throw new NacosRuntimeException(NacosException.SERVER_ERROR, e);
    }
}
Also used : NacosRuntimeException(com.alibaba.nacos.api.exception.runtime.NacosRuntimeException) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosRuntimeException(com.alibaba.nacos.api.exception.runtime.NacosRuntimeException)

Example 13 with NacosRuntimeException

use of com.alibaba.nacos.api.exception.runtime.NacosRuntimeException in project nacos by alibaba.

the class EphemeralClientOperationServiceImpl 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 persistent service, can't register ephemeral instance.", singleton.getGroupedServiceName()));
    }
    Client client = clientManager.getClient(clientId);
    if (!clientIsLegal(client, clientId)) {
        return;
    }
    InstancePublishInfo instanceInfo = getPublishInfo(instance);
    client.addServiceInstance(singleton, instanceInfo);
    client.setLastUpdatedTime();
    NotifyCenter.publishEvent(new ClientOperationEvent.ClientRegisterServiceEvent(singleton, clientId));
    NotifyCenter.publishEvent(new MetadataEvent.InstanceMetadataEvent(singleton, instanceInfo.getMetadataId(), false));
}
Also used : ClientOperationEvent(com.alibaba.nacos.naming.core.v2.event.client.ClientOperationEvent) MetadataEvent(com.alibaba.nacos.naming.core.v2.event.metadata.MetadataEvent) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ClientOperationService(com.alibaba.nacos.naming.core.v2.service.ClientOperationService) Client(com.alibaba.nacos.naming.core.v2.client.Client) NacosRuntimeException(com.alibaba.nacos.api.exception.runtime.NacosRuntimeException)

Example 14 with NacosRuntimeException

use of com.alibaba.nacos.api.exception.runtime.NacosRuntimeException 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);
    }
}
Also used : WriteRequest(com.alibaba.nacos.consistency.entity.WriteRequest) ClientOperationService(com.alibaba.nacos.naming.core.v2.service.ClientOperationService) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) NacosRuntimeException(com.alibaba.nacos.api.exception.runtime.NacosRuntimeException) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosRuntimeException(com.alibaba.nacos.api.exception.runtime.NacosRuntimeException) IOException(java.io.IOException)

Aggregations

NacosRuntimeException (com.alibaba.nacos.api.exception.runtime.NacosRuntimeException)14 NacosException (com.alibaba.nacos.api.exception.NacosException)13 NJdbcException (com.alibaba.nacos.config.server.exception.NJdbcException)7 Response (com.alibaba.nacos.consistency.entity.Response)7 ConsistencyException (com.alibaba.nacos.consistency.exception.ConsistencyException)7 TimeoutException (java.util.concurrent.TimeoutException)7 DataAccessException (org.springframework.dao.DataAccessException)7 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)7 BadSqlGrammarException (org.springframework.jdbc.BadSqlGrammarException)7 IOException (java.io.IOException)4 NotifyCenter (com.alibaba.nacos.common.notify.NotifyCenter)2 MD5Utils (com.alibaba.nacos.common.utils.MD5Utils)2 StringUtils (com.alibaba.nacos.common.utils.StringUtils)2 Constants (com.alibaba.nacos.config.server.constant.Constants)2 DynamicDataSource (com.alibaba.nacos.config.server.service.datasource.DynamicDataSource)2 WriteRequest (com.alibaba.nacos.consistency.entity.WriteRequest)2 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)2 ClientOperationService (com.alibaba.nacos.naming.core.v2.service.ClientOperationService)2 JustForTest (com.alibaba.nacos.common.JustForTest)1 RestResult (com.alibaba.nacos.common.model.RestResult)1