@Override public void onSuccess(EndpointProfileDto endpointProfileDto) { List<EndpointProfileDto> result = new ArrayList<>(); if (endpointProfileDto.getApplicationId().equals(applicationId)) { result.add(endpointProfileDto); } endpointProfilesList.clear(); endpointProfilesList.addAll(result); callback.onSuccess(endpointProfilesList); } });
@Override public Optional<EndpointSpecificConfigurationDto> findByEndpointKeyHashAndConfSchemaVersion(byte[] endpointKeyHash, Integer confSchemaVersion) { LOG.debug("Looking for endpoint specific configuration by EP key hash {} and confSchemaVersion", endpointKeyHash, confSchemaVersion); validateNotNull(confSchemaVersion, "Configuration schema version is required"); EndpointProfileDto profileDto = getEndpointProfileDto(endpointKeyHash); if (profileDto == null) { return Optional.empty(); } validateConfSchemaVersion(profileDto.getApplicationId(), confSchemaVersion); EndpointSpecificConfiguration configuration = endpointSpecificConfigurationDao.findByEndpointKeyHashAndConfigurationVersion(endpointKeyHash, confSchemaVersion); return Optional.ofNullable(configuration).map(ToDto::toDto); }
EndpointProfileDto checkEndpointProfile(byte[] endpointKeyHash) throws KaaAdminServiceException { try { validateNotNull(endpointKeyHash, "Missing endpoint key hash"); EndpointProfileDto endpointProfile = endpointService.findEndpointProfileByKeyHash(endpointKeyHash); checkNotNull(endpointProfile); checkApplicationId(endpointProfile.getApplicationId()); return endpointProfile; } catch (Exception ex) { throw Utils.handleException(ex); } }
@Override public EndpointProfileDto getEndpointProfileByKeyHash(String endpointProfileKeyHash) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { EndpointProfileDto profileDto = controlService.getEndpointProfileByKeyHash( endpointProfileKeyHash); if (profileDto == null) { throw new KaaAdminServiceException( "Requested item was not found!", ServiceErrorCode.ITEM_NOT_FOUND); } checkApplicationId(profileDto.getApplicationId()); return profileDto; } catch (Exception ex) { throw Utils.handleException(ex); } }
@Override public void removeEndpointProfileByKeyHash(String endpointKeyHash) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { EndpointProfileDto endpointProfile = controlService.getEndpointProfileByKeyHash( endpointKeyHash); Utils.checkNotNull(endpointProfile); checkApplicationId(endpointProfile.getApplicationId()); controlService.removeEndpointProfile(endpointProfile); } catch (Exception cause) { throw Utils.handleException(cause); } }
@Override public Schema findEndpointConfigurationSchemaByEndpointKeyHash(String endpointKeyHash) throws KaaAdminServiceException { EndpointProfileDto endpointProfileDto = profileService .findEndpointProfileByEndpointKeyHash(endpointKeyHash); ConfigurationSchemaDto configurationSchemaDto = configurationService .findConfSchemaByAppIdAndVersion( endpointProfileDto.getApplicationId(), endpointProfileDto.getConfigurationVersion() ); CTLSchemaDto ctlSchemaDto = ctlService .findCtlSchemaById(configurationSchemaDto.getCtlSchemaId()); return ctlService.flatExportAsSchema(ctlSchemaDto); }
@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); } }
EndpointProfileDto profileDto = controlService.getEndpointProfileByKeyHash(endpointKeyHash); Utils.checkNotNull(profileDto); checkApplicationId(profileDto.getApplicationId()); ServerProfileSchemaDto serverProfileSchema = controlService.getServerProfileSchemaByApplicationIdAndVersion( profileDto.getApplicationId(), serverProfileVersion); Utils.checkNotNull(serverProfileSchema); RecordField record;
@Override public EndpointSpecificConfigurationDto save(EndpointSpecificConfigurationDto configurationDto) { EndpointProfileDto profileDto = getEndpointProfileDto(configurationDto.getEndpointKeyHash()); if (configurationDto.getConfigurationSchemaVersion() == null) { configurationDto.setConfigurationSchemaVersion(profileDto.getConfigurationVersion()); } validateEndpointSpecificConfiguration(configurationDto, profileDto.getApplicationId()); return endpointSpecificConfigurationDao.save(configurationDto).toDto(); }
ApplicationDto appDto = getApplication(endpointProfileDto.getApplicationId()); ThriftServerProfileUpdateMessage nf = new ThriftServerProfileUpdateMessage(); nf.setAddress(
private void sendEndpointConfigurationRefreshMessage(EndpointSpecificConfigurationDto configuration) { byte[] endpointKeyHashBytes = configuration.getEndpointKeyHash(); EndpointProfileDto endpointProfile = endpointService.findEndpointProfileByKeyHash(endpointKeyHashBytes); if (!configuration.getConfigurationSchemaVersion().equals(endpointProfile.getConfigurationVersion())) { return; } checkNeighbors(); String endpointKeyHash = Base64Util.encode(configuration.getEndpointKeyHash()); ApplicationDto appDto = applicationService.findAppById(endpointProfile.getApplicationId()); OperationsNodeInfo server = resolve(endpointKeyHash); if (server != null) { ThriftEndpointConfigurationRefreshMessage msg = new ThriftEndpointConfigurationRefreshMessage(); msg.setAddress(new ThriftEntityAddress(appDto.getTenantId(), appDto.getApplicationToken(), ThriftClusterEntityType.ENDPOINT, ByteBuffer.wrap(endpointKeyHashBytes))); msg.setActorClassifier(ThriftActorClassifier.GLOBAL); if (LOG.isTraceEnabled()) { LOG.trace("Sending message {} to [{}]", msg, Neighbors.getServerId(server.getConnectionInfo())); } neighbors.sendMessage(server.getConnectionInfo(), OperationsServiceMsg.fromEndpointConfigurationRefresh(msg)); } else { LOG.warn("Can't find server for endpoint [{}]", endpointKeyHash); } }
ConfigurationSchemaDto configurationSchemaDto = configurationService .findConfSchemaByAppIdAndVersion( endpointProfileDto.getApplicationId(), endpointProfileDto.getConfigurationVersion() ); try { appToken = applicationService .findAppById(endpointProfileDto.getApplicationId()) .getApplicationToken(); byte[] config = deltaService
@Override public void removeEndpointProfile(EndpointProfileDto endpointProfile) throws ControlServiceException { checkNeighbors(); byte[] endpointKeyHash = endpointProfile.getEndpointKeyHash(); this.endpointService.removeEndpointProfileByKeyHash(endpointKeyHash); ApplicationDto appDto = getApplication(endpointProfile.getApplicationId()); ThriftEndpointDeregistrationMessage nf = new ThriftEndpointDeregistrationMessage(); nf.setAddress( new ThriftEntityAddress( appDto.getTenantId(), appDto.getApplicationToken(), ThriftClusterEntityType.ENDPOINT, ByteBuffer.wrap(endpointKeyHash) ) ); nf.setActorClassifier(ThriftActorClassifier.APPLICATION); neighbors.brodcastMessage(OperationsServiceMsg.fromDeregistration(nf)); }
@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; }
== null) { ServerProfileSchemaDto serverProfileSchemaDto = serverProfileService .findLatestServerProfileSchema(endpointProfileDto.getApplicationId()); CTLSchemaDto schemaDto = ctlService.findCtlSchemaById( serverProfileSchemaDto.getCtlSchemaId());
ep.getClientProfileVersion(), ep.getServerProfileVersion(), ep.getApplicationId()); endpointProfileBodyDto.setEndpointKeyHash(ep.getEndpointKeyHash()); profilesBody.add(endpointProfileBodyDto);
@Test public void removeByAppId() { EndpointProfileDto endpointProfile = generateEndpointProfileDto(null, null); Assert.assertNotNull(endpointProfile); byte[] keyHash = endpointProfile.getEndpointKeyHash(); endpointProfileDao.removeByAppId(endpointProfile.getApplicationId()); MongoEndpointProfile found = endpointProfileDao.findByKeyHash(keyHash); Assert.assertNull(found); }
@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); }
this.applicationId = dto.getApplicationId(); this.endpointKey = dto.getEndpointKey(); this.endpointKeyHash = dto.getEndpointKeyHash();
this.applicationId = dto.getApplicationId(); this.endpointProfileKey = getByteBuffer(dto.getEndpointKey()); this.endpointKeyHash = getByteBuffer(dto.getEndpointKeyHash());