Search in sources :

Example 26 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource in project cloud-pipeline by epam.

the class PipelineRunManager method validateToolInstanceAndPriceTypes.

private void validateToolInstanceAndPriceTypes(final PipelineConfiguration configuration, final String instanceType, final PriceType priceType) {
    final Tool tool = toolManager.loadByNameOrId(configuration.getDockerImage());
    final ContextualPreferenceExternalResource toolResource = new ContextualPreferenceExternalResource(ContextualPreferenceLevel.TOOL, tool.getId().toString());
    Assert.isTrue(!StringUtils.hasText(instanceType) || instanceOfferManager.isToolInstanceAllowed(instanceType, toolResource), messageHelper.getMessage(MessageConstants.ERROR_INSTANCE_TYPE_IS_NOT_ALLOWED, instanceType));
    Assert.isTrue(instanceOfferManager.isPriceTypeAllowed(priceType.getLiteral(), toolResource), messageHelper.getMessage(MessageConstants.ERROR_PRICE_TYPE_IS_NOT_ALLOWED, priceType));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) Tool(com.epam.pipeline.entity.pipeline.Tool)

Example 27 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource in project cloud-pipeline by epam.

the class RunConfigurationProvider method validateEntryConfiguration.

private void validateEntryConfiguration(final PipelineConfiguration configuration) {
    if (configuration.getInstanceType() != null) {
        final ContextualPreferenceExternalResource resource = retrieveResource(configuration);
        Assert.isTrue(instanceOfferManager.isToolInstanceAllowed(configuration.getInstanceType(), resource), messageHelper.getMessage(MessageConstants.ERROR_INSTANCE_TYPE_IS_NOT_ALLOWED, configuration.getInstanceType()));
    }
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource)

Example 28 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource in project cloud-pipeline by epam.

the class ContextualPreferenceDaoTest method upsertShouldUpdateCreatedDateWhileUpdatingPreference.

@Test
public void upsertShouldUpdateCreatedDateWhileUpdatingPreference() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
    final ContextualPreference oldPreference = contextualPreferenceDao.upsert(preference);
    contextualPreferenceDao.upsert(oldPreference.withValue(ANOTHER_VALUE));
    final Optional<ContextualPreference> loadedPreference = contextualPreferenceDao.load(NAME, resource);
    assertTrue(loadedPreference.isPresent());
    assertThat(loadedPreference.get().getCreatedDate(), is(not(oldPreference.getCreatedDate())));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Example 29 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource in project cloud-pipeline by epam.

the class ContextualPreferenceDaoTest method upsertShouldCreatePreference.

@Test
public void upsertShouldCreatePreference() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference preference = contextualPreferenceDao.upsert(new ContextualPreference(NAME, VALUE, resource));
    final Optional<ContextualPreference> loadedPreference = contextualPreferenceDao.load(NAME, resource);
    assertTrue(loadedPreference.isPresent());
    assertThat(loadedPreference.get(), is(preference));
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Example 30 with ContextualPreferenceExternalResource

use of com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource in project cloud-pipeline by epam.

the class ContextualPreferenceDaoTest method loadShouldReturnPreference.

@Test
public void loadShouldReturnPreference() {
    final ContextualPreferenceExternalResource resource = new ContextualPreferenceExternalResource(LEVEL, RESOURCE_ID);
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, TYPE, resource);
    final ContextualPreference storedPreference = contextualPreferenceDao.upsert(preference);
    final Optional<ContextualPreference> loadedPreference = contextualPreferenceDao.load(NAME, resource);
    assertTrue(loadedPreference.isPresent());
    loadedPreference.ifPresent(pref -> {
        assertThat(pref.getName(), is(storedPreference.getName()));
        assertThat(pref.getValue(), is(storedPreference.getValue()));
        assertThat(pref.getType(), is(storedPreference.getType()));
        assertThat(pref.getCreatedDate(), is(storedPreference.getCreatedDate()));
        assertThat(pref.getResource(), is(storedPreference.getResource()));
    });
}
Also used : ContextualPreferenceExternalResource(com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Aggregations

ContextualPreferenceExternalResource (com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource)40 Test (org.junit.Test)37 ContextualPreference (com.epam.pipeline.entity.contextual.ContextualPreference)35 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)10 ContextualPreferenceVO (com.epam.pipeline.controller.vo.ContextualPreferenceVO)3 AllowedInstanceAndPriceTypes (com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes)1 InstanceType (com.epam.pipeline.entity.cluster.InstanceType)1 Tool (com.epam.pipeline.entity.pipeline.Tool)1