use of com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription in project photon-model by vmware.
the class VSphereAdapterSnapshotService method processNextStepsForDeleteOperation.
private void processNextStepsForDeleteOperation(SnapshotContext context, DeferredResult<SnapshotContext> deferredResult) {
final SnapshotState snapshot = context.snapshotState;
// Update the isCurrent
if (snapshot.isCurrent && snapshot.parentLink != null) {
logInfo("Updating the parent of the snapshot %s to current", snapshot.name);
SnapshotState parentSnapshot = new SnapshotState();
parentSnapshot.isCurrent = Boolean.TRUE;
context.snapshotOperations.add(Operation.createPatch(PhotonModelUriUtils.createInventoryUri(this.getHost(), snapshot.parentLink)).setBody(parentSnapshot).setReferer(getUri()));
}
// Check if the deleted snapshot is the last available snapshot
DeferredResult<Boolean> result = isLastSnapshotForCompute(context);
Operation[] patchComputeOp = new Operation[1];
result.whenComplete((b, e) -> {
if (e != null) {
logSevere(e);
deferredResult.fail(e);
return;
}
if (b) {
ComputeStateWithDescription compute = context.computeDescription;
compute.customProperties.put(ComputeProperties.CUSTOM_PROP_COMPUTE_HAS_SNAPSHOTS, Boolean.FALSE.toString());
// patch compute adding property that it _hasSnapshots
logInfo("Updating the state of compute resource: %s", compute.name);
patchComputeOp[0] = Operation.createPatch(UriUtils.buildUri(getHost(), snapshot.computeLink)).setBody(compute).setReferer(getUri());
context.snapshotOperations.add(patchComputeOp[0]);
}
OperationJoin.JoinedCompletionHandler joinCompletion = (ox, exc) -> {
if (exc != null) {
this.logSevere(() -> String.format("Error updating the snapshot states: %s", Utils.toString(exc)));
deferredResult.fail(new IllegalStateException("Error updating the snapshot states"));
return;
}
deferredResult.complete(context);
};
context.snapshotOperations.add(Operation.createDelete(UriUtils.buildUri(getHost(), snapshot.documentSelfLink)).setReferer(getUri()));
OperationJoin joinOp = OperationJoin.create(context.snapshotOperations);
joinOp.setCompletion(joinCompletion);
joinOp.sendWith(this.getHost());
});
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription in project photon-model by vmware.
the class VSphereNetworkEnumerationHelper method makeNetworkStateFromResults.
private static NetworkState makeNetworkStateFromResults(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, NetworkOverlay net) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
ComputeStateWithDescription parent = enumerationProgress.getParent();
NetworkState state = new NetworkState();
state.documentSelfLink = NetworkService.FACTORY_LINK + "/" + service.getHost().nextUUID();
state.id = state.name = net.getName();
state.endpointLink = enumerationProgress.getRequest().endpointLink;
AdapterUtils.addToEndpointLinks(state, enumerationProgress.getRequest().endpointLink);
state.regionId = enumerationProgress.getRegionId();
state.resourcePoolLink = request.resourcePoolLink;
state.adapterManagementReference = request.adapterManagementReference;
state.authCredentialsLink = parent.description.authCredentialsLink;
URI ref = parent.description.instanceAdapterReference;
state.instanceAdapterReference = AdapterUriUtil.buildAdapterUri(ref.getPort(), VSphereUriPaths.DVS_NETWORK_SERVICE);
CustomProperties custProp = CustomProperties.of(state).put(CustomProperties.MOREF, net.getId()).put(CustomProperties.DATACENTER_SELF_LINK, enumerationProgress.getDcLink()).put(CustomProperties.TYPE, net.getId().getType());
if (net.getSummary() instanceof OpaqueNetworkSummary) {
OpaqueNetworkSummary ons = (OpaqueNetworkSummary) net.getSummary();
custProp.put(NsxProperties.OPAQUE_NET_ID, ons.getOpaqueNetworkId());
custProp.put(NsxProperties.OPAQUE_NET_TYPE, ons.getOpaqueNetworkType());
}
if (net.getId().getType().equals(VimNames.TYPE_DVS)) {
// dvs'es have a stable link
state.documentSelfLink = buildStableDvsLink(net.getId(), request.endpointLink);
custProp.put(DvsProperties.DVS_UUID, net.getDvsUuid());
}
VsphereEnumerationHelper.populateResourceStateWithAdditionalProps(state, enumerationProgress.getVcUuid());
return state;
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription in project photon-model by vmware.
the class TestAWSMissingEnumerationResourcesService method createPrimaryRootCompute.
public ComputeStateWithDescription createPrimaryRootCompute() {
ComputeStateWithDescription primaryRootCompute = new ComputeStateWithDescription();
primaryRootCompute.id = "456";
primaryRootCompute.name = "MOCK_ACC";
primaryRootCompute.type = ComputeType.ENDPOINT_HOST;
primaryRootCompute.documentSelfLink = "selfLink";
primaryRootCompute.description = new ComputeDescription();
Set<URI> statsAdapterReferences = new HashSet<>();
statsAdapterReferences.add(UriUtils.buildUri("stats-adapter-references"));
primaryRootCompute.description.statsAdapterReferences = statsAdapterReferences;
primaryRootCompute.creationTimeMicros = 1492610429910002L;
primaryRootCompute.endpointLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, generateUuidFromStr("endpointLink"));
primaryRootCompute.adapterManagementReference = UriUtils.buildUri("amazonaws.com");
primaryRootCompute.customProperties = new HashMap<>();
primaryRootCompute.customProperties.put(EndpointAllocationTaskService.CUSTOM_PROP_ENPOINT_TYPE, EndpointType.aws.name());
primaryRootCompute.resourcePoolLink = "resourcePoolLink";
return primaryRootCompute;
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription in project photon-model by vmware.
the class ResourceRemovalTaskService method sendInstanceDelete.
private void sendInstanceDelete(String resourceLink, String subTaskLink, Operation o, ResourceRemovalTaskState currentState) {
ComputeStateWithDescription chd = o.getBody(ComputeStateWithDescription.class);
if (chd.description.instanceAdapterReference != null) {
ComputeInstanceRequest deleteReq = new ComputeInstanceRequest();
deleteReq.resourceReference = createInventoryUri(this.getHost(), resourceLink);
deleteReq.taskReference = UriUtils.buildUri(getHost(), subTaskLink);
deleteReq.requestType = ComputeInstanceRequest.InstanceRequestType.DELETE;
deleteReq.isMockRequest = currentState.isMockRequest;
sendRequest(Operation.createPatch(chd.description.instanceAdapterReference).setBody(deleteReq).setCompletion((deleteOp, e) -> {
if (e != null) {
logWarning(() -> String.format("PATCH to instance service %s, failed: %s", deleteOp.getUri(), e.toString()));
ResourceOperationResponse fail = ResourceOperationResponse.fail(resourceLink, e);
sendPatch(subTaskLink, fail);
return;
}
}));
} else {
logWarning(() -> String.format("Compute instance %s doesn't not have configured" + " instanceAdapter. Only local resource will be deleted.", resourceLink));
ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.finish(resourceLink);
sendPatch(subTaskLink, subTaskPatchBody);
}
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription in project photon-model by vmware.
the class SingleResourceStatsCollectionTaskService method getDescriptions.
private void getDescriptions(SingleResourceStatsCollectionTaskState currentState) {
URI computeDescUri = ComputeStateWithDescription.buildUri(UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), currentState.computeLink));
sendRequest(Operation.createGet(computeDescUri).setCompletion((getOp, getEx) -> {
if (getEx != null) {
TaskUtils.sendFailurePatch(this, currentState, getEx);
return;
}
ComputeStateWithDescription computeStateWithDesc = getOp.getBody(ComputeStateWithDescription.class);
ComputeStatsRequest statsRequest = new ComputeStatsRequest();
statsRequest.isMockRequest = currentState.options != null ? currentState.options.contains(TaskOption.IS_MOCK) : false;
URI patchUri = null;
Object patchBody = null;
ComputeDescription description = computeStateWithDesc.description;
URI statsAdapterReference = null;
List<String> tenantLinks = new ArrayList<>();
if (description != null) {
tenantLinks = description.tenantLinks;
// provided
if (currentState.statsAdapterReference == null) {
statsAdapterReference = description.statsAdapterReference;
} else if (description.statsAdapterReferences != null) {
for (URI uri : description.statsAdapterReferences) {
if (uri.getPath().equals(currentState.statsAdapterReference.getPath())) {
statsAdapterReference = currentState.statsAdapterReference;
break;
}
}
}
}
if (statsAdapterReference != null) {
statsRequest.nextStage = SingleResourceTaskCollectionStage.UPDATE_STATS.name();
statsRequest.resourceReference = UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), computeStateWithDesc.documentSelfLink);
statsRequest.taskReference = getUri();
patchUri = statsAdapterReference;
populateLastCollectionTimeForMetricsInStatsRequest(currentState, statsRequest, patchUri, tenantLinks);
} else {
// no adapter associated with this resource, just patch completion
SingleResourceStatsCollectionTaskState nextStageState = new SingleResourceStatsCollectionTaskState();
nextStageState.taskInfo = new TaskState();
nextStageState.taskInfo.stage = TaskStage.FINISHED;
patchUri = getUri();
patchBody = nextStageState;
sendStatsRequestToAdapter(currentState, patchUri, patchBody);
}
}));
}
Aggregations