支持获取namespace下的全部service列表

pull/38/head
lambdaxiao 3 years ago
parent fe45c4f299
commit e409527a08

@ -63,7 +63,7 @@
<properties> <properties>
<revision>1.1.4.Hoxton.SR9-SNAPSHOT</revision> <revision>1.1.4.Hoxton.SR9-SNAPSHOT</revision>
<polaris.version>1.2.2-SNAPSHOT</polaris.version> <polaris.version>1.2.4-SNAPSHOT</polaris.version>
<tomcat.version>10.0.0-M6</tomcat.version> <tomcat.version>10.0.0-M6</tomcat.version>
<powermock.version>2.0.0</powermock.version> <powermock.version>2.0.0</powermock.version>

@ -23,10 +23,10 @@ import com.tencent.cloud.polaris.PolarisProperties;
import com.tencent.polaris.api.core.ConsumerAPI; import com.tencent.polaris.api.core.ConsumerAPI;
import com.tencent.polaris.api.core.ProviderAPI; import com.tencent.polaris.api.core.ProviderAPI;
import com.tencent.polaris.api.pojo.ServiceInfo; import com.tencent.polaris.api.pojo.ServiceInfo;
import com.tencent.polaris.api.rpc.GetAllInstancesRequest; import com.tencent.polaris.api.rpc.*;
import com.tencent.polaris.api.rpc.GetInstancesRequest;
import com.tencent.polaris.api.rpc.InstancesResponse;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -93,4 +93,18 @@ public class PolarisDiscoveryHandler {
return providerAPI; return providerAPI;
} }
/**
* Return all service for given namespace
*
* @return namespace
*/
public ServicesResponse GetServices() {
String namespace = polarisProperties.getNamespace();
Map<String, String> allTransitiveCustomMetadata = MetadataContextHolder.get().getAllTransitiveCustomMetadata();
GetServicesRequest request = new GetServicesRequest();
request.setNamespace(namespace);
request.setMetadata(allTransitiveCustomMetadata);
return polarisConsumer.getServices(request);
}
} }

@ -17,15 +17,21 @@
package com.tencent.cloud.polaris.discovery; package com.tencent.cloud.polaris.discovery;
import com.tencent.cloud.polaris.PolarisProperties;
import com.tencent.cloud.polaris.pojo.PolarisServiceInstance; import com.tencent.cloud.polaris.pojo.PolarisServiceInstance;
import com.tencent.polaris.api.exception.PolarisException; import com.tencent.polaris.api.exception.PolarisException;
import com.tencent.polaris.api.pojo.Instance; import com.tencent.polaris.api.pojo.Instance;
import com.tencent.polaris.api.pojo.ServiceInfo;
import com.tencent.polaris.api.pojo.ServiceInstances; import com.tencent.polaris.api.pojo.ServiceInstances;
import com.tencent.polaris.api.rpc.InstancesResponse; import com.tencent.polaris.api.rpc.InstancesResponse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import com.tencent.polaris.api.rpc.ServicesResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
/** /**
@ -57,13 +63,18 @@ public class PolarisServiceDiscovery {
} }
/** /**
* TODO Return the names of all services. * Return the names of all services.
* *
* @return list of service names * @return list of service names
* @throws PolarisException polarisException * @throws PolarisException polarisException
*/ */
public List<String> getServices() throws PolarisException { public List<String> getServices() throws PolarisException {
return Collections.emptyList(); return polarisDiscoveryHandler.
GetServices().
getServices().
stream().
map(ServiceInfo::getService).
collect(Collectors.toList());
} }
} }

Loading…
Cancel
Save