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