Search in sources :

Example 16 with SnapshotState

use of com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState in project photon-model by vmware.

the class VSphereVMSnapshotEnumerationHelper method updateSnapshot.

static DeferredResult<SnapshotState> updateSnapshot(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, VmOverlay vm, SnapshotState oldState, SnapshotState newState, String id) {
    newState.documentSelfLink = oldState.documentSelfLink;
    newState.id = id;
    newState.regionId = enumerationProgress.getRegionId();
    DeferredResult<SnapshotState> res = new DeferredResult<>();
    VsphereEnumerationHelper.submitWorkToVSpherePool(service, () -> {
        VsphereEnumerationHelper.populateTags(service, enumerationProgress, vm, newState);
        newState.tenantLinks = enumerationProgress.getTenantLinks();
        service.logFine(() -> String.format("Syncing snapshot %s", oldState.name));
        Operation opPatchSnapshot = Operation.createPatch(UriUtils.buildUri(service.getHost(), oldState.documentSelfLink)).setBody(newState);
        service.sendWithDeferredResult(opPatchSnapshot, SnapshotState.class).handle((snap, e) -> {
            if (e != null) {
                res.fail(e);
            } else {
                res.complete(snap);
            }
            return null;
        });
    });
    return res;
}
Also used : SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) Operation(com.vmware.xenon.common.Operation) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 17 with SnapshotState

use of com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState in project photon-model by vmware.

the class VSphereVMSnapshotEnumerationHelper method constructSnapshot.

static SnapshotState constructSnapshot(VSphereIncrementalEnumerationService service, VirtualMachineSnapshotTree current, String parentLink, String vmSelfLink, EnumerationProgress enumerationProgress, VmOverlay vm) {
    SnapshotState snapshot = new SnapshotState();
    snapshot.computeLink = vmSelfLink;
    snapshot.parentLink = parentLink;
    snapshot.description = current.getDescription();
    // TODO how to determine if the snapshot is current
    // snapshot.isCurrent = current.isQuiesced()
    snapshot.creationTimeMicros = current.getCreateTime().toGregorianCalendar().getTimeInMillis();
    // TODO How to fetch custom properties
    // snapshot.customProperties = current.get
    // TODO what are snapshot grouplinks
    // snapshot.groupLinks
    snapshot.name = current.getName();
    snapshot.regionId = enumerationProgress.getRegionId();
    snapshot.id = current.getId().toString();
    VsphereEnumerationHelper.populateTags(service, enumerationProgress, vm, snapshot);
    snapshot.tenantLinks = enumerationProgress.getTenantLinks();
    if (snapshot.endpointLinks == null) {
        snapshot.endpointLinks = new HashSet<>();
    }
    snapshot.endpointLinks.add(enumerationProgress.getRequest().endpointLink);
    CustomProperties.of(snapshot).put(CustomProperties.MOREF, VimUtils.convertMoRefToString(current.getSnapshot())).put(CustomProperties.DATACENTER_SELF_LINK, enumerationProgress.getDcLink()).put(CustomProperties.TYPE, current.getSnapshot().getType());
    VsphereEnumerationHelper.populateResourceStateWithAdditionalProps(snapshot, enumerationProgress.getVcUuid());
    return snapshot;
}
Also used : SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState)

Aggregations

SnapshotState (com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState)17 Operation (com.vmware.xenon.common.Operation)10 QueryTask (com.vmware.xenon.services.common.QueryTask)9 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)8 QueryResultsProcessor (com.vmware.xenon.common.QueryResultsProcessor)8 DeferredResult (com.vmware.xenon.common.DeferredResult)7 ArrayList (java.util.ArrayList)7 ResourceOperationRequest (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest)6 List (java.util.List)6 TestRequestSender (com.vmware.xenon.common.test.TestRequestSender)5 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)4 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)4 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)4 TaskInfo (com.vmware.vim25.TaskInfo)4 UriUtils (com.vmware.xenon.common.UriUtils)4 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)3 IAAS_API_ENABLED (com.vmware.photon.controller.model.UriPaths.IAAS_API_ENABLED)3 ResourceOperationSpecService (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService)3 TargetCriteria (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.TargetCriteria)3 ResourceOperationUtils.handleAdapterResourceOperationRegistration (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.handleAdapterResourceOperationRegistration)3