diff --git a/server/common/admin-rest-client/src/main/java/org/kaaproject/kaa/server/common/admin/AdminClient.java b/server/common/admin-rest-client/src/main/java/org/kaaproject/kaa/server/common/admin/AdminClient.java index 04b9a90442..3062010a3f 100644 --- a/server/common/admin-rest-client/src/main/java/org/kaaproject/kaa/server/common/admin/AdminClient.java +++ b/server/common/admin-rest-client/src/main/java/org/kaaproject/kaa/server/common/admin/AdminClient.java @@ -31,6 +31,7 @@ import org.kaaproject.kaa.common.dto.EndpointProfileSchemaDto; import org.kaaproject.kaa.common.dto.EndpointProfilesBodyDto; import org.kaaproject.kaa.common.dto.EndpointProfilesPageDto; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; import org.kaaproject.kaa.common.dto.EndpointUserConfigurationDto; import org.kaaproject.kaa.common.dto.NotificationDto; import org.kaaproject.kaa.common.dto.NotificationSchemaDto; @@ -527,6 +528,18 @@ public void editUserConfiguration(EndpointUserConfigurationDto endpointUserConfi restTemplate.postForLocation(restTemplate.getUrl() + "userConfiguration", endpointUserConfiguration); } + public EndpointSpecificConfigurationDto editEndpointSpecificConfiguration(EndpointSpecificConfigurationDto configuration) throws Exception { + return restTemplate.postForObject(restTemplate.getUrl() + "endpointConfiguration", configuration, EndpointSpecificConfigurationDto.class); + } + + public void deleteEndpointSpecificConfiguration(String endpointKeyHash) throws Exception { + restTemplate.delete(restTemplate.getUrl() + "endpointConfiguration/" + endpointKeyHash); + } + + public EndpointSpecificConfigurationDto findEndpointSpecificConfiguration(String endpointKeyHash) throws Exception { + return restTemplate.getForObject(restTemplate.getUrl() + "endpointConfiguration/" + endpointKeyHash, EndpointSpecificConfigurationDto.class); + } + public ProfileFilterDto editProfileFilter(ProfileFilterDto profileFilter) throws Exception { return restTemplate.postForObject(restTemplate.getUrl() + "profileFilter", profileFilter, ProfileFilterDto.class); } diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/ConfigurationService.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/ConfigurationService.java index 0ef879feee..dbf41803ba 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/ConfigurationService.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/ConfigurationService.java @@ -17,9 +17,6 @@ package org.kaaproject.kaa.server.common.dao; -import java.util.Collection; -import java.util.List; - import org.kaaproject.kaa.common.dto.ChangeConfigurationNotification; import org.kaaproject.kaa.common.dto.ConfigurationDto; import org.kaaproject.kaa.common.dto.ConfigurationRecordDto; @@ -27,6 +24,9 @@ import org.kaaproject.kaa.common.dto.HistoryDto; import org.kaaproject.kaa.common.dto.VersionDto; +import java.util.Collection; +import java.util.List; + /** * The interface Configuration service. */ @@ -192,6 +192,8 @@ public interface ConfigurationService { */ ConfigurationSchemaDto saveConfSchema(ConfigurationSchemaDto configurationSchema); + String validateConfiguration(String appId, int schemaVersion, String configurationBody); + /** * Find configuration schema by id. * diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/EndpointSpecificConfigurationService.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/EndpointSpecificConfigurationService.java new file mode 100644 index 0000000000..ee59c49971 --- /dev/null +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/EndpointSpecificConfigurationService.java @@ -0,0 +1,61 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * 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 org.kaaproject.kaa.server.common.dao; + +import org.kaaproject.kaa.common.dto.EndpointProfileDto; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; + +import java.util.Optional; + +/** + * The interface Endpoint specific configuration service. + */ +public interface EndpointSpecificConfigurationService { + + /** + * Find endpoint specific configuration by endpoint key hash + * + * @param endpointKeyHash + * @return the endpoint specific configuration + */ + Optional findByEndpointKeyHash(String endpointKeyHash); + + /** + * Find endpoint specific configuration by endpoint profile + * + * @param endpointProfileDto + * @return the endpoint specific configuration + */ + Optional findByEndpointProfile(EndpointProfileDto endpointProfileDto); + + /** + * Delete endpoint specific configuration by endpoint key hash + * + * @param endpointKeyHash + * @return deleted endpoint specific configuration + */ + Optional deleteByEndpointKeyHash(String endpointKeyHash); + + /** + * Save endpoint specific configuration by endpoint key hash + * + * @param configurationDto endpoint specific configuration + * @return saved endpoint specific configuration + */ + EndpointSpecificConfigurationDto save(EndpointSpecificConfigurationDto configurationDto); + +} diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/EndpointSpecificConfigurationDao.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/EndpointSpecificConfigurationDao.java new file mode 100644 index 0000000000..bc901a7022 --- /dev/null +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/EndpointSpecificConfigurationDao.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * 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 org.kaaproject.kaa.server.common.dao.impl; + +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; +import org.kaaproject.kaa.server.common.dao.model.EndpointSpecificConfiguration; + +public interface EndpointSpecificConfigurationDao extends Dao { + + void removeByEndpointKeyHash(String endpointKeyHash); + + EndpointSpecificConfiguration findByEndpointKeyHashAndConfigurationVersion(String endpointKeyHash, int configurationVersion); + + EndpointSpecificConfiguration save(EndpointSpecificConfigurationDto endpointSpecificConfigurationDto); + +} diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/EndpointSpecificConfiguration.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/EndpointSpecificConfiguration.java new file mode 100644 index 0000000000..74839d96b7 --- /dev/null +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/EndpointSpecificConfiguration.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * 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 org.kaaproject.kaa.server.common.dao.model; + +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; +import org.kaaproject.kaa.common.dto.HasVersion; + +import java.io.Serializable; + +/** + * An endpoint specific configuration provides single endpoint configuration without creating dedicated endpoint group. + * Endpoint specific configuration has highest priority in configuration override. + */ +public interface EndpointSpecificConfiguration extends ToDto, HasVersion, Serializable { + +} diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/ConfigurationServiceImpl.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/ConfigurationServiceImpl.java index 6d75008326..3eefbcbb4b 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/ConfigurationServiceImpl.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/ConfigurationServiceImpl.java @@ -16,22 +16,6 @@ package org.kaaproject.kaa.server.common.dao.service; -import static org.apache.commons.lang.StringUtils.isBlank; -import static org.kaaproject.kaa.common.dto.UpdateStatus.ACTIVE; -import static org.kaaproject.kaa.common.dto.UpdateStatus.INACTIVE; -import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.convertDtoList; -import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.getDto; -import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.idToString; -import static org.kaaproject.kaa.server.common.dao.service.Validator.isValidId; -import static org.kaaproject.kaa.server.common.dao.service.Validator.validateId; -import static org.kaaproject.kaa.server.common.dao.service.Validator.validateSqlId; -import static org.kaaproject.kaa.server.common.dao.service.Validator.validateSqlObject; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - import org.apache.avro.Schema; import org.apache.avro.generic.GenericRecord; import org.apache.commons.lang.StringUtils; @@ -58,6 +42,7 @@ import org.kaaproject.kaa.server.common.core.configuration.BaseData; import org.kaaproject.kaa.server.common.core.configuration.BaseDataFactory; import org.kaaproject.kaa.server.common.core.configuration.KaaData; +import org.kaaproject.kaa.server.common.core.configuration.OverrideData; import org.kaaproject.kaa.server.common.core.configuration.OverrideDataFactory; import org.kaaproject.kaa.server.common.core.schema.BaseSchema; import org.kaaproject.kaa.server.common.core.schema.DataSchema; @@ -82,6 +67,23 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import static org.apache.commons.lang.StringUtils.isBlank; +import static org.kaaproject.kaa.common.dto.UpdateStatus.ACTIVE; +import static org.kaaproject.kaa.common.dto.UpdateStatus.INACTIVE; +import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.convertDtoList; +import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.getDto; +import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.idToString; +import static org.kaaproject.kaa.server.common.dao.service.Validator.isValidId; +import static org.kaaproject.kaa.server.common.dao.service.Validator.validateId; +import static org.kaaproject.kaa.server.common.dao.service.Validator.validateSqlId; +import static org.kaaproject.kaa.server.common.dao.service.Validator.validateSqlObject; + @Service @Transactional public class ConfigurationServiceImpl implements ConfigurationService { @@ -466,6 +468,34 @@ public ConfigurationSchemaDto saveConfSchema(ConfigurationSchemaDto configuratio return savedConfigSchema; } + @Override + public String validateConfiguration(String appId, int schemaVersion, String configurationBody) { + ConfigurationSchemaDto schemaDto = this.findConfSchemaByAppIdAndVersion(appId, schemaVersion); + if (schemaDto != null) { + OverrideSchema overrideSchema = new OverrideSchema(schemaDto.getOverrideSchema()); + LOG.debug("Create default UUID validator with override schema: {}", overrideSchema.getRawSchema()); + UuidValidator uuidValidator = new DefaultUuidValidator<>(overrideSchema, new OverrideDataFactory()); + GenericAvroConverter avroConverter = new GenericAvroConverter<>(overrideSchema.getRawSchema()); + try { + GenericRecord configRecord = avroConverter.decodeJson(configurationBody); + // TODO: Need to use last active configuration instead of null. Will be changed after supporting delta configuration + KaaData body = uuidValidator.validateUuidFields(configRecord, null); + if (body != null) { + return body.getRawData(); + } else { + LOG.warn("Validated configuration body is empty"); + throw new IncorrectParameterException("Validated configuration body is empty"); + } + } catch (IOException e) { + LOG.error("Invalid configuration for override schema.", e); + throw new IncorrectParameterException("Invalid configuration for override schema."); + } + } else { + LOG.warn("Can't find configuration schema with version {}.", schemaVersion); + throw new IncorrectParameterException("Can't find configuration schema for specified version."); + } + } + @Override public ConfigurationSchemaDto findConfSchemaById(String id) { validateSqlId(id, "Incorrect configuration schema id " + id + ". Can't find configuration schema."); diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/EndpointSpecificConfigurationServiceImpl.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/EndpointSpecificConfigurationServiceImpl.java new file mode 100644 index 0000000000..43cab7f738 --- /dev/null +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/EndpointSpecificConfigurationServiceImpl.java @@ -0,0 +1,112 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * 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 org.kaaproject.kaa.server.common.dao.service; + +import org.kaaproject.kaa.common.dto.EndpointProfileDto; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; +import org.kaaproject.kaa.server.common.dao.ConfigurationService; +import org.kaaproject.kaa.server.common.dao.EndpointService; +import org.kaaproject.kaa.server.common.dao.EndpointSpecificConfigurationService; +import org.kaaproject.kaa.server.common.dao.impl.EndpointSpecificConfigurationDao; +import org.kaaproject.kaa.server.common.dao.model.EndpointSpecificConfiguration; +import org.kaaproject.kaa.server.common.dao.model.ToDto; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.Base64Utils; + +import java.util.Optional; + +import static org.kaaproject.kaa.server.common.dao.service.Validator.validateString; + +@Service +public class EndpointSpecificConfigurationServiceImpl implements EndpointSpecificConfigurationService { + + private static final Logger LOG = LoggerFactory.getLogger(EndpointSpecificConfigurationServiceImpl.class); + + private EndpointSpecificConfigurationDao endpointSpecificConfigurationDao; + @Autowired + private EndpointService endpointService; + @Autowired + private ConfigurationService configurationService; + + @Override + public Optional findByEndpointKeyHash(String endpointKeyHash) { + LOG.debug("Looking for endpoint specific configuration by EP key hash {}", endpointKeyHash); + EndpointProfileDto profileDto = getEndpointProfileDto(endpointKeyHash); + if (profileDto == null) { + return Optional.empty(); + } + EndpointSpecificConfiguration configuration = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(endpointKeyHash, profileDto.getConfigurationVersion()); + return Optional.ofNullable(configuration).map(ToDto::toDto); + } + + @Override + public Optional findByEndpointProfile(EndpointProfileDto endpointProfileDto) { + String base64EncodedEndpointKeyHash = Base64Utils.encodeToString(endpointProfileDto.getEndpointKeyHash()); + int configurationVersion = endpointProfileDto.getConfigurationVersion(); + EndpointSpecificConfiguration configuration = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(base64EncodedEndpointKeyHash, configurationVersion); + return Optional.ofNullable(configuration).map(ToDto::toDto); + + } + + @Override + public Optional deleteByEndpointKeyHash(String endpointKeyHash) { + Optional configuration = findByEndpointKeyHash(endpointKeyHash); + if (configuration.isPresent()) { + endpointSpecificConfigurationDao.removeByEndpointKeyHash(endpointKeyHash); + } + return configuration; + } + + @Override + public EndpointSpecificConfigurationDto save(EndpointSpecificConfigurationDto configurationDto) { + EndpointProfileDto profileDto = getEndpointProfileDto(configurationDto.getEndpointKeyHash()); + configurationDto.setConfigurationVersion(profileDto.getConfigurationVersion()); + validateConfigurationBody(configurationDto, profileDto); + return endpointSpecificConfigurationDao.save(configurationDto).toDto(); + } + + private EndpointProfileDto getEndpointProfileDto(String endpointKeyHash) { + validateString(endpointKeyHash, "Endpoint key hash is required"); + return endpointService.findEndpointProfileByKeyHash(Base64Utils.decodeFromString(endpointKeyHash)); + } + + + private void validateConfigurationBody(EndpointSpecificConfigurationDto configurationDto, EndpointProfileDto ep) { + validateString(configurationDto.getConfiguration(), "Endpoint specific configuration body is required"); + int configurationVersion = configurationDto.getConfigurationVersion(); + String appId = ep.getApplicationId(); + String configurationBody = configurationDto.getConfiguration(); + configurationBody = configurationService.validateConfiguration(appId, configurationVersion, configurationBody); + validateString(configurationBody, "Provided configuration body is invalid"); + configurationDto.setConfiguration(configurationBody); + } + + public void setEndpointSpecificConfigurationDao(EndpointSpecificConfigurationDao endpointSpecificConfigurationDao) { + this.endpointSpecificConfigurationDao = endpointSpecificConfigurationDao; + } + + public void setEndpointService(EndpointService endpointService) { + this.endpointService = endpointService; + } + + public void setConfigurationService(ConfigurationService configurationService) { + this.configurationService = configurationService; + } +} diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImpl.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImpl.java index 069b9bab55..bb532cdebe 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImpl.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImpl.java @@ -16,17 +16,8 @@ package org.kaaproject.kaa.server.common.dao.service; -import org.apache.avro.generic.GenericRecord; -import org.kaaproject.kaa.common.avro.GenericAvroConverter; import org.kaaproject.kaa.common.dto.ApplicationDto; -import org.kaaproject.kaa.common.dto.ConfigurationSchemaDto; import org.kaaproject.kaa.common.dto.EndpointUserConfigurationDto; -import org.kaaproject.kaa.server.common.core.algorithms.validator.DefaultUuidValidator; -import org.kaaproject.kaa.server.common.core.algorithms.validator.UuidValidator; -import org.kaaproject.kaa.server.common.core.configuration.KaaData; -import org.kaaproject.kaa.server.common.core.configuration.OverrideData; -import org.kaaproject.kaa.server.common.core.configuration.OverrideDataFactory; -import org.kaaproject.kaa.server.common.core.schema.OverrideSchema; import org.kaaproject.kaa.server.common.dao.ApplicationService; import org.kaaproject.kaa.server.common.dao.ConfigurationService; import org.kaaproject.kaa.server.common.dao.UserConfigurationService; @@ -40,7 +31,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.io.IOException; import java.util.List; import static org.apache.commons.lang.StringUtils.isNotBlank; @@ -72,31 +62,8 @@ public EndpointUserConfigurationDto saveUserConfiguration(EndpointUserConfigurat ApplicationDto applicationDto = applicationService.findAppByApplicationToken(appToken); if (applicationDto != null) { int schemaVersion = userConfig.getSchemaVersion(); - ConfigurationSchemaDto schemaDto = configurationService.findConfSchemaByAppIdAndVersion(applicationDto.getId(), schemaVersion); - if (schemaDto != null) { - OverrideSchema overrideSchema = new OverrideSchema(schemaDto.getOverrideSchema()); - LOG.debug("Create default UUID validator with override schema: {}", overrideSchema.getRawSchema()); - UuidValidator uuidValidator = new DefaultUuidValidator<>(overrideSchema, new OverrideDataFactory()); - GenericAvroConverter avroConverter = new GenericAvroConverter<>(overrideSchema.getRawSchema()); - try { - GenericRecord configRecord = avroConverter.decodeJson(userConfigBody); - // TODO: Need to use last active configuration instead of null. Will be changed after supporting delta configuration - KaaData body = uuidValidator.validateUuidFields(configRecord, null); - if (body != null) { - userConfig.setBody(body.getRawData()); - userConfigurationDto = getDto(endpointUserConfigurationDao.save(userConfig)); - } else { - LOG.warn("Validated endpoint user configuration body is empty"); - throw new IncorrectParameterException("Validated endpoint user configuration body is empty"); - } - } catch (IOException e) { - LOG.error("Invalid endpoint user configuration for override schema.", e); - throw new IncorrectParameterException("Invalid endpoint user configuration for override schema."); - } - } else { - LOG.warn("Can't find configuration schema with version {} for endpoint user configuration.", schemaVersion); - throw new IncorrectParameterException("Can't find configuration schema for specified version."); - } + userConfig.setBody(configurationService.validateConfiguration(applicationDto.getId(), schemaVersion, userConfigBody)); + userConfigurationDto = getDto(endpointUserConfigurationDao.save(userConfig)); } else { LOG.warn("Can't find application with token {} for endpoint user configuration.", appToken); throw new IncorrectParameterException("Can't find application for specified token."); diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/Validator.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/Validator.java index 521619eeeb..20a414d2ba 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/Validator.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/Validator.java @@ -151,6 +151,32 @@ public static void validateString(String id, String errorMessage) { } } + /** + * This method validates Object object. If object is not null than throw + * IncorrectParameterException exception + * + * @param obj the obj + * @param errorMessage the error message for exception + */ + public static void validateNull(Object obj, String errorMessage) { + if (obj != null) { + throw new IncorrectParameterException(errorMessage); + } + } + + /** + * This method validates Object object. If object is null than throw + * IncorrectParameterException exception + * + * @param obj the obj + * @param errorMessage the error message for exception + */ + public static void validateNotNull(Object obj, String errorMessage) { + if (obj == null) { + throw new IncorrectParameterException(errorMessage); + } + } + /** * This method validate byte array hash. If hash is invalid than throw * IncorrectParameterException exception diff --git a/server/common/dao/src/main/resources/common-dao-context.xml b/server/common/dao/src/main/resources/common-dao-context.xml index 47de446fc3..e81ffb747c 100644 --- a/server/common/dao/src/main/resources/common-dao-context.xml +++ b/server/common/dao/src/main/resources/common-dao-context.xml @@ -84,7 +84,11 @@ - + + + + diff --git a/server/common/dao/src/main/resources/nosql-dao.properties b/server/common/dao/src/main/resources/nosql-dao.properties index 8aa95b9479..439769ef96 100644 --- a/server/common/dao/src/main/resources/nosql-dao.properties +++ b/server/common/dao/src/main/resources/nosql-dao.properties @@ -1,3 +1,3 @@ # NoSQL database provider name, autogenerated when mongo-dao or cassandra-dao profile is activated # Possible options: mongodb, cassandra -nosql_db_provider_name=mongodb +nosql_db_provider_name=cassandra diff --git a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/AbstractTest.java b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/AbstractTest.java index 25c9f9f2fe..f8fa5dca61 100644 --- a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/AbstractTest.java +++ b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/AbstractTest.java @@ -16,31 +16,6 @@ package org.kaaproject.kaa.server.common.dao; -import static org.apache.commons.lang.StringUtils.isBlank; -import static org.apache.commons.lang.StringUtils.isNotBlank; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.charset.Charset; -import java.nio.file.FileSystem; -import java.nio.file.FileSystemAlreadyExistsException; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Random; -import java.util.UUID; - -import javax.sql.DataSource; - import org.junit.Assert; import org.kaaproject.kaa.common.dto.ApplicationDto; import org.kaaproject.kaa.common.dto.ChangeConfigurationNotification; @@ -66,8 +41,6 @@ import org.kaaproject.kaa.common.dto.TopicTypeDto; import org.kaaproject.kaa.common.dto.UpdateNotificationDto; import org.kaaproject.kaa.common.dto.UserDto; -import org.kaaproject.kaa.common.dto.credentials.CredentialsDto; -import org.kaaproject.kaa.common.dto.credentials.CredentialsStatus; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.common.dto.logs.LogAppenderDto; @@ -79,32 +52,30 @@ import org.kaaproject.kaa.server.common.core.configuration.OverrideDataFactory; import org.kaaproject.kaa.server.common.core.schema.BaseSchema; import org.kaaproject.kaa.server.common.core.schema.KaaSchema; -import org.kaaproject.kaa.server.common.core.schema.KaaSchemaFactoryImpl; import org.kaaproject.kaa.server.common.core.schema.OverrideSchema; -import org.kaaproject.kaa.server.common.dao.exception.CredentialsServiceException; import org.kaaproject.kaa.server.common.dao.exception.DatabaseProcessingException; -import org.kaaproject.kaa.server.common.dao.impl.LogAppenderDao; -import org.kaaproject.kaa.server.common.dao.impl.TenantDao; -import org.kaaproject.kaa.server.common.dao.impl.UserDao; import org.kaaproject.kaa.server.common.dao.impl.ApplicationDao; -import org.kaaproject.kaa.server.common.dao.impl.EndpointGroupDao; -import org.kaaproject.kaa.server.common.dao.impl.ConfigurationSchemaDao; +import org.kaaproject.kaa.server.common.dao.impl.ApplicationEventFamilyMapDao; +import org.kaaproject.kaa.server.common.dao.impl.CTLSchemaDao; +import org.kaaproject.kaa.server.common.dao.impl.CTLSchemaMetaInfoDao; import org.kaaproject.kaa.server.common.dao.impl.ConfigurationDao; -import org.kaaproject.kaa.server.common.dao.impl.ProfileSchemaDao; -import org.kaaproject.kaa.server.common.dao.impl.ProfileFilterDao; -import org.kaaproject.kaa.server.common.dao.impl.TopicDao; -import org.kaaproject.kaa.server.common.dao.impl.HistoryDao; -import org.kaaproject.kaa.server.common.dao.impl.EventClassFamilyDao; +import org.kaaproject.kaa.server.common.dao.impl.ConfigurationSchemaDao; +import org.kaaproject.kaa.server.common.dao.impl.EndpointGroupDao; import org.kaaproject.kaa.server.common.dao.impl.EventClassDao; -import org.kaaproject.kaa.server.common.dao.impl.ApplicationEventFamilyMapDao; +import org.kaaproject.kaa.server.common.dao.impl.EventClassFamilyDao; +import org.kaaproject.kaa.server.common.dao.impl.HistoryDao; +import org.kaaproject.kaa.server.common.dao.impl.LogAppenderDao; import org.kaaproject.kaa.server.common.dao.impl.LogSchemaDao; -import org.kaaproject.kaa.server.common.dao.impl.NotificationSchemaDao; import org.kaaproject.kaa.server.common.dao.impl.NotificationDao; -import org.kaaproject.kaa.server.common.dao.impl.UserVerifierDao; +import org.kaaproject.kaa.server.common.dao.impl.NotificationSchemaDao; +import org.kaaproject.kaa.server.common.dao.impl.ProfileFilterDao; +import org.kaaproject.kaa.server.common.dao.impl.ProfileSchemaDao; import org.kaaproject.kaa.server.common.dao.impl.SdkProfileDao; -import org.kaaproject.kaa.server.common.dao.impl.CTLSchemaDao; -import org.kaaproject.kaa.server.common.dao.impl.CTLSchemaMetaInfoDao; import org.kaaproject.kaa.server.common.dao.impl.ServerProfileSchemaDao; +import org.kaaproject.kaa.server.common.dao.impl.TenantDao; +import org.kaaproject.kaa.server.common.dao.impl.TopicDao; +import org.kaaproject.kaa.server.common.dao.impl.UserDao; +import org.kaaproject.kaa.server.common.dao.impl.UserVerifierDao; import org.kaaproject.kaa.server.common.dao.impl.sql.H2DBTestRunner; import org.kaaproject.kaa.server.common.dao.impl.sql.MariaDBTestRunner; import org.kaaproject.kaa.server.common.dao.impl.sql.PostgreDBTestRunner; @@ -136,10 +107,35 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ActiveProfiles; +import javax.sql.DataSource; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.Charset; +import java.nio.file.FileSystem; +import java.nio.file.FileSystemAlreadyExistsException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Random; +import java.util.UUID; + +import static org.apache.commons.lang.StringUtils.isBlank; +import static org.apache.commons.lang.StringUtils.isNotBlank; + @ActiveProfiles({"h2"}) public class AbstractTest { private static final Logger LOG = LoggerFactory.getLogger(AbstractTest.class); + private static final byte[] EPS_CONFIG_HASH = "eps_hash_conf".getBytes(); protected static final Random RANDOM = new Random(0); protected static final String SUPER_TENANT = "SuperTenant"; @@ -747,6 +743,7 @@ protected EndpointProfileDto generateEndpointProfileDto(String appId, List implements EndpointSpecificConfigurationDao { + + private static final Logger LOG = LoggerFactory.getLogger(EndpointSpecificConfigurationCassandraDao.class); + + @Override + protected Class getColumnFamilyClass() { + return CassandraEndpointSpecificConfiguration.class; + } + + @Override + protected String getColumnFamilyName() { + return EPS_CONFIGURATION_COLUMN_FAMILY_NAME; + } + + @Override + public void removeById(String id) { + throw new NotImplementedException(); + } + + @Override + public CassandraEndpointSpecificConfiguration findById(String id) { + throw new NotImplementedException(); + } + + @Override + public void removeByEndpointKeyHash(String endpointKeyHash) { + LOG.debug("Remove endpoint specific configuration by endpointKeyHash {}", endpointKeyHash); + Delete.Where deleteQuery = delete().from(getColumnFamilyName()) + .where(eq(EPS_CONFIGURATION_KEY_HASH_PROPERTY, endpointKeyHash)); + LOG.trace("Remove endpoint specific configuration by endpointKeyHash query {}", deleteQuery); + execute(deleteQuery); + } + + @Override + public CassandraEndpointSpecificConfiguration findByEndpointKeyHashAndConfigurationVersion(String endpointKeyHash, int configurationVersion) { + LOG.debug("Try to find endpoint specific configuration by endpointKeyHash {} and configurationVersion {}", endpointKeyHash, configurationVersion); + Select.Where where = select().from(getColumnFamilyName()) + .where(eq(EPS_CONFIGURATION_KEY_HASH_PROPERTY, endpointKeyHash)) + .and(eq(EPS_CONFIGURATION_CONFIGURATION_VERSION_PROPERTY, configurationVersion)); + LOG.trace("Try to find endpoint specific configuration by cql select {}", where); + CassandraEndpointSpecificConfiguration configuration = findOneByStatement(where); + LOG.trace("Found {} endpoint specific configuration", configuration); + return configuration; + } + + @Override + public EndpointSpecificConfiguration save(EndpointSpecificConfigurationDto dto) { + LOG.debug("Saving endpoint specific configuration {}", dto); + EndpointSpecificConfiguration configuration = save(new CassandraEndpointSpecificConfiguration(dto)); + if (LOG.isTraceEnabled()) { + LOG.trace("Saved: {}", configuration); + } else { + LOG.debug("Saved: {}", configuration != null); + } + return configuration; + + } + +} diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointProfile.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointProfile.java index ff4c460517..f12f187f45 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointProfile.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointProfile.java @@ -16,17 +16,11 @@ package org.kaaproject.kaa.server.common.nosql.cassandra.dao.model; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.OPT_LOCK; -import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.convertDtoToModelList; -import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.convertECFVersionDtoToModelList; -import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.getByteBuffer; -import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.getBytes; -import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.*; - -import java.io.Serializable; -import java.nio.ByteBuffer; -import java.util.List; - +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.FrozenValue; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; +import com.datastax.driver.mapping.annotations.Transient; import org.kaaproject.kaa.common.dto.EndpointProfileDto; import org.kaaproject.kaa.common.dto.EventClassFamilyVersionStateDto; import org.kaaproject.kaa.server.common.dao.impl.DaoUtil; @@ -34,11 +28,44 @@ import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.type.CassandraEndpointGroupState; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.type.CassandraEventClassFamilyVersionState; -import com.datastax.driver.mapping.annotations.Column; -import com.datastax.driver.mapping.annotations.FrozenValue; -import com.datastax.driver.mapping.annotations.PartitionKey; -import com.datastax.driver.mapping.annotations.Table; -import com.datastax.driver.mapping.annotations.Transient; +import java.io.Serializable; +import java.nio.ByteBuffer; +import java.util.List; + +import static org.kaaproject.kaa.server.common.dao.DaoConstants.OPT_LOCK; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.convertDtoToModelList; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.convertECFVersionDtoToModelList; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.getByteBuffer; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.getBytes; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_ACCESS_TOKEN_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_APP_ID_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_COLUMN_FAMILY_NAME; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_CONFIGURATION_VERSION_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_CONFIG_HASH_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_ECF_VERSION_STATE_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_ENDPOINT_ID_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_EPS_CONFIG_HASH_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_EP_KEY_HASH_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_EP_KEY_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_GROUP_STATE_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_LOG_SCHEMA_VERSION_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_NOTIFICATION_VERSION_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_PROFILE_HASH_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_PROFILE_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_PROFILE_VERSION_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SDK_TOKEN_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SEQUENCE_NUMBER_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SERVER_HASH_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SERVER_PROFILE_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SERVER_PROFILE_VERSION_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SIMPLE_TOPIC_HASH_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SUBSCRIPTIONS_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SYSTEM_NOTIFICATION_VERSION_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_TOPIC_HASH_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_USER_CONFIG_HASH_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_USER_ID_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_USER_NOTIFICATION_VERSION_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_USE_RAW_SCHEMA; @Table(name = EP_COLUMN_FAMILY_NAME) public final class CassandraEndpointProfile implements EndpointProfile, Serializable { @@ -76,6 +103,8 @@ public final class CassandraEndpointProfile implements EndpointProfile, Serializ private ByteBuffer configurationHash; @Column(name = EP_USER_CONFIG_HASH_PROPERTY) private ByteBuffer userConfigurationHash; + @Column(name = EP_EPS_CONFIG_HASH_PROPERTY) + private ByteBuffer epsConfigurationHash; @Column(name = EP_CONFIGURATION_VERSION_PROPERTY) private int configurationVersion; @Column(name = EP_NOTIFICATION_VERSION_PROPERTY) @@ -140,6 +169,7 @@ public CassandraEndpointProfile(EndpointProfileDto dto) { this.serverProfile = dto.getServerProfileBody(); this.useConfigurationRawSchema = dto.isUseConfigurationRawSchema(); this.version = dto.getVersion(); + this.epsConfigurationHash = getByteBuffer(dto.getEpsConfigurationHash()); } public void setId(String id) { @@ -247,6 +277,14 @@ public void setUserConfigurationHash(ByteBuffer userConfigurationHash) { this.userConfigurationHash = userConfigurationHash; } + public ByteBuffer getEpsConfigurationHash() { + return epsConfigurationHash; + } + + public void setEpsConfigurationHash(ByteBuffer epsConfigurationHash) { + this.epsConfigurationHash = epsConfigurationHash; + } + public int getConfigurationVersion() { return configurationVersion; } @@ -402,6 +440,8 @@ public boolean equals(Object o) { if (configurationHash != null ? !configurationHash.equals(that.configurationHash) : that.configurationHash != null) return false; if (userConfigurationHash != null ? !userConfigurationHash.equals(that.userConfigurationHash) : that.userConfigurationHash != null) return false; + if (epsConfigurationHash != null ? !epsConfigurationHash.equals(that.epsConfigurationHash) : that.epsConfigurationHash != null) + return false; if (subscriptions != null ? !subscriptions.equals(that.subscriptions) : that.subscriptions != null) return false; if (topicHash != null ? !topicHash.equals(that.topicHash) : that.topicHash != null) return false; if (ecfVersionStates != null ? !ecfVersionStates.equals(that.ecfVersionStates) : that.ecfVersionStates != null) return false; @@ -430,6 +470,7 @@ public int hashCode() { result = 31 * result + serverProfileVersion; result = 31 * result + (configurationHash != null ? configurationHash.hashCode() : 0); result = 31 * result + (userConfigurationHash != null ? userConfigurationHash.hashCode() : 0); + result = 31 * result + (epsConfigurationHash != null ? epsConfigurationHash.hashCode() : 0); result = 31 * result + configurationVersion; result = 31 * result + notificationVersion; result = 31 * result + (subscriptions != null ? subscriptions.hashCode() : 0); @@ -462,6 +503,7 @@ public String toString() { ", serverProfileVersion=" + serverProfileVersion + ", configurationHash=" + configurationHash + ", userConfigurationHash=" + userConfigurationHash + + ", epsConfigurationHash=" + epsConfigurationHash + ", configurationVersion=" + configurationVersion + ", notificationVersion=" + notificationVersion + ", subscriptions=" + subscriptions + @@ -509,6 +551,7 @@ public EndpointProfileDto toDto() { dto.setServerProfileBody(serverProfile); dto.setUseConfigurationRawSchema(useConfigurationRawSchema); dto.setVersion(version); + dto.setEpsConfigurationHash(getBytes(epsConfigurationHash)); return dto; } } diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointSpecificConfiguration.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointSpecificConfiguration.java new file mode 100644 index 0000000000..028c1be858 --- /dev/null +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointSpecificConfiguration.java @@ -0,0 +1,122 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * 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 org.kaaproject.kaa.server.common.nosql.cassandra.dao.model; + +import com.datastax.driver.mapping.annotations.ClusteringColumn; +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; +import com.datastax.driver.mapping.annotations.Transient; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; +import org.kaaproject.kaa.server.common.dao.model.EndpointSpecificConfiguration; + +import java.io.Serializable; + +import static org.kaaproject.kaa.server.common.dao.DaoConstants.OPT_LOCK; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EPS_CONFIGURATION_CONFIGURATION_BODY_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EPS_CONFIGURATION_CONFIGURATION_VERSION_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EPS_CONFIGURATION_KEY_HASH_PROPERTY; + +@Table(name = CassandraModelConstants.EPS_CONFIGURATION_COLUMN_FAMILY_NAME) +public final class CassandraEndpointSpecificConfiguration implements EndpointSpecificConfiguration, Serializable { + @Transient + private static final long serialVersionUID = -8639669282952330290L; + + @PartitionKey + @Column(name = EPS_CONFIGURATION_KEY_HASH_PROPERTY) + private String endpointKeyHash; + @ClusteringColumn + @Column(name = EPS_CONFIGURATION_CONFIGURATION_VERSION_PROPERTY) + private Integer configurationVersion; + @Column(name = EPS_CONFIGURATION_CONFIGURATION_BODY_PROPERTY) + private String configuration; + @Column(name = OPT_LOCK) + private Long version; + + public CassandraEndpointSpecificConfiguration() { + } + + public CassandraEndpointSpecificConfiguration(EndpointSpecificConfigurationDto dto) { + this.endpointKeyHash = dto.getEndpointKeyHash(); + this.configurationVersion = dto.getConfigurationVersion(); + this.configuration = dto.getConfiguration(); + this.version = dto.getVersion(); + } + + @Override + public EndpointSpecificConfigurationDto toDto() { + EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto(); + dto.setEndpointKeyHash(this.getEndpointKeyHash()); + dto.setConfiguration(this.getConfiguration()); + dto.setConfigurationVersion(this.getConfigurationVersion()); + dto.setVersion(this.getVersion()); + return dto; + } + + public String getEndpointKeyHash() { + return endpointKeyHash; + } + + public void setEndpointKeyHash(String endpointKeyHash) { + this.endpointKeyHash = endpointKeyHash; + } + + public Integer getConfigurationVersion() { + return configurationVersion; + } + + public void setConfigurationVersion(Integer configurationVersion) { + this.configurationVersion = configurationVersion; + } + + public String getConfiguration() { + return configuration; + } + + public void setConfiguration(String configuration) { + this.configuration = configuration; + } + + @Override + public Long getVersion() { + return version; + } + + @Override + public void setVersion(Long version) { + this.version = version; + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + @Override + public boolean equals(Object other) { + return EqualsBuilder.reflectionEquals(this, other); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + } +} diff --git a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraModelConstants.java b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraModelConstants.java index 1dcfe4acec..61f1492e2f 100644 --- a/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraModelConstants.java +++ b/server/common/nosql/cassandra-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraModelConstants.java @@ -87,6 +87,7 @@ private CassandraModelConstants() { public static final String EP_APP_ID_PROPERTY = APPLICATION_ID_PROPERTY; public static final String EP_CONFIG_HASH_PROPERTY = CONFIGURATION_HASH_PROPERTY; public static final String EP_USER_CONFIG_HASH_PROPERTY = USER_CONFIGURATION_HASH_PROPERTY; + public static final String EP_EPS_CONFIG_HASH_PROPERTY = "eps_cf_hash"; public static final String EP_ACCESS_TOKEN_PROPERTY = ACCESS_TOKEN_PROPERTY; public static final String EP_ENDPOINT_ID_PROPERTY = "ep_id"; public static final String EP_EP_KEY_HASH_PROPERTY = ENDPOINT_KEY_HASH_PROPERTY; @@ -215,6 +216,14 @@ private CassandraModelConstants() { public static final String EP_REGISTRATION_BY_ENDPOINT_ID_CREDENTIALS_ID_PROPERTY = EP_REGISTRATION_CREDENTIALS_ID_PROPERTY; public static final String EP_REGISTRATION_BY_ENDPOINT_ID_ENDPOINT_ID_PROPERTY = EP_REGISTRATION_ENDPOINT_ID_PROPERTY; + /** + * {@link org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEndpointSpecificConfiguration} + */ + public static final String EPS_CONFIGURATION_COLUMN_FAMILY_NAME = "ep_specific_conf"; + public static final String EPS_CONFIGURATION_KEY_HASH_PROPERTY = ENDPOINT_KEY_HASH_PROPERTY; + public static final String EPS_CONFIGURATION_CONFIGURATION_VERSION_PROPERTY = EP_CONFIGURATION_VERSION_PROPERTY; + public static final String EPS_CONFIGURATION_CONFIGURATION_BODY_PROPERTY = BODY_PROPERTY; + /** * Cassandra Credentials constants */ diff --git a/server/common/nosql/cassandra-dao/src/main/resources/cassandra.cql b/server/common/nosql/cassandra-dao/src/main/resources/cassandra.cql index ec8bee0dfb..44d5ed997b 100644 --- a/server/common/nosql/cassandra-dao/src/main/resources/cassandra.cql +++ b/server/common/nosql/cassandra-dao/src/main/resources/cassandra.cql @@ -73,6 +73,7 @@ CREATE TABLE IF NOT EXISTS kaa.ep_profile ( pf_ver int, srv_pf_ver int, ucf_hash blob, + eps_cf_hash blob, cf_hash blob, cf_ver int, topic_hash blob, @@ -149,4 +150,12 @@ CREATE TABLE IF NOT EXISTS kaa.credentials ( creds_body blob, creds_status text, PRIMARY KEY (creds_application_id, creds_id) -); \ No newline at end of file +); + +CREATE TABLE IF NOT EXISTS kaa.ep_specific_conf ( + ep_key_hash text, + cf_ver int, + body text, + opt_lock bigint, + PRIMARY KEY((ep_key_hash), cf_ver) +) WITH CLUSTERING ORDER BY (cf_ver DESC); \ No newline at end of file diff --git a/server/common/nosql/cassandra-dao/src/main/resources/common-dao-cassandra-context.xml b/server/common/nosql/cassandra-dao/src/main/resources/common-dao-cassandra-context.xml index 25b1c09d37..e74a534f35 100644 --- a/server/common/nosql/cassandra-dao/src/main/resources/common-dao-cassandra-context.xml +++ b/server/common/nosql/cassandra-dao/src/main/resources/common-dao-cassandra-context.xml @@ -42,5 +42,7 @@ + diff --git a/server/common/nosql/cassandra-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/AbstractCassandraTest.java b/server/common/nosql/cassandra-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/AbstractCassandraTest.java index 12dd01d6f6..154893c89f 100644 --- a/server/common/nosql/cassandra-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/AbstractCassandraTest.java +++ b/server/common/nosql/cassandra-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/AbstractCassandraTest.java @@ -19,28 +19,31 @@ import org.kaaproject.kaa.common.dto.CTLDataDto; import org.kaaproject.kaa.common.dto.EndpointGroupStateDto; import org.kaaproject.kaa.common.dto.EndpointProfileDto; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; import org.kaaproject.kaa.common.dto.EndpointUserDto; import org.kaaproject.kaa.common.dto.NotificationDto; import org.kaaproject.kaa.common.dto.NotificationTypeDto; import org.kaaproject.kaa.common.dto.credentials.CredentialsDto; import org.kaaproject.kaa.common.dto.credentials.CredentialsStatus; import org.kaaproject.kaa.common.dto.credentials.EndpointRegistrationDto; +import org.kaaproject.kaa.server.common.dao.impl.CredentialsDao; import org.kaaproject.kaa.server.common.dao.impl.EndpointConfigurationDao; import org.kaaproject.kaa.server.common.dao.impl.EndpointNotificationDao; import org.kaaproject.kaa.server.common.dao.impl.EndpointProfileDao; import org.kaaproject.kaa.server.common.dao.impl.EndpointRegistrationDao; +import org.kaaproject.kaa.server.common.dao.impl.EndpointSpecificConfigurationDao; import org.kaaproject.kaa.server.common.dao.impl.NotificationDao; import org.kaaproject.kaa.server.common.dao.impl.TopicListEntryDao; +import org.kaaproject.kaa.server.common.dao.model.Credentials; +import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraCredentials; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEndpointConfiguration; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEndpointNotification; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEndpointProfile; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEndpointRegistration; +import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEndpointSpecificConfiguration; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEndpointUser; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraNotification; import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraTopicListEntry; -import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraCredentials; -import org.kaaproject.kaa.server.common.dao.impl.CredentialsDao; -import org.kaaproject.kaa.server.common.dao.model.Credentials; import org.springframework.beans.factory.annotation.Autowired; import java.nio.ByteBuffer; @@ -52,6 +55,7 @@ public abstract class AbstractCassandraTest { private static final String TEST_ENDPOINT_GROUP_ID = "124"; + private static final byte[] EPS_CONFIG_HASH = "eps_hash_conf".getBytes(); @Autowired protected EndpointNotificationDao unicastNotificationDao; @@ -69,6 +73,8 @@ public abstract class AbstractCassandraTest { protected TopicListEntryDao topicListEntryDao; @Autowired protected CredentialsDao credentialsDao; + @Autowired + protected EndpointSpecificConfigurationDao endpointSpecificConfigurationDao; protected List generateEndpointNotification(ByteBuffer endpointKeyHash, int count) { List savedNotifications = new ArrayList<>(); @@ -149,6 +155,7 @@ protected EndpointProfileDto generateEndpointProfile(String appId, String sdkTok profileDto.setSubscriptions(topicIds); profileDto.setEndpointKeyHash(keyHash); profileDto.setAccessToken(accessToken); + profileDto.setEpsConfigurationHash(EPS_CONFIG_HASH); if (ctlDataDto != null) { profileDto.setServerProfileBody(ctlDataDto.getBody()); profileDto.setServerProfileVersion(ctlDataDto.getServerProfileVersion()); @@ -164,6 +171,7 @@ protected EndpointProfileDto generateEndpointProfileForTestUpdate(String id, byt profileDto.setAccessToken(generateStringId()); profileDto.setGroupState(cfGroupState); profileDto.setSdkToken(UUID.randomUUID().toString()); + profileDto.setEpsConfigurationHash(EPS_CONFIG_HASH); return profileDto; } @@ -178,6 +186,7 @@ protected EndpointProfileDto generateEndpointProfileWithEndpointGroupId(String a profileDto.setAccessToken(generateStringId()); profileDto.setClientProfileBody("test profile"); profileDto.setServerProfileBody("test server-side profile"); + profileDto.setEpsConfigurationHash(EPS_CONFIG_HASH); List groupState = new ArrayList<>(); groupState.add(new EndpointGroupStateDto(TEST_ENDPOINT_GROUP_ID, null, null)); profileDto.setGroupState(groupState); @@ -233,4 +242,12 @@ protected CredentialsDto generateCredentials(String applicationId, String creden CredentialsDto generatedCredentials = saved.toDto(); return generatedCredentials; } + + protected EndpointSpecificConfigurationDto generateEpsConfigurationDto(String endpointKeyHash, + Integer configurationVersion, + String configuration, + Long version) { + EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto(endpointKeyHash, configurationVersion, configuration, version); + return endpointSpecificConfigurationDao.save(dto).toDto(); + } } diff --git a/server/common/nosql/cassandra-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/EndpointSpecificConfigurationCassandraDaoTest.java b/server/common/nosql/cassandra-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/EndpointSpecificConfigurationCassandraDaoTest.java new file mode 100644 index 0000000000..776deb519c --- /dev/null +++ b/server/common/nosql/cassandra-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/EndpointSpecificConfigurationCassandraDaoTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * 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 org.kaaproject.kaa.server.common.nosql.cassandra.dao; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; +import org.kaaproject.kaa.server.common.dao.exception.KaaOptimisticLockingFailureException; +import org.kaaproject.kaa.server.common.dao.model.EndpointSpecificConfiguration; +import org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraEndpointSpecificConfiguration; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.List; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "/cassandra-client-test-context.xml") +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +public class EndpointSpecificConfigurationCassandraDaoTest extends AbstractCassandraTest { + + private static final String KEY = "key"; + private static final String KEY_2 = "key2"; + private static final String BODY = "body"; + private EndpointSpecificConfigurationDto saved1; + private EndpointSpecificConfigurationDto saved2; + private EndpointSpecificConfigurationDto saved3; + + @Test + public void testRemoveByEndpointKeyHash() throws Exception { + List found = endpointSpecificConfigurationDao.find(); + Assert.assertTrue(found.size() == 3); + endpointSpecificConfigurationDao.removeByEndpointKeyHash(KEY); + found = endpointSpecificConfigurationDao.find(); + Assert.assertTrue(found.size() == 1); + } + + @Test + public void testFindByEndpointKeyHashAndConfigurationVersion() throws Exception { + List found = endpointSpecificConfigurationDao.find(); + Assert.assertTrue(found.size() == 3); + EndpointSpecificConfigurationDto found1 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY, 0).toDto(); + EndpointSpecificConfigurationDto found2 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY, 1).toDto(); + EndpointSpecificConfigurationDto found3 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY_2, 0).toDto(); + EndpointSpecificConfiguration found4 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY_2, 4); + Assert.assertEquals(saved1, found1); + Assert.assertEquals(saved2, found2); + Assert.assertEquals(saved3, found3); + Assert.assertNull(found4); + } + + @Test(expected = KaaOptimisticLockingFailureException.class) + public void testLocking() throws Exception { + saved1 = generateEpsConfigurationDto(KEY, 1, BODY, 9L); + saved2 = generateEpsConfigurationDto(KEY, 1, BODY, 9L); + } + + @Before + public void setUp() throws Exception { + saved1 = generateEpsConfigurationDto(KEY, 0, BODY, null); + saved2 = generateEpsConfigurationDto(KEY, 1, BODY, null); + saved3 = generateEpsConfigurationDto(KEY_2, 0, BODY, null); + } + + @After + public void tearDown() throws Exception { + endpointSpecificConfigurationDao.removeAll(); + } +} \ No newline at end of file diff --git a/server/common/nosql/cassandra-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointSpecificConfigurationTest.java b/server/common/nosql/cassandra-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointSpecificConfigurationTest.java new file mode 100644 index 0000000000..7988e2c82e --- /dev/null +++ b/server/common/nosql/cassandra-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/cassandra/dao/model/CassandraEndpointSpecificConfigurationTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * 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 org.kaaproject.kaa.server.common.nosql.cassandra.dao.model; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Assert; +import org.junit.Test; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; + +public class CassandraEndpointSpecificConfigurationTest { + + @Test + public void hashCodeEqualsTest() { + EqualsVerifier.forClass(CassandraEndpointSpecificConfiguration.class).suppress(Warning.NONFINAL_FIELDS).verify(); + } + + @Test + public void dataConversionTest() throws Exception { + EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto("hash", 1, "conf body", 2L); + CassandraEndpointSpecificConfiguration configuration = new CassandraEndpointSpecificConfiguration(dto); + Assert.assertEquals(dto, configuration.toDto()); + } +} diff --git a/server/common/nosql/cassandra-dao/src/test/resources/cassandra-client-test-context.xml b/server/common/nosql/cassandra-dao/src/test/resources/cassandra-client-test-context.xml index b0da74576a..ad44937482 100644 --- a/server/common/nosql/cassandra-dao/src/test/resources/cassandra-client-test-context.xml +++ b/server/common/nosql/cassandra-dao/src/test/resources/cassandra-client-test-context.xml @@ -49,5 +49,7 @@ + \ No newline at end of file diff --git a/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/EndpointSpecificConfigurationMongoDao.java b/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/EndpointSpecificConfigurationMongoDao.java new file mode 100644 index 0000000000..6d63edccbc --- /dev/null +++ b/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/EndpointSpecificConfigurationMongoDao.java @@ -0,0 +1,86 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * 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 org.kaaproject.kaa.server.common.nosql.mongo.dao; + +import org.apache.commons.lang.NotImplementedException; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; +import org.kaaproject.kaa.server.common.dao.impl.EndpointSpecificConfigurationDao; +import org.kaaproject.kaa.server.common.dao.model.EndpointSpecificConfiguration; +import org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoEndpointSpecificConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Repository; + +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_ENDPOINT_KEY_HASH; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SPECIFIC_CONFIGURATION; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SPECIFIC_CONFIGURATION_CONFIGURATION_VERSION; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SPECIFIC_CONFIGURATION_KEY_HASH; +import static org.springframework.data.mongodb.core.query.Criteria.where; +import static org.springframework.data.mongodb.core.query.Query.query; + +@Repository +public class EndpointSpecificConfigurationMongoDao extends AbstractVersionableMongoDao implements EndpointSpecificConfigurationDao { + + private static final Logger LOG = LoggerFactory.getLogger(EndpointSpecificConfigurationMongoDao.class); + + @Override + public void removeByEndpointKeyHash(String endpointKeyHash) { + LOG.debug("Remove endpoint specific configuration by endpoint key hash [{}] ", endpointKeyHash); + mongoTemplate.remove(query(where(EP_ENDPOINT_KEY_HASH).is(endpointKeyHash)), getCollectionName()); + } + + @Override + public EndpointSpecificConfiguration findByEndpointKeyHashAndConfigurationVersion(String endpointKeyHash, int configurationVersion) { + LOG.debug("Try to find endpoint specific configuration by endpointKeyHash {} and configurationVersion {}", endpointKeyHash, configurationVersion); + EndpointSpecificConfiguration configuration = findOne(query(where(EP_SPECIFIC_CONFIGURATION_KEY_HASH).is(endpointKeyHash) + .and(EP_SPECIFIC_CONFIGURATION_CONFIGURATION_VERSION).is(configurationVersion))); + LOG.trace("Found {} endpoint specific configuration", configuration); + return configuration; + } + + @Override + public EndpointSpecificConfiguration save(EndpointSpecificConfigurationDto dto) { + LOG.debug("Saving endpoint specific configuration {}", dto); + MongoEndpointSpecificConfiguration configuration = save(new MongoEndpointSpecificConfiguration(dto)); + if (LOG.isTraceEnabled()) { + LOG.trace("Saved: {}", configuration); + } else { + LOG.debug("Saved: {}", configuration != null); + } + return configuration; + } + + @Override + public MongoEndpointSpecificConfiguration findById(String key) { + throw new NotImplementedException(); + } + + @Override + public void removeById(String key) { + throw new NotImplementedException(); + } + + @Override + protected String getCollectionName() { + return EP_SPECIFIC_CONFIGURATION; + } + + @Override + protected Class getDocumentClass() { + return MongoEndpointSpecificConfiguration.class; + } +} diff --git a/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoEndpointProfile.java b/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoEndpointProfile.java index fc07d54cab..28d21c4862 100644 --- a/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoEndpointProfile.java +++ b/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoEndpointProfile.java @@ -16,14 +16,8 @@ package org.kaaproject.kaa.server.common.nosql.mongo.dao.model; -import static org.kaaproject.kaa.server.common.dao.DaoConstants.OPT_LOCK; -import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.getArrayCopy; -import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.*; - -import java.io.Serializable; -import java.util.Arrays; -import java.util.List; - +import com.mongodb.DBObject; +import com.mongodb.util.JSON; import org.kaaproject.kaa.common.dto.EndpointProfileDto; import org.kaaproject.kaa.server.common.dao.impl.DaoUtil; import org.kaaproject.kaa.server.common.dao.model.EndpointProfile; @@ -33,8 +27,39 @@ import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Field; -import com.mongodb.DBObject; -import com.mongodb.util.JSON; +import java.io.Serializable; +import java.util.Arrays; +import java.util.List; + +import static org.kaaproject.kaa.server.common.dao.DaoConstants.OPT_LOCK; +import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.getArrayCopy; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.ENDPOINT_PROFILE; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_ACCESS_TOKEN; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_APPLICATION_ID; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_CHANGED_FLAG; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_CONFIGURATION_HASH; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_CONFIGURATION_VERSION; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_ECF_VERSION_STATE; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_ENDPOINT_KEY; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_ENDPOINT_KEY_HASH; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_EPS_CONFIGURATION_HASH; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_GROUP_STATE; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_LOG_SCHEMA_VERSION; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_NOTIFICATION_VERSION; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_PROFILE_HASH; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_PROFILE_VERSION; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SDK_TOKEN; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SEQ_NUM; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SERVER_HASH; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SERVER_PROFILE_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SERVER_PROFILE_VERSION_PROPERTY; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SIMPLE_TOPIC_HASH; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SYSTEM_NF_VERSION; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_TOPIC_HASH; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_USER_CONFIGURATION_HASH; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_USER_ID; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_USER_NF_VERSION; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_USE_RAW_SCHEMA; @Document(collection = ENDPOINT_PROFILE) public final class MongoEndpointProfile implements EndpointProfile, Serializable { @@ -73,6 +98,8 @@ public final class MongoEndpointProfile implements EndpointProfile, Serializable private byte[] configurationHash; @Field(EP_USER_CONFIGURATION_HASH) private byte[] userConfigurationHash; + @Field(EP_EPS_CONFIGURATION_HASH) + private byte[] epsConfigurationHash; @Field(EP_CONFIGURATION_VERSION) private int configurationVersion; @Field(EP_NOTIFICATION_VERSION) @@ -125,6 +152,7 @@ public MongoEndpointProfile(EndpointProfileDto dto, Long version) { this.serverProfileVersion = dto.getServerProfileVersion(); this.configurationHash = dto.getConfigurationHash(); this.userConfigurationHash = dto.getUserConfigurationHash(); + this.epsConfigurationHash = dto.getEpsConfigurationHash(); this.configurationVersion = dto.getConfigurationVersion(); this.subscriptions = dto.getSubscriptions(); this.notificationVersion = dto.getNotificationVersion(); @@ -250,6 +278,14 @@ public void setUserConfigurationHash(byte[] userConfigurationHash) { this.userConfigurationHash = getArrayCopy(userConfigurationHash); } + public byte[] getEpsConfigurationHash() { + return epsConfigurationHash; + } + + public void setEpsConfigurationHash(byte[] epsConfigurationHash) { + this.epsConfigurationHash = epsConfigurationHash; + } + public int getConfigurationVersion() { return configurationVersion; } @@ -400,6 +436,9 @@ public boolean equals(Object o) { if (!Arrays.equals(userConfigurationHash, that.userConfigurationHash)) { return false; } + if (!Arrays.equals(epsConfigurationHash, that.epsConfigurationHash)) { + return false; + } if (groupState != null ? !groupState.equals(that.groupState) : that.groupState != null) { return false; } @@ -445,6 +484,7 @@ public int hashCode() { result = 31 * result + serverProfileVersion; result = 31 * result + (configurationHash != null ? Arrays.hashCode(configurationHash) : 0); result = 31 * result + (userConfigurationHash != null ? Arrays.hashCode(userConfigurationHash) : 0); + result = 31 * result + (epsConfigurationHash != null ? Arrays.hashCode(epsConfigurationHash) : 0); result = 31 * result + configurationVersion; result = 31 * result + notificationVersion; result = 31 * result + (subscriptions != null ? subscriptions.hashCode() : 0); @@ -472,6 +512,7 @@ public String toString() { ", serverProfileVersion=" + serverProfileVersion + ", configurationHash=" + Arrays.toString(configurationHash) + ", userConfigurationHash=" + Arrays.toString(userConfigurationHash) + + ", epsConfigurationHash=" + Arrays.toString(epsConfigurationHash) + ", configurationVersion=" + configurationVersion + ", notificationVersion=" + notificationVersion + ", subscriptions=" + subscriptions + @@ -493,6 +534,7 @@ public EndpointProfileDto toDto() { dto.setSequenceNumber(sequenceNumber); dto.setConfigurationHash(configurationHash); dto.setUserConfigurationHash(userConfigurationHash); + dto.setEpsConfigurationHash(epsConfigurationHash); dto.setConfigurationVersion(configurationVersion); dto.setApplicationId(applicationId); dto.setEndpointKey(endpointKey); diff --git a/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoEndpointSpecificConfiguration.java b/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoEndpointSpecificConfiguration.java new file mode 100644 index 0000000000..15dfbee6e3 --- /dev/null +++ b/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoEndpointSpecificConfiguration.java @@ -0,0 +1,132 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * 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 org.kaaproject.kaa.server.common.nosql.mongo.dao.model; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; +import org.kaaproject.kaa.server.common.dao.model.EndpointSpecificConfiguration; +import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.Version; +import org.springframework.data.mongodb.core.index.Indexed; +import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.core.mapping.Field; + +import java.io.Serializable; + +import static org.kaaproject.kaa.server.common.dao.DaoConstants.OPT_LOCK; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SPECIFIC_CONFIGURATION; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SPECIFIC_CONFIGURATION_CONFIGURATION; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SPECIFIC_CONFIGURATION_CONFIGURATION_VERSION; +import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SPECIFIC_CONFIGURATION_KEY_HASH; + +@Document(collection = EP_SPECIFIC_CONFIGURATION) +public class MongoEndpointSpecificConfiguration implements EndpointSpecificConfiguration, Serializable { + + private static final long serialVersionUID = 2913495348256356048L; + + @Id + private String id; + @Indexed + @Field(EP_SPECIFIC_CONFIGURATION_KEY_HASH) + private String endpointKeyHash; + @Field(EP_SPECIFIC_CONFIGURATION_CONFIGURATION_VERSION) + private Integer configurationVersion; + @Field(EP_SPECIFIC_CONFIGURATION_CONFIGURATION) + private String configuration; + @Version + @Field(OPT_LOCK) + private Long version; + + public MongoEndpointSpecificConfiguration() { + } + + public MongoEndpointSpecificConfiguration(EndpointSpecificConfigurationDto dto) { + this.endpointKeyHash = dto.getEndpointKeyHash(); + this.configurationVersion = dto.getConfigurationVersion(); + this.configuration = dto.getConfiguration(); + this.version = dto.getVersion(); + generateId(); + } + + + @Override + public EndpointSpecificConfigurationDto toDto() { + EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto(); + dto.setEndpointKeyHash(new String(this.getEndpointKeyHash())); + dto.setConfiguration(this.getConfiguration()); + dto.setConfigurationVersion(this.getConfigurationVersion()); + dto.setVersion(this.getVersion()); + return dto; + } + + protected void generateId() { + id = endpointKeyHash + '#' + configurationVersion; + } + + public String getEndpointKeyHash() { + return endpointKeyHash; + } + + public void setEndpointKeyHash(String endpointKeyHash) { + this.endpointKeyHash = endpointKeyHash; + } + + public Integer getConfigurationVersion() { + return configurationVersion; + } + + public void setConfigurationVersion(Integer configurationVersion) { + this.configurationVersion = configurationVersion; + } + + public String getConfiguration() { + return configuration; + } + + public void setConfiguration(String configuration) { + this.configuration = configuration; + } + + @Override + public Long getVersion() { + return version; + } + + @Override + public void setVersion(Long version) { + this.version = version; + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + @Override + public boolean equals(Object other) { + return EqualsBuilder.reflectionEquals(this, other); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + } + +} diff --git a/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoModelConstants.java b/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoModelConstants.java index 921771c075..9afcfa95bd 100644 --- a/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoModelConstants.java +++ b/server/common/nosql/mongo-dao/src/main/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoModelConstants.java @@ -95,6 +95,7 @@ private MongoModelConstants() { public static final String EP_SERVER_PROFILE_VERSION_PROPERTY = "srv_profile_version"; public static final String EP_CONFIGURATION_HASH = "configuration_hash"; public static final String EP_USER_CONFIGURATION_HASH = "user_configuration_hash"; + public static final String EP_EPS_CONFIGURATION_HASH = "eps_configuration_hash"; public static final String EP_CONFIGURATION_VERSION = "configuration_version"; public static final String EP_TOPIC_HASH = "topic_hash"; public static final String EP_SIMPLE_TOPIC_HASH = "simple_topic_hash"; @@ -136,6 +137,14 @@ private MongoModelConstants() { public static final String EP_REGISTRATION_SERVER_PROFILE_VERSION = "server_profile_version"; public static final String EP_REGISTRATION_SERVER_PROFILE_BODY = "server_profile"; + /** + * {@link org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoEndpointSpecificConfiguration} + */ + public static final String EP_SPECIFIC_CONFIGURATION = "endpoint_specific_configuration"; + public static final String EP_SPECIFIC_CONFIGURATION_KEY_HASH = EP_ENDPOINT_KEY_HASH; + public static final String EP_SPECIFIC_CONFIGURATION_CONFIGURATION_VERSION = EP_CONFIGURATION_VERSION; + public static final String EP_SPECIFIC_CONFIGURATION_CONFIGURATION = BODY; + /** * {@link org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoCredentials} */ diff --git a/server/common/nosql/mongo-dao/src/main/resources/common-dao-mongodb-context.xml b/server/common/nosql/mongo-dao/src/main/resources/common-dao-mongodb-context.xml index df90a5f01d..bc81fca6ba 100644 --- a/server/common/nosql/mongo-dao/src/main/resources/common-dao-mongodb-context.xml +++ b/server/common/nosql/mongo-dao/src/main/resources/common-dao-mongodb-context.xml @@ -50,6 +50,9 @@ + + diff --git a/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/AbstractMongoTest.java b/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/AbstractMongoTest.java index 523102d54b..fe3bfdb8b9 100644 --- a/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/AbstractMongoTest.java +++ b/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/AbstractMongoTest.java @@ -16,9 +16,8 @@ package org.kaaproject.kaa.server.common.nosql.mongo.dao; -import java.util.UUID; - import org.kaaproject.kaa.common.dto.EndpointConfigurationDto; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; import org.kaaproject.kaa.common.dto.credentials.CredentialsDto; import org.kaaproject.kaa.common.dto.credentials.CredentialsStatus; import org.kaaproject.kaa.common.dto.credentials.EndpointRegistrationDto; @@ -27,9 +26,11 @@ import org.kaaproject.kaa.server.common.dao.impl.EndpointConfigurationDao; import org.kaaproject.kaa.server.common.dao.impl.EndpointProfileDao; import org.kaaproject.kaa.server.common.dao.impl.EndpointRegistrationDao; +import org.kaaproject.kaa.server.common.dao.impl.EndpointSpecificConfigurationDao; import org.kaaproject.kaa.server.common.dao.impl.EndpointUserConfigurationDao; import org.kaaproject.kaa.server.common.dao.impl.TopicListEntryDao; import org.kaaproject.kaa.server.common.dao.model.Credentials; +import org.kaaproject.kaa.server.common.dao.model.EndpointSpecificConfiguration; import org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoEndpointConfiguration; import org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoEndpointProfile; import org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoEndpointRegistration; @@ -37,6 +38,8 @@ import org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoTopicListEntry; import org.springframework.beans.factory.annotation.Autowired; +import java.util.UUID; + public class AbstractMongoTest extends AbstractTest { @Autowired @@ -47,6 +50,8 @@ public class AbstractMongoTest extends AbstractTest { protected EndpointProfileDao endpointProfileDao; @Autowired protected TopicListEntryDao topicListEntryDao; + @Autowired + protected EndpointSpecificConfigurationDao endpointSpecificConfigurationDao; protected EndpointConfigurationDto generateEndpointConfiguration() { EndpointConfigurationDto configurationDto = new EndpointConfigurationDto(); @@ -89,4 +94,19 @@ protected EndpointRegistrationDto generateEndpointRegistration(String applicatio EndpointRegistrationDto endpointRegistration = new EndpointRegistrationDto(applicationId, endpointId, credentialsId, null, null); return this.endpointRegistrationDao.save(endpointRegistration).toDto(); } + + /** + * Constructs an endpoint specific configuration with the information provided and + * saves it to the database. + * + * @param endpointKeyHash The endpoint key hash + * @param configurationVersion The endpoint configuration version + * @param configuration The configuration body + * @param version The endpoint specific configuration version + * @return Saved endpoint specific configuration + */ + protected EndpointSpecificConfigurationDto generateEndpointSpecificConfigurationDto(String endpointKeyHash, Integer configurationVersion, String configuration, Long version) { + EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto(endpointKeyHash, configurationVersion, configuration, version); + return endpointSpecificConfigurationDao.save(dto).toDto(); + } } diff --git a/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/EndpointSpecificConfigurationMongoDaoTest.java b/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/EndpointSpecificConfigurationMongoDaoTest.java new file mode 100644 index 0000000000..3c07c33b4e --- /dev/null +++ b/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/EndpointSpecificConfigurationMongoDaoTest.java @@ -0,0 +1,96 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * 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 org.kaaproject.kaa.server.common.nosql.mongo.dao; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; +import org.kaaproject.kaa.server.common.dao.exception.KaaOptimisticLockingFailureException; +import org.kaaproject.kaa.server.common.dao.model.EndpointSpecificConfiguration; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.List; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "/mongo-dao-test-context.xml") +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +public class EndpointSpecificConfigurationMongoDaoTest extends AbstractMongoTest { + private static final String KEY = "key"; + private static final String KEY_2 = "key2"; + private static final String BODY = "body"; + private EndpointSpecificConfigurationDto saved1; + private EndpointSpecificConfigurationDto saved2; + private EndpointSpecificConfigurationDto saved3; + + @BeforeClass + public static void init() throws Exception { + MongoDBTestRunner.setUp(); + } + + @AfterClass + public static void after() throws Exception { + MongoDBTestRunner.tearDown(); + } + + @Test + public void testRemoveByEndpointKeyHash() throws Exception { + List found = endpointSpecificConfigurationDao.find(); + Assert.assertTrue(found.size() == 3); + endpointSpecificConfigurationDao.removeByEndpointKeyHash(KEY); + found = endpointSpecificConfigurationDao.find(); + Assert.assertTrue(found.size() == 1); + } + + @Test + public void testFindByEndpointKeyHashAndConfigurationVersion() throws Exception { + List found = endpointSpecificConfigurationDao.find(); + Assert.assertTrue(found.size() == 3); + EndpointSpecificConfigurationDto found1 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY, 0).toDto(); + EndpointSpecificConfigurationDto found2 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY, 1).toDto(); + EndpointSpecificConfigurationDto found3 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY_2, 0).toDto(); + EndpointSpecificConfiguration found4 = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(KEY_2, 4); + Assert.assertEquals(saved1, found1); + Assert.assertEquals(saved2, found2); + Assert.assertEquals(saved3, found3); + Assert.assertNull(found4); + } + + @Test(expected = KaaOptimisticLockingFailureException.class) + public void testLocking() throws Exception { + saved1 = generateEndpointSpecificConfigurationDto(KEY, 1, BODY, 8L); + saved2 = generateEndpointSpecificConfigurationDto(KEY, 1, BODY, 8L); + } + + @Before + public void setUp() throws Exception { + saved1 = generateEndpointSpecificConfigurationDto(KEY, 0, BODY, null); + saved2 = generateEndpointSpecificConfigurationDto(KEY, 1, BODY, null); + saved3 = generateEndpointSpecificConfigurationDto(KEY_2, 0, BODY, null); + } + + @After + public void tearDown() throws Exception { + endpointSpecificConfigurationDao.removeAll(); + } +} \ No newline at end of file diff --git a/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoEndpointSpecificConfigurationTest.java b/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoEndpointSpecificConfigurationTest.java new file mode 100644 index 0000000000..85987c07a8 --- /dev/null +++ b/server/common/nosql/mongo-dao/src/test/java/org/kaaproject/kaa/server/common/nosql/mongo/dao/model/MongoEndpointSpecificConfigurationTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * 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 org.kaaproject.kaa.server.common.nosql.mongo.dao.model; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Assert; +import org.junit.Test; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; + +public class MongoEndpointSpecificConfigurationTest { + + @Test + public void equalsVerifierTest() throws Exception { + EqualsVerifier.forClass(MongoEndpointRegistration.class).suppress(Warning.NONFINAL_FIELDS).verify(); + } + + @Test + public void dataConversionTest() throws Exception { + EndpointSpecificConfigurationDto dto = new EndpointSpecificConfigurationDto("hash", 1, "conf body", 2L); + MongoEndpointSpecificConfiguration configuration = new MongoEndpointSpecificConfiguration(dto); + Assert.assertEquals(dto, configuration.toDto()); + } +} \ No newline at end of file diff --git a/server/common/nosql/mongo-dao/src/test/resources/mongo-dao-nosql-test-context.xml b/server/common/nosql/mongo-dao/src/test/resources/mongo-dao-nosql-test-context.xml index 89380f93c4..f193502290 100644 --- a/server/common/nosql/mongo-dao/src/test/resources/mongo-dao-nosql-test-context.xml +++ b/server/common/nosql/mongo-dao/src/test/resources/mongo-dao-nosql-test-context.xml @@ -48,6 +48,8 @@ + diff --git a/server/common/nosql/mongo-dao/src/test/resources/mongo-dao-test-context.xml b/server/common/nosql/mongo-dao/src/test/resources/mongo-dao-test-context.xml index 1f3d8bb2fa..ba5445ed14 100644 --- a/server/common/nosql/mongo-dao/src/test/resources/mongo-dao-test-context.xml +++ b/server/common/nosql/mongo-dao/src/test/resources/mongo-dao-test-context.xml @@ -89,4 +89,8 @@ + + + diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/bootstrap/BootstrapThriftService.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/bootstrap/BootstrapThriftService.java index 5a17840d9f..748558cbe4 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/bootstrap/BootstrapThriftService.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/bootstrap/BootstrapThriftService.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class BootstrapThriftService { public interface Iface { diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/bootstrap/ThriftOperationsServer.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/bootstrap/ThriftOperationsServer.java index 98e1780704..dc0c2eb4de 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/bootstrap/ThriftOperationsServer.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/bootstrap/ThriftOperationsServer.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class ThriftOperationsServer implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ThriftOperationsServer"); @@ -234,7 +234,7 @@ public Object getFieldValue(_Fields field) { return getId(); case PRIORITY: - return Integer.valueOf(getPriority()); + return getPriority(); } throw new IllegalStateException(); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CliThriftException.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CliThriftException.java index 92c9f479ae..85e7154272 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CliThriftException.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CliThriftException.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class CliThriftException extends TException implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("CliThriftException"); @@ -231,7 +231,7 @@ public void setFieldValue(_Fields field, Object value) { public Object getFieldValue(_Fields field) { switch (field) { case ERROR_CODE: - return Integer.valueOf(getErrorCode()); + return getErrorCode(); case MESSAGE: return getMessage(); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CliThriftService.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CliThriftService.java index c418baf3bb..eb73024844 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CliThriftService.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CliThriftService.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class CliThriftService { public interface Iface { @@ -2163,7 +2163,7 @@ public void setFieldValue(_Fields field, Object value) { public Object getFieldValue(_Fields field) { switch (field) { case FORCE_GC: - return Boolean.valueOf(isForceGC()); + return isForceGC(); } throw new IllegalStateException(); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CommandResult.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CommandResult.java index 2c0d23c908..83a4c9b2bf 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CommandResult.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CommandResult.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class CommandResult implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("CommandResult"); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CommandStatus.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CommandStatus.java index 69f9147f7f..07b190efb8 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CommandStatus.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/CommandStatus.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/MemoryUsage.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/MemoryUsage.java index 7746d33368..6718a5a5ba 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/MemoryUsage.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/cli/MemoryUsage.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class MemoryUsage implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("MemoryUsage"); @@ -276,13 +276,13 @@ public void setFieldValue(_Fields field, Object value) { public Object getFieldValue(_Fields field) { switch (field) { case MAX: - return Long.valueOf(getMax()); + return getMax(); case TOTAL: - return Long.valueOf(getTotal()); + return getTotal(); case FREE: - return Long.valueOf(getFree()); + return getFree(); } throw new IllegalStateException(); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/node/KaaNodeThriftService.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/node/KaaNodeThriftService.java index 1ef95ce31f..533501d911 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/node/KaaNodeThriftService.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/node/KaaNodeThriftService.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class KaaNodeThriftService { public interface Iface extends org.kaaproject.kaa.server.common.thrift.gen.cli.CliThriftService.Iface { diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointEvent.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointEvent.java index 9a9a1f4f96..8f2937fedd 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointEvent.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointEvent.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class EndpointEvent implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("EndpointEvent"); @@ -395,10 +395,10 @@ public Object getFieldValue(_Fields field) { return getEventData(); case CREATE_TIME: - return Long.valueOf(getCreateTime()); + return getCreateTime(); case VERSION: - return Integer.valueOf(getVersion()); + return getVersion(); } throw new IllegalStateException(); @@ -608,7 +608,7 @@ public String toString() { if (this.sender == null) { sb.append("null"); } else { - sb.append(this.sender); + org.apache.thrift.TBaseHelper.toString(this.sender, sb); } first = false; if (!first) sb.append(", "); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointRouteUpdate.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointRouteUpdate.java index 16a90b62f8..9e72031bb4 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointRouteUpdate.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointRouteUpdate.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class EndpointRouteUpdate implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("EndpointRouteUpdate"); @@ -449,7 +449,7 @@ public Object getFieldValue(_Fields field) { return getUpdateType(); case CF_SCHEMA_VERSION: - return Integer.valueOf(getCfSchemaVersion()); + return getCfSchemaVersion(); case UCF_HASH: return getUcfHash(); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointStateUpdate.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointStateUpdate.java index 87609da5a2..1b632007e3 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointStateUpdate.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EndpointStateUpdate.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class EndpointStateUpdate implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("EndpointStateUpdate"); @@ -622,7 +622,7 @@ public String toString() { if (this.endpointKey == null) { sb.append("null"); } else { - sb.append(this.endpointKey); + org.apache.thrift.TBaseHelper.toString(this.endpointKey, sb); } first = false; if (!first) sb.append(", "); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Event.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Event.java index 306cb081e5..53534029ff 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Event.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Event.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class Event implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Event"); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventClassFamilyVersion.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventClassFamilyVersion.java index 2649b97c8f..085edf0223 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventClassFamilyVersion.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventClassFamilyVersion.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class EventClassFamilyVersion implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("EventClassFamilyVersion"); @@ -234,7 +234,7 @@ public Object getFieldValue(_Fields field) { return getEndpointClassFamilyId(); case ENDPOINT_CLASS_FAMILY_VERSION: - return Integer.valueOf(getEndpointClassFamilyVersion()); + return getEndpointClassFamilyVersion(); } throw new IllegalStateException(); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventMessageType.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventMessageType.java index b7d6de8623..115a26bda6 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventMessageType.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventMessageType.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventRoute.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventRoute.java index 407cc12da0..0f1b1aead6 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventRoute.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventRoute.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class EventRoute implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("EventRoute"); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventRouteUpdateType.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventRouteUpdateType.java index 730583e6f3..08f14edec2 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventRouteUpdateType.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/EventRouteUpdateType.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Message.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Message.java index 28d167a5d1..9d35b09aee 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Message.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Message.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class Message implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Message"); @@ -475,7 +475,7 @@ public Object getFieldValue(_Fields field) { return getType(); case EVENT_ID: - return Long.valueOf(getEventId()); + return getEventId(); case EVENT: return getEvent(); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Notification.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Notification.java index 274288e44d..63e7cff5bc 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Notification.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Notification.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class Notification implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Notification"); @@ -745,25 +745,25 @@ public Object getFieldValue(_Fields field) { return getAppId(); case APP_SEQ_NUMBER: - return Integer.valueOf(getAppSeqNumber()); + return getAppSeqNumber(); case GROUP_ID: return getGroupId(); case GROUP_SEQ_NUMBER: - return Integer.valueOf(getGroupSeqNumber()); + return getGroupSeqNumber(); case PROFILE_FILTER_ID: return getProfileFilterId(); case PROFILE_FILTER_SEQ_NUMBER: - return Integer.valueOf(getProfileFilterSeqNumber()); + return getProfileFilterSeqNumber(); case CONFIGURATION_ID: return getConfigurationId(); case CONFIGURATION_SEQ_NUMBER: - return Integer.valueOf(getConfigurationSeqNumber()); + return getConfigurationSeqNumber(); case NOTIFICATION_ID: return getNotificationId(); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Operation.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Operation.java index 642be5007d..8ad1bec563 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Operation.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/Operation.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/OperationsThriftService.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/OperationsThriftService.java index 900de14987..cb8e20795b 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/OperationsThriftService.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/OperationsThriftService.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class OperationsThriftService { public interface Iface { @@ -95,6 +95,13 @@ public interface Iface { */ public void onEndpointDeregistration(ThriftEndpointDeregistrationMessage message) throws org.apache.thrift.TException; + /** + * Interface to send endpoint configuration refresh message + * + * @param message + */ + public void sendEndpointConfigurationRefreshMessage(ThriftEndpointConfigurationRefreshMessage message) throws org.apache.thrift.TException; + } public interface AsyncIface { @@ -115,6 +122,8 @@ public interface AsyncIface { public void onEndpointDeregistration(ThriftEndpointDeregistrationMessage message, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void sendEndpointConfigurationRefreshMessage(ThriftEndpointConfigurationRefreshMessage message, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + } public static class Client extends org.apache.thrift.TServiceClient implements Iface { @@ -297,6 +306,26 @@ public void recv_onEndpointDeregistration() throws org.apache.thrift.TException return; } + public void sendEndpointConfigurationRefreshMessage(ThriftEndpointConfigurationRefreshMessage message) throws org.apache.thrift.TException + { + send_sendEndpointConfigurationRefreshMessage(message); + recv_sendEndpointConfigurationRefreshMessage(); + } + + public void send_sendEndpointConfigurationRefreshMessage(ThriftEndpointConfigurationRefreshMessage message) throws org.apache.thrift.TException + { + sendEndpointConfigurationRefreshMessage_args args = new sendEndpointConfigurationRefreshMessage_args(); + args.setMessage(message); + sendBase("sendEndpointConfigurationRefreshMessage", args); + } + + public void recv_sendEndpointConfigurationRefreshMessage() throws org.apache.thrift.TException + { + sendEndpointConfigurationRefreshMessage_result result = new sendEndpointConfigurationRefreshMessage_result(); + receiveBase(result, "sendEndpointConfigurationRefreshMessage"); + return; + } + } public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { @@ -571,6 +600,38 @@ public void getResult() throws org.apache.thrift.TException { } } + public void sendEndpointConfigurationRefreshMessage(ThriftEndpointConfigurationRefreshMessage message, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + sendEndpointConfigurationRefreshMessage_call method_call = new sendEndpointConfigurationRefreshMessage_call(message, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class sendEndpointConfigurationRefreshMessage_call extends org.apache.thrift.async.TAsyncMethodCall { + private ThriftEndpointConfigurationRefreshMessage message; + public sendEndpointConfigurationRefreshMessage_call(ThriftEndpointConfigurationRefreshMessage message, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + this.message = message; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("sendEndpointConfigurationRefreshMessage", org.apache.thrift.protocol.TMessageType.CALL, 0)); + sendEndpointConfigurationRefreshMessage_args args = new sendEndpointConfigurationRefreshMessage_args(); + args.setMessage(message); + args.write(prot); + prot.writeMessageEnd(); + } + + public void getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + (new Client(prot)).recv_sendEndpointConfigurationRefreshMessage(); + } + } + } public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { @@ -592,6 +653,7 @@ protected Processor(I iface, Map extends org.apache.thrift.ProcessFunction { + public sendEndpointConfigurationRefreshMessage() { + super("sendEndpointConfigurationRefreshMessage"); + } + + public sendEndpointConfigurationRefreshMessage_args getEmptyArgsInstance() { + return new sendEndpointConfigurationRefreshMessage_args(); + } + + protected boolean isOneway() { + return false; + } + + public sendEndpointConfigurationRefreshMessage_result getResult(I iface, sendEndpointConfigurationRefreshMessage_args args) throws org.apache.thrift.TException { + sendEndpointConfigurationRefreshMessage_result result = new sendEndpointConfigurationRefreshMessage_result(); + iface.sendEndpointConfigurationRefreshMessage(args.message); + return result; + } + } + } public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { @@ -776,6 +858,7 @@ protected AsyncProcessor(I iface, Map extends org.apache.thrift.AsyncProcessFunction { + public sendEndpointConfigurationRefreshMessage() { + super("sendEndpointConfigurationRefreshMessage"); + } + + public sendEndpointConfigurationRefreshMessage_args getEmptyArgsInstance() { + return new sendEndpointConfigurationRefreshMessage_args(); + } + + public AsyncMethodCallback getResultHandler(final AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new AsyncMethodCallback() { + public void onComplete(Void o) { + sendEndpointConfigurationRefreshMessage_result result = new sendEndpointConfigurationRefreshMessage_result(); + try { + fcall.sendResponse(fb,result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + return; + } catch (Exception e) { + LOGGER.error("Exception writing to internal frame buffer", e); + } + fb.close(); + } + public void onError(Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TBase msg; + sendEndpointConfigurationRefreshMessage_result result = new sendEndpointConfigurationRefreshMessage_result(); + { + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + return; + } catch (Exception ex) { + LOGGER.error("Exception writing to internal frame buffer", ex); + } + fb.close(); + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, sendEndpointConfigurationRefreshMessage_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws TException { + iface.sendEndpointConfigurationRefreshMessage(args.message,resultHandler); + } + } + } public static class onNotification_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { @@ -6240,4 +6373,618 @@ public void read(org.apache.thrift.protocol.TProtocol prot, onEndpointDeregistra } + public static class sendEndpointConfigurationRefreshMessage_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("sendEndpointConfigurationRefreshMessage_args"); + + private static final org.apache.thrift.protocol.TField MESSAGE_FIELD_DESC = new org.apache.thrift.protocol.TField("message", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new sendEndpointConfigurationRefreshMessage_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new sendEndpointConfigurationRefreshMessage_argsTupleSchemeFactory()); + } + + public ThriftEndpointConfigurationRefreshMessage message; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + MESSAGE((short)1, "message"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // MESSAGE + return MESSAGE; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.MESSAGE, new org.apache.thrift.meta_data.FieldMetaData("message", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ThriftEndpointConfigurationRefreshMessage.class))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(sendEndpointConfigurationRefreshMessage_args.class, metaDataMap); + } + + public sendEndpointConfigurationRefreshMessage_args() { + } + + public sendEndpointConfigurationRefreshMessage_args( + ThriftEndpointConfigurationRefreshMessage message) + { + this(); + this.message = message; + } + + /** + * Performs a deep copy on other. + */ + public sendEndpointConfigurationRefreshMessage_args(sendEndpointConfigurationRefreshMessage_args other) { + if (other.isSetMessage()) { + this.message = new ThriftEndpointConfigurationRefreshMessage(other.message); + } + } + + public sendEndpointConfigurationRefreshMessage_args deepCopy() { + return new sendEndpointConfigurationRefreshMessage_args(this); + } + + @Override + public void clear() { + this.message = null; + } + + public ThriftEndpointConfigurationRefreshMessage getMessage() { + return this.message; + } + + public sendEndpointConfigurationRefreshMessage_args setMessage(ThriftEndpointConfigurationRefreshMessage message) { + this.message = message; + return this; + } + + public void unsetMessage() { + this.message = null; + } + + /** Returns true if field message is set (has been assigned a value) and false otherwise */ + public boolean isSetMessage() { + return this.message != null; + } + + public void setMessageIsSet(boolean value) { + if (!value) { + this.message = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case MESSAGE: + if (value == null) { + unsetMessage(); + } else { + setMessage((ThriftEndpointConfigurationRefreshMessage)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case MESSAGE: + return getMessage(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case MESSAGE: + return isSetMessage(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof sendEndpointConfigurationRefreshMessage_args) + return this.equals((sendEndpointConfigurationRefreshMessage_args)that); + return false; + } + + public boolean equals(sendEndpointConfigurationRefreshMessage_args that) { + if (that == null) + return false; + + boolean this_present_message = true && this.isSetMessage(); + boolean that_present_message = true && that.isSetMessage(); + if (this_present_message || that_present_message) { + if (!(this_present_message && that_present_message)) + return false; + if (!this.message.equals(that.message)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_message = true && (isSetMessage()); + list.add(present_message); + if (present_message) + list.add(message); + + return list.hashCode(); + } + + @Override + public int compareTo(sendEndpointConfigurationRefreshMessage_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetMessage()).compareTo(other.isSetMessage()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetMessage()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.message, other.message); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("sendEndpointConfigurationRefreshMessage_args("); + boolean first = true; + + sb.append("message:"); + if (this.message == null) { + sb.append("null"); + } else { + sb.append(this.message); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (message != null) { + message.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class sendEndpointConfigurationRefreshMessage_argsStandardSchemeFactory implements SchemeFactory { + public sendEndpointConfigurationRefreshMessage_argsStandardScheme getScheme() { + return new sendEndpointConfigurationRefreshMessage_argsStandardScheme(); + } + } + + private static class sendEndpointConfigurationRefreshMessage_argsStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, sendEndpointConfigurationRefreshMessage_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // MESSAGE + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.message = new ThriftEndpointConfigurationRefreshMessage(); + struct.message.read(iprot); + struct.setMessageIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, sendEndpointConfigurationRefreshMessage_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.message != null) { + oprot.writeFieldBegin(MESSAGE_FIELD_DESC); + struct.message.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class sendEndpointConfigurationRefreshMessage_argsTupleSchemeFactory implements SchemeFactory { + public sendEndpointConfigurationRefreshMessage_argsTupleScheme getScheme() { + return new sendEndpointConfigurationRefreshMessage_argsTupleScheme(); + } + } + + private static class sendEndpointConfigurationRefreshMessage_argsTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, sendEndpointConfigurationRefreshMessage_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetMessage()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetMessage()) { + struct.message.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, sendEndpointConfigurationRefreshMessage_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.message = new ThriftEndpointConfigurationRefreshMessage(); + struct.message.read(iprot); + struct.setMessageIsSet(true); + } + } + } + + } + + public static class sendEndpointConfigurationRefreshMessage_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("sendEndpointConfigurationRefreshMessage_result"); + + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new sendEndpointConfigurationRefreshMessage_resultStandardSchemeFactory()); + schemes.put(TupleScheme.class, new sendEndpointConfigurationRefreshMessage_resultTupleSchemeFactory()); + } + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { +; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(sendEndpointConfigurationRefreshMessage_result.class, metaDataMap); + } + + public sendEndpointConfigurationRefreshMessage_result() { + } + + /** + * Performs a deep copy on other. + */ + public sendEndpointConfigurationRefreshMessage_result(sendEndpointConfigurationRefreshMessage_result other) { + } + + public sendEndpointConfigurationRefreshMessage_result deepCopy() { + return new sendEndpointConfigurationRefreshMessage_result(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof sendEndpointConfigurationRefreshMessage_result) + return this.equals((sendEndpointConfigurationRefreshMessage_result)that); + return false; + } + + public boolean equals(sendEndpointConfigurationRefreshMessage_result that) { + if (that == null) + return false; + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + return list.hashCode(); + } + + @Override + public int compareTo(sendEndpointConfigurationRefreshMessage_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("sendEndpointConfigurationRefreshMessage_result("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class sendEndpointConfigurationRefreshMessage_resultStandardSchemeFactory implements SchemeFactory { + public sendEndpointConfigurationRefreshMessage_resultStandardScheme getScheme() { + return new sendEndpointConfigurationRefreshMessage_resultStandardScheme(); + } + } + + private static class sendEndpointConfigurationRefreshMessage_resultStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, sendEndpointConfigurationRefreshMessage_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, sendEndpointConfigurationRefreshMessage_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class sendEndpointConfigurationRefreshMessage_resultTupleSchemeFactory implements SchemeFactory { + public sendEndpointConfigurationRefreshMessage_resultTupleScheme getScheme() { + return new sendEndpointConfigurationRefreshMessage_resultTupleScheme(); + } + } + + private static class sendEndpointConfigurationRefreshMessage_resultTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, sendEndpointConfigurationRefreshMessage_result struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, sendEndpointConfigurationRefreshMessage_result struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + } + } + + } + } diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RedirectionRule.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RedirectionRule.java index 491db4d76b..87d7d1cbb3 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RedirectionRule.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RedirectionRule.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class RedirectionRule implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("RedirectionRule"); @@ -366,19 +366,19 @@ public void setFieldValue(_Fields field, Object value) { public Object getFieldValue(_Fields field) { switch (field) { case ACCESS_POINT_ID: - return Integer.valueOf(getAccessPointId()); + return getAccessPointId(); case RULE_ID: - return Long.valueOf(getRuleId()); + return getRuleId(); case INIT_REDIRECT_PROBABILITY: - return Double.valueOf(getInitRedirectProbability()); + return getInitRedirectProbability(); case SESSION_REDIRECT_PROBABILITY: - return Double.valueOf(getSessionRedirectProbability()); + return getSessionRedirectProbability(); case RULE_TTL: - return Long.valueOf(getRuleTTL()); + return getRuleTTL(); } throw new IllegalStateException(); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RouteAddress.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RouteAddress.java index 1ad1c55de6..d003282f99 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RouteAddress.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RouteAddress.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class RouteAddress implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("RouteAddress"); @@ -440,7 +440,7 @@ public String toString() { if (this.endpointKey == null) { sb.append("null"); } else { - sb.append(this.endpointKey); + org.apache.thrift.TBaseHelper.toString(this.endpointKey, sb); } first = false; if (!first) sb.append(", "); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RouteInfo.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RouteInfo.java index d84866caa2..8aebb91f21 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RouteInfo.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/RouteInfo.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class RouteInfo implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("RouteInfo"); @@ -574,7 +574,7 @@ public String toString() { if (this.endpointId == null) { sb.append("null"); } else { - sb.append(this.endpointId); + org.apache.thrift.TBaseHelper.toString(this.endpointId, sb); } first = false; sb.append(")"); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftActorClassifier.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftActorClassifier.java index da1551aa9a..69efea29a0 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftActorClassifier.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftActorClassifier.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftClusterEntityType.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftClusterEntityType.java index 1b80be5a55..6a7a6a9421 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftClusterEntityType.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftClusterEntityType.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEndpointConfigurationRefreshMessage.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEndpointConfigurationRefreshMessage.java new file mode 100644 index 0000000000..83e6ea3a1a --- /dev/null +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEndpointConfigurationRefreshMessage.java @@ -0,0 +1,524 @@ +/** + * Autogenerated by Thrift Compiler (0.9.3) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package org.kaaproject.kaa.server.common.thrift.gen.operations; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") +public class ThriftEndpointConfigurationRefreshMessage implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ThriftEndpointConfigurationRefreshMessage"); + + private static final org.apache.thrift.protocol.TField ADDRESS_FIELD_DESC = new org.apache.thrift.protocol.TField("address", org.apache.thrift.protocol.TType.STRUCT, (short)1); + private static final org.apache.thrift.protocol.TField ACTOR_CLASSIFIER_FIELD_DESC = new org.apache.thrift.protocol.TField("actorClassifier", org.apache.thrift.protocol.TType.I32, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new ThriftEndpointConfigurationRefreshMessageStandardSchemeFactory()); + schemes.put(TupleScheme.class, new ThriftEndpointConfigurationRefreshMessageTupleSchemeFactory()); + } + + public ThriftEntityAddress address; // required + /** + * + * @see ThriftActorClassifier + */ + public ThriftActorClassifier actorClassifier; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + ADDRESS((short)1, "address"), + /** + * + * @see ThriftActorClassifier + */ + ACTOR_CLASSIFIER((short)2, "actorClassifier"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // ADDRESS + return ADDRESS; + case 2: // ACTOR_CLASSIFIER + return ACTOR_CLASSIFIER; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.ADDRESS, new org.apache.thrift.meta_data.FieldMetaData("address", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ThriftEntityAddress.class))); + tmpMap.put(_Fields.ACTOR_CLASSIFIER, new org.apache.thrift.meta_data.FieldMetaData("actorClassifier", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, ThriftActorClassifier.class))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(ThriftEndpointConfigurationRefreshMessage.class, metaDataMap); + } + + public ThriftEndpointConfigurationRefreshMessage() { + } + + public ThriftEndpointConfigurationRefreshMessage( + ThriftEntityAddress address, + ThriftActorClassifier actorClassifier) + { + this(); + this.address = address; + this.actorClassifier = actorClassifier; + } + + /** + * Performs a deep copy on other. + */ + public ThriftEndpointConfigurationRefreshMessage(ThriftEndpointConfigurationRefreshMessage other) { + if (other.isSetAddress()) { + this.address = new ThriftEntityAddress(other.address); + } + if (other.isSetActorClassifier()) { + this.actorClassifier = other.actorClassifier; + } + } + + public ThriftEndpointConfigurationRefreshMessage deepCopy() { + return new ThriftEndpointConfigurationRefreshMessage(this); + } + + @Override + public void clear() { + this.address = null; + this.actorClassifier = null; + } + + public ThriftEntityAddress getAddress() { + return this.address; + } + + public ThriftEndpointConfigurationRefreshMessage setAddress(ThriftEntityAddress address) { + this.address = address; + return this; + } + + public void unsetAddress() { + this.address = null; + } + + /** Returns true if field address is set (has been assigned a value) and false otherwise */ + public boolean isSetAddress() { + return this.address != null; + } + + public void setAddressIsSet(boolean value) { + if (!value) { + this.address = null; + } + } + + /** + * + * @see ThriftActorClassifier + */ + public ThriftActorClassifier getActorClassifier() { + return this.actorClassifier; + } + + /** + * + * @see ThriftActorClassifier + */ + public ThriftEndpointConfigurationRefreshMessage setActorClassifier(ThriftActorClassifier actorClassifier) { + this.actorClassifier = actorClassifier; + return this; + } + + public void unsetActorClassifier() { + this.actorClassifier = null; + } + + /** Returns true if field actorClassifier is set (has been assigned a value) and false otherwise */ + public boolean isSetActorClassifier() { + return this.actorClassifier != null; + } + + public void setActorClassifierIsSet(boolean value) { + if (!value) { + this.actorClassifier = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case ADDRESS: + if (value == null) { + unsetAddress(); + } else { + setAddress((ThriftEntityAddress)value); + } + break; + + case ACTOR_CLASSIFIER: + if (value == null) { + unsetActorClassifier(); + } else { + setActorClassifier((ThriftActorClassifier)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case ADDRESS: + return getAddress(); + + case ACTOR_CLASSIFIER: + return getActorClassifier(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case ADDRESS: + return isSetAddress(); + case ACTOR_CLASSIFIER: + return isSetActorClassifier(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof ThriftEndpointConfigurationRefreshMessage) + return this.equals((ThriftEndpointConfigurationRefreshMessage)that); + return false; + } + + public boolean equals(ThriftEndpointConfigurationRefreshMessage that) { + if (that == null) + return false; + + boolean this_present_address = true && this.isSetAddress(); + boolean that_present_address = true && that.isSetAddress(); + if (this_present_address || that_present_address) { + if (!(this_present_address && that_present_address)) + return false; + if (!this.address.equals(that.address)) + return false; + } + + boolean this_present_actorClassifier = true && this.isSetActorClassifier(); + boolean that_present_actorClassifier = true && that.isSetActorClassifier(); + if (this_present_actorClassifier || that_present_actorClassifier) { + if (!(this_present_actorClassifier && that_present_actorClassifier)) + return false; + if (!this.actorClassifier.equals(that.actorClassifier)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_address = true && (isSetAddress()); + list.add(present_address); + if (present_address) + list.add(address); + + boolean present_actorClassifier = true && (isSetActorClassifier()); + list.add(present_actorClassifier); + if (present_actorClassifier) + list.add(actorClassifier.getValue()); + + return list.hashCode(); + } + + @Override + public int compareTo(ThriftEndpointConfigurationRefreshMessage other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetAddress()).compareTo(other.isSetAddress()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetAddress()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.address, other.address); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetActorClassifier()).compareTo(other.isSetActorClassifier()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetActorClassifier()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.actorClassifier, other.actorClassifier); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("ThriftEndpointConfigurationRefreshMessage("); + boolean first = true; + + sb.append("address:"); + if (this.address == null) { + sb.append("null"); + } else { + sb.append(this.address); + } + first = false; + if (!first) sb.append(", "); + sb.append("actorClassifier:"); + if (this.actorClassifier == null) { + sb.append("null"); + } else { + sb.append(this.actorClassifier); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (address != null) { + address.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class ThriftEndpointConfigurationRefreshMessageStandardSchemeFactory implements SchemeFactory { + public ThriftEndpointConfigurationRefreshMessageStandardScheme getScheme() { + return new ThriftEndpointConfigurationRefreshMessageStandardScheme(); + } + } + + private static class ThriftEndpointConfigurationRefreshMessageStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, ThriftEndpointConfigurationRefreshMessage struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // ADDRESS + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.address = new ThriftEntityAddress(); + struct.address.read(iprot); + struct.setAddressIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // ACTOR_CLASSIFIER + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.actorClassifier = org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftActorClassifier.findByValue(iprot.readI32()); + struct.setActorClassifierIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, ThriftEndpointConfigurationRefreshMessage struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.address != null) { + oprot.writeFieldBegin(ADDRESS_FIELD_DESC); + struct.address.write(oprot); + oprot.writeFieldEnd(); + } + if (struct.actorClassifier != null) { + oprot.writeFieldBegin(ACTOR_CLASSIFIER_FIELD_DESC); + oprot.writeI32(struct.actorClassifier.getValue()); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class ThriftEndpointConfigurationRefreshMessageTupleSchemeFactory implements SchemeFactory { + public ThriftEndpointConfigurationRefreshMessageTupleScheme getScheme() { + return new ThriftEndpointConfigurationRefreshMessageTupleScheme(); + } + } + + private static class ThriftEndpointConfigurationRefreshMessageTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, ThriftEndpointConfigurationRefreshMessage struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetAddress()) { + optionals.set(0); + } + if (struct.isSetActorClassifier()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetAddress()) { + struct.address.write(oprot); + } + if (struct.isSetActorClassifier()) { + oprot.writeI32(struct.actorClassifier.getValue()); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, ThriftEndpointConfigurationRefreshMessage struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.address = new ThriftEntityAddress(); + struct.address.read(iprot); + struct.setAddressIsSet(true); + } + if (incoming.get(1)) { + struct.actorClassifier = org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftActorClassifier.findByValue(iprot.readI32()); + struct.setActorClassifierIsSet(true); + } + } + } + +} + diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEndpointDeregistrationMessage.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEndpointDeregistrationMessage.java index 386b04e744..0e77124109 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEndpointDeregistrationMessage.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEndpointDeregistrationMessage.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class ThriftEndpointDeregistrationMessage implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ThriftEndpointDeregistrationMessage"); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityAddress.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityAddress.java index da5696d670..9dbaac971a 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityAddress.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityAddress.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class ThriftEntityAddress implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ThriftEntityAddress"); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityClusterAddress.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityClusterAddress.java index 1707512e4e..5f168bbd2a 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityClusterAddress.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityClusterAddress.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class ThriftEntityClusterAddress implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ThriftEntityClusterAddress"); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityRouteMessage.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityRouteMessage.java index 437ad56417..110953f6bd 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityRouteMessage.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftEntityRouteMessage.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class ThriftEntityRouteMessage implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ThriftEntityRouteMessage"); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftRouteOperation.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftRouteOperation.java index bd355ca57d..d57c6075d4 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftRouteOperation.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftRouteOperation.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftServerProfileUpdateMessage.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftServerProfileUpdateMessage.java index 8f32d0a603..844da29bfe 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftServerProfileUpdateMessage.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftServerProfileUpdateMessage.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class ThriftServerProfileUpdateMessage implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ThriftServerProfileUpdateMessage"); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftUnicastNotificationMessage.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftUnicastNotificationMessage.java index 6976364044..df88b65306 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftUnicastNotificationMessage.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/ThriftUnicastNotificationMessage.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class ThriftUnicastNotificationMessage implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ThriftUnicastNotificationMessage"); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/UserConfigurationUpdate.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/UserConfigurationUpdate.java index e5a12d7f08..7b18c57b62 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/UserConfigurationUpdate.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/UserConfigurationUpdate.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class UserConfigurationUpdate implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("UserConfigurationUpdate"); @@ -385,7 +385,7 @@ public Object getFieldValue(_Fields field) { return getApplicationToken(); case CF_SCHEMA_VERSION: - return Integer.valueOf(getCfSchemaVersion()); + return getCfSchemaVersion(); case UCF_HASH: return getUcfHash(); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/UserRouteInfo.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/UserRouteInfo.java index 4cdc51b957..3df3e546d6 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/UserRouteInfo.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/operations/UserRouteInfo.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class UserRouteInfo implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("UserRouteInfo"); diff --git a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/shared/DataStruct.java b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/shared/DataStruct.java index 1ef2a560b8..5657cc6528 100644 --- a/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/shared/DataStruct.java +++ b/server/common/thrift/src/main/thrift-java/org/kaaproject/kaa/server/common/thrift/gen/shared/DataStruct.java @@ -1,5 +1,5 @@ /** - * Autogenerated by Thrift Compiler (0.9.2) + * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-4-19") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-09-27") public class DataStruct implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("DataStruct"); diff --git a/server/common/thrift/src/main/thrift/operations.thrift b/server/common/thrift/src/main/thrift/operations.thrift index 3773f2ecc8..33295738a4 100644 --- a/server/common/thrift/src/main/thrift/operations.thrift +++ b/server/common/thrift/src/main/thrift/operations.thrift @@ -236,6 +236,11 @@ struct ThriftUnicastNotificationMessage { 3: string notificationId; } +struct ThriftEndpointConfigurationRefreshMessage { + 1: ThriftEntityAddress address + 2: ThriftActorClassifier actorClassifier +} + struct ThriftServerProfileUpdateMessage { 1: ThriftEntityAddress address 2: ThriftActorClassifier actorClassifier @@ -282,4 +287,10 @@ service OperationsThriftService { * Interface to send server profile update message */ void onEndpointDeregistration(1: ThriftEndpointDeregistrationMessage message); + +/** +* Interface to send endpoint configuration refresh message +*/ + void sendEndpointConfigurationRefreshMessage(1: ThriftEndpointConfigurationRefreshMessage message); + } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/ConfigurationController.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/ConfigurationController.java index bde6f67561..8cde7f5788 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/ConfigurationController.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/ConfigurationController.java @@ -24,6 +24,7 @@ import org.kaaproject.kaa.common.dto.ConfigurationDto; import org.kaaproject.kaa.common.dto.ConfigurationRecordDto; import org.kaaproject.kaa.common.dto.ConfigurationSchemaDto; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; import org.kaaproject.kaa.common.dto.EndpointUserConfigurationDto; import org.kaaproject.kaa.common.dto.VersionDto; import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException; @@ -281,6 +282,83 @@ public void editUserConfiguration( configurationService.editUserConfiguration(endpointUserConfiguration); } + /** + * Creates or updates endpoint specific configuration by the endpoint key hash + * + * @param endpointSpecificConfiguration endpoint specific configuration + * @throws KaaAdminServiceException the kaa admin service exception + */ + @ApiOperation(value = "Create or update endpoint specific configuration", + notes = "Creates or updates endpoint specific configuration. If a configuration for target endpoint does not " + + "exist, then it will be created. If a configuration for target endpoint, it is updated. Only users " + + "with the TENANT_DEVELOPER or TENANT_USER role are allowed to perform this operation.") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Endpoint specific configuration created"), + @ApiResponse(code = 400, message = "Invalid input parameter provided"), + @ApiResponse(code = 401, message = "The user is not authenticated or invalid credentials were provided"), + @ApiResponse(code = 403, message = "The authenticated user does not have the required role (TENANT_DEVELOPER or TENANT_USER) or the Tenant ID " + + "of the application does not match the Tenant ID of the authenticated user"), + @ApiResponse(code = 404, message = "Specified endpoint does not exist"), + @ApiResponse(code = 409, message = "Can't update entity with provided version. Entity already changed"), + @ApiResponse(code = 500, message = "An unexpected error occurred on the server side")}) + @RequestMapping(value = "endpointConfiguration", method = RequestMethod.POST) + @ResponseStatus(value = HttpStatus.OK) + @ResponseBody + public EndpointSpecificConfigurationDto editEndpointSpecificConfiguration( + @ApiParam(name = "endpointSpecificConfiguration", value = "endpointSpecificConfigurationDto body. Mandatory fields: endpointKeyHash, configuration", required = true) + @RequestBody EndpointSpecificConfigurationDto endpointSpecificConfiguration) throws KaaAdminServiceException { + return configurationService.editEndpointSpecificConfiguration(endpointSpecificConfiguration); + } + + /** + * Retrieves endpoint specific configuration by the endpoint key hash + * + * @param endpointKeyHash endpoint key hash + * @throws KaaAdminServiceException the kaa admin service exception + */ + @ApiOperation(value = "Retrieve endpoint specific configuration", + notes = "Retrieves endpoint specific configuration by the endpoint key hash. If a configuration for provided endpoint key hash does not " + + "exist, then request is rejected. Only users " + + "with the TENANT_DEVELOPER or TENANT_USER role are allowed to perform this operation.") + @ApiResponses(value = { + @ApiResponse(code = 401, message = "Endpoint specific configuration successfully retrieved"), + @ApiResponse(code = 401, message = "The user is not authenticated or invalid credentials were provided"), + @ApiResponse(code = 403, message = "The authenticated user does not have the required role (TENANT_DEVELOPER or TENANT_USER) or the Tenant ID " + + "of the application does not match the Tenant ID of the authenticated user"), + @ApiResponse(code = 404, message = "Specified endpoint does not exist"), + @ApiResponse(code = 500, message = "An unexpected error occurred on the server side")}) + @RequestMapping(value = "endpointConfiguration/{endpointKeyHash}", method = RequestMethod.GET) + @ResponseStatus(value = HttpStatus.OK) + @ResponseBody + public EndpointSpecificConfigurationDto findEndpointSpecificConfiguration( + @PathVariable String endpointKeyHash) throws KaaAdminServiceException { + return configurationService.findEndpointSpecificConfiguration(endpointKeyHash); + } + + /** + * Deletes endpoint specific configuration by the endpoint key hash + * + * @param endpointKeyHash endpoint key hash + * @throws KaaAdminServiceException the kaa admin service exception + */ + @ApiOperation(value = "Delete endpoint specific configuration", + notes = "Deletes endpoint specific configuration by the endpoint key hash. If a configuration for provided endpoint key hash does not " + + "exist, then request is rejected. Only users " + + "with the TENANT_DEVELOPER or TENANT_USER role are allowed to perform this operation.") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Endpoint specific configuration successfully deleted"), + @ApiResponse(code = 401, message = "The user is not authenticated or invalid credentials were provided"), + @ApiResponse(code = 403, message = "The authenticated user does not have the required role (TENANT_DEVELOPER or TENANT_USER) or the Tenant ID " + + "of the application does not match the Tenant ID of the authenticated user"), + @ApiResponse(code = 404, message = "Specified endpoint does not exist"), + @ApiResponse(code = 500, message = "An unexpected error occurred on the server side")}) + @RequestMapping(value = "endpointConfiguration/{endpointKeyHash}", method = RequestMethod.DELETE) + @ResponseStatus(value = HttpStatus.OK) + public void deleteEndpointSpecificConfiguration( + @PathVariable String endpointKeyHash) throws KaaAdminServiceException { + configurationService.deleteEndpointSpecificConfiguration(endpointKeyHash); + } + /** * Activate configuration by its id. * diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AbstractAdminService.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AbstractAdminService.java index c01d6816ed..24d79c5151 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AbstractAdminService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AbstractAdminService.java @@ -24,7 +24,12 @@ import org.kaaproject.avro.ui.shared.Fqn; import org.kaaproject.avro.ui.shared.RecordField; import org.kaaproject.kaa.common.avro.GenericAvroConverter; -import org.kaaproject.kaa.common.dto.*; +import org.kaaproject.kaa.common.dto.AbstractSchemaDto; +import org.kaaproject.kaa.common.dto.ApplicationDto; +import org.kaaproject.kaa.common.dto.EndpointGroupDto; +import org.kaaproject.kaa.common.dto.EndpointProfileDto; +import org.kaaproject.kaa.common.dto.KaaAuthorityDto; +import org.kaaproject.kaa.common.dto.UserDto; import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.plugin.PluginDto; import org.kaaproject.kaa.server.admin.services.cache.CacheService; @@ -44,7 +49,9 @@ import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException; import org.kaaproject.kaa.server.admin.shared.services.ServiceErrorCode; +import org.kaaproject.kaa.server.common.Base64Util; import org.kaaproject.kaa.server.common.core.schema.KaaSchemaFactoryImpl; +import org.kaaproject.kaa.server.common.dao.EndpointService; import org.kaaproject.kaa.server.common.plugin.KaaPluginConfig; import org.kaaproject.kaa.server.common.plugin.PluginConfig; import org.kaaproject.kaa.server.common.plugin.PluginType; @@ -69,9 +76,11 @@ import java.util.Map; import java.util.Set; +import static org.kaaproject.kaa.server.admin.services.util.Utils.checkNotNull; import static org.kaaproject.kaa.server.admin.services.util.Utils.getCurrentUser; import static org.kaaproject.kaa.server.admin.shared.schema.ConverterType.CONFIGURATION_FORM_AVRO_CONVERTER; import static org.kaaproject.kaa.server.admin.shared.util.Utils.isEmpty; +import static org.kaaproject.kaa.server.common.dao.service.Validator.validateString; public abstract class AbstractAdminService implements InitializingBean { @@ -93,6 +102,9 @@ public abstract class AbstractAdminService implements InitializingBean { @Autowired MessagingService messagingService; + @Autowired + EndpointService endpointService; + @Autowired CacheService cacheService; @@ -200,7 +212,7 @@ String checkApplicationToken(String applicationToken) throws KaaAdminServiceExce } void checkApplication(ApplicationDto application) throws KaaAdminServiceException { - Utils.checkNotNull(application); + checkNotNull(application); checkTenantId(application.getTenantId()); } @@ -210,7 +222,7 @@ EndpointGroupDto checkEndpointGroupId(String endpointGroupId) throws KaaAdminSer throw new IllegalArgumentException("The endpointGroupId parameter is empty."); } EndpointGroupDto endpointGroup = controlService.getEndpointGroup(endpointGroupId); - Utils.checkNotNull(endpointGroup); + checkNotNull(endpointGroup); checkApplicationId(endpointGroup.getApplicationId()); return endpointGroup; } catch (Exception e) { @@ -218,6 +230,18 @@ EndpointGroupDto checkEndpointGroupId(String endpointGroupId) throws KaaAdminSer } } + EndpointProfileDto checkEndpointProfile(String endpointKeyHash) throws KaaAdminServiceException { + try { + validateString(endpointKeyHash, "Missing endpoint key hash"); + EndpointProfileDto endpointProfile = endpointService.findEndpointProfileByKeyHash(Base64Util.decode(endpointKeyHash)); + checkNotNull(endpointProfile); + checkApplicationId(endpointProfile.getApplicationId()); + return endpointProfile; + } catch (Exception e) { + throw Utils.handleException(e); + } + } + String getTenantId() throws KaaAdminServiceException { return getCurrentUser().getTenantId(); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/ConfigurationServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/ConfigurationServiceImpl.java index ce78b89d55..832778374f 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/ConfigurationServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/ConfigurationServiceImpl.java @@ -27,6 +27,7 @@ import org.kaaproject.kaa.common.dto.ConfigurationRecordDto; import org.kaaproject.kaa.common.dto.ConfigurationSchemaDto; import org.kaaproject.kaa.common.dto.EndpointGroupDto; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; import org.kaaproject.kaa.common.dto.EndpointUserConfigurationDto; import org.kaaproject.kaa.common.dto.KaaAuthorityDto; import org.kaaproject.kaa.common.dto.StructureRecordDto; @@ -233,6 +234,42 @@ public void editUserConfiguration(EndpointUserConfigurationDto endpointUserConfi } } + @Override + public EndpointSpecificConfigurationDto editEndpointSpecificConfiguration(EndpointSpecificConfigurationDto configuration) throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + try { + checkEndpointProfile(configuration.getEndpointKeyHash()); + return controlService.editEndpointSpecificConfiguration(configuration); + } catch (Exception e) { + throw Utils.handleException(e); + } + } + + @Override + public EndpointSpecificConfigurationDto findEndpointSpecificConfiguration(String endpointKeyHash) throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + try { + checkEndpointProfile(endpointKeyHash); + EndpointSpecificConfigurationDto configuration = controlService.findEndpointSpecificConfiguration(endpointKeyHash); + Utils.checkNotNull(configuration); + return configuration; + } catch (Exception e) { + throw Utils.handleException(e); + } + } + + @Override + public EndpointSpecificConfigurationDto deleteEndpointSpecificConfiguration(String endpointKeyHash) throws KaaAdminServiceException { + try { + checkEndpointProfile(endpointKeyHash); + EndpointSpecificConfigurationDto configuration = controlService.deleteEndpointSpecificConfiguration(endpointKeyHash); + Utils.checkNotNull(configuration); + return configuration; + } catch (Exception e) { + throw Utils.handleException(e); + } + } + @Override public ConfigurationDto activateConfiguration(String configurationId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/util/Utils.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/util/Utils.java index d1e97322d7..2089563f8a 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/util/Utils.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/util/Utils.java @@ -20,6 +20,7 @@ import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException; import org.kaaproject.kaa.server.admin.shared.services.ServiceErrorCode; import org.kaaproject.kaa.server.common.dao.exception.IncorrectParameterException; +import org.kaaproject.kaa.server.common.dao.exception.KaaOptimisticLockingFailureException; import org.kaaproject.kaa.server.common.dao.exception.NotFoundException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,7 +28,6 @@ import org.springframework.security.core.context.SecurityContextHolder; import java.util.Set; -import java.util.stream.Collectors; public class Utils { @@ -62,6 +62,8 @@ public static KaaAdminServiceException handleException(Exception exception, bool return (KaaAdminServiceException) exception; } else if (exception instanceof NotFoundException) { return new KaaAdminServiceException(exception.getMessage(), ServiceErrorCode.ITEM_NOT_FOUND); + } else if (exception instanceof KaaOptimisticLockingFailureException) { + return new KaaAdminServiceException(exception.getMessage(), ServiceErrorCode.CONFLICT); } else if (exception instanceof IllegalArgumentException || exception instanceof IncorrectParameterException || cause.contains("IncorrectParameterException")) { return new KaaAdminServiceException(exception.getMessage(), ServiceErrorCode.BAD_REQUEST_PARAMS); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/ConfigurationService.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/ConfigurationService.java index a9dffbd6ea..b6de82b673 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/ConfigurationService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/ConfigurationService.java @@ -16,38 +16,20 @@ package org.kaaproject.kaa.server.admin.shared.services; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import org.apache.avro.Schema; +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; import org.kaaproject.avro.ui.shared.RecordField; import org.kaaproject.kaa.common.dto.ConfigurationDto; import org.kaaproject.kaa.common.dto.ConfigurationRecordDto; import org.kaaproject.kaa.common.dto.ConfigurationSchemaDto; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; import org.kaaproject.kaa.common.dto.EndpointUserConfigurationDto; import org.kaaproject.kaa.common.dto.VersionDto; -import org.kaaproject.kaa.common.dto.file.FileData; import org.kaaproject.kaa.server.admin.shared.config.ConfigurationRecordFormDto; import org.kaaproject.kaa.server.admin.shared.config.ConfigurationRecordViewDto; import org.kaaproject.kaa.server.admin.shared.schema.ConfigurationSchemaViewDto; import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; import org.kaaproject.kaa.server.admin.shared.schema.SchemaInfoDto; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.multipart.MultipartFile; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; import java.util.List; @@ -108,4 +90,9 @@ public interface ConfigurationService extends RemoteService { EndpointUserConfigurationDto findUserConfigurationByExternalUIdAndAppIdAndSchemaVersion(String externalUId, String appId, Integer schemaVersion) throws KaaAdminServiceException; + EndpointSpecificConfigurationDto editEndpointSpecificConfiguration(EndpointSpecificConfigurationDto configuration) throws KaaAdminServiceException; + + EndpointSpecificConfigurationDto findEndpointSpecificConfiguration(String endpointKeyHash) throws KaaAdminServiceException; + + EndpointSpecificConfigurationDto deleteEndpointSpecificConfiguration(String endpointKeyHash) throws KaaAdminServiceException; } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/control/service/ControlService.java b/server/node/src/main/java/org/kaaproject/kaa/server/control/service/ControlService.java index 9dc040382c..7c3d8f9b6e 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/control/service/ControlService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/control/service/ControlService.java @@ -16,14 +16,34 @@ package org.kaaproject.kaa.server.control.service; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - import org.apache.avro.Schema; import org.kaaproject.avro.ui.shared.Fqn; -import org.kaaproject.kaa.common.dto.*; +import org.kaaproject.kaa.common.dto.ApplicationDto; +import org.kaaproject.kaa.common.dto.ConfigurationDto; +import org.kaaproject.kaa.common.dto.ConfigurationRecordDto; +import org.kaaproject.kaa.common.dto.ConfigurationSchemaDto; +import org.kaaproject.kaa.common.dto.EndpointGroupDto; +import org.kaaproject.kaa.common.dto.EndpointNotificationDto; +import org.kaaproject.kaa.common.dto.EndpointProfileBodyDto; +import org.kaaproject.kaa.common.dto.EndpointProfileDto; +import org.kaaproject.kaa.common.dto.EndpointProfileSchemaDto; +import org.kaaproject.kaa.common.dto.EndpointProfilesBodyDto; +import org.kaaproject.kaa.common.dto.EndpointProfilesPageDto; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; +import org.kaaproject.kaa.common.dto.EndpointUserConfigurationDto; +import org.kaaproject.kaa.common.dto.EndpointUserDto; +import org.kaaproject.kaa.common.dto.NotificationDto; +import org.kaaproject.kaa.common.dto.NotificationSchemaDto; +import org.kaaproject.kaa.common.dto.NotificationTypeDto; +import org.kaaproject.kaa.common.dto.PageLinkDto; +import org.kaaproject.kaa.common.dto.ProfileFilterDto; +import org.kaaproject.kaa.common.dto.ProfileFilterRecordDto; +import org.kaaproject.kaa.common.dto.ProfileVersionPairDto; +import org.kaaproject.kaa.common.dto.ServerProfileSchemaDto; +import org.kaaproject.kaa.common.dto.TenantDto; +import org.kaaproject.kaa.common.dto.TopicDto; +import org.kaaproject.kaa.common.dto.UserDto; +import org.kaaproject.kaa.common.dto.VersionDto; import org.kaaproject.kaa.common.dto.admin.RecordKey; import org.kaaproject.kaa.common.dto.admin.SdkPlatform; import org.kaaproject.kaa.common.dto.admin.SdkProfileDto; @@ -44,6 +64,11 @@ import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException; import org.kaaproject.kaa.server.control.service.exception.ControlServiceException; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + /** * The Interface ControlService. */ @@ -557,6 +582,30 @@ List getConfigurationRecordsByEndpointGroupId(String end */ void editUserConfiguration(EndpointUserConfigurationDto configuration) throws ControlServiceException; + /** + * Creates endpoint specific configuration. + * + * @param configuration endpoint specific configuration + * @return saved endpoint specific configuration + */ + EndpointSpecificConfigurationDto editEndpointSpecificConfiguration(EndpointSpecificConfigurationDto configuration); + + /** + * Retrieves endpoint specific configuration by endpoint key hash. + * + * @param endpointKeyHash endpoint key hash + * @return endpoint specific configuration + */ + EndpointSpecificConfigurationDto findEndpointSpecificConfiguration(String endpointKeyHash); + + /** + * Deletes endpoint specific configuration by endpoint key hash. + * + * @param endpointKeyHash endpoint key hash + * @return deleted endpoint specific configuration + */ + EndpointSpecificConfigurationDto deleteEndpointSpecificConfiguration(String endpointKeyHash); + /** * Activate configuration. * diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/control/service/DefaultControlService.java b/server/node/src/main/java/org/kaaproject/kaa/server/control/service/DefaultControlService.java index 8aff89d745..e52a40dec2 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/control/service/DefaultControlService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/control/service/DefaultControlService.java @@ -16,24 +16,6 @@ package org.kaaproject.kaa.server.control.service; -import static org.apache.commons.lang.StringUtils.isNotBlank; -import static org.kaaproject.kaa.server.admin.services.util.Utils.getCurrentUser; -import static org.kaaproject.kaa.server.admin.shared.util.Utils.isEmpty; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.PreDestroy; - import org.apache.avro.Schema; import org.apache.commons.codec.binary.Base64; import org.apache.thrift.TException; @@ -77,6 +59,7 @@ import org.kaaproject.kaa.server.common.dao.ConfigurationService; import org.kaaproject.kaa.server.common.dao.EndpointRegistrationService; import org.kaaproject.kaa.server.common.dao.EndpointService; +import org.kaaproject.kaa.server.common.dao.EndpointSpecificConfigurationService; import org.kaaproject.kaa.server.common.dao.EventClassService; import org.kaaproject.kaa.server.common.dao.LogAppendersService; import org.kaaproject.kaa.server.common.dao.LogSchemaService; @@ -99,6 +82,7 @@ import org.kaaproject.kaa.server.common.thrift.gen.operations.OperationsThriftService.Iface; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftActorClassifier; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftClusterEntityType; +import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointConfigurationRefreshMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointDeregistrationMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEntityAddress; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftServerProfileUpdateMessage; @@ -131,6 +115,22 @@ import org.springframework.stereotype.Service; import org.springframework.util.Base64Utils; +import javax.annotation.PreDestroy; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +import static org.apache.commons.lang.StringUtils.isNotBlank; +import static org.kaaproject.kaa.server.admin.shared.util.Utils.isEmpty; + /** * The Class DefaultControlService. */ @@ -286,6 +286,9 @@ public class DefaultControlService implements ControlService { @Autowired private EndpointRegistrationService endpointRegistrationService; + @Autowired + private EndpointSpecificConfigurationService endpointSpecificConfigurationService; + /** * The neighbor connections size. */ @@ -881,6 +884,48 @@ public void editUserConfiguration(EndpointUserConfigurationDto configuration) th } } + @Override + public EndpointSpecificConfigurationDto editEndpointSpecificConfiguration(EndpointSpecificConfigurationDto configuration) { + configuration = endpointSpecificConfigurationService.save(configuration); + sendEndpointConfigurationRefreshMessage(configuration.getEndpointKeyHash()); + return configuration; + } + + @Override + public EndpointSpecificConfigurationDto findEndpointSpecificConfiguration(String endpointKeyHash) { + return endpointSpecificConfigurationService.findByEndpointKeyHash(endpointKeyHash) + .orElseThrow(() -> new NotFoundException("Endpoint specific configuration not found")); + } + + @Override + public EndpointSpecificConfigurationDto deleteEndpointSpecificConfiguration(String endpointKeyHash) { + EndpointSpecificConfigurationDto configuration = endpointSpecificConfigurationService.deleteByEndpointKeyHash(endpointKeyHash) + .orElseThrow(() -> new NotFoundException("Endpoint specific configuration not found")); + sendEndpointConfigurationRefreshMessage(endpointKeyHash); + return configuration; + } + + private void sendEndpointConfigurationRefreshMessage(String endpointKeyHash) { + checkNeighbors(); + byte[] endpointKeyHashBytes = Base64Util.decode(endpointKeyHash); + EndpointProfileDto endpointProfile = endpointService.findEndpointProfileByKeyHash(endpointKeyHashBytes); + ApplicationDto appDto = applicationService.findAppById(endpointProfile.getApplicationId()); + OperationsNodeInfo server = resolve(endpointKeyHash); + + if (server != null) { + ThriftEndpointConfigurationRefreshMessage nf = new ThriftEndpointConfigurationRefreshMessage(); + nf.setAddress(new ThriftEntityAddress(appDto.getTenantId(), appDto.getApplicationToken(), ThriftClusterEntityType.ENDPOINT, + ByteBuffer.wrap(endpointKeyHashBytes))); + nf.setActorClassifier(ThriftActorClassifier.GLOBAL); + if (LOG.isTraceEnabled()) { + LOG.trace("Sending message {} to [{}]", nf, Neighbors.getServerID(server.getConnectionInfo())); + } + neighbors.sendMessage(server.getConnectionInfo(), OperationsServiceMsg.fromEndpointConfigurationRefresh(nf)); + } else { + LOG.warn("Can't find server for endpoint [{}]", endpointKeyHash); + } + } + /** * Check neighbors. */ diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/thrift/OperationsServiceMsg.java b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/thrift/OperationsServiceMsg.java index 0e2e03cc79..fc8dac2598 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/thrift/OperationsServiceMsg.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/thrift/OperationsServiceMsg.java @@ -16,16 +16,17 @@ package org.kaaproject.kaa.server.node.service.thrift; -import java.util.ArrayList; -import java.util.List; - import org.apache.thrift.TException; +import org.kaaproject.kaa.server.common.thrift.gen.operations.OperationsThriftService.Iface; +import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointConfigurationRefreshMessage; +import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointDeregistrationMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEntityRouteMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftServerProfileUpdateMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftUnicastNotificationMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.UserConfigurationUpdate; -import org.kaaproject.kaa.server.common.thrift.gen.operations.OperationsThriftService.Iface; -import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointDeregistrationMessage; + +import java.util.ArrayList; +import java.util.List; public class OperationsServiceMsg { private final ThriftUnicastNotificationMessage unicastNotificationMsg; @@ -33,36 +34,43 @@ public class OperationsServiceMsg { private final ThriftEntityRouteMessage entityRouteMsg; private final ThriftEndpointDeregistrationMessage endpointDeregistrationMsg; private final UserConfigurationUpdate userConfigurationUpdateMsg; + private final ThriftEndpointConfigurationRefreshMessage endpointConfigurationRefreshMessage; private OperationsServiceMsg(ThriftUnicastNotificationMessage unicastNotificationMsg, - ThriftServerProfileUpdateMessage serverProfileUpdateMsg, ThriftEntityRouteMessage entityRouteMsg, - UserConfigurationUpdate userConfigurationUpdateMsg, ThriftEndpointDeregistrationMessage endpointDeregistrationMsg) { + ThriftServerProfileUpdateMessage serverProfileUpdateMsg, ThriftEntityRouteMessage entityRouteMsg, + UserConfigurationUpdate userConfigurationUpdateMsg, ThriftEndpointDeregistrationMessage endpointDeregistrationMsg, + ThriftEndpointConfigurationRefreshMessage endpointConfigurationRefreshMessage) { super(); this.unicastNotificationMsg = unicastNotificationMsg; this.serverProfileUpdateMsg = serverProfileUpdateMsg; this.entityRouteMsg = entityRouteMsg; this.endpointDeregistrationMsg = endpointDeregistrationMsg; this.userConfigurationUpdateMsg = userConfigurationUpdateMsg; + this.endpointConfigurationRefreshMessage = endpointConfigurationRefreshMessage; } public static OperationsServiceMsg fromServerProfileUpdateMessage(ThriftServerProfileUpdateMessage serverProfileUpdateMsg) { - return new OperationsServiceMsg(null, serverProfileUpdateMsg, null, null, null); + return new OperationsServiceMsg(null, serverProfileUpdateMsg, null, null, null, null); } public static OperationsServiceMsg fromNotification(ThriftUnicastNotificationMessage unicastNotificationMsg) { - return new OperationsServiceMsg(unicastNotificationMsg, null, null, null, null); + return new OperationsServiceMsg(unicastNotificationMsg, null, null, null, null, null); } public static OperationsServiceMsg fromRoute(ThriftEntityRouteMessage entityRouteMsg) { - return new OperationsServiceMsg(null, null, entityRouteMsg, null, null); + return new OperationsServiceMsg(null, null, entityRouteMsg, null, null, null); } public static OperationsServiceMsg fromUpdate(UserConfigurationUpdate userConfigurationUpdateMsg) { - return new OperationsServiceMsg(null, null, null, userConfigurationUpdateMsg, null); + return new OperationsServiceMsg(null, null, null, userConfigurationUpdateMsg, null, null); } public static OperationsServiceMsg fromDeregistration(ThriftEndpointDeregistrationMessage endpointDeregistrationMsg) { - return new OperationsServiceMsg(null, null, null, null, endpointDeregistrationMsg); + return new OperationsServiceMsg(null, null, null, null, endpointDeregistrationMsg, null); + } + + public static OperationsServiceMsg fromEndpointConfigurationRefresh(ThriftEndpointConfigurationRefreshMessage endpointConfigurationRefreshMessage) { + return new OperationsServiceMsg(null, null, null, null, null, endpointConfigurationRefreshMessage); } public ThriftUnicastNotificationMessage getUnicastNotificationMsg() { @@ -101,6 +109,9 @@ public static void dispatch(Iface client, List messages) t if (msg.getUserConfigurationUpdateMsg() != null) { updates.add(msg.getUserConfigurationUpdateMsg()); } + if (msg.getEndpointConfigurationRefreshMessage() != null) { + client.sendEndpointConfigurationRefreshMessage(msg.getEndpointConfigurationRefreshMessage()); + } if (msg.getEntityRouteMsg() != null) { routes.add(msg.getEntityRouteMsg()); } @@ -113,4 +124,8 @@ public static void dispatch(Iface client, List messages) t } } + public ThriftEndpointConfigurationRefreshMessage getEndpointConfigurationRefreshMessage() { + return endpointConfigurationRefreshMessage; + } + } \ No newline at end of file diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/DefaultOperationsService.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/DefaultOperationsService.java index 40fe591ed5..f09b4e890d 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/DefaultOperationsService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/DefaultOperationsService.java @@ -16,18 +16,9 @@ package org.kaaproject.kaa.server.operations.service; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.security.PublicKey; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; - import org.kaaproject.kaa.common.dto.EndpointGroupStateDto; import org.kaaproject.kaa.common.dto.EndpointProfileDto; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; import org.kaaproject.kaa.common.dto.EndpointUserConfigurationDto; import org.kaaproject.kaa.common.dto.NotificationDto; import org.kaaproject.kaa.common.dto.TopicDto; @@ -37,6 +28,7 @@ import org.kaaproject.kaa.server.common.Base64Util; import org.kaaproject.kaa.server.common.core.structure.Pair; import org.kaaproject.kaa.server.common.dao.EndpointService; +import org.kaaproject.kaa.server.common.dao.EndpointSpecificConfigurationService; import org.kaaproject.kaa.server.common.dao.UserConfigurationService; import org.kaaproject.kaa.server.operations.pojo.GetDeltaRequest; import org.kaaproject.kaa.server.operations.pojo.GetDeltaResponse; @@ -85,6 +77,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.security.PublicKey; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; + @Service public class DefaultOperationsService implements OperationsService { @@ -115,6 +118,9 @@ public class DefaultOperationsService implements OperationsService { @Autowired EndpointService endpointService; + @Autowired + EndpointSpecificConfigurationService endpointSpecificConfigurationService; + private String operationServerHash; @Override @@ -192,7 +198,7 @@ public SyncContext processEventListenerRequests(SyncContext context, EventClient return context; } - private EndpointProfileDto syncProfileState(String appToken, String endpointId, EndpointProfileDto endpointProfile, boolean userConfigurationChanged) { + private EndpointProfileDto syncProfileState(String appToken, String endpointId, EndpointProfileDto endpointProfile, boolean updateConfiguration) { LOG.debug("[{}][{}] going to sync endpoint group states", appToken, endpointId); Function> updateFunction = profile -> { @@ -201,7 +207,7 @@ private EndpointProfileDto syncProfileState(String appToken, String endpointId, HistoryDelta historyDelta = fetchHistory(endpointId, appToken, profile, curAppSeqNumber); profile.setGroupState(historyDelta.getEndpointGroupStates()); profile.setSequenceNumber(curAppSeqNumber); - if (historyDelta.isConfigurationChanged() || userConfigurationChanged) { + if (historyDelta.isConfigurationChanged() || updateConfiguration) { LOG.debug("[{}][{}] configuration change detected", appToken, endpointId); try { syncEndpointConfiguration(appToken, endpointId, profile); @@ -221,11 +227,12 @@ private EndpointProfileDto syncProfileState(String appToken, String endpointId, endpointProfile = result.getV1(); HistoryDelta historyDelta = result.getV2(); - if (historyDelta.isSmthChanged() || userConfigurationChanged) { + if (historyDelta.isSmthChanged() || updateConfiguration) { LOG.debug("[{}][{}] going to save new profile", appToken, endpointId); endpointProfile = profileService.updateProfile(endpointProfile, (storedProfile, newProfile) -> { - if (userConfigurationChanged) { + if (updateConfiguration) { storedProfile.setUserConfigurationHash(newProfile.getUserConfigurationHash()); + storedProfile.setEpsConfigurationHash(newProfile.getEpsConfigurationHash()); } storedProfile.setGroupState(new ArrayList()); return updateFunction.apply(storedProfile).getV1(); @@ -241,11 +248,11 @@ private void syncEndpointConfiguration(String appToken, String endpointId, Endpo LOG.trace("[{}][{}] Result configuration hash is {}", appToken, endpointId, Arrays.toString(configurationHash)); } profile.setConfigurationHash(configurationHash); - if (configurationCache.getUserConfigurationHash() != null) { - profile.setUserConfigurationHash(configurationCache.getUserConfigurationHash().getData()); - } else { - profile.setUserConfigurationHash(null); - } + EndpointObjectHash userConfigHash = configurationCache.getUserConfigurationHash(); + profile.setUserConfigurationHash(userConfigHash == null ? null : userConfigHash.getData()); + EndpointObjectHash epsConfigHash = configurationCache.getEpsConfigurationHash(); + profile.setEpsConfigurationHash(epsConfigHash == null ? null : epsConfigHash.getData()); + } private void syncTopicList(String appToken, String endpointId, EndpointProfileDto profile) { @@ -268,10 +275,11 @@ public SyncContext syncConfiguration(SyncContext context, ConfigurationClientSyn } @Override - public SyncContext syncUserConfigurationHash(SyncContext context, byte[] ucfHash) { + public SyncContext syncConfigurationHashes(SyncContext context, byte[] ucfHash, byte[] epsConfigHash) { EndpointProfileDto profile = context.getEndpointProfile(); profile.setUserConfigurationHash(ucfHash); - profile = syncProfileState(context.getAppToken(), context.getEndpointKey(), profile, true); + profile.setEpsConfigurationHash(epsConfigHash); + syncProfileState(context.getAppToken(), context.getEndpointKey(), profile, true); return context; } @@ -341,6 +349,13 @@ public byte[] fetchUcfHash(String appToken, EndpointProfileDto profile) { return null; } + @Override + public byte[] fetchEndpointSpecificConfigurationHash(EndpointProfileDto profile) { + Optional configuration = endpointSpecificConfigurationService.findByEndpointProfile(profile); + return configuration.filter(conf -> conf.getConfiguration() != null) + .map(dto -> EndpointObjectHash.fromString(dto.getConfiguration()).getData()).orElse(null); + } + private EndpointProfileDto registerEndpoint(String endpointId, int requestHash, ClientSyncMetaData metaData, ProfileClientSync request) { LOG.debug("[{}][{}] register endpoint. request: {}", endpointId, requestHash, request); byte[] endpointKey = toByteArray(request.getEndpointPublicKey()); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/OperationsService.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/OperationsService.java index 3589d1291a..68d72b6110 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/OperationsService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/OperationsService.java @@ -16,8 +16,6 @@ package org.kaaproject.kaa.server.operations.service; -import java.util.List; - import org.kaaproject.kaa.common.dto.EndpointProfileDto; import org.kaaproject.kaa.common.dto.NotificationDto; import org.kaaproject.kaa.common.hash.EndpointObjectHash; @@ -31,6 +29,8 @@ import org.kaaproject.kaa.server.sync.ServerSync; import org.kaaproject.kaa.server.sync.UserClientSync; +import java.util.List; + /** * The interface OperationsService is used to define key operations with * Endpoint Node. One can register, update and sync endpoint state. @@ -63,6 +63,15 @@ public interface OperationsService extends PublicKeyAware { */ EndpointProfileDto attachEndpointToUser(EndpointProfileDto profile, String appToken, String userExternalId); + /** + * Retrieves endpoint specific configuration hash according + * to current endpoint configuration schema version + * + * @param profile the endpoint profile + * @return endpoint specific configuration hash + */ + byte[] fetchEndpointSpecificConfigurationHash(EndpointProfileDto profile); + /** * Update sync response. * @@ -92,13 +101,14 @@ public interface OperationsService extends PublicKeyAware { public EndpointProfileDto refreshServerEndpointProfile(EndpointObjectHash hash); /** - * Update profile state based on new user configuration hash + * Update profile state based on new user and endpoint specific configuration hashes * * @param context - sync context that contains profile and other metadata * @param ucfHash - user configuration hash + * @param epsConfHash - endpoint specific configuration hash * @return sync context */ - SyncContext syncUserConfigurationHash(SyncContext context, byte[] ucfHash); + SyncContext syncConfigurationHashes(SyncContext context, byte[] ucfHash, byte[] epsConfHash); SyncContext syncUseConfigurationRawSchema(SyncContext context, boolean useConfigurationRawSchema); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/global/GlobalEndpointActorMessageProcessor.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/global/GlobalEndpointActorMessageProcessor.java index 868042615b..d4f89a12bd 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/global/GlobalEndpointActorMessageProcessor.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/global/GlobalEndpointActorMessageProcessor.java @@ -16,11 +16,11 @@ package org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.global; -import java.util.function.BiConsumer; - +import akka.actor.ActorContext; import org.kaaproject.kaa.common.hash.EndpointObjectHash; import org.kaaproject.kaa.server.common.Base64Util; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftActorClassifier; +import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointConfigurationRefreshMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftServerProfileUpdateMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftUnicastNotificationMessage; import org.kaaproject.kaa.server.operations.service.OperationsService; @@ -35,7 +35,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import akka.actor.ActorContext; +import java.util.function.BiConsumer; public class GlobalEndpointActorMessageProcessor extends AbstractEndpointActorMessageProcessor { @@ -86,6 +86,8 @@ protected void processThriftMsg(ActorContext context, ThriftEndpointActorMsg processServerProfileUpdateMsg(context, (ThriftServerProfileUpdateMessage) thriftMsg); } else if (thriftMsg instanceof ThriftUnicastNotificationMessage) { processUnicastNotificationMsg(context, (ThriftUnicastNotificationMessage) thriftMsg); + } else if (thriftMsg instanceof ThriftEndpointConfigurationRefreshMessage) { + processEndpointConfigurationRefreshMsg(context, (ThriftEndpointConfigurationRefreshMessage) thriftMsg); } } @@ -106,6 +108,12 @@ private void processUnicastNotificationMsg(ActorContext context, ThriftUnicastNo }); } + private void processEndpointConfigurationRefreshMsg(ActorContext context, ThriftEndpointConfigurationRefreshMessage thriftMsg) { + ThriftEndpointConfigurationRefreshMessage localMsg = new ThriftEndpointConfigurationRefreshMessage(thriftMsg); + localMsg.setActorClassifier(ThriftActorClassifier.LOCAL); + dispatchMsg(context, localMsg, clusterService::sendEndpointConfigurationRefreshMessage); + } + private void dispatchMsg(ActorContext context, T localMsg, BiConsumer f) { for (EndpointClusterAddress address : routes.getLocalRoutes()) { LOG.info("Forwarding {} to local endpoint actor {}", localMsg, address); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/local/LocalEndpointActorMessageProcessor.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/local/LocalEndpointActorMessageProcessor.java index 508c142e6a..41437402f1 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/local/LocalEndpointActorMessageProcessor.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/local/LocalEndpointActorMessageProcessor.java @@ -16,18 +16,7 @@ package org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.local; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - +import akka.actor.ActorContext; import org.kaaproject.kaa.common.TransportType; import org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.PingResponse; import org.kaaproject.kaa.common.dto.EndpointProfileDataDto; @@ -37,6 +26,7 @@ import org.kaaproject.kaa.server.common.Base64Util; import org.kaaproject.kaa.server.common.log.shared.appender.LogEvent; import org.kaaproject.kaa.server.common.log.shared.appender.data.BaseLogEventPack; +import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointConfigurationRefreshMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointDeregistrationMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftServerProfileUpdateMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftUnicastNotificationMessage; @@ -93,10 +83,20 @@ import org.kaaproject.kaa.server.transport.channel.ChannelType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import akka.actor.ActorContext; import scala.concurrent.duration.Duration; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + public class LocalEndpointActorMessageProcessor extends AbstractEndpointActorMessageProcessor { /** The Constant LOG. */ @@ -149,7 +149,7 @@ public void processThriftNotification(ActorContext context) { public void processUserConfigurationUpdate(ActorContext context, EndpointUserConfigurationUpdateMessage message) { if (message.getUserConfigurationUpdate() != null) { state.setUcfHash(message.getUserConfigurationUpdate().getHash()); - syncChannels(context, state.getChannelsByTypes(TransportType.CONFIGURATION), true, false); + refreshConfiguration(context); } } @@ -162,7 +162,22 @@ protected void processThriftMsg(ActorContext context, ThriftEndpointActorMsg processUnicastNotificationMsg(context, (ThriftUnicastNotificationMessage) thriftMsg); } else if (thriftMsg instanceof ThriftEndpointDeregistrationMessage) { processEndpointDeregistrationMessage(context, (ThriftEndpointDeregistrationMessage) thriftMsg); + } else if (thriftMsg instanceof ThriftEndpointConfigurationRefreshMessage) { + processEndpointSpecificConfigurationChanged(context); + } + } + + private void processEndpointSpecificConfigurationChanged(ActorContext context) { + if (state.getProfile() == null) { + state.setProfile(operationsService.refreshServerEndpointProfile(key)); } + EndpointProfileDto profile = state.getProfile(); + state.setEpsConfigurationHash(operationsService.fetchEndpointSpecificConfigurationHash(profile)); + refreshConfiguration(context); + } + + private void refreshConfiguration(ActorContext context) { + syncChannels(context, state.getChannelsByTypes(TransportType.CONFIGURATION), true, false); } private void processServerProfileUpdateMsg(ActorContext context, ThriftServerProfileUpdateMessage thriftMsg) { @@ -287,8 +302,9 @@ private SyncContext sync(ClientSync request) throws GetDeltaException { LOG.warn("[{}] Request is not valid. It does not contain profile information!", endpointKey); return SyncContext.failure(request.getRequestId()); } + EndpointProfileDto profile = state.getProfile(); SyncContext context = new SyncContext(new ServerSync()); - context.setEndpointProfile(state.getProfile()); + context.setEndpointProfile(profile); context.setRequestId(request.getRequestId()); context.setStatus(SyncStatus.SUCCESS); context.setEndpointKey(endpointKey); @@ -305,17 +321,20 @@ private SyncContext sync(ClientSync request) throws GetDeltaException { return context; } if (state.isUcfHashRequiresIntialization()) { - byte[] hash = operationsService.fetchUcfHash(appToken, state.getProfile()); + byte[] hash = operationsService.fetchUcfHash(appToken, profile); LOG.debug("[{}][{}] Initialized endpoint user configuration hash {}", endpointKey, context.getRequestHash(), Arrays.toString(hash)); state.setUcfHash(hash); } + if (state.isEpsConfigurationRequiresInitialization()) { + state.setEpsConfigurationHash(operationsService.fetchEndpointSpecificConfigurationHash(profile)); + } context = operationsService.processEndpointAttachDetachRequests(context, request.getUserSync()); context = operationsService.processEventListenerRequests(context, request.getEventSync()); - if (state.isUserConfigurationUpdatePending()) { - context = operationsService.syncUserConfigurationHash(context, state.getUcfHash()); + if (state.isUserConfigurationUpdatePending() || state.isEpsConfigurationChanged()) { + context = operationsService.syncConfigurationHashes(context, state.getUcfHash(), state.getEpsConfigurationHash()); } context = operationsService.syncConfiguration(context, request.getConfigurationSync()); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/local/LocalEndpointActorState.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/local/LocalEndpointActorState.java index 5aa9556637..b9a2941e9f 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/local/LocalEndpointActorState.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/akka/actors/core/endpoint/local/LocalEndpointActorState.java @@ -16,6 +16,14 @@ package org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.local; +import org.kaaproject.kaa.common.TransportType; +import org.kaaproject.kaa.common.dto.EndpointProfileDto; +import org.kaaproject.kaa.common.dto.NotificationDto; +import org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.AbstractEndpointActorState; +import org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.local.ChannelMap.ChannelMetaData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -25,14 +33,6 @@ import java.util.Set; import java.util.UUID; -import org.kaaproject.kaa.common.TransportType; -import org.kaaproject.kaa.common.dto.EndpointProfileDto; -import org.kaaproject.kaa.common.dto.NotificationDto; -import org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.AbstractEndpointActorState; -import org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.local.ChannelMap.ChannelMetaData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class LocalEndpointActorState extends AbstractEndpointActorState { private static final Logger LOG = LoggerFactory.getLogger(LocalEndpointActorState.class); @@ -46,6 +46,8 @@ public class LocalEndpointActorState extends AbstractEndpointActorState { private boolean ucfHashIntialized; private byte[] ucfHash; + private boolean epsConfigurationInitialized; + private byte[] epsConfigurationHash; public LocalEndpointActorState(String endpointKey, String actorKey) { super(endpointKey, actorKey); @@ -187,6 +189,29 @@ public byte[] getUcfHash() { return ucfHash; } + public boolean isEpsConfigurationRequiresInitialization() { + if (endpointProfile == null) { + return false; + } + return !epsConfigurationInitialized; + } + + public boolean isEpsConfigurationChanged() { + if (endpointProfile == null) { + return false; + } + return !Arrays.equals(epsConfigurationHash, endpointProfile.getEpsConfigurationHash()); + } + + public byte[] getEpsConfigurationHash() { + return epsConfigurationHash; + } + + public void setEpsConfigurationHash(byte[] epsConfigurationHash) { + this.epsConfigurationHash = epsConfigurationHash; + this.epsConfigurationInitialized = true; + } + public List filter(List notifications) { List list = new ArrayList(notifications.size()); for (NotificationDto nf : notifications) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/ConfigurationCacheEntry.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/ConfigurationCacheEntry.java index 081b7eaf26..43d5783797 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/ConfigurationCacheEntry.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/ConfigurationCacheEntry.java @@ -16,11 +16,11 @@ package org.kaaproject.kaa.server.operations.service.cache; -import java.io.Serializable; - import org.kaaproject.kaa.common.hash.EndpointObjectHash; import org.kaaproject.kaa.server.common.core.algorithms.delta.RawBinaryDelta; +import java.io.Serializable; + /** * The Class DeltaCacheEntry is used to model cache entry for delta calculation. * Contains hash object, result configuration itself and delta. @@ -44,6 +44,8 @@ public class ConfigurationCacheEntry implements Serializable { /** The hash. */ private final EndpointObjectHash userConfigurationHash; + private final EndpointObjectHash epsConfigurationHash; + /** * Instantiates a new delta cache entry. * @@ -51,13 +53,17 @@ public class ConfigurationCacheEntry implements Serializable { * @param delta the delta * @param hash the hash * @param userConfigurationHash the user configuration hash + * @param epsConfigurationHash endpoint specific configuration hash */ - public ConfigurationCacheEntry(byte[] configuration, RawBinaryDelta delta, EndpointObjectHash hash, EndpointObjectHash userConfigurationHash) { + public ConfigurationCacheEntry(byte[] configuration, RawBinaryDelta delta, + EndpointObjectHash hash, EndpointObjectHash userConfigurationHash, + EndpointObjectHash epsConfigurationHash) { super(); this.configuration = configuration; this.delta = delta; this.hash = hash; this.userConfigurationHash = userConfigurationHash; + this.epsConfigurationHash = epsConfigurationHash; } /** @@ -95,4 +101,8 @@ public EndpointObjectHash getHash() { public EndpointObjectHash getUserConfigurationHash() { return userConfigurationHash; } + + public EndpointObjectHash getEpsConfigurationHash() { + return epsConfigurationHash; + } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKey.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKey.java index 4437cf9b63..70e7b5a4d8 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKey.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKey.java @@ -16,12 +16,12 @@ package org.kaaproject.kaa.server.operations.service.cache; -import java.io.Serializable; -import java.util.List; - import org.kaaproject.kaa.common.dto.EndpointGroupStateDto; import org.kaaproject.kaa.common.hash.EndpointObjectHash; +import java.io.Serializable; +import java.util.List; + /** * The Class DeltaCacheKey is used to model key of cache entry for delta * calculation. Contains appToken, appSeqNumber, list of active endpoint groups @@ -37,7 +37,7 @@ public final class DeltaCacheKey implements Serializable { private final List endpointGroups; - private final EndpointObjectHash endpointConfHash; + private final EndpointObjectHash confHash; // indicates that client want to receive resync based on base schema private final boolean resyncOnly; @@ -45,26 +45,29 @@ public final class DeltaCacheKey implements Serializable { private final boolean useConfigurationRawSchema; private final EndpointObjectHash userConfHash; + private final EndpointObjectHash epsConfHash; public DeltaCacheKey(AppVersionKey appConfigVersionKey, List endpointGroups, EndpointObjectHash userConfHash, - EndpointObjectHash endpointConfHash) { - this(appConfigVersionKey, endpointGroups, userConfHash, endpointConfHash, true, false); + EndpointObjectHash epsConfHash, EndpointObjectHash confHash) { + this(appConfigVersionKey, endpointGroups, userConfHash, epsConfHash, confHash, true, false); } public DeltaCacheKey(AppVersionKey appConfigVersionKey, List endpointGroups, EndpointObjectHash userConfHash, - EndpointObjectHash endpointConfHash, boolean useConfigurationRawSchema) { - this(appConfigVersionKey, endpointGroups, userConfHash, endpointConfHash, useConfigurationRawSchema, false); + EndpointObjectHash epsConfHash, EndpointObjectHash confHash, boolean useConfigurationRawSchema) { + this(appConfigVersionKey, endpointGroups, userConfHash, epsConfHash, confHash, useConfigurationRawSchema, false); } public DeltaCacheKey(AppVersionKey appConfigVersionKey, List endpointGroups, - EndpointObjectHash userConfHash, EndpointObjectHash endpointConfHash, boolean useConfigurationRawSchema, boolean resyncOnly) { + EndpointObjectHash userConfHash, EndpointObjectHash epsConfHash, EndpointObjectHash confHash, + boolean useConfigurationRawSchema, boolean resyncOnly) { this.appConfigVersionKey = appConfigVersionKey; this.userConfHash = userConfHash; this.endpointGroups = endpointGroups; - this.endpointConfHash = endpointConfHash; + this.confHash = confHash; this.useConfigurationRawSchema = useConfigurationRawSchema; this.resyncOnly = resyncOnly; + this.epsConfHash = epsConfHash; } @@ -79,8 +82,8 @@ public List getEndpointGroups() { } - public EndpointObjectHash getEndpointConfHash() { - return endpointConfHash; + public EndpointObjectHash getConfHash() { + return confHash; } /** @@ -114,7 +117,9 @@ public boolean equals(Object o) { return false; if (endpointGroups != null ? !endpointGroups.equals(that.endpointGroups) : that.endpointGroups != null) return false; - if (endpointConfHash != null ? !endpointConfHash.equals(that.endpointConfHash) : that.endpointConfHash != null) + if (confHash != null ? !confHash.equals(that.confHash) : that.confHash != null) + return false; + if (epsConfHash != null ? !epsConfHash.equals(that.epsConfHash) : that.epsConfHash != null) return false; return userConfHash != null ? userConfHash.equals(that.userConfHash) : that.userConfHash == null; @@ -124,10 +129,11 @@ public boolean equals(Object o) { public int hashCode() { int result = appConfigVersionKey != null ? appConfigVersionKey.hashCode() : 0; result = 31 * result + (endpointGroups != null ? endpointGroups.hashCode() : 0); - result = 31 * result + (endpointConfHash != null ? endpointConfHash.hashCode() : 0); + result = 31 * result + (confHash != null ? confHash.hashCode() : 0); result = 31 * result + (resyncOnly ? 1 : 0); result = 31 * result + (useConfigurationRawSchema ? 1 : 0); result = 31 * result + (userConfHash != null ? userConfHash.hashCode() : 0); + result = 31 * result + (epsConfHash != null ? epsConfHash.hashCode() : 0); return result; } @@ -138,14 +144,16 @@ public String toString() { builder.append(appConfigVersionKey); builder.append(", endpointGroups="); builder.append(endpointGroups); - builder.append(", endpointConfHash="); - builder.append(endpointConfHash); + builder.append(", confHash="); + builder.append(confHash); builder.append(", resyncOnly="); builder.append(resyncOnly); builder.append(", useRawSchema="); builder.append(useConfigurationRawSchema); builder.append(", userConfHash="); builder.append(userConfHash); + builder.append(", epsConfHash="); + builder.append(epsConfHash); builder.append("]"); return builder.toString(); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cluster/ClusterService.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cluster/ClusterService.java index 44a5019e20..f520587c96 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cluster/ClusterService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cluster/ClusterService.java @@ -16,9 +16,8 @@ package org.kaaproject.kaa.server.operations.service.cluster; -import java.util.List; - import org.kaaproject.kaa.common.hash.EndpointObjectHash; +import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointConfigurationRefreshMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointDeregistrationMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEntityRouteMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftServerProfileUpdateMessage; @@ -27,6 +26,8 @@ import org.kaaproject.kaa.server.operations.service.akka.messages.core.route.EndpointRouteMessage; import org.kaaproject.kaa.server.resolve.OperationsServerResolver; +import java.util.List; + public interface ClusterService { /** @@ -123,6 +124,13 @@ public interface ClusterService { */ void sendServerProfileUpdateMessage(String nodeId, ThriftServerProfileUpdateMessage msg); + /** + * Send endpoint configuration refresh message to specified node + * @param nodeId id of the server node + * @param msg the endpoint configuration refresh message + */ + void sendEndpointConfigurationRefreshMessage(String nodeId, ThriftEndpointConfigurationRefreshMessage msg); + /** * Process entity route messages * @@ -137,6 +145,13 @@ public interface ClusterService { */ void onUnicastNotificationMessage(ThriftUnicastNotificationMessage msg); + /** + * Process endpoint configuration refresh message + * + * @param msg endpoint configuration refresh message + */ + void sendEndpointConfigurationRefreshMessage(ThriftEndpointConfigurationRefreshMessage msg); + /** * Process server profile update message * @param msg the server profile update message diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cluster/DefaultClusterService.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cluster/DefaultClusterService.java index e99c175cf3..3ac0f35380 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cluster/DefaultClusterService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/cluster/DefaultClusterService.java @@ -16,13 +16,6 @@ package org.kaaproject.kaa.server.operations.service.cluster; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.apache.thrift.TException; import org.kaaproject.kaa.common.hash.EndpointObjectHash; import org.kaaproject.kaa.server.common.Base64Util; @@ -30,6 +23,7 @@ import org.kaaproject.kaa.server.common.thrift.gen.operations.OperationsThriftService.Iface; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftActorClassifier; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftClusterEntityType; +import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointConfigurationRefreshMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointDeregistrationMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEntityAddress; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEntityClusterAddress; @@ -58,6 +52,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + @Service public class DefaultClusterService implements ClusterService { @@ -209,6 +209,11 @@ public void sendServerProfileUpdateMessage(String serverId, ThriftServerProfileU sendServerProfileUpdateMessage(serverId, OperationsServiceMsg.fromServerProfileUpdateMessage(msg)); } + @Override + public void sendEndpointConfigurationRefreshMessage(String serverId, ThriftEndpointConfigurationRefreshMessage msg) { + sendServerProfileUpdateMessage(serverId, OperationsServiceMsg.fromEndpointConfigurationRefresh(msg)); + } + private void sendServerProfileUpdateMessage(String serverId, OperationsServiceMsg msg) { NeighborConnection server = neighbors.getNeghborConnection(serverId); if (server == null) { @@ -238,6 +243,13 @@ public void onUnicastNotificationMessage(ThriftUnicastNotificationMessage msg) { listener.onEndpointActorMsg(new ThriftEndpointActorMsg(address, classifier, msg)); } + @Override + public void sendEndpointConfigurationRefreshMessage(ThriftEndpointConfigurationRefreshMessage msg) { + EndpointAddress address = fromThriftAddress(msg.getAddress()); + ActorClassifier classifier = fromThriftActorClassifier(msg.getActorClassifier()); + listener.onEndpointActorMsg(new ThriftEndpointActorMsg(address, classifier, msg)); + } + @Override public void onServerProfileUpdateMessage(ThriftServerProfileUpdateMessage msg) { EndpointAddress address = fromThriftAddress(msg.getAddress()); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java index a5bbd2cad9..26fbb592c5 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/delta/DefaultDeltaService.java @@ -16,9 +16,6 @@ package org.kaaproject.kaa.server.operations.service.delta; -import java.io.IOException; -import java.util.*; - import org.apache.commons.lang.StringUtils; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.map.ObjectMapper; @@ -29,8 +26,8 @@ import org.kaaproject.kaa.common.dto.EndpointGroupDto; import org.kaaproject.kaa.common.dto.EndpointGroupStateDto; import org.kaaproject.kaa.common.dto.EndpointProfileDto; +import org.kaaproject.kaa.common.dto.EndpointSpecificConfigurationDto; import org.kaaproject.kaa.common.dto.EndpointUserConfigurationDto; -import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.endpoint.security.MessageEncoderDecoder; import org.kaaproject.kaa.common.hash.EndpointObjectHash; import org.kaaproject.kaa.server.common.Base64Util; @@ -49,6 +46,7 @@ import org.kaaproject.kaa.server.common.core.structure.Pair; import org.kaaproject.kaa.server.common.dao.ConfigurationService; import org.kaaproject.kaa.server.common.dao.EndpointService; +import org.kaaproject.kaa.server.common.dao.EndpointSpecificConfigurationService; import org.kaaproject.kaa.server.common.dao.UserConfigurationService; import org.kaaproject.kaa.server.operations.pojo.GetDeltaRequest; import org.kaaproject.kaa.server.operations.pojo.GetDeltaResponse; @@ -64,6 +62,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; + /** * Implementation of {@link DeltaService}. Delta calculation process is quite * resource consuming. In order to minimize amount of delta calculations, @@ -93,6 +99,9 @@ public class DefaultDeltaService implements DeltaService { @Autowired private OverrideAlgorithmFactory configurationOverrideFactory; + @Autowired + private EndpointSpecificConfigurationService endpointSpecificConfigurationService; + private static final Comparator ENDPOINT_GROUP_COMPARATOR = new Comparator() { @@ -119,8 +128,11 @@ public DefaultDeltaService() { public ConfigurationCacheEntry getConfiguration(String appToken, String endpointId, EndpointProfileDto profile) throws GetDeltaException { LOG.debug("[{}][{}] Calculating new configuration", appToken, endpointId); AppVersionKey appConfigVersionKey = new AppVersionKey(appToken, profile.getConfigurationVersion()); - DeltaCacheKey deltaKey = new DeltaCacheKey(appConfigVersionKey, profile.getGroupState(), EndpointObjectHash.fromBytes(profile - .getUserConfigurationHash()), null, profile.isUseConfigurationRawSchema(), true); + EndpointObjectHash userConfHash = EndpointObjectHash.fromBytes(profile + .getUserConfigurationHash()); + EndpointObjectHash epsConfHash = EndpointObjectHash.fromBytes(profile + .getEpsConfigurationHash()); + DeltaCacheKey deltaKey = new DeltaCacheKey(appConfigVersionKey, profile.getGroupState(), userConfHash, epsConfHash, null, profile.isUseConfigurationRawSchema(), true); LOG.debug("[{}][{}] Built resync delta key {}", appToken, endpointId, deltaKey); return getDelta(endpointId, profile.getEndpointUserId(), deltaKey, profile.isUseConfigurationRawSchema()); } @@ -185,14 +197,21 @@ private void logHashMismatch(GetDeltaRequest request, EndpointProfileDto profile */ private ConfigurationCacheEntry getDelta(final String endpointId, final String userId, DeltaCacheKey deltaKey, boolean useConfigurationRawSchema) throws GetDeltaException { EndpointUserConfigurationDto userConfiguration = findLatestUserConfiguration(userId, deltaKey); - + Optional epsConfigOpt = Optional.empty(); + if (endpointId != null) { + epsConfigOpt = endpointSpecificConfigurationService.findByEndpointKeyHash(endpointId); + } + EndpointSpecificConfigurationDto epsConfig = epsConfigOpt.orElse(null); final DeltaCacheKey newKey; - if (userConfiguration != null) { + EndpointObjectHash userConfHash = userConfiguration != null ? EndpointObjectHash.fromString(userConfiguration.getBody()) : null; + EndpointObjectHash epsConfHash = epsConfigOpt.map(conf -> EndpointObjectHash.fromString(conf.getConfiguration())).orElse(null); + if (userConfiguration != null || epsConfig != null) { newKey = new DeltaCacheKey( deltaKey.getAppConfigVersionKey(), deltaKey.getEndpointGroups(), - EndpointObjectHash.fromString(userConfiguration.getBody()), - deltaKey.getEndpointConfHash(), + userConfHash, + epsConfHash, + deltaKey.getConfHash(), useConfigurationRawSchema, deltaKey.isResyncOnly() ); @@ -209,14 +228,9 @@ public ConfigurationCacheEntry compute(DeltaCacheKey deltaKey) { AbstractKaaData data; ConfigurationSchemaDto latestConfigurationSchema = cacheService.getConfSchemaByAppAndVersion(deltaKey.getAppConfigVersionKey()); - EndpointUserConfigurationDto userConfiguration = findLatestUserConfiguration(userId, deltaKey); + EndpointUserConfigurationDto userConfig = findLatestUserConfiguration(userId, deltaKey); - EndpointObjectHash userConfigurationHash = null; - if (userConfiguration != null) { - userConfigurationHash = EndpointObjectHash.fromString(userConfiguration.getBody()); - } - - Pair mergedConfiguration = getMergedConfiguration(endpointId, userConfiguration, deltaKey, latestConfigurationSchema); + Pair mergedConfiguration = getMergedConfiguration(endpointId, userConfig, epsConfig, deltaKey, latestConfigurationSchema); if(useConfigurationRawSchema) { data = mergedConfiguration.getV2(); @@ -225,7 +239,7 @@ public ConfigurationCacheEntry compute(DeltaCacheKey deltaKey) { } LOG.trace("[{}] Merged configuration {}", endpointId, data.getRawData()); - deltaCache = buildBaseResyncDelta(endpointId, data.getRawData(), data.getSchema().getRawSchema(), userConfigurationHash); + deltaCache = buildBaseResyncDelta(endpointId, data.getRawData(), data.getSchema().getRawSchema(), userConfHash, epsConfHash); if (cacheService.getConfByHash(deltaCache.getHash()) == null) { EndpointConfigurationDto newConfiguration = new EndpointConfigurationDto(); @@ -297,13 +311,14 @@ private BaseData processEndpointGroups(List endpointGroups, Li * Gets the latest conf from cache * * @param endpointId - * @param userConfiguration + * @param userConfig * @param cacheKey * @return the latest conf from cache * @throws GetDeltaException */ - private Pair getMergedConfiguration(final String endpointId, final EndpointUserConfigurationDto userConfiguration, - final DeltaCacheKey cacheKey, ConfigurationSchemaDto latestConfigurationSchema) throws GetDeltaException { + private Pair getMergedConfiguration(final String endpointId, final EndpointUserConfigurationDto userConfig, + EndpointSpecificConfigurationDto epsConfig, final DeltaCacheKey cacheKey, + ConfigurationSchemaDto latestConfigurationSchema) throws GetDeltaException { final List egsList = cacheKey.getEndpointGroups(); // return Pair in order to cache both calculated configuration and optimize performance @@ -356,33 +371,42 @@ public Pair compute(List key) { } }); - if (userConfiguration != null) { - OverrideAlgorithm configurationMerger = configurationOverrideFactory.createConfigurationOverrideAlgorithm(); - OverrideSchema overrideSchema = new OverrideSchema(latestConfigurationSchema.getOverrideSchema()); - try { - LOG.trace("Merging group configuration with user configuration: {}", userConfiguration.getBody()); - BaseData baseData = configurationMerger.override(mergedConfiguration.getV1(), - Collections.singletonList(new OverrideData(overrideSchema, userConfiguration.getBody()))); - - JsonNode json = new ObjectMapper().readTree(baseData.getRawData()); - AvroUtils.removeUuids(json); - RawData rawData = new RawData(new RawSchema(mergedConfiguration.getV2().getSchema().getRawSchema()), json.toString()); - - mergedConfiguration = new Pair<>(baseData, rawData); - } catch (OverrideException | IOException oe) { - LOG.error("[{}] Unexpected exception occurred while merging configuration: ", endpointId, oe); - throw new GetDeltaException(oe); - } finally { - LOG.trace("[{}] getMergedConfiguration.compute end", endpointId); - } + if (userConfig != null) { + mergedConfiguration = mergeConfiguration(endpointId, userConfig.getBody(), latestConfigurationSchema, mergedConfiguration); + } + if (epsConfig != null) { + mergedConfiguration = mergeConfiguration(endpointId, epsConfig.getConfiguration(), latestConfigurationSchema, mergedConfiguration); } return mergedConfiguration; } - private ConfigurationCacheEntry buildBaseResyncDelta(String endpointId, String jsonData, String schema, EndpointObjectHash userConfigurationHash) throws IOException { + private Pair mergeConfiguration(String endpointId, String config, ConfigurationSchemaDto configSchema, + Pair mergedConfiguration) throws GetDeltaException { + OverrideAlgorithm configurationMerger = configurationOverrideFactory.createConfigurationOverrideAlgorithm(); + OverrideSchema overrideSchema = new OverrideSchema(configSchema.getOverrideSchema()); + try { + LOG.trace("Merging group configuration with configuration: {}", config); + BaseData baseData = configurationMerger.override(mergedConfiguration.getV1(), + Collections.singletonList(new OverrideData(overrideSchema, config))); + + JsonNode json = new ObjectMapper().readTree(baseData.getRawData()); + AvroUtils.removeUuids(json); + RawData rawData = new RawData(new RawSchema(mergedConfiguration.getV2().getSchema().getRawSchema()), json.toString()); + + return new Pair<>(baseData, rawData); + } catch (OverrideException | IOException oe) { + LOG.error("[{}] Unexpected exception occurred while merging configuration: ", endpointId, oe); + throw new GetDeltaException(oe); + } finally { + LOG.trace("[{}] getMergedConfiguration.compute end", endpointId); + } + } + + private ConfigurationCacheEntry buildBaseResyncDelta(String endpointId, String jsonData, String schema, + EndpointObjectHash userConfHash, EndpointObjectHash epsConfHash) throws IOException { byte[] configuration = GenericAvroConverter.toRawData(jsonData, schema); return new ConfigurationCacheEntry(configuration, new BaseBinaryDelta(configuration), EndpointObjectHash.fromSHA1(configuration), - userConfigurationHash); + userConfHash, epsConfHash); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/thrift/OperationsThriftServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/thrift/OperationsThriftServiceImpl.java index 4abc2ce946..397538cee7 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/thrift/OperationsThriftServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/operations/service/thrift/OperationsThriftServiceImpl.java @@ -16,9 +16,6 @@ package org.kaaproject.kaa.server.operations.service.thrift; -import java.security.PublicKey; -import java.util.List; - import org.apache.thrift.TException; import org.kaaproject.kaa.common.dto.ApplicationDto; import org.kaaproject.kaa.common.dto.ProfileFilterDto; @@ -33,6 +30,7 @@ import org.kaaproject.kaa.server.common.thrift.gen.operations.Operation; import org.kaaproject.kaa.server.common.thrift.gen.operations.OperationsThriftService; import org.kaaproject.kaa.server.common.thrift.gen.operations.RedirectionRule; +import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointConfigurationRefreshMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointDeregistrationMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEntityRouteMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftServerProfileUpdateMessage; @@ -50,6 +48,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.security.PublicKey; +import java.util.List; + /** * The implementation of {#link * org.kaaproject.kaa.server.common.thrift.gen.operations @@ -224,4 +225,9 @@ public void onEndpointDeregistration(ThriftEndpointDeregistrationMessage message cacheService.resetEndpointKey(hash, endpointPublickKey); } } + + @Override + public void sendEndpointConfigurationRefreshMessage(ThriftEndpointConfigurationRefreshMessage message) throws TException { + clusterService.sendEndpointConfigurationRefreshMessage(message); + } } diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java index 2c4a887e49..0bfd07397a 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/OperationsServiceIT.java @@ -16,23 +16,6 @@ package org.kaaproject.kaa.server.operations.service; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.net.URL; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; - import org.apache.avro.generic.GenericRecord; import org.junit.After; import org.junit.AfterClass; @@ -100,6 +83,23 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "/operations/common-test-context.xml") @DirtiesContext(classMode = ClassMode.AFTER_CLASS) @@ -811,6 +811,7 @@ private static SyncContext createContext(ClientSync request) { context.setRequestId(request.getRequestId()); context.setStatus(SyncStatus.SUCCESS); context.setMetaData(request.getClientSyncMetaData()); + context.setEndpointKey("endpointKey"); return context; } diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java index 6a487373d2..dc96a090ae 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/akka/DefaultAkkaServiceTest.java @@ -16,6 +16,9 @@ package org.kaaproject.kaa.server.operations.service.akka; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -97,6 +100,7 @@ import org.kaaproject.kaa.server.common.log.shared.appender.data.BaseLogEventPack; import org.kaaproject.kaa.server.common.thrift.gen.operations.Notification; import org.kaaproject.kaa.server.common.thrift.gen.operations.RedirectionRule; +import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointConfigurationRefreshMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftEndpointDeregistrationMessage; import org.kaaproject.kaa.server.common.thrift.gen.operations.ThriftUnicastNotificationMessage; import org.kaaproject.kaa.server.node.service.credentials.CredentialsService; @@ -351,8 +355,8 @@ public void before() throws GeneralSecurityException, CredentialsServiceExceptio when(eventService.isMainUserNode(Mockito.anyString())).thenReturn(true); when(clusterService.getNodeId()).thenReturn(LOCAL_NODE_ID); - when(clusterService.getEntityNode(Mockito.any(byte[].class))).thenReturn(LOCAL_NODE_ID); - when(clusterService.getEntityNode(Mockito.any(EndpointObjectHash.class))).thenReturn(LOCAL_NODE_ID); + when(clusterService.getEntityNode(any(byte[].class))).thenReturn(LOCAL_NODE_ID); + when(clusterService.getEntityNode(any(EndpointObjectHash.class))).thenReturn(LOCAL_NODE_ID); } private void registerPublicKey(PublicKey publicKey) throws EndpointRegistrationServiceException { @@ -369,14 +373,14 @@ public void after() { } private SessionInitMessage toSignedRequest(final UUID uuid, final ChannelType channelType, final ChannelContext ctx, - SyncRequest request, final MessageBuilder responseBuilder, final ErrorBuilder errorBuilder) throws Exception { + SyncRequest request, final MessageBuilder responseBuilder, final ErrorBuilder errorBuilder) throws Exception { MessageEncoderDecoder crypt = new MessageEncoderDecoder(clientPair.getPrivate(), clientPair.getPublic(), serverPair.getPublic()); return toSignedRequest(uuid, channelType, ctx, request, responseBuilder, errorBuilder, crypt); } private SessionInitMessage toSignedRequest(final UUID uuid, final ChannelType channelType, final ChannelContext ctx, - SyncRequest request, final MessageBuilder responseBuilder, final ErrorBuilder errorBuilder, MessageEncoderDecoder crypt) - throws Exception { + SyncRequest request, final MessageBuilder responseBuilder, final ErrorBuilder errorBuilder, MessageEncoderDecoder crypt) + throws Exception { AvroByteArrayConverter requestConverter = new AvroByteArrayConverter<>(SyncRequest.class); byte[] data = requestConverter.toByteArray(request); @@ -462,7 +466,7 @@ public void testDecodeSighnedException() throws Exception { Mockito.when(message.getSessionKeySignature()).thenReturn("dummy".getBytes()); Mockito.when(message.isEncrypted()).thenReturn(true); akkaService.process(message); - Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT * 10).atLeastOnce()).build(Mockito.any(Exception.class)); + Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT * 10).atLeastOnce()).build(any(Exception.class)); } @Test @@ -479,7 +483,7 @@ public void testDecodeSessionException() throws Exception { Mockito.when(message.getEncodedMessageData()).thenReturn("dummy".getBytes()); Mockito.when(message.isEncrypted()).thenReturn(true); akkaService.process(message); - Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT * 10).atLeastOnce()).build(Mockito.any(Exception.class)); + Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT * 10).atLeastOnce()).build(any(Exception.class)); } @Test @@ -540,10 +544,10 @@ public void testEndpointRegistrationRequest() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT * 10).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); - Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(byte[].class), - Mockito.any(boolean.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT * 10).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); + Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(byte[].class), + any(boolean.class)); } @Test @@ -574,10 +578,10 @@ public void testEndpointUpdateRequest() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT * 10).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); - Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(byte[].class), - Mockito.any(boolean.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT * 10).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); + Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(byte[].class), + any(boolean.class)); } @Test @@ -606,10 +610,10 @@ public void testSyncRequest() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); - Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(byte[].class), - Mockito.any(boolean.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); + Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(byte[].class), + any(boolean.class)); } @Test @@ -642,9 +646,9 @@ public void testMultipleSyncRequest() throws Exception { akkaService.process(message1); akkaService.process(message2); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT * 10).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); - Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeast(2)).build(Mockito.any(byte[].class), Mockito.any(boolean.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT * 10).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); + Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeast(2)).build(any(byte[].class), any(boolean.class)); } @Test @@ -672,25 +676,25 @@ public void testLongSyncRequest() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); - Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(byte[].class), - Mockito.any(boolean.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); + Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(byte[].class), + any(boolean.class)); } private void whenSync(SyncContext response) throws GetDeltaException { - Mockito.when(operationsService.syncClientProfile(Mockito.any(SyncContext.class), Mockito.any(ProfileClientSync.class))) + Mockito.when(operationsService.syncClientProfile(any(SyncContext.class), any(ProfileClientSync.class))) .thenReturn(response); Mockito.when( - operationsService.processEndpointAttachDetachRequests(Mockito.any(SyncContext.class), Mockito.any(UserClientSync.class))) + operationsService.processEndpointAttachDetachRequests(any(SyncContext.class), any(UserClientSync.class))) .thenReturn(response); - Mockito.when(operationsService.processEventListenerRequests(Mockito.any(SyncContext.class), Mockito.any(EventClientSync.class))) + Mockito.when(operationsService.processEventListenerRequests(any(SyncContext.class), any(EventClientSync.class))) .thenReturn(response); - Mockito.when(operationsService.syncConfiguration(Mockito.any(SyncContext.class), Mockito.any(ConfigurationClientSync.class))) + Mockito.when(operationsService.syncConfiguration(any(SyncContext.class), any(ConfigurationClientSync.class))) .thenReturn(response); - Mockito.when(operationsService.syncNotification(Mockito.any(SyncContext.class), Mockito.any(NotificationClientSync.class))) + Mockito.when(operationsService.syncNotification(any(SyncContext.class), any(NotificationClientSync.class))) .thenReturn(response); - Mockito.when(operationsService.syncUseConfigurationRawSchema(Mockito.any(SyncContext.class), Matchers.anyBoolean())) + Mockito.when(operationsService.syncUseConfigurationRawSchema(any(SyncContext.class), Matchers.anyBoolean())) .thenReturn(response); } @@ -720,7 +724,7 @@ public void testLongSyncNotification() throws Exception { request.setSyncRequestMetaData(md); ConfigurationSyncRequest csRequest = new ConfigurationSyncRequest(); - csRequest.setConfigurationHash(ByteBuffer.wrap(new byte[]{})); + csRequest.setConfigurationHash(ByteBuffer.wrap(new byte[] {})); csRequest.setResyncOnly(true); request.setConfigurationSyncRequest(csRequest); @@ -736,8 +740,8 @@ public void testLongSyncNotification() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); Mockito.when(applicationService.findAppById(APP_ID)).thenReturn(applicationDto); whenSync(deltaResponse); @@ -746,8 +750,8 @@ public void testLongSyncNotification() throws Exception { thriftNotification.setAppId(APP_ID); akkaService.onNotification(thriftNotification); - Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(byte[].class), - Mockito.any(boolean.class)); + Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(byte[].class), + any(boolean.class)); } @Test @@ -771,8 +775,8 @@ public void testLongSyncUnicastNotification() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT / 2).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT / 2).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); Mockito.when(operationsService.updateSyncResponse(noDeltaResponse.getResponse(), new ArrayList(), UNICAST_NOTIFICATION_ID)).thenReturn(noDeltaResponse.getResponse()); @@ -780,15 +784,15 @@ public void testLongSyncUnicastNotification() throws Exception { EndpointAddress address = new EndpointAddress(applicationDto.getTenantId(), applicationDto.getApplicationToken(), EndpointObjectHash.fromBytes(clientPublicKeyHash.array())); - ActorClassifier classifier = ActorClassifier.GLOBAL; + ActorClassifier classifier = ActorClassifier.GLOBAL; // TODO: replace nulls with values ThriftUnicastNotificationMessage msg = new ThriftUnicastNotificationMessage(null, null, UNICAST_NOTIFICATION_ID); clusterServiceListener.onEndpointActorMsg(new ThriftEndpointActorMsg(address, classifier, msg)); Mockito.verify(operationsService, Mockito.timeout(10 * TIMEOUT / 2).atLeastOnce()).updateSyncResponse(noDeltaResponse.getResponse(), new ArrayList(), UNICAST_NOTIFICATION_ID); - Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(byte[].class), - Mockito.any(boolean.class)); + Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(byte[].class), + any(boolean.class)); } @@ -824,12 +828,12 @@ public void testLongSyncTopicNotificationOnStart() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT / 2).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT / 2).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); Mockito.verify(operationsService, Mockito.timeout(TIMEOUT / 2).atLeastOnce()) .updateSyncResponse(noDeltaResponseWithTopicState.getResponse(), Collections.singletonList(topicNotification), null); - Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(byte[].class), - Mockito.any(boolean.class)); + Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(byte[].class), + any(boolean.class)); } @Test @@ -865,12 +869,12 @@ public void testLongSyncTopicNotification() throws Exception { thriftNotification.setNotificationId(UNICAST_NOTIFICATION_ID); akkaService.onNotification(thriftNotification); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT / 2).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT / 2).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); Mockito.verify(operationsService, Mockito.timeout(TIMEOUT / 2).atLeastOnce()) .updateSyncResponse(noDeltaResponseWithTopicState.getResponse(), Collections.singletonList(topicNotification), null); - Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(byte[].class), - Mockito.any(boolean.class)); + Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(byte[].class), + any(boolean.class)); } @Test @@ -898,8 +902,8 @@ public void testRedirect() throws Exception { response.setRedirectSyncResponse(new RedirectSyncResponse("testDNS".hashCode())); Thread.sleep(TIMEOUT / 2); - Mockito.verify(operationsService, Mockito.never()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.never()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); AvroByteArrayConverter responseConverter = new AvroByteArrayConverter<>(SyncResponse.class); byte[] encodedData = crypt.encodeData(responseConverter.toByteArray(response)); @@ -983,8 +987,8 @@ public byte[] getEncodedMessageData() { response.setRedirectSyncResponse(new RedirectSyncResponse("testDNS".hashCode())); Thread.sleep(TIMEOUT / 2); - Mockito.verify(operationsService, Mockito.never()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.never()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); AvroByteArrayConverter responseConverter = new AvroByteArrayConverter<>(SyncResponse.class); byte[] encodedData = crypt.encodeData(responseConverter.toByteArray(response)); @@ -1018,8 +1022,8 @@ public void testRedirectExpire() throws Exception { response.setStatus(SyncResponseResultType.REDIRECT); response.setRedirectSyncResponse(new RedirectSyncResponse("testDNS".hashCode())); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT / 2).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT / 2).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); } @Test @@ -1098,8 +1102,8 @@ public void testEndpointEventBasic() throws Exception { akkaService.process(sourceMessage); // sourceRequest - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); MessageEncoderDecoder targetCrypt = new MessageEncoderDecoder(targetPair.getPrivate(), targetPair.getPublic(), serverPair.getPublic()); @@ -1108,8 +1112,8 @@ public void testEndpointEventBasic() throws Exception { akkaService.process(targetMessage); // targetRequest - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); SyncResponse eventResponse = new SyncResponse(); eventResponse.setRequestId(REQUEST_ID); @@ -1212,8 +1216,8 @@ public void testEndpointEventSeqNumberBasic() throws Exception { akkaService.process(sourceMessage); // sourceRequest - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); SyncResponse eventResponse = new SyncResponse(); eventResponse.setRequestId(REQUEST_ID); @@ -1273,8 +1277,8 @@ public void testRemoteIncomingEndpointEventBasic() throws Exception { targetRequest, responseBuilder, errorBuilder, targetCrypt); akkaService.process(targetMessage); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); org.kaaproject.kaa.server.sync.Event event = new org.kaaproject.kaa.server.sync.Event(0, FQN1, ByteBuffer.wrap(new byte[0]), null, null); @@ -1346,8 +1350,8 @@ public void testRemoteOutcomingEndpointEventBasic() throws Exception { akkaService.process(sourceMessage); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); UserRouteInfo userRouteInfo = new UserRouteInfo(TENANT_ID, USER_ID, SERVER2, RouteOperation.ADD); akkaService.getListener().onUserRouteInfo(userRouteInfo); @@ -1359,7 +1363,7 @@ public void testRemoteOutcomingEndpointEventBasic() throws Exception { TimeUnit.SECONDS.sleep(2); akkaService.getListener().onRouteInfo(routeInfo); - Mockito.verify(eventService, Mockito.timeout(TIMEOUT).atLeastOnce()).sendEvent(Mockito.any(RemoteEndpointEvent.class)); + Mockito.verify(eventService, Mockito.timeout(TIMEOUT).atLeastOnce()).sendEvent(any(RemoteEndpointEvent.class)); } @Test @@ -1417,15 +1421,15 @@ public void testLogSyncRequest() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); Mockito.verify(logAppenderService, Mockito.timeout(TIMEOUT).atLeastOnce()).getLogSchema(APP_ID, 44); - Mockito.verify(mockAppender, Mockito.timeout(TIMEOUT).atLeastOnce()).doAppend(Mockito.any(BaseLogEventPack.class), - Mockito.any(LogDeliveryCallback.class)); + Mockito.verify(mockAppender, Mockito.timeout(TIMEOUT).atLeastOnce()).doAppend(any(BaseLogEventPack.class), + any(LogDeliveryCallback.class)); - Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(byte[].class), - Mockito.any(boolean.class)); + Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(byte[].class), + any(boolean.class)); } @Test @@ -1472,8 +1476,8 @@ public void testUserChange() throws Exception { akkaService.process(message); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); Mockito.verify(eventService, Mockito.timeout(TIMEOUT).atLeastOnce()).sendUserRouteInfo(new UserRouteInfo(TENANT_ID, USER_ID)); UserRouteInfo userRouteInfo = new UserRouteInfo(TENANT_ID, USER_ID, SERVER2, RouteOperation.ADD); @@ -1560,8 +1564,8 @@ public void testEndpointAttach() throws Exception { akkaService.process(targetMessage); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); Mockito.verify(eventService, Mockito.timeout(TIMEOUT).atLeastOnce()).sendUserRouteInfo(new UserRouteInfo(TENANT_ID, USER_ID)); EndpointProfileDto sourceProfileMock = Mockito.mock(EndpointProfileDto.class); @@ -1602,8 +1606,8 @@ public void testEndpointAttach() throws Exception { sourceRequest, sourceResponseBuilder, sourceErrorBuilder); akkaService.process(sourceMessage); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); SyncResponse targetSyncResponse = new SyncResponse(); targetSyncResponse.setRequestId(REQUEST_ID); @@ -1664,8 +1668,8 @@ public void testEndpointDetach() throws Exception { targetRequest, targetResponseBuilder, targetErrorBuilder, targetCrypt); akkaService.process(targetMessage); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); Mockito.verify(eventService, Mockito.timeout(TIMEOUT).atLeastOnce()).sendUserRouteInfo(new UserRouteInfo(TENANT_ID, USER_ID)); EndpointProfileDto sourceProfileMock = Mockito.mock(EndpointProfileDto.class); @@ -1704,8 +1708,8 @@ public void testEndpointDetach() throws Exception { sourceRequest, sourceResponseBuilder, sourceErrorBuilder); akkaService.process(sourceMessage); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); SyncResponse targetSyncResponse = new SyncResponse(); targetSyncResponse.setRequestId(REQUEST_ID); targetSyncResponse.setStatus(SyncResponseResultType.SUCCESS); @@ -1782,17 +1786,16 @@ public void testNoEndpointCredentialsSyncRequest() throws Exception { MessageBuilder responseBuilder = Mockito.mock(MessageBuilder.class); ErrorBuilder errorBuilder = Mockito.mock(ErrorBuilder.class); - - Mockito.when(registrationService.findEndpointRegistrationByCredentialsId(Mockito.anyString())).thenReturn(Optional.ofNullable((EndpointRegistrationDto) null)); + Mockito.when(registrationService.findEndpointRegistrationByCredentialsId(Mockito.anyString())).thenReturn(Optional.ofNullable((EndpointRegistrationDto)null)); SessionInitMessage message = toSignedRequest(UUID.randomUUID(), ChannelType.SYNC, channelContextMock, request, responseBuilder, errorBuilder); Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(EndpointVerificationException.class)); + Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(EndpointVerificationException.class)); } - + @Test public void testRevokedEndpointCredentialsSyncRequest() throws Exception { ChannelContext channelContextMock = Mockito.mock(ChannelContext.class); @@ -1813,8 +1816,8 @@ public void testRevokedEndpointCredentialsSyncRequest() throws Exception { MessageBuilder responseBuilder = Mockito.mock(MessageBuilder.class); ErrorBuilder errorBuilder = Mockito.mock(ErrorBuilder.class); - - Mockito.when(registrationService.findEndpointRegistrationByCredentialsId(Mockito.anyString())).thenReturn(Optional.ofNullable((EndpointRegistrationDto) null)); + + Mockito.when(registrationService.findEndpointRegistrationByCredentialsId(Mockito.anyString())).thenReturn(Optional.ofNullable((EndpointRegistrationDto)null)); Mockito.when(credentialsService.lookupCredentials(Mockito.anyString())).thenReturn(Optional.of(new CredentialsDto(new byte[]{}, CredentialsStatus.REVOKED))); SessionInitMessage message = toSignedRequest(UUID.randomUUID(), ChannelType.SYNC, channelContextMock, request, responseBuilder, @@ -1822,9 +1825,9 @@ public void testRevokedEndpointCredentialsSyncRequest() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(EndpointVerificationException.class)); + Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(EndpointVerificationException.class)); } - + @Test public void testInUseEndpointCredentialsSyncRequest() throws Exception { ChannelContext channelContextMock = Mockito.mock(ChannelContext.class); @@ -1845,8 +1848,8 @@ public void testInUseEndpointCredentialsSyncRequest() throws Exception { MessageBuilder responseBuilder = Mockito.mock(MessageBuilder.class); ErrorBuilder errorBuilder = Mockito.mock(ErrorBuilder.class); - - Mockito.when(registrationService.findEndpointRegistrationByCredentialsId(Mockito.anyString())).thenReturn(Optional.ofNullable((EndpointRegistrationDto) null)); + + Mockito.when(registrationService.findEndpointRegistrationByCredentialsId(Mockito.anyString())).thenReturn(Optional.ofNullable((EndpointRegistrationDto)null)); Mockito.when(credentialsService.lookupCredentials(Mockito.anyString())).thenReturn(Optional.of(new CredentialsDto(new byte[]{}, CredentialsStatus.IN_USE))); SessionInitMessage message = toSignedRequest(UUID.randomUUID(), ChannelType.SYNC, channelContextMock, request, responseBuilder, @@ -1854,9 +1857,9 @@ public void testInUseEndpointCredentialsSyncRequest() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(EndpointVerificationException.class)); + Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(EndpointVerificationException.class)); } - + @Test public void testLongSyncRevocation() throws Exception { ChannelContext channelContextMock = Mockito.mock(ChannelContext.class); @@ -1867,7 +1870,7 @@ public void testLongSyncRevocation() throws Exception { request.setSyncRequestMetaData(md); ConfigurationSyncRequest csRequest = new ConfigurationSyncRequest(); - csRequest.setConfigurationHash(ByteBuffer.wrap(new byte[]{})); + csRequest.setConfigurationHash(ByteBuffer.wrap(new byte[] {})); csRequest.setResyncOnly(true); request.setConfigurationSyncRequest(csRequest); @@ -1883,8 +1886,8 @@ public void testLongSyncRevocation() throws Exception { Assert.assertNotNull(akkaService.getActorSystem()); akkaService.process(message); - Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(Mockito.any(SyncContext.class), - Mockito.any(ProfileClientSync.class)); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); Mockito.when(applicationService.findAppById(APP_ID)).thenReturn(applicationDto); whenSync(deltaResponse); @@ -1896,7 +1899,51 @@ public void testLongSyncRevocation() throws Exception { clusterServiceListener.onEndpointActorMsg(new ThriftEndpointActorMsg( address, classifier, new ThriftEndpointDeregistrationMessage())); - Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(Mockito.any(EndpointRevocationException.class)); + Mockito.verify(errorBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(EndpointRevocationException.class)); + } + + @Test + public void testEndpointConfigurationRefresh() throws Exception { + ChannelContext channelContextMock = Mockito.mock(ChannelContext.class); + EndpointProfileDto profileDto = new EndpointProfileDto(); + SyncRequest request = new SyncRequest(); + request.setRequestId(REQUEST_ID); + SyncRequestMetaData md = buildSyncRequestMetaData(); + request.setSyncRequestMetaData(md); + + ConfigurationSyncRequest csRequest = new ConfigurationSyncRequest(); + csRequest.setConfigurationHash(ByteBuffer.wrap("hash".getBytes())); + request.setConfigurationSyncRequest(csRequest); + + Mockito.when(cacheService.getEndpointKey(EndpointObjectHash.fromBytes(clientPublicKeyHash.array()))) + .thenReturn(clientPair.getPublic()); + whenSync(noDeltaResponse); + + MessageBuilder responseBuilder = Mockito.mock(MessageBuilder.class); + ErrorBuilder errorBuilder = Mockito.mock(ErrorBuilder.class); + + SessionInitMessage message = toSignedRequest(UUID.randomUUID(), ChannelType.SYNC_WITH_TIMEOUT, channelContextMock, request, + responseBuilder, errorBuilder); + Assert.assertNotNull(akkaService.getActorSystem()); + akkaService.process(message); + Mockito.verify(operationsService, Mockito.timeout(TIMEOUT).atLeastOnce()).syncClientProfile(any(SyncContext.class), + any(ProfileClientSync.class)); + + byte[] epsConfHash = "hash2".getBytes(); + whenSync(deltaResponse); + Mockito.when(applicationService.findAppById(APP_ID)).thenReturn(applicationDto); + Mockito.when(operationsService.fetchEndpointSpecificConfigurationHash(any(EndpointProfileDto.class))).thenReturn(epsConfHash); + Mockito.when(operationsService.refreshServerEndpointProfile(any(EndpointObjectHash.class))).thenReturn(profileDto); + EndpointAddress address = new EndpointAddress(applicationDto.getTenantId(), applicationDto.getApplicationToken(), + EndpointObjectHash.fromBytes(clientPublicKeyHash.array())); + ActorClassifier classifier = ActorClassifier.GLOBAL; + + ThriftEndpointConfigurationRefreshMessage msg = new ThriftEndpointConfigurationRefreshMessage(null, null); + clusterServiceListener.onEndpointActorMsg(new ThriftEndpointActorMsg(address, classifier, msg)); + + Mockito.verify(responseBuilder, Mockito.timeout(TIMEOUT).atLeastOnce()).build(any(byte[].class), + any(boolean.class)); + Mockito.verify(operationsService).syncConfigurationHashes(any(SyncContext.class), isNull(byte[].class), eq(epsConfHash)); } private SyncRequestMetaData buildSyncRequestMetaData() { diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKeyTest.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKeyTest.java index a6d55efac5..7c6538b304 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKeyTest.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/cache/DeltaCacheKeyTest.java @@ -16,20 +16,19 @@ package org.kaaproject.kaa.server.operations.service.cache; -import java.util.ArrayList; -import java.util.List; - import nl.jqno.equalsverifier.EqualsVerifier; - import org.junit.Assert; import org.junit.Test; import org.kaaproject.kaa.common.dto.EndpointGroupStateDto; import org.kaaproject.kaa.common.hash.EndpointObjectHash; -import org.kaaproject.kaa.server.operations.service.cache.AppVersionKey; -import org.kaaproject.kaa.server.operations.service.cache.DeltaCacheKey; + +import java.util.ArrayList; +import java.util.List; public class DeltaCacheKeyTest { + private static final EndpointObjectHash HASH_1 = EndpointObjectHash.fromSHA1("test1"); + private static final EndpointObjectHash HASH_2 = EndpointObjectHash.fromSHA1("test2"); @Test public void deltaCacheKeyEqualsTest() { EqualsVerifier.forClass(DeltaCacheKey.class).verify(); @@ -37,14 +36,17 @@ public void deltaCacheKeyEqualsTest() { @Test public void deltaSameCacheKeyTest() { - DeltaCacheKey key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, EndpointObjectHash.fromSHA1("test1")); - DeltaCacheKey key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, EndpointObjectHash.fromSHA1("test1")); + DeltaCacheKey key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, HASH_1, null); + DeltaCacheKey key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, HASH_1, null); + Assert.assertEquals(key1, key2); + key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, null, null); + key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, null, null); Assert.assertEquals(key1, key2); - key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, null); - key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), null, null, null); + key1 = new DeltaCacheKey(null, null, null, null, null); + key2 = new DeltaCacheKey(null, null, null, null, null); Assert.assertEquals(key1, key2); - key1 = new DeltaCacheKey(null, null, null, null); - key2 = new DeltaCacheKey(null, null, null, null); + key1 = new DeltaCacheKey(null, null, null, null, HASH_2); + key2 = new DeltaCacheKey(null, null, null, null, HASH_2); Assert.assertEquals(key1, key2); } @@ -52,20 +54,24 @@ public void deltaSameCacheKeyTest() { public void deltaDifferentCacheKeyTest() { List egsList = new ArrayList<>(); egsList.add(new EndpointGroupStateDto("eg1", "pf1", "cf1")); - DeltaCacheKey key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList, null, EndpointObjectHash.fromSHA1("test1")); - DeltaCacheKey key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList, null, EndpointObjectHash.fromSHA1("test2")); + DeltaCacheKey key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList, null, HASH_1, null); + DeltaCacheKey key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList, null, HASH_2, null); + Assert.assertNotEquals(key1, key2); + + key1 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList, null, HASH_1, HASH_2); + key2 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList, null, HASH_1, HASH_1); Assert.assertNotEquals(key1, key2); List egsList2 = new ArrayList<>(); egsList2.add(new EndpointGroupStateDto("eg1", "pf1", "cf2")); - DeltaCacheKey key3 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList2, null, EndpointObjectHash.fromSHA1("test1")); + DeltaCacheKey key3 = new DeltaCacheKey(new AppVersionKey("appId1", 1), egsList2, null, EndpointObjectHash.fromSHA1("test1"), null); Assert.assertNotEquals(key1, key3); - DeltaCacheKey key4 = new DeltaCacheKey(new AppVersionKey("appId2", 1), egsList, null, EndpointObjectHash.fromSHA1("test1")); + DeltaCacheKey key4 = new DeltaCacheKey(new AppVersionKey("appId2", 1), egsList, null, EndpointObjectHash.fromSHA1("test1"), null); Assert.assertNotEquals(key1, key4); - DeltaCacheKey key5 = new DeltaCacheKey(new AppVersionKey("appId1", 2), egsList, null, EndpointObjectHash.fromSHA1("test1")); + DeltaCacheKey key5 = new DeltaCacheKey(new AppVersionKey("appId1", 2), egsList, null, EndpointObjectHash.fromSHA1("test1"), null); Assert.assertNotEquals(key1, key5); } diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java index f7c767b882..bf25e54f73 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/delta/DeltaServiceIT.java @@ -16,25 +16,15 @@ package org.kaaproject.kaa.server.operations.service.delta; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.UUID; - -import javax.transaction.Transactional; - import org.apache.avro.Schema; import org.apache.avro.generic.GenericContainer; import org.apache.avro.generic.GenericRecord; -import org.junit.*; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import org.junit.runner.RunWith; import org.kaaproject.kaa.common.avro.GenericAvroConverter; import org.kaaproject.kaa.common.dto.ApplicationDto; @@ -51,12 +41,10 @@ import org.kaaproject.kaa.common.dto.ctl.CTLSchemaMetaInfoDto; import org.kaaproject.kaa.common.endpoint.gen.BasicEndpointProfile; import org.kaaproject.kaa.common.hash.EndpointObjectHash; -import org.kaaproject.kaa.server.admin.services.schema.CTLSchemaParser; import org.kaaproject.kaa.server.common.core.algorithms.delta.DeltaCalculatorException; import org.kaaproject.kaa.server.common.dao.AbstractTest; import org.kaaproject.kaa.server.common.dao.exception.IncorrectParameterException; import org.kaaproject.kaa.server.common.nosql.mongo.dao.MongoDBTestRunner; -import org.kaaproject.kaa.server.control.service.ControlService; import org.kaaproject.kaa.server.control.service.exception.ControlServiceException; import org.kaaproject.kaa.server.operations.pojo.GetDeltaRequest; import org.kaaproject.kaa.server.operations.pojo.GetDeltaResponse; @@ -70,6 +58,20 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.Base64Utils; + +import javax.transaction.Transactional; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "/operations/common-test-context.xml") @@ -233,7 +235,7 @@ public void beforeTest() throws IOException, DeltaCalculatorException, ControlSe endpointProfile = new EndpointProfileDto(); endpointProfile.setApplicationId(application.getId()); - endpointProfile.setEndpointKeyHash(UUID.randomUUID().toString().getBytes()); + endpointProfile.setEndpointKeyHash(Base64Utils.decodeFromString("EndpointId")); endpointProfile.setClientProfileBody(PROFILE_JSON); endpointProfile.setProfileHash(EndpointObjectHash.fromSHA1(PROFILE_BYTES).getData()); endpointProfile.setConfigurationHash(endpointConfiguration.getConfigurationHash()); diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/event/ESTestOperationsService.java b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/event/ESTestOperationsService.java index ef53500c22..5dece87b91 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/event/ESTestOperationsService.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/operations/service/event/ESTestOperationsService.java @@ -16,9 +16,6 @@ package org.kaaproject.kaa.server.operations.service.event; -import java.security.PublicKey; -import java.util.List; - import org.kaaproject.kaa.common.dto.EndpointProfileDto; import org.kaaproject.kaa.common.dto.NotificationDto; import org.kaaproject.kaa.common.hash.EndpointObjectHash; @@ -32,6 +29,9 @@ import org.kaaproject.kaa.server.sync.ServerSync; import org.kaaproject.kaa.server.sync.UserClientSync; +import java.security.PublicKey; +import java.util.List; + /** * @author Andrey Panasenko * @@ -81,6 +81,12 @@ public EndpointProfileDto attachEndpointToUser(EndpointProfileDto profile, Strin return null; } + @Override + public byte[] fetchEndpointSpecificConfigurationHash(EndpointProfileDto profile) { + // TODO Auto-generated method stub + return null; + } + @Override public ServerSync updateSyncResponse(ServerSync response, List notifications, String unicastNotificationId) { // TODO Auto-generated method stub @@ -100,7 +106,7 @@ public EndpointProfileDto refreshServerEndpointProfile(EndpointObjectHash hash) } @Override - public SyncContext syncUserConfigurationHash(SyncContext context, byte[] ucfHash) { + public SyncContext syncConfigurationHashes(SyncContext context, byte[] ucfHash, byte[] epsConfHash) { // TODO Auto-generated method stub return null; }