@Override public String compute(ConfigurationIdKey key) { LOG.debug("Fetching result for getConfIdByKey"); String confId = null; List<ConfigurationDto> configurations = configurationService.findConfigurationsByEndpointGroupId(key.getEndpointGroupId()); for (ConfigurationDto confDto : configurations) { if (confDto.getSchemaVersion() == key.getConfigSchemaVersion()) { confId = confDto.getId(); break; } } return confId; } });
@Test(expected = IncorrectParameterException.class) public void deactivateInactiveConfigurationTest() { ConfigurationDto config = generateConfigurationDto(null, null, 1, false, false).get(0); configurationService.deactivateConfiguration(config.getId(), null); }
@Test(expected = UpdateStatusConflictException.class) public void activateConfigurationTestFail() { List<ConfigurationDto> configurations = generateConfigurationDto(null, null, 1, true, false); ConfigurationDto configuration = configurations.get(0); configurationService.activateConfiguration(configuration.getId(), null); }
@Test public void saveConfigurationObjectWithoutIdTest() throws SchemaCreationException { List<ConfigurationDto> configs = generateConfigurationDto(null, null, 1, false, false); ConfigurationDto saved = configurationService.findConfigurationById(configs.get(0).getId()); String inactiveId = saved.getId(); saved.setId(null); ConfigurationDto updated = configurationService.saveConfiguration(saved); Assert.assertNotNull(saved); Assert.assertEquals(saved.getStatus(), UpdateStatus.INACTIVE); Assert.assertEquals(inactiveId, updated.getId()); }
@Test(expected = UpdateStatusConflictException.class) public void saveConfigurationWithIncorrectStatusTestFail() throws SchemaCreationException { List<ConfigurationDto> configurations = generateConfigurationDto(null, null, 1, true, false); ConfigurationDto configurationDto = configurationService.findConfigurationById(configurations.get(0).getId()); configurationService.saveConfiguration(configurationDto); }
@Test public void deactivateConfigurationTest() { ConfigurationDto config = generateConfigurationDto(null, null, 1, true, false).get(0); configurationService.deactivateConfiguration(config.getId(), null); config = configurationService.findConfigurationById(config.getId()); Assert.assertNotNull(config); Assert.assertEquals(UpdateStatus.DEPRECATED, config.getStatus()); }
private HistoryDto addHistory(ConfigurationDto dto, ChangeType type) { LOG.debug("Add history information about configuration update"); HistoryDto history = new HistoryDto(); history.setApplicationId(dto.getApplicationId()); ChangeDto change = new ChangeDto(); change.setConfigurationId(dto.getId()); change.setCfVersion(dto.getSchemaVersion()); change.setEndpointGroupId(dto.getEndpointGroupId()); change.setType(type); history.setChange(change); return historyService.saveHistory(history); }
@Test public void saveConfigurationObjectWithoutInactiveConfigurationTest() throws SchemaCreationException { List<ConfigurationDto> configs = generateConfigurationDto(null, null, 3, true, false); ConfigurationDto saved = configurationService.findConfigurationById(configs.get(2).getId()); String id = saved.getId(); saved.setId(null); ConfigurationDto updated = configurationService.saveConfiguration(saved); Assert.assertNotNull(updated); Assert.assertEquals(updated.getStatus(), UpdateStatus.INACTIVE); Assert.assertEquals(saved.getSequenceNumber(), updated.getSequenceNumber()); Assert.assertNotEquals(id, updated.getId()); }
@Test public void findConfigurationByIdTest() { List<ConfigurationDto> configurations = generateConfigurationDto(null, null, 1, false, false); ConfigurationDto configuration = configurations.get(0); ConfigurationDto foundConfiguration = configurationService.findConfigurationById(configuration.getId()); Assert.assertNotNull(foundConfiguration); Assert.assertEquals(configuration, foundConfiguration); }
@Test(expected = IncorrectParameterException.class) public void saveConfigurationObjectWithIncorrectSchemaIdTest() throws SchemaCreationException { List<ConfigurationDto> configurations = generateConfigurationDto(null, null, 1, false, false); ConfigurationDto configurationDto = configurationService.findConfigurationById(configurations.get(0).getId()); configurationDto.setId(null); configurationDto.setSchemaId(100500 + ""); configurationService.saveConfiguration(configurationDto); }
@Override public ConfigurationDto editConfiguration(ConfigurationDto configuration) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { String username = getCurrentUser().getUsername(); if (isEmpty(configuration.getId())) { configuration.setCreatedUsername(username); checkEndpointGroupId(configuration.getEndpointGroupId()); } else { configuration.setModifiedUsername(username); ConfigurationDto storedConfiguration = controlService.getConfiguration( configuration.getId()); Utils.checkNotNull(storedConfiguration); checkEndpointGroupId(storedConfiguration.getEndpointGroupId()); } return controlService.editConfiguration(configuration); } catch (StaleObjectStateException ex) { LOG.error( "Someone has already updated the configuration. Reload page to be able to edit it. ", ex); throw new KaaAdminServiceException( "Someone has already updated the configuration. Reload page to be able to edit it.", ServiceErrorCode.GENERAL_ERROR); } catch (Exception ex) { throw Utils.handleException(ex); } }
@Test public void saveConfigurationObjectWithIdTest() throws SchemaCreationException, IOException, ConfigurationGenerationException { List<ConfigurationDto> configs = generateConfigurationDto(null, null, 1, false, false); ConfigurationDto saved = configurationService.findConfigurationById(configs.get(0).getId()); ConfigurationDto updated = configurationService.saveConfiguration(saved); // update one more time (nothing should change) updated = configurationService.saveConfiguration(updated); Assert.assertNotNull(saved); Assert.assertEquals(updated.getStatus(), UpdateStatus.INACTIVE); }
@Test public void activateConfiguration() { List<ConfigurationDto> configurations = generateConfigurationDto(null, null, 1, false, false); String configId = configurations.get(0).getId(); ConfigurationDto found = configurationService.findConfigurationById(configId); ChangeConfigurationNotification notification = configurationService.activateConfiguration(configId, null); Assert.assertNotNull(notification); ConfigurationDto dto = notification.getConfigurationDto(); Assert.assertNotNull(dto); Assert.assertEquals(dto.getStatus(), UpdateStatus.ACTIVE); Assert.assertEquals(dto.getId(), configId); Assert.assertNotEquals(dto.getSequenceNumber(), found.getSequenceNumber()); }
@Override public ConfigurationDto saveConfiguration(ConfigurationDto configurationDto) { validateConfiguration(configurationDto); String id = configurationDto.getId(); ConfigurationSchemaDto configurationSchemaDto; Configuration oldActiveConfiguration = null; if (StringUtils.isNotBlank(id)) { ConfigurationDto oldConfiguration = findConfigurationById(configurationDto.getId()); if (oldConfiguration != null && oldConfiguration.getStatus() != INACTIVE) { throw new UpdateStatusConflictException("Can't update configuration, invalid id " + id); configurationDto.setCreatedTime(oldConfiguration.getCreatedTime()); configurationDto.setCreatedUsername(oldConfiguration.getCreatedUsername()); LOG.debug("Update existing configuration with id: [{}]", configurationDto.getId()); } else { String schemaId = configurationDto.getSchemaId();
ConfigurationDto savedConfiguration = saveConfiguration(configurationDto); if (savedConfiguration != null) { activateConfiguration(savedConfiguration.getId(), savedSchema.getCreatedUsername()); } else { LOG.warn("Can't save default configuration.");
/** * Notify endpoints. * * @param notification the notification * @param profileFilter the profile filter * @param configuration the configuration */ private void notifyEndpoints(ChangeNotificationDto notification, ProfileFilterDto profileFilter, ConfigurationDto configuration) { Notification thriftNotification = new Notification(); thriftNotification.setAppId(notification.getAppId()); thriftNotification.setAppSeqNumber(notification.getAppSeqNumber()); thriftNotification.setGroupId(notification.getGroupId()); thriftNotification.setGroupSeqNumber(notification.getGroupSeqNumber()); if (profileFilter != null) { thriftNotification.setProfileFilterId(profileFilter.getId()); thriftNotification.setProfileFilterSeqNumber(profileFilter.getSequenceNumber()); } if (configuration != null) { thriftNotification.setConfigurationId(configuration.getId()); thriftNotification.setConfigurationSeqNumber(configuration.getSequenceNumber()); } controlZkService.sendEndpointNotification(thriftNotification); }
Assert.assertNotNull(saved); if (activate) { ChangeConfigurationNotification notification = configurationService.activateConfiguration(saved.getId(), schemaDto.getCreatedUsername()); saved = notification.getConfigurationDto();
@Test public void editConfigurationObjectTest() { List<ConfigurationDto> configs = generateConfigurationDto(null, null, 1, false, false); ConfigurationDto saved = configurationService.findConfigurationById(configs.get(0).getId()); ConfigurationDto configurationToEdit = new ConfigurationDto(); configurationToEdit.setId(saved.getId()); configurationToEdit.setApplicationId(saved.getApplicationId()); configurationToEdit.setEndpointGroupId(saved.getEndpointGroupId()); configurationToEdit.setSchemaId(saved.getSchemaId()); configurationToEdit.setVersion(saved.getVersion()); configurationToEdit.setBody(saved.getBody()); ConfigurationDto updated = configurationService.saveConfiguration(configurationToEdit); Assert.assertNotNull(saved); Assert.assertNotNull(updated); Assert.assertEquals(saved.getSchemaVersion(), updated.getSchemaVersion()); Assert.assertEquals(saved.getCreatedTime(), updated.getCreatedTime()); Assert.assertEquals(saved.getCreatedUsername(), updated.getCreatedUsername()); }