use of com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription in project photon-model by vmware.
the class MockCostStatsAdapterService method getAccountDescription.
@Override
protected void getAccountDescription(AWSCostStatsCreationContext statsData, AWSCostStatsCreationStages next) {
ComputeDescription compDesc = new ComputeDescription();
compDesc.id = "123";
compDesc.documentSelfLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, generateUuidFromStr(compDesc.id));
Set<URI> statsAdapterReferences = new HashSet<>();
statsAdapterReferences.add(UriUtils.buildUri("stats-adapter-references"));
compDesc.statsAdapterReferences = statsAdapterReferences;
statsData.accountId = TestAWSCostAdapterService.account1Id;
ComputeStateWithDescription account1ComputeState = new ComputeStateWithDescription();
account1ComputeState.documentSelfLink = TestAWSCostAdapterService.account1SelfLink;
account1ComputeState.type = ComputeType.ENDPOINT_HOST;
account1ComputeState.endpointLink = "endpoint1";
account1ComputeState.endpointLinks = new HashSet<String>();
account1ComputeState.endpointLinks.add("endpoint1");
account1ComputeState.name = "account1";
account1ComputeState.descriptionLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, generateUuidFromStr("123"));
account1ComputeState.creationTimeMicros = Utils.getNowMicrosUtc();
account1ComputeState.customProperties = new HashMap<>();
account1ComputeState.customProperties.put(AWSConstants.AWS_ACCOUNT_ID_KEY, "account1Id");
account1ComputeState.customProperties.put(EndpointAllocationTaskService.CUSTOM_PROP_ENPOINT_TYPE, EndpointType.aws.name());
account1ComputeState.description = new ComputeDescription();
account1ComputeState.description.statsAdapterReferences = statsAdapterReferences;
account1ComputeState.tenantLinks = Collections.singletonList("tenant-1");
statsData.computeDesc = account1ComputeState;
statsData.awsAccountIdToComputeStates.put(TestAWSCostAdapterService.account1Id, Collections.singletonList(account1ComputeState));
inferEndpointLink(statsData);
getParentAuth(statsData, next);
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription in project photon-model by vmware.
the class AWSCostStatsService method getAccountDescription.
protected void getAccountDescription(AWSCostStatsCreationContext statsData, AWSCostStatsCreationStages next) {
Consumer<Operation> onSuccess = (op) -> {
ComputeStateWithDescription compute = op.getBody(ComputeStateWithDescription.class);
statsData.computeDesc = compute;
inferEndpointLink(statsData);
String accountId = AWSUtils.isAwsS3Proxy() ? "mock" : compute.customProperties.get(AWS_ACCOUNT_ID_KEY);
if (compute.type != ComputeType.ENDPOINT_HOST || compute.parentLink != null || compute.endpointLink == null || accountId == null || CollectionUtils.isEmpty(compute.endpointLinks)) {
logWithContext(statsData, Level.SEVERE, () -> "Malformed Root Compute.");
postAccumulatedCostStats(statsData, true);
return;
}
statsData.accountId = accountId;
statsData.awsAccountIdToComputeStates.put(accountId, Collections.singletonList(compute));
getEndpointState(statsData, next);
};
URI computeUri = UriUtils.extendUriWithQuery(statsData.statsRequest.resourceReference, UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
AdapterUtils.getServiceState(this, computeUri, onSuccess, getFailureConsumer(statsData));
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription in project photon-model by vmware.
the class ResourceEnumerationTaskService method sendEnumRequest.
private void sendEnumRequest(Operation start, ResourceEnumerationTaskState state) {
ComputeEnumerateResourceRequest req = new ComputeEnumerateResourceRequest();
req.resourcePoolLink = state.resourcePoolLink;
req.adapterManagementReference = state.adapterManagementReference;
req.resourceReference = createInventoryUri(this.getHost(), state.parentComputeLink);
req.endpointLinkReference = createInventoryUri(this.getHost(), state.endpointLink);
req.enumerationAction = state.enumerationAction;
req.taskReference = UriUtils.buildUri(getHost(), state.documentSelfLink);
req.isMockRequest = state.options.contains(TaskOption.IS_MOCK);
req.preserveMissing = state.options.contains(TaskOption.PRESERVE_MISSING_RESOUCES);
req.endpointLink = state.endpointLink;
req.deletedResourceExpirationMicros = getResourceExpirationMicros(state.expirationPolicy == null ? ResourceExpirationPolicy.EXPIRE_AFTER_ONE_MONTH : state.expirationPolicy);
// Patch the enumerate service URI from the CHD
CompletionHandler descriptionCompletion = (o, ex) -> {
if (ex != null) {
TaskUtils.sendFailurePatch(this, state, ex);
start.fail(ex);
return;
}
ComputeStateWithDescription csd = o.getBody(ComputeStateWithDescription.class);
if (csd.description.enumerationAdapterReference == null) {
// no enumeration adapter associated with this resource, just patch completion
sendSelfFinishedPatch(state);
return;
}
sendRequest(Operation.createPatch(csd.description.enumerationAdapterReference).setBody(req));
};
URI computeUri = UriUtils.extendUriWithQuery(UriUtils.buildUri(this.getHost(), state.parentComputeLink), UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
sendRequest(Operation.createGet(computeUri).setCompletion(descriptionCompletion));
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription in project photon-model by vmware.
the class BaseAdapterContext method getParentDescription.
/**
* Populate context with parent {@code ComputeStateWithDescription}.
* <p>
* <p>
* By default {@code context.child.parentLink} is used as source.
*/
protected DeferredResult<T> getParentDescription(T context) {
URI ref = context.child != null ? // 'child' is already resolved so used it
UriUtils.buildUri(context.service.getHost(), context.child.parentLink) : // state machine starts from here so resRef should point to the parent
context.resourceReference;
ref = ComputeStateWithDescription.buildUri(ref);
Operation op = Operation.createGet(ref);
return context.service.sendWithDeferredResult(op, ComputeStateWithDescription.class).thenApply(state -> {
context.parent = state;
return context;
});
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription in project photon-model by vmware.
the class VSphereIncrementalEnumerationService method handlePatch.
@Override
public void handlePatch(Operation patch) {
// complete the patch immediately.
patch.complete();
logInfo("Received PATCH for incremental enumeration!");
VSphereIncrementalEnumerationRequest enumerationRequest = patch.getBody(VSphereIncrementalEnumerationRequest.class);
ComputeEnumerateResourceRequest request = enumerationRequest.request;
URI parentUri = ComputeService.ComputeStateWithDescription.buildUri(PhotonModelUriUtils.createInventoryUri(getHost(), request.resourceReference));
logInfo("Creating task manager!");
TaskManager mgr = new TaskManager(this, request.taskReference, request.resourceLink());
logInfo(" Requesting GET on compute state with description!.");
Operation.createGet(parentUri).setCompletion(o -> {
logInfo("Submitting job to threadpool!");
VsphereEnumerationHelper.submitWorkToVSpherePool(this, () -> {
logInfo("Incremental enumeration job started for endpoint %s", enumerationRequest.request.endpointLink);
ComputeStateWithDescription computeStateWithDesc = o.getBody(ComputeStateWithDescription.class);
VapiConnection vapiConnection = VapiConnection.createFromVimConnection(this.connection);
logInfo("Establishing VAPI connection for endpoint %s", enumerationRequest.request.endpointLink);
try {
vapiConnection.login();
} catch (IOException | RpcException rpce) {
logWarning(() -> String.format("Cannot login into vAPI endpoint: %s", Utils.toString(rpce)));
mgr.patchTaskToFailure(rpce);
// self delete service so that full enumeration kicks in next invocation.
selfDeleteService();
return;
}
try {
// Get instanceUuid of the vCenter
AboutInfo vCenter = this.connection.getServiceContent().getAbout();
for (CollectorDetails collectorDetails : this.collectors) {
logInfo("Retrieving resources incremental data for data center: %s", collectorDetails.datacenter);
EnumerationProgress enumerationProgress = new EnumerationProgress(new HashSet<>(), request, computeStateWithDesc, vapiConnection, collectorDetails.datacenter, vCenter.getInstanceUuid());
EnumerationClient client = new EnumerationClient(this.connection, computeStateWithDesc, VimUtils.convertStringToMoRef(collectorDetails.datacenter));
List<ObjectUpdate> resourcesUpdates = collectResourcesData(collectorDetails);
List<ObjectUpdate> vmUpdates = collectVMData(collectorDetails);
logInfo("Received resources updates for datacenter: %s : %s", collectorDetails.datacenter, resourcesUpdates.size());
logInfo("Received vm updates for datacenter: %s : %s", collectorDetails.datacenter, vmUpdates.size());
logInfo("Resources Updates: %s", Utils.toJson(resourcesUpdates));
logInfo("VM Updates: %s", Utils.toJson(vmUpdates));
if (!resourcesUpdates.isEmpty()) {
SegregatedOverlays segregatedOverlays = segregateObjectUpdates(enumerationProgress, resourcesUpdates);
this.logInfo("Processing incremental changes for folders for datacenter [%s]!", collectorDetails.datacenter);
VsphereFolderEnumerationHelper.handleFolderChanges(this, segregatedOverlays.folders, enumerationProgress, client);
logInfo("Processing incremental changes for networks for datacenter [%s]!", collectorDetails.datacenter);
VSphereNetworkEnumerationHelper.handleNetworkChanges(this, segregatedOverlays.networks, enumerationProgress, client);
logInfo("Processing incremental changes for Datastores for datacenter [%s]!", collectorDetails.datacenter);
VsphereDatastoreEnumerationHelper.handleDatastoreChanges(this, segregatedOverlays.datastores, enumerationProgress);
logInfo("Processing incremental changes for compute resource for datacenter [%s]!", collectorDetails.datacenter);
VsphereComputeResourceEnumerationHelper.handleComputeResourceChanges(this, segregatedOverlays.clusters, enumerationProgress, client);
logInfo("Processing incremental changes for host system for datacenter [%s]!", collectorDetails.datacenter);
VSphereHostSystemEnumerationHelper.handleHostSystemChanges(this, segregatedOverlays.hosts, enumerationProgress, client);
logInfo("Processing incremental changes for resource pool for datacenter [%s]!", collectorDetails.datacenter);
VSphereResourcePoolEnumerationHelper.handleResourcePoolChanges(this, segregatedOverlays.resourcePools, enumerationProgress, client);
}
if (!vmUpdates.isEmpty()) {
logInfo("Processing incremental changes for virtual machines for datacenter [%s]!", collectorDetails.datacenter);
VSphereVirtualMachineEnumerationHelper.handleVMChanges(this, vmUpdates, enumerationProgress, client);
}
// sync storage profiles
logInfo("Syncing storage profiles for datacenter [%s]!", collectorDetails.datacenter);
VsphereStoragePolicyEnumerationHelper.syncStorageProfiles(this, client, enumerationProgress);
}
mgr.patchTask(TaskStage.FINISHED);
} catch (Exception exception) {
String msg = "Error processing PropertyCollector results during incremental retrieval";
logWarning(() -> msg + ": " + exception.toString());
mgr.patchTaskToFailure(exception);
// self delete service so that full enumeration kicks in next invocation.
// TODO: This is not complete. We need to enable owner selection on this service.
selfDeleteService();
return;
} finally {
vapiConnection.close();
}
});
}, mgr).sendWith(this);
}
Aggregations