Skip to content

Commit

Permalink
Merge pull request #1130 from chuntaojun/feature_service_curd
Browse files Browse the repository at this point in the history
[ISSUE #747#1154] Add create and update service methods in SDK and update instance operation
  • Loading branch information
Fury Zhu authored May 9, 2019
2 parents a6ef86d + 221ce12 commit df6f3a8
Show file tree
Hide file tree
Showing 18 changed files with 1,007 additions and 121 deletions.
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.NamingMaintainFactory;
import com.alibaba.nacos.api.naming.NamingMaintainService;
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 NamingMaintainService
* @throws NacosException Exception
*/
public static NamingMaintainService createMaintainService(String serverAddr) throws NacosException {
return NamingMaintainFactory.createMaintainService(serverAddr);
}

/**
* Create maintain service
*
* @param properties
* @return NamingMaintainService
* @throws NacosException Exception
*/
public static NamingMaintainService createMaintainService(Properties properties) throws NacosException {
return NamingMaintainFactory.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 DEFAULT_PROTECT_THRESHOLD = 0.0F;

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.1
*/
public class NamingMaintainFactory {

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

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
* 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.Instance;
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.1
*/
public interface NamingMaintainService {

/**
* update instance info
*
* @param serviceName
* @param instance
* @throws NacosException
*/
void updateInstance(String serviceName, Instance instance) throws NacosException;

/**
* update instance info
*
* @param serviceName
* @param groupName
* @param instance
* @throws NacosException
*/
void updateInstance(String serviceName, String groupName, Instance instance) throws NacosException;

/**
* query service
*
* @param serviceName
* @return
* @throws NacosException
*/
Service queryService(String serviceName) throws NacosException;

/**
* query service
*
* @param serviceName
* @param groupName
* @return
* @throws NacosException
*/
Service queryService(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;

/**
* 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
11 changes: 11 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/naming/pojo/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,15 @@ public void setMetadata(Map<String, String> metadata) {
public void addMetadata(String key, String value) {
this.metadata.put(key, value);
}

@Override
public String toString() {
return "Service{" +
"name='" + name + '\'' +
", protectThreshold=" + protectThreshold +
", appName='" + appName + '\'' +
", groupName='" + groupName + '\'' +
", metadata=" + metadata +
'}';
}
}
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.1
*/
public class NoneSelector extends AbstractSelector {

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

0 comments on commit df6f3a8

Please sign in to comment.