Search in sources :

Example 61 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class BusinessObjectDataServiceGenerateBusinessObjectDataDdlTest method testGenerateBusinessObjectDataDdlInvalidParameters.

@Test
public void testGenerateBusinessObjectDataDdlInvalidParameters() {
    // Prepare test data.
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataDdlTesting();
    BusinessObjectDataDdlRequest request;
    // Try to retrieve business object data ddl using non-existing format.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(UNSORTED_PARTITION_VALUES, CUSTOM_DDL_NAME);
    request.setBusinessObjectDefinitionName("I_DO_NOT_EXIST");
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an ObjectNotFoundException when non-existing business object format is used.");
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage(request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()), e.getMessage());
    }
    // Try to retrieve business object data ddl using non-existing partition key (partition column).
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(UNSORTED_PARTITION_VALUES, CUSTOM_DDL_NAME);
    request.getPartitionValueFilters().get(0).setPartitionKey("I_DO_NOT_EXIST");
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when non-existing partition key is used.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("The partition key \"%s\" does not exist in first %d partition columns in the schema for business object format " + "{namespace: \"%s\", businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", businessObjectFormatFileType: \"%s\", " + "businessObjectFormatVersion: %d}.", request.getPartitionValueFilters().get(0).getPartitionKey(), BusinessObjectDataEntity.MAX_SUBPARTITIONS + 1, request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()), e.getMessage());
    }
    // Try to retrieve business object data ddl when both partition value filter and partition value filter list are specified.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(UNSORTED_PARTITION_VALUES, CUSTOM_DDL_NAME);
    request.setPartitionValueFilter(new PartitionValueFilter(FIRST_PARTITION_COLUMN_NAME.toUpperCase(), new ArrayList<>(UNSORTED_PARTITION_VALUES), NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE));
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when both a list of partition value filters and a standalone partition value filter are specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A list of partition value filters and a standalone partition value filter cannot be both specified.", e.getMessage());
    }
    // Try to retrieve business object data ddl when partition value filter has none or more than one partition value filter option specified.
    for (PartitionValueFilter partitionValueFilter : businessObjectDataServiceTestHelper.getInvalidPartitionValueFilters()) {
        request = new BusinessObjectDataDdlRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, FORMAT_VERSION, Arrays.asList(partitionValueFilter), NO_STANDALONE_PARTITION_VALUE_FILTER, DATA_VERSION, NO_STORAGE_NAMES, STORAGE_NAME, BusinessObjectDataDdlOutputFormatEnum.HIVE_13_DDL, TABLE_NAME, NO_CUSTOM_DDL_NAME, INCLUDE_DROP_TABLE_STATEMENT, INCLUDE_IF_NOT_EXISTS_OPTION, NO_INCLUDE_DROP_PARTITIONS, NO_ALLOW_MISSING_DATA, NO_INCLUDE_ALL_REGISTERED_SUBPARTITIONS, NO_SUPPRESS_SCAN_FOR_UNREGISTERED_SUBPARTITIONS);
        try {
            businessObjectDataService.generateBusinessObjectDataDdl(request);
            fail("Should throw an IllegalArgumentException when partition value filter has more than one partition value filter option.");
        } catch (IllegalArgumentException e) {
            assertEquals("Exactly one partition value filter option must be specified.", e.getMessage());
        }
    }
    // Try to retrieve business object data ddl when partition value token is specified with a partition value range.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(BusinessObjectDataService.MAX_PARTITION_VALUE_TOKEN, END_PARTITION_VALUE);
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when partition value token is specified with a partition value range.");
    } catch (IllegalArgumentException e) {
        assertEquals("A partition value token cannot be specified with a partition value range.", e.getMessage());
    }
    // Try to retrieve business object data ddl when partition value token is specified with a partition value range.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(BusinessObjectDataService.MIN_PARTITION_VALUE_TOKEN, END_PARTITION_VALUE);
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when partition value token is specified with a partition value range.");
    } catch (IllegalArgumentException e) {
        assertEquals("A partition value token cannot be specified with a partition value range.", e.getMessage());
    }
    // Try to retrieve business object data ddl when partition value token is specified with a partition value range.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(START_PARTITION_VALUE, BusinessObjectDataService.MAX_PARTITION_VALUE_TOKEN);
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when partition value token is specified with a partition value range.");
    } catch (IllegalArgumentException e) {
        assertEquals("A partition value token cannot be specified with a partition value range.", e.getMessage());
    }
    // Try to retrieve business object data ddl when partition value token is specified with a partition value range.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(END_PARTITION_VALUE, BusinessObjectDataService.MIN_PARTITION_VALUE_TOKEN);
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when partition value token is specified with a partition value range.");
    } catch (IllegalArgumentException e) {
        assertEquals("A partition value token cannot be specified with a partition value range.", e.getMessage());
    }
    // Try to retrieve business object data ddl when partition value filter has start partition value which is greater than the end partition value.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(END_PARTITION_VALUE, START_PARTITION_VALUE, CUSTOM_DDL_NAME);
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when start partition value which is greater than the end partition value.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("The start partition value \"%s\" cannot be greater than the end partition value \"%s\".", END_PARTITION_VALUE, START_PARTITION_VALUE), e.getMessage());
    }
    // Try to retrieve business object data ddl when partition value filter has specifies a range that results in no valid partition values.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest("I_DO_NOT_EXIST_1", "I_DO_NOT_EXIST_2", null, CUSTOM_DDL_NAME);
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when partition value filter has specifies a range that results in no valid partition values.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Partition value range [\"%s\", \"%s\"] contains no valid partition values in partition key group \"%s\". " + "Business object format: {%s}", request.getPartitionValueFilters().get(0).getPartitionValueRange().getStartPartitionValue(), request.getPartitionValueFilters().get(0).getPartitionValueRange().getEndPartitionValue(), PARTITION_KEY_GROUP, businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatKeyAsString(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, FORMAT_VERSION)), e.getMessage());
    }
    // Try to retrieve business object data ddl when partition value filter has specifies a range that results in no valid partition values.
    String invalidPartitionValue = "INVALID_PARTITION_VALUE_/";
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(Arrays.asList(invalidPartitionValue), CUSTOM_DDL_NAME);
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when partition value contains a '/' character.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Partition value \"%s\" can not contain a '/' character.", request.getPartitionValueFilters().get(0).getPartitionValues().get(0)), e.getMessage());
    }
    // Try to retrieve business object data ddl when partition value token is specified as a partition value.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(Arrays.asList(BusinessObjectDataService.MAX_PARTITION_VALUE_TOKEN), CUSTOM_DDL_NAME);
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when partition value token is specified as a partition value.");
    } catch (IllegalArgumentException e) {
        assertEquals("A partition value token cannot be specified as one of partition values.", e.getMessage());
    }
    // Try to retrieve business object data ddl when partition value token is specified as a partition value.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(Arrays.asList(BusinessObjectDataService.MIN_PARTITION_VALUE_TOKEN), CUSTOM_DDL_NAME);
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when partition value token is specified as a partition value.");
    } catch (IllegalArgumentException e) {
        assertEquals("A partition value token cannot be specified as one of partition values.", e.getMessage());
    }
    // Try to retrieve business object data ddl when both a list of storage names and standalone storage name are specified.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(UNSORTED_PARTITION_VALUES);
    request.setStorageName(BLANK_TEXT);
    request.setStorageNames(STORAGE_NAMES);
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an IllegalArgumentException when both a list of storage names and standalone storage name are specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A list of storage names and a standalone storage name cannot be both specified.", e.getMessage());
    }
    // Try to retrieve business object data ddl passing a non-existing storage as a standalone storage name.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(UNSORTED_PARTITION_VALUES, CUSTOM_DDL_NAME);
    request.setStorageName("I_DO_NOT_EXIST");
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an ObjectNotFoundException when non-existing storage is used as a standalone storage name.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Storage with name \"%s\" doesn't exist.", request.getStorageName()), e.getMessage());
    }
    // Try to retrieve business object data ddl passing a non-existing storage in the list of storage names.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(UNSORTED_PARTITION_VALUES);
    request.setStorageName(null);
    request.setStorageNames(Arrays.asList("I_DO_NOT_EXIST"));
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an ObjectNotFoundException when non-existing storage is used in the list of storage names.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Storage with name \"%s\" doesn't exist.", request.getStorageNames().get(0)), e.getMessage());
    }
    // Try to retrieve business object data ddl using non-existing custom ddl.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(UNSORTED_PARTITION_VALUES, CUSTOM_DDL_NAME);
    request.setCustomDdlName("I_DO_NOT_EXIST");
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(request);
        fail("Should throw an ObjectNotFoundException when non-existing custom ddl is used.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Custom DDL with name \"%s\" does not exist for business object format with namespace \"%s\", " + "business object definition name \"%s\", format usage \"%s\", format file type \"%s\", and format version \"%d\".", request.getCustomDdlName(), request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()), e.getMessage());
    }
}
Also used : BusinessObjectDataDdlRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) ArrayList(java.util.ArrayList) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) Test(org.junit.Test)

