Search in sources :

Example 11 with AwsRegion

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

the class S3StorageProviderTest method setUp.

@Before
public void setUp() {
    when(bucket.getName()).thenReturn(bucketName);
    when(amazonClient.createBucket(any(CreateBucketRequest.class))).thenReturn(bucket);
    when(s3Helper.getDefaultS3Client()).thenReturn(amazonClient);
    AwsRegion region = new AwsRegion();
    region.setId(REGION_ID);
    region.setAwsRegionName("us-east-1");
    region.setCorsRules("[" + "  {" + "    \"AllowedOrigins\": [\"string\"]," + "    \"AllowedMethods\": [\"PUT\", \"GET\"]," + "    \"AllowedHeaders\": [\"string\"]," + "    \"MaxAgeSeconds\": 3000," + "    \"ExposeHeaders\": [\"string\"]" + "  }" + "]");
    when(awsRegionManager.getAwsRegion(any())).thenReturn(region);
    doReturn(s3Helper).when(s3StorageProvider).getS3Helper(any());
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) CreateBucketRequest(com.amazonaws.services.s3.model.CreateBucketRequest) Before(org.junit.Before)

Example 12 with AwsRegion

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

the class DataStorageManager method generateTemporaryCredentials.

public AbstractTemporaryCredentials generateTemporaryCredentials(List<DataStorageAction> actions) {
    AbstractDataStorage dataStorage = ListUtils.emptyIfNull(actions).stream().findFirst().map(action -> load(action.getId())).orElseThrow(() -> new IllegalArgumentException("Actions are not provided"));
    Assert.isTrue(dataStorage instanceof S3bucketDataStorage, "Temporary credentials are supported only for S3 Buckets.");
    S3bucketDataStorage bucket = (S3bucketDataStorage) dataStorage;
    AwsRegion awsRegion = awsRegionManager.getAwsRegion(bucket);
    actions.forEach(action -> {
        AbstractDataStorage loaded = action.getId().equals(dataStorage.getId()) ? dataStorage : load(action.getId());
        Assert.isTrue(loaded instanceof S3bucketDataStorage, "Temporary credentials are supported only for S3 Buckets.");
        action.setBucketName(loaded.getPath());
        Long regionId = ((S3bucketDataStorage) loaded).getRegionId();
        Assert.isTrue(Objects.equals(regionId, bucket.getRegionId()), "Actions shall be requested for buckets from the same region");
    });
    return dataStorageFactory.temporaryCredentials(bucket.getType()).withRole(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_TEMP_CREDENTIALS_ROLE)).withDurationSeconds(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_TEMP_CREDENTIALS_DURATION)).withKmsArn(awsRegion.getKmsKeyArn()).withRegionId(awsRegion.getAwsRegionName()).generate(actions);
}
Also used : Arrays(java.util.Arrays) S3Constants(com.epam.pipeline.manager.datastorage.providers.aws.s3.S3Constants) LoggerFactory(org.slf4j.LoggerFactory) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) StoragePolicy(com.epam.pipeline.entity.datastorage.StoragePolicy) StringUtils(org.apache.commons.lang3.StringUtils) DataStorageVO(com.epam.pipeline.controller.vo.DataStorageVO) Folder(com.epam.pipeline.entity.pipeline.Folder) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MessageHelper(com.epam.pipeline.common.MessageHelper) ListUtils(org.apache.commons.collections4.ListUtils) Map(java.util.Map) DataStorageItemContent(com.epam.pipeline.entity.datastorage.DataStorageItemContent) DataStorageListing(com.epam.pipeline.entity.datastorage.DataStorageListing) AntPathMatcher(org.springframework.util.AntPathMatcher) SecuredEntityManager(com.epam.pipeline.manager.security.SecuredEntityManager) DataStorageItemType(com.epam.pipeline.entity.datastorage.DataStorageItemType) DataStorageLink(com.epam.pipeline.entity.pipeline.run.parameter.DataStorageLink) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) RoleManager(com.epam.pipeline.manager.user.RoleManager) DataStorageDownloadFileUrl(com.epam.pipeline.entity.datastorage.DataStorageDownloadFileUrl) Collection(java.util.Collection) Set(java.util.Set) StorageContainer(com.epam.pipeline.entity.user.StorageContainer) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Collectors(java.util.stream.Collectors) AbstractDataStorageFactory(com.epam.pipeline.entity.datastorage.AbstractDataStorageFactory) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) Objects(java.util.Objects) List(java.util.List) UserManager(com.epam.pipeline.manager.user.UserManager) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) AclSync(com.epam.pipeline.manager.security.acl.AclSync) Optional(java.util.Optional) EntityVO(com.epam.pipeline.controller.vo.EntityVO) AbstractTemporaryCredentials(com.epam.pipeline.entity.datastorage.AbstractTemporaryCredentials) DataStorageDao(com.epam.pipeline.dao.datastorage.DataStorageDao) MessageConstants(com.epam.pipeline.common.MessageConstants) DataStorageAction(com.epam.pipeline.entity.datastorage.DataStorageAction) HashMap(java.util.HashMap) Function(java.util.function.Function) DataStorageFolder(com.epam.pipeline.entity.datastorage.DataStorageFolder) ArrayList(java.util.ArrayList) MetadataManager(com.epam.pipeline.manager.metadata.MetadataManager) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) BaseEntity(com.epam.pipeline.entity.BaseEntity) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Logger(org.slf4j.Logger) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) MapUtils(org.apache.commons.collections.MapUtils) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageType(com.epam.pipeline.entity.datastorage.DataStorageType) AbstractDataStorageItem(com.epam.pipeline.entity.datastorage.AbstractDataStorageItem) Paths(java.nio.file.Paths) NumberUtils(org.apache.commons.lang3.math.NumberUtils) AclClass(com.epam.pipeline.entity.security.acl.AclClass) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) AuthManager(com.epam.pipeline.manager.security.AuthManager) UpdateDataStorageItemVO(com.epam.pipeline.controller.vo.data.storage.UpdateDataStorageItemVO) Collections(java.util.Collections) AwsRegionManager(com.epam.pipeline.manager.region.AwsRegionManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) InputStream(java.io.InputStream) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)

