/** * Saves agent mapping. * * @param agentMappings * To save * @throws IOException * If {@link IOException} occurs. * @throws JAXBException * If {@link JAXBException} occurs. If saving fails. */ private void saveAgentMapping(AgentMappings agentMappings) throws JAXBException, IOException { transformator.marshall(pathResolver.getAgentMappingFilePath(), agentMappings, getRelativeToSchemaPath(pathResolver.getDefaultCiPath()).toString(), ISchemaVersionAware.ConfigurationInterface.SCHEMA_VERSION); }
/** * Save the given {@link AlertingDefinition}. * * @param alertingDefinition * the {@link AlertingDefinition} to save * @throws IOException * if {@link IOException} occurs * @throws JAXBException * if {@link JAXBException} occurs. If saving fails */ private void saveAlertingDefinition(AlertingDefinition alertingDefinition) throws JAXBException, IOException { transformator.marshall(pathResolver.getAlertingDefinitionFilePath(alertingDefinition), alertingDefinition, getRelativeToSchemaPath(pathResolver.getDefaultCiPath()).toString(), ISchemaVersionAware.ConfigurationInterface.SCHEMA_VERSION); }
/** * Returns path pointing to the alerting definition file. * * @param alertingDefinition * {@link AlertingDefinition} * @return Path to the file. */ public Path getAlertingDefinitionFilePath(AlertingDefinition alertingDefinition) { String secureDefinitionName = removeIllegalFilenameCharacters(alertingDefinition.getName()); String fileName = alertingDefinition.getId() + "-" + secureDefinitionName + ".xml"; return getAlertingDefinitionsPath().resolve(fileName); }
/** * Returns the {@link ConfigurationInterfaceImportData} from the given import data bytes. * * @param importData * bytes that were exported. * @return {@link ConfigurationInterfaceImportData}. * @throws SAXException * IF {@link SAXException} occurs during unmarshall. * @throws IOException * If {@link IOException} occurs during unmarshall. * @throws JAXBException * If {@link JAXBException} occurs during unmarshall. */ public ConfigurationInterfaceImportData getImportData(byte[] importData) throws JAXBException, IOException, SAXException { return transformator.unmarshall(importData, pathResolver.getSchemaPath(), ISchemaVersionAware.ConfigurationInterface.SCHEMA_VERSION, pathResolver.getMigrationPath(), ConfigurationInterfaceImportData.class); }
/** * Returns path pointing to the environment file. * * @param environment * {@link Environment} * @return Path to the file. */ public Path getEnvironmentFilePath(Environment environment) { String secureEnvironmentName = removeIllegalFilenameCharacters(environment.getName()); String fileName = environment.getId() + "-" + secureEnvironmentName + ".xml"; return getEnvironmentPath().resolve(fileName); }
final ConfigurationInterfacePathResolver resolverHelper = new ConfigurationInterfacePathResolver(); resolverHelper.init(); when(pathResolver.getDefaultCiPath()).thenReturn(Paths.get(TEST_FOLDER)); when(pathResolver.getAgentMappingFilePath()).thenReturn(Paths.get(TEST_FOLDER).resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getAgentMappingFilePath()))); when(pathResolver.getEnvironmentPath()).thenReturn(Paths.get(TEST_FOLDER).resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getEnvironmentPath()))); when(pathResolver.getProfilesPath()).thenReturn(Paths.get(TEST_FOLDER).resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getProfilesPath()))); when(pathResolver.getSchemaPath()).thenReturn(Paths.get(TEST_FOLDER).resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getSchemaPath()))); when(pathResolver.getBusinessContextFilePath()).thenReturn(Paths.get(TEST_FOLDER).resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getBusinessContextFilePath()))); when(pathResolver.getAlertingDefinitionsPath()).thenReturn(Paths.get(TEST_FOLDER).resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getAlertingDefinitionsPath()))); doAnswer(new Answer<Path>() { @Override .resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getEnvironmentFilePath((Environment) invocation.getArguments()[0]))); }).when(pathResolver).getEnvironmentFilePath(Matchers.<Environment> any()); doAnswer(new Answer<Path>() { @Override .resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getProfileFilePath((Profile) invocation.getArguments()[0]))); }).when(pathResolver).getProfileFilePath(Matchers.<Profile> any()); doAnswer(new Answer<Path>() { @Override .resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getAlertingDefinitionFilePath((AlertingDefinition) invocation.getArguments()[0]))); }).when(pathResolver).getAlertingDefinitionFilePath(Matchers.<AlertingDefinition> any());
/** * Loads the business context definition if it is not already loaded. If successfully loaded * definition will be placed in the {@link #businessContextDefinition} field. */ private void loadBusinessContextDefinition() { log.info("|-Loading the business context definition"); Path path = pathResolver.getBusinessContextFilePath(); BusinessContextDefinition businessContextDefinition = null; if (Files.exists(path)) { try { businessContextDefinition = transformator.unmarshall(path, pathResolver.getSchemaPath(), ISchemaVersionAware.ConfigurationInterface.SCHEMA_VERSION, pathResolver.getMigrationPath(), BusinessContextDefinition.class); } catch (JAXBException | IOException | SAXException e) { log.error("Error loading Configuration interface business context file. File path: " + path.toString() + ".", e); } } if (null == businessContextDefinition) { businessContextDefinition = new BusinessContextDefinition(); try { saveBusinessContext(businessContextDefinition); } catch (JAXBException | IOException e) { log.error("Error saving Configuration interface business context file. File path: " + path.toString() + ".", e); } } businessContextDefinitionReference.set(businessContextDefinition); }
Path path = pathResolver.getAgentMappingFilePath(); if (Files.notExists(path)) { log.info("||-The agent mappings file does not exists. Creating default mapping."); agentMappings = transformator.unmarshall(path, pathResolver.getSchemaPath(), ISchemaVersionAware.ConfigurationInterface.SCHEMA_VERSION, pathResolver.getMigrationPath(), AgentMappings.class); } catch (JAXBException | IOException | SAXException e) { agentMappings = new AgentMappings(Collections.<AgentMapping> emptyList());
/** * Saves {@link Environment} to the disk. * * @param environment * {@link Environment} to save. * @throws IOException * If {@link IOException} occurs. * @throws JAXBException * If {@link JAXBException} occurs. If saving fails. */ private void saveEnvironment(Environment environment) throws JAXBException, IOException { transformator.marshall(pathResolver.getEnvironmentFilePath(environment), environment, getRelativeToSchemaPath(pathResolver.getEnvironmentPath()).toString(), ISchemaVersionAware.ConfigurationInterface.SCHEMA_VERSION); }
/** * Returns the directory where profiles are saved. * * @return Profiles directory path. */ public Path getProfilesPath() { return getDefaultCiPath().resolve(PROFILES_FOLDER); }
/** * Saves the passed {@link IBusinessContextDefinition}. * * @param businessContextDefinition * {@link IBusinessContextDefinition} to save * @throws IOException * If {@link IOException} occurs. * @throws JAXBException * If {@link JAXBException} occurs. If saving fails. */ private void saveBusinessContext(BusinessContextDefinition businessContextDefinition) throws JAXBException, IOException { businessContextDefinitionReference.set(businessContextDefinition); transformator.marshall(pathResolver.getBusinessContextFilePath(), businessContextDefinition, getRelativeToSchemaPath(pathResolver.getDefaultCiPath()).toString(), ISchemaVersionAware.ConfigurationInterface.SCHEMA_VERSION); }
existingProfiles = new ConcurrentHashMap<>(16, 0.75f, 2); Path path = pathResolver.getProfilesPath(); final Path schemaPath = pathResolver.getSchemaPath();
@Override public Path answer(InvocationOnMock invocation) throws Throwable { return Paths.get(TEST_FOLDER).resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getEnvironmentPath())) .resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getProfileFilePath((Profile) invocation.getArguments()[0]))); } }).when(pathResolver).getProfileFilePath(Matchers.<Profile> any());
@Override public Path answer(InvocationOnMock invocation) throws Throwable { return Paths.get(TEST_FOLDER).resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getAlertingDefinitionsPath())) .resolve(EXT_RESOURCES_PATH.relativize(resolverHelper.getAlertingDefinitionFilePath((AlertingDefinition) invocation.getArguments()[0]))); } }).when(pathResolver).getAlertingDefinitionFilePath(Matchers.<AlertingDefinition> any());
/** * Saves profile and persists it to the list. * * @param profile * Profile to be saved. * @throws IOException * If {@link IOException} occurs during save. * @throws JAXBException * If {@link JAXBException} occurs during save. * @throws BusinessException * If saving of the common profile is requested. */ private void saveProfile(Profile profile) throws BusinessException, JAXBException, IOException { if (profile.isCommonProfile()) { throw new BusinessException("Save the profile '" + profile.getName() + " to disk.", ConfigurationInterfaceErrorCodeEnum.COMMON_PROFILE_CAN_NOT_BE_ALTERED); } transformator.marshall(pathResolver.getProfileFilePath(profile), profile, getRelativeToSchemaPath(pathResolver.getProfilesPath()).toString(), ISchemaVersionAware.ConfigurationInterface.SCHEMA_VERSION); }
existingEnvironments = new ConcurrentHashMap<>(16, 0.75f, 2); Path path = pathResolver.getEnvironmentPath(); final Path schemaPath = pathResolver.getSchemaPath();
/** * Returns path pointing to the profile file. * * @param profile * {@link Profile} * @return Path to the file. */ public Path getProfileFilePath(Profile profile) { String secureProfileName = removeIllegalFilenameCharacters(profile.getName()); String fileName = profile.getId() + "-" + secureProfileName + ".xml"; return getProfilesPath().resolve(fileName); }
/** * Deletes the existing environment. * * @param environment * Environment to delete. * @throws IOException * If {@link IOException} occurs during delete. */ public void deleteEnvironment(Environment environment) throws IOException { String id = environment.getId(); Environment local = existingEnvironments.remove(id); if (null != local) { Files.deleteIfExists(pathResolver.getEnvironmentFilePath(local)); AgentMappings agentMappings = agentMappingsReference.get(); if (checkEnvironments(agentMappings)) { try { saveAgentMappings(agentMappings, false); } catch (Exception e) { log.error("Update of the agent mappings on the environment deletion failed.", e); } } } }
Profile local = existingProfiles.get(id); if (null != local) { Files.deleteIfExists(pathResolver.getProfileFilePath(local));
/** * Deletes the alerting definition. * * @param alertingDefinition * AlertingDefinition to delete. * @throws IOException * If {@link IOException} occurs during delete. */ public void deleteAlertingDefinition(AlertingDefinition alertingDefinition) throws IOException { String id = alertingDefinition.getId(); AlertingDefinition local = existingAlertingDefinitions.remove(id); if (local != null) { Files.deleteIfExists(pathResolver.getAlertingDefinitionFilePath(local)); eventPublisher.publishEvent(new AbstractAlertingDefinitionEvent.AlertingDefinitionDeletedEvent(this, local)); } }