Search in sources :

Example 21 with AwsRegion

use of com.epam.pipeline.entity.region.AwsRegion in project cloud-pipeline by epam.

the class AwsRegionManagerTest method createShouldSetKmsKeyIdToDefaultValueIfMissing.

@Test
public void createShouldSetKmsKeyIdToDefaultValueIfMissing() {
    final String defaultKeyId = KMS_KEY_ID;
    when(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_SECURITY_KEY_ID)).thenReturn(defaultKeyId);
    final AwsRegionVO regionVO = getAwsRegionVoBuilder().kmsKeyArn(KMS_KEY_ARN).policy(EMPTY_POLICY).corsRules(EMPTY_CORS_RULES).awsRegionName(VALID_REGION_ID).isDefault(false).build();
    awsRegionManager.create(regionVO);
    final ArgumentCaptor<AwsRegion> regionCaptor = ArgumentCaptor.forClass(AwsRegion.class);
    verify(awsRegionDao).create(regionCaptor.capture());
    final AwsRegion actualRegion = regionCaptor.getValue();
    assertThat(actualRegion.getKmsKeyId(), is(defaultKeyId));
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Test(org.junit.Test)

Example 22 with AwsRegion

use of com.epam.pipeline.entity.region.AwsRegion in project cloud-pipeline by epam.

the class ClusterManagerImpl method buildNodeUpDefaultCommand.

private String buildNodeUpDefaultCommand(String nodeId) {
    AwsRegion region = awsRegionManager.loadDefaultRegion();
    List<String> commands = new ArrayList<>();
    commands.add(EXECUTABLE);
    commands.add(nodeUpScript);
    commands.add(RUN_ID_PARAMETER);
    commands.add(nodeId);
    commands.add("--ins_key");
    commands.add(preferenceManager.getPreference(SystemPreferences.CLUSTER_SSH_KEY_NAME));
    commands.add("--ins_img");
    commands.add(preferenceManager.getPreference(SystemPreferences.CLUSTER_INSTANCE_IMAGE));
    commands.add("--ins_type");
    commands.add(preferenceManager.getPreference(SystemPreferences.CLUSTER_INSTANCE_TYPE));
    commands.add("--ins_hdd");
    commands.add(String.valueOf(preferenceManager.getPreference(SystemPreferences.CLUSTER_INSTANCE_HDD)));
    if (preferenceManager.getPreference(SystemPreferences.CLUSTER_SPOT)) {
        commands.add("--is_spot");
        commands.add("True");
        commands.add("--bid_price");
        Double bidPrice = customizeSpotArguments(preferenceManager.getPreference(SystemPreferences.CLUSTER_INSTANCE_TYPE), region.getAwsRegionName());
        commands.add(bidPrice == null ? "" : String.valueOf(bidPrice));
    }
    commands.add("--region_id");
    commands.add(region.getAwsRegionName());
    return commands.stream().collect(Collectors.joining(" "));
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) ArrayList(java.util.ArrayList)

Example 23 with AwsRegion

use of com.epam.pipeline.entity.region.AwsRegion in project cloud-pipeline by epam.

the class InstanceOfferManager method getPipelineRunEstimatedPrice.

public PipelineRunPrice getPipelineRunEstimatedPrice(Long runId, Long regionId) {
    PipelineRun pipelineRun = pipelineRunManager.loadPipelineRun(runId);
    RunInstance runInstance = pipelineRun.getInstance();
    AwsRegion region = awsRegionManager.loadRegionOrGetDefault(regionId);
    double pricePerHourForInstance = getPricePerHourForInstance(runInstance.getNodeType(), isSpotRequest(runInstance.getSpot()), region.getAwsRegionName());
    double pricePerDisk = getPriceForDisk(runInstance.getNodeDisk(), region.getAwsRegionName());
    double pricePerHour = pricePerDisk + pricePerHourForInstance;
    PipelineRunPrice price = new PipelineRunPrice();
    price.setInstanceDisk(runInstance.getNodeDisk());
    price.setInstanceType(runInstance.getNodeType());
    price.setPricePerHour(pricePerHour);
    if (pipelineRun.getStatus().isFinal()) {
        long duration = pipelineRun.getEndDate().getTime() - pipelineRun.getStartDate().getTime();
        price.setTotalPrice(duration / ONE_HOUR * pricePerHour);
    } else {
        price.setTotalPrice(0);
    }
    return price;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) PipelineRunPrice(com.epam.pipeline.entity.cluster.PipelineRunPrice) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance)

