Search in sources :

Example 1 with AllowedInstanceAndPriceTypes

use of com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes in project cloud-pipeline by epam.

the class InstanceOfferManagerUnitTest method getAllowedInstanceAndPriceTypesShouldSearchPreferencesUsingToolAsExternalResourceIfToolIdIsSpecified.

@Test
public void getAllowedInstanceAndPriceTypesShouldSearchPreferencesUsingToolAsExternalResourceIfToolIdIsSpecified() {
    final List<String> allowedPriceTypes = Arrays.asList(SPOT, ON_DEMAND);
    final List<InstanceType> allInstanceTypes = Arrays.asList(m4InstanceType, m5InstanceType, t2InstanceType);
    final List<InstanceType> allowedInstanceTypes = Arrays.asList(m4InstanceType, m5InstanceType);
    final List<InstanceType> allowedInstanceDockerTypes = Collections.singletonList(m4InstanceType);
    when(contextualPreferenceManager.search(eq(INSTANCE_TYPES_PREFERENCES), eq(TOOL_RESOURCE))).thenReturn(new ContextualPreference(ALLOWED_INSTANCE_TYPES_PREFERENCE, M4_M5_PATTERNS));
    when(contextualPreferenceManager.search(eq(Arrays.asList(ALLOWED_DOCKER_INSTANCE_TYPES_PREFERENCE, ALLOWED_INSTANCE_TYPES_PREFERENCE)), eq(TOOL_RESOURCE))).thenReturn(new ContextualPreference(ALLOWED_DOCKER_INSTANCE_TYPES_PREFERENCE, M4_PATTERN));
    when(contextualPreferenceManager.search(eq(Collections.singletonList(ALLOWED_PRICE_TYPES_PREFERENCE)), eq(TOOL_RESOURCE))).thenReturn(new ContextualPreference(ALLOWED_PRICE_TYPES_PREFERENCE, SPOT_AND_ON_DEMAND_TYPES));
    when(instanceOfferDao.loadInstanceTypes(any())).thenReturn(allInstanceTypes);
    final AllowedInstanceAndPriceTypes allowedInstanceAndPriceTypes = instanceOfferManager.getAllowedInstanceAndPriceTypes(TOOL_ID);
    assertThat(allowedInstanceAndPriceTypes.getAllowedInstanceTypes(), is(allowedInstanceTypes));
    assertThat(allowedInstanceAndPriceTypes.getAllowedInstanceDockerTypes(), is(allowedInstanceDockerTypes));
    assertThat(allowedInstanceAndPriceTypes.getAllowedPriceTypes(), is(allowedPriceTypes));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) AllowedInstanceAndPriceTypes(com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes) InstanceType(com.epam.pipeline.entity.cluster.InstanceType) Test(org.junit.Test)

Example 2 with AllowedInstanceAndPriceTypes

use of com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes in project cloud-pipeline by epam.

the class InstanceOfferManager method getAllowedInstanceAndPriceTypes.

/**
 * Returns allowed instance and price types for a current user.
 *
 * @param toolId Optional tool id. If specified than allowed instance and price types will be bounded for a
 *               specific tool.
 */
public AllowedInstanceAndPriceTypes getAllowedInstanceAndPriceTypes(final String toolId) {
    final ContextualPreferenceExternalResource resource = toolId != null ? new ContextualPreferenceExternalResource(ContextualPreferenceLevel.TOOL, toolId) : null;
    final List<InstanceType> instanceTypes = getAllInstanceTypes();
    final List<InstanceType> allowedInstanceTypes = getAllowedInstanceTypes(instanceTypes, resource, SystemPreferences.CLUSTER_ALLOWED_INSTANCE_TYPES);
    final List<InstanceType> allowedInstanceDockerTypes = getAllowedInstanceTypes(instanceTypes, resource, SystemPreferences.CLUSTER_ALLOWED_INSTANCE_TYPES_DOCKER, SystemPreferences.CLUSTER_ALLOWED_INSTANCE_TYPES);
    final List<String> allowedPriceTypes = getContextualPreferenceValueAsList(resource, SystemPreferences.CLUSTER_ALLOWED_PRICE_TYPES);
    return new AllowedInstanceAndPriceTypes(allowedInstanceTypes, allowedInstanceDockerTypes, allowedPriceTypes);
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) AllowedInstanceAndPriceTypes(com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes) InstanceType(com.epam.pipeline.entity.cluster.InstanceType)

Example 3 with AllowedInstanceAndPriceTypes

use of com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes in project cloud-pipeline by epam.

the class InstanceOfferManagerUnitTest method getAllowedInstanceAndPriceTypesShouldSearchPreferencesIfToolIdIsNull.

@Test
public void getAllowedInstanceAndPriceTypesShouldSearchPreferencesIfToolIdIsNull() {
    final List<String> allowedPriceTypes = Arrays.asList(SPOT, ON_DEMAND);
    final List<InstanceType> allInstanceTypes = Arrays.asList(m4InstanceType, m5InstanceType, t2InstanceType);
    final List<InstanceType> allowedInstanceTypes = Arrays.asList(m4InstanceType, m5InstanceType);
    final List<InstanceType> allowedInstanceDockerTypes = Collections.singletonList(m4InstanceType);
    when(contextualPreferenceManager.search(eq(INSTANCE_TYPES_PREFERENCES), eq(null))).thenReturn(new ContextualPreference(ALLOWED_INSTANCE_TYPES_PREFERENCE, M4_M5_PATTERNS));
    when(contextualPreferenceManager.search(eq(Arrays.asList(ALLOWED_DOCKER_INSTANCE_TYPES_PREFERENCE, ALLOWED_INSTANCE_TYPES_PREFERENCE)), eq(null))).thenReturn(new ContextualPreference(ALLOWED_DOCKER_INSTANCE_TYPES_PREFERENCE, M4_PATTERN));
    when(contextualPreferenceManager.search(eq(Collections.singletonList(ALLOWED_PRICE_TYPES_PREFERENCE)), eq(null))).thenReturn(new ContextualPreference(ALLOWED_PRICE_TYPES_PREFERENCE, SPOT_AND_ON_DEMAND_TYPES));
    when(instanceOfferDao.loadInstanceTypes(any())).thenReturn(allInstanceTypes);
    final AllowedInstanceAndPriceTypes allowedInstanceAndPriceTypes = instanceOfferManager.getAllowedInstanceAndPriceTypes(null);
    assertThat(allowedInstanceAndPriceTypes.getAllowedInstanceTypes(), is(allowedInstanceTypes));
    assertThat(allowedInstanceAndPriceTypes.getAllowedInstanceDockerTypes(), is(allowedInstanceDockerTypes));
    assertThat(allowedInstanceAndPriceTypes.getAllowedPriceTypes(), is(allowedPriceTypes));
}
Also used : ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) AllowedInstanceAndPriceTypes(com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes) InstanceType(com.epam.pipeline.entity.cluster.InstanceType) Test(org.junit.Test)

Aggregations

AllowedInstanceAndPriceTypes (com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes)3 InstanceType (com.epam.pipeline.entity.cluster.InstanceType)3 ContextualPreference (com.epam.pipeline.entity.contextual.ContextualPreference)2 Test (org.junit.Test)2 ContextualPreferenceExternalResource (com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource)1