Search in sources :

Example 11 with ComputeStateWithDescription

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());
    });
}
Also used : Service(com.vmware.xenon.common.Service) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) SessionUtil(com.vmware.photon.controller.model.resources.SessionUtil) ResourceOperationUtils.handleAdapterResourceOperationRegistration(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.handleAdapterResourceOperationRegistration) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) ResourceOperationSpecService(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) StringUtils(org.apache.commons.lang3.StringUtils) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) ArrayList(java.util.ArrayList) TargetCriteria(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.TargetCriteria) Utils(com.vmware.xenon.common.Utils) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) SnapshotRequestType(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotRequestType) BiConsumer(java.util.function.BiConsumer) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) URI(java.net.URI) TaskInfo(com.vmware.vim25.TaskInfo) OperationSequence(com.vmware.xenon.common.OperationSequence) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) MapUtils(org.apache.commons.collections.MapUtils) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SnapshotService(com.vmware.photon.controller.model.resources.SnapshotService) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) List(java.util.List) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) Optional(java.util.Optional) VSphereConstants(com.vmware.photon.controller.model.adapters.vsphere.constants.VSphereConstants) FactoryService(com.vmware.xenon.common.FactoryService) IAAS_API_ENABLED(com.vmware.photon.controller.model.UriPaths.IAAS_API_ENABLED) TaskInfoState(com.vmware.vim25.TaskInfoState) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) OperationJoin(com.vmware.xenon.common.OperationJoin) Operation(com.vmware.xenon.common.Operation) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)

Example 12 with ComputeStateWithDescription

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;
}
Also used : OpaqueNetworkSummary(com.vmware.vim25.OpaqueNetworkSummary) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) URI(java.net.URI)

Example 13 with ComputeStateWithDescription

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;
}
Also used : ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) URI(java.net.URI) HashSet(java.util.HashSet)

Example 14 with ComputeStateWithDescription

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);
    }
}
Also used : Service(com.vmware.xenon.common.Service) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) Utils(com.vmware.xenon.common.Utils) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) URI(java.net.URI) EnumSet(java.util.EnumSet) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) Operation(com.vmware.xenon.common.Operation) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SnapshotService(com.vmware.photon.controller.model.resources.SnapshotService) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ResourceIPDeallocationTaskState(com.vmware.photon.controller.model.tasks.ResourceIPDeallocationTaskService.ResourceIPDeallocationTaskState) List(java.util.List) Stream(java.util.stream.Stream) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ServiceTaskCallbackResponse(com.vmware.photon.controller.model.tasks.ServiceTaskCallback.ServiceTaskCallbackResponse) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) TaskState(com.vmware.xenon.common.TaskState) TaskService(com.vmware.xenon.services.common.TaskService) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)

Example 15 with ComputeStateWithDescription

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);
        }
    }));
}
Also used : Service(com.vmware.xenon.common.Service) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) AggregationType(com.vmware.xenon.common.ServiceStats.TimeSeriesStats.AggregationType) MatchType(com.vmware.xenon.services.common.QueryTask.QueryTerm.MatchType) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) Utils(com.vmware.xenon.common.Utils) TaskFactoryService(com.vmware.xenon.services.common.TaskFactoryService) Map(java.util.Map) URI(java.net.URI) EnumSet(java.util.EnumSet) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) ServiceStats(com.vmware.xenon.common.ServiceStats) List(java.util.List) TimeSeriesStats(com.vmware.xenon.common.ServiceStats.TimeSeriesStats) UriUtils(com.vmware.xenon.common.UriUtils) Entry(java.util.Map.Entry) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) TaskState(com.vmware.xenon.common.TaskState) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) FactoryService(com.vmware.xenon.common.FactoryService) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) TaskService(com.vmware.xenon.services.common.TaskService) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) TaskUtils(com.vmware.photon.controller.model.tasks.TaskUtils) InMemoryResourceMetric(com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService.InMemoryResourceMetric) HashMap(java.util.HashMap) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) ArrayList(java.util.ArrayList) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) OperationSequence(com.vmware.xenon.common.OperationSequence) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) TypeName(com.vmware.xenon.common.ServiceDocumentDescription.TypeName) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) InMemoryResourceMetricService(com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) Comparator(java.util.Comparator) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) List(java.util.List) ArrayList(java.util.ArrayList) URI(java.net.URI) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) TaskState(com.vmware.xenon.common.TaskState)

Aggregations

ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)15 URI (java.net.URI)13 Operation (com.vmware.xenon.common.Operation)10 Utils (com.vmware.xenon.common.Utils)8 List (java.util.List)8 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)7 UriUtils (com.vmware.xenon.common.UriUtils)7 QueryTask (com.vmware.xenon.services.common.QueryTask)7 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)6 OperationJoin (com.vmware.xenon.common.OperationJoin)6 ArrayList (java.util.ArrayList)6 UriPaths (com.vmware.photon.controller.model.UriPaths)5 TaskManager (com.vmware.photon.controller.model.adapters.util.TaskManager)5 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)5 Service (com.vmware.xenon.common.Service)5 ServiceDocument (com.vmware.xenon.common.ServiceDocument)5 QueryOption (com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption)5 HashMap (java.util.HashMap)5 ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)4 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)4