@Override public void modifyInstanceAttribute(AmazonEC2Client ec2Client, ModifyInstanceAttributeRequest modifyInstanceAttributeRequest) { if (modifyInstanceAttributeRequest.getGroups() != null && modifyInstanceAttributeRequest.getGroups().get(0).equals(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION)) { throw new AmazonServiceException(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION); } if (modifyInstanceAttributeRequest.getGroups() != null && modifyInstanceAttributeRequest.getGroups().get(0).equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) { AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception"); throttlingException.setErrorCode("ThrottlingException"); throw throttlingException; } }
/** * Adds the security groups to an EC2 instance. * * @param ec2InstanceId the ec2 instance id. * @param securityGroups security groups to be added. * @param awsParams awsParamsDto object * * @return updated security groups. */ @Override public List<String> addSecurityGroupsToEc2Instance(String ec2InstanceId, List<String> securityGroups, AwsParamsDto awsParams) { Set<String> updatedSecurityGroups = new HashSet<>(); for (String securityGroup : securityGroups) { updatedSecurityGroups.add(securityGroup); } // Get existing security groups DescribeInstanceAttributeRequest describeInstanceAttributeRequest = new DescribeInstanceAttributeRequest().withInstanceId(ec2InstanceId).withAttribute(InstanceAttributeName.GroupSet); DescribeInstanceAttributeResult describeInstanceAttributeResult = ec2Operations.describeInstanceAttribute(getEc2Client(awsParams), describeInstanceAttributeRequest); List<GroupIdentifier> groups = describeInstanceAttributeResult.getInstanceAttribute().getGroups(); for (GroupIdentifier groupIdentifier : groups) { updatedSecurityGroups.add(groupIdentifier.getGroupId()); } // Add security group on master EC2 instance ModifyInstanceAttributeRequest modifyInstanceAttributeRequest = new ModifyInstanceAttributeRequest().withInstanceId(ec2InstanceId).withGroups(updatedSecurityGroups); ec2Operations.modifyInstanceAttribute(getEc2Client(awsParams), modifyInstanceAttributeRequest); return new ArrayList<>(updatedSecurityGroups); }
public void modifyInstanceAttributes(String instanceId, Attribute... attributes) { checkState(!isNullOrEmpty(instanceId)); // InstanceState instanceState = // ec2_.describeInstanceStatus(new DescribeInstanceStatusRequest().withInstanceIds(instanceId)).getInstanceStatuses().get(0).getInstanceState(); // // final InstanceStateType stateType = InstanceStateType.valueOfFrom(instanceState.getName()); // boolean isRunning = InstanceStateType.RUNNING.equals(stateType); // // if (isRunning) // { this.stop(instanceId); // } for (Attribute attribute : attributes) { if (attribute != null && !isNullOrEmpty(attribute.getName())) { ModifyInstanceAttributeRequest request = new ModifyInstanceAttributeRequest() .withInstanceId(instanceId) .withAttribute(attribute.getName()); if (!isNullOrEmpty(attribute.getValue())) { request.setValue(attribute.getValue()); } ec2_.modifyInstanceAttribute(request); } } // if (isRunning) // { this.startInstances(instanceId); // } }
@Override public void modifyAttribute(String attribute, ResultCapture<Void> extractor) { ModifyInstanceAttributeRequest request = new ModifyInstanceAttributeRequest() .withAttribute(attribute); modifyAttribute(request, extractor); }
@Override public void modifyInstanceAttribute(ModifyInstanceAttributeRequest modifyInstanceAttributeRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
/** * Adds a delete on termination flag to all volumes in an {@code InstanceEbsVolumes} list * that have the ATTACHED status. This makes sure that the volumes associated with the * instance will be automatically cleaned up upon instance termination. * * @param instanceEbsVolumesList list of instances along with their associated volumes */ public void addDeleteOnTerminationFlag(List<InstanceEbsVolumes> instanceEbsVolumesList) { Set<String> volumesToFlag = getAllVolumeIdsWithStatus(instanceEbsVolumesList, InstanceEbsVolumes.Status.ATTACHED); if (!volumesToFlag.isEmpty()) { for (InstanceEbsVolumes instanceEbsVolumes : instanceEbsVolumesList) { String ec2InstanceId = instanceEbsVolumes.getEc2InstanceId(); DescribeInstanceAttributeRequest instanceAttributeRequest = new DescribeInstanceAttributeRequest() .withAttribute(InstanceAttributeName.BlockDeviceMapping) .withInstanceId(ec2InstanceId); List<InstanceBlockDeviceMapping> blockDeviceMappings = client.describeInstanceAttribute(instanceAttributeRequest) .getInstanceAttribute() .getBlockDeviceMappings(); for (InstanceBlockDeviceMapping blockDeviceMapping : blockDeviceMappings) { String volumeId = blockDeviceMapping.getEbs().getVolumeId(); // The block device mapping may have volumes associated with it that were not // provisioned by us. We skip marking those volumes for deletion. if (!volumesToFlag.contains(volumeId)) { continue; } InstanceBlockDeviceMappingSpecification updatedSpec = new InstanceBlockDeviceMappingSpecification() .withEbs( new EbsInstanceBlockDeviceSpecification() .withDeleteOnTermination(true) .withVolumeId(volumeId) ) .withDeviceName(blockDeviceMapping.getDeviceName()); ModifyInstanceAttributeRequest modifyRequest = new ModifyInstanceAttributeRequest() .withBlockDeviceMappings(updatedSpec) .withInstanceId(ec2InstanceId); client.modifyInstanceAttribute(modifyRequest); } } } }
/** * Modify EC2 instance attributes */ @Override public void modifyInstanceAttribute(AmazonEC2Client ec2Client, ModifyInstanceAttributeRequest modifyInstanceAttributeRequest) { ec2Client.modifyInstanceAttribute(modifyInstanceAttributeRequest); }
/** * Attaches volume(s) for EBS. * @return true if successful attachment, or nothing to do. false otherwise */ private boolean attachVolumes() { // If volume is found in map, it has been successfully created (no need to check here) for( Map.Entry<String,String> entry : this.storageIdToVolumeId.entrySet()) { String volumeId = entry.getValue(); String storageId = entry.getKey(); // Give a name to the volume before attaching String nameTemplate = Ec2IaasHandler.findStorageProperty(this.targetProperties, storageId, VOLUME_NAME_PREFIX); String name = Ec2IaasHandler.expandVolumeName( nameTemplate, this.applicationName, this.scopedInstance.getName()); if(Utils.isEmptyOrWhitespaces(name)) name = "Created by Roboconf for " + this.tagName; tagResource(volumeId, name); // Attach volume now String mountPoint = Ec2IaasHandler.findStorageProperty(this.targetProperties, storageId, VOLUME_MOUNT_POINT_PREFIX); if(Utils.isEmptyOrWhitespaces(mountPoint)) mountPoint = "/dev/sdf"; AttachVolumeRequest attachRequest = new AttachVolumeRequest() .withInstanceId(this.machineId) .withDevice(mountPoint) .withVolumeId(volumeId); try { this.ec2Api.attachVolume(attachRequest); } catch(Exception e) { this.logger.warning("EBS Volume attachment error: " + e); } // Set deleteOnTermination flag ? if(Boolean.parseBoolean(Ec2IaasHandler.findStorageProperty(this.targetProperties, storageId, VOLUME_DELETE_OT_PREFIX))) { EbsInstanceBlockDeviceSpecification ebsSpecification = new EbsInstanceBlockDeviceSpecification() .withVolumeId(volumeId) .withDeleteOnTermination(true); InstanceBlockDeviceMappingSpecification mappingSpecification = new InstanceBlockDeviceMappingSpecification() .withDeviceName(mountPoint) .withEbs(ebsSpecification); ModifyInstanceAttributeRequest request = new ModifyInstanceAttributeRequest() .withInstanceId(this.machineId) .withBlockDeviceMappings(mappingSpecification); this.ec2Api.modifyInstanceAttribute(request); } } return true; }
@Override public void modifyAttribute(ModifyInstanceAttributeRequest request) { modifyAttribute(request, null); }
@Override public void modifyAttribute(ModifyInstanceAttributeRequest request, ResultCapture<Void> extractor) { resource.performAction("ModifyAttribute", request, extractor); }
/** * {@link AmazonEC2#modifyInstanceAttribute(ModifyInstanceAttributeRequest)} * * @param ec2Client {@link AmazonEC2} to use. * @param modifyInstanceAttributeRequest The request object. */ public void modifyInstanceAttribute(AmazonEC2Client ec2Client, ModifyInstanceAttributeRequest modifyInstanceAttributeRequest);
/** * Performs the <code>ModifyAttribute</code> action. * * <p> * The following request parameters will be populated from the data of this * <code>Instance</code> resource, and any conflicting parameter value set * in the request will be overridden: * <ul> * <li> * <b><code>InstanceId</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @see ModifyInstanceAttributeRequest */ void modifyAttribute(ModifyInstanceAttributeRequest request);
/** * Performs the <code>ModifyAttribute</code> action and use a ResultCapture * to retrieve the low-level client response. * * <p> * The following request parameters will be populated from the data of this * <code>Instance</code> resource, and any conflicting parameter value set * in the request will be overridden: * <ul> * <li> * <b><code>InstanceId</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @see ModifyInstanceAttributeRequest */ void modifyAttribute(ModifyInstanceAttributeRequest request, ResultCapture<Void> extractor);