Example 62 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class BusinessObjectDataServiceGenerateBusinessObjectDataDdlTest method testGenerateBusinessObjectDataDdlLatestAfterPartitionValueNoExists.

@Test
public void testGenerateBusinessObjectDataDdlLatestAfterPartitionValueNoExists() {
    // Prepare database entities required for testing.
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataDdlTesting(PARTITION_VALUE);
    // Try retrieve business object data ddl using a latest before partition value filter option when the latest partition value does not exist.
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(new BusinessObjectDataDdlRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(FIRST_PARTITION_COLUMN_NAME, NO_PARTITION_VALUES, NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, new LatestAfterPartitionValue(PARTITION_VALUE_2))), NO_STANDALONE_PARTITION_VALUE_FILTER, DATA_VERSION, NO_STORAGE_NAMES, STORAGE_NAME, BusinessObjectDataDdlOutputFormatEnum.HIVE_13_DDL, TABLE_NAME, NO_CUSTOM_DDL_NAME, INCLUDE_DROP_TABLE_STATEMENT, INCLUDE_IF_NOT_EXISTS_OPTION, NO_INCLUDE_DROP_PARTITIONS, NO_ALLOW_MISSING_DATA, NO_INCLUDE_ALL_REGISTERED_SUBPARTITIONS, NO_SUPPRESS_SCAN_FOR_UNREGISTERED_SUBPARTITIONS));
        fail("Suppose to throw an ObjectNotFoundException when failed to find the latest after partition value.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Failed to find partition value which is the latest after partition value = \"%s\" " + "for partition key = \"%s\" due to no available business object data " + "in \"%s\" storage that satisfies the search criteria. Business object data {namespace: \"%s\", " + "businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", businessObjectFormatFileType: \"%s\", " + "businessObjectFormatVersion: %d, businessObjectDataVersion: %d}", PARTITION_VALUE_2, FIRST_PARTITION_COLUMN_NAME, STORAGE_NAME, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, FORMAT_VERSION, DATA_VERSION), e.getMessage());
    }
}
Also used : BusinessObjectDataDdlRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) LatestAfterPartitionValue(org.finra.herd.model.api.xml.LatestAfterPartitionValue) Test(org.junit.Test)

