Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #747、#1154] Add create and update service methods in SDK and update instance operation #1130

Merged
merged 16 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/NacosFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.alibaba.nacos.api.config.ConfigFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.MaintainFactory;
import com.alibaba.nacos.api.naming.MaintainService;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;

Expand Down Expand Up @@ -74,4 +76,26 @@ public static NamingService createNamingService(Properties properties) throws Na
return NamingFactory.createNamingService(properties);
}

/**
* Create maintain service
*
* @param serverAddr
* @return MaintainService
* @throws NacosException Exception
*/
public static MaintainService createMaintainService(String serverAddr) throws NacosException {
return MaintainFactory.createMaintainService(serverAddr);
}

/**
* Create maintain service
*
* @param properties
* @return MaintainService
* @throws NacosException Exception
*/
public static MaintainService createMaintainService(Properties properties) throws NacosException {
return MaintainFactory.createMaintainService(properties);
}

}
2 changes: 2 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public class Constants {

public static final int FLOW_CONTROL_INTERVAL = 1000;

public static final float PROTECT_THRESHOLD = 0.0F;
chuntaojun marked this conversation as resolved.
Show resolved Hide resolved

public static final String LINE_SEPARATOR = Character.toString((char)1);

public static final String WORD_SEPARATOR = Character.toString((char)2);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.api.naming;

import com.alibaba.nacos.api.exception.NacosException;

import java.lang.reflect.Constructor;
import java.util.Properties;

/**
* @author liaochuntao
* @since 1.0.0
*/
public class MaintainFactory {

public static MaintainService createMaintainService(String serverList) throws NacosException {
try {
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosMaintainService");
Constructor constructor = driverImplClass.getConstructor(String.class);
MaintainService vendorImpl = (MaintainService)constructor.newInstance(serverList);
return vendorImpl;
} catch (Throwable e) {
throw new NacosException(-400, e.getMessage());
}
}

public static MaintainService createMaintainService(Properties properties) throws NacosException {
try {
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosMaintainService");
Constructor constructor = driverImplClass.getConstructor(Properties.class);
MaintainService vendorImpl = (MaintainService)constructor.newInstance(properties);
return vendorImpl;
} catch (Throwable e) {
throw new NacosException(-400, e.getMessage());
}
}

}
148 changes: 148 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/naming/MaintainService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.api.naming;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.pojo.Service;
import com.alibaba.nacos.api.selector.AbstractSelector;

import java.util.Map;

/**
* Operations related to Nacos
*
* @author liaochuntao
* @since 1.0.0
chuntaojun marked this conversation as resolved.
Show resolved Hide resolved
*/
public interface MaintainService {

/**
* query service
*
* @param serviceName
* @return
* @throws NacosException
*/
Service selectOneService(String serviceName) throws NacosException;
chuntaojun marked this conversation as resolved.
Show resolved Hide resolved

/**
* query service
*
* @param serviceName
* @param groupName
* @return
* @throws NacosException
*/
Service selectOneService(String serviceName, String groupName) throws NacosException;

/**
* create service to Nacos
*
* @param serviceName name of service
* @throws NacosException
*/
void createService(String serviceName) throws NacosException;

/**
* create service to Nacos
*
* @param serviceName name of service
* @param groupName group of service
* @throws NacosException
*/
void createService(String serviceName, String groupName) throws NacosException;

/**
* create service to Nacos
*
* @param serviceName name of service
* @param groupName group of service
* @param protectThreshold protectThreshold of service
* @throws NacosException
*/
void createService(String serviceName, String groupName, Float protectThreshold) throws NacosException;

/**
* create service to Nacos
*
* @param serviceName name of service
* @param groupName group of service
* @param protectThreshold protectThreshold of service
* @param expression expression of selector
* @throws NacosException
*/
void createService(String serviceName, String groupName, Float protectThreshold, String expression) throws NacosException;

/**
* create service to Nacos
*
* @param service name of service
* @param selector selector
* @throws NacosException
*/
void createService(Service service, AbstractSelector selector) throws NacosException;

/**
* delete service from Nacos
*
* @param serviceName name of service
* @return if delete service success return true
* @throws NacosException
*/
boolean deleteService(String serviceName) throws NacosException;

/**
* delete service from Nacos
*
* @param serviceName name of service
* @param groupName group of service
* @return if delete service success return true
* @throws NacosException
*/
boolean deleteService(String serviceName, String groupName) throws NacosException;

/**
* update service to Nacos
*
* @param serviceName name of service
* @param groupName group of service
* @param protectThreshold protectThreshold of service
* @throws NacosException
*/
void updateService(String serviceName, String groupName, Float protectThreshold) throws NacosException;
chuntaojun marked this conversation as resolved.
Show resolved Hide resolved

/**
* update service to Nacos
*
* @param serviceName name of service
* @param groupName group of service
* @param protectThreshold protectThreshold of service
* @param metadata metadata of service
* @throws NacosException
*/
void updateService(String serviceName, String groupName, Float protectThreshold, Map<String, String> metadata) throws NacosException;

/**
* update service to Nacos with selector
*
* @param service {@link Service} pojo of service
* @param selector {@link AbstractSelector} pojo of selector
* @throws NacosException
*/
void updateService(Service service, AbstractSelector selector) throws NacosException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import com.alibaba.nacos.api.naming.listener.EventListener;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.api.naming.pojo.Service;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.alibaba.nacos.api.selector.AbstractSelector;

import java.util.List;
import java.util.Map;

/**
* Naming Service
Expand Down
28 changes: 28 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/selector/NoneSelector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.api.selector;

/**
* @author liaochuntao
* @since 1.0.0
*/
public class NoneSelector extends AbstractSelector {

public NoneSelector() {
this.setType(SelectorType.none.name());
}
}
Loading