Java Code Examples for com.amazonaws.services.ec2.model.Instance#setInstanceId()

The following examples show how to use com.amazonaws.services.ec2.model.Instance#setInstanceId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Ec2LookupServiceTest.java    From Gatekeeper with Apache License 2.0 6 votes vote down vote up
private Reservation fakeInstance(String instanceID, String instanceIP, String instanceName, String instanceApplication, String platform) {
    Reservation container = new Reservation();
    List<Instance> instances = new ArrayList<>();
    Instance i = new Instance();
    List<Tag> tags = new ArrayList<>();
    i.setInstanceId(instanceID);
    i.setPrivateIpAddress(instanceIP);
    Tag nameTag = new Tag();
    nameTag.setKey("Name");
    nameTag.setValue(instanceName);
    Tag applicationTag = new Tag();
    applicationTag.setKey("Application");
    applicationTag.setValue(instanceApplication);
    tags.add(applicationTag);
    tags.add(nameTag);
    i.setTags(tags);
    i.setPlatform(platform);
    instances.add(i);
    container.setInstances(instances);

    return container;
}
 
Example 2
Source File: AutomationReaperTaskTest.java    From SeleniumGridScaler with GNU General Public License v2.0 6 votes vote down vote up
@Test
// Tests that a node that is being tracked internally is not shut down
public void testNoShutdownNodeTracked() {
    MockVmManager ec2 = new MockVmManager();
    Reservation reservation = new Reservation();
    Instance instance = new Instance();
    String instanceId = "foo";
    AutomationContext.getContext().addNode(new AutomationDynamicNode("faky",instanceId,null,null,new Date(),1));
    instance.setInstanceId(instanceId);
    instance.setLaunchTime(AutomationUtils.modifyDate(new Date(),-5,Calendar.HOUR));
    reservation.setInstances(Arrays.asList(instance));
    ec2.setReservations(Arrays.asList(reservation));
    AutomationReaperTask task = new AutomationReaperTask(null,ec2);
    task.run();
    Assert.assertFalse("Node should NOT be terminated as it was tracked internally", ec2.isTerminated());
}
 
Example 3
Source File: MockVmManager.java    From SeleniumGridScaler with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<Instance> launchNodes(String uuid, String os, String browser, String hubHostName, int nodeCount, int maxSessions) {
    if(throwException) {
        throw new RuntimeException("Can't start nodes");
    }
    this.nodesLaunched = true;
    this.numberLaunched = nodeCount;
    this.browser = browser;
    Instance instance = new Instance();
    instance.setInstanceId("instanceId");
    List<Instance> instances = new ArrayList<Instance>();
    instances.add(instance);
    return instances;
}
 
Example 4
Source File: AutomationReaperTaskTest.java    From SeleniumGridScaler with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testShutdown() {
    MockVmManager ec2 = new MockVmManager();
    Reservation reservation = new Reservation();
    Instance instance = new Instance();
    String instanceId = "foo";
    instance.setInstanceId(instanceId);
    instance.setLaunchTime(AutomationUtils.modifyDate(new Date(),-5,Calendar.HOUR));
    reservation.setInstances(Arrays.asList(instance));
    ec2.setReservations(Arrays.asList(reservation));
    AutomationReaperTask task = new AutomationReaperTask(null,ec2);
    task.run();
    Assert.assertTrue("Node should be terminated as it was empty", ec2.isTerminated());
}
 
Example 5
Source File: AutomationReaperTaskTest.java    From SeleniumGridScaler with GNU General Public License v2.0 5 votes vote down vote up
@Test
// Tests that a node that is not old enough is not terminated
public void testNoShutdownTooRecent() {
    MockVmManager ec2 = new MockVmManager();
    Reservation reservation = new Reservation();
    Instance instance = new Instance();
    String instanceId = "foo";
    instance.setInstanceId(instanceId);
    instance.setLaunchTime(AutomationUtils.modifyDate(new Date(),-15,Calendar.MINUTE));
    reservation.setInstances(Arrays.asList(instance));
    ec2.setReservations(Arrays.asList(reservation));
    AutomationReaperTask task = new AutomationReaperTask(null,ec2);
    task.run();
    Assert.assertFalse("Node should NOT be terminated as it was not old", ec2.isTerminated());
}
 
Example 6
Source File: InstanceConverter.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Instance convertObject(com.xerox.amazonws.ec2.ReservationDescription.Instance from) {
    Instance to = new Instance();

    to.setInstanceId(from.getInstanceId());
    to.setImageId(from.getImageId());

    InstanceState state = new InstanceState();
    state.setCode(from.getStateCode());
    state.setName(from.getState());
    to.setState(state);

    to.setPrivateDnsName(from.getPrivateDnsName());
    to.setPublicDnsName(from.getDnsName());
    to.setStateTransitionReason(from.getReason());
    to.setKeyName(from.getKeyName());
    to.setAmiLaunchIndex(null);
    to.setProductCodes(null);
    to.setInstanceType(from.getInstanceType().name());
    to.setLaunchTime(from.getLaunchTime().getTime());

    Placement placement = new Placement();
    placement.setAvailabilityZone(from.getAvailabilityZone());
    placement.setGroupName(null); // 未実装
    to.setPlacement(placement);

    to.setKernelId(from.getKernelId());
    to.setRamdiskId(from.getRamdiskId());
    to.setPlatform(from.getPlatform());

    Monitoring monitoring = new Monitoring();
    monitoring.setState(Boolean.toString(from.isMonitoring()));
    to.setMonitoring(monitoring);

    // 未実装
    to.setSubnetId(null);
    to.setVpcId(null);
    to.setPrivateIpAddress(null);
    to.setPublicIpAddress(null);
    to.setStateReason(null);
    //to.setArchitecture(null);
    to.setRootDeviceName(null);
    to.setRootDeviceName(null);
    to.setBlockDeviceMappings(null);
    //to.setVirtualizationType(null);
    //to.setInstanceLifecycle(null);
    to.setSpotInstanceRequestId(null);
    //to.setLicense(null);
    to.setClientToken(null);
    to.setTags(null);

    return to;
}