test_class.file: herd-code/herd-service/src/test/java/org/finra/herd/service/helper/EmrClusterDefinitionHelperTest.java
test_class.identifier: EmrClusterDefinitionHelperTest
test_class.superclass: extends AbstractServiceTest
test_case.body: @Test
      public void testValidateEmrClusterDefinitionConfigurationMasterOnDemandThresholdSpecified()
      {
          EmrClusterDefinition emrClusterDefinition = createValidEmrClusterDefinition();
          emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceOnDemandThreshold(BigDecimal.ONE);
  
          try
          {
              emrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(emrClusterDefinition);
              fail("expected IllegalArgumentException, but no exception was thrown");
          }
          catch (Exception e)
          {
              assertEquals("thrown exception", IllegalArgumentException.class, e.getClass());
          }
      }
test_case.class_method_signature: EmrClusterDefinitionHelperTest.testValidateEmrClusterDefinitionConfigurationMasterOnDemandThresholdSpecified()
test_case.full_signature: @Test public void testValidateEmrClusterDefinitionConfigurationMasterOnDemandThresholdSpecified()
test_case.identifier: testValidateEmrClusterDefinitionConfigurationMasterOnDemandThresholdSpecified
test_case.invocations: createValidEmrClusterDefinition setInstanceOnDemandThreshold getMasterInstances getInstanceDefinitions validateEmrClusterDefinitionConfiguration fail assertEquals getClass
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testValidateEmrClusterDefinitionConfigurationMasterOnDemandThresholdSpecified()
focal_class.declarator: alternateKeyHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private AlternateKeyHelper alternateKeyHelper;
focal_class.type: AlternateKeyHelper
focal_class.var_name: alternateKeyHelper
focal_class.declarator: configurationHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private ConfigurationHelper configurationHelper;
focal_class.type: ConfigurationHelper
focal_class.var_name: configurationHelper
focal_class.declarator: emrHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private EmrHelper emrHelper;
focal_class.type: EmrHelper
focal_class.var_name: emrHelper
focal_class.declarator: herdStringHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private HerdStringHelper herdStringHelper;
focal_class.type: HerdStringHelper
focal_class.var_name: herdStringHelper
focal_class.file: herd-code/herd-service/src/main/java/org/finra/herd/service/helper/EmrClusterDefinitionHelper.java
focal_class.identifier: EmrClusterDefinitionHelper
focal_class.class_method_signature: EmrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(EmrClusterDefinition emrClusterDefinition)
focal_class.full_signature: public void validateEmrClusterDefinitionConfiguration(EmrClusterDefinition emrClusterDefinition)
focal_class.identifier: validateEmrClusterDefinitionConfiguration
focal_class.modifiers: public
focal_class.parameters: (EmrClusterDefinition emrClusterDefinition)
focal_class.return: void
focal_class.signature: void validateEmrClusterDefinitionConfiguration(EmrClusterDefinition emrClusterDefinition)
focal_class.class_method_signature: EmrClusterDefinitionHelper.validateEmrClusterDefinitionKey(EmrClusterDefinitionKey key)
focal_class.full_signature: public void validateEmrClusterDefinitionKey(EmrClusterDefinitionKey key)
focal_class.identifier: validateEmrClusterDefinitionKey
focal_class.modifiers: public
focal_class.parameters: (EmrClusterDefinitionKey key)
focal_class.return: void
focal_class.signature: void validateEmrClusterDefinitionKey(EmrClusterDefinitionKey key)
focal_class.class_method_signature: EmrClusterDefinitionHelper.assertNotBlankAndTrim(List<String> list, String displayName)
focal_class.full_signature: private List<String> assertNotBlankAndTrim(List<String> list, String displayName)
focal_class.identifier: assertNotBlankAndTrim
focal_class.modifiers: private
focal_class.parameters: (List<String> list, String displayName)
focal_class.return: List<String>
focal_class.signature: List<String> assertNotBlankAndTrim(List<String> list, String displayName)
focal_class.class_method_signature: EmrClusterDefinitionHelper.validateInstanceDefinition(String name, InstanceDefinition instanceDefinition, Integer minimumInstanceCount)
focal_class.full_signature: private void validateInstanceDefinition(String name, InstanceDefinition instanceDefinition, Integer minimumInstanceCount)
focal_class.identifier: validateInstanceDefinition
focal_class.modifiers: private
focal_class.parameters: (String name, InstanceDefinition instanceDefinition, Integer minimumInstanceCount)
focal_class.return: void
focal_class.signature: void validateInstanceDefinition(String name, InstanceDefinition instanceDefinition, Integer minimumInstanceCount)
focal_class.class_method_signature: EmrClusterDefinitionHelper.validateMasterInstanceDefinition(MasterInstanceDefinition masterInstanceDefinition)
focal_class.full_signature: private void validateMasterInstanceDefinition(MasterInstanceDefinition masterInstanceDefinition)
focal_class.identifier: validateMasterInstanceDefinition
focal_class.modifiers: private
focal_class.parameters: (MasterInstanceDefinition masterInstanceDefinition)
focal_class.return: void
focal_class.signature: void validateMasterInstanceDefinition(MasterInstanceDefinition masterInstanceDefinition)
focal_method.body: public void validateEmrClusterDefinitionConfiguration(EmrClusterDefinition emrClusterDefinition) throws IllegalArgumentException
      {
          Assert.notNull(emrClusterDefinition, "An EMR cluster definition configuration must be specified.");
  
          Assert.isTrue(StringUtils.isNotBlank(emrClusterDefinition.getSubnetId()), "Subnet ID must be specified");
          for (String token : emrClusterDefinition.getSubnetId().split(","))
          {
              Assert.isTrue(StringUtils.isNotBlank(token), "No blank is allowed in the list of subnet IDs");
          }
  
          Assert.isTrue(!emrHelper.isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions()) ||
              CollectionUtils.isNotEmpty(emrClusterDefinition.getInstanceFleets()), "Instance group definitions or instance fleets must be specified.");
  
          if (!emrHelper.isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions()))
          {
              // Check master instances.
              Assert.notNull(emrClusterDefinition.getInstanceDefinitions().getMasterInstances(), "Master instances must be specified.");
              validateMasterInstanceDefinition(emrClusterDefinition.getInstanceDefinitions().getMasterInstances());
  
              // Check core instances.
              if (emrClusterDefinition.getInstanceDefinitions().getCoreInstances() != null)
              {
                  validateInstanceDefinition("core", emrClusterDefinition.getInstanceDefinitions().getCoreInstances(), 0);
                  // If instance count is <= 0, remove the entire core instance definition since it is redundant.
                  if (emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceCount() <= 0)
                  {
                      emrClusterDefinition.getInstanceDefinitions().setCoreInstances(null);
                  }
              }
  
              // Check task instances
              if (emrClusterDefinition.getInstanceDefinitions().getTaskInstances() != null)
              {
                  validateInstanceDefinition("task", emrClusterDefinition.getInstanceDefinitions().getTaskInstances(), 1);
              }
  
              // Check that total number of instances does not exceed the max allowed.
              int maxEmrInstanceCount = configurationHelper.getProperty(ConfigurationValue.MAX_EMR_INSTANCES_COUNT, Integer.class);
              if (maxEmrInstanceCount > 0)
              {
                  int instancesRequested = emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceCount();
                  if (emrClusterDefinition.getInstanceDefinitions().getCoreInstances() != null)
                  {
                      instancesRequested += emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceCount();
                  }
                  if (emrClusterDefinition.getInstanceDefinitions().getTaskInstances() != null)
                  {
                      instancesRequested += emrClusterDefinition.getInstanceDefinitions().getTaskInstances().getInstanceCount();
                  }
  
                  Assert.isTrue((maxEmrInstanceCount >= instancesRequested), "Total number of instances requested can not exceed : " + maxEmrInstanceCount);
              }
          }
  
          // Make sure instance fleet minimum ip available filter is non-negative
          if (emrClusterDefinition.getInstanceFleetMinimumIpAvailableFilter() != null)
          {
              Assert.isTrue(emrClusterDefinition.getInstanceFleetMinimumIpAvailableFilter() >= 0,
                      "Minimum number of available IPs required for the instance fleet must be non-negative");
          }
  
          // Validate node tags including checking for required tags and detecting any duplicate node tag names in case sensitive manner.
          Assert.notEmpty(emrClusterDefinition.getNodeTags(), "Node tags must be specified.");
          HashSet<String> nodeTagNameValidationSet = new HashSet<>();
          for (NodeTag nodeTag : emrClusterDefinition.getNodeTags())
          {
              Assert.hasText(nodeTag.getTagName(), "A node tag name must be specified.");
              Assert.hasText(nodeTag.getTagValue(), "A node tag value must be specified.");
              Assert.isTrue(!nodeTagNameValidationSet.contains(nodeTag.getTagName()), String.format("Duplicate node tag \"%s\" is found.", nodeTag.getTagName()));
              nodeTagNameValidationSet.add(nodeTag.getTagName());
          }
  
          // Validate the mandatory AWS tags are there
          for (String mandatoryTag : herdStringHelper.splitStringWithDefaultDelimiter(configurationHelper.getProperty(ConfigurationValue.MANDATORY_AWS_TAGS)))
          {
              Assert.isTrue(nodeTagNameValidationSet.contains(mandatoryTag), String.format("Mandatory AWS tag not specified: \"%s\"", mandatoryTag));
          }
  
          emrClusterDefinition.setAdditionalMasterSecurityGroups(
              assertNotBlankAndTrim(emrClusterDefinition.getAdditionalMasterSecurityGroups(), "additionalMasterSecurityGroup"));
  
          emrClusterDefinition
              .setAdditionalSlaveSecurityGroups(assertNotBlankAndTrim(emrClusterDefinition.getAdditionalSlaveSecurityGroups(), "additionalSlaveSecurityGroup"));
  
          // Fail if security configuration is specified for EMR version less than 4.8.0.
          if (StringUtils.isNotBlank(emrClusterDefinition.getSecurityConfiguration()))
          {
              final DefaultArtifactVersion securityConfigurationMinEmrVersion = new DefaultArtifactVersion("4.8.0");
              Assert.isTrue(StringUtils.isNotBlank(emrClusterDefinition.getReleaseLabel()) &&
                  securityConfigurationMinEmrVersion.compareTo(new DefaultArtifactVersion(emrClusterDefinition.getReleaseLabel().replaceFirst("^(emr-)", ""))) <=
                      0, "EMR security configuration is not supported prior to EMR release 4.8.0.");
          }
      }