Example 24 with AwsRegion

use of com.epam.pipeline.entity.region.AwsRegion in project cloud-pipeline by epam.

the class InstanceOfferManager method getInstanceEstimatedPrice.

public InstancePrice getInstanceEstimatedPrice(Long id, String version, String configName, String instanceType, int instanceDisk, Boolean spot, Long regionId) throws GitClientException {
    Boolean useSpot = spot;
    if (StringUtils.isEmpty(instanceType) || instanceDisk <= 0 || useSpot == null) {
        PipelineConfiguration pipelineConfiguration = versionManager.loadParametersFromScript(id, version, configName);
        if (StringUtils.isEmpty(instanceType)) {
            instanceType = pipelineConfiguration.getInstanceType();
        }
        if (instanceDisk <= 0) {
            instanceDisk = Integer.parseInt(pipelineConfiguration.getInstanceDisk());
        }
        if (useSpot == null) {
            useSpot = pipelineConfiguration.getIsSpot();
        }
    }
    Assert.isTrue(isInstanceAllowed(instanceType), messageHelper.getMessage(MessageConstants.ERROR_INSTANCE_TYPE_IS_NOT_ALLOWED, instanceType));
    AwsRegion region = awsRegionManager.loadRegionOrGetDefault(regionId);
    double pricePerHourForInstance = getPricePerHourForInstance(instanceType, isSpotRequest(useSpot), region.getAwsRegionName());
    double pricePerDisk = getPriceForDisk(instanceDisk, region.getAwsRegionName());
    double pricePerHour = pricePerDisk + pricePerHourForInstance;
    InstancePrice instancePrice = new InstancePrice(instanceType, instanceDisk, pricePerHour);
    List<PipelineRun> runs = pipelineRunManager.loadAllRunsByPipeline(id, version).stream().filter(run -> run.getStatus().isFinal()).collect(Collectors.toList());
    if (!runs.isEmpty()) {
        long minimumDuration = -1;
        long maximumDuration = -1;
        long totalDurations = 0;
        for (PipelineRun run : runs) {
            long duration = run.getEndDate().getTime() - run.getStartDate().getTime();
            if (minimumDuration == -1 || minimumDuration > duration) {
                minimumDuration = duration;
            }
            if (maximumDuration == -1 || maximumDuration < duration) {
                maximumDuration = duration;
            }
            totalDurations += duration;
        }
        double averageDuration = (double) totalDurations / runs.size();
        instancePrice.setAverageTimePrice(pricePerHour * averageDuration / ONE_HOUR);
        instancePrice.setMinimumTimePrice(pricePerHour * minimumDuration / ONE_HOUR);
        instancePrice.setMaximumTimePrice(pricePerHour * maximumDuration / ONE_HOUR);
    }
    return instancePrice;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Arrays(java.util.Arrays) InstanceType(com.epam.pipeline.entity.cluster.InstanceType) URL(java.net.URL) Date(java.util.Date) BehaviorSubject(io.reactivex.subjects.BehaviorSubject) LoggerFactory(org.slf4j.LoggerFactory) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) MessageHelper(com.epam.pipeline.common.MessageHelper) ContextualPreferenceManager(com.epam.pipeline.manager.contextual.ContextualPreferenceManager) ListUtils(org.apache.commons.collections4.ListUtils) AntPathMatcher(org.springframework.util.AntPathMatcher) AllowedInstanceAndPriceTypes(com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes) InstancePrice(com.epam.pipeline.entity.cluster.InstancePrice) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Set(java.util.Set) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Collectors(java.util.stream.Collectors) ContextualPreferenceLevel(com.epam.pipeline.entity.contextual.ContextualPreferenceLevel) List(java.util.List) PostConstruct(javax.annotation.PostConstruct) MessageConstants(com.epam.pipeline.common.MessageConstants) GitClientException(com.epam.pipeline.exception.git.GitClientException) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) PipelineRunPrice(com.epam.pipeline.entity.cluster.PipelineRunPrice) AtomicReference(java.util.concurrent.atomic.AtomicReference) PipelineVersionManager(com.epam.pipeline.manager.pipeline.PipelineVersionManager) ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) InstanceOffer(com.epam.pipeline.entity.cluster.InstanceOffer) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) Observable(io.reactivex.Observable) Subject(io.reactivex.subjects.Subject) AbstractSystemPreference(com.epam.pipeline.manager.preference.AbstractSystemPreference) InstanceOfferRequestVO(com.epam.pipeline.controller.vo.InstanceOfferRequestVO) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Logger(org.slf4j.Logger) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) InstanceOfferDao(com.epam.pipeline.dao.cluster.InstanceOfferDao) BufferedReader(java.io.BufferedReader) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) AwsRegionManager(com.epam.pipeline.manager.region.AwsRegionManager) NoArgsConstructor(lombok.NoArgsConstructor) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) InputStream(java.io.InputStream) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) InstancePrice(com.epam.pipeline.entity.cluster.InstancePrice) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration)

