Search in sources :

Example 6 with InstanceType

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

the class InstanceOfferManagerUnitTest method instanceType.

private InstanceType instanceType(final String name) {
    final InstanceType instanceType = new InstanceType();
    instanceType.setName(name);
    return instanceType;
}
Also used : InstanceType(com.epam.pipeline.entity.cluster.InstanceType)

Example 7 with InstanceType

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

the class ResourceMonitoringManagerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    resourceMonitoringManager = new ResourceMonitoringManager(pipelineRunManager, preferenceManager, notificationManager, instanceOfferManager, monitoringESDao, taskScheduler, messageHelper);
    when(preferenceManager.getObservablePreference(SystemPreferences.SYSTEM_RESOURCE_MONITORING_PERIOD)).thenReturn(Observable.empty());
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_RESOURCE_MONITORING_PERIOD)).thenReturn(TEST_RESOURCE_MONITORING_DELAY);
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_IDLE_CPU_THRESHOLD_PERCENT)).thenReturn(TEST_IDLE_THRESHOLD_PERCENT);
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_IDLE_ACTION_TIMEOUT_MINUTES)).thenReturn(1);
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_MAX_IDLE_TIMEOUT_MINUTES)).thenReturn(TEST_MAX_IDLE_MONITORING_TIMEOUT);
    testType = new InstanceType();
    testType.setVCPU(2);
    testType.setName("t1.test");
    BehaviorSubject<List<InstanceType>> mockSubject = BehaviorSubject.createDefault(Collections.singletonList(testType));
    when(instanceOfferManager.getAllInstanceTypesObservable()).thenReturn(mockSubject);
    RunInstance spotInstance = new RunInstance(testType.getName(), 0, 0, null, null, null, null, true, null);
    okayRun = new PipelineRun();
    okayRun.setInstance(spotInstance);
    okayRun.setPodId("okay-pod");
    okayRun.setId(TEST_OK_RUN_ID);
    okayRun.setStartDate(new Date(Instant.now().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES).toEpochMilli()));
    okayRun.setProlongedAtTime(DateUtils.nowUTC().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES));
    idleSpotRun = new PipelineRun();
    idleSpotRun.setInstance(spotInstance);
    idleSpotRun.setPodId("idle-spot");
    idleSpotRun.setId(TEST_IDLE_SPOT_RUN_ID);
    idleSpotRun.setStartDate(new Date(Instant.now().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES).toEpochMilli()));
    idleSpotRun.setProlongedAtTime(DateUtils.nowUTC().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES));
    idleOnDemandRun = new PipelineRun();
    idleOnDemandRun.setInstance(new RunInstance(testType.getName(), 0, 0, null, null, null, null, false, null));
    idleOnDemandRun.setPodId("idle-on-demand");
    idleOnDemandRun.setId(TEST_IDLE_ON_DEMAND_RUN_ID);
    idleOnDemandRun.setStartDate(new Date(Instant.now().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES).toEpochMilli()));
    idleOnDemandRun.setProlongedAtTime(DateUtils.nowUTC().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES));
    idleRunToProlong = new PipelineRun();
    idleRunToProlong.setInstance(new RunInstance(testType.getName(), 0, 0, null, null, null, null, false, null));
    idleRunToProlong.setPodId("idle-to-prolong");
    idleRunToProlong.setId(TEST_IDLE_RUN_TO_PROLONG_ID);
    idleRunToProlong.setStartDate(new Date(Instant.now().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES).toEpochMilli()));
    idleRunToProlong.setProlongedAtTime(DateUtils.nowUTC().minus(TEST_MAX_IDLE_MONITORING_TIMEOUT + 1, ChronoUnit.MINUTES));
    mockStats = new HashMap<>();
    // in milicores, equals 80% of core load, per 2 cores,
    mockStats.put(okayRun.getPodId(), TEST_OK_RUN_CPU_LOAD);
    // should be = 40% load
    mockStats.put(idleSpotRun.getPodId(), TEST_IDLE_SPOT_RUN_CPU_LOAD);
    mockStats.put(idleOnDemandRun.getPodId(), TEST_IDLE_ON_DEMAND_RUN_CPU_LOAD);
    when(monitoringESDao.loadCpuUsageRateMetrics(any(), any(LocalDateTime.class), any(LocalDateTime.class))).thenReturn(mockStats);
    resourceMonitoringManager.init();
    verify(taskScheduler).scheduleWithFixedDelay(any(), eq(TEST_RESOURCE_MONITORING_DELAY.longValue()));
    Assert.assertNotNull(Whitebox.getInternalState(resourceMonitoringManager, "instanceTypeMap"));
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) LocalDateTime(java.time.LocalDateTime) List(java.util.List) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) InstanceType(com.epam.pipeline.entity.cluster.InstanceType) Date(java.util.Date) Before(org.junit.Before)

Example 8 with InstanceType

use of com.epam.pipeline.entity.cluster.InstanceType 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)

Aggregations

InstanceType (com.epam.pipeline.entity.cluster.InstanceType)8 AllowedInstanceAndPriceTypes (com.epam.pipeline.entity.cluster.AllowedInstanceAndPriceTypes)4 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)3 ContextualPreference (com.epam.pipeline.entity.contextual.ContextualPreference)2 ContextualPreferenceExternalResource (com.epam.pipeline.entity.contextual.ContextualPreferenceExternalResource)2 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)2 Date (java.util.Date)2 List (java.util.List)2 MessageConstants (com.epam.pipeline.common.MessageConstants)1 MessageHelper (com.epam.pipeline.common.MessageHelper)1 InstanceOfferRequestVO (com.epam.pipeline.controller.vo.InstanceOfferRequestVO)1 InstanceOfferDao (com.epam.pipeline.dao.cluster.InstanceOfferDao)1 InstanceOffer (com.epam.pipeline.entity.cluster.InstanceOffer)1 InstancePrice (com.epam.pipeline.entity.cluster.InstancePrice)1 PipelineRunPrice (com.epam.pipeline.entity.cluster.PipelineRunPrice)1 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)1 ContextualPreferenceLevel (com.epam.pipeline.entity.contextual.ContextualPreferenceLevel)1 ToolVersion (com.epam.pipeline.entity.docker.ToolVersion)1 AwsRegion (com.epam.pipeline.entity.region.AwsRegion)1 GitClientException (com.epam.pipeline.exception.git.GitClientException)1