Search in sources :

Example 1 with DescribeAutoScalingInstancesResult

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;
}
Also used : DescribeAutoScalingInstancesRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingInstancesRequest) AutoScalingInstanceDetails(com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails) DescribeAutoScalingInstancesResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingInstancesResult)

Example 2 with DescribeAutoScalingInstancesResult

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);
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Dictionary(java.util.Dictionary) SchedulerException(org.quartz.SchedulerException) Hashtable(java.util.Hashtable) AmazonAutoScaling(com.amazonaws.services.autoscaling.AmazonAutoScaling) ArrayList(java.util.ArrayList) AutoScalingInstanceDetails(com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails) LifecycleHook(com.amazonaws.services.autoscaling.model.LifecycleHook) SchedulerException(org.quartz.SchedulerException) IAnswer(org.easymock.IAnswer) JobDetail(org.quartz.JobDetail) JobExecutionContext(org.quartz.JobExecutionContext) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) DescribeAutoScalingInstancesResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingInstancesResult) Before(org.junit.Before)

Aggregations

AutoScalingInstanceDetails (com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)2 DescribeAutoScalingInstancesResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingInstancesResult)2 AmazonAutoScaling (com.amazonaws.services.autoscaling.AmazonAutoScaling)1 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)1 DescribeAutoScalingInstancesRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingInstancesRequest)1 LifecycleHook (com.amazonaws.services.autoscaling.model.LifecycleHook)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 IAnswer (org.easymock.IAnswer)1 Before (org.junit.Before)1 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)1 JobDetail (org.quartz.JobDetail)1 JobExecutionContext (org.quartz.JobExecutionContext)1 SchedulerException (org.quartz.SchedulerException)1 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)1