/** * Elements contain whitespace only elements, which should be ignored. */ @Test public void testJoinIgnoreBlanks() { List<String> list = Arrays.asList(" \t\n\r", "A", " \t\n\r", "B", " \t\n\r"); String delimiter = "|"; String escapeSequence = "\\"; String result = herdStringHelper.join(list, delimiter, escapeSequence); assertEquals("result", "A|B", result); }
/** * 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 script arguments from the DelegateExecution, delimited and escaped as a list. * * @param execution the DelegateExecution * * @return script arguments */ protected List<String> getScriptArguments(DelegateExecution execution) { String scriptArgumentsString = activitiHelper.getExpressionVariableAsString(scriptArguments, execution); return daoHelper.splitStringWithDefaultDelimiterEscaped(scriptArgumentsString); }
private List<Parameter> buildJobParameters(StorageUnitNotificationEventParamsDto storageUnitNotificationEventParams) throws IOException { List<Parameter> parameters = new ArrayList<>(); BusinessObjectData businessObjectData = storageUnitNotificationEventParams.getBusinessObjectData(); NotificationJobActionEntity notificationJobActionEntity = storageUnitNotificationEventParams.getNotificationJobAction(); parameters.add(new Parameter(PARAM_NAMESPACE, storageUnitNotificationEventParams.getStorageUnitNotificationRegistration().getNamespace().getCode())); parameters.add(new Parameter(PARAM_NOTIFICATION_NAME, storageUnitNotificationEventParams.getStorageUnitNotificationRegistration().getName())); parameters.add(new Parameter(PARAM_STORAGE_UNIT_EVENT_TYPE, storageUnitNotificationEventParams.getEventType())); parameters.add(new Parameter(PARAM_CORRELATION_DATA, notificationJobActionEntity.getCorrelationData())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DATA, jsonHelper.objectToJson(businessObjectData))); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DEFINITION_NAMESPACE, businessObjectData.getNamespace())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DEFINITION_NAME, businessObjectData.getBusinessObjectDefinitionName())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_FORMAT_USAGE, businessObjectData.getBusinessObjectFormatUsage())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_FORMAT_FILE_TYPE, businessObjectData.getBusinessObjectFormatFileType())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_FORMAT_VERSION, Integer.toString(businessObjectData.getBusinessObjectFormatVersion()))); parameters.add(new Parameter(PARAM_PARTITION_COLUMN_NAMES, herdStringHelper.buildStringWithDefaultDelimiter(storageUnitNotificationEventParams.getPartitionColumnNames()))); parameters.add( new Parameter(PARAM_PARTITION_VALUES, herdStringHelper.buildStringWithDefaultDelimiter(storageUnitNotificationEventParams.getPartitionValues()))); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DATA_VERSION, Integer.toString(businessObjectData.getVersion()))); parameters.add(new Parameter(PARAM_STORAGE_NAME, storageUnitNotificationEventParams.getStorageName())); parameters.add(new Parameter(PARAM_NEW_STORAGE_UNIT_STATUS, storageUnitNotificationEventParams.getNewStorageUnitStatus())); parameters.add(new Parameter(PARAM_OLD_STORAGE_UNIT_STATUS, storageUnitNotificationEventParams.getOldStorageUnitStatus())); return parameters; } }
@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())); } }
/** * Get and validates configuration value for the delay in days to complete the business object data destroy operation. * * @return the delay in days to complete the business object data destroy operation */ int getAndValidateFinalDestroyInDays() { // Get the configured delay (in days) for business object data finalize destroy. int finalDestroyInDays = herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.BDATA_FINAL_DESTROY_DELAY_IN_DAYS); // Validate the finalize delay configuration value. if (finalDestroyInDays <= 0) { throw new IllegalStateException( String.format("Configuration \"%s\" must be a positive integer.", ConfigurationValue.BDATA_FINAL_DESTROY_DELAY_IN_DAYS.getKey())); } return finalDestroyInDays; }
@Test public void testGetRequiredConfigurationValue() throws Exception { Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE.getKey(), STRING_VALUE); modifyPropertySourceInEnvironment(overrideMap); try { String resultValue = herdStringHelper.getRequiredConfigurationValue(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE); assertEquals(STRING_VALUE, resultValue); } finally { restorePropertySourceInEnvironment(); } }
/** * Returns a list of subnets specified in the definition. The definition specifies a comma-separated list of subnet IDs. This method parses it, looks up the * subnet from AWS, and returns the list. If the subnet is not specified or empty, all subnets in the current VPC is returned. This is AWS's default * behavior. All subnet IDs will be trimmed, and ignored if empty. * * @param emrClusterDefinition the definition specifying the subnet IDs * @param awsParamsDto the AWS related parameters for access/secret keys and proxy details * * @return the list of subnets */ private List<Subnet> getSubnets(EmrClusterDefinition emrClusterDefinition, AwsParamsDto awsParamsDto) { String definitionSubnetId = emrClusterDefinition.getSubnetId(); Set<String> subnetIds = Collections.emptySet(); if (StringUtils.isNotBlank(definitionSubnetId)) { subnetIds = herdStringHelper.splitAndTrim(definitionSubnetId, ","); } return ec2Dao.getSubnets(subnetIds, awsParamsDto); } }
/** * Returns a mapping of instance types to spot prices for the given AZ and instance types. The spot prices are retrieved from EC2 API. * <p/> * This method also validates that the given instance types are real instance types supported by AWS. * * @param availabilityZone the AZ of the spot instances * @param instanceTypes the size of the spot instances * @param awsParamsDto the AWS related parameters for access/secret keys and proxy details * * @return the mapping of instance type to spot prices * @throws ObjectNotFoundException when any of the instance type does not exist in AWS */ private Map<String, BigDecimal> getInstanceTypeSpotPrices(AvailabilityZone availabilityZone, Set<String> instanceTypes, AwsParamsDto awsParamsDto) { List<String> productDescriptions = herdStringHelper.getDelimitedConfigurationValue(ConfigurationValue.EMR_SPOT_PRICE_HISTORY_PRODUCT_DESCRIPTIONS); List<SpotPrice> spotPrices = ec2Dao.getLatestSpotPrices(availabilityZone.getZoneName(), instanceTypes, productDescriptions, awsParamsDto); Map<String, BigDecimal> instanceTypeSpotPrices = new HashMap<>(); for (SpotPrice spotPrice : spotPrices) { instanceTypeSpotPrices.put(spotPrice.getInstanceType(), new BigDecimal(spotPrice.getSpotPrice())); } return instanceTypeSpotPrices; }
private List<Parameter> buildJobParameters(StorageUnitNotificationEventParamsDto storageUnitNotificationEventParams) throws IOException { List<Parameter> parameters = new ArrayList<>(); BusinessObjectData businessObjectData = storageUnitNotificationEventParams.getBusinessObjectData(); NotificationJobActionEntity notificationJobActionEntity = storageUnitNotificationEventParams.getNotificationJobAction(); parameters.add(new Parameter(PARAM_NAMESPACE, storageUnitNotificationEventParams.getStorageUnitNotificationRegistration().getNamespace().getCode())); parameters.add(new Parameter(PARAM_NOTIFICATION_NAME, storageUnitNotificationEventParams.getStorageUnitNotificationRegistration().getName())); parameters.add(new Parameter(PARAM_STORAGE_UNIT_EVENT_TYPE, storageUnitNotificationEventParams.getEventType())); parameters.add(new Parameter(PARAM_CORRELATION_DATA, notificationJobActionEntity.getCorrelationData())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DATA, jsonHelper.objectToJson(businessObjectData))); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DEFINITION_NAMESPACE, businessObjectData.getNamespace())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DEFINITION_NAME, businessObjectData.getBusinessObjectDefinitionName())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_FORMAT_USAGE, businessObjectData.getBusinessObjectFormatUsage())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_FORMAT_FILE_TYPE, businessObjectData.getBusinessObjectFormatFileType())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_FORMAT_VERSION, Integer.toString(businessObjectData.getBusinessObjectFormatVersion()))); parameters.add(new Parameter(PARAM_PARTITION_COLUMN_NAMES, herdStringHelper.buildStringWithDefaultDelimiter(storageUnitNotificationEventParams.getPartitionColumnNames()))); parameters.add( new Parameter(PARAM_PARTITION_VALUES, herdStringHelper.buildStringWithDefaultDelimiter(storageUnitNotificationEventParams.getPartitionValues()))); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DATA_VERSION, Integer.toString(businessObjectData.getVersion()))); parameters.add(new Parameter(PARAM_STORAGE_NAME, storageUnitNotificationEventParams.getStorageName())); parameters.add(new Parameter(PARAM_NEW_STORAGE_UNIT_STATUS, storageUnitNotificationEventParams.getNewStorageUnitStatus())); parameters.add(new Parameter(PARAM_OLD_STORAGE_UNIT_STATUS, storageUnitNotificationEventParams.getOldStorageUnitStatus())); return parameters; } }
@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())); } }
/** * Get and validates configuration value for the delay in days to complete the business object data destroy operation. * * @return the delay in days to complete the business object data destroy operation */ int getAndValidateFinalDestroyInDays() { // Get the configured delay (in days) for business object data finalize destroy. int finalDestroyInDays = herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.BDATA_FINAL_DESTROY_DELAY_IN_DAYS); // Validate the finalize delay configuration value. if (finalDestroyInDays <= 0) { throw new IllegalStateException( String.format("Configuration \"%s\" must be a positive integer.", ConfigurationValue.BDATA_FINAL_DESTROY_DELAY_IN_DAYS.getKey())); } return finalDestroyInDays; }
@Test public void testGetRequiredConfigurationValueBlank() throws Exception { Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE.getKey(), BLANK_TEXT); modifyPropertySourceInEnvironment(overrideMap); try { herdStringHelper.getRequiredConfigurationValue(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE); fail("Suppose to throw an IllegalStateException when encrypted configuration value is blank."); } catch (IllegalStateException e) { assertEquals( String.format("Missing configuration parameter value for key \"%s\".", ConfigurationValue.ACTIVITI_JOB_DEFINITION_ID_TEMPLATE.getKey()), e.getMessage()); } finally { restorePropertySourceInEnvironment(); } }
/** * Returns a list of subnets specified in the definition. The definition specifies a comma-separated list of subnet IDs. This method parses it, looks up the * subnet from AWS, and returns the list. If the subnet is not specified or empty, all subnets in the current VPC is returned. This is AWS's default * behavior. All subnet IDs will be trimmed, and ignored if empty. * * @param emrClusterDefinition the definition specifying the subnet IDs * @param awsParamsDto the AWS related parameters for access/secret keys and proxy details * * @return the list of subnets */ private List<Subnet> getSubnets(EmrClusterDefinition emrClusterDefinition, AwsParamsDto awsParamsDto) { String definitionSubnetId = emrClusterDefinition.getSubnetId(); Set<String> subnetIds = Collections.emptySet(); if (StringUtils.isNotBlank(definitionSubnetId)) { subnetIds = herdStringHelper.splitAndTrim(definitionSubnetId, ","); } return ec2Dao.getSubnets(subnetIds, awsParamsDto); } }
/** * Returns a mapping of instance types to spot prices for the given AZ and instance types. The spot prices are retrieved from EC2 API. * <p/> * This method also validates that the given instance types are real instance types supported by AWS. * * @param availabilityZone the AZ of the spot instances * @param instanceTypes the size of the spot instances * @param awsParamsDto the AWS related parameters for access/secret keys and proxy details * * @return the mapping of instance type to spot prices * @throws ObjectNotFoundException when any of the instance type does not exist in AWS */ private Map<String, BigDecimal> getInstanceTypeSpotPrices(AvailabilityZone availabilityZone, Set<String> instanceTypes, AwsParamsDto awsParamsDto) { List<String> productDescriptions = herdStringHelper.getDelimitedConfigurationValue(ConfigurationValue.EMR_SPOT_PRICE_HISTORY_PRODUCT_DESCRIPTIONS); List<SpotPrice> spotPrices = ec2Dao.getLatestSpotPrices(availabilityZone.getZoneName(), instanceTypes, productDescriptions, awsParamsDto); Map<String, BigDecimal> instanceTypeSpotPrices = new HashMap<>(); for (SpotPrice spotPrice : spotPrices) { instanceTypeSpotPrices.put(spotPrice.getInstanceType(), new BigDecimal(spotPrice.getSpotPrice())); } return instanceTypeSpotPrices; }
/** * Gets the script arguments from the DelegateExecution, delimited and escaped as a list. * * @param execution the DelegateExecution * * @return script arguments */ protected List<String> getScriptArguments(DelegateExecution execution) { String scriptArgumentsString = activitiHelper.getExpressionVariableAsString(scriptArguments, execution); return daoHelper.splitStringWithDefaultDelimiterEscaped(scriptArgumentsString); }
/** * Only 1 element in the list */ @Test public void testJoinSingleElement() { List<String> list = Arrays.asList("A"); String delimiter = "|"; String escapeSequence = "\\"; String result = herdStringHelper.join(list, delimiter, escapeSequence); assertEquals("result", "A", result); }
/** * 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)); }
private List<Parameter> buildJobParameters(BusinessObjectDataNotificationEventParamsDto businessObjectDataNotificationEventParams) throws IOException { List<Parameter> parameters = new ArrayList<>(); BusinessObjectData businessObjectData = businessObjectDataNotificationEventParams.getBusinessObjectData(); NotificationJobActionEntity notificationJobActionEntity = businessObjectDataNotificationEventParams.getNotificationJobAction(); parameters.add( new Parameter(PARAM_NAMESPACE, businessObjectDataNotificationEventParams.getBusinessObjectDataNotificationRegistration().getNamespace().getCode())); parameters .add(new Parameter(PARAM_NOTIFICATION_NAME, businessObjectDataNotificationEventParams.getBusinessObjectDataNotificationRegistration().getName())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DATA_EVENT_TYPE, businessObjectDataNotificationEventParams.getEventType())); parameters.add(new Parameter(PARAM_CORRELATION_DATA, notificationJobActionEntity.getCorrelationData())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DATA, jsonHelper.objectToJson(businessObjectData))); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DEFINITION_NAMESPACE, businessObjectData.getNamespace())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DEFINITION_NAME, businessObjectData.getBusinessObjectDefinitionName())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_FORMAT_USAGE, businessObjectData.getBusinessObjectFormatUsage())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_FORMAT_FILE_TYPE, businessObjectData.getBusinessObjectFormatFileType())); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_FORMAT_VERSION, Integer.toString(businessObjectData.getBusinessObjectFormatVersion()))); parameters.add(new Parameter(PARAM_PARTITION_COLUMN_NAMES, herdStringHelper.buildStringWithDefaultDelimiter(businessObjectDataNotificationEventParams.getPartitionColumnNames()))); parameters.add(new Parameter(PARAM_PARTITION_VALUES, herdStringHelper.buildStringWithDefaultDelimiter(businessObjectDataNotificationEventParams.getPartitionValues()))); parameters.add(new Parameter(PARAM_BUSINESS_OBJECT_DATA_VERSION, Integer.toString(businessObjectData.getVersion()))); parameters.add(new Parameter(PARAM_NEW_BUSINESS_OBJECT_DATA_STATUS, businessObjectDataNotificationEventParams.getNewBusinessObjectDataStatus())); parameters.add(new Parameter(PARAM_OLD_BUSINESS_OBJECT_DATA_STATUS, businessObjectDataNotificationEventParams.getOldBusinessObjectDataStatus())); return parameters; } }
/** * Gets a list of historic process instances by the given process definition keys, job status, start time, and/or end time. If the given list of process * definition keys is empty or null, the result will not be filtered by the process definition keys. If the given job status is null, the result will not be * filtered by the job status. When job status is RUNNING or SUSPENDED, then all "unfinished" process instances are returned. * * @param processDefinitionKeys Optional. The set of process definition keys * @param jobStatus an optional job status * @param startTime an optional job start time * @param endTime an optional job end time * * @return A list of historic process instances */ private List<HistoricProcessInstance> getHistoricProcessInstances(Collection<String> processDefinitionKeys, JobStatusEnum jobStatus, DateTime startTime, DateTime endTime) { /* * Validates the result count before actually retrieving the result set, so that it would fail-fast and minimize the impact of the query. */ long processInstanceCount = activitiService.getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(jobStatus, processDefinitionKeys, startTime, endTime); int jobsMaxQueryResults = herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.JOBS_QUERY_MAX_RESULTS); Assert.isTrue(processInstanceCount <= jobsMaxQueryResults, "Too many jobs found for the specified filter parameters. The maximum number of results allowed is " + jobsMaxQueryResults + " and the number of results returned was " + processInstanceCount + "."); return activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(jobStatus, processDefinitionKeys, startTime, endTime); }