1. Help Center
  2. CLI
  3. Developer Guide
  4. SDK
  5. JAVA
  6. EVS Java SDK Demo

EVS Java SDK Demo

Elastic Volume Service (EVS) disks are scalable virtual block storage devices designed based on the distributed architecture. You can create EVS disks online and attach them to ECSs. The method for using EVS disks is the same as that for using hard disks on physical servers. Compared with traditional hard disks, EVS disks have higher data reliability and I/O throughput capabilities. They are also easier to use. EVS disks apply to file systems, databases, and system software and applications that require block storage devices.

Creating a Volume

You can create a volume using OpenStack4j based on the following code. The volume can be attached to the ECS only when the volume is in the available status.

Volume volume = os.blockStorage().volumes() 
// wait until volume status available 
int createVolumeCount = 1; 
boolean createVolumeFlag = false; 
while (createVolumeCount < 120) { 
if (os.blockStorage().volumes().get(volume.getId()).getStatus().toString().equals("available")) { 
System.out.println("volume Created successfully"); 
createVolumeFlag = true; 
if (!createVolumeFlag) { 
System.out.println("Volume created failure"); 

Attaching a Volume to the ECS

You can attach the volume to the ECS using OpenStack4j based on the following code. The attachment operation is successful after the volume is in the in-use status.

//after volume is available, attach to server 
VolumeAttachment attachResult = os.compute().servers().attachVolume(server.getId(), volume.getId(), 
//adjust if attached successfully 
int i = 1; 
boolean attachStatus = false; 
while (i < 10) { 
if (os.blockStorage().volumes().get(volume.getId()).getStatus().toString().equals("in-use")) { 
attachStatus = true; 
System.out.println("volume attached successfully to " + os.compute().servers().get(server.getId()).getName()); 
if (!attachStatus) { 
System.out.println("attach failed"); 

Detaching a Volume from the ECS

You can detach the volume from the ECS based on the following code. Detachment execution takes some time, and the volume can be deleted only when the volume is detached.

ActionResponse detachResult = os.compute().servers().detachVolume(server.getId(), attachResult.getId()); 
int detachCount = 1; 
boolean detachStatus = false; 
while (detachCount < 60) { 
if (os.blockStorage().volumes().get(volume.getId()).getStatus().toString().equals("available")) { 
detachStatus = true; 
System.out.println("volume detached successfully to " ); 
if (!detachStatus) { 
System.out.println("detach failed"); 

Deleting a Volume

You can delete a volume using OpenStack4j based on the following code.

//after detached. delete the volume 
ActionResponse deletVolumeResult = os.blockStorage().volumes().delete(volume.getId()); 
System.out.println("Delete volume result" + deletVolumeResult);