/** * Returns the {@link AlertingDefinition} for the given id. * * @param id * the identifier of the {@link AlertingDefinition} * @return {@link AlertingDefinition} of the given id * @throws BusinessException * if no {@link AlertingDefinition} exists for the given id */ public AlertingDefinition getAlertingDefinition(String id) throws BusinessException { AlertingDefinition alertingDefinition = existingAlertingDefinitions.get(id); if (null == alertingDefinition) { throw new BusinessException("Load alerting definition with the id=" + id + ".", AlertErrorCodeEnum.ALERTING_DEFINITION_DOES_NOT_EXIST); } return alertingDefinition; }
/** * Returns the profile with the given id. * * @param id * Id of profile. * @return {@link Profile} * @throws BusinessException * If profile with given id does not exist. */ public Profile getProfile(String id) throws BusinessException { Profile profile = existingProfiles.get(id); if (null == profile) { throw new BusinessException("Load profile with the id=" + id + ".", ConfigurationInterfaceErrorCodeEnum.PROFILE_DOES_NOT_EXIST); } return profile; }
/** * Returns the environment with the given id. * * @param id * Id of environment. * @return {@link Environment} * @throws BusinessException * If environment with given id does not exist. */ public Environment getEnvironment(String id) throws BusinessException { Environment environment = existingEnvironments.get(id); if (null == environment) { throw new BusinessException("Load environemnt with the id=" + id + ".", ConfigurationInterfaceErrorCodeEnum.ENVIRONMENT_DOES_NOT_EXIST); } return environment; }
/** * {@inheritDoc} */ @Override public PlatformIdent getCompleteAgent(long id) throws BusinessException { for (PlatformIdent platformIdent : agents) { if (platformIdent.getId().longValue() == id) { return platformIdent; } } throw new BusinessException("Load the agent with the ID=" + id + ".", AgentManagementErrorCodeEnum.AGENT_DOES_NOT_EXIST); }
/** * {@inheritDoc} */ @Override public void removeLabelType(AbstractStorageLabelType<?> labelType) throws BusinessException { if (getAllLabelsForType(labelType).isEmpty()) { JpaUtil.delete(entityManager, labelType); } else { throw new BusinessException("Delete label type " + labelType.getClass().getSimpleName() + ".", StorageErrorCodeEnum.LABEL_TYPE_CAN_NOT_BE_DELETED); } }
/** * Returns the local cached object that represent the {@link StorageData}. * * @param storageData * Template. * @return Local object. * @throws BusinessException * If local object can not be found. */ private StorageData getLocalStorageDataObject(StorageData storageData) throws BusinessException { for (StorageData existing : existingStoragesSet) { if (existing.getId().equals(storageData.getId())) { return existing; } } throw new BusinessException("Find storage " + storageData + ".", StorageErrorCodeEnum.STORAGE_DOES_NOT_EXIST); }
/** * {@inheritDoc} */ @Override @MethodLog public PlatformIdent getCompleteAgent(long id) throws BusinessException { PlatformIdent platformIdent = platformIdentDao.findInitialized(id); if (null != platformIdent) { return platformIdent; } else { throw new BusinessException("Load the agent with ID=" + id + ".", AgentManagementErrorCodeEnum.AGENT_DOES_NOT_EXIST); } }
/** * {@inheritDoc} */ @Override @MethodLog public String getCachedStorageDataFileLocation(StorageData storageData, int hash) throws BusinessException { if (!storageManager.isStorageExisting(storageData)) { throw new BusinessException("Load cached storage data files locations for storage " + storageData + ".", StorageErrorCodeEnum.STORAGE_DOES_NOT_EXIST); } return storageManager.getCachedStorageDataFileLocation(storageData, hash); }
@Test public void profileDoesNotExists() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenThrow(new BusinessException(null)); Collection<JmxMonitoringApplier> jmxMonitoringAppliers = configurationResolver.getJmxMonitoringAppliers(environment); assertThat(jmxMonitoringAppliers, is(empty())); }
@Test public void profileDoesNotExists() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenThrow(new BusinessException(null)); Collection<ExcludeRule> rules = configurationResolver.getAllExcludeRules(environment); assertThat(rules, is(empty())); }
@Test(expectedExceptions = BusinessException.class) public void noMappingsForAgent() throws BusinessException { List<String> definedIPs = mock(List.class); String agentName = "agentName"; String version = "v1"; when(configurationResolver.getEnvironmentForAgent(definedIPs, agentName)).thenThrow(new BusinessException(null)); manager.register(definedIPs, agentName, version); }
@Test public void profileDoesNotExists() throws BusinessException { when(environment.getProfileIds()).thenReturn(Collections.singleton(PROFILE_ID)); when(configurationInterfaceManager.getProfile(PROFILE_ID)).thenThrow(new BusinessException(null)); Collection<IInstrumentationApplier> appliers = configurationResolver.getInstrumentationAppliers(environment); assertThat(appliers, is(empty())); verify(functionalAssignmentFactory).getSpecialAssignments(environment); }
/** * {@inheritDoc} */ @Override @Transactional @MethodLog public Map<String, Long> getBusinessContextFilesLocation(StorageData storageData) throws BusinessException { if (!storageManager.isStorageExisting(storageData)) { throw new BusinessException("Load business context files locations for the storage " + storageData + ".", StorageErrorCodeEnum.STORAGE_DOES_NOT_EXIST); } try { return storageManager.getFilesHttpLocation(storageData, StorageFileType.BUSINESS_CONTEXT_FILE.getExtension()); } catch (IOException e) { throw new TechnicalException("Load business context files locations for the storage " + storageData + ".", StorageErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
@Test public void noClassCacheWarningShouldBeLoggedOnce() throws Exception { when(connection.isConnected()).thenReturn(true); BusinessException businessException = new BusinessException(AgentManagementErrorCodeEnum.AGENT_DOES_NOT_EXIST); doThrow(businessException).when(connection).analyzeJmxAttributes(anyLong(), Matchers.anyList()); jmxSensor.mbeanServerAdded(mBeanServer); verify(agentStatisticsLogger, times(1)).noClassCacheAvailable(); } }
/** * {@inheritDoc} */ @Override @MethodLog public Map<String, Long> getDataFilesLocations(StorageData storageData) throws BusinessException { if (!storageManager.isStorageExisting(storageData)) { throw new BusinessException("Load data files locations for the storage " + storageData + ".", StorageErrorCodeEnum.STORAGE_DOES_NOT_EXIST); } try { return storageManager.getFilesHttpLocation(storageData, StorageFileType.DATA_FILE.getExtension()); } catch (IOException e) { throw new TechnicalException("Load data files locations for the storage " + storageData + ".", StorageErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
/** * Test the Business exception. */ @Test public void businessException() throws SerializationException { BusinessException businessException = new BusinessException("Message", StorageErrorCodeEnum.CAN_NOT_START_RECORDING); businessException.printStackTrace(); BusinessException deserialized = serializeBackAndForth(businessException); assertThat(deserialized, is(instanceOf(BusinessException.class))); assertThat(deserialized.getMessage(), is(equalTo(businessException.getMessage()))); assertThat(deserialized.getStackTrace(), is(equalTo(businessException.getStackTrace()))); assertThat(deserialized.getActionPerformed(), is(equalTo(businessException.getActionPerformed()))); assertThat(deserialized.getErrorCode(), is(equalTo(businessException.getErrorCode()))); }
/** * {@inheritDoc} */ @Override @MethodLog public Map<String, Long> getIndexFilesLocations(StorageData storageData) throws BusinessException { if (!storageManager.isStorageExisting(storageData)) { throw new BusinessException("Load index files locations for the storage " + storageData + ".", StorageErrorCodeEnum.STORAGE_DOES_NOT_EXIST); } try { return storageManager.getFilesHttpLocation(storageData, StorageFileType.INDEX_FILE.getExtension()); } catch (IOException e) { throw new TechnicalException("Load index files locations for the storage " + storageData + ".", StorageErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
/** * {@inheritDoc} */ @Override @MethodLog public Map<String, Long> getAgentFilesLocations(StorageData storageData) throws BusinessException { if (!storageManager.isStorageExisting(storageData)) { throw new BusinessException("Load agent files locations for the storage " + storageData + ".", StorageErrorCodeEnum.STORAGE_DOES_NOT_EXIST); } try { return storageManager.getFilesHttpLocation(storageData, StorageFileType.AGENT_FILE.getExtension()); } catch (IOException e) { throw new TechnicalException("Load agent files locations for the storage " + storageData + ".", StorageErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
/** * {@inheritDoc} */ @Override @MethodLog public Map<String, Long> getCachedDataFilesLocations(StorageData storageData) throws BusinessException { if (!storageManager.isStorageExisting(storageData)) { throw new BusinessException("Load cached files locations for the storage " + storageData + ".", StorageErrorCodeEnum.STORAGE_DOES_NOT_EXIST); } try { return storageManager.getFilesHttpLocation(storageData, StorageFileType.CACHED_DATA_FILE.getExtension()); } catch (IOException e) { throw new TechnicalException("Load cache files locations for the storage " + storageData + ".", StorageErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
/** * {@inheritDoc} */ @Override @MethodLog public void writeToStorage(StorageData storageData, Collection<DefaultData> defaultDataCollection, Collection<AbstractDataProcessor> dataProcessors, boolean synchronously) throws BusinessException { if (!storageManager.isStorageOpen(storageData)) { throw new BusinessException("Write to the storage " + storageData + ".", StorageErrorCodeEnum.STORAGE_IS_NOT_OPENED); } try { storageManager.writeToStorage(storageData, defaultDataCollection, dataProcessors, synchronously); } catch (SerializationException e) { throw new TechnicalException("Write to the storage " + storageData + ".", StorageErrorCodeEnum.SERIALIZATION_FAILED, e); } catch (IOException e) { throw new TechnicalException("Write to the storage " + storageData + ".", StorageErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }