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));
}
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(" "));
}
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;
}
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;
}
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);
}
}
Aggregations