use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class VSphereVMSnapshotEnumerationHelper method processSnapshot.
static void processSnapshot(VSphereIncrementalEnumerationService service, VirtualMachineSnapshotTree current, String parentLink, EnumerationProgress enumerationProgress, VmOverlay vm, String vmSelfLink) {
enumerationProgress.getSnapshotTracker().register();
QueryTask task = queryForSnapshot(enumerationProgress, current.getId().toString(), vmSelfLink);
VsphereEnumerationHelper.withTaskResults(service, task, (ServiceDocumentQueryResult result) -> {
VsphereEnumerationHelper.submitWorkToVSpherePool(service, () -> {
SnapshotState snapshotState = constructSnapshot(service, current, parentLink, vmSelfLink, enumerationProgress, vm);
if (result.documentLinks.isEmpty()) {
VSphereVirtualMachineEnumerationHelper.createSnapshot(service, snapshotState).thenCompose(createdSnapshotState -> trackAndProcessChildSnapshots(service, current, enumerationProgress, vm, vmSelfLink, createdSnapshotState)).whenComplete((ss, e) -> {
if (e != null) {
service.log(Level.SEVERE, "Creation of snapshot with name {%s} failed.", snapshotState.name);
}
enumerationProgress.getSnapshotTracker().arrive();
});
} else {
SnapshotState oldState = VsphereEnumerationHelper.convertOnlyResultToDocument(result, SnapshotState.class);
updateSnapshot(service, enumerationProgress, vm, oldState, snapshotState, current.getId().toString()).thenCompose(updatedSnapshotState -> trackAndProcessChildSnapshots(service, current, enumerationProgress, vm, vmSelfLink, updatedSnapshotState)).whenComplete((ss, e) -> {
if (e != null) {
service.logSevere("Updating of snapshot with name {%s}, selfLink {%s} failed", snapshotState.name, oldState.documentSelfLink);
}
enumerationProgress.getSnapshotTracker().arrive();
});
}
});
});
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class VsphereFolderEnumerationHelper method processFoundFolder.
static void processFoundFolder(VSphereIncrementalEnumerationService service, EnumerationProgress ctx, FolderOverlay folder, List<FolderOverlay> rootFolders, EnumerationClient client) {
QueryTask task = queryForFolder(ctx, folder);
withTaskResults(service, task, (ServiceDocumentQueryResult result) -> {
try {
if (result.documentLinks.isEmpty()) {
createFolder(service, ctx, folder, rootFolders, client);
} else {
ResourceGroupState oldDocument = convertOnlyResultToDocument(result, ResourceGroupState.class);
updateFolder(service, ctx, folder, oldDocument, rootFolders, client, true);
}
} catch (Exception e) {
service.logSevere("Error occurred while processing folder!", e);
ctx.getFolderTracker().track(folder.getId(), ResourceTracker.ERROR);
}
});
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class VsphereStoragePolicyEnumerationHelper method updateStorageDescription.
static void updateStorageDescription(VSphereIncrementalEnumerationService service, Stream<Operation> opStream, String spSelfLink, ServiceDocumentQueryResult result) {
List<Operation> patchOps = new ArrayList<>();
List<String> originalLinks = new ArrayList<>();
if (result.documentLinks != null) {
originalLinks.addAll(result.documentLinks);
}
opStream.forEach(op -> {
StorageDescription storageDescription = op.getBody(StorageDescription.class);
if (result.documentLinks != null && result.documentLinks.contains(storageDescription.documentSelfLink)) {
originalLinks.remove(storageDescription.documentSelfLink);
} else {
if (storageDescription.groupLinks == null) {
storageDescription.groupLinks = new HashSet<>();
}
storageDescription.groupLinks.add(spSelfLink);
patchOps.add(Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), storageDescription.documentSelfLink)).setBody(storageDescription));
}
});
// In this case, we need to update the datastore by removing the policy group link
if (!originalLinks.isEmpty()) {
originalLinks.stream().forEach(link -> {
Map<String, Collection<Object>> collectionsToRemove = Collections.singletonMap(ResourceState.FIELD_NAME_GROUP_LINKS, Collections.singletonList(spSelfLink));
ServiceStateCollectionUpdateRequest updateGroupLinksRequest = ServiceStateCollectionUpdateRequest.create(null, collectionsToRemove);
patchOps.add(Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), link)).setBody(updateGroupLinksRequest));
});
}
if (!patchOps.isEmpty()) {
OperationJoin.create(patchOps).setCompletion((ops, exs) -> {
if (exs != null) {
service.logFine(() -> String.format("Syncing Storage policy failed %s", Utils.toString(exs)));
}
}).sendWith(service);
}
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class VSphereNetworkEnumerationHelper method processFoundNetwork.
public static void processFoundNetwork(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, NetworkOverlay net, MoRefKeyedMap<NetworkOverlay> allNetworks) {
if (net.getParentSwitch() != null) {
// portgroup: create subnet
QueryTask task = queryForSubnet(enumerationProgress, net, net.getParentSwitch());
withTaskResults(service, task, (ServiceDocumentQueryResult result) -> {
if (result.documentLinks.isEmpty()) {
createNewSubnet(service, enumerationProgress, net, allNetworks.get(net.getParentSwitch()).getDvsUuid());
} else {
SubnetState oldDocument = convertOnlyResultToDocument(result, SubnetState.class);
updateSubnet(service, oldDocument, enumerationProgress, net, true);
}
});
} else {
// DVS or opaque network
QueryTask task = queryForNetwork(enumerationProgress, net);
withTaskResults(service, task, result -> {
if (result.documentLinks.isEmpty()) {
createNewNetwork(service, enumerationProgress, net);
} else {
NetworkState oldDocument = convertOnlyResultToDocument(result, NetworkState.class);
updateNetwork(service, oldDocument, enumerationProgress, net);
}
});
}
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class VSphereNetworkEnumerationHelper method handleNetworkChanges.
/**
* Handles incremental changes on networks.
*
* @param service the incremental service
* @param networks the filtered network overlays
* @param enumerationProgress the context for enumeration.
* @param client the enumeration client
*/
public static void handleNetworkChanges(VSphereIncrementalEnumerationService service, MoRefKeyedMap<NetworkOverlay> networks, EnumerationProgress enumerationProgress, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
enumerationProgress.expectNetworkCount(networks.values().size());
for (NetworkOverlay netOverlay : networks.values()) {
// if a network | DVS | DV port group is added.
if (ObjectUpdateKind.ENTER == netOverlay.getObjectUpdateKind()) {
// if DV port group is added
if (netOverlay.getParentSwitch() != null) {
// check if the parent switch is present as part of this enumeration
NetworkOverlay parentSwitch = networks.get(netOverlay.getParentSwitch());
String dvsUUID;
if (parentSwitch == null) {
// retrieve the uuid from vCenter
dvsUUID = client.getUUIDForDVS(netOverlay);
} else {
dvsUUID = parentSwitch.getDvsUuid();
}
createNewSubnet(service, enumerationProgress, netOverlay, dvsUUID);
} else {
createNewNetwork(service, enumerationProgress, netOverlay);
}
} else {
// if DV port group is changed
if (netOverlay.getId().getType().equals(VimNames.TYPE_PORTGROUP)) {
ManagedObjectReference parentSwitch = netOverlay.getParentSwitch();
// if parent is not retrieved, Retrieve it.
if (null == parentSwitch && ObjectUpdateKind.MODIFY.equals(netOverlay.getObjectUpdateKind())) {
parentSwitch = client.getParentSwitchForDVPortGroup(netOverlay.getId());
}
QueryTask task = queryForSubnet(enumerationProgress, netOverlay, parentSwitch);
withTaskResults(service, task, (ServiceDocumentQueryResult result) -> {
if (!result.documentLinks.isEmpty()) {
SubnetState oldDocument = convertOnlyResultToDocument(result, SubnetState.class);
if (ObjectUpdateKind.MODIFY.equals(netOverlay.getObjectUpdateKind())) {
updateSubnet(service, oldDocument, enumerationProgress, netOverlay, false);
} else {
// DV port group has been removed. Remove the subnet state document.
deleteNetwork(service, enumerationProgress, netOverlay, oldDocument);
}
} else {
enumerationProgress.getNetworkTracker().track();
}
});
} else {
// DVS or Opaque network.
QueryTask task = queryForNetwork(enumerationProgress, netOverlay);
VsphereEnumerationHelper.withTaskResults(service, task, result -> {
if (!result.documentLinks.isEmpty()) {
NetworkState oldDocument = convertOnlyResultToDocument(result, NetworkState.class);
if (ObjectUpdateKind.MODIFY.equals(netOverlay.getObjectUpdateKind())) {
updateNetwork(service, oldDocument, enumerationProgress, netOverlay);
} else {
deleteNetwork(service, enumerationProgress, netOverlay, oldDocument);
}
} else {
enumerationProgress.getNetworkTracker().track();
}
});
}
}
}
try {
enumerationProgress.getNetworkTracker().await();
} catch (InterruptedException e) {
service.logSevere("Interrupted during incremental enumeration for networks!", e);
}
}
Aggregations