本文整理汇总了Java中org.jclouds.googlecomputeengine.domain.Operation类的典型用法代码示例。如果您正苦于以下问题:Java Operation类的具体用法?Java Operation怎么用?Java Operation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Operation类属于org.jclouds.googlecomputeengine.domain包,在下文中一共展示了Operation类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForOperation
import org.jclouds.googlecomputeengine.domain.Operation; //导入依赖的package包/类
private static int waitForOperation(OperationApi api, Operation operation) {
// TODO: configurable timeout.
// TODO: write this method using org.jclouds.util.Predicates2.retry;
int timeout = 60; // seconds
int time = 0;
while (operation != null && operation.status() != Operation.Status.DONE) {
if (time >= timeout) {
return 1;
}
time++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.warn(e);
}
operation = api.get(operation.selfLink());
}
return 0;
}
示例2: createVolume
import org.jclouds.googlecomputeengine.domain.Operation; //导入依赖的package包/类
@Override
public String createVolume(int sizeGB, String snapshotId) {
// generate a random diskname
Random rand = new Random();
String diskName = "stratos-disk-" + rand.nextInt(100000);
DiskApi diskApi = getGCEDiskApi();
String zone = getZone();
log.info("Creating volume: " + diskName + " in zone: " + zone + " of size: " + sizeGB);
try {
DiskCreationOptions diskCreationOptions = new DiskCreationOptions.Builder().sizeGb(sizeGB).sourceSnapshot
(new URI(snapshotId)).build();
Operation oper = diskApi.create(diskName, diskCreationOptions);
oper = waitGCEOperationDone(oper);
if (!oper.status().equals(Operation.Status.DONE)) {
log.error("Failed to create volume: " + diskName + " of size: " + sizeGB +
" in zone: " + zone + " operation: " + oper);
return null;
}
return diskName;
}
catch (Exception e) {
log.error("Error creating volume", e);
}
return null;
}
示例3: detachVolume
import org.jclouds.googlecomputeengine.domain.Operation; //导入依赖的package包/类
@Override
public void detachVolume(String instanceId, String volumeId) {
InstanceApi instApi = getGCEInstanceApi();
String zone = getZone();
Instance inst = instApi.get(instanceId);
log.info("Trying to detach volume: " + volumeId + " from instance: " + instanceId + " in zone: " + zone);
if (inst == null) {
log.error("Failed to find instance: " + instanceId + " in zone: " + zone);
return;
}
for (Instance.AttachedDisk disk : inst.disks()) {
if (disk.deviceName().equals(volumeId)) {
log.info("Found disk to be detached. Source: " + disk.source() + " devicename: " + disk.deviceName());
Operation oper = instApi.detachDisk(instanceId, disk.deviceName());
oper = waitGCEOperationDone(oper);
if (!oper.status().equals(Operation.Status.DONE)) {
log.error("Failed to detach volume: " + volumeId + " to instance: " + instanceId +
" in zone: " + zone + " at device: " + disk.deviceName() + " result operation: " + oper);
}
return;
}
}
log.error("Cannot find volume: " + volumeId + " in instance: " + instanceId);
}
示例4: WaitForOperation
import org.jclouds.googlecomputeengine.domain.Operation; //导入依赖的package包/类
public static int WaitForOperation(OperationApi api, Operation operation){
int timeout = 60; // seconds
int time = 0;
while (operation.status() != Operation.Status.DONE){
if (time >= timeout){
return 1;
}
time++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
operation = api.get(operation.selfLink());
}
//TODO: Check for errors.
return 0;
}
示例5: attachVolume
import org.jclouds.googlecomputeengine.domain.Operation; //导入依赖的package包/类
@Override
public String attachVolume(String instanceId, String volumeId, String deviceName) {
DiskApi diskApi = getGCEDiskApi();
InstanceApi instApi = getGCEInstanceApi();
String zone = getZone();
log.info("Trying to attach volume: " + volumeId + " to instance: " + instanceId +
" in zone: " + zone + " at devicename: " + deviceName);
Disk disk = diskApi.get(volumeId);
if (disk == null) {
log.error("Failed to get volume: " + volumeId + " in zone: " + zone);
return null;
}
log.debug("Found volumeId: " + volumeId + " volume: " + disk);
try {
Operation oper =
instApi.attachDisk(instanceId, AttachDisk.create(AttachDisk.Type.PERSISTENT, AttachDisk.Mode
.READ_WRITE, disk.selfLink(), deviceName, true, null, false, null, null));
oper = waitGCEOperationDone(oper);
if (!oper.status().equals(Operation.Status.DONE)) {
log.error("Failed to attach volume: " + volumeId + " to instance: " + instanceId +
" in zone: " + zone + " at device: " + deviceName + " operation: " + oper);
return null;
}
return volumeId;
}
catch (Exception e) {
log.error("Error attaching volume", e);
}
return null;
}
示例6: deleteVolume
import org.jclouds.googlecomputeengine.domain.Operation; //导入依赖的package包/类
@Override
public void deleteVolume(String volumeId) {
DiskApi diskApi = getGCEDiskApi();
String zone = getZone();
log.info("Deleting volume: " + volumeId + " in zone: " + zone);
Operation oper = diskApi.delete(volumeId);
oper = waitGCEOperationDone(oper);
if (!oper.status().equals(Operation.Status.DONE)) {
log.error("Failed to delete volume: " + volumeId + " in zone: " + zone +
" operation: " + oper);
}
}
示例7: waitGCEOperationDone
import org.jclouds.googlecomputeengine.domain.Operation; //导入依赖的package包/类
private Operation waitGCEOperationDone(Operation operation) {
IaasProvider iaasInfo = getIaasProvider();
Injector injector = ContextBuilder.newBuilder(iaasInfo.getProvider())
.credentials(iaasInfo.getIdentity(), iaasInfo.getCredential())
.buildInjector();
Predicate<AtomicReference<Operation>> zoneOperationDonePredicate =
injector.getInstance(Key.get(new TypeLiteral<Predicate<AtomicReference<Operation>>>() {
}, Names.named("zone")));
AtomicReference<Operation> operationReference = Atomics.newReference(operation);
retry(zoneOperationDonePredicate, MAX_WAIT_TIME, 1, SECONDS).apply(operationReference);
return operationReference.get();
}