focal_method.class_method_signature: EmrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(EmrClusterDefinition emrClusterDefinition)
focal_method.full_signature: public void validateEmrClusterDefinitionConfiguration(EmrClusterDefinition emrClusterDefinition)
focal_method.identifier: validateEmrClusterDefinitionConfiguration
focal_method.invocations: notNull isTrue isNotBlank getSubnetId split getSubnetId isTrue isNotBlank isTrue isInstanceDefinitionsEmpty getInstanceDefinitions isNotEmpty getInstanceFleets isInstanceDefinitionsEmpty getInstanceDefinitions notNull getMasterInstances getInstanceDefinitions validateMasterInstanceDefinition getMasterInstances getInstanceDefinitions getCoreInstances getInstanceDefinitions validateInstanceDefinition getCoreInstances getInstanceDefinitions getInstanceCount getCoreInstances getInstanceDefinitions setCoreInstances getInstanceDefinitions getTaskInstances getInstanceDefinitions validateInstanceDefinition getTaskInstances getInstanceDefinitions getProperty getInstanceCount getMasterInstances getInstanceDefinitions getCoreInstances getInstanceDefinitions getInstanceCount getCoreInstances getInstanceDefinitions getTaskInstances getInstanceDefinitions getInstanceCount getTaskInstances getInstanceDefinitions isTrue getInstanceFleetMinimumIpAvailableFilter isTrue getInstanceFleetMinimumIpAvailableFilter notEmpty getNodeTags getNodeTags hasText getTagName hasText getTagValue isTrue contains getTagName format getTagName add getTagName splitStringWithDefaultDelimiter getProperty isTrue contains format setAdditionalMasterSecurityGroups assertNotBlankAndTrim getAdditionalMasterSecurityGroups setAdditionalSlaveSecurityGroups assertNotBlankAndTrim getAdditionalSlaveSecurityGroups isNotBlank getSecurityConfiguration isTrue isNotBlank getReleaseLabel compareTo replaceFirst getReleaseLabel
focal_method.modifiers: public
focal_method.parameters: (EmrClusterDefinition emrClusterDefinition)
focal_method.return: void
focal_method.signature: void validateEmrClusterDefinitionConfiguration(EmrClusterDefinition emrClusterDefinition)