@Override public MonitorInstancesResult monitorInstances(MonitorInstancesRequest monitorInstancesRequest) { MonitorInstancesResult result = new MonitorInstancesResult(); if (!monitorInstancesRequest.getInstanceIds().isEmpty()) { Collection<InstanceMonitoring> coll = new ArrayList(); Iterator it = monitorInstancesRequest.getInstanceIds().iterator(); while (it.hasNext()) { String id = (String) it.next(); InstanceMonitoring mon = new InstanceMonitoring(); mon.setInstanceId(id); Monitoring monitoring = new Monitoring(); monitoring.setState(MonitoringState.Enabled); mon.setMonitoring(monitoring); coll.add(mon); } result.setInstanceMonitorings(coll); } return result; }
@Override public UnmonitorInstancesResult unmonitorInstances(UnmonitorInstancesRequest unmonitorInstancesRequest) { UnmonitorInstancesResult result = new UnmonitorInstancesResult(); if (!unmonitorInstancesRequest.getInstanceIds().isEmpty()) { Collection<InstanceMonitoring> coll = new ArrayList(); Iterator it = unmonitorInstancesRequest.getInstanceIds().iterator(); while (it.hasNext()) { String id = (String) it.next(); InstanceMonitoring mon = new InstanceMonitoring(); mon.setInstanceId(id); Monitoring monitoring = new Monitoring(); monitoring.setState(MonitoringState.Disabled); mon.setMonitoring(monitoring); coll.add(mon); } result.setInstanceMonitorings(coll); } return result; }
@Test public void convertCompleteInstance() { DateTime launchTime = UtcTime.now(); Instance instance = new Instance().withInstanceId("i-1") .withState(new InstanceState().withName(InstanceStateName.Running)).withPublicIpAddress("1.2.3.4") .withPrivateIpAddress("1.2.3.5").withInstanceType(InstanceType.M1Small) .withLaunchTime(launchTime.toDate()) .withMonitoring(new Monitoring().withState(MonitoringState.Disabled)).withHypervisor(HypervisorType.Xen) .withPlacement(new Placement("us-east-1c")); Machine machine = convert(instance); assertThat(machine.getId(), is(instance.getInstanceId())); assertThat(machine.getLaunchTime(), is(launchTime)); assertThat(machine.getMachineState(), is(MachineState.RUNNING)); assertThat(machine.getCloudProvider(), is(CloudProviders.AWS_EC2)); assertThat(machine.getRegion(), is("us-east-1")); assertThat(machine.getMachineSize(), is("m1.small")); assertThat(machine.getMembershipStatus(), is(MembershipStatus.defaultStatus())); assertThat(machine.getServiceState(), is(ServiceState.UNKNOWN)); assertThat(machine.getPublicIps().size(), is(1)); assertThat(machine.getPublicIps().get(0), is(instance.getPublicIpAddress())); assertThat(machine.getPrivateIps().size(), is(1)); assertThat(machine.getPrivateIps().get(0), is(instance.getPrivateIpAddress())); assertThat(machine.getMetadata(), is(JsonUtils.toJson(instance))); }
@Test public void convertInstanceMissingPublicIp() { DateTime launchTime = UtcTime.now(); Instance instance = new Instance().withInstanceId("i-1") .withState(new InstanceState().withName(InstanceStateName.Running)).withPrivateIpAddress("1.2.3.5") .withInstanceType(InstanceType.M1Small).withLaunchTime(launchTime.toDate()) .withMonitoring(new Monitoring().withState(MonitoringState.Disabled)).withHypervisor(HypervisorType.Xen) .withPlacement(new Placement("us-east-1a")); Machine machine = convert(instance); assertThat(machine.getId(), is(instance.getInstanceId())); assertThat(machine.getCloudProvider(), is(CloudProviders.AWS_EC2)); assertThat(machine.getRegion(), is("us-east-1")); assertThat(machine.getMachineSize(), is("m1.small")); assertThat(machine.getLaunchTime(), is(launchTime)); assertThat(machine.getMachineState(), is(MachineState.RUNNING)); assertThat(machine.getMembershipStatus(), is(MembershipStatus.defaultStatus())); assertThat(machine.getServiceState(), is(ServiceState.UNKNOWN)); assertThat(machine.getPublicIps().size(), is(0)); assertThat(machine.getPrivateIps().size(), is(1)); assertThat(machine.getPrivateIps().get(0), is(instance.getPrivateIpAddress())); assertThat(machine.getMetadata(), is(JsonUtils.toJson(instance))); }
@Test public void convertInstanceMissingPrivateIp() { DateTime launchTime = UtcTime.now(); Instance instance = new Instance().withInstanceId("i-1") .withState(new InstanceState().withName(InstanceStateName.Running)).withPublicIpAddress("1.2.3.4") .withInstanceType(InstanceType.M1Medium).withLaunchTime(launchTime.toDate()) .withMonitoring(new Monitoring().withState(MonitoringState.Disabled)).withHypervisor(HypervisorType.Xen) .withPlacement(new Placement("us-east-1b")); Machine machine = convert(instance); assertThat(machine.getId(), is(instance.getInstanceId())); assertThat(machine.getCloudProvider(), is(CloudProviders.AWS_EC2)); assertThat(machine.getRegion(), is("us-east-1")); assertThat(machine.getMachineSize(), is("m1.medium")); assertThat(machine.getLaunchTime(), is(launchTime)); assertThat(machine.getMachineState(), is(MachineState.RUNNING)); assertThat(machine.getMembershipStatus(), is(MembershipStatus.defaultStatus())); assertThat(machine.getServiceState(), is(ServiceState.UNKNOWN)); assertThat(machine.getPublicIps().size(), is(1)); assertThat(machine.getPublicIps().get(0), is(instance.getPublicIpAddress())); assertThat(machine.getPrivateIps().size(), is(0)); assertThat(machine.getMetadata(), is(JsonUtils.toJson(instance))); }
@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; }
@Override public Monitoring getMonitoring() { return (Monitoring) resource.getAttribute("Monitoring"); }
/** * Gets the value of the Monitoring attribute. If this resource is not yet * loaded, a call to {@code load()} is made to retrieve the value of the * attribute. */ Monitoring getMonitoring();