/** * Returns a list of values from a configuration value which are delimited by the default delimited configured by FIELD_DATA_DELIMITER. Returns an empty * list if the configuration value does not exist. * * @param configurationValue The configuration value * * @return List of values */ public List<String> getDelimitedConfigurationValue(ConfigurationValue configurationValue) { return splitStringWithDefaultDelimiter(configurationHelper.getProperty(configurationValue)); }
/** * Returns a list of values from a configuration value which are delimited by the default delimited configured by FIELD_DATA_DELIMITER. Returns an empty * list if the configuration value does not exist. * * @param configurationValue The configuration value * * @return List of values */ public List<String> getDelimitedConfigurationValue(ConfigurationValue configurationValue) { return splitStringWithDefaultDelimiter(configurationHelper.getProperty(configurationValue)); }
/** * Gets the header names from configuration in the current environment. * * @return map of header name key to header value */ private Map<String, String> getHeaderNames() { Map<String, String> headerNames = new HashMap<>(); List<String> headers = herdStringHelper.splitStringWithDefaultDelimiter(getSecurityHeaderNames()); for (String header : headers) { String[] keyValueString = header.split("="); headerNames.put(keyValueString[0], keyValueString[1]); } return headerNames; }
/** * Checks if the method name is not allowed against the configuration. * * @param methodName the method name * * @throws org.finra.herd.model.MethodNotAllowedException if requested method is not allowed. */ public void checkNotAllowedMethod(String methodName) throws MethodNotAllowedException { boolean needToBlock = false; ConfigurationEntity configurationEntity = configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); if (configurationEntity != null && StringUtils.isNotBlank(configurationEntity.getValueClob())) { List<String> methodsToBeBlocked = herdStringHelper.splitStringWithDefaultDelimiter(configurationEntity.getValueClob()); needToBlock = methodsToBeBlocked.contains(methodName); } if (needToBlock) { throw new MethodNotAllowedException("The requested method is not allowed."); } }
/** * Checks if the method name is not allowed against the configuration. * * @param methodName the method name * * @throws org.finra.herd.model.MethodNotAllowedException if requested method is not allowed. */ public void checkNotAllowedMethod(String methodName) throws MethodNotAllowedException { boolean needToBlock = false; ConfigurationEntity configurationEntity = configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); if (configurationEntity != null && StringUtils.isNotBlank(configurationEntity.getValueClob())) { List<String> methodsToBeBlocked = herdStringHelper.splitStringWithDefaultDelimiter(configurationEntity.getValueClob()); needToBlock = methodsToBeBlocked.contains(methodName); } if (needToBlock) { throw new MethodNotAllowedException("The requested method is not allowed."); } }
@Test public void testCheckNotAllowedMethodMethodIsNotBlocked() { // Create a list of methods to be blocked. String blockedMethodListAsText = STRING_VALUE; List<String> blockedMethods = Arrays.asList(METHOD_NAME); // Create a mock configuration entity. ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(blockedMethodListAsText); // Mock the external calls. when(configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey())).thenReturn(configurationEntity); when(herdStringHelper.splitStringWithDefaultDelimiter(blockedMethodListAsText)).thenReturn(blockedMethods); // Call the method under test. configurationDaoHelper.checkNotAllowedMethod(METHOD_NAME_2); // Verify the external calls. verify(configurationDao).getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); verify(herdStringHelper).splitStringWithDefaultDelimiter(blockedMethodListAsText); verifyNoMoreInteractionsHelper(); }
@Test public void testCheckNotAllowedMethod() { // Create a list of methods to be blocked. String blockedMethodListAsText = STRING_VALUE; List<String> blockedMethods = Arrays.asList(METHOD_NAME); // Create a mock configuration entity. ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(blockedMethodListAsText); // Mock the external calls. when(configurationDao.getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey())).thenReturn(configurationEntity); when(herdStringHelper.splitStringWithDefaultDelimiter(blockedMethodListAsText)).thenReturn(blockedMethods); // Try to call the method under test. try { configurationDaoHelper.checkNotAllowedMethod(METHOD_NAME); fail(); } catch (MethodNotAllowedException e) { assertEquals("The requested method is not allowed.", e.getMessage()); } // Verify the external calls. verify(configurationDao).getConfigurationByKey(ConfigurationValue.NOT_ALLOWED_HERD_ENDPOINTS.getKey()); verify(herdStringHelper).splitStringWithDefaultDelimiter(blockedMethodListAsText); verifyNoMoreInteractionsHelper(); }
@Override public void executeImpl(DelegateExecution execution) throws Exception { // Create the request. EmrMasterSecurityGroupAddRequest request = new EmrMasterSecurityGroupAddRequest(); request.setNamespace(activitiHelper.getExpressionVariableAsString(namespace, execution)); request.setEmrClusterDefinitionName(activitiHelper.getExpressionVariableAsString(emrClusterDefinitionName, execution)); request.setEmrClusterName(activitiHelper.getExpressionVariableAsString(emrClusterName, execution)); request.setAccountId(activitiHelper.getExpressionVariableAsString(accountId, execution)); String groupIdStr = activitiHelper.getExpressionVariableAsString(securityGroupIds, execution); if (StringUtils.isBlank(groupIdStr)) { throw new IllegalArgumentException("At least one security group must be specified."); } request.setSecurityGroupIds(daoHelper.splitStringWithDefaultDelimiter(groupIdStr.trim())); // Create the cluster in a new transaction. EmrMasterSecurityGroup emrMasterSecurityGroup = emrService.addSecurityGroupsToClusterMaster(request); // Set workflow variables based on the security groups. setTaskWorkflowVariable(execution, VARIABLE_EMR_MASTER_SECURITY_GROUPS, herdStringHelper.buildStringWithDefaultDelimiter(emrMasterSecurityGroup.getSecurityGroupIds())); } }
@Override public void executeImpl(DelegateExecution execution) throws Exception { // Create the request. EmrMasterSecurityGroupAddRequest request = new EmrMasterSecurityGroupAddRequest(); request.setNamespace(activitiHelper.getExpressionVariableAsString(namespace, execution)); request.setEmrClusterDefinitionName(activitiHelper.getExpressionVariableAsString(emrClusterDefinitionName, execution)); request.setEmrClusterName(activitiHelper.getExpressionVariableAsString(emrClusterName, execution)); request.setAccountId(activitiHelper.getExpressionVariableAsString(accountId, execution)); String groupIdStr = activitiHelper.getExpressionVariableAsString(securityGroupIds, execution); if (StringUtils.isBlank(groupIdStr)) { throw new IllegalArgumentException("At least one security group must be specified."); } request.setSecurityGroupIds(daoHelper.splitStringWithDefaultDelimiter(groupIdStr.trim())); // Create the cluster in a new transaction. EmrMasterSecurityGroup emrMasterSecurityGroup = emrService.addSecurityGroupsToClusterMaster(request); // Set workflow variables based on the security groups. setTaskWorkflowVariable(execution, VARIABLE_EMR_MASTER_SECURITY_GROUPS, herdStringHelper.buildStringWithDefaultDelimiter(emrMasterSecurityGroup.getSecurityGroupIds())); } }
for (String mandatoryTag : herdStringHelper.splitStringWithDefaultDelimiter(configurationHelper.getProperty(ConfigurationValue.MANDATORY_AWS_TAGS)))
for (String mandatoryTag : herdStringHelper.splitStringWithDefaultDelimiter(configurationHelper.getProperty(ConfigurationValue.MANDATORY_AWS_TAGS)))