Search in sources :

Example 11 with ServiceDocument

use of com.vmware.xenon.common.ServiceDocument in project photon-model by vmware.

the class EndpointAllocationTaskService method invokeAdapter.

private void invokeAdapter(EndpointAllocationTaskState currentState, SubStage next) {
    CompletionHandler c = (o, e) -> {
        if (e != null) {
            sendFailurePatch(this, currentState, e);
            return;
        }
        EndpointConfigRequest req = new EndpointConfigRequest();
        req.isMockRequest = currentState.options.contains(TaskOption.IS_MOCK);
        req.requestType = RequestType.ENHANCE;
        req.tenantLinks = currentState.tenantLinks;
        req.resourceReference = createInventoryUri(this.getHost(), currentState.endpointState.documentSelfLink);
        ServiceDocument subTask = o.getBody(ServiceDocument.class);
        req.taskReference = UriUtils.buildUri(this.getHost(), subTask.documentSelfLink);
        req.endpointProperties = currentState.endpointState.endpointProperties;
        sendEnhanceRequest(req, currentState);
    };
    createSubTask(c, next, currentState);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) CertificateInfoServiceErrorResponse(com.vmware.photon.controller.model.support.CertificateInfoServiceErrorResponse) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Utils(com.vmware.xenon.common.Utils) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) Map(java.util.Map) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) URI(java.net.URI) SINGLE_ASSIGNMENT(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SINGLE_ASSIGNMENT) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ENDPOINT_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PhotonModelAdaptersConfigAccessService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersConfigAccessService) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) TaskUtils.sendFailurePatch(com.vmware.photon.controller.model.tasks.TaskUtils.sendFailurePatch) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) TaskService(com.vmware.xenon.services.common.TaskService) AdapterTypePath(com.vmware.photon.controller.model.UriPaths.AdapterTypePath) STORE_ONLY(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.STORE_ONLY) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) OperationSequence(com.vmware.xenon.common.OperationSequence) SERVICE_USE(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SERVICE_USE) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Operation(com.vmware.xenon.common.Operation) CertificateInfo(com.vmware.photon.controller.model.support.CertificateInfo) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) PropertyIndexingOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) ServiceDocument(com.vmware.xenon.common.ServiceDocument) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)

Example 12 with ServiceDocument

use of com.vmware.xenon.common.ServiceDocument in project photon-model by vmware.

the class ProvisionDiskTaskService method doSubStageDiskOperation.

private void doSubStageDiskOperation(ProvisionDiskTaskState updatedState, ProvisionDiskTaskState.SubStage nextStage, DiskInstanceRequest.DiskRequestType diskRequestType) {
    Operation.CompletionHandler c = (o, e) -> {
        if (e != null) {
            failTask(e);
            return;
        }
        DiskInstanceRequest cr = new DiskInstanceRequest();
        cr.resourceReference = createInventoryUri(this.getHost(), updatedState.diskLink);
        cr.requestType = diskRequestType;
        ServiceDocument subTask = o.getBody(ServiceDocument.class);
        cr.taskReference = UriUtils.buildUri(this.getHost(), subTask.documentSelfLink);
        cr.isMockRequest = updatedState.isMockRequest;
        sendHostServiceRequest(cr, updatedState.diskAdapterReference);
    };
    // after setting boot order and rebooting, we want the sub
    // task to patch us, the main task, to the "next" state
    createSubTask(c, nextStage, updatedState);
}
Also used : ProvisionDiskTaskState(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState) Operation(com.vmware.xenon.common.Operation) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) DiskInstanceRequest(com.vmware.photon.controller.model.adapterapi.DiskInstanceRequest) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Utils(com.vmware.xenon.common.Utils) UriPaths(com.vmware.photon.controller.model.UriPaths) SubStage(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService.ProvisionDiskTaskState.SubStage) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) UriUtils(com.vmware.xenon.common.UriUtils) TaskState(com.vmware.xenon.common.TaskState) URI(java.net.URI) TaskService(com.vmware.xenon.services.common.TaskService) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Operation(com.vmware.xenon.common.Operation) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) DiskInstanceRequest(com.vmware.photon.controller.model.adapterapi.DiskInstanceRequest)