Example 63 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class Ec2DaoImpl method getSubnets.

/**
 * This implementation uses the DescribeSubnets API.
 */
@Override
public List<Subnet> getSubnets(Collection<String> subnetIds, AwsParamsDto awsParamsDto) {
    AmazonEC2Client ec2Client = getEc2Client(awsParamsDto);
    DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();
    describeSubnetsRequest.setSubnetIds(subnetIds);
    try {
        DescribeSubnetsResult describeSubnetsResult = ec2Operations.describeSubnets(ec2Client, describeSubnetsRequest);
        return describeSubnetsResult.getSubnets();
    } catch (AmazonServiceException amazonServiceException) {
        /*
             * AWS throws a 400 error when any one of the specified subnet ID is not found.
             * We want to catch it and throw as an handled herd error as a 404 not found.
             */
        if (ERROR_CODE_SUBNET_ID_NOT_FOUND.equals(amazonServiceException.getErrorCode())) {
            throw new ObjectNotFoundException(amazonServiceException.getErrorMessage(), amazonServiceException);
        } else // Any other type of error we throw as is because they are unexpected.
        {
            throw amazonServiceException;
        }
    }
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest)

Example 64 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class EmrPricingHelper method updateEmrClusterDefinitionWithBestPrice.

/**
 * Finds the best price for each master and core instances based on the subnets and master and core instance search parameters given in the definition.
 * <p/>
 * The results of the findings are used to update the given definition.
 * <p/>
 * If the instance's instanceSpotPrice is set, the instance definition will keep that value. If the instance's instanceMaxSearchPrice is set, the best price
 * will be found. If the found price is spot, the instanceSpotPrice will be set to the value of instanceMaxSearchPrice. If the found price is on-demand, the
 * instanceSpotPrice will be removed. The definition's subnetId will be set to the particular subnet which the best price is found. The value will always be
 * replaced by a single subnet ID.
 * <p/>
 * The definition's instanceMaxSearchPrice and instanceOnDemandThreshold will be removed by this operation.
 *
 * @param emrClusterAlternateKeyDto EMR cluster alternate key
 * @param emrClusterDefinition The EMR cluster definition with search criteria, and the definition that will be updated
 * @param awsParamsDto the AWS related parameters for access/secret keys and proxy details
 */
