/** * Returns list of EmrClusterInstanceTypeConfiguration * * @param configurations AWS configuration object list * * @return list of EmrClusterInstanceTypeConfiguration */ protected List<EmrClusterInstanceTypeConfiguration> getConfigurations(List<Configuration> configurations) { List<EmrClusterInstanceTypeConfiguration> emrClusterInstanceTypeConfigurations = null; if (!CollectionUtils.isEmpty(configurations)) { emrClusterInstanceTypeConfigurations = new ArrayList<>(); for (Configuration configuration : configurations) { if (configuration != null) { EmrClusterInstanceTypeConfiguration emrClusterInstanceTypeConfiguration = new EmrClusterInstanceTypeConfiguration(); emrClusterInstanceTypeConfiguration.setClassification(configuration.getClassification()); emrClusterInstanceTypeConfiguration.setConfigurations(getConfigurations(configuration.getConfigurations())); emrClusterInstanceTypeConfiguration.setProperties(getParameterList(configuration.getProperties())); emrClusterInstanceTypeConfigurations.add(emrClusterInstanceTypeConfiguration); } } } return emrClusterInstanceTypeConfigurations; }
/** * Converts the given list of {@link EmrClusterDefinitionConfiguration} into a list of {@link Configuration}. * * @param emrClusterDefinitionConfigurations list of {@link EmrClusterDefinitionConfiguration} * * @return list of {@link Configuration} */ protected List<Configuration> getConfigurations(List<EmrClusterDefinitionConfiguration> emrClusterDefinitionConfigurations) { List<Configuration> configurations = null; if (!CollectionUtils.isEmpty(emrClusterDefinitionConfigurations)) { configurations = new ArrayList<>(); for (EmrClusterDefinitionConfiguration emrClusterDefinitionConfiguration : emrClusterDefinitionConfigurations) { if (emrClusterDefinitionConfiguration != null) { Configuration configuration = new Configuration(); configuration.setClassification(emrClusterDefinitionConfiguration.getClassification()); configuration.setConfigurations(getConfigurations(emrClusterDefinitionConfiguration.getConfigurations())); configuration.setProperties(getMap(emrClusterDefinitionConfiguration.getProperties())); configurations.add(configuration); } } } return configurations; }
@Test public void testGetConfigurations() { // Create objects required for testing. final String classification = STRING_VALUE; final List<EmrClusterDefinitionConfiguration> emrClusterDefinitionConfigurations = null; final List<Parameter> properties = null; final EmrClusterDefinitionConfiguration emrClusterDefinitionConfiguration = new EmrClusterDefinitionConfiguration(classification, emrClusterDefinitionConfigurations, properties); // Call the method under test. List<Configuration> result = emrDaoImpl.getConfigurations(Arrays.asList(emrClusterDefinitionConfiguration)); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. final List<Configuration> expectedConfigurations = null; assertEquals(Arrays.asList(new Configuration().withClassification(classification).withConfigurations(expectedConfigurations).withProperties(null)), result); }
@Test public void testGetConfigurationsWhenInputListContainsNullElement() { // Create objects required for testing with a list of emrClusterDefinitionConfigurations having a null element. List<EmrClusterDefinitionConfiguration> emrClusterDefinitionConfigurations = new ArrayList<>(); emrClusterDefinitionConfigurations.add(null); // Call the method under test. List<Configuration> result = emrDaoImpl.getConfigurations(emrClusterDefinitionConfigurations); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(new ArrayList<>(), result); }
@Test public void testGetInstanceTypeConfigs() { // Create objects required for testing. final String instanceType = STRING_VALUE; final Integer weightedCapacity = INTEGER_VALUE; final String bidPrice = STRING_VALUE_2; final Double bidPriceAsPercentageOfOnDemandPrice = DOUBLE_VALUE; final EmrClusterDefinitionEbsConfiguration emrClusterDefinitionEbsConfiguration = null; final List<EmrClusterDefinitionConfiguration> emrClusterDefinitionConfigurations = null; final EmrClusterDefinitionInstanceTypeConfig emrClusterDefinitionInstanceTypeConfig = new EmrClusterDefinitionInstanceTypeConfig(instanceType, weightedCapacity, bidPrice, bidPriceAsPercentageOfOnDemandPrice, emrClusterDefinitionEbsConfiguration, emrClusterDefinitionConfigurations); // Call the method under test. List<InstanceTypeConfig> result = emrDaoImpl.getInstanceTypeConfigs(Arrays.asList(emrClusterDefinitionInstanceTypeConfig)); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. final List<Configuration> expectedConfigurations = null; assertEquals(Arrays.asList(new InstanceTypeConfig().withInstanceType(instanceType).withWeightedCapacity(weightedCapacity).withBidPrice(bidPrice) .withBidPriceAsPercentageOfOnDemandPrice(bidPriceAsPercentageOfOnDemandPrice).withEbsConfiguration(null) .withConfigurations(expectedConfigurations)), result); }
@Test public void testGetConfigurationsWhenInputListIsEmpty() { // Call the method under test. List<Configuration> result = emrDaoImpl.getConfigurations(new ArrayList<>()); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertNull(result); }
private List<Configuration> configurations(JsonNode node) { if (node.isTextual()) { // File String configurationJson; try { configurationJson = workspace.templateFile(templateEngine, node.asText(), UTF_8, params); } catch (IOException | TemplateException e) { throw new TaskExecutionException(e); } List<ConfigurationJson> values; try { values = objectMapper.readValue(configurationJson, new TypeReference<List<ConfigurationJson>>() {}); } catch (IOException e) { throw new ConfigException("Invalid EMR configuration file: " + node.asText()); } return values.stream() .map(ConfigurationJson::toConfiguration) .collect(toList()); } else if (node.isObject()) { // Embedded configuration Config config = cf.create(node); return ImmutableList.of(new Configuration() .withConfigurations(config.getListOrEmpty("configurations", JsonNode.class).stream() .map(this::configurations) .flatMap(Collection::stream) .collect(toList())) .withClassification(config.get("classification", String.class, null)) .withProperties(config.get("properties", new TypeReference<Map<String, String>>() {}, null))); }
default Configuration toConfiguration() { return new Configuration() .withClassification(classification().orNull()) .withConfigurations(configurations().stream() .map(ConfigurationJson::toConfiguration) .collect(toList())) .withProperties(properties()); }
Configuration toAwsConfig() { Configuration config = new Configuration().withClassification(classification).withProperties(properties); List<Configuration> subConfigs = new ArrayList<>(); for (EmrConfig conf : configs){ subConfigs.add(conf.toAwsConfig()); } return config.withConfigurations(subConfigs); }