/** * Returns {@code true} if the supplied InstanceDefinitions is {@code null} or empty (contains no elements). * * @param instanceDefinitions the instance group definitions from the EMR cluster definition * * @return whether the given InstanceDefinitions is empty */ public boolean isInstanceDefinitionsEmpty(InstanceDefinitions instanceDefinitions) { return (instanceDefinitions == null || (instanceDefinitions.getMasterInstances() == null && instanceDefinitions.getCoreInstances() == null && instanceDefinitions.getTaskInstances() == null)); }
/** * Returns {@code true} if the supplied InstanceDefinitions is {@code null} or empty (contains no elements). * * @param instanceDefinitions the instance group definitions from the EMR cluster definition * * @return whether the given InstanceDefinitions is empty */ public boolean isInstanceDefinitionsEmpty(InstanceDefinitions instanceDefinitions) { return (instanceDefinitions == null || (instanceDefinitions.getMasterInstances() == null && instanceDefinitions.getCoreInstances() == null && instanceDefinitions.getTaskInstances() == null)); }
/** * Returns the core instance definition. * * @param emrClusterDefinition the EMR cluster definition * * @return the core instance definition */ private InstanceDefinition getCoreInstanceDefinition(EmrClusterDefinition emrClusterDefinition) { InstanceDefinition coreInstances = emrClusterDefinition.getInstanceDefinitions().getCoreInstances(); if (coreInstances != null && coreInstances.getInstanceCount() <= 0) { coreInstances = null; } return coreInstances; }
/** * Returns the core instance definition. * * @param emrClusterDefinition the EMR cluster definition * * @return the core instance definition */ private InstanceDefinition getCoreInstanceDefinition(EmrClusterDefinition emrClusterDefinition) { InstanceDefinition coreInstances = emrClusterDefinition.getInstanceDefinitions().getCoreInstances(); if (coreInstances != null && coreInstances.getInstanceCount() <= 0) { coreInstances = null; } return coreInstances; }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { MasterInstanceDefinition theMasterInstances; theMasterInstances = this.getMasterInstances(); strategy.appendField(locator, this, "masterInstances", buffer, theMasterInstances, (this.masterInstances!= null)); } { InstanceDefinition theCoreInstances; theCoreInstances = this.getCoreInstances(); strategy.appendField(locator, this, "coreInstances", buffer, theCoreInstances, (this.coreInstances!= null)); } { InstanceDefinition theTaskInstances; theTaskInstances = this.getTaskInstances(); strategy.appendField(locator, this, "taskInstances", buffer, theTaskInstances, (this.taskInstances!= null)); } return buffer; }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { MasterInstanceDefinition theMasterInstances; theMasterInstances = this.getMasterInstances(); strategy.appendField(locator, this, "masterInstances", buffer, theMasterInstances, (this.masterInstances!= null)); } { InstanceDefinition theCoreInstances; theCoreInstances = this.getCoreInstances(); strategy.appendField(locator, this, "coreInstances", buffer, theCoreInstances, (this.coreInstances!= null)); } { InstanceDefinition theTaskInstances; theTaskInstances = this.getTaskInstances(); strategy.appendField(locator, this, "taskInstances", buffer, theTaskInstances, (this.taskInstances!= null)); } return buffer; }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { MasterInstanceDefinition theMasterInstances; theMasterInstances = this.getMasterInstances(); strategy.appendField(locator, this, "masterInstances", buffer, theMasterInstances, (this.masterInstances!= null)); } { InstanceDefinition theCoreInstances; theCoreInstances = this.getCoreInstances(); strategy.appendField(locator, this, "coreInstances", buffer, theCoreInstances, (this.coreInstances!= null)); } { InstanceDefinition theTaskInstances; theTaskInstances = this.getTaskInstances(); strategy.appendField(locator, this, "taskInstances", buffer, theTaskInstances, (this.taskInstances!= null)); } return buffer; }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { MasterInstanceDefinition theMasterInstances; theMasterInstances = this.getMasterInstances(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "masterInstances", theMasterInstances), currentHashCode, theMasterInstances, (this.masterInstances!= null)); } { InstanceDefinition theCoreInstances; theCoreInstances = this.getCoreInstances(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "coreInstances", theCoreInstances), currentHashCode, theCoreInstances, (this.coreInstances!= null)); } { InstanceDefinition theTaskInstances; theTaskInstances = this.getTaskInstances(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "taskInstances", theTaskInstances), currentHashCode, theTaskInstances, (this.taskInstances!= null)); } return currentHashCode; }
/** * Updates the given definition with the given subnet and EMR pricing information. * <p/> * Sets the subnet with the given subnet ID. Removes any maxSearchPrice and onDemandThreshold that were set. Sets the spotPrice only if the given cluster * price is a spot. * * @param emrClusterDefinition the definition to update * @param bestEmrClusterSubnet the subnet to use * @param bestEmrClusterPrice the EMR pricing information for each instance */ private void updateInstanceDefinitionsWithBestPrice(EmrClusterDefinition emrClusterDefinition, Subnet bestEmrClusterSubnet, EmrClusterPriceDto bestEmrClusterPrice) { emrClusterDefinition.setSubnetId(bestEmrClusterSubnet.getSubnetId()); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceMaxSearchPrice(null); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceOnDemandThreshold(null); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceSpotPrice(getSpotBidPrice(bestEmrClusterPrice.getMasterPrice())); if (bestEmrClusterPrice.getCorePrice() != null) { emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceMaxSearchPrice(null); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceOnDemandThreshold(null); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceSpotPrice(getSpotBidPrice(bestEmrClusterPrice.getCorePrice())); } }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { MasterInstanceDefinition theMasterInstances; theMasterInstances = this.getMasterInstances(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "masterInstances", theMasterInstances), currentHashCode, theMasterInstances, (this.masterInstances!= null)); } { InstanceDefinition theCoreInstances; theCoreInstances = this.getCoreInstances(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "coreInstances", theCoreInstances), currentHashCode, theCoreInstances, (this.coreInstances!= null)); } { InstanceDefinition theTaskInstances; theTaskInstances = this.getTaskInstances(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "taskInstances", theTaskInstances), currentHashCode, theTaskInstances, (this.taskInstances!= null)); } return currentHashCode; }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { MasterInstanceDefinition theMasterInstances; theMasterInstances = this.getMasterInstances(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "masterInstances", theMasterInstances), currentHashCode, theMasterInstances, (this.masterInstances!= null)); } { InstanceDefinition theCoreInstances; theCoreInstances = this.getCoreInstances(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "coreInstances", theCoreInstances), currentHashCode, theCoreInstances, (this.coreInstances!= null)); } { InstanceDefinition theTaskInstances; theTaskInstances = this.getTaskInstances(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "taskInstances", theTaskInstances), currentHashCode, theTaskInstances, (this.taskInstances!= null)); } return currentHashCode; }
/** * Updates the given definition with the given subnet and EMR pricing information. * <p/> * Sets the subnet with the given subnet ID. Removes any maxSearchPrice and onDemandThreshold that were set. Sets the spotPrice only if the given cluster * price is a spot. * * @param emrClusterDefinition the definition to update * @param bestEmrClusterSubnet the subnet to use * @param bestEmrClusterPrice the EMR pricing information for each instance */ private void updateInstanceDefinitionsWithBestPrice(EmrClusterDefinition emrClusterDefinition, Subnet bestEmrClusterSubnet, EmrClusterPriceDto bestEmrClusterPrice) { emrClusterDefinition.setSubnetId(bestEmrClusterSubnet.getSubnetId()); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceMaxSearchPrice(null); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceOnDemandThreshold(null); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceSpotPrice(getSpotBidPrice(bestEmrClusterPrice.getMasterPrice())); if (bestEmrClusterPrice.getCorePrice() != null) { emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceMaxSearchPrice(null); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceOnDemandThreshold(null); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceSpotPrice(getSpotBidPrice(bestEmrClusterPrice.getCorePrice())); } }
@Test public void testCreateEmrClusterOverrideExistingCoreInstanceTo0InstanceCountAssertSuccess() throws Exception { // Create the namespace entity. NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); String definitionXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()); EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, definitionXml); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceCount(1); emrClusterDefinitionDaoTestHelper .createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, xmlHelper.objectToXml(emrClusterDefinition)); // Create a new EMR cluster create request EmrClusterCreateRequest request = getNewEmrClusterCreateRequest(); EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition(); emrClusterDefinitionOverride.setInstanceDefinitions(emrClusterDefinition.getInstanceDefinitions()); emrClusterDefinitionOverride.getInstanceDefinitions().getCoreInstances().setInstanceCount(0); request.setEmrClusterDefinitionOverride(emrClusterDefinitionOverride); EmrCluster emrClusterCreateResponse = emrService.createCluster(request); assertNull(emrClusterCreateResponse.getEmrClusterDefinition().getInstanceDefinitions().getCoreInstances()); }
@Test public void testValidateEmrClusterDefinitionConfigurationCoreInstanceSpecifiedInstanceCountNegative() { EmrClusterDefinition emrClusterDefinition = createValidEmrClusterDefinition(); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceCount(-1); try { emrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(emrClusterDefinition); fail(); } catch (IllegalArgumentException e) { assertEquals("At least 0 core instance must be specified.", e.getMessage()); } }
@Test public void testCreateEmrClusterOverrideExistingCoreInstanceToNegativeInstanceCountAssertException() throws Exception { // Create the namespace entity. NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); String definitionXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()); EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, definitionXml); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceCount(1); emrClusterDefinitionDaoTestHelper .createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, xmlHelper.objectToXml(emrClusterDefinition)); // Create a new EMR cluster create request EmrClusterCreateRequest request = getNewEmrClusterCreateRequest(); EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition(); emrClusterDefinitionOverride.setInstanceDefinitions(emrClusterDefinition.getInstanceDefinitions()); emrClusterDefinitionOverride.getInstanceDefinitions().getCoreInstances().setInstanceCount(-1); request.setEmrClusterDefinitionOverride(emrClusterDefinitionOverride); try { emrService.createCluster(request); fail(); } catch (IllegalArgumentException e) { assertEquals("At least 0 core instance must be specified.", e.getMessage()); } }
@Test public void testCreateEmrClusterOverrideExistingCoreInstanceToNullAssertSuccess() throws Exception { // Create the namespace entity. NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); String definitionXml = IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()); EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, definitionXml); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceCount(1); emrClusterDefinitionDaoTestHelper .createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, xmlHelper.objectToXml(emrClusterDefinition)); // Create a new EMR cluster create request EmrClusterCreateRequest request = getNewEmrClusterCreateRequest(); EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition(); emrClusterDefinitionOverride.setInstanceDefinitions(emrClusterDefinition.getInstanceDefinitions()); emrClusterDefinitionOverride.getInstanceDefinitions().setCoreInstances(null); request.setEmrClusterDefinitionOverride(emrClusterDefinitionOverride); EmrCluster emrClusterCreateResponse = emrService.createCluster(request); assertNull(emrClusterCreateResponse.getEmrClusterDefinition().getInstanceDefinitions().getCoreInstances()); }
/** * Asserts that when 0 is specified for core instance count, no validation exception is thrown. */ @Test public void testCreateEmrClusterDefinitionCoreInstanceCount0AssertResponseCoreInstanceDefinitionIsNull() throws Exception { // Create and persist the namespace entity. namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE); // Create an EMR cluster definition create request. EmrClusterDefinitionCreateRequest request = createEmrClusterDefinitionCreateRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, getTestEmrClusterDefinitionConfiguration(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH)); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(0, "m1.medium", NO_EMR_CLUSTER_DEFINITION_EBS_CONFIGURATION, NO_INSTANCE_SPOT_PRICE, NO_INSTANCE_MAX_SEARCH_PRICE, NO_INSTANCE_ON_DEMAND_THRESHOLD); request.getEmrClusterDefinition().getInstanceDefinitions().setCoreInstances(coreInstanceDefinition); // Create an EMR cluster definition. EmrClusterDefinitionInformation emrClusterDefinitionInformation = emrClusterDefinitionService.createEmrClusterDefinition(request); assertNull(emrClusterDefinitionInformation.getEmrClusterDefinition().getInstanceDefinitions().getCoreInstances()); }
/** * The definition will have it's best price search criteria information removed after being updated by the algorithm. This method asserts that is the case. * The task instance information is optional. Task instances will only be validated if it was given in the original definition. * * @param emrClusterDefinition - The definition updated by the algorithm */ private void assertBestPriceCriteriaRemoved(EmrClusterDefinition emrClusterDefinition) { assertNull("master instance max search price was not removed", emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceMaxSearchPrice()); assertNull("master instance on-demand threshold was not removed", emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceOnDemandThreshold()); assertNull("core instance max search price was not removed", emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceMaxSearchPrice()); assertNull("core instance on-demand threshold was not removed", emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceOnDemandThreshold()); if (emrClusterDefinition.getInstanceDefinitions().getTaskInstances() != null) { assertNull("task instance max search price was not removed", emrClusterDefinition.getInstanceDefinitions().getTaskInstances().getInstanceMaxSearchPrice()); assertNull("task instance on-demand threshold was not removed", emrClusterDefinition.getInstanceDefinitions().getTaskInstances().getInstanceOnDemandThreshold()); } }
/** * Test cases where user sets instances to explicitly use spot for master and on-demand for core by setting the instanceSpotPrice property and not * specifying criteria, respectively. */ @Test public void testBestPriceExplicitSpotAndOnDemand() { String subnetId = SUBNET_1; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); masterInstanceDefinition.setInstanceSpotPrice(ON_DEMAND); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(1); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); InstanceDefinition taskInstanceDefinition = null; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertEquals("master instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice()); assertNull("core instance was not on-demand", emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice()); }
/** * Tests algorithmic case when the max search price equals to on-demand price and spot price is not available. Master should pick on-demand because spot is * not available and max >= on-demand. Core spot > on-demand, max search price = spot - Core should pick on-demand since on-demand is cheaper. */ @Test public void testBestPriceAlgorithmicMaxSearchPriceEqualsToOnDemandAndSpotPriceNotAvailable() { String subnetId = SUBNET_1; // For master instance definition, use instance type that does not have spot price available. MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_4); masterInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(1); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_3); coreInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND); InstanceDefinition taskInstanceDefinition = null; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertNull("master instance was not on-demand", emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice()); assertNull("core instance was not on-demand", emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice()); }