use of com.amazonaws.services.autoscaling.model.DescribeAutoScalingInstancesResult in project opencast by opencast.
the class AutoScalingTerminationStateService method getAutoScalingGroupName.
private String getAutoScalingGroupName() {
DescribeAutoScalingInstancesRequest request = new DescribeAutoScalingInstancesRequest().withInstanceIds(instanceId);
DescribeAutoScalingInstancesResult result = autoScaling.describeAutoScalingInstances(request);
List<AutoScalingInstanceDetails> instances = result.getAutoScalingInstances();
logger.debug("Found {} autoscaling instances", instances.size());
if (!instances.isEmpty()) {
AutoScalingInstanceDetails autoScalingInstance = instances.get(0);
return autoScalingInstance.getAutoScalingGroupName();
}
return null;
}
use of com.amazonaws.services.autoscaling.model.DescribeAutoScalingInstancesResult in project opencast by opencast.
the class AutoScalingTerminationStateServiceTest method setUp.
@Before
public void setUp() throws Exception {
serviceRegistry = EasyMock.createMock(ServiceRegistry.class);
autoScaling = EasyMock.createMock(AmazonAutoScaling.class);
autoScalingGroup = new AutoScalingGroup();
autoScalingGroup.setAutoScalingGroupName("test-auto-scaling");
lifecycleHook = new LifecycleHook();
lifecycleHook.setLifecycleHookName("test-terminate");
instance = new AutoScalingInstanceDetails();
instance.setLifecycleState("InService");
jobExecutionContext = EasyMock.createMock(JobExecutionContext.class);
try {
scheduler = new StdSchedulerFactory().getScheduler();
} catch (SchedulerException e) {
throw new Exception(e);
}
nRunningJobs = 1L;
EasyMock.expect(serviceRegistry.getRegistryHostname()).andReturn("localhost").anyTimes();
EasyMock.expect(serviceRegistry.countByHost(null, "localhost", Job.Status.RUNNING)).andAnswer(new IAnswer<Long>() {
@Override
public Long answer() throws Throwable {
return nRunningJobs;
}
}).anyTimes();
serviceRegistry.setMaintenanceStatus("localhost", true);
EasyMock.expectLastCall().atLeastOnce();
EasyMock.replay(serviceRegistry);
List<AutoScalingInstanceDetails> instances = new ArrayList<>();
instances.add(instance);
DescribeAutoScalingInstancesResult dasir = EasyMock.createMock(DescribeAutoScalingInstancesResult.class);
EasyMock.expect(dasir.getAutoScalingInstances()).andReturn(instances).anyTimes();
EasyMock.replay(dasir);
EasyMock.expect(autoScaling.describeAutoScalingInstances(EasyMock.anyObject(DescribeAutoScalingInstancesRequest.class))).andReturn(dasir).anyTimes();
EasyMock.expect(autoScaling.recordLifecycleActionHeartbeat(EasyMock.anyObject(RecordLifecycleActionHeartbeatRequest.class))).andReturn(null).anyTimes();
EasyMock.expect(autoScaling.completeLifecycleAction(EasyMock.anyObject(CompleteLifecycleActionRequest.class))).andReturn(null).once();
autoScaling.shutdown();
EasyMock.expectLastCall();
EasyMock.replay(autoScaling);
service = new AutoScalingTerminationStateService();
service.setServiceRegistry(serviceRegistry);
service.setAutoScaling(autoScaling);
service.setAutoScalingGroup(autoScalingGroup);
service.setLifecycleHook(lifecycleHook);
service.setScheduler(scheduler);
JobDetail jobDetail = new JobDetail();
jobDetail.getJobDataMap().put(AutoScalingTerminationStateService.SCHEDULE_JOB_PARAM_PARENT, service);
EasyMock.expect(jobExecutionContext.getJobDetail()).andReturn(jobDetail).anyTimes();
EasyMock.replay(jobExecutionContext);
Dictionary config = new Hashtable();
config.put(AutoScalingTerminationStateService.CONFIG_ENABLE, "true");
config.put(AutoScalingTerminationStateService.CONFIG_LIFECYCLE_POLLING_PERIOD, "1");
config.put(AutoScalingTerminationStateService.CONFIG_LIFECYCLE_HEARTBEAT_PERIOD, "1");
service.configure(config);
}
Aggregations