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


Java TaskInfo.getState方法代码示例

本文整理汇总了Java中com.vmware.vim25.TaskInfo.getState方法的典型用法代码示例。如果您正苦于以下问题:Java TaskInfo.getState方法的具体用法?Java TaskInfo.getState怎么用?Java TaskInfo.getState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.vmware.vim25.TaskInfo的用法示例。


在下文中一共展示了TaskInfo.getState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: detachDiskFromVM

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
public void detachDiskFromVM() throws Exception {
    ArrayOfVirtualDevice devices = this.get
            .entityProp(this.vm, VimPath.vm_config_hardware_device);
    VirtualDisk vd = (VirtualDisk) findMatchingVirtualDevice(getListOfVirtualDisk(devices));
    if (vd == null) {
        throw new IllegalStateException(
                String.format(
                        "Matching Virtual Disk is not for disk %s.",
                        this.diskState.documentSelfLink));
    }
    // Detach the disk from VM.
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
    deviceConfigSpec.setDevice(vd);

    VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
    spec.getDeviceChange().add(deviceConfigSpec);

    ManagedObjectReference reconfigureTask = getVimPort().reconfigVMTask(this.vm, spec);
    TaskInfo info = VimUtils.waitTaskEnd(this.connection, reconfigureTask);
    if (info.getState() == TaskInfoState.ERROR) {
        VimUtils.rethrow(info.getError());
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:25,代码来源:InstanceDiskClient.java

示例2: logTaskInfo

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
private void logTaskInfo(TaskInfo info) {
    if (info == null) {
        logger.debug("Deleted task info key");
        return;
    }

    TaskInfoState state = info.getState();

    Integer progress = info.getProgress();
    if (state == TaskInfoState.SUCCESS) {
        progress = Integer.valueOf(100);
    } else if (progress == null) {
        progress = Integer.valueOf(0);
    }

    LocalizableMessage desc = info.getDescription();
    String description = desc != null ? desc.getMessage() : "";

    XMLGregorianCalendar queueT = info.getQueueTime();
    String queueTime = queueT != null
            ? queueT.toGregorianCalendar().getTime().toString() : "";

    XMLGregorianCalendar startT = info.getStartTime();
    String startTime = startT != null
            ? startT.toGregorianCalendar().getTime().toString() : "";

    XMLGregorianCalendar completeT = info.getCompleteTime();
    String completeTime = completeT != null
            ? completeT.toGregorianCalendar().getTime().toString() : "";

    logger.debug("Save task info key: " + info.getKey() + " name: "
            + info.getName() + " target: " + info.getEntityName()
            + " state: " + state.name() + " progress: " + progress
            + "% description: " + description + " queue-time: " + queueTime
            + " start-time: " + startTime + " complete-time: "
            + completeTime);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:38,代码来源:VMPropertyHandler.java

示例3: powerOffVM

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
/**
 * Power off virtual machine
 */
public static void powerOffVM(final Connection connection, final VimPortType vimPort,
        final ManagedObjectReference vm) throws Exception {
    ManagedObjectReference powerTask = vimPort.powerOffVMTask(vm);
    TaskInfo info = VimUtils.waitTaskEnd(connection, powerTask);
    if (info.getState() == TaskInfoState.ERROR) {
        VimUtils.rethrow(info.getError());
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:12,代码来源:ClientUtils.java

示例4: powerOnVM

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
/**
 * Power on virtual machine
 */
public static void powerOnVM(final Connection connection, final VimPortType vimPort,
        final ManagedObjectReference vm) throws Exception {
    ManagedObjectReference powerTask = vimPort.powerOnVMTask(vm, null);
    TaskInfo info = VimUtils.waitTaskEnd(connection, powerTask);
    if (info.getState() == TaskInfoState.ERROR) {
        VimUtils.rethrow(info.getError());
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:12,代码来源:ClientUtils.java

示例5: reconfigureBootDisk

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
/**
 * Reconfigure image disk with the customizations
 */
private void reconfigureBootDisk(ManagedObjectReference vmMoref,
        List<VirtualDeviceConfigSpec> deviceConfigSpecs) throws Exception {
    if (deviceConfigSpecs != null && !deviceConfigSpecs.isEmpty()) {
        VirtualMachineConfigSpec bootDiskSpec = new VirtualMachineConfigSpec();
        bootDiskSpec.getDeviceChange().addAll(deviceConfigSpecs);
        ManagedObjectReference task = getVimPort().reconfigVMTask(vmMoref, bootDiskSpec);
        TaskInfo info = waitTaskEnd(task);

        if (info.getState() == TaskInfoState.ERROR) {
            VimUtils.rethrow(info.getError());
        }
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:17,代码来源:InstanceClient.java

示例6: createVirtualDisk

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
/**
 * Create Virtual Disk
 */
public void createVirtualDisk() throws Exception {
    ManagedObjectReference diskManager = this.connection.getServiceContent()
            .getVirtualDiskManager();
    List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(this.diskState);

    String dsName = this.diskContext.datastoreName != null && !this.diskContext.datastoreName
            .isEmpty() ? this.diskContext.datastoreName : ClientUtils.getDefaultDatastore(this.finder);
    String diskName = getUniqueDiskName();

    // Create the parent folder before creation of the disk file
    String parentDir = String.format(VM_PATH_FORMAT, dsName, diskName);
    createParentFolder(parentDir);

    String diskFullPath = constructDiskFullPath(dsName, diskName);
    ManagedObjectReference createTask = getVimPort().createVirtualDiskTask(diskManager,
            diskFullPath, this.diskContext.datacenterMoRef,
            createVirtualDiskSpec(this.diskState, pbmSpec));
    TaskInfo info = waitTaskEnd(createTask);

    if (info.getState() == TaskInfoState.ERROR) {
        VimUtils.rethrow(info.getError());
    }

    // Update the details of the disk
    CustomProperties.of(this.diskState)
            .put(DISK_FULL_PATH, diskFullPath)
            .put(DISK_PARENT_DIRECTORY, parentDir)
            .put(DISK_DATASTORE_NAME, dsName);
    this.diskState.status = DiskService.DiskStatus.AVAILABLE;
    this.diskState.id = diskName;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:35,代码来源:DiskClient.java

示例7: deleteVirtualDisk

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
/**
 * Delete Virtual disk.
 */
public void deleteVirtualDisk()
        throws Exception {
    ManagedObjectReference diskManager = this.connection.getServiceContent()
            .getVirtualDiskManager();

    if (this.diskState.status != DiskService.DiskStatus.AVAILABLE) {
        throw new IllegalArgumentException("Only disk with status AVAILABLE can be deleted, as it is not attached to any VM.");
    }

    String diskFullPath = CustomProperties.of(this.diskState).getString(DISK_FULL_PATH, null);
    if (diskFullPath == null) {
        throw new IllegalArgumentException("Disk full path to issue delete request is empty.");
    }

    // Delete the vmdk file
    ManagedObjectReference deleteTask = getVimPort().deleteVirtualDiskTask(diskManager,
            diskFullPath, this.diskContext.datacenterMoRef);
    TaskInfo info = waitTaskEnd(deleteTask);

    if (info.getState() == TaskInfoState.ERROR) {
        VimUtils.rethrow(info.getError());
    }

    // Delete the folder that holds the vmdk file
    String dirName = CustomProperties.of(this.diskState).getString(DISK_PARENT_DIRECTORY, null);
    if (dirName != null) {
        ManagedObjectReference fileManager = this.connection.getServiceContent()
                .getFileManager();
        ManagedObjectReference deleteFile = getVimPort().deleteDatastoreFileTask(fileManager, dirName, this.diskContext
                .datacenterMoRef);
        info = waitTaskEnd(deleteFile);
        if (info.getState() == TaskInfoState.ERROR) {
            VimUtils.rethrow(info.getError());
        }
    } else {
        Utils.logWarning("Disk parent directory is null, hence couldn't cleanup disk directory in the datastore");
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:42,代码来源:DiskClient.java

示例8: handleTask

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
private void handleTask(Task task) throws DestructionException, InterruptedException, RemoteException {
    task.waitForTask();

    TaskInfo taskInfo = task.getTaskInfo();
    if (TaskInfoState.error == taskInfo.getState()) {
        throw new DestructionException(taskInfo.getError().getLocalizedMessage());
    }
}
 
开发者ID:strepsirrhini-army,项目名称:chaos-lemur,代码行数:9,代码来源:VSphereInfrastructure.java

示例9: logTaskInfo

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
private void logTaskInfo(TaskInfo info) {
    String key = info.getKey();
    String name = info.getName();
    String target = info.getEntityName();
    TaskInfoState state = info.getState();
    Integer progress = info.getProgress();
    if (state == TaskInfoState.SUCCESS) {
        progress = Integer.valueOf(100);
    } else if (progress == null) {
        progress = Integer.valueOf(0);
    }
    LocalizableMessage desc = info.getDescription();
    String description = desc != null ? desc.getMessage() : "";
    TaskReason reason = info.getReason();
    String initiatedBy = "";
    if (reason != null) {
        if (reason instanceof TaskReasonUser) {
            initiatedBy = ((TaskReasonUser) reason).getUserName();
        } else if (reason instanceof TaskReasonSystem) {
            initiatedBy = "System";
        } else if (reason instanceof TaskReasonSchedule) {
            initiatedBy = ((TaskReasonSchedule) reason).getName();
        } else if (reason instanceof TaskReasonAlarm) {
            initiatedBy = ((TaskReasonAlarm) reason).getAlarmName();
        }
    }

    XMLGregorianCalendar queueT = info.getQueueTime();
    String queueTime = queueT != null
            ? queueT.toGregorianCalendar().getTime().toString() : "";
    XMLGregorianCalendar startT = info.getStartTime();
    String startTime = startT != null
            ? startT.toGregorianCalendar().getTime().toString() : "";
    XMLGregorianCalendar completeT = info.getCompleteTime();
    String completeTime = completeT != null
            ? completeT.toGregorianCalendar().getTime().toString() : "";
    logger.debug(key + " name: " + name + " target: " + target + " state: "
            + state + " progress: " + progress + "% description: "
            + description + " initiated: " + initiatedBy + " queue-time: "
            + queueTime + " start-time: " + startTime + " complete-time: "
            + completeTime);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:43,代码来源:Actions.java

示例10: createInstanceFromSnapshot

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
public ComputeState createInstanceFromSnapshot() throws Exception {
    String message = "";
    if (this.ctx.snapshotMoRef == null) {
        message = String.format("No MoRef found for the specified snapshot %s",
              this.ctx.child.documentSelfLink);

        logger.error(message);

        this.ctx.fail(new IllegalStateException(message));
    }

    if (this.ctx.referenceComputeMoRef == null) {
        if (this.ctx.snapshotMoRef == null) {
            message = String.format("No MoRef found for the reference compute for linkedclone creation for %s.",
                  this.ctx.child.documentSelfLink);

            logger.error(message);

            this.ctx.fail(new IllegalStateException(message));
        }
    }

    VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();
    relocateSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions
            .CREATE_NEW_CHILD_DISK_BACKING.value());

    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    cloneSpec.setPowerOn(false);
    cloneSpec.setLocation(relocateSpec);
    cloneSpec.setSnapshot(this.ctx.snapshotMoRef);
    cloneSpec.setTemplate(false);

    ManagedObjectReference folder = getVmFolder();
    String displayName = this.ctx.child.name;

    ManagedObjectReference linkedCloneTask = getVimPort()
            .cloneVMTask(this.ctx.referenceComputeMoRef, folder, displayName, cloneSpec);

    TaskInfo info = waitTaskEnd(linkedCloneTask);

    if (info.getState() == TaskInfoState.ERROR) {
        MethodFault fault = info.getError().getFault();
        if (fault instanceof FileAlreadyExists) {
            // a .vmx file already exists, assume someone won the race to create the vm
            return null;
        } else {
            return VimUtils.rethrow(info.getError());
        }
    }

    ManagedObjectReference clonedVM = (ManagedObjectReference) info.getResult();
    if (clonedVM == null) {
        // vm was created by someone else
        return null;
    }
    // store reference to created vm for further processing
    this.vm = clonedVM;

    customizeAfterClone();

    ComputeState state = new ComputeState();
    state.resourcePoolLink = VimUtils
          .firstNonNull(this.ctx.child.resourcePoolLink, this.ctx.parent.resourcePoolLink);

    return state;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:67,代码来源:InstanceClient.java

示例11: cloneVm

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
private ManagedObjectReference cloneVm(ManagedObjectReference template) throws Exception {
    ManagedObjectReference folder = getVmFolder();
    List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(this.bootDisk);
    ManagedObjectReference datastore = getDataStoreForDisk(this.bootDisk, pbmSpec);
    ManagedObjectReference resourcePool = getResourcePool();

    Map<String, Object> props = this.get.entityProps(template, VimPath.vm_config_hardware_device);

    ArrayOfVirtualDevice devices = (ArrayOfVirtualDevice) props
            .get(VimPath.vm_config_hardware_device);

    VirtualDisk vd = devices.getVirtualDevice().stream()
            .filter(d -> d instanceof VirtualDisk)
            .map(d -> (VirtualDisk) d).findFirst().orElse(null);

    VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
    relocSpec.setDatastore(datastore);
    if (pbmSpec != null) {
        pbmSpec.stream().forEach(spec -> {
            relocSpec.getProfile().add(spec);
        });
    }
    relocSpec.setFolder(folder);
    relocSpec.setPool(resourcePool);
    relocSpec.setDiskMoveType(computeDiskMoveType().value());

    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    cloneSpec.setLocation(relocSpec);

    //Set the provisioning type of the parent disk.
    VirtualMachineRelocateSpecDiskLocator diskProvisionTypeLocator = setProvisioningType(vd, datastore,
            pbmSpec);
    if (diskProvisionTypeLocator != null) {
        cloneSpec.getLocation().getDisk().add(diskProvisionTypeLocator);
    }

    cloneSpec.setPowerOn(false);
    cloneSpec.setTemplate(false);

    String displayName = this.ctx.child.name;

    ManagedObjectReference cloneTask = getVimPort()
            .cloneVMTask(template, folder, displayName, cloneSpec);

    TaskInfo info = waitTaskEnd(cloneTask);

    if (info.getState() == TaskInfoState.ERROR) {
        MethodFault fault = info.getError().getFault();
        if (fault instanceof FileAlreadyExists) {
            // a .vmx file already exists, assume someone won the race to create the vm
            return null;
        } else {
            return VimUtils.rethrow(info.getError());
        }
    }

    return (ManagedObjectReference) info.getResult();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:59,代码来源:InstanceClient.java

示例12: ignoreError

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
private void ignoreError(String s, TaskInfo info) {
    if (info.getState() == TaskInfoState.ERROR) {
        logger.info(s + ": " + info.getError().getLocalizedMessage());
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:6,代码来源:InstanceClient.java

示例13: createVm

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
/**
 * Creates a VM in vsphere. This method will block until the CreateVM_Task completes. The path
 * to the .vmx file is explicitly set and its existence is iterpreted as if the VM has been
 * successfully created and returns null.
 *
 * @return
 * @throws FinderException
 * @throws Exception
 */
private ManagedObjectReference createVm() throws Exception {
    ManagedObjectReference folder = getVmFolder();
    List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(this.bootDisk);
    ManagedObjectReference datastore = getDataStoreForDisk(this.bootDisk, pbmSpec);
    ManagedObjectReference resourcePool = getResourcePool();
    ManagedObjectReference host = getHost();

    // If datastore for disk is null, if storage policy is configured pick the compatible
    // datastore from that.
    if (datastore == null) {
        ManagedObjectReference dsFromSp = getDatastoreFromStoragePolicy(this.connection,
                pbmSpec);
        datastore = dsFromSp == null ? getDatastore() : dsFromSp;
    }
    String datastoreName = this.get.entityProp(datastore, "name");
    VirtualMachineConfigSpec spec = buildVirtualMachineConfigSpec(datastoreName);

    String gt = CustomProperties.of(this.ctx.child).getString(CustomProperties.GUEST_ID, null);
    if (gt != null) {
        try {
            gt = VirtualMachineGuestOsIdentifier.valueOf(gt).value();
        } catch (IllegalArgumentException e) {
            // silently default to generic 64 bit guest.
            gt = DEFAULT_GUEST_ID.value();
        }

        spec.setGuestId(gt);
    }

    populateCloudConfig(spec, null);
    recordTimestamp(spec.getExtraConfig());
    // set the maximum snapshot limit if specified
    final String snapshotLimit = CustomProperties.of(this.ctx.child).getString(CustomProperties.SNAPSHOT_MAXIMUM_LIMIT);
    recordSnapshotLimit(spec.getExtraConfig(), snapshotLimit);

    ManagedObjectReference vmTask = getVimPort().createVMTask(folder, spec, resourcePool,
            host);

    TaskInfo info = waitTaskEnd(vmTask);

    if (info.getState() == TaskInfoState.ERROR) {
        MethodFault fault = info.getError().getFault();
        if (fault instanceof FileAlreadyExists) {
            // a .vmx file already exists, assume someone won the race to create the vm
            return null;
        } else {
            return VimUtils.rethrow(info.getError());
        }
    }

    return (ManagedObjectReference) info.getResult();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:62,代码来源:InstanceClient.java

示例14: awaitTaskEnd

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
private void awaitTaskEnd(ManagedObjectReference task) throws Exception {
    TaskInfo taskInfo = VimUtils.waitTaskEnd(this.connection, task);
    if (taskInfo.getState() == TaskInfoState.ERROR) {
        VimUtils.rethrow(taskInfo.getError());
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:7,代码来源:PowerStateClient.java

示例15: createSnapshot

import com.vmware.vim25.TaskInfo; //导入方法依赖的package包/类
private void createSnapshot(Connection connection, SnapshotContext context,
                            DeferredResult<SnapshotContext> deferredResult) {
    ManagedObjectReference vmMoRef = CustomProperties.of(context.computeDescription).getMoRef(CustomProperties.MOREF);

    if (vmMoRef == null) {
        deferredResult.fail(new IllegalStateException("Cannot find VM to snapshot"));
        return;
    }

    ManagedObjectReference task;
    TaskInfo info;
    try {
        logInfo("Creating snapshot for compute resource %s", context.computeDescription.name);
        task = connection.getVimPort()
                .createSnapshotTask(vmMoRef, context.snapshotState.name, context.snapshotState.description, context.snapshotMemory, false);
        info = VimUtils.waitTaskEnd(connection, task);
        if (info.getState() != TaskInfoState.SUCCESS) {
            VimUtils.rethrow(info.getError());
        }
    } catch (Exception e) {
        deferredResult.fail(e);
        return;
    }

    CustomProperties.of(context.snapshotState).put(CustomProperties.MOREF, (ManagedObjectReference) info.getResult());
    context.snapshotState.isCurrent = true; //mark this as current snapshot

    // create a new xenon SnapshotState
    logInfo(String.format("Creating a new snapshot state for compute : %s", context.computeDescription.name));
    Operation createSnapshotState = Operation.createPost(PhotonModelUriUtils.createInventoryUri(getHost(),
            SnapshotService.FACTORY_LINK))
            .setBody(context.snapshotState);

    if (context.existingSnapshotState != null) {
        // un-mark old snapshot as current snapshot
        context.existingSnapshotState.isCurrent = false;
        Operation patchOldSnapshot = Operation
                .createPatch(UriUtils.buildUri(getHost(), context.existingSnapshotState.documentSelfLink))
                .setBody(context.existingSnapshotState);
        OperationSequence.create(createSnapshotState)
                .next(patchOldSnapshot)
                .setCompletion((o, e) -> {
                    if (e != null && !e.isEmpty()) {
                        deferredResult.fail(e.values().iterator().next());
                    }
                    deferredResult.complete(context);
                }).sendWith(this);
    } else {
        context.computeDescription.customProperties.put(ComputeProperties.CUSTOM_PROP_COMPUTE_HAS_SNAPSHOTS, "true");
        // patch compute adding the property '_hasSnapshots' with true
        Operation patchCompute = Operation
                .createPatch(UriUtils.buildUri(getHost(), context.snapshotState.computeLink))
                .setBody(context.computeDescription);

        OperationSequence.create(createSnapshotState)
                .next(patchCompute)
                .setCompletion((o, e) -> {
                    if (e != null && !e.isEmpty()) {
                        deferredResult.fail(e.values().iterator().next());
                    }
                    logInfo(String.format("Created a new snapshot state for compute : %s", context.computeDescription.name));
                    deferredResult.complete(context);
                }).sendWith(this);
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:66,代码来源:VSphereAdapterSnapshotService.java


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