Java 类com.amazonaws.services.ec2.model.VolumeType 实例源码

项目:photon-model    文件:AWSVolumeTypeDiscoveryService.java   
@Override
public void handleGet(Operation get) {
    Map<String, String> params = UriUtils.parseUriQueryParams(get.getUri());
    String deviceType = params.get(DEVICE_TYPE);
    if (deviceType == null || deviceType.isEmpty()) {
        get.fail(new IllegalArgumentException("No deviceType provided."));
        return;
    }
    if (!deviceType.equals(AWSConstants.AWSStorageType.EBS.name().toLowerCase())) {
        get.fail(new IllegalArgumentException("Unsupported device Type"));
        return;
    }

    VolumeTypeList volumeTypeList = new VolumeTypeList();
    for (VolumeType volumeType : VolumeType.values()) {
        volumeTypeList.volumeTypes.add(volumeType.toString());
    }

    get.setBody(volumeTypeList);
    get.complete();
}
项目:enhanced-snapshots    文件:AWSRestoreVolumeStrategyTaskExecutor.java   
private Volume creationTempVolumeStep(TaskEntry taskEntry, BackupEntry backupEntry) {
    checkThreadInterruption(taskEntry);
    setProgress(taskEntry, TaskProgress.CREATING_TEMP_VOLUME);
    Volume tempVolume;

    LOG.info("Used backup record: {}", backupEntry.getFileName());
    int size = Integer.parseInt(backupEntry.getSizeGiB());
    checkThreadInterruption(taskEntry);
    // creating temporary volume
    if (taskEntry.getTempVolumeType().equals(VolumeType.Io1.toString())) {
        tempVolume = awsCommunication.createIO1Volume(size, taskEntry.getTempVolumeIopsPerGb());
    } else {
        tempVolume = awsCommunication.createVolume(size, VolumeType.fromValue(taskEntry.getTempVolumeType()));
    }
    LOG.info("Created {} volume:{}", taskEntry.getTempVolumeType(), tempVolume.toString());
    checkThreadInterruption(taskEntry);
    awsCommunication.createTemporaryTag(tempVolume.getVolumeId(), backupEntry.getFileName());
    taskEntry.setTempVolumeId(tempVolume.getVolumeId());
    taskRepository.save(taskEntry);

    return tempVolume;
}
项目:enhanced-snapshots    文件:TaskServiceTest.java   
@Before
    public void setUp(){

        taskDto = new TaskDto();
        taskDto.setVolumes(Arrays.asList("volId-1"));

        when(configuration.getTempVolumeIopsPerGb()).thenReturn(iopsPerGb);
        when(configuration.getTempVolumeType()).thenReturn(VolumeType.Gp2.toString());
        when(configuration.getRestoreVolumeIopsPerGb()).thenReturn(iopsPerGb);
        when(configuration.getRestoreVolumeType()).thenReturn(VolumeType.Gp2.toString());
        when(configuration.getMaxQueueSize()).thenReturn(5);

        when(backupRepository.findByVolumeId(anyObject())).thenReturn(Arrays.asList(new BackupEntry()));
//        when(backupRepository.findOne(anyObject())).thenReturn(new BackupEntry());
        when(snapshotRepository.findOne((anyString()))).thenReturn(new SnapshotEntry());
    }
