当前位置: 首页>>代码示例>>Java>>正文


Java Operation类代码示例

本文整理汇总了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;
}
 
开发者ID:karamelchef,项目名称:karamel,代码行数:22,代码来源:GceLauncher.java

示例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;
}
 
开发者ID:apache,项目名称:stratos,代码行数:26,代码来源:GCEIaas.java

示例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);
}
 
开发者ID:apache,项目名称:stratos,代码行数:25,代码来源:GCEIaas.java

示例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;
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:21,代码来源:MainApp.java

示例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;
}
 
开发者ID:apache,项目名称:stratos,代码行数:33,代码来源:GCEIaas.java

示例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);
    }
}
 
开发者ID:apache,项目名称:stratos,代码行数:14,代码来源:GCEIaas.java

示例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();
}
 
开发者ID:apache,项目名称:stratos,代码行数:14,代码来源:GCEIaas.java


注:本文中的org.jclouds.googlecomputeengine.domain.Operation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。