Example 13 with AwsRegion

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

the class S3StorageProvider method checkStorage.

@Override
public boolean checkStorage(S3bucketDataStorage dataStorage) {
    if (dataStorage.getRegionId() == null) {
        AwsRegion awsRegion = awsRegionManager.getAwsRegion(dataStorage);
        dataStorage.setRegionId(awsRegion.getId());
    }
    return getS3Helper(dataStorage).checkBucket(dataStorage.getPath());
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion)

Example 14 with AwsRegion

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

the class PipelineRunManagerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    notScannedTool = new Tool();
    notScannedTool.setId(1L);
    notScannedTool.setImage(TEST_IMAGE);
    notScannedTool.setDefaultCommand("sleep");
    configuration = new PipelineConfiguration();
    configuration.setDockerImage(TEST_IMAGE);
    configuration.setInstanceDisk("1");
    configuration.setIsSpot(true);
    price = new InstancePrice(configuration.getInstanceType(), Integer.valueOf(configuration.getInstanceDisk()), PRICE_PER_HOUR);
    when(toolManager.loadByNameOrId(TEST_IMAGE)).thenReturn(notScannedTool);
    when(instanceOfferManager.isInstanceAllowed(anyString())).thenReturn(true);
    when(instanceOfferManager.isToolInstanceAllowed(anyString(), any())).thenReturn(true);
    when(instanceOfferManager.isPriceTypeAllowed(anyString(), any())).thenReturn(true);
    when(instanceOfferManager.getAllInstanceTypesObservable()).thenReturn(BehaviorSubject.create());
    when(instanceOfferManager.getInstanceEstimatedPrice(anyString(), anyInt(), anyBoolean(), anyString())).thenReturn(price);
    when(pipelineLauncher.launch(any(PipelineRun.class), any(), any(), anyString(), anyString())).thenReturn("sleep");
    when(toolManager.loadToolVersionScan(notScannedTool.getId(), null)).thenReturn(Optional.empty());
    when(toolVersionManager.loadToolVersion(anyLong(), anyString())).thenReturn(ToolVersion.builder().size(1L).build());
    doReturn(configuration).when(pipelineConfigurationManager).getPipelineConfiguration(any());
    doReturn(configuration).when(pipelineConfigurationManager).getPipelineConfiguration(any(), any());
    AwsRegion region = new AwsRegion();
    region.setAwsRegionName("us-east-1");
    doReturn(region).when(awsRegionManager).loadDefaultRegion();
    doNothing().when(entityManager).setManagers(any());
    doNothing().when(resourceMonitoringManager).monitorResourceUsage();
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) InstancePrice(com.epam.pipeline.entity.cluster.InstancePrice) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Tool(com.epam.pipeline.entity.pipeline.Tool) Before(org.junit.Before)

Example 15 with AwsRegion

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

the class AwsRegionManagerTest method createShouldSetCorsRulesToDefaultValueIfMissing.

@Test
public void createShouldSetCorsRulesToDefaultValueIfMissing() {
    final String corsRulesAsString = "[{" + "\"id\":\"id1\"," + "\"allowedOrigins\":[\"origin1\",\"origin2\"]," + "\"maxAgeSeconds\":0" + "},{" + "\"id\":\"id2\"," + "\"maxAgeSeconds\":0," + "\"allowedHeaders\":[\"header1\"]" + "}]";
    Preference corsPolicy = new Preference();
    corsPolicy.setValue(corsRulesAsString);
    doReturn(Optional.of(corsPolicy)).when(preferenceManager).load(eq(SystemPreferences.DATA_STORAGE_CORS_POLICY.getKey()));
    final AwsRegionVO regionVO = getAwsRegionVoBuilder().policy(EMPTY_POLICY).kmsKeyId(KMS_KEY_ID).kmsKeyArn(KMS_KEY_ARN).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.getCorsRules(), is(corsRulesAsString));
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Preference(com.epam.pipeline.entity.preference.Preference) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Test(org.junit.Test)

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