项目:enhanced-snapshots    文件:TaskServiceTest.java   
@Test
public void shouldSetIO1TempVolumeTypeForBackupTask(){
    taskDto.setType("backup");

    when(configuration.getTempVolumeIopsPerGb()).thenReturn(iopsPerGb);
    when(configuration.getTempVolumeType()).thenReturn(VolumeType.Io1.toString());

    taskService.createTask(taskDto);

    ArgumentCaptor<ArrayList> validTasks = ArgumentCaptor.forClass(ArrayList.class);
    verify(taskRepository).save(validTasks.capture());
    TaskEntry taskEntry = (TaskEntry) validTasks.getAllValues().get(0).get(0);

    // should set temp volume info
    Assert.assertTrue(taskEntry.getTempVolumeIopsPerGb() == iopsPerGb);
    Assert.assertTrue(taskEntry.getTempVolumeType().equals(VolumeType.Io1.toString()));
}
项目:enhanced-snapshots    文件:TaskServiceTest.java   
@Test
public void shouldSetGP2TempVolumeTypeForBackupTask(){
    taskDto.setType("backup");

    when(configuration.getTempVolumeIopsPerGb()).thenReturn(iopsPerGb);
    when(configuration.getTempVolumeType()).thenReturn(VolumeType.Gp2.toString());

    taskService.createTask(taskDto);

    ArgumentCaptor<ArrayList> validTasks = ArgumentCaptor.forClass(ArrayList.class);
    verify(taskRepository).save(validTasks.capture());
    TaskEntry taskEntry = (TaskEntry) validTasks.getAllValues().get(0).get(0);

    // should set temp volume info
    Assert.assertTrue(taskEntry.getTempVolumeIopsPerGb() == 0);
    Assert.assertTrue(taskEntry.getTempVolumeType().equals(VolumeType.Gp2.toString()));
}
项目:enhanced-snapshots    文件:TaskServiceTest.java   
@Test
public void shouldSetGP2TempVolumeTypeForRestoreTask(){
    taskDto.setType("restore");

    when(configuration.getTempVolumeIopsPerGb()).thenReturn(iopsPerGb);
    when(configuration.getTempVolumeType()).thenReturn(VolumeType.Gp2.toString());

    taskService.createTask(taskDto);

    ArgumentCaptor<ArrayList> validTasks = ArgumentCaptor.forClass(ArrayList.class);
    verify(taskRepository).save(validTasks.capture());
    TaskEntry taskEntry = (TaskEntry) validTasks.getAllValues().get(0).get(0);

    // should set temp volume info
    Assert.assertTrue(taskEntry.getTempVolumeIopsPerGb() == 0);
    Assert.assertTrue(taskEntry.getTempVolumeType().equals(VolumeType.Gp2.toString()));
}
项目:enhanced-snapshots    文件:TaskServiceTest.java   
@Test
public void shouldSetOP1TempVolumeTypeForRestoreTask(){
    taskDto.setType("restore");

    when(configuration.getTempVolumeIopsPerGb()).thenReturn(iopsPerGb);
    when(configuration.getTempVolumeType()).thenReturn(VolumeType.Io1.toString());

    taskService.createTask(taskDto);

    ArgumentCaptor<ArrayList> validTasks = ArgumentCaptor.forClass(ArrayList.class);
    verify(taskRepository).save(validTasks.capture());
    TaskEntry taskEntry = (TaskEntry) validTasks.getAllValues().get(0).get(0);

    // should set temp volume info
    Assert.assertTrue(taskEntry.getTempVolumeIopsPerGb() == iopsPerGb);
    Assert.assertTrue(taskEntry.getTempVolumeType().equals(VolumeType.Io1.toString()));

}
项目:enhanced-snapshots    文件:TaskServiceTest.java   
@Test
public void shouldSetOP1RestoreVolumeTypeForRestoreTask(){
    taskDto.setType("restore");

    when(configuration.getRestoreVolumeIopsPerGb()).thenReturn(iopsPerGb);
    when(configuration.getRestoreVolumeType()).thenReturn(VolumeType.Io1.toString());

    taskService.createTask(taskDto);

    ArgumentCaptor<ArrayList> validTasks = ArgumentCaptor.forClass(ArrayList.class);
    verify(taskRepository).save(validTasks.capture());
    TaskEntry taskEntry = (TaskEntry) validTasks.getAllValues().get(0).get(0);

    //should set restore volume info
    Assert.assertTrue(taskEntry.getRestoreVolumeIopsPerGb() == iopsPerGb);
    Assert.assertTrue(taskEntry.getRestoreVolumeType() == VolumeType.Io1.toString());
}
项目:enhanced-snapshots    文件:TaskServiceTest.java   
@Test
public void shouldSetGP2RestoreVolumeTypeForRestoreTask(){
    taskDto.setType("restore");

    when(configuration.getRestoreVolumeIopsPerGb()).thenReturn(iopsPerGb);
    when(configuration.getRestoreVolumeType()).thenReturn(VolumeType.Gp2.toString());

    taskService.createTask(taskDto);

    ArgumentCaptor<ArrayList> validTasks = ArgumentCaptor.forClass(ArrayList.class);
    verify(taskRepository).save(validTasks.capture());
    TaskEntry taskEntry = (TaskEntry) validTasks.getAllValues().get(0).get(0);

    //should set restore volume info
    Assert.assertTrue(taskEntry.getRestoreVolumeIopsPerGb() == 0);
    Assert.assertTrue(taskEntry.getRestoreVolumeType() == VolumeType.Gp2.toString());
}
项目:enhanced-snapshots    文件:AWSRestoreVolumeStrategyTaskExecutor.java   
private void restoreFromSnapshot(TaskEntry taskEntry) {
    try {
        notificationService.notifyAboutRunningTaskProgress(taskEntry.getId(), "Restore from snapshot", 20);
        String targetZone = taskEntry.getAvailabilityZone();

        String volumeId = taskEntry.getVolume();
        String snapshotId = snapshotService.getSnapshotIdByVolumeId(volumeId);
        // check that snapshot exists
        if (snapshotId == null || !awsCommunication.snapshotExists(snapshotId)) {
            LOG.error("Failed to find snapshot for volume {} ", volumeId);
            throw new DataAccessException("Backup for volume: " + volumeId + " was not found");
        }

        checkThreadInterruption(taskEntry);
        notificationService.notifyAboutRunningTaskProgress(taskEntry.getId(), "Creating volume from snapshot", 50);

        Volume volume = awsCommunication.createVolumeFromSnapshot(snapshotId, targetZone, VolumeType.fromValue(taskEntry.getRestoreVolumeType()),
                taskEntry.getRestoreVolumeIopsPerGb());
        awsCommunication.setResourceName(volume.getVolumeId(), RESTORED_NAME_PREFIX + taskEntry.getVolume());
        awsCommunication.addTag(volume.getVolumeId(), "Created by", "Enhanced Snapshots");
        setProgress(taskEntry, TaskProgress.DONE);
    } catch (EnhancedSnapshotsTaskInterruptedException e) {
        LOG.info("Restore task was canceled");
        taskRepository.delete(taskEntry);
        mailService.notifyAboutSystemStatus("Restore task for volume with id" + taskEntry.getVolume() + " was canceled");
        setProgress(taskEntry, TaskProgress.DONE);
    }
}
项目:enhanced-snapshots    文件:AWSRestoreVolumeStrategyTaskExecutor.java   
private Volume moveToTargetZoneStep(TaskEntry taskEntry) {
    checkThreadInterruption(taskEntry);
    notificationService.notifyAboutRunningTaskProgress(taskEntry.getId(), "Moving into target zone...", 95);

    return awsCommunication.createVolumeFromSnapshot(taskEntry.getTempSnapshotId(), taskEntry.getAvailabilityZone(),
            VolumeType.fromValue(taskEntry.getRestoreVolumeType()), taskEntry.getRestoreVolumeIopsPerGb());
}
项目:enhanced-snapshots    文件:TaskServiceImpl.java   
private void setTempVolumeAndIops(TaskEntry taskEntry){
    if(taskEntry.getType().equals(TaskEntry.TaskEntryType.RESTORE.getType()) || taskEntry.getType().equals(TaskEntry.TaskEntryType.BACKUP.getType())){
        taskEntry.setTempVolumeType(configurationMediator.getTempVolumeType());
        if (configurationMediator.getTempVolumeType().equals(VolumeType.Io1.toString())) {
            taskEntry.setTempVolumeIopsPerGb(configurationMediator.getTempVolumeIopsPerGb());
        }
    }
}
项目:enhanced-snapshots    文件:TaskServiceImpl.java   
private void setRestoreVolumeTypeAndIops(TaskEntry taskEntry){
    if(taskEntry.getType().equals(TaskEntry.TaskEntryType.RESTORE.getType())){
        taskEntry.setRestoreVolumeType(configurationMediator.getRestoreVolumeType());
        if (configurationMediator.getRestoreVolumeType().equals(VolumeType.Io1.toString())) {
            taskEntry.setRestoreVolumeIopsPerGb(configurationMediator.getRestoreVolumeIopsPerGb());
        }
    }
}
项目:s3-bucket-loader    文件:Ec2Util.java   
public List<Instance> launchEc2Instances(AmazonEC2Client ec2Client, Properties props) throws Exception {

    Integer totalExpectedWorkers = Integer.valueOf(props.getProperty("master.workers.total"));

    // disk size
    Collection<BlockDeviceMapping> blockDevices = new ArrayList<BlockDeviceMapping>();
    blockDevices.add(
            new BlockDeviceMapping()
                .withDeviceName(props.getProperty("master.workers.ec2.disk.deviceName"))
                .withEbs(new EbsBlockDevice()
                        .withVolumeType(VolumeType.valueOf(props.getProperty("master.workers.ec2.disk.volumeType")))
                        .withDeleteOnTermination(true)
                        .withVolumeSize(Integer.valueOf(props.getProperty("master.workers.ec2.disk.size.gigabytes")))));

    // create our run request for the total workers we expect
    RunInstancesRequest runInstancesRequest = new RunInstancesRequest();
    runInstancesRequest.withImageId(props.getProperty("master.workers.ec2.ami.id"))
                        .withInstanceType(props.getProperty("master.workers.ec2.instanceType"))
                        .withMinCount(totalExpectedWorkers)
                        .withMaxCount(totalExpectedWorkers)
                        .withBlockDeviceMappings(blockDevices)
                        .withKeyName(props.getProperty("master.workers.ec2.keyName"))
                        .withSecurityGroupIds(props.getProperty("master.workers.ec2.securityGroupId"))
                        .withInstanceInitiatedShutdownBehavior(ShutdownBehavior.valueOf(props.getProperty("master.workers.ec2.shutdownBehavior")))
                        .withSubnetId(props.getProperty("master.workers.ec2.subnetId"))
                        .withUserData(Base64.encodeAsString(readFile(props.getProperty("master.workers.ec2.userDataFile")).getBytes()));

    // launch
    logger.debug("Launching " + totalExpectedWorkers + " EC2 instances, " +
                        "it may take few minutes for workers to come up...: \n" +
                        "\tamiId:" + runInstancesRequest.getImageId() +"\n"+
                        "\tsecGrpId:" + runInstancesRequest.getSecurityGroupIds().get(0) +"\n"+
                        "\tsubnetId:" + runInstancesRequest.getSubnetId() +"\n"+
                        "\tinstanceType:" + runInstancesRequest.getInstanceType() +"\n"+
                        "\tshutdownBehavior:" + runInstancesRequest.getInstanceInitiatedShutdownBehavior() +"\n"+
                        "\tkeyName:" + runInstancesRequest.getKeyName() 
                        );


    // as the instances come up, assuming the "userData" above launches the worker we will be good
    // they will auto register w/ us the master 
    RunInstancesResult result = ec2Client.runInstances(runInstancesRequest);
    Reservation reservation = result.getReservation();
    return reservation.getInstances();
}