Example 25 with AwsRegion

use of com.epam.pipeline.entity.region.AwsRegion in project cloud-pipeline by epam.

the class S3StorageProvider method createStorage.

@Override
public String createStorage(S3bucketDataStorage storage) {
    try {
        AwsRegion awsRegion = getAwsRegion(storage);
        if (storage.getRegionId() == null) {
            storage.setRegionId(awsRegion.getId());
        }
        final ObjectMapper corsRulesMapper = JsonMapper.newInstance().addMixIn(CORSRule.class, AbstractCORSRuleMixin.class).configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
        final List<CORSRule> corsPolicyRules = JsonMapper.parseData(awsRegion.getCorsRules(), new TypeReference<List<CORSRule>>() {
        }, corsRulesMapper);
        final Map<String, String> tags = new HashMap<>();
        AwsRegionsConfiguration configuration = preferenceManager.getObjectPreferenceAs(SystemPreferences.CLUSTER_NETWORKS_CONFIG, new TypeReference<AwsRegionsConfiguration>() {
        });
        if (configuration != null && !CollectionUtils.isEmpty(configuration.getTags())) {
            tags.putAll(configuration.getTags());
        }
        return getS3Helper(storage).createS3Bucket(storage.getPath(), awsRegion.getPolicy(), corsPolicyRules, storage.getAllowedCidrs(), awsRegion, tags, storage.isShared());
    } catch (IOException e) {
        throw new DataStorageException(messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_CREATE_FAILED, storage.getName()), e);
    }
}
Also used : HashMap(java.util.HashMap) CORSRule(com.amazonaws.services.s3.model.CORSRule) IOException(java.io.IOException) DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) AwsRegionsConfiguration(com.epam.pipeline.entity.cluster.AwsRegionsConfiguration) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

AwsRegion (com.epam.pipeline.entity.region.AwsRegion)42 Test (org.junit.Test)24 AwsRegionVO (com.epam.pipeline.controller.vo.AwsRegionVO)13 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)9 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)6 Transactional (org.springframework.transaction.annotation.Transactional)5 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)4 Before (org.junit.Before)4 Date (java.util.Date)3 List (java.util.List)3 MessageConstants (com.epam.pipeline.common.MessageConstants)2 MessageHelper (com.epam.pipeline.common.MessageHelper)2 InstancePrice (com.epam.pipeline.entity.cluster.InstancePrice)2 PipelineRunPrice (com.epam.pipeline.entity.cluster.PipelineRunPrice)2 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)2 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)2 DataStorageException (com.epam.pipeline.entity.datastorage.DataStorageException)2 StoragePolicy (com.epam.pipeline.entity.datastorage.StoragePolicy)2 S3bucketDataStorage (com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)2 Folder (com.epam.pipeline.entity.pipeline.Folder)2