public void updateEmrClusterDefinitionWithBestPrice(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrClusterDefinition emrClusterDefinition, AwsParamsDto awsParamsDto) {
    EmrVpcPricingState emrVpcPricingState = new EmrVpcPricingState();
    // Get total count of instances this definition will attempt to create
    int totalInstanceCount = getTotalInstanceCount(emrClusterDefinition);
    // Get the subnet information
    List<Subnet> subnets = getSubnets(emrClusterDefinition, awsParamsDto);
    for (Subnet subnet : subnets) {
        emrVpcPricingState.getSubnetAvailableIpAddressCounts().put(subnet.getSubnetId(), subnet.getAvailableIpAddressCount());
    }
    // Filter out subnets with not enough available IPs
    removeSubnetsWithAvailableIpsLessThan(subnets, totalInstanceCount);
    if (subnets.isEmpty()) {
        LOGGER.info(String.format("Insufficient IP availability. namespace=\"%s\" emrClusterDefinitionName=\"%s\" emrClusterName=\"%s\" " + "totalRequestedInstanceCount=%s emrVpcPricingState=%s", emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName(), emrClusterAlternateKeyDto.getEmrClusterName(), totalInstanceCount, jsonHelper.objectToJson(emrVpcPricingState)));
        throw new ObjectNotFoundException(String.format("There are no subnets in the current VPC which have sufficient IP addresses available to run your " + "clusters. Try expanding the list of subnets or try again later. requestedInstanceCount=%s%n%s", totalInstanceCount, emrVpcPricingStateFormatter.format(emrVpcPricingState)));
    }
    // Best prices are accumulated in this list
    List<EmrClusterPriceDto> emrClusterPrices = new ArrayList<>();
    InstanceDefinition masterInstanceDefinition = getMasterInstanceDefinition(emrClusterDefinition);
    InstanceDefinition coreInstanceDefinition = getCoreInstanceDefinition(emrClusterDefinition);
    InstanceDefinition taskInstanceDefinition = getTaskInstanceDefinition(emrClusterDefinition);
    Set<String> requestedInstanceTypes = new HashSet<>();
    String masterInstanceType = masterInstanceDefinition.getInstanceType();
    requestedInstanceTypes.add(masterInstanceType);
    if (coreInstanceDefinition != null) {
        String coreInstanceType = coreInstanceDefinition.getInstanceType();
        requestedInstanceTypes.add(coreInstanceType);
    }
    if (taskInstanceDefinition != null) {
        String taskInstanceType = taskInstanceDefinition.getInstanceType();
        requestedInstanceTypes.add(taskInstanceType);
    }
    // Get AZs for the subnets
    for (AvailabilityZone availabilityZone : getAvailabilityZones(subnets, awsParamsDto)) {
        // Create a mapping of instance types to prices for more efficient, in-memory lookup
        // This method also validates that the given instance types are real instance types supported by AWS.
        Map<String, BigDecimal> instanceTypeOnDemandPrices = getInstanceTypeOnDemandPrices(availabilityZone, requestedInstanceTypes);
        // Create a mapping of instance types to prices for more efficient, in-memory lookup
        // When AWS does not return any spot price history for an instance type in an availability zone, the algorithm will not use that availability zone
        // when selecting the lowest price.
        Map<String, BigDecimal> instanceTypeSpotPrices = getInstanceTypeSpotPrices(availabilityZone, requestedInstanceTypes, awsParamsDto);
        emrVpcPricingState.getSpotPricesPerAvailabilityZone().put(availabilityZone.getZoneName(), instanceTypeSpotPrices);
        emrVpcPricingState.getOnDemandPricesPerAvailabilityZone().put(availabilityZone.getZoneName(), instanceTypeOnDemandPrices);
        // Get and compare master price
        BigDecimal masterSpotPrice = instanceTypeSpotPrices.get(masterInstanceType);
        BigDecimal masterOnDemandPrice = instanceTypeOnDemandPrices.get(masterInstanceType);
        Ec2PriceDto masterPrice = getBestInstancePrice(masterSpotPrice, masterOnDemandPrice, masterInstanceDefinition);
        // Get and compare core price
        Ec2PriceDto corePrice = null;
        if (coreInstanceDefinition != null) {
            String coreInstanceType = coreInstanceDefinition.getInstanceType();
            BigDecimal coreSpotPrice = instanceTypeSpotPrices.get(coreInstanceType);
            BigDecimal coreOnDemandPrice = instanceTypeOnDemandPrices.get(coreInstanceType);
            corePrice = getBestInstancePrice(coreSpotPrice, coreOnDemandPrice, coreInstanceDefinition);
        }
        // Get and compare task price
        Ec2PriceDto taskPrice = null;
        if (taskInstanceDefinition != null) {
            String taskInstanceType = taskInstanceDefinition.getInstanceType();
            BigDecimal taskSpotPrice = instanceTypeSpotPrices.get(taskInstanceType);
            BigDecimal taskOnDemandPrice = instanceTypeOnDemandPrices.get(taskInstanceType);
            taskPrice = getBestInstancePrice(taskSpotPrice, taskOnDemandPrice, taskInstanceDefinition);
        }
        // If prices were found
        if (masterPrice != null && (coreInstanceDefinition == null || corePrice != null) && (taskInstanceDefinition == null || taskPrice != null)) {
            // Add the pricing result to the result list
            emrClusterPrices.add(createEmrClusterPrice(availabilityZone, masterPrice, corePrice, taskPrice));
        }
    // If prices were not found for either master or core, this AZ cannot satisfy the search criteria. Ignore this AZ.
    }
    if (emrClusterPrices.isEmpty()) {
        LOGGER.info(String.format("No subnets which satisfied the best price search criteria. namespace=\"%s\" emrClusterDefinitionName=\"%s\" " + "emrClusterName=\"%s\" emrVpcPricingState=%s", emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName(), emrClusterAlternateKeyDto.getEmrClusterName(), jsonHelper.objectToJson(emrVpcPricingState)));
        throw new ObjectNotFoundException(String.format("There were no subnets which satisfied your best price search criteria. If you explicitly opted to use spot EC2 instances, please confirm " + "that your instance types support spot pricing. Otherwise, try setting the max price or the on-demand threshold to a higher value.%n%s", emrVpcPricingStateFormatter.format(emrVpcPricingState)));
    }
    // Find the best prices from the result list
    EmrClusterPriceDto bestEmrClusterPrice = getEmrClusterPriceWithLowestCoreInstancePrice(emrClusterPrices);
    // Find the best subnet among the best AZ's
    Subnet bestEmrClusterSubnet = getBestSubnetForAvailabilityZone(bestEmrClusterPrice.getAvailabilityZone(), subnets);
    // Update the definition with the new calculated values
    updateInstanceDefinitionsWithBestPrice(emrClusterDefinition, bestEmrClusterSubnet, bestEmrClusterPrice);
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) EmrVpcPricingState(org.finra.herd.model.dto.EmrVpcPricingState) EmrClusterPriceDto(org.finra.herd.model.dto.EmrClusterPriceDto) ArrayList(java.util.ArrayList) AvailabilityZone(com.amazonaws.services.ec2.model.AvailabilityZone) BigDecimal(java.math.BigDecimal) Ec2PriceDto(org.finra.herd.model.dto.Ec2PriceDto) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Subnet(com.amazonaws.services.ec2.model.Subnet) HashSet(java.util.HashSet)

