mirror of
https://github.com/Telecominfraproject/wlan-cloud-opensync-controller.git
synced 2026-03-21 02:39:11 +00:00
fixed connectivity between OpenSyncGatewayCloudProcess and AllCloudInOneServer
This commit is contained in:
@@ -29,18 +29,6 @@
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency> -->
|
||||
<!-- <artifactId>webtoken-auth-service</artifactId> -->
|
||||
<!-- <groupId>com.telecominfraproject.wlan</groupId> -->
|
||||
<!-- <version>${tip-wlan-cloud.release.version}</version> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
<!-- <dependency> -->
|
||||
<!-- <artifactId>portal-services</artifactId> -->
|
||||
<!-- <groupId>com.telecominfraproject.wlan</groupId> -->
|
||||
<!-- <version>${tip-wlan-cloud.release.version}</version> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
<dependency>
|
||||
<artifactId>customer-service-interface</artifactId>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
|
||||
@@ -86,7 +86,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
|
||||
@PostConstruct
|
||||
private void postCreate() {
|
||||
LOG.info("Using Cloud integration");
|
||||
cloudEquipmentRecordCache = cacheManagerShortLived.getCache("KDC_equipment_record_cache");
|
||||
cloudEquipmentRecordCache = cacheManagerShortLived.getCache("equipment_record_cache");
|
||||
opensyncNodeMap = Collections.synchronizedMap(new HashMap<String, OpensyncNode>());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.telecominfraproject.wlan.opensync.external.integration.client;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.client.AsyncRestTemplate;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
|
||||
/**
|
||||
* @author dtop
|
||||
* Configure rest client to understand KDC classes that are children of KDC BaseJsonModel
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(RestTemplate.class)
|
||||
public class OpensyncCloudTemplatePostConfiguration {
|
||||
|
||||
private static final Logger LOG = LoggerFactory
|
||||
.getLogger(OpensyncCloudTemplatePostConfiguration.class);
|
||||
|
||||
|
||||
public OpensyncCloudTemplatePostConfiguration(@Autowired(required=false) AsyncRestTemplate asyncRestTemplate, @Autowired RestTemplate restTemplate) {
|
||||
registerModulesWithObjectMappers(restTemplate);
|
||||
if(asyncRestTemplate!=null) {
|
||||
registerModulesWithObjectMappers(asyncRestTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerModulesWithObjectMappers(AsyncRestTemplate restT) {
|
||||
//this is needed so that rest client can produce and consume JSON objects with (and without) _type property
|
||||
for(@SuppressWarnings("rawtypes") HttpMessageConverter c: restT.getMessageConverters()){
|
||||
if(c instanceof MappingJackson2HttpMessageConverter){
|
||||
LOG.info("Configuring ObjectMapper on AsyncRestTemplate");
|
||||
BaseJsonModel.registerAllSubtypes(((MappingJackson2HttpMessageConverter)c).getObjectMapper());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerModulesWithObjectMappers(RestTemplate restT) {
|
||||
//this is needed so that rest client can produce and consume JSON objects with (and without) _type property
|
||||
for(@SuppressWarnings("rawtypes") HttpMessageConverter c: restT.getMessageConverters()){
|
||||
if(c instanceof MappingJackson2HttpMessageConverter){
|
||||
LOG.info("Configuring ObjectMapper on RestTemplate");
|
||||
BaseJsonModel.registerAllSubtypes(((MappingJackson2HttpMessageConverter)c).getObjectMapper());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.telecominfraproject.wlan.opensync.external.integration.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
|
||||
|
||||
/**
|
||||
* @author dtoptygin
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
//@EnableWebMvc - DTOP: do not use this, it will break mapping for index.html file
|
||||
// see http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-auto-configuration
|
||||
public class OpensyncCloudWebConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(OpensyncCloudWebConfig.class);
|
||||
|
||||
@Override
|
||||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
//this is needed so that servlets can consume and produce JSON objects with (and without) _type parameters
|
||||
LOG.info("extending MessageConverters to understand KDC BaseJsonModel and its descendants");
|
||||
for(HttpMessageConverter<?> c: converters){
|
||||
if(c instanceof MappingJackson2HttpMessageConverter){
|
||||
BaseJsonModel.registerAllSubtypes(((MappingJackson2HttpMessageConverter)c).getObjectMapper());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFormatters(FormatterRegistry registry) {
|
||||
// This is needed so that @RequestParam annotations in the servlet
|
||||
// methods can be used with BaseJsonModel and its descendants and its
|
||||
// collections.
|
||||
|
||||
//Use GenericlConverter here, simple one does not work
|
||||
LOG.info("Adding custom converters to process KDC BaseJsonModel and its descendants");
|
||||
|
||||
registry.addConverter(new OpensyncCloudWebGenericConverter());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
package com.telecominfraproject.wlan.opensync.external.integration.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
|
||||
/**
|
||||
* @author dtoptygin
|
||||
*
|
||||
*/
|
||||
public class OpensyncCloudWebGenericConverter implements GenericConverter {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(OpensyncCloudWebGenericConverter.class);
|
||||
private Set<ConvertiblePair> convertiblePairs;
|
||||
|
||||
/**
|
||||
* Format the typeDescriptor for logging
|
||||
* @param typeDescriptor
|
||||
* @return
|
||||
*/
|
||||
public static String getDataType(TypeDescriptor typeDescriptor) {
|
||||
if (typeDescriptor == null) {
|
||||
return "";
|
||||
}
|
||||
if (typeDescriptor.isCollection()) {
|
||||
return typeDescriptor.getName() + "<" + getDataType(typeDescriptor.getElementTypeDescriptor()) + ">";
|
||||
}
|
||||
if (typeDescriptor.isArray()) {
|
||||
return getDataType(typeDescriptor.getElementTypeDescriptor()) + "[]";
|
||||
}
|
||||
return typeDescriptor.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public OpensyncCloudWebGenericConverter() {
|
||||
LOG.info("Registering Object Converter for the KDC models");
|
||||
convertiblePairs = new HashSet<>();
|
||||
convertiblePairs.add(new ConvertiblePair(String.class, BaseJsonModel.class));
|
||||
convertiblePairs.add(new ConvertiblePair(String.class, List.class));
|
||||
convertiblePairs.add(new ConvertiblePair(String.class, Set.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||
return convertiblePairs;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
// dtop: this is ugly and needs to be generalized, but it works for
|
||||
// List/Set of Integer/Long/BaseJsonModel/String
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("Attempting to convert '{}' from {} to {}", source, getDataType(sourceType),
|
||||
getDataType(targetType));
|
||||
}
|
||||
|
||||
if (targetType.isAssignableTo(TypeDescriptor.valueOf(String.class)) || targetType
|
||||
.isAssignableTo(TypeDescriptor.collection(Collection.class, TypeDescriptor.valueOf(String.class)))) {
|
||||
LOG.trace("Proceeding with conversion of String ... ");
|
||||
Object ret = null;
|
||||
if (targetType.isCollection()) {
|
||||
if (targetType.getName().equals(List.class.getName())) {
|
||||
ret = new ArrayList();
|
||||
} else if (targetType.getName().equals(Set.class.getName())) {
|
||||
ret = new HashSet();
|
||||
} else {
|
||||
throw new IllegalStateException("Unsupported collection type " + targetType.getName());
|
||||
}
|
||||
|
||||
if (sourceType.isArray() || sourceType.isCollection()) {
|
||||
for (Object obj : (Iterable<Object>) source) {
|
||||
((Collection) ret).add((String) obj);
|
||||
}
|
||||
} else {
|
||||
for (String str : ((String) source).split(",")) {
|
||||
str = str.trim();
|
||||
if (str.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
((Collection) ret).add(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (targetType.isAssignableTo(TypeDescriptor.valueOf(Integer.class)) || targetType
|
||||
.isAssignableTo(TypeDescriptor.collection(Collection.class, TypeDescriptor.valueOf(Integer.class)))) {
|
||||
LOG.trace("Proceeding with conversion of Integer ... ");
|
||||
Object ret = null;
|
||||
if (targetType.isCollection()) {
|
||||
if (targetType.getName().equals(List.class.getName())) {
|
||||
ret = new ArrayList();
|
||||
} else if (targetType.getName().equals(Set.class.getName())) {
|
||||
ret = new HashSet();
|
||||
} else {
|
||||
throw new IllegalStateException("Unsupported collection type " + targetType.getName());
|
||||
}
|
||||
|
||||
if (sourceType.isArray() || sourceType.isCollection()) {
|
||||
for (Object obj : (Iterable<Object>) source) {
|
||||
((Collection) ret).add(Integer.parseInt((String) obj));
|
||||
}
|
||||
} else {
|
||||
for (String str : ((String) source).split(",")) {
|
||||
str = str.trim();
|
||||
if (str.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
((Collection) ret).add(Integer.parseInt(str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (targetType.isAssignableTo(TypeDescriptor.valueOf(Long.class)) || targetType
|
||||
.isAssignableTo(TypeDescriptor.collection(Collection.class, TypeDescriptor.valueOf(Long.class)))) {
|
||||
LOG.trace("Proceeding with conversion of Long ... ");
|
||||
Object ret = null;
|
||||
if (targetType.isCollection()) {
|
||||
if (targetType.getName().equals(List.class.getName())) {
|
||||
ret = new ArrayList();
|
||||
} else if (targetType.getName().equals(Set.class.getName())) {
|
||||
ret = new HashSet();
|
||||
} else {
|
||||
throw new IllegalStateException("Unsupported collection type " + targetType.getName());
|
||||
}
|
||||
|
||||
if (sourceType.isArray() || sourceType.isCollection()) {
|
||||
for (Object obj : (Iterable<Object>) source) {
|
||||
((Collection) ret).add(Long.parseLong((String) obj));
|
||||
}
|
||||
} else {
|
||||
for (String str : ((String) source).split(",")) {
|
||||
str = str.trim();
|
||||
if (str.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
((Collection) ret).add(Long.parseLong(str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!targetType.isAssignableTo(TypeDescriptor.valueOf(BaseJsonModel.class)) && !targetType.isAssignableTo(
|
||||
TypeDescriptor.collection(Collection.class, TypeDescriptor.valueOf(BaseJsonModel.class)))) {
|
||||
throw new IllegalStateException(
|
||||
"WC GenericConverter only handles BaseJsonModel and its collections and its descendants, not "
|
||||
+ targetType.getName());
|
||||
}
|
||||
|
||||
LOG.trace("Proceeding with conversion of BaseJsonModel ... ");
|
||||
|
||||
LOG.debug("Attempting to convert {} from {} to {}", source, sourceType.getName(), targetType.getName());
|
||||
|
||||
Object ret;
|
||||
if (targetType.isCollection()) {
|
||||
if (targetType.getName().equals(List.class.getName())) {
|
||||
ret = new ArrayList();
|
||||
} else if (targetType.getName().equals(Set.class.getName())) {
|
||||
ret = new HashSet();
|
||||
} else {
|
||||
throw new IllegalStateException("Unsupported collection type " + targetType.getName());
|
||||
}
|
||||
|
||||
if (sourceType.isArray() || sourceType.isCollection()) {
|
||||
if (source != null) {
|
||||
for (Object obj : (Iterable<Object>) source) {
|
||||
((Collection) ret).add(BaseJsonModel.fromString((String) obj, BaseJsonModel.class));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (source != null && !((String) source).isEmpty()) {
|
||||
((Collection) ret).addAll(BaseJsonModel.listFromString((String) source, BaseJsonModel.class));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (source != null && ((String) source).startsWith("[{")) {
|
||||
// DT: should not ever get here
|
||||
ret = BaseJsonModel.listFromString((String) source, BaseJsonModel.class);
|
||||
} else {
|
||||
if (source == null || "".equals(source)) {
|
||||
return null;
|
||||
}
|
||||
ret = BaseJsonModel.fromString((String) source, BaseJsonModel.class);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user