@Override public String getValue(EndpointProfileDto item) { return item.getServerProfileVersion() + ""; } }, 80);
private EndpointProfileDataDto convert(EndpointProfileDto profileDto) { return new EndpointProfileDataDto( profileDto.getId(), endpointKey, profileDto.getClientProfileVersion(), profileDto.getClientProfileBody(), profileDto.getServerProfileVersion(), profileDto.getServerProfileBody()); }
@Override public List<SchemaInfoDto> getServerProfileSchemaInfosByEndpointKey(String endpointKeyHash) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { EndpointProfileDto endpointProfile = getEndpointProfileByKeyHash(endpointKeyHash); List<ServerProfileSchemaDto> serverProfileSchemas = controlService.getServerProfileSchemasByApplicationId( endpointProfile.getApplicationId()); List<SchemaInfoDto> schemaInfos = new ArrayList<>(serverProfileSchemas.size()); for (ServerProfileSchemaDto serverProfileSchema : serverProfileSchemas) { SchemaInfoDto schemaInfo = new SchemaInfoDto(serverProfileSchema); String body = null; if (schemaInfo.getVersion() == endpointProfile.getServerProfileVersion()) { body = endpointProfile.getServerProfileBody(); } RecordField schemaForm = createRecordFieldFromCtlSchemaAndBody( serverProfileSchema.getCtlSchemaId(), body); schemaInfo.setSchemaName(serverProfileSchema.getName()); schemaInfo.setSchemaForm(schemaForm); schemaInfos.add(schemaInfo); } Collections.sort(schemaInfos, Collections.reverseOrder()); return schemaInfos; } catch (Exception ex) { throw Utils.handleException(ex); } }
@Override public boolean matches(String appToken, String profileFilterId, EndpointProfileDto profile) { AppProfileVersionsKey key = new AppProfileVersionsKey( appToken, profile.getClientProfileVersion(), profile.getServerProfileVersion()); String endpointProfileSchemaBody = getEndpointProfileSchemaBody(key); String serverProfileSchemaBody = getServerProfileSchemaBody(key); FilterEvaluator filterEvaluator = new DefaultFilterEvaluator(); filterEvaluator.init(profile, endpointProfileSchemaBody, serverProfileSchemaBody); ProfileFilterDto filter = cacheService.getFilter(profileFilterId); LOG.trace("matching profile body with filter [{}]: {}", filter.getId(), filter.getBody()); return checkFilter(filterEvaluator, filter); }
@Override public HistoryDelta getDelta(EndpointProfileDto profile, String applicationToken, int curAppSeqNumber) { String endpointId = Base64Util.encode(profile); ConfigurationIdKey confIdKey = new ConfigurationIdKey( applicationToken, curAppSeqNumber, profile.getConfigurationVersion()); AppProfileVersionsKey appVersionsKey = new AppProfileVersionsKey( applicationToken, profile.getClientProfileVersion(), profile.getServerProfileVersion()); List<ProfileFilterDto> filters = filterService.getAllMatchingFilters(appVersionsKey, profile); LOG.debug("[{}] Found {} matching filters", endpointId, filters.size()); List<EndpointGroupStateDto> result = new ArrayList<>(1 + filters.size()); EndpointGroupDto groupDto = cacheService.getDefaultGroup(applicationToken); EndpointGroupStateDto groupAllState = new EndpointGroupStateDto(); groupAllState.setEndpointGroupId(groupDto.getId()); groupAllState.setConfigurationId(cacheService.getConfIdByKey( confIdKey.copyWithNewEgId(groupDto.getId()))); result.add(groupAllState); for (ProfileFilterDto filter : filters) { String confId = cacheService.getConfIdByKey( confIdKey.copyWithNewEgId(filter.getEndpointGroupId())); EndpointGroupStateDto endpointGroupState = new EndpointGroupStateDto(); endpointGroupState.setEndpointGroupId(filter.getEndpointGroupId()); endpointGroupState.setProfileFilterId(filter.getId()); endpointGroupState.setConfigurationId(confId); result.add(endpointGroupState); } return new HistoryDelta(result, true, true, true); }
@Override public EndpointProfileBodyDto findBodyByKeyHash(byte[] endpointKeyHash) { LOG.debug("Find endpoint profile body by endpoint key hash [{}] ", endpointKeyHash); EndpointProfileBodyDto endpointProfileBodyDto = null; Query query = Query.query(where(EP_ENDPOINT_KEY_HASH).is(endpointKeyHash)); query.fields() .include(DaoConstants.PROFILE) .include(EP_SERVER_PROFILE_PROPERTY) .include(EP_APPLICATION_ID) .include(EP_PROFILE_VERSION) .include(EP_SERVER_PROFILE_VERSION_PROPERTY) .include(EP_USE_RAW_SCHEMA); EndpointProfileDto pf = mongoTemplate.findOne(query, getDocumentClass()).toDto(); if (pf != null) { endpointProfileBodyDto = new EndpointProfileBodyDto( endpointKeyHash, pf.getClientProfileBody(), pf.getServerProfileBody(), pf.getClientProfileVersion(), pf.getServerProfileVersion(), pf.getApplicationId()); } LOG.debug("[{}] Found client-side endpoint profile body {} with client-side endpoint " + "profile version {} and server-side endpoint profile body {} " + "with server-side endpoint profile version {} and application id {}", endpointKeyHash, pf.getClientProfileBody(), pf.getServerProfileBody(), pf.getClientProfileVersion(), pf.getServerProfileVersion(), pf.getApplicationId()); return endpointProfileBodyDto; }
profile.getClientProfileVersion(), profile.getServerProfileVersion()); ConfigurationIdKey confIdKey = new ConfigurationIdKey( applicationToken, curAppSeqNumber, profile.getConfigurationVersion());
ep.getServerProfileBody(), ep.getClientProfileVersion(), ep.getServerProfileVersion(), ep.getApplicationId()); endpointProfileBodyDto.setEndpointKeyHash(ep.getEndpointKeyHash());
@Test public void testSaveServerProfile() throws IOException { ServerProfileSchemaDto schemaDto = generateServerProfileSchema(null, null); EndpointProfileDto ep = generateEndpointProfileDtoWithSchemaVersion(schemaDto.getApplicationId(), schemaDto.getVersion(), null); EndpointProfileDto updated = serverProfileService.saveServerProfile(ep.getEndpointKeyHash(), schemaDto.getVersion(), readSchemaFileAsString(TEST_PROFILE_BODY_PATH)); Assert.assertArrayEquals(ep.getEndpointKeyHash(), updated.getEndpointKeyHash()); Assert.assertNotEquals(ep.getServerProfileBody(), updated.getServerProfileBody()); Assert.assertEquals(ep.getServerProfileVersion(), updated.getServerProfileVersion()); }
@Test @Ignore("generateEndpointProfileDtoWithSchemaVersion() updates profile," + " but it shouldn't have existed by the moment, so save must have have been invoked") public void testFindServerProfileSchemaByKeyHash() { ServerProfileSchemaDto schemaDto = generateServerProfileSchema(null, null); EndpointProfileDto ep = generateEndpointProfileDtoWithSchemaVersion(schemaDto.getApplicationId(), schemaDto.getVersion(), null); EndpointProfileDto found = endpointService.findEndpointProfileByKeyHash(ep.getEndpointKeyHash()); ServerProfileSchemaDto foundSchema = serverProfileService.findServerProfileSchemaByAppIdAndVersion(found.getApplicationId(), found.getServerProfileVersion()); Assert.assertEquals(schemaDto, foundSchema); }
controlService.getServerProfileSchemaByApplicationIdAndVersion( endpointProfile.getApplicationId(), endpointProfile.getServerProfileVersion()); endpointProfileView.setProfileSchemaName(clientProfileSchema.getName()); endpointProfileView.setProfileSchemaVersion(clientProfileSchema.toVersionDto());
this.profileHash = dto.getProfileHash(); this.profileVersion = dto.getClientProfileVersion(); this.serverProfileVersion = dto.getServerProfileVersion(); this.configurationHash = dto.getConfigurationHash(); this.userConfigurationHash = dto.getUserConfigurationHash();
this.profileHash = getByteBuffer(dto.getProfileHash()); this.profileVersion = dto.getClientProfileVersion(); this.serverProfileVersion = dto.getServerProfileVersion(); this.configurationHash = getByteBuffer(dto.getConfigurationHash()); this.userConfigurationHash = getByteBuffer(dto.getUserConfigurationHash());