Example 65 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class StorageUnitNotificationRegistrationServiceTest method testUpdateStorageUnitNotificationRegistrationNoExists.

@Test
public void testUpdateStorageUnitNotificationRegistrationNoExists() {
    // Try to update a non-existing storage unit notification registration.
    try {
        storageUnitNotificationRegistrationService.updateStorageUnitNotificationRegistration(new NotificationRegistrationKey(NAMESPACE, NOTIFICATION_NAME), new StorageUnitNotificationRegistrationUpdateRequest(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name(), new StorageUnitNotificationFilter(BDEF_NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, STORAGE_NAME_2, STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS), notificationRegistrationDaoTestHelper.getTestJobActions2(), NotificationRegistrationStatusEntity.ENABLED));
        fail("Should throw an ObjectNotFoundException when trying to update a non-existing storage unit notification.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Storage unit notification registration with name \"%s\" does not exist for \"%s\" namespace.", NOTIFICATION_NAME, NAMESPACE), e.getMessage());
    }
}
Also used : StorageUnitNotificationRegistrationUpdateRequest(org.finra.herd.model.api.xml.StorageUnitNotificationRegistrationUpdateRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) StorageUnitNotificationFilter(org.finra.herd.model.api.xml.StorageUnitNotificationFilter) NotificationRegistrationKey(org.finra.herd.model.api.xml.NotificationRegistrationKey) Test(org.junit.Test)

Aggregations

ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)216 Test (org.junit.Test)193 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)36 ArrayList (java.util.ArrayList)18 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)16 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)16 BusinessObjectDataAttributeKey (org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey)14 PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)12 TagKey (org.finra.herd.model.api.xml.TagKey)11 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)10 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)10 BusinessObjectDataDdlRequest (org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest)9 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)8 InstanceDefinition (org.finra.herd.model.api.xml.InstanceDefinition)7 MasterInstanceDefinition (org.finra.herd.model.api.xml.MasterInstanceDefinition)7 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)6 BusinessObjectDefinitionColumnKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnKey)6 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)5