Example 13 with ServiceDocument

use of com.vmware.xenon.common.ServiceDocument in project photon-model by vmware.

the class ResourceGroomerTaskService method populateEndpointLinksByDocumentLinks.

/**
 * Helper for creating corresponding object and parsing the response for given documentKind
 * to store selfLink and endpointLink.
 */
private static void populateEndpointLinksByDocumentLinks(Map<String, Object> documents, Map<String, Set<String>> endpointLinksByDocumentLinks, Map<String, String> endpointLinkByDocumentLinks) {
    for (Object document : documents.values()) {
        ServiceDocument doc = Utils.fromJson(document, ServiceDocument.class);
        Set<String> endpointLinks = new HashSet<>();
        if (doc.documentKind.equals(COMPUTE_STATE_DOCUMENT_KIND)) {
            ComputeState state = Utils.fromJson(document, ComputeState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(DISK_STATE_DOCUMENT_KIND)) {
            DiskState state = Utils.fromJson(document, DiskState.class);
            if (state.customProperties != null && state.customProperties.containsKey(ResourceUtils.CUSTOM_PROP_NO_ENDPOINT)) {
                // skip resources that have never been attached to a particular endpoint
                continue;
            }
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(COMPUTE_DESCRIPTION_DOCUMENT_KIND)) {
            ComputeDescription state = Utils.fromJson(document, ComputeDescription.class);
            // only deleting discovered resources
            if (!(state.customProperties != null && (ResourceEnumerationTaskService.FACTORY_LINK.equals(state.customProperties.get(SOURCE_TASK_LINK)) || EndpointAllocationTaskService.FACTORY_LINK.equals(state.customProperties.get(SOURCE_TASK_LINK))))) {
                continue;
            }
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(NETWORK_STATE_DOCUMENT_KIND)) {
            NetworkState state = Utils.fromJson(document, NetworkState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(NETWORK_INTERFACE_STATE_DOCUMENT_KIND)) {
            NetworkInterfaceState state = Utils.fromJson(document, NetworkInterfaceState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(SECURITY_GROUP_STATE_DOCUMENT_KIND)) {
            SecurityGroupState state = Utils.fromJson(document, SecurityGroupState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(SUBNET_STATE_DOCUMENT_KIND)) {
            SubnetState state = Utils.fromJson(document, SubnetState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(LOAD_BALANCER_DOCUMENT_KIND)) {
            LoadBalancerState state = Utils.fromJson(document, LoadBalancerState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(STORAGE_DESCRIPTION_DOCUMENT_KIND)) {
            StorageDescription state = Utils.fromJson(document, StorageDescription.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(RESOURCE_GROUP_DOCUMENT_KIND)) {
            ResourceGroupState state = Utils.fromJson(document, ResourceGroupState.class);
            if (state.customProperties != null && state.customProperties.containsKey(ResourceGroupService.PROPERTY_NAME_IS_USER_CREATED)) {
                continue;
            }
            if (state.customProperties != null && state.customProperties.containsKey(ResourceUtils.CUSTOM_PROP_NO_ENDPOINT)) {
                // skip resources that have never been attached to a particular endpoint
                continue;
            }
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(IMAGE_STATE_KIND)) {
            ImageState state = Utils.fromJson(document, ImageState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(ROUTER_STATE_KIND)) {
            RouterState state = Utils.fromJson(document, RouterState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(AUTH_CREDENTIALS_SERVICE_STATE_KIND)) {
            AuthCredentialsServiceState state = Utils.fromJson(document, AuthCredentialsServiceState.class);
            if (state.customProperties != null && state.customProperties.get(CUSTOM_PROP_ENDPOINT_LINK) != null) {
                endpointLinkByDocumentLinks.put(state.documentSelfLink, state.customProperties.get(CUSTOM_PROP_ENDPOINT_LINK));
            } else {
                endpointLinkByDocumentLinks.put(state.documentSelfLink, EMPTY_STRING);
            }
        }
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) RouterState(com.vmware.photon.controller.model.resources.RouterService.RouterState) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) HashSet(java.util.HashSet) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 14 with ServiceDocument

use of com.vmware.xenon.common.ServiceDocument in project photon-model by vmware.

the class EndpointRemovalTaskServiceTest method createEndpoint.

private static EndpointState createEndpoint(BaseModelTest test) throws Throwable {
    EndpointState endpoint = createEndpointState();
    // Create endpoint
    EndpointAllocationTaskState startState = createEndpointAllocationRequest(endpoint);
    startState.adapterReference = UriUtils.buildUri(test.getHost(), MockSuccessEndpointAdapter.SELF_LINK);
    EndpointAllocationTaskState returnState = test.postServiceSynchronously(EndpointAllocationTaskService.FACTORY_LINK, startState, EndpointAllocationTaskState.class);
    EndpointAllocationTaskState completeState = test.waitForServiceState(EndpointAllocationTaskState.class, returnState.documentSelfLink, state -> TaskState.TaskStage.FINISHED.ordinal() <= state.taskInfo.stage.ordinal());
    assertThat(completeState.taskInfo.stage, is(TaskState.TaskStage.FINISHED));
    EndpointAllocationTaskState taskState = getServiceSynchronously(test, completeState.documentSelfLink, EndpointAllocationTaskState.class);
    assertNotNull(taskState);
    assertNotNull(taskState.endpointState);
    ServiceDocument endpointState = taskState.endpointState;
    assertNotNull(endpointState.documentSelfLink);
    return getServiceSynchronously(test, endpointState.documentSelfLink, EndpointState.class);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument)

Example 15 with ServiceDocument

use of com.vmware.xenon.common.ServiceDocument in project photon-model by vmware.

the class EndpointServiceTests method testCreateAndThenValidate.

public void testCreateAndThenValidate(EndpointService.EndpointState ep) throws Throwable {
    EndpointAllocationTaskState createEndpoint = new EndpointAllocationTaskState();
    createEndpoint.endpointState = ep;
    createEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
    EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, createEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
    this.host.waitForFinishedTask(EndpointAllocationTaskState.class, outTask.documentSelfLink);
    EndpointAllocationTaskState taskState = getServiceSynchronously(outTask.documentSelfLink, EndpointAllocationTaskState.class);
    assertNotNull(taskState);
    assertNotNull(taskState.endpointState);
    ServiceDocument endpointState = taskState.endpointState;
    assertNotNull(endpointState.documentSelfLink);
    // check endpoint document was created
    EndpointService.EndpointState endpoint = getServiceSynchronously(endpointState.documentSelfLink, EndpointService.EndpointState.class);
    // now do validation
    EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
    validateEndpoint.endpointState = endpoint;
    validateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : EnumSet.noneOf(TaskOption.class);
    validateEndpoint.options.add(TaskOption.VALIDATE_ONLY);
    EndpointAllocationTaskState validateEndpointTask = TestUtils.doPost(this.host, validateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
    this.host.waitForFinishedTask(EndpointAllocationTaskState.class, validateEndpointTask.documentSelfLink);
}
Also used : EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState)

Aggregations

ServiceDocument (com.vmware.xenon.common.ServiceDocument)47 Operation (com.vmware.xenon.common.Operation)11 URI (java.net.URI)6 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)5 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)5 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)5 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)5 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)5 CompletionHandler (com.vmware.xenon.common.Operation.CompletionHandler)5 UriUtils (com.vmware.xenon.common.UriUtils)5 List (java.util.List)5 UriPaths (com.vmware.photon.controller.model.UriPaths)4 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)4 TaskState (com.vmware.xenon.common.TaskState)4 TaskStage (com.vmware.xenon.common.TaskState.TaskStage)4 Utils (com.vmware.xenon.common.Utils)4 TaskService (com.vmware.xenon.services.common.TaskService)4 TimeUnit (java.util.concurrent.TimeUnit)4